Fix "possible loss of data" Win64 compiler warnings.
authorAndy Polyakov <appro@openssl.org>
Mon, 29 Dec 2008 12:35:49 +0000 (12:35 +0000)
committerAndy Polyakov <appro@openssl.org>
Mon, 29 Dec 2008 12:35:49 +0000 (12:35 +0000)
crypto/bn/bn_lib.c
crypto/bn/bn_nist.c
crypto/dso/dso_win32.c
crypto/evp/e_des.c
crypto/evp/e_des3.c
crypto/md32_common.h
crypto/modes/cfb128.c
crypto/rc4/rc4_enc.c
crypto/sha/sha512.c
crypto/whrlpool/wp_dgst.c

index 0c6e7e59644c6cd17f5d65263fd0c91940ac1938..2564c332b376cdde4b486e3f2a95c12918bdcc0f 100644 (file)
@@ -763,7 +763,7 @@ int BN_is_bit_set(const BIGNUM *a, int n)
        i=n/BN_BITS2;
        j=n%BN_BITS2;
        if (a->top <= i) return 0;
-       return(((a->d[i])>>j)&((BN_ULONG)1));
+       return(((a->d[i])>>j)&((BN_ULONG)1)==1);
        }
 
 int BN_mask_bits(BIGNUM *a, int n)
index ea991c95b1ceb37249ddd3c3b336d2fc1cba3018..2ca5b0139111f76352b3d2c08ba6232056efb942 100644 (file)
@@ -388,14 +388,14 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        nist_cp_bn_0(buf, a_d + BN_NIST_192_TOP, top - BN_NIST_192_TOP, BN_NIST_192_TOP);
 
        nist_set_192(t_d, buf, 0, 3, 3);
-       carry = bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
+       carry = (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
        nist_set_192(t_d, buf, 4, 4, 0);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
        nist_set_192(t_d, buf, 5, 5, 5)
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP);
 
        if (carry > 0)
-               carry = bn_sub_words(r_d,r_d,_nist_p_192[carry-1],BN_NIST_192_TOP);
+               carry = (int)bn_sub_words(r_d,r_d,_nist_p_192[carry-1],BN_NIST_192_TOP);
        else
                carry = 1;
 
@@ -482,13 +482,13 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        nist_cp_bn_0(buf, a_d + BN_NIST_224_TOP, top - BN_NIST_224_TOP, BN_NIST_224_TOP);
 #endif
        nist_set_224(t_d, buf, 10, 9, 8, 7, 0, 0, 0);
-       carry = bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
+       carry = (int)bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
        nist_set_224(t_d, buf, 0, 13, 12, 11, 0, 0, 0);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP);
        nist_set_224(t_d, buf, 13, 12, 11, 10, 9, 8, 7);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);
        nist_set_224(t_d, buf, 0, 0, 0, 0, 13, 12, 11);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP);
 
 #if BN_BITS2==64
        carry = (int)(r_d[BN_NIST_224_TOP-1]>>32);
@@ -496,7 +496,7 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        u.f = bn_sub_words;
        if (carry > 0)
                {
-               carry = bn_sub_words(r_d,r_d,_nist_p_224[carry-1],BN_NIST_224_TOP);
+               carry = (int)bn_sub_words(r_d,r_d,_nist_p_224[carry-1],BN_NIST_224_TOP);
 #if BN_BITS2==64
                carry=(int)(~(r_d[BN_NIST_224_TOP-1]>>32))&1;
 #endif
@@ -509,7 +509,7 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                 * the modulus. but if it does, then result has
                 * to be compared to the modulus and conditionally
                 * adjusted by *subtracting* the latter. */
-               carry = bn_add_words(r_d,r_d,_nist_p_224[-carry-1],BN_NIST_224_TOP);
+               carry = (int)bn_add_words(r_d,r_d,_nist_p_224[-carry-1],BN_NIST_224_TOP);
                mask = 0-(size_t)carry;
                u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
                }
@@ -587,7 +587,7 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
        nist_set_256(t_d, buf, 15, 14, 13, 12, 11, 0, 0, 0);
        /*S2*/
        nist_set_256(c_d, buf, 0, 15, 14, 13, 12, 0, 0, 0);
-       carry = bn_add_words(t_d, t_d, c_d, BN_NIST_256_TOP);
+       carry = (int)bn_add_words(t_d, t_d, c_d, BN_NIST_256_TOP);
        /* left shift */
                {
                register BN_ULONG *ap,t,c;
@@ -602,33 +602,33 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                carry <<= 1;
                carry  |= c;
                }
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
        /*S3*/
        nist_set_256(t_d, buf, 15, 14, 0, 0, 0, 10, 9, 8);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
        /*S4*/
        nist_set_256(t_d, buf, 8, 13, 15, 14, 13, 11, 10, 9);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP);
        /*D1*/
        nist_set_256(t_d, buf, 10, 8, 0, 0, 0, 13, 12, 11);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
        /*D2*/
        nist_set_256(t_d, buf, 11, 9, 0, 0, 15, 14, 13, 12);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
        /*D3*/
        nist_set_256(t_d, buf, 12, 0, 10, 9, 8, 15, 14, 13);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
        /*D4*/
        nist_set_256(t_d, buf, 13, 0, 11, 10, 9, 0, 15, 14);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP);
 
        /* see BN_nist_mod_224 for explanation */
        u.f = bn_sub_words;
        if (carry > 0)
