From 24b1feb5ca9dbc3461d373e4de30a33157f81375 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Nov 2011 11:07:43 -0500 Subject: sha2: Cast safe conversions to smaller integer types Add a cast to lines converting "uint64_t" to "unsigned int" that are known safe due to use of modulus with a small integer. This avoids compiler warnings such as conversion from 'cm_sha2_uint64_t' to 'unsigned int', possible loss of data from MSVC. --- Source/cm_sha2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/cm_sha2.c b/Source/cm_sha2.c index b89f8fe..7991d27 100644 --- a/Source/cm_sha2.c +++ b/Source/cm_sha2.c @@ -652,7 +652,7 @@ void SHA1_Update(SHA_CTX* context, const sha_byte *data, size_t len) { /* Sanity check: */ assert(context != (SHA_CTX*)0 && data != (sha_byte*)0); - usedspace = (context->s1.bitcount >> 3) % 64; + usedspace = (unsigned int)((context->s1.bitcount >> 3) % 64); if (usedspace > 0) { /* Calculate how much free space is available in the buffer */ freespace = 64 - usedspace; @@ -705,7 +705,7 @@ void SHA1_Final(sha_byte digest[], SHA_CTX* context) { return; } - usedspace = (context->s1.bitcount >> 3) % 64; + usedspace = (unsigned int)((context->s1.bitcount >> 3) % 64); if (usedspace == 0) { /* Set-up for the last transform: */ MEMSET_BZERO(context->s1.buffer, 56); @@ -992,7 +992,7 @@ void SHA256_Update(SHA_CTX* context, const sha_byte *data, size_t len) { /* Sanity check: */ assert(context != (SHA_CTX*)0 && data != (sha_byte*)0); - usedspace = (context->s256.bitcount >> 3) % 64; + usedspace = (unsigned int)((context->s256.bitcount >> 3) % 64); if (usedspace > 0) { /* Calculate how much free space is available in the buffer */ freespace = 64 - usedspace; @@ -1032,7 +1032,7 @@ void SHA256_Update(SHA_CTX* context, const sha_byte *data, size_t len) { void SHA256_Internal_Last(SHA_CTX* context) { unsigned int usedspace; - usedspace = (context->s256.bitcount >> 3) % 64; + usedspace = (unsigned int)((context->s256.bitcount >> 3) % 64); #if BYTE_ORDER == LITTLE_ENDIAN /* Convert FROM host byte order */ REVERSE64(context->s256.bitcount,context->s256.bitcount); @@ -1399,7 +1399,7 @@ void SHA512_Update(SHA_CTX* context, const sha_byte *data, size_t len) { /* Sanity check: */ assert(context != (SHA_CTX*)0 && data != (sha_byte*)0); - usedspace = (context->s512.bitcount[0] >> 3) % 128; + usedspace = (unsigned int)((context->s512.bitcount[0] >> 3) % 128); if (usedspace > 0) { /* Calculate how much free space is available in the buffer */ freespace = 128 - usedspace; @@ -1439,7 +1439,7 @@ void SHA512_Update(SHA_CTX* context, const sha_byte *data, size_t len) { void SHA512_Internal_Last(SHA_CTX* context) { unsigned int usedspace; - usedspace = (context->s512.bitcount[0] >> 3) % 128; + usedspace = (unsigned int)((context->s512.bitcount[0] >> 3) % 128); #if BYTE_ORDER == LITTLE_ENDIAN /* Convert FROM host byte order */ REVERSE64(context->s512.bitcount[0],context->s512.bitcount[0]); -- cgit v0.12