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.
This commit is contained in:
Brad King 2011-11-17 11:07:43 -05:00
parent 1ec3fa00c9
commit 24b1feb5ca
1 changed files with 6 additions and 6 deletions

View File

@ -652,7 +652,7 @@ void SHA1_Update(SHA_CTX* context, const sha_byte *data, size_t len) {
/* Sanity check: */ /* Sanity check: */
assert(context != (SHA_CTX*)0 && data != (sha_byte*)0); 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) { if (usedspace > 0) {
/* Calculate how much free space is available in the buffer */ /* Calculate how much free space is available in the buffer */
freespace = 64 - usedspace; freespace = 64 - usedspace;
@ -705,7 +705,7 @@ void SHA1_Final(sha_byte digest[], SHA_CTX* context) {
return; return;
} }
usedspace = (context->s1.bitcount >> 3) % 64; usedspace = (unsigned int)((context->s1.bitcount >> 3) % 64);
if (usedspace == 0) { if (usedspace == 0) {
/* Set-up for the last transform: */ /* Set-up for the last transform: */
MEMSET_BZERO(context->s1.buffer, 56); 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: */ /* Sanity check: */
assert(context != (SHA_CTX*)0 && data != (sha_byte*)0); 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) { if (usedspace > 0) {
/* Calculate how much free space is available in the buffer */ /* Calculate how much free space is available in the buffer */
freespace = 64 - usedspace; 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) { void SHA256_Internal_Last(SHA_CTX* context) {
unsigned int usedspace; unsigned int usedspace;
usedspace = (context->s256.bitcount >> 3) % 64; usedspace = (unsigned int)((context->s256.bitcount >> 3) % 64);
#if BYTE_ORDER == LITTLE_ENDIAN #if BYTE_ORDER == LITTLE_ENDIAN
/* Convert FROM host byte order */ /* Convert FROM host byte order */
REVERSE64(context->s256.bitcount,context->s256.bitcount); 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: */ /* Sanity check: */
assert(context != (SHA_CTX*)0 && data != (sha_byte*)0); 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) { if (usedspace > 0) {
/* Calculate how much free space is available in the buffer */ /* Calculate how much free space is available in the buffer */
freespace = 128 - usedspace; 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) { void SHA512_Internal_Last(SHA_CTX* context) {
unsigned int usedspace; unsigned int usedspace;
usedspace = (context->s512.bitcount[0] >> 3) % 128; usedspace = (unsigned int)((context->s512.bitcount[0] >> 3) % 128);
#if BYTE_ORDER == LITTLE_ENDIAN #if BYTE_ORDER == LITTLE_ENDIAN
/* Convert FROM host byte order */ /* Convert FROM host byte order */
REVERSE64(context->s512.bitcount[0],context->s512.bitcount[0]); REVERSE64(context->s512.bitcount[0],context->s512.bitcount[0]);