Fixes for implicit casts.

Tested with `./configure --disable-asm --enable-32bit --enable-asn=original --enable-cryptonly CFLAGS="-Wconversion -pedantic" && make`. Some progress with ASN template, but not complete.
This commit is contained in:
David Garske
2023-04-04 13:46:30 -07:00
committed by Daniel Pouzzner
parent 6a89464176
commit 6418e3cbfe
12 changed files with 421 additions and 401 deletions

View File

@@ -2893,7 +2893,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
aes->left = 0; aes->left = 0;
#endif #endif
aes->keylen = keylen; aes->keylen = (int)keylen;
aes->rounds = (keylen/4) + 6; aes->rounds = (keylen/4) + 6;
#ifdef WOLFSSL_AESNI #ifdef WOLFSSL_AESNI
@@ -4563,7 +4563,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
#if (defined(HAVE_AESGCM) && !defined(WC_NO_RNG)) || defined(HAVE_AESCCM) #if (defined(HAVE_AESGCM) && !defined(WC_NO_RNG)) || defined(HAVE_AESCCM)
static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz) static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
{ {
int i; word32 i;
for (i = ctrSz-1; i >= 0; i--) { for (i = ctrSz-1; i >= 0; i--) {
if (++ctr[i]) if (++ctr[i])
break; break;
@@ -4683,12 +4683,12 @@ static void GenerateM0(Aes* aes)
#elif defined(GCM_TABLE_4BIT) #elif defined(GCM_TABLE_4BIT)
#if !defined(BIG_ENDIAN_ORDER) && !defined(WC_16BIT_CPU) #if !defined(BIG_ENDIAN_ORDER) && !defined(WC_16BIT_CPU)
static WC_INLINE void Shift4_M0(byte *r8, byte* z8) static WC_INLINE void Shift4_M0(byte *r8, byte *z8)
{ {
int i; int i;
for (i = 15; i > 0; i--) for (i = 15; i > 0; i--)
r8[i] = (z8[i-1] << 4) | (z8[i] >> 4); r8[i] = (byte)(z8[i-1] << 4) | (byte)(z8[i] >> 4);
r8[0] = z8[0] >> 4; r8[0] = (byte)(z8[0] >> 4);
} }
#endif #endif
@@ -7165,7 +7165,7 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C(
/* ConstantCompare returns the cumulative bitwise or of the bitwise xor of /* ConstantCompare returns the cumulative bitwise or of the bitwise xor of
* the pairwise bytes in the strings. * the pairwise bytes in the strings.
*/ */
res = ConstantCompare(authTag, Tprime, authTagSz); res = ConstantCompare(authTag, Tprime, (int)authTagSz);
/* convert positive retval from ConstantCompare() to all-1s word, in /* convert positive retval from ConstantCompare() to all-1s word, in
* constant time. * constant time.
*/ */
@@ -8571,7 +8571,7 @@ int wc_AesGcmSetExtIV(Aes* aes, const byte* iv, word32 ivSz)
{ {
int ret = 0; int ret = 0;
if (aes == NULL || iv == NULL || !CheckAesGcmIvSize(ivSz)) { if (aes == NULL || iv == NULL || !CheckAesGcmIvSize((int)ivSz)) {
ret = BAD_FUNC_ARG; ret = BAD_FUNC_ARG;
} }
@@ -8599,7 +8599,7 @@ int wc_AesGcmSetIV(Aes* aes, word32 ivSz,
{ {
int ret = 0; int ret = 0;
if (aes == NULL || rng == NULL || !CheckAesGcmIvSize(ivSz) || if (aes == NULL || rng == NULL || !CheckAesGcmIvSize((int)ivSz) ||
(ivFixed == NULL && ivFixedSz != 0) || (ivFixed == NULL && ivFixedSz != 0) ||
(ivFixed != NULL && ivFixedSz != AES_IV_FIXED_SZ)) { (ivFixed != NULL && ivFixedSz != AES_IV_FIXED_SZ)) {

File diff suppressed because it is too large Load Diff

View File

@@ -3020,7 +3020,7 @@ static int ecc_mulmod(const mp_int* k, ecc_point* P, ecc_point* Q,
err = mp_copy(k, kt); err = mp_copy(k, kt);
} }
if (err == MP_OKAY) { if (err == MP_OKAY) {
err = mp_grow(kt, modulus->used + 1); err = mp_grow(kt, (int)modulus->used + 1);
} }
/* Step 2: for j = 1 to t-1 do */ /* Step 2: for j = 1 to t-1 do */
for (i = 1; (err == MP_OKAY) && (i < t); i++) { for (i = 1; (err == MP_OKAY) && (i < t); i++) {
@@ -3042,11 +3042,11 @@ static int ecc_mulmod(const mp_int* k, ecc_point* P, ecc_point* Q,
/* Swap R[0] and R[1] if other index is needed. */ /* Swap R[0] and R[1] if other index is needed. */
swap ^= b; swap ^= b;
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->x, R[1]->x, modulus->used, swap); err = mp_cond_swap_ct(R[0]->x, R[1]->x, (int)modulus->used, swap);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->y, R[1]->y, modulus->used, swap); err = mp_cond_swap_ct(R[0]->y, R[1]->y, (int)modulus->used, swap);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->z, R[1]->z, modulus->used, swap); err = mp_cond_swap_ct(R[0]->z, R[1]->z, (int)modulus->used, swap);
swap = (int)b; swap = (int)b;
if (err == MP_OKAY) if (err == MP_OKAY)
@@ -3062,11 +3062,11 @@ static int ecc_mulmod(const mp_int* k, ecc_point* P, ecc_point* Q,
/* Swap back if last bit is 0. */ /* Swap back if last bit is 0. */
swap ^= 1; swap ^= 1;
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->x, R[1]->x, modulus->used, swap); err = mp_cond_swap_ct(R[0]->x, R[1]->x, (int)modulus->used, swap);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->y, R[1]->y, modulus->used, swap); err = mp_cond_swap_ct(R[0]->y, R[1]->y, (int)modulus->used, swap);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->z, R[1]->z, modulus->used, swap); err = mp_cond_swap_ct(R[0]->z, R[1]->z, (int)modulus->used, swap);
#endif #endif
/* Step 5: b = k[0]; R[b] = R[b] - P */ /* Step 5: b = k[0]; R[b] = R[b] - P */
@@ -3085,21 +3085,21 @@ static int ecc_mulmod(const mp_int* k, ecc_point* P, ecc_point* Q,
&infinity); &infinity);
#else #else
/* Swap R[0] and R[1], if necessary, to operate on the one we want. */ /* Swap R[0] and R[1], if necessary, to operate on the one we want. */
err = mp_cond_swap_ct(R[0]->x, R[1]->x, modulus->used, (int)b); err = mp_cond_swap_ct(R[0]->x, R[1]->x, (int)modulus->used, (int)b);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->y, R[1]->y, modulus->used, (int)b); err = mp_cond_swap_ct(R[0]->y, R[1]->y, (int)modulus->used, (int)b);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->z, R[1]->z, modulus->used, (int)b); err = mp_cond_swap_ct(R[0]->z, R[1]->z, (int)modulus->used, (int)b);
if (err == MP_OKAY) if (err == MP_OKAY)
err = ecc_projective_add_point_safe(R[0], R[2], R[0], a, modulus, err = ecc_projective_add_point_safe(R[0], R[2], R[0], a, modulus,
mp, &infinity); mp, &infinity);
/* Swap back if necessary. */ /* Swap back if necessary. */
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->x, R[1]->x, modulus->used, (int)b); err = mp_cond_swap_ct(R[0]->x, R[1]->x, (int)modulus->used, (int)b);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->y, R[1]->y, modulus->used, (int)b); err = mp_cond_swap_ct(R[0]->y, R[1]->y, (int)modulus->used, (int)b);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_cond_swap_ct(R[0]->z, R[1]->z, modulus->used, (int)b); err = mp_cond_swap_ct(R[0]->z, R[1]->z, (int)modulus->used, (int)b);
#endif #endif
} }
@@ -4584,7 +4584,7 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
#ifdef WOLFSSL_NO_MALLOC #ifdef WOLFSSL_NO_MALLOC
ecc_point lcl_result; ecc_point lcl_result;
#endif #endif
word32 x = 0; int x = 0;
mp_digit mp = 0; mp_digit mp = 0;
DECLARE_CURVE_SPECS(3); DECLARE_CURVE_SPECS(3);
@@ -4644,17 +4644,17 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
} }
if (err == MP_OKAY) { if (err == MP_OKAY) {
x = mp_unsigned_bin_size(curve->prime); x = mp_unsigned_bin_size(curve->prime);
if (*outlen < x || (int)x < mp_unsigned_bin_size(result->x)) { if (*outlen < (word32)x || x < mp_unsigned_bin_size(result->x)) {
err = BUFFER_E; err = BUFFER_E;
} }
} }
if (err == MP_OKAY) { if (err == MP_OKAY) {
XMEMSET(out, 0, x); XMEMSET(out, 0, x);
err = mp_to_unsigned_bin(result->x,out + err = mp_to_unsigned_bin(result->x, out +
(x - mp_unsigned_bin_size(result->x))); (x - mp_unsigned_bin_size(result->x)));
} }
*outlen = x; *outlen = (word32)x;
mp_forcezero(result->x); mp_forcezero(result->x);
mp_forcezero(result->y); mp_forcezero(result->y);
@@ -4974,7 +4974,7 @@ int wc_ecc_gen_k(WC_RNG* rng, int size, mp_int* k, mp_int* order)
int err; int err;
byte buf[ECC_MAXSIZE_GEN]; byte buf[ECC_MAXSIZE_GEN];
if (rng == NULL || size + 8 > ECC_MAXSIZE_GEN || k == NULL || if (rng == NULL || size <= 0 || size + 8 > ECC_MAXSIZE_GEN || k == NULL ||
order == NULL) { order == NULL) {
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
@@ -4984,14 +4984,14 @@ int wc_ecc_gen_k(WC_RNG* rng, int size, mp_int* k, mp_int* order)
size += 8; size += 8;
/* make up random string */ /* make up random string */
err = wc_RNG_GenerateBlock(rng, buf, size); err = wc_RNG_GenerateBlock(rng, buf, (word32)size);
#ifdef WOLFSSL_CHECK_MEM_ZERO #ifdef WOLFSSL_CHECK_MEM_ZERO
wc_MemZero_Add("wc_ecc_gen_k buf", buf, size); wc_MemZero_Add("wc_ecc_gen_k buf", buf, size);
#endif #endif
/* load random buffer data into k */ /* load random buffer data into k */
if (err == 0) if (err == 0)
err = mp_read_unsigned_bin(k, buf, size); err = mp_read_unsigned_bin(k, buf, (word32)size);
/* the key should be smaller than the order of base point */ /* the key should be smaller than the order of base point */
if (err == MP_OKAY) { if (err == MP_OKAY) {
@@ -5285,7 +5285,7 @@ static int _ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key,
return err; return err;
} }
key->flags = flags; key->flags = (byte)flags;
#ifdef WOLF_CRYPTO_CB #ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) { if (key->devId != INVALID_DEVID) {
@@ -5921,7 +5921,7 @@ int wc_ecc_set_flags(ecc_key* key, word32 flags)
static int wc_ecc_get_curve_order_bit_count(const ecc_set_type* dp) static int wc_ecc_get_curve_order_bit_count(const ecc_set_type* dp)
{ {
int err = MP_OKAY; int err = MP_OKAY;
word32 orderBits; int orderBits;
DECLARE_CURVE_SPECS(1); DECLARE_CURVE_SPECS(1);
ALLOC_CURVE_SPECS(1, err); ALLOC_CURVE_SPECS(1, err);
@@ -5937,7 +5937,7 @@ static int wc_ecc_get_curve_order_bit_count(const ecc_set_type* dp)
wc_ecc_curve_free(curve); wc_ecc_curve_free(curve);
FREE_CURVE_SPECS(); FREE_CURVE_SPECS();
return (int)orderBits; return orderBits;
} }
#ifdef HAVE_ECC_SIGN #ifdef HAVE_ECC_SIGN
@@ -6878,7 +6878,7 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
/* load digest into e */ /* load digest into e */
if (err == MP_OKAY) { if (err == MP_OKAY) {
/* we may need to truncate if hash is longer than key size */ /* we may need to truncate if hash is longer than key size */
word32 orderBits = mp_count_bits(curve->order); word32 orderBits = (word32)mp_count_bits(curve->order);
/* truncate down to byte size, may be all that's needed */ /* truncate down to byte size, may be all that's needed */
if ((WOLFSSL_BIT_SIZE * inlen) > orderBits) if ((WOLFSSL_BIT_SIZE * inlen) > orderBits)
@@ -7656,7 +7656,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
ecc_point lcl_precomp[SHAMIR_PRECOMP_SZ]; ecc_point lcl_precomp[SHAMIR_PRECOMP_SZ];
#endif #endif
#endif #endif
unsigned bitbufA, bitbufB, lenA, lenB, len, nA, nB, nibble; unsigned int bitbufA, bitbufB, lenA, lenB, len, nA, nB, nibble;
#ifdef WOLFSSL_NO_MALLOC #ifdef WOLFSSL_NO_MALLOC
unsigned char tA[ECC_BUFSIZE]; unsigned char tA[ECC_BUFSIZE];
unsigned char tB[ECC_BUFSIZE]; unsigned char tB[ECC_BUFSIZE];
@@ -7750,8 +7750,8 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
#endif #endif
/* get sizes */ /* get sizes */
lenA = mp_unsigned_bin_size(kA); lenA = (unsigned int)mp_unsigned_bin_size(kA);
lenB = mp_unsigned_bin_size(kB); lenB = (unsigned int)mp_unsigned_bin_size(kB);
len = MAX(lenA, lenB); len = MAX(lenA, lenB);
/* sanity check */ /* sanity check */
@@ -7863,7 +7863,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
/* if not both zero */ /* if not both zero */
if ((nA != 0) || (nB != 0)) { if ((nA != 0) || (nB != 0)) {
int i = nA + (nB<<2); unsigned int i = nA + (nB<<2);
if (first == 1) { if (first == 1) {
/* if first, copy from table */ /* if first, copy from table */
first = 0; first = 0;
@@ -8581,7 +8581,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
return err; return err;
} }
keySz = key->dp->size; keySz = (word32)key->dp->size;
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \ #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \
defined(WOLFSSL_ASYNC_CRYPT_SW) defined(WOLFSSL_ASYNC_CRYPT_SW)
@@ -8837,7 +8837,7 @@ int wc_ecc_import_point_der_ex(const byte* in, word32 inLen,
/* read data */ /* read data */
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_read_unsigned_bin(point->x, in, keysize); err = mp_read_unsigned_bin(point->x, in, (word32)keysize);
#ifdef HAVE_COMP_KEY #ifdef HAVE_COMP_KEY
if (err == MP_OKAY && compressed == 1) { /* build y */ if (err == MP_OKAY && compressed == 1) { /* build y */
@@ -8980,7 +8980,7 @@ int wc_ecc_import_point_der_ex(const byte* in, word32 inLen,
#ifdef HAVE_COMP_KEY #ifdef HAVE_COMP_KEY
if (compressed == 0) if (compressed == 0)
#endif #endif
err = mp_read_unsigned_bin(point->y, in + keysize, keysize); err = mp_read_unsigned_bin(point->y, in + keysize, (word32)keysize);
} }
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_set(point->z, 1); err = mp_set(point->z, 1);
@@ -9034,7 +9034,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
if ((curve_idx < 0) || (wc_ecc_is_valid_idx(curve_idx) == 0)) if ((curve_idx < 0) || (wc_ecc_is_valid_idx(curve_idx) == 0))
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
numlen = ecc_sets[curve_idx].size; numlen = (word32)ecc_sets[curve_idx].size;
/* return length needed only */ /* return length needed only */
if (point != NULL && out == NULL && outLen != NULL) { if (point != NULL && out == NULL && outLen != NULL) {
@@ -9068,7 +9068,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
/* pad and store x */ /* pad and store x */
XMEMSET(buf, 0, ECC_BUFSIZE); XMEMSET(buf, 0, ECC_BUFSIZE);
ret = mp_to_unsigned_bin(point->x, buf + ret = mp_to_unsigned_bin(point->x, buf +
(numlen - mp_unsigned_bin_size(point->x))); (numlen - (word32)mp_unsigned_bin_size(point->x)));
if (ret != MP_OKAY) if (ret != MP_OKAY)
goto done; goto done;
XMEMCPY(out+1, buf, numlen); XMEMCPY(out+1, buf, numlen);
@@ -9076,7 +9076,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
/* pad and store y */ /* pad and store y */
XMEMSET(buf, 0, ECC_BUFSIZE); XMEMSET(buf, 0, ECC_BUFSIZE);
ret = mp_to_unsigned_bin(point->y, buf + ret = mp_to_unsigned_bin(point->y, buf +
(numlen - mp_unsigned_bin_size(point->y))); (numlen - (word32)mp_unsigned_bin_size(point->y)));
if (ret != MP_OKAY) if (ret != MP_OKAY)
goto done; goto done;
XMEMCPY(out+1+numlen, buf, numlen); XMEMCPY(out+1+numlen, buf, numlen);
@@ -9177,8 +9177,8 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
/* return length needed only */ /* return length needed only */
if (key != NULL && out == NULL && outLen != NULL) { if (key != NULL && out == NULL && outLen != NULL) {
/* if key hasn't been setup assume max bytes for size estimation */ /* if key hasn't been setup assume max bytes for size estimation */
numlen = key->dp ? key->dp->size : MAX_ECC_BYTES; numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
*outLen = 1 + 2*numlen; *outLen = 1 + 2 * numlen;
return LENGTH_ONLY_E; return LENGTH_ONLY_E;
} }
@@ -9208,7 +9208,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
} }
numlen = key->dp->size; numlen = (word32)key->dp->size;
/* verify room in out buffer */ /* verify room in out buffer */
if (*outLen < (1 + 2*numlen)) { if (*outLen < (1 + 2*numlen)) {
@@ -9217,8 +9217,8 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
} }
/* verify public key length is less than key size */ /* verify public key length is less than key size */
pubxlen = mp_unsigned_bin_size(key->pubkey.x); pubxlen = (word32)mp_unsigned_bin_size(key->pubkey.x);
pubylen = mp_unsigned_bin_size(key->pubkey.y); pubylen = (word32)mp_unsigned_bin_size(key->pubkey.y);
if ((pubxlen > numlen) || (pubylen > numlen)) { if ((pubxlen > numlen) || (pubylen > numlen)) {
WOLFSSL_MSG("Public key x/y invalid!"); WOLFSSL_MSG("Public key x/y invalid!");
return BUFFER_E; return BUFFER_E;
@@ -10056,7 +10056,7 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
/* read data */ /* read data */
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_read_unsigned_bin(key->pubkey.x, in, keysize); err = mp_read_unsigned_bin(key->pubkey.x, in, (word32)keysize);
#ifdef HAVE_COMP_KEY #ifdef HAVE_COMP_KEY
if (err == MP_OKAY && compressed == 1) { /* build y */ if (err == MP_OKAY && compressed == 1) { /* build y */
@@ -10192,7 +10192,8 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
if (compressed == 0) if (compressed == 0)
#endif #endif
{ {
err = mp_read_unsigned_bin(key->pubkey.y, in + keysize, keysize); err = mp_read_unsigned_bin(key->pubkey.y, in + keysize,
(word32)keysize);
} }
} }
if (err == MP_OKAY) if (err == MP_OKAY)
@@ -10280,7 +10281,7 @@ int wc_ecc_export_ex(ecc_key* key, byte* qx, word32* qxLen,
if (wc_ecc_is_valid_idx(key->idx) == 0 || key->dp == NULL) { if (wc_ecc_is_valid_idx(key->idx) == 0 || key->dp == NULL) {
return ECC_BAD_ARG_E; return ECC_BAD_ARG_E;
} }
keySz = key->dp->size; keySz = (word32)key->dp->size;
/* private key, d */ /* private key, d */
if (d != NULL) { if (d != NULL) {
@@ -10437,7 +10438,7 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
wc_ecc_reset(key); wc_ecc_reset(key);
/* set key size */ /* set key size */
ret = wc_ecc_set_curve(key, privSz, curve_id); ret = wc_ecc_set_curve(key, (int)privSz, curve_id);
key->type = ECC_PRIVATEKEY_ONLY; key->type = ECC_PRIVATEKEY_ONLY;
} }
@@ -10771,7 +10772,7 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
err = mp_read_radix(key->pubkey.x, qx, MP_RADIX_HEX); err = mp_read_radix(key->pubkey.x, qx, MP_RADIX_HEX);
else else
err = mp_read_unsigned_bin(key->pubkey.x, (const byte*)qx, err = mp_read_unsigned_bin(key->pubkey.x, (const byte*)qx,
key->dp->size); (word32)key->dp->size);
if (mp_isneg(key->pubkey.x)) { if (mp_isneg(key->pubkey.x)) {
WOLFSSL_MSG("Invalid Qx"); WOLFSSL_MSG("Invalid Qx");
@@ -10788,7 +10789,7 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
err = mp_read_radix(key->pubkey.y, qy, MP_RADIX_HEX); err = mp_read_radix(key->pubkey.y, qy, MP_RADIX_HEX);
else else
err = mp_read_unsigned_bin(key->pubkey.y, (const byte*)qy, err = mp_read_unsigned_bin(key->pubkey.y, (const byte*)qy,
key->dp->size); (word32)key->dp->size);
if (mp_isneg(key->pubkey.y)) { if (mp_isneg(key->pubkey.y)) {
WOLFSSL_MSG("Invalid Qy"); WOLFSSL_MSG("Invalid Qy");
@@ -10946,7 +10947,7 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
#endif /* WOLFSSL_QNX_CAAM */ #endif /* WOLFSSL_QNX_CAAM */
{ {
err = mp_read_unsigned_bin(&key->k, (const byte*)d, err = mp_read_unsigned_bin(&key->k, (const byte*)d,
key->dp->size); (word32)key->dp->size);
} }
} }
#if defined(WOLFSSL_XILINX_CRYPT_VERSAL) #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)

View File

@@ -531,7 +531,7 @@ int wc_Hash(enum wc_HashType hash_type, const byte* data,
word32 dig_size; word32 dig_size;
/* Validate hash buffer size */ /* Validate hash buffer size */
dig_size = wc_HashGetDigestSize(hash_type); dig_size = (word32)wc_HashGetDigestSize(hash_type);
if (hash_len < dig_size) { if (hash_len < dig_size) {
return BUFFER_E; return BUFFER_E;
} }

View File

@@ -384,25 +384,25 @@ WC_MISC_STATIC WC_INLINE int ConstantCompare(const byte* a, const byte* b,
/* converts a 32 bit integer to 24 bit */ /* converts a 32 bit integer to 24 bit */
WC_MISC_STATIC WC_INLINE void c32to24(word32 in, word24 out) WC_MISC_STATIC WC_INLINE void c32to24(word32 in, word24 out)
{ {
out[0] = (in >> 16) & 0xff; out[0] = (byte)((in >> 16) & 0xff);
out[1] = (in >> 8) & 0xff; out[1] = (byte)((in >> 8) & 0xff);
out[2] = in & 0xff; out[2] = (byte)(in & 0xff);
} }
/* convert 16 bit integer to opaque */ /* convert 16 bit integer to opaque */
WC_MISC_STATIC WC_INLINE void c16toa(word16 wc_u16, byte* c) WC_MISC_STATIC WC_INLINE void c16toa(word16 wc_u16, byte* c)
{ {
c[0] = (wc_u16 >> 8) & 0xff; c[0] = (byte)((wc_u16 >> 8) & 0xff);
c[1] = wc_u16 & 0xff; c[1] = (byte)(wc_u16 & 0xff);
} }
/* convert 32 bit integer to opaque */ /* convert 32 bit integer to opaque */
WC_MISC_STATIC WC_INLINE void c32toa(word32 wc_u32, byte* c) WC_MISC_STATIC WC_INLINE void c32toa(word32 wc_u32, byte* c)
{ {
c[0] = (wc_u32 >> 24) & 0xff; c[0] = (byte)((wc_u32 >> 24) & 0xff);
c[1] = (wc_u32 >> 16) & 0xff; c[1] = (byte)((wc_u32 >> 16) & 0xff);
c[2] = (wc_u32 >> 8) & 0xff; c[2] = (byte)((wc_u32 >> 8) & 0xff);
c[3] = wc_u32 & 0xff; c[3] = (byte)(wc_u32 & 0xff);
} }
#endif #endif
@@ -410,14 +410,16 @@ WC_MISC_STATIC WC_INLINE void c32toa(word32 wc_u32, byte* c)
/* convert a 24 bit integer into a 32 bit one */ /* convert a 24 bit integer into a 32 bit one */
WC_MISC_STATIC WC_INLINE void c24to32(const word24 wc_u24, word32* wc_u32) WC_MISC_STATIC WC_INLINE void c24to32(const word24 wc_u24, word32* wc_u32)
{ {
*wc_u32 = ((word32)wc_u24[0] << 16) | (wc_u24[1] << 8) | wc_u24[2]; *wc_u32 = ((word32)wc_u24[0] << 16) |
((word32)wc_u24[1] << 8) |
(word32)wc_u24[2];
} }
/* convert opaque to 24 bit integer */ /* convert opaque to 24 bit integer */
WC_MISC_STATIC WC_INLINE void ato24(const byte* c, word32* wc_u24) WC_MISC_STATIC WC_INLINE void ato24(const byte* c, word32* wc_u24)
{ {
*wc_u24 = ((word32)c[0] << 16) | (c[1] << 8) | c[2]; *wc_u24 = ((word32)c[0] << 16) | ((word32)c[1] << 8) | c[2];
} }
/* convert opaque to 16 bit integer */ /* convert opaque to 16 bit integer */
@@ -429,7 +431,10 @@ WC_MISC_STATIC WC_INLINE void ato16(const byte* c, word16* wc_u16)
/* convert opaque to 32 bit integer */ /* convert opaque to 32 bit integer */
WC_MISC_STATIC WC_INLINE void ato32(const byte* c, word32* wc_u32) WC_MISC_STATIC WC_INLINE void ato32(const byte* c, word32* wc_u32)
{ {
*wc_u32 = ((word32)c[0] << 24) | ((word32)c[1] << 16) | (c[2] << 8) | c[3]; *wc_u32 = ((word32)c[0] << 24) |
((word32)c[1] << 16) |
((word32)c[2] << 8) |
(word32)c[3];
} }
@@ -474,31 +479,31 @@ WC_MISC_STATIC WC_INLINE int ByteToHexStr(byte in, char* out)
/* Constant time - mask set when a > b. */ /* Constant time - mask set when a > b. */
WC_MISC_STATIC WC_INLINE byte ctMaskGT(int a, int b) WC_MISC_STATIC WC_INLINE byte ctMaskGT(int a, int b)
{ {
return (byte)((((word32)a - b - 1) >> 31) - 1); return (byte)((((word32)a - (word32)b - 1) >> 31) - 1);
} }
/* Constant time - mask set when a >= b. */ /* Constant time - mask set when a >= b. */
WC_MISC_STATIC WC_INLINE byte ctMaskGTE(int a, int b) WC_MISC_STATIC WC_INLINE byte ctMaskGTE(int a, int b)
{ {
return (byte)((((word32)a - b ) >> 31) - 1); return (byte)((((word32)a - (word32)b) >> 31) - 1);
} }
/* Constant time - mask set when a >= b. */ /* Constant time - mask set when a >= b. */
WC_MISC_STATIC WC_INLINE int ctMaskIntGTE(int a, int b) WC_MISC_STATIC WC_INLINE int ctMaskIntGTE(int a, int b)
{ {
return (int)((((word32)a - b ) >> 31) - 1); return (int)((((word32)a - (word32)b) >> 31) - 1);
} }
/* Constant time - mask set when a < b. */ /* Constant time - mask set when a < b. */
WC_MISC_STATIC WC_INLINE byte ctMaskLT(int a, int b) WC_MISC_STATIC WC_INLINE byte ctMaskLT(int a, int b)
{ {
return (byte)((((word32)b - a - 1) >> 31) - 1); return (byte)((((word32)b - (word32)a - 1) >> 31) - 1);
} }
/* Constant time - mask set when a <= b. */ /* Constant time - mask set when a <= b. */
WC_MISC_STATIC WC_INLINE byte ctMaskLTE(int a, int b) WC_MISC_STATIC WC_INLINE byte ctMaskLTE(int a, int b)
{ {
return (byte)((((word32)b - a ) >> 31) - 1); return (byte)((((word32)b - (word32)a) >> 31) - 1);
} }
/* Constant time - mask set when a == b. */ /* Constant time - mask set when a == b. */
@@ -510,25 +515,25 @@ WC_MISC_STATIC WC_INLINE byte ctMaskEq(int a, int b)
/* Constant time - sets 16 bit integer mask when a > b */ /* Constant time - sets 16 bit integer mask when a > b */
WC_MISC_STATIC WC_INLINE word16 ctMask16GT(int a, int b) WC_MISC_STATIC WC_INLINE word16 ctMask16GT(int a, int b)
{ {
return (word16)((((word32)a - b - 1) >> 31) - 1); return (word16)((((word32)a - (word32)b - 1) >> 31) - 1);
} }
/* Constant time - sets 16 bit integer mask when a >= b */ /* Constant time - sets 16 bit integer mask when a >= b */
WC_MISC_STATIC WC_INLINE word16 ctMask16GTE(int a, int b) WC_MISC_STATIC WC_INLINE word16 ctMask16GTE(int a, int b)
{ {
return (word16)((((word32)a - b ) >> 31) - 1); return (word16)((((word32)a - (word32)b) >> 31) - 1);
} }
/* Constant time - sets 16 bit integer mask when a < b. */ /* Constant time - sets 16 bit integer mask when a < b. */
WC_MISC_STATIC WC_INLINE word16 ctMask16LT(int a, int b) WC_MISC_STATIC WC_INLINE word16 ctMask16LT(int a, int b)
{ {
return (word16)((((word32)b - a - 1) >> 31) - 1); return (word16)((((word32)b - (word32)a - 1) >> 31) - 1);
} }
/* Constant time - sets 16 bit integer mask when a <= b. */ /* Constant time - sets 16 bit integer mask when a <= b. */
WC_MISC_STATIC WC_INLINE word16 ctMask16LTE(int a, int b) WC_MISC_STATIC WC_INLINE word16 ctMask16LTE(int a, int b)
{ {
return (word16)((((word32)b - a ) >> 31) - 1); return (word16)((((word32)b - (word32)a) >> 31) - 1);
} }
/* Constant time - sets 16 bit integer mask when a == b. */ /* Constant time - sets 16 bit integer mask when a == b. */
@@ -559,7 +564,7 @@ WC_MISC_STATIC WC_INLINE int ctMaskSelInt(byte m, int a, int b)
/* Constant time - bit set when a <= b. */ /* Constant time - bit set when a <= b. */
WC_MISC_STATIC WC_INLINE byte ctSetLTE(int a, int b) WC_MISC_STATIC WC_INLINE byte ctSetLTE(int a, int b)
{ {
return (byte)(((word32)a - b - 1) >> 31); return (byte)(((word32)a - (word32)b - 1) >> 31);
} }
/* Constant time - conditionally copy size bytes from src to dst if mask is set /* Constant time - conditionally copy size bytes from src to dst if mask is set

View File

@@ -778,7 +778,7 @@ int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
/* process full blocks */ /* process full blocks */
if (bytes >= POLY1305_BLOCK_SIZE) { if (bytes >= POLY1305_BLOCK_SIZE) {
size_t want = (bytes & ~(POLY1305_BLOCK_SIZE - 1)); size_t want = ((size_t)bytes & ~(POLY1305_BLOCK_SIZE - 1));
#if !defined(WOLFSSL_ARMASM) || !defined(__aarch64__) #if !defined(WOLFSSL_ARMASM) || !defined(__aarch64__)
int ret; int ret;
ret = poly1305_blocks(ctx, m, want); ret = poly1305_blocks(ctx, m, want);

View File

@@ -519,7 +519,7 @@ int wc_RNG_DRBG_Reseed(WC_RNG* rng, const byte* seed, word32 seedSz)
static WC_INLINE void array_add_one(byte* data, word32 dataSz) static WC_INLINE void array_add_one(byte* data, word32 dataSz)
{ {
int i; word32 i;
for (i = dataSz - 1; i >= 0; i--) { for (i = dataSz - 1; i >= 0; i--) {
data[i]++; data[i]++;
if (data[i] != 0) break; if (data[i] != 0) break;
@@ -618,7 +618,7 @@ static int Hash_gen(DRBG_internal* drbg, byte* out, word32 outSz, const byte* V)
static WC_INLINE void array_add(byte* d, word32 dLen, const byte* s, word32 sLen) static WC_INLINE void array_add(byte* d, word32 dLen, const byte* s, word32 sLen)
{ {
if (dLen > 0 && sLen > 0 && dLen >= sLen) { if (dLen > 0 && sLen > 0 && dLen >= sLen) {
int sIdx, dIdx; word32 sIdx, dIdx;
word16 carry = 0; word16 carry = 0;
dIdx = dLen - 1; dIdx = dLen - 1;
@@ -779,7 +779,7 @@ int wc_RNG_TestSeed(const byte* seed, word32 seedSz)
while (seedIdx < seedSz - SEED_BLOCK_SZ) { while (seedIdx < seedSz - SEED_BLOCK_SZ) {
if (ConstantCompare(seed + seedIdx, if (ConstantCompare(seed + seedIdx,
seed + seedIdx + scratchSz, seed + seedIdx + scratchSz,
scratchSz) == 0) { (int)scratchSz) == 0) {
ret = DRBG_CONT_FAILURE; ret = DRBG_CONT_FAILURE;
} }
@@ -3753,7 +3753,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
break; break;
} }
sz -= len; sz -= (word32)len;
output += len; output += len;
if (sz) { if (sz) {

View File

@@ -943,7 +943,7 @@ static int InitSha256(wc_Sha256* sha256)
S[i] = sha256->digest[i]; S[i] = sha256->digest[i];
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
W[i] = *((const word32*)&data[i*sizeof(word32)]); W[i] = *((const word32*)&data[i*(int)sizeof(word32)]);
for (i = 16; i < WC_SHA256_BLOCK_SIZE; i++) for (i = 16; i < WC_SHA256_BLOCK_SIZE; i++)
W[i] = Gamma1(W[i-2]) + W[i-7] + Gamma0(W[i-15]) + W[i-16]; W[i] = Gamma1(W[i-2]) + W[i-7] + Gamma0(W[i-15]) + W[i-16];

View File

@@ -67,9 +67,9 @@ static int wc_SignatureDerEncode(enum wc_HashType hash_type, byte* hash_data,
} }
oid = ret; oid = ret;
ret = wc_EncodeSignature(hash_data, hash_data, hash_len, oid); ret = (int)wc_EncodeSignature(hash_data, hash_data, hash_len, oid);
if (ret > 0) { if (ret > 0) {
*hash_enc_len = ret; *hash_enc_len = (word32)ret;
ret = 0; ret = 0;
} }
@@ -295,7 +295,7 @@ int wc_SignatureVerify(
WOLFSSL_MSG("wc_SignatureVerify: Invalid hash type/len"); WOLFSSL_MSG("wc_SignatureVerify: Invalid hash type/len");
return ret; return ret;
} }
hash_enc_len = hash_len = ret; hash_enc_len = hash_len = (word32)ret;
#ifndef NO_RSA #ifndef NO_RSA
if (sig_type == WC_SIGNATURE_TYPE_RSA_W_ENC) { if (sig_type == WC_SIGNATURE_TYPE_RSA_W_ENC) {
@@ -429,7 +429,7 @@ int wc_SignatureGenerateHash_ex(
} while (ret == WC_PENDING_E); } while (ret == WC_PENDING_E);
#endif /* WOLFSSL_CRYPTOCELL */ #endif /* WOLFSSL_CRYPTOCELL */
if (ret >= 0) { if (ret >= 0) {
*sig_len = ret; *sig_len = (word32)ret;
ret = 0; /* Success */ ret = 0; /* Success */
} }
#else #else
@@ -494,7 +494,7 @@ int wc_SignatureGenerate_ex(
WOLFSSL_MSG("wc_SignatureGenerate: Invalid hash type/len"); WOLFSSL_MSG("wc_SignatureGenerate: Invalid hash type/len");
return ret; return ret;
} }
hash_enc_len = hash_len = ret; hash_enc_len = hash_len = (word32)ret;
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
if (sig_type == WC_SIGNATURE_TYPE_RSA_W_ENC) { if (sig_type == WC_SIGNATURE_TYPE_RSA_W_ENC) {

View File

@@ -178,7 +178,7 @@ This library provides single precision (SP) integer math functions.
do { \ do { \
ALLOC_SP_INT(n, s, err, h); \ ALLOC_SP_INT(n, s, err, h); \
if ((err) == MP_OKAY) { \ if ((err) == MP_OKAY) { \
(n)->size = (s); \ (n)->size = (unsigned int)(s); \
} \ } \
} \ } \
while (0) while (0)
@@ -4682,7 +4682,7 @@ static void _sp_zero(sp_int* a)
* @param [out] a SP integer. * @param [out] a SP integer.
* @param [in] size Number of words to say are available. * @param [in] size Number of words to say are available.
*/ */
static void _sp_init_size(sp_int* a, int size) static void _sp_init_size(sp_int* a, unsigned int size)
{ {
volatile sp_int_minimal* am = (sp_int_minimal *)a; volatile sp_int_minimal* am = (sp_int_minimal *)a;
@@ -4702,7 +4702,7 @@ static void _sp_init_size(sp_int* a, int size)
* @return MP_OKAY on success. * @return MP_OKAY on success.
* @return MP_VAL when a is NULL. * @return MP_VAL when a is NULL.
*/ */
int sp_init_size(sp_int* a, int size) int sp_init_size(sp_int* a, unsigned int size)
{ {
int err = MP_OKAY; int err = MP_OKAY;
@@ -4998,8 +4998,8 @@ int sp_exch(sp_int* a, sp_int* b)
ALLOC_SP_INT(t, a->used, err, NULL); ALLOC_SP_INT(t, a->used, err, NULL);
if (err == MP_OKAY) { if (err == MP_OKAY) {
/* Cache allocated size of a and b. */ /* Cache allocated size of a and b. */
int asize = a->size; unsigned int asize = a->size;
int bsize = b->size; unsigned int bsize = b->size;
/* Copy all of SP int: t <= a, a <= b, b <= t. */ /* Copy all of SP int: t <= a, a <= b, b <= t. */
XMEMCPY(t, a, MP_INT_SIZEOF(a->used)); XMEMCPY(t, a, MP_INT_SIZEOF(a->used));
XMEMCPY(a, b, MP_INT_SIZEOF(b->used)); XMEMCPY(a, b, MP_INT_SIZEOF(b->used));
@@ -5030,16 +5030,16 @@ int sp_cond_swap_ct(sp_int* a, sp_int* b, int cnt, int swap)
{ {
unsigned int i; unsigned int i;
int err = MP_OKAY; int err = MP_OKAY;
sp_int_digit mask = (sp_int_digit)0 - swap; sp_int_digit mask = (sp_int_digit)0 - (sp_int_digit)swap;
DECL_SP_INT(t, cnt); DECL_SP_INT(t, cnt);
/* Allocate temporary to hold masked xor of a and b. */ /* Allocate temporary to hold masked xor of a and b. */
ALLOC_SP_INT(t, cnt, err, NULL); ALLOC_SP_INT(t, cnt, err, NULL);
if (err == MP_OKAY) { if (err == MP_OKAY) {
/* XOR other fields in sp_int into temp - mask set when swapping. */ /* XOR other fields in sp_int into temp - mask set when swapping. */
t->used = (int)((a->used ^ b->used) & mask); t->used = (a->used ^ b->used) & mask;
#ifdef WOLFSSL_SP_INT_NEGATIVE #ifdef WOLFSSL_SP_INT_NEGATIVE
t->sign = (int)((a->sign ^ b->sign) & mask); t->sign = (a->sign ^ b->sign) & mask;
#endif #endif
/* XOR requested words into temp - mask set when swapping. */ /* XOR requested words into temp - mask set when swapping. */
@@ -5430,13 +5430,13 @@ int sp_cnt_lsb(const sp_int* a)
/* Done if not all 4 bits are zero. */ /* Done if not all 4 bits are zero. */
if (cnt != 4) { if (cnt != 4) {
/* Add checked bits and count in last 4 bits checked. */ /* Add checked bits and count in last 4 bits checked. */
bc += j + cnt; bc += j + (unsigned int)cnt;
break; break;
} }
} }
} }
return bc; return (int)bc;
} }
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */ #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
@@ -6758,7 +6758,7 @@ static void _sp_div_2(const sp_int* a, sp_int* r)
/* Last word only needs to be shifted down. */ /* Last word only needs to be shifted down. */
r->dp[i] = a->dp[i] >> 1; r->dp[i] = a->dp[i] >> 1;
/* Set used to be all words seen. */ /* Set used to be all words seen. */
r->used = i + 1; r->used = (unsigned int)i + 1;
/* Remove leading zeros. */ /* Remove leading zeros. */
sp_clamp(r); sp_clamp(r);
#ifdef WOLFSSL_SP_INT_NEGATIVE #ifdef WOLFSSL_SP_INT_NEGATIVE
@@ -7267,7 +7267,7 @@ int sp_addmod(const sp_int* a, const sp_int* b, const sp_int* m, sp_int* r)
{ {
int err = MP_OKAY; int err = MP_OKAY;
/* Calculate used based on digits used in a and b. */ /* Calculate used based on digits used in a and b. */
int used = ((a == NULL) || (b == NULL)) ? 1 : unsigned int used = ((a == NULL) || (b == NULL)) ? 1 :
((a->used >= b->used) ? a->used + 1 : b->used + 1); ((a->used >= b->used) ? a->used + 1 : b->used + 1);
DECL_SP_INT(t, used); DECL_SP_INT(t, used);
@@ -7780,7 +7780,7 @@ static int sp_lshb(sp_int* a, int n)
if (a->used != 0) { if (a->used != 0) {
/* Calculate number of digits to shift. */ /* Calculate number of digits to shift. */
unsigned int s = n >> SP_WORD_SHIFT; unsigned int s = (unsigned int)n >> SP_WORD_SHIFT;
/* Ensure number has enough digits for result. */ /* Ensure number has enough digits for result. */
if (a->used + s >= a->size) { if (a->used + s >= a->size) {
@@ -8757,11 +8757,11 @@ static int _sp_mul_4(const sp_int* a, const sp_int* b, sp_int* r)
w[14] = (sp_int_word)da[3] * db[2]; w[14] = (sp_int_word)da[3] * db[2];
w[15] = (sp_int_word)da[3] * db[3]; w[15] = (sp_int_word)da[3] * db[3];
r->dp[0] = w[0]; r->dp[0] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[1]; w[0] += (sp_int_digit)w[1];
w[0] += (sp_int_digit)w[2]; w[0] += (sp_int_digit)w[2];
r->dp[1] = w[0]; r->dp[1] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[1] >>= SP_WORD_SIZE; w[1] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[1]; w[0] += (sp_int_digit)w[1];
@@ -8770,7 +8770,7 @@ static int _sp_mul_4(const sp_int* a, const sp_int* b, sp_int* r)
w[0] += (sp_int_digit)w[3]; w[0] += (sp_int_digit)w[3];
w[0] += (sp_int_digit)w[4]; w[0] += (sp_int_digit)w[4];
w[0] += (sp_int_digit)w[5]; w[0] += (sp_int_digit)w[5];
r->dp[2] = w[0]; r->dp[2] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[3] >>= SP_WORD_SIZE; w[3] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[3]; w[0] += (sp_int_digit)w[3];
@@ -8782,7 +8782,7 @@ static int _sp_mul_4(const sp_int* a, const sp_int* b, sp_int* r)
w[0] += (sp_int_digit)w[7]; w[0] += (sp_int_digit)w[7];
w[0] += (sp_int_digit)w[8]; w[0] += (sp_int_digit)w[8];
w[0] += (sp_int_digit)w[9]; w[0] += (sp_int_digit)w[9];
r->dp[3] = w[0]; r->dp[3] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[6] >>= SP_WORD_SIZE; w[6] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[6]; w[0] += (sp_int_digit)w[6];
@@ -8795,7 +8795,7 @@ static int _sp_mul_4(const sp_int* a, const sp_int* b, sp_int* r)
w[0] += (sp_int_digit)w[10]; w[0] += (sp_int_digit)w[10];
w[0] += (sp_int_digit)w[11]; w[0] += (sp_int_digit)w[11];
w[0] += (sp_int_digit)w[12]; w[0] += (sp_int_digit)w[12];
r->dp[4] = w[0]; r->dp[4] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[10] >>= SP_WORD_SIZE; w[10] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[10]; w[0] += (sp_int_digit)w[10];
@@ -8805,18 +8805,18 @@ static int _sp_mul_4(const sp_int* a, const sp_int* b, sp_int* r)
w[0] += (sp_int_digit)w[12]; w[0] += (sp_int_digit)w[12];
w[0] += (sp_int_digit)w[13]; w[0] += (sp_int_digit)w[13];
w[0] += (sp_int_digit)w[14]; w[0] += (sp_int_digit)w[14];
r->dp[5] = w[0]; r->dp[5] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[13] >>= SP_WORD_SIZE; w[13] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[13]; w[0] += (sp_int_digit)w[13];
w[14] >>= SP_WORD_SIZE; w[14] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[14]; w[0] += (sp_int_digit)w[14];
w[0] += (sp_int_digit)w[15]; w[0] += (sp_int_digit)w[15];
r->dp[6] = w[0]; r->dp[6] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[15] >>= SP_WORD_SIZE; w[15] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[15]; w[0] += (sp_int_digit)w[15];
r->dp[7] = w[0]; r->dp[7] = (sp_int_digit)w[0];
r->used = 8; r->used = 8;
sp_clamp(r); sp_clamp(r);
@@ -12094,7 +12094,8 @@ int sp_invmod_mont_ct(const sp_int* a, const sp_int* m, sp_int* r,
* One or more of the top bits is 1 so count. * One or more of the top bits is 1 so count.
*/ */
for (i = sp_count_bits(e)-2, j = 1; i >= 0; i--, j++) { for (i = sp_count_bits(e)-2, j = 1; i >= 0; i--, j++) {
if ((!sp_is_bit_set(e, i)) || (j == CT_INV_MOD_PRE_CNT)) { if ((!sp_is_bit_set(e, (unsigned int)i)) ||
(j == CT_INV_MOD_PRE_CNT)) {
break; break;
} }
} }
@@ -12110,7 +12111,7 @@ int sp_invmod_mont_ct(const sp_int* a, const sp_int* m, sp_int* r,
*/ */
for (; (err == MP_OKAY) && (i >= 0); i--) { for (; (err == MP_OKAY) && (i >= 0); i--) {
/* 6.1. bit = e[i] */ /* 6.1. bit = e[i] */
int bit = sp_is_bit_set(e, i); int bit = sp_is_bit_set(e, (unsigned int)i);
/* 6.2. j += bit /* 6.2. j += bit
* Update count of consequitive 1 bits. * Update count of consequitive 1 bits.
@@ -13231,7 +13232,7 @@ static int _sp_exptmod_nct(const sp_int* b, const sp_int* e, const sp_int* m,
/* Top bit of exponent fixed as 1 for pre-calculated window. */ /* Top bit of exponent fixed as 1 for pre-calculated window. */
preCnt = 1 << (winBits - 1); preCnt = 1 << (winBits - 1);
/* Mask for calculating index into pre-computed table. */ /* Mask for calculating index into pre-computed table. */
mask = preCnt - 1; mask = (sp_int_digit)preCnt - 1;
/* Allocate sp_ints for: /* Allocate sp_ints for:
* - pre-computation table * - pre-computation table
@@ -14109,11 +14110,11 @@ static int _sp_sqr_4(const sp_int* a, sp_int* r)
w[8] = (sp_int_word)da[2] * da[3]; w[8] = (sp_int_word)da[2] * da[3];
w[9] = (sp_int_word)da[3] * da[3]; w[9] = (sp_int_word)da[3] * da[3];
r->dp[0] = w[0]; r->dp[0] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[1]; w[0] += (sp_int_digit)w[1];
w[0] += (sp_int_digit)w[1]; w[0] += (sp_int_digit)w[1];
r->dp[1] = w[0]; r->dp[1] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[1] >>= SP_WORD_SIZE; w[1] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[1]; w[0] += (sp_int_digit)w[1];
@@ -14121,7 +14122,7 @@ static int _sp_sqr_4(const sp_int* a, sp_int* r)
w[0] += (sp_int_digit)w[2]; w[0] += (sp_int_digit)w[2];
w[0] += (sp_int_digit)w[2]; w[0] += (sp_int_digit)w[2];
w[0] += (sp_int_digit)w[3]; w[0] += (sp_int_digit)w[3];
r->dp[2] = w[0]; r->dp[2] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[2] >>= SP_WORD_SIZE; w[2] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[2]; w[0] += (sp_int_digit)w[2];
@@ -14132,7 +14133,7 @@ static int _sp_sqr_4(const sp_int* a, sp_int* r)
w[0] += (sp_int_digit)w[4]; w[0] += (sp_int_digit)w[4];
w[0] += (sp_int_digit)w[5]; w[0] += (sp_int_digit)w[5];
w[0] += (sp_int_digit)w[5]; w[0] += (sp_int_digit)w[5];
r->dp[3] = w[0]; r->dp[3] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[4] >>= SP_WORD_SIZE; w[4] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[4]; w[0] += (sp_int_digit)w[4];
@@ -14143,7 +14144,7 @@ static int _sp_sqr_4(const sp_int* a, sp_int* r)
w[0] += (sp_int_digit)w[6]; w[0] += (sp_int_digit)w[6];
w[0] += (sp_int_digit)w[6]; w[0] += (sp_int_digit)w[6];
w[0] += (sp_int_digit)w[7]; w[0] += (sp_int_digit)w[7];
r->dp[4] = w[0]; r->dp[4] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[6] >>= SP_WORD_SIZE; w[6] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[6]; w[0] += (sp_int_digit)w[6];
@@ -14152,17 +14153,17 @@ static int _sp_sqr_4(const sp_int* a, sp_int* r)
w[0] += (sp_int_digit)w[7]; w[0] += (sp_int_digit)w[7];
w[0] += (sp_int_digit)w[8]; w[0] += (sp_int_digit)w[8];
w[0] += (sp_int_digit)w[8]; w[0] += (sp_int_digit)w[8];
r->dp[5] = w[0]; r->dp[5] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[8] >>= SP_WORD_SIZE; w[8] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[8]; w[0] += (sp_int_digit)w[8];
w[0] += (sp_int_digit)w[8]; w[0] += (sp_int_digit)w[8];
w[0] += (sp_int_digit)w[9]; w[0] += (sp_int_digit)w[9];
r->dp[6] = w[0]; r->dp[6] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE; w[0] >>= SP_WORD_SIZE;
w[9] >>= SP_WORD_SIZE; w[9] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[9]; w[0] += (sp_int_digit)w[9];
r->dp[7] = w[0]; r->dp[7] = (sp_int_digit)w[0];
r->used = 8; r->used = 8;
sp_clamp(r); sp_clamp(r);
@@ -16846,7 +16847,7 @@ static void _sp_mont_setup(const sp_int* m, sp_int_digit* rho)
x *= 1 + y; x *= 1 + y;
/* rho = -1/m mod d, subtract x (unsigned) from 0, assign negative */ /* rho = -1/m mod d, subtract x (unsigned) from 0, assign negative */
*rho = (sp_int_digit)((sp_int_digit)0 - (sp_int_sdigit)x); *rho = (sp_int_digit)((sp_int_sdigit)0 - (sp_int_sdigit)x);
} }
/* Calculate the bottom digit of the inverse of negative m. /* Calculate the bottom digit of the inverse of negative m.
@@ -16916,7 +16917,7 @@ int sp_mont_norm(sp_int* norm, const sp_int* m)
} }
/* Smallest number greater than m of form 2^n. */ /* Smallest number greater than m of form 2^n. */
_sp_zero(norm); _sp_zero(norm);
err = sp_set_bit(norm, bits); err = sp_set_bit(norm, (int)bits);
} }
if (err == MP_OKAY) { if (err == MP_OKAY) {
/* norm = 2^n % m */ /* norm = 2^n % m */
@@ -17292,7 +17293,7 @@ static int _sp_read_radix_10(sp_int* a, const char* in)
break; break;
} }
/* Add character value. */ /* Add character value. */
err = _sp_add_d(a, ch, a); err = _sp_add_d(a, (sp_int_digit)ch, a);
if (err != MP_OKAY) { if (err != MP_OKAY) {
break; break;
} }
@@ -17467,7 +17468,7 @@ int sp_tohex(const sp_int* a, char* str)
d = a->dp[i]; d = a->dp[i];
/* Write out all nibbles of digit. */ /* Write out all nibbles of digit. */
for (j = SP_WORD_SIZE - 4; j >= 0; j -= 4) { for (j = SP_WORD_SIZE - 4; j >= 0; j -= 4) {
*(str++) = (byte)ByteToHex((byte)(d >> j)); *(str++) = (char)ByteToHex((byte)(d >> j));
} }
} }
} }
@@ -18265,7 +18266,7 @@ int sp_prime_is_prime_ex(const sp_int* a, int trials, int* result, WC_RNG* rng)
* give a (1/4)^t chance of a false prime. */ * give a (1/4)^t chance of a false prime. */
if ((err == MP_OKAY) && (!haveRes)) { if ((err == MP_OKAY) && (!haveRes)) {
int bits = sp_count_bits(a); int bits = sp_count_bits(a);
word32 baseSz = (bits + 7) / 8; word32 baseSz = ((word32)bits + 7) / 8;
DECL_SP_INT_ARRAY(ds, a->used + 1, 2); DECL_SP_INT_ARRAY(ds, a->used + 1, 2);
DECL_SP_INT_ARRAY(d, a->used * 2 + 1, 2); DECL_SP_INT_ARRAY(d, a->used * 2 + 1, 2);

View File

@@ -96,7 +96,7 @@ int get_digit_count(const mp_int* a)
if (a == NULL) if (a == NULL)
return 0; return 0;
return a->used; return (int)a->used;
} }
mp_digit get_digit(const mp_int* a, int n) mp_digit get_digit(const mp_int* a, int n)
@@ -122,7 +122,7 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
#if defined(SP_WORD_SIZE) && SP_WORD_SIZE == 8 #if defined(SP_WORD_SIZE) && SP_WORD_SIZE == 8
unsigned int mask = (unsigned int)0 - copy; unsigned int mask = (unsigned int)0 - copy;
#else #else
mp_digit mask = (mp_digit)0 - copy; mp_digit mask = (mp_digit)0 - (mp_digit)copy;
#endif #endif
if (a == NULL || b == NULL) if (a == NULL || b == NULL)
@@ -130,7 +130,7 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
/* Ensure b has enough space to copy a into */ /* Ensure b has enough space to copy a into */
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_grow(b, a->used + 1); err = mp_grow(b, (int)a->used + 1);
if (err == MP_OKAY) { if (err == MP_OKAY) {
#if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
unsigned int i; unsigned int i;
@@ -144,15 +144,15 @@ int mp_cond_copy(mp_int* a, int copy, mp_int* b)
* get_digit() returns 0 when index greater than available digit. * get_digit() returns 0 when index greater than available digit.
*/ */
for (i = 0; i < a->used; i++) { for (i = 0; i < a->used; i++) {
b->dp[i] ^= (get_digit(a, i) ^ get_digit(b, i)) & mask; b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
} }
for (; i < b->used; i++) { for (; i < b->used; i++) {
b->dp[i] ^= (get_digit(a, i) ^ get_digit(b, i)) & mask; b->dp[i] ^= (get_digit(a, (int)i) ^ get_digit(b, (int)i)) & mask;
} }
b->used ^= (a->used ^ b->used) & (int)mask; b->used ^= (a->used ^ b->used) & (mp_digit)mask;
#if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \ #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
defined(WOLFSSL_SP_INT_NEGATIVE) defined(WOLFSSL_SP_INT_NEGATIVE)
b->sign ^= (a->sign ^ b->sign) & (int)mask; b->sign ^= (a->sign ^ b->sign) & (mp_digit)mask;
#endif #endif
} }
@@ -171,7 +171,7 @@ int get_rand_digit(WC_RNG* rng, mp_digit* d)
int mp_rand(mp_int* a, int digits, WC_RNG* rng) int mp_rand(mp_int* a, int digits, WC_RNG* rng)
{ {
int ret = 0; int ret = 0;
int cnt = digits * sizeof(mp_digit); int cnt = digits * (int)sizeof(mp_digit);
if (rng == NULL) { if (rng == NULL) {
ret = MISSING_RNG_E; ret = MISSING_RNG_E;
@@ -195,12 +195,12 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng)
ret = BAD_FUNC_ARG; ret = BAD_FUNC_ARG;
} }
if (ret == MP_OKAY) { if (ret == MP_OKAY) {
a->used = digits; a->used = (word32)digits;
} }
#endif #endif
/* fill the data with random bytes */ /* fill the data with random bytes */
if (ret == MP_OKAY) { if (ret == MP_OKAY) {
ret = wc_RNG_GenerateBlock(rng, (byte*)a->dp, cnt); ret = wc_RNG_GenerateBlock(rng, (byte*)a->dp, (word32)cnt);
} }
if (ret == MP_OKAY) { if (ret == MP_OKAY) {
#ifdef USE_INTEGER_HEAP_MATH #ifdef USE_INTEGER_HEAP_MATH
@@ -264,7 +264,8 @@ int wc_export_int(mp_int* mp, byte* buf, word32* len, word32 keySz,
} }
*len = keySz; *len = keySz;
XMEMSET(buf, 0, *len); XMEMSET(buf, 0, *len);
err = mp_to_unsigned_bin(mp, buf + (keySz - mp_unsigned_bin_size(mp))); err = mp_to_unsigned_bin(mp, buf +
(keySz - (word32)mp_unsigned_bin_size(mp)));
} }
return err; return err;

View File

@@ -669,7 +669,7 @@ typedef struct sp_ecc_ctx {
*/ */
#define sp_clamp(a) \ #define sp_clamp(a) \
do { \ do { \
int ii; \ unsigned int ii; \
for (ii = (a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \ for (ii = (a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
} \ } \
(a)->used = ii + 1; \ (a)->used = ii + 1; \
@@ -891,7 +891,7 @@ typedef sp_int_digit mp_digit;
*/ */
MP_API int sp_init(sp_int* a); MP_API int sp_init(sp_int* a);
MP_API int sp_init_size(sp_int* a, int size); MP_API int sp_init_size(sp_int* a, unsigned int size);
MP_API int sp_init_multi(sp_int* n1, sp_int* n2, sp_int* n3, sp_int* n4, MP_API int sp_init_multi(sp_int* n1, sp_int* n2, sp_int* n3, sp_int* n4,
sp_int* n5, sp_int* n6); sp_int* n5, sp_int* n6);
MP_API void sp_free(sp_int* a); MP_API void sp_free(sp_int* a);