Make EVP_Digest*() routines return a value.

TODO: update docs, and make soe other routines
which use EVP_Digest*() check return codes.
This commit is contained in:
Dr. Stephen Henson 2001-03-08 14:04:22 +00:00
parent 4f98cbabde
commit 2dc769a1c1
17 changed files with 76 additions and 55 deletions

View File

@ -3,6 +3,11 @@
Changes between 0.9.6 and 0.9.7 [xx XXX 2000]
*) Modify EVP_Digest*() routines so they now return values. Although the
internal software routines can never fail additional hardware versions
might.
[Steve Henson]
*) Clean up crypto/err/err.h and change some error codes to avoid conflicts:
Previously ERR_R_FATAL was too small and coincided with ERR_LIB_PKCS7

View File

@ -61,24 +61,26 @@
#include <openssl/objects.h>
#include <openssl/evp.h>
void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
{
ctx->digest=type;
type->init(&(ctx->md));
return type->init(&(ctx->md));
}
void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
unsigned int count)
{
ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count);
return ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count);
}
void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
{
ctx->digest->final(md,&(ctx->md.base[0]));
int ret;
ret = ctx->digest->final(md,&(ctx->md.base[0]));
if (size != NULL)
*size=ctx->digest->md_size;
memset(&(ctx->md),0,sizeof(ctx->md));
return ret;
}
int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in)
@ -95,8 +97,9 @@ int EVP_Digest(void *data, unsigned int count,
unsigned char *md, unsigned int *size, const EVP_MD *type)
{
EVP_MD_CTX ctx;
EVP_DigestInit(&ctx, type);
EVP_DigestUpdate(&ctx, data, count);
EVP_DigestFinal(&ctx, md, size);
return 1;
if (!EVP_DigestInit(&ctx, type))
return 0;
if (!EVP_DigestUpdate(&ctx, data, count))
return 0;
return EVP_DigestFinal(&ctx, md, size);
}

View File

@ -268,9 +268,9 @@ typedef struct env_md_st
int type;
int pkey_type;
int md_size;
void (*init)();
void (*update)();
void (*final)();
int (*init)();
int (*update)();
int (*final)();
int (*sign)();
int (*verify)();
@ -558,10 +558,10 @@ void BIO_set_md(BIO *,const EVP_MD *md);
int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
void EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
unsigned int cnt);
void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
int EVP_Digest(void *data, unsigned int count,
unsigned char *md, unsigned int *size, const EVP_MD *type);

View File

@ -62,8 +62,9 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
static void function(void)
static int function(void)
{
return 1;
}
static EVP_MD null_md=

View File

@ -80,9 +80,9 @@ typedef struct MD2state_st
} MD2_CTX;
const char *MD2_options(void);
void MD2_Init(MD2_CTX *c);
void MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len);
void MD2_Final(unsigned char *md, MD2_CTX *c);
int MD2_Init(MD2_CTX *c);
int MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len);
int MD2_Final(unsigned char *md, MD2_CTX *c);
unsigned char *MD2(const unsigned char *d, unsigned long n,unsigned char *md);
#ifdef __cplusplus
}

View File

