Procházet zdrojové kódy

fix some MSVC compiler warnings

Steffen Jaeckel před 6 roky
rodič
revize
ef55d1335e

+ 5 - 4
src/misc/padding/padding_pad.c

@@ -84,9 +84,10 @@ static int _padding_padded_length(unsigned long *length, unsigned long mode)
 */
 */
 int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded_length, unsigned long mode)
 int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded_length, unsigned long mode)
 {
 {
-   unsigned long diff, l;
+   unsigned long l;
    enum padding_type type;
    enum padding_type type;
    int err;
    int err;
+   unsigned char diff;
 
 
    LTC_ARGCHK(data          != NULL);
    LTC_ARGCHK(data          != NULL);
    LTC_ARGCHK(padded_length != NULL);
    LTC_ARGCHK(padded_length != NULL);
@@ -111,8 +112,8 @@ int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded
       return CRYPT_BUFFER_OVERFLOW;
       return CRYPT_BUFFER_OVERFLOW;
    }
    }
 
 
-   diff = l - length;
-   if (diff > 255) return CRYPT_INVALID_ARG;
+   if (l - length > 255) return CRYPT_INVALID_ARG;
+   diff = (unsigned char)(l - length);
 
 
    switch (type) {
    switch (type) {
       case LTC_PAD_PKCS7:
       case LTC_PAD_PKCS7:
@@ -120,7 +121,7 @@ int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded
          break;
          break;
 #ifdef LTC_RNG_GET_BYTES
 #ifdef LTC_RNG_GET_BYTES
       case LTC_PAD_ISO_10126:
       case LTC_PAD_ISO_10126:
-         if (rng_get_bytes(&data[length], diff-1, NULL) != diff-1) {
+         if (rng_get_bytes(&data[length], diff-1u, NULL) != diff-1u) {
             return CRYPT_ERROR_READPRNG;
             return CRYPT_ERROR_READPRNG;
          }
          }
          data[l-1] =  diff;
          data[l-1] =  diff;

+ 2 - 1
src/pk/asn1/oid/pk_oid_str.c

@@ -11,7 +11,8 @@
 
 
 int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen)
 int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen)
 {
 {
-   unsigned long i, j, limit, OID_len, oid_j;
+   unsigned long i, j, limit, oid_j;
+   size_t OID_len;
 
 
    LTC_ARGCHK(oidlen != NULL);
    LTC_ARGCHK(oidlen != NULL);
 
 

+ 2 - 2
src/prngs/fortuna.c

@@ -237,8 +237,8 @@ int fortuna_start(prng_state *prng)
           return err;
           return err;
        }
        }
    }
    }
-   prng->u.fortuna.pool_idx = prng->u.fortuna.pool0_len = prng->u.fortuna.wd = 0;
-   prng->u.fortuna.reset_cnt = 0;
+   prng->u.fortuna.pool_idx = prng->u.fortuna.pool0_len = 0;
+   prng->u.fortuna.reset_cnt = prng->u.fortuna.wd = 0;
 
 
    /* reset bufs */
    /* reset bufs */
    zeromem(prng->u.fortuna.K, 32);
    zeromem(prng->u.fortuna.K, 32);

+ 1 - 1
src/stream/chacha/chacha_memory.c

@@ -34,7 +34,7 @@ int chacha_memory(const unsigned char *key,    unsigned long keylen,  unsigned l
 
 
    if ((err = chacha_setup(&st, key, keylen, rounds))       != CRYPT_OK) goto WIPE_KEY;
    if ((err = chacha_setup(&st, key, keylen, rounds))       != CRYPT_OK) goto WIPE_KEY;
    if (ivlen > 8) {
    if (ivlen > 8) {
-        if ((err = chacha_ivctr32(&st, iv, ivlen, counter)) != CRYPT_OK) goto WIPE_KEY;
+        if ((err = chacha_ivctr32(&st, iv, ivlen, (ulong32)counter)) != CRYPT_OK) goto WIPE_KEY;
    } else {
    } else {
         if ((err = chacha_ivctr64(&st, iv, ivlen, counter)) != CRYPT_OK) goto WIPE_KEY;
         if ((err = chacha_ivctr64(&st, iv, ivlen, counter)) != CRYPT_OK) goto WIPE_KEY;
    }
    }

+ 2 - 2
tests/der_test.c

@@ -1099,9 +1099,9 @@ static int der_choice_n_custom_test(void)
        /* custom encode */
        /* custom encode */
        child[0] = types[x % n];
        child[0] = types[x % n];
        if (x < n) {
        if (x < n) {
-          LTC_SET_ASN1_CUSTOM_CONSTRUCTED(root, 0, LTC_ASN1_CL_CONTEXT_SPECIFIC, 1U << (x % n), child);
+          LTC_SET_ASN1_CUSTOM_CONSTRUCTED(root, 0, LTC_ASN1_CL_CONTEXT_SPECIFIC, 1uLL << (x % n), child);
        } else {
        } else {
-          LTC_SET_ASN1_CUSTOM_PRIMITIVE(root, 0, LTC_ASN1_CL_CONTEXT_SPECIFIC, 1U << (x % n), child->type, child->data, child->size);
+          LTC_SET_ASN1_CUSTOM_PRIMITIVE(root, 0, LTC_ASN1_CL_CONTEXT_SPECIFIC, 1uLL << (x % n), child->type, child->data, child->size);
        }
        }
        custlen = sizeof(custbuf);
        custlen = sizeof(custbuf);
        /* don't try to custom-encode a primitive custom-type */
        /* don't try to custom-encode a primitive custom-type */