-               carry = bn_sub_words(r_d,r_d,_nist_p_256[carry-1],BN_NIST_256_TOP);
+               carry = (int)bn_sub_words(r_d,r_d,_nist_p_256[carry-1],BN_NIST_256_TOP);
        else if (carry < 0)
                {
-               carry = bn_add_words(r_d,r_d,_nist_p_256[-carry-1],BN_NIST_256_TOP);
+               carry = (int)bn_add_words(r_d,r_d,_nist_p_256[-carry-1],BN_NIST_256_TOP);
                mask = 0-(size_t)carry;
                u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
                }
@@ -721,39 +721,39 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
                        }
                *ap=c;
                }
-       carry = bn_add_words(r_d+(128/BN_BITS2), r_d+(128/BN_BITS2), 
+       carry = (int)bn_add_words(r_d+(128/BN_BITS2), r_d+(128/BN_BITS2), 
                t_d, BN_NIST_256_TOP);
        /*S2 */
-       carry += bn_add_words(r_d, r_d, buf, BN_NIST_384_TOP);
+       carry += (int)bn_add_words(r_d, r_d, buf, BN_NIST_384_TOP);
        /*S3*/
        nist_set_384(t_d,buf,20,19,18,17,16,15,14,13,12,23,22,21);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
        /*S4*/
        nist_set_384(t_d,buf,19,18,17,16,15,14,13,12,20,0,23,0);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
        /*S5*/
        nist_set_384(t_d, buf,0,0,0,0,23,22,21,20,0,0,0,0);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
        /*S6*/
        nist_set_384(t_d,buf,0,0,0,0,0,0,23,22,21,0,0,20);
-       carry += bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
+       carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);
        /*D1*/
        nist_set_384(t_d,buf,22,21,20,19,18,17,16,15,14,13,12,23);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
        /*D2*/
        nist_set_384(t_d,buf,0,0,0,0,0,0,0,23,22,21,20,0);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
        /*D3*/
        nist_set_384(t_d,buf,0,0,0,0,0,0,0,23,23,0,0,0);
-       carry -= bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
+       carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);
 
        /* see BN_nist_mod_224 for explanation */
        u.f = bn_sub_words;
        if (carry > 0)
-               carry = bn_sub_words(r_d,r_d,_nist_p_384[carry-1],BN_NIST_384_TOP);
+               carry = (int)bn_sub_words(r_d,r_d,_nist_p_384[carry-1],BN_NIST_384_TOP);
        else if (carry < 0)
                {
-               carry = bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP);
+               carry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP);
                mask = 0-(size_t)carry;
                u.p = ((size_t)bn_sub_words&mask) | ((size_t)bn_add_words&~mask);
                }
index b8693c13e54a3029325c9faf49e6804b76422c5f..c5b00c0d131639dfd3cfb51f08d5ec9efc190e07 100644 (file)
@@ -358,7 +358,7 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                                return(NULL);
                                }
                        result->device = start;
-                       result->devicelen = filename - start;
+                       result->devicelen = (int)(filename - start);
                        position = IN_FILE;
                        start = ++filename;
                        result->dir = start;
@@ -367,7 +367,7 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                case '/':
                        if(position == IN_NODE)
                                {
-                               result->nodelen = filename - start;
+                               result->nodelen = (int)(filename - start);
                                position = IN_FILE;
                                start = ++filename;
                                result->dir = start;
@@ -377,20 +377,20 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                                position = IN_FILE;
                                filename++;
                                result->dir = start;
-                               result->dirlen = filename - start;
+                               result->dirlen = (int)(filename - start);
                                start = filename;
                                }
                        else
                                {
                                filename++;
-                               result->dirlen += filename - start;
+                               result->dirlen += (int)(filename - start);
                                start = filename;
                                }
                        break;
                case '\0':
                        if(position == IN_NODE)
                                {
-                               result->nodelen = filename - start;
+                               result->nodelen = (int)(filename - start);
                                }
                        else
                                {
@@ -404,13 +404,13 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
                                                        result->dirlen = 0;
                                                        }
                                                result->dirlen +=
-                                                       filename - start;
+                                                       (int)(filename - start);
                                                }
                                        else
                                                {
                                                result->file = start;
                                                result->filelen =
-                                                       filename - start;
+                                                       (int)(filename - start);
                                                }
                                        }
                                }
@@ -504,7 +504,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split)
                                + file_split->predirlen
                                - (start - file_split->predir);
                strncpy(&result[offset], start,
-                       end - start); offset += end - start;
+                       end - start); offset += (int)(end - start);
                result[offset] = '\\'; offset++;
                start = end + 1;
                }