@ -115,19 +115,20 @@ const char *MD2_options(void)
return("md2(int)");
}
void MD2_Init(MD2_CTX *c)
int MD2_Init(MD2_CTX *c)
{
c->num=0;
memset(c->state,0,MD2_BLOCK*sizeof(MD2_INT));
memset(c->cksm,0,MD2_BLOCK*sizeof(MD2_INT));
memset(c->data,0,MD2_BLOCK);
return 1;
}
void MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len)
int MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len)
{
register UCHAR *p;
if (len == 0) return;
if (len == 0) return 1;
p=c->data;
if (c->num != 0)
@ -146,7 +147,7 @@ void MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len)
memcpy(&(p[c->num]),data,(int)len);
/* data+=len; */
c->num+=(int)len;
return;
return 1;
}
}
/* we now can process the input data in blocks of MD2_BLOCK
@ -159,6 +160,7 @@ void MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len)
}
memcpy(p,data,(int)len);
c->num=(int)len;
return 1;
}
static void md2_block(MD2_CTX *c, const unsigned char *d)
@ -197,7 +199,7 @@ static void md2_block(MD2_CTX *c, const unsigned char *d)
memset(state,0,48*sizeof(MD2_INT));
}
void MD2_Final(unsigned char *md, MD2_CTX *c)
int MD2_Final(unsigned char *md, MD2_CTX *c)
{
int i,v;
register UCHAR *cp;
@ -219,5 +221,6 @@ void MD2_Final(unsigned char *md, MD2_CTX *c)
for (i=0; i<16; i++)
md[i]=(UCHAR)(p1[i]&0xff);
memset((char *)&c,0,sizeof(c));
return 1;
}

View File

@ -410,14 +410,14 @@
* Time for some action:-)
*/
void HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
int HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
{
const unsigned char *data=data_;
register HASH_LONG * p;
register unsigned long l;
int sw,sc,ew,ec;
if (len==0) return;
if (len==0) return 1;
l=(c->Nl+(len<<3))&0xffffffffL;
/* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
@ -466,7 +466,7 @@ void HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
HOST_c2l_p(data,l,ec); p[sw]=l;
}
}
return;
return 1;
}
}
@ -520,6 +520,7 @@ void HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
HOST_c2l_p(data,l,ec);
*p=l;
}
return 1;
}
@ -543,7 +544,7 @@ void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
}
void HASH_FINAL (unsigned char *md, HASH_CTX *c)
int HASH_FINAL (unsigned char *md, HASH_CTX *c)
{
register HASH_LONG *p;
register unsigned long l;
@ -604,4 +605,5 @@ void HASH_FINAL (unsigned char *md, HASH_CTX *c)
* but I'm not worried :-)
memset((void *)c,0,sizeof(HASH_CTX));
*/
return 1;
}

View File

@ -104,9 +104,9 @@ typedef struct MD4state_st
int num;
} MD4_CTX;
void MD4_Init(MD4_CTX *c);
void MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
void MD4_Final(unsigned char *md, MD4_CTX *c);
int MD4_Init(MD4_CTX *c);
int MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
int MD4_Final(unsigned char *md, MD4_CTX *c);
unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md);
void MD4_Transform(MD4_CTX *c, const unsigned char *b);
#ifdef __cplusplus

View File

@ -70,7 +70,7 @@ const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT;
#define INIT_DATA_C (unsigned long)0x98badcfeL
#define INIT_DATA_D (unsigned long)0x10325476L
void MD4_Init(MD4_CTX *c)
int MD4_Init(MD4_CTX *c)
{
c->A=INIT_DATA_A;
c->B=INIT_DATA_B;
@ -79,6 +79,7 @@ void MD4_Init(MD4_CTX *c)
c->Nl=0;
c->Nh=0;
c->num=0;
return 1;
}
#ifndef md4_block_host_order

View File

@ -102,9 +102,9 @@ typedef struct MD5state_st
int num;
} MD5_CTX;
void MD5_Init(MD5_CTX *c);
void MD5_Update(MD5_CTX *c, const void *data, unsigned long len);
void MD5_Final(unsigned char *md, MD5_CTX *c);
int MD5_Init(MD5_CTX *c);
int MD5_Update(MD5_CTX *c, const void *data, unsigned long len);
int MD5_Final(unsigned char *md, MD5_CTX *c);
unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md);
void MD5_Transform(MD5_CTX *c, const unsigned char *b);
#ifdef __cplusplus

View File

@ -70,7 +70,7 @@ const char *MD5_version="MD5" OPENSSL_VERSION_PTEXT;
#define INIT_DATA_C (unsigned long)0x98badcfeL
#define INIT_DATA_D (unsigned long)0x10325476L
void MD5_Init(MD5_CTX *c)
int MD5_Init(MD5_CTX *c)
{
c->A=INIT_DATA_A;
c->B=INIT_DATA_B;
@ -79,6 +79,7 @@ void MD5_Init(MD5_CTX *c)
c->Nl=0;
c->Nh=0;
c->num=0;
return 1;
}
#ifndef md5_block_host_order

View File

@ -81,9 +81,9 @@ typedef struct mdc2_ctx_st
} MDC2_CTX;
void MDC2_Init(MDC2_CTX *c);
void MDC2_Update(MDC2_CTX *c, const unsigned char *data, unsigned long len);
void MDC2_Final(unsigned char *md, MDC2_CTX *c);
int MDC2_Init(MDC2_CTX *c);
int MDC2_Update(MDC2_CTX *c, const unsigned char *data, unsigned long len);
int MDC2_Final(unsigned char *md, MDC2_CTX *c);
unsigned char *MDC2(const unsigned char *d, unsigned long n,
unsigned char *md);

