diff options
author | David Benjamin <davidben@chromium.org> | 2015-05-27 08:00:07 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-06-02 01:12:21 +0300 |
commit | 049756be467500458e63bf274e94ed2c23b4d513 (patch) | |
tree | 2e17f81e9844317b18d5400c2cde6b7206f872b6 /crypto/digest | |
parent | 338e06771c600108ba8b1e3df6a15a8920961c37 (diff) |
Fix integer types in low-level hash functions.
Use sized integer types rather than unsigned char/int/long. The latter
two are especially a mess as they're both used in lieu of uint32_t.
Sometimes the code just blindly uses unsigned long and sometimes it uses
unsigned int when an LP64 architecture would notice.
Change-Id: I4c5c6aaf82cfe9fe523435588d286726a7c43056
Reviewed-on: https://boringssl-review.googlesource.com/4952
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/digest')
-rw-r--r-- | crypto/digest/digests.c | 16 | ||||
-rw-r--r-- | crypto/digest/md32_common.h | 78 |
2 files changed, 45 insertions, 49 deletions
diff --git a/crypto/digest/digests.c b/crypto/digest/digests.c index ac00ed34..b0036af1 100644 --- a/crypto/digest/digests.c +++ b/crypto/digest/digests.c @@ -70,7 +70,7 @@ static int md4_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return MD4_Update(ctx->md_data, data, count); } -static int md4_final(EVP_MD_CTX *ctx, unsigned char *out) { +static int md4_final(EVP_MD_CTX *ctx, uint8_t *out) { return MD4_Final(out, ctx->md_data); } @@ -88,7 +88,7 @@ static int md5_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return MD5_Update(ctx->md_data, data, count); } -static int md5_final(EVP_MD_CTX *ctx, unsigned char *out) { +static int md5_final(EVP_MD_CTX *ctx, uint8_t *out) { return MD5_Final(out, ctx->md_data); } @@ -106,7 +106,7 @@ static int sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return SHA1_Update(ctx->md_data, data, count); } -static int sha1_final(EVP_MD_CTX *ctx, unsigned char *md) { +static int sha1_final(EVP_MD_CTX *ctx, uint8_t *md) { return SHA1_Final(md, ctx->md_data); } @@ -124,7 +124,7 @@ static int sha224_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return SHA224_Update(ctx->md_data, data, count); } -static int sha224_final(EVP_MD_CTX *ctx, unsigned char *md) { +static int sha224_final(EVP_MD_CTX *ctx, uint8_t *md) { return SHA224_Final(md, ctx->md_data); } @@ -143,7 +143,7 @@ static int sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return SHA256_Update(ctx->md_data, data, count); } -static int sha256_final(EVP_MD_CTX *ctx, unsigned char *md) { +static int sha256_final(EVP_MD_CTX *ctx, uint8_t *md) { return SHA256_Final(md, ctx->md_data); } @@ -162,7 +162,7 @@ static int sha384_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return SHA384_Update(ctx->md_data, data, count); } -static int sha384_final(EVP_MD_CTX *ctx, unsigned char *md) { +static int sha384_final(EVP_MD_CTX *ctx, uint8_t *md) { return SHA384_Final(md, ctx->md_data); } @@ -181,7 +181,7 @@ static int sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return SHA512_Update(ctx->md_data, data, count); } -static int sha512_final(EVP_MD_CTX *ctx, unsigned char *md) { +static int sha512_final(EVP_MD_CTX *ctx, uint8_t *md) { return SHA512_Final(md, ctx->md_data); } @@ -209,7 +209,7 @@ static int md5_sha1_update(EVP_MD_CTX *md_ctx, const void *data, size_t count) { return MD5_Update(&ctx->md5, data, count) && SHA1_Update(&ctx->sha1, data, count); } -static int md5_sha1_final(EVP_MD_CTX *md_ctx, unsigned char *out) { +static int md5_sha1_final(EVP_MD_CTX *md_ctx, uint8_t *out) { MD5_SHA1_CTX *ctx = md_ctx->md_data; if (!MD5_Final(out, &ctx->md5) || !SHA1_Final(out + MD5_DIGEST_LENGTH, &ctx->sha1)) { diff --git a/crypto/digest/md32_common.h b/crypto/digest/md32_common.h index d7caba27..14607fba 100644 --- a/crypto/digest/md32_common.h +++ b/crypto/digest/md32_common.h @@ -147,11 +147,11 @@ extern "C" { * <appro@fy.chalmers.se> */ # if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) -# define ROTATE(a,n) ({ register unsigned int ret; \ +# define ROTATE(a,n) ({ register uint32_t ret; \ asm ( \ "roll %1,%0" \ : "=r"(ret) \ - : "I"(n), "0"((unsigned int)(a)) \ + : "I"(n), "0"((uint32_t)(a)) \ : "cc"); \ ret; \ }) @@ -173,28 +173,28 @@ extern "C" { * this trick on x86* platforms only, because these CPUs can fetch * unaligned data without raising an exception. */ -# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \ +# define HOST_c2l(c,l) ({ uint32_t r=*((const uint32_t *)(c)); \ asm ("bswapl %0":"=r"(r):"0"(r)); \ (c)+=4; (l)=r; }) -# define HOST_l2c(l,c) ({ unsigned int r=(l); \ +# define HOST_l2c(l,c) ({ uint32_t r=(l); \ asm ("bswapl %0":"=r"(r):"0"(r)); \ - *((unsigned int *)(c))=r; (c)+=4; r; }) + *((uint32_t *)(c))=r; (c)+=4; r; }) # elif defined(__aarch64__) # if defined(__BYTE_ORDER__) # if defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__ -# define HOST_c2l(c,l) ({ unsigned int r; \ +# define HOST_c2l(c,l) ({ uint32_t r; \ asm ("rev %w0,%w1" \ :"=r"(r) \ - :"r"(*((const unsigned int *)(c))));\ + :"r"(*((const uint32_t *)(c))));\ (c)+=4; (l)=r; }) -# define HOST_l2c(l,c) ({ unsigned int r; \ +# define HOST_l2c(l,c) ({ uint32_t r; \ asm ("rev %w0,%w1" \ :"=r"(r) \ - :"r"((unsigned int)(l)));\ - *((unsigned int *)(c))=r; (c)+=4; r; }) + :"r"((uint32_t)(l))); \ + *((uint32_t *)(c))=r; (c)+=4; r; }) # elif defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ -# define HOST_c2l(c,l) (void)((l)=*((const unsigned int *)(c)), (c)+=4) -# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, (l)) +# define HOST_c2l(c,l) (void)((l)=*((const uint32_t *)(c)), (c)+=4) +# define HOST_l2c(l,c) (*((uint32_t *)(c))=(l), (c)+=4, (l)) # endif # endif # endif @@ -202,16 +202,16 @@ extern "C" { #endif #ifndef HOST_c2l -#define HOST_c2l(c,l) (void)(l =(((unsigned long)(*((c)++)))<<24), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++))) )) +#define HOST_c2l(c,l) (void)(l =(((uint32_t)(*((c)++)))<<24), \ + l|=(((uint32_t)(*((c)++)))<<16), \ + l|=(((uint32_t)(*((c)++)))<< 8), \ + l|=(((uint32_t)(*((c)++))) )) #endif #ifndef HOST_l2c -#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l) )&0xff), \ +#define HOST_l2c(l,c) (*((c)++)=(uint8_t)(((l)>>24)&0xff), \ + *((c)++)=(uint8_t)(((l)>>16)&0xff), \ + *((c)++)=(uint8_t)(((l)>> 8)&0xff), \ + *((c)++)=(uint8_t)(((l) )&0xff), \ l) #endif @@ -219,21 +219,21 @@ extern "C" { #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) /* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */ -# define HOST_c2l(c,l) (void)((l)=*((const unsigned int *)(c)), (c)+=4) -# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, l) +# define HOST_c2l(c,l) (void)((l)=*((const uint32_t *)(c)), (c)+=4) +# define HOST_l2c(l,c) (*((uint32_t *)(c))=(l), (c)+=4, l) #endif #ifndef HOST_c2l -#define HOST_c2l(c,l) (void)(l =(((unsigned long)(*((c)++))) ), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<<24)) +#define HOST_c2l(c,l) (void)(l =(((uint32_t)(*((c)++))) ), \ + l|=(((uint32_t)(*((c)++)))<< 8), \ + l|=(((uint32_t)(*((c)++)))<<16), \ + l|=(((uint32_t)(*((c)++)))<<24)) #endif #ifndef HOST_l2c -#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24)&0xff), \ +#define HOST_l2c(l,c) (*((c)++)=(uint8_t)(((l) )&0xff), \ + *((c)++)=(uint8_t)(((l)>> 8)&0xff), \ + *((c)++)=(uint8_t)(((l)>>16)&0xff), \ + *((c)++)=(uint8_t)(((l)>>24)&0xff), \ l) #endif @@ -241,8 +241,8 @@ extern "C" { int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len) { - const unsigned char *data=data_; - unsigned char *p; + const uint8_t *data=data_; + uint8_t *p; HASH_LONG l; size_t n; @@ -259,7 +259,7 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len) n = c->num; if (n != 0) { - p=(unsigned char *)c->data; + p=(uint8_t *)c->data; if (len >= HASH_CBLOCK || len+n >= HASH_CBLOCK) { @@ -290,7 +290,7 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len) if (len != 0) { - p = (unsigned char *)c->data; + p = (uint8_t *)c->data; c->num = (unsigned int)len; memcpy (p,data,len); } @@ -298,15 +298,15 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len) } -void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) +void HASH_TRANSFORM (HASH_CTX *c, const uint8_t *data) { HASH_BLOCK_DATA_ORDER (c,data,1); } -int HASH_FINAL (unsigned char *md, HASH_CTX *c) +int HASH_FINAL (uint8_t *md, HASH_CTX *c) { - unsigned char *p = (unsigned char *)c->data; + uint8_t *p = (uint8_t *)c->data; size_t n = c->num; p[n] = 0x80; /* there is always room for one */ @@ -342,10 +342,6 @@ int HASH_FINAL (unsigned char *md, HASH_CTX *c) return 1; } -#ifndef MD32_REG_T -#define MD32_REG_T int -#endif - #if defined(__cplusplus) } /* extern C */ |