@@ -525,7 +525,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split)
                                + file_split->dirlen
                                - (start - file_split->dir);
                strncpy(&result[offset], start,
-                       end - start); offset += end - start;
+                       end - start); offset += (int)(end - start);
                result[offset] = '\\'; offset++;
                start = end + 1;
                }
index 1e4230493b0c7b1fbb3602d33832fcc3458daa8a..ca009f2c5250ebda012f5ef8ceaa52ccd7388777 100644 (file)
@@ -147,7 +147,8 @@ static int des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
            c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
            DES_cfb_encrypt(c,d,1,1,ctx->cipher_data,(DES_cblock *)ctx->iv,
                        ctx->encrypt);
-           out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
+           out[n/8]=(out[n/8]&~(0x80 >> (unsigned int)(n%8))) |
+                    ((d[0]&0x80) >> (unsigned int)(n%8));
            }
        inl-=chunk;
        in +=chunk;
index 059ad77118c22858b4150b64f201a5105aedba2a..3232cfe024b2b3d671c431537bf669fe78cf4c17 100644 (file)
@@ -179,7 +179,8 @@ static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
        DES_ede3_cfb_encrypt(c,d,1,1,
                             &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
                             (DES_cblock *)ctx->iv,ctx->encrypt);
-       out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
+       out[n/8]=(out[n/8]&~(0x80 >> (unsigned int)(n%8))) |
+                ((d[0]&0x80) >> (unsigned int)(n%8));
        }
 
     return 1;
index 61bcd9786f8679668d706b78c0691a0d3c51f1d6..279916fa5902b918543f63540aa1315ad992354f 100644 (file)
@@ -293,7 +293,7 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len)
         * Wei Dai <weidai@eskimo.com> for pointing it out. */
        if (l < c->Nl) /* overflow */
                c->Nh++;
-       c->Nh+=(len>>29);       /* might cause compiler warning on 16-bit */
+       c->Nh+=(HASH_LONG)(len>>29);    /* might cause compiler warning on 16-bit */
        c->Nl=l;
 
        n = c->num;
@@ -331,7 +331,7 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len)
        if (len != 0)
                {
                p = (unsigned char *)c->data;
-               c->num = len;
+               c->num = (unsigned int)len;
                memcpy (p,data,len);
                }
        return 1;
index 9ba498471877199983de9add3001896b4ebb34f5..b6d1e886b9c38592485db56894c52e59e98d60b6 100644 (file)
@@ -229,7 +229,8 @@ void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
        {
        c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
        cfbr_encrypt_block(c,d,1,key,ivec,enc,block);
-       out[n/8]=(out[n/8]&~(1 << (7-n%8)))|((d[0]&0x80) >> (n%8));
+       out[n/8]=(out[n/8]&~(1 << (unsigned int)(7-n%8))) |
+                ((d[0]&0x80) >> (unsigned int)(n%8));
        }
 }
 
index 37ef43c16ca3256e1eda0940363ddabbf6214140..8c4fc6c7a3da38451da27f8b429ef340d2684a40 100644 (file)
@@ -157,7 +157,7 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
                if (!is_endian.little)
                        {       /* BIG-ENDIAN CASE */
 # define BESHFT(c)     (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
-                       for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
+                       for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
                                {
                                ichunk  = *(RC4_CHUNK *)indata;
                                otp  = RC4_STEP<<BESHFT(0);
@@ -210,7 +210,7 @@ void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
                else
                        {       /* LITTLE-ENDIAN CASE */
 # define LESHFT(c)     (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
-                       for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
+                       for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
                                {
                                ichunk  = *(RC4_CHUNK *)indata;
                                otp  = RC4_STEP;
index 832cae24f186bb9f6b66bd24fdff54f6612fb4c9..d1aa7614b2f6bab444b0cd4d98c23330b82aaf68 100644 (file)
@@ -240,7 +240,7 @@ int SHA512_Update (SHA512_CTX *c, const void *_data, size_t len)
 
                if (len < n)
                        {
-                       memcpy (p+c->num,data,len), c->num += len;
+                       memcpy (p+c->num,data,len), c->num += (unsigned int)len;
                        return 1;
                        }
                else    {
index 291991405935bca4a380f8bb609b673290cd5fe9..ee5c5c1bf3a80549ff1ce02f02aa58b98d3aa20e 100644 (file)
@@ -130,7 +130,7 @@ void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *_inp,size_t bits)
                                else
                                        {
                                        memcpy(c->data+byteoff,inp,bits/8);
-                                       bitoff += bits;
+                                       bitoff += (unsigned int)bits;
                                        bits = 0;
                                        }
                                c->bitoff = bitoff;
@@ -197,7 +197,7 @@ void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *_inp,size_t bits)
                                b = (inp[0]<<inpgap)&0xff;
                                if (bitrem)     c->data[byteoff++] |= b>>bitrem;
                                else            c->data[byteoff++]  = b;
-                               bitoff += bits;
+                               bitoff += (unsigned int)bits;
                                if (bitoff==WHIRLPOOL_BBLOCK)
                                        {
                                        whirlpool_block(c,c->data,1);