View File

@ -75,15 +75,16 @@
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
static void mdc2_body(MDC2_CTX *c, const unsigned char *in, unsigned int len);
void MDC2_Init(MDC2_CTX *c)
int MDC2_Init(MDC2_CTX *c)
{
c->num=0;
c->pad_type=1;
memset(&(c->h[0]),0x52,MDC2_BLOCK);
memset(&(c->hh[0]),0x25,MDC2_BLOCK);
return 1;
}
void MDC2_Update(MDC2_CTX *c, const unsigned char *in, unsigned long len)
int MDC2_Update(MDC2_CTX *c, const unsigned char *in, unsigned long len)
{
int i,j;
@ -95,7 +96,7 @@ void MDC2_Update(MDC2_CTX *c, const unsigned char *in, unsigned long len)
/* partial block */
memcpy(&(c->data[i]),in,(int)len);
c->num+=(int)len;
return;
return 1;
}
else
{
@ -116,6 +117,7 @@ void MDC2_Update(MDC2_CTX *c, const unsigned char *in, unsigned long len)
memcpy(&(c->data[0]),&(in[i]),j);
c->num=j;
}
return 1;
}
static void mdc2_body(MDC2_CTX *c, const unsigned char *in, unsigned int len)
@ -156,7 +158,7 @@ static void mdc2_body(MDC2_CTX *c, const unsigned char *in, unsigned int len)
}
}
void MDC2_Final(unsigned char *md, MDC2_CTX *c)
int MDC2_Final(unsigned char *md, MDC2_CTX *c)
{
int i,j;
@ -171,6 +173,7 @@ void MDC2_Final(unsigned char *md, MDC2_CTX *c)
}
memcpy(md,(char *)c->h,MDC2_BLOCK);
memcpy(&(md[MDC2_BLOCK]),(char *)c->hh,MDC2_BLOCK);
return 1;
}
#undef TEST

View File

@ -90,9 +90,9 @@ typedef struct RIPEMD160state_st
int num;
} RIPEMD160_CTX;
void RIPEMD160_Init(RIPEMD160_CTX *c);
void RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
int RIPEMD160_Init(RIPEMD160_CTX *c);
int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
unsigned char *md);
void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);

View File

@ -69,7 +69,7 @@ const char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
# endif
void RIPEMD160_Init(RIPEMD160_CTX *c)
int RIPEMD160_Init(RIPEMD160_CTX *c)
{
c->A=RIPEMD160_A;
c->B=RIPEMD160_B;
@ -79,6 +79,7 @@ void RIPEMD160_Init(RIPEMD160_CTX *c)
c->Nl=0;
c->Nh=0;
c->num=0;
return 1;
}
#ifndef ripemd160_block_host_order

View File

@ -101,16 +101,16 @@ typedef struct SHAstate_st
} SHA_CTX;
#ifndef OPENSSL_NO_SHA0
void SHA_Init(SHA_CTX *c);
void SHA_Update(SHA_CTX *c, const void *data, unsigned long len);
void SHA_Final(unsigned char *md, SHA_CTX *c);
int SHA_Init(SHA_CTX *c);
int SHA_Update(SHA_CTX *c, const void *data, unsigned long len);
int SHA_Final(unsigned char *md, SHA_CTX *c);
unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
void SHA_Transform(SHA_CTX *c, const unsigned char *data);
#endif
#ifndef OPENSSL_NO_SHA1
void SHA1_Init(SHA_CTX *c);
void SHA1_Update(SHA_CTX *c, const void *data, unsigned long len);
void SHA1_Final(unsigned char *md, SHA_CTX *c);
int SHA1_Init(SHA_CTX *c);
int SHA1_Update(SHA_CTX *c, const void *data, unsigned long len);
int SHA1_Final(unsigned char *md, SHA_CTX *c);
unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
#endif

View File

@ -138,7 +138,7 @@
#define INIT_DATA_h3 0x10325476UL
#define INIT_DATA_h4 0xc3d2e1f0UL
void HASH_INIT (SHA_CTX *c)
int HASH_INIT (SHA_CTX *c)
{
c->h0=INIT_DATA_h0;
c->h1=INIT_DATA_h1;
@ -148,6 +148,7 @@ void HASH_INIT (SHA_CTX *c)
c->Nl=0;
c->Nh=0;
c->num=0;
return 1;
}
#define K_00_19 0x5a827999UL