From 2dc769a1c17e1e0c7aef6e11496c8ba2c1db2e28 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Thu, 8 Mar 2001 14:04:22 +0000 Subject: [PATCH] Make EVP_Digest*() routines return a value. TODO: update docs, and make soe other routines which use EVP_Digest*() check return codes. --- CHANGES | 5 +++++ crypto/evp/digest.c | 23 +++++++++++++---------- crypto/evp/evp.h | 12 ++++++------ crypto/evp/m_null.c | 3 ++- crypto/md2/md2.h | 6 +++--- crypto/md2/md2_dgst.c | 13 ++++++++----- crypto/md32_common.h | 10 ++++++---- crypto/md4/md4.h | 6 +++--- crypto/md4/md4_dgst.c | 3 ++- crypto/md5/md5.h | 6 +++--- crypto/md5/md5_dgst.c | 3 ++- crypto/mdc2/mdc2.h | 6 +++--- crypto/mdc2/mdc2dgst.c | 11 +++++++---- crypto/ripemd/ripemd.h | 6 +++--- crypto/ripemd/rmd_dgst.c | 3 ++- crypto/sha/sha.h | 12 ++++++------ crypto/sha/sha_locl.h | 3 ++- 17 files changed, 76 insertions(+), 55 deletions(-) diff --git a/CHANGES b/CHANGES index 36acb79f03..d52d19f0a8 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 5c75a347b8..ad69bfdedd 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -61,24 +61,26 @@ #include #include -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); } diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h index 42462d7f8c..100726ded6 100644 --- a/crypto/evp/evp.h +++ b/crypto/evp/evp.h @@ -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); diff --git a/crypto/evp/m_null.c b/crypto/evp/m_null.c index e2dadf3dab..9001b3d8c6 100644 --- a/crypto/evp/m_null.c +++ b/crypto/evp/m_null.c @@ -62,8 +62,9 @@ #include #include -static void function(void) +static int function(void) { + return 1; } static EVP_MD null_md= diff --git a/crypto/md2/md2.h b/crypto/md2/md2.h index 5494afd6d8..ad9241455c 100644 --- a/crypto/md2/md2.h +++ b/crypto/md2/md2.h @@ -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 } diff --git a/crypto/md2/md2_dgst.c b/crypto/md2/md2_dgst.c index 608baefa8f..e25dd00e02 100644 --- a/crypto/md2/md2_dgst.c +++ b/crypto/md2/md2_dgst.c @@ -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; } diff --git a/crypto/md32_common.h b/crypto/md32_common.h index e028376fbe..c169c9fe5d 100644 --- a/crypto/md32_common.h +++ b/crypto/md32_common.h @@ -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; } diff --git a/crypto/md4/md4.h b/crypto/md4/md4.h index 8a9326d994..7a7b23682f 100644 --- a/crypto/md4/md4.h +++ b/crypto/md4/md4.h @@ -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 diff --git a/crypto/md4/md4_dgst.c b/crypto/md4/md4_dgst.c index 81488ae2e2..6446f5f5e7 100644 --- a/crypto/md4/md4_dgst.c +++ b/crypto/md4/md4_dgst.c @@ -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 diff --git a/crypto/md5/md5.h b/crypto/md5/md5.h index c08d509861..52cb753e6a 100644 --- a/crypto/md5/md5.h +++ b/crypto/md5/md5.h @@ -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 diff --git a/crypto/md5/md5_dgst.c b/crypto/md5/md5_dgst.c index 23d196b8d4..c38a3f021e 100644 --- a/crypto/md5/md5_dgst.c +++ b/crypto/md5/md5_dgst.c @@ -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 diff --git a/crypto/mdc2/mdc2.h b/crypto/mdc2/mdc2.h index a23f58afaf..c4a81831bf 100644 --- a/crypto/mdc2/mdc2.h +++ b/crypto/mdc2/mdc2.h @@ -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); diff --git a/crypto/mdc2/mdc2dgst.c b/crypto/mdc2/mdc2dgst.c index c630a24c2e..3a873d147a 100644 --- a/crypto/mdc2/mdc2dgst.c +++ b/crypto/mdc2/mdc2dgst.c @@ -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 diff --git a/crypto/ripemd/ripemd.h b/crypto/ripemd/ripemd.h index 67a94555f7..78d5f36560 100644 --- a/crypto/ripemd/ripemd.h +++ b/crypto/ripemd/ripemd.h @@ -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); diff --git a/crypto/ripemd/rmd_dgst.c b/crypto/ripemd/rmd_dgst.c index bdfae270b6..a3170f7c8a 100644 --- a/crypto/ripemd/rmd_dgst.c +++ b/crypto/ripemd/rmd_dgst.c @@ -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 diff --git a/crypto/sha/sha.h b/crypto/sha/sha.h index b75194319a..3fd54a10cc 100644 --- a/crypto/sha/sha.h +++ b/crypto/sha/sha.h @@ -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 diff --git a/crypto/sha/sha_locl.h b/crypto/sha/sha_locl.h index 2f8aef83f3..36d3ec2616 100644 --- a/crypto/sha/sha_locl.h +++ b/crypto/sha/sha_locl.h @@ -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 -- 2.25.1