Merge pull request #6284 from douzzer/20230410-Wconversion-fixes

20230410-Wconversion-fixes
This commit is contained in:
JacobBarthelmeh
2023-04-12 17:07:24 -06:00
committed by GitHub
21 changed files with 1370 additions and 1219 deletions

View File

@@ -500,19 +500,19 @@
*/
static int bench_all = 1;
/* Cipher algorithms to benchmark. */
static int bench_cipher_algs = 0;
static word32 bench_cipher_algs = 0;
/* Digest algorithms to benchmark. */
static int bench_digest_algs = 0;
static word32 bench_digest_algs = 0;
/* MAC algorithms to benchmark. */
static int bench_mac_algs = 0;
static word32 bench_mac_algs = 0;
/* Asymmetric algorithms to benchmark. */
static int bench_asym_algs = 0;
static word32 bench_asym_algs = 0;
/* Post-Quantum Asymmetric algorithms to benchmark. */
static int bench_pq_asym_algs = 0;
static word32 bench_pq_asym_algs = 0;
/* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
static int bench_pq_asym_algs2 = 0;
static word32 bench_pq_asym_algs2 = 0;
/* Other cryptographic algorithms to benchmark. */
static int bench_other_algs = 0;
static word32 bench_other_algs = 0;
#if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
@@ -907,10 +907,10 @@ static const char* bench_desc_words[][15] = {
#define SHOW_INTEL_CYCLES(b, n, s) \
(void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), " %s = %6.2f\n", \
bench_result_words1[lng_index][2], \
count == 0 ? 0 : (float)total_cycles / ((word64)count*(s)))
count == 0 ? 0 : (double)total_cycles / ((word64)count*(s)))
#define SHOW_INTEL_CYCLES_CSV(b, n, s) \
(void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), "%.6f,\n", \
count == 0 ? 0 : (float)total_cycles / ((word64)count*(s)))
count == 0 ? 0 : (double)total_cycles / ((word64)count*(s)))
#elif defined(LINUX_CYCLE_COUNT)
#include <linux/perf_event.h>
#include <sys/syscall.h>
@@ -1323,15 +1323,15 @@ static const char* bench_result_words2[][5] = {
while(options) {
if (options & AAD_SIZE_DEFAULT) {
aesAuthAddSz = AES_AUTH_ADD_SZ;
options &= ~AAD_SIZE_DEFAULT;
options &= ~(word32)AAD_SIZE_DEFAULT;
}
else if (options & AAD_SIZE_ZERO) {
aesAuthAddSz = 0;
options &= ~AAD_SIZE_ZERO;
options &= ~(word32)AAD_SIZE_ZERO;
}
else if (options & AAD_SIZE_CUSTOM) {
aesAuthAddSz = aes_aad_size;
options &= ~AAD_SIZE_CUSTOM;
options &= ~(word32)AAD_SIZE_CUSTOM;
}
fn(i);
aesAuthAddSz = aesAuthAddSz_orig;
@@ -1754,7 +1754,7 @@ static const char* get_blocktype_base10(double* blocks)
/* countSz is number of bytes that 1 count represents. Normally bench_size,
* except for AES direct that operates on AES_BLOCK_SIZE blocks */
static void bench_stats_sym_finish(const char* desc, int useDeviceID,
int count, int countSz,
int count, word32 countSz,
double start, int ret)
{
double total, persec = 0, blocks = (double)count;
@@ -1880,7 +1880,7 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
ESP_LOGV(TAG, "finish total_cycles = %llu", total_cycles);
/* implement other cycle counters here */
#else
SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), countSz);
SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
#endif
} /* if (csv_format == 1) */
@@ -1913,7 +1913,7 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
/* implement other architecture cycle counters here */
#else
SHOW_INTEL_CYCLES(msg, sizeof(msg), countSz);
SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
#endif
} /* not CSV format */
@@ -3658,7 +3658,7 @@ static void bench_aesecb_internal(int useDeviceID,
bench_stats_start(&count, &start);
do {
int outer_loop_limit = ((bench_size / benchSz) * 10) + 1;
int outer_loop_limit = (((int)bench_size / benchSz) * 10) + 1;
for (times = 0;
times < outer_loop_limit /* numBlocks */ || pending > 0;
) {
@@ -3700,7 +3700,7 @@ exit_aes_enc:
bench_stats_start(&count, &start);
do {
int outer_loop_limit = (10 * (bench_size / benchSz)) + 1;
int outer_loop_limit = (10 * ((int)bench_size / benchSz)) + 1;
for (times = 0; times < outer_loop_limit || pending > 0; ) {
bench_async_poll(&pending);
@@ -5835,7 +5835,7 @@ void bench_blake2s(void)
#ifdef WOLFSSL_CMAC
static void bench_cmac_helper(int keySz, const char* outMsg, int useDeviceID)
static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
{
Cmac cmac;
byte digest[AES_BLOCK_SIZE];
@@ -6180,7 +6180,7 @@ void bench_siphash(void)
#ifndef NO_RSA
#if defined(WOLFSSL_KEY_GEN)
static void bench_rsaKeyGen_helper(int useDeviceID, int keySz)
static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
{
RsaKey genKey[BENCH_MAX_PENDING];
double start;
@@ -6207,7 +6207,8 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz)
goto exit;
}
ret = wc_MakeRsaKey(&genKey[i], keySz, rsa_e_val, &gRng);
ret = wc_MakeRsaKey(&genKey[i], (int)keySz, rsa_e_val,
&gRng);
if (!bench_async_handle(&ret,
BENCH_ASYNC_GET_DEV(&genKey[i]), 0,
&times, &pending)) {
@@ -6219,7 +6220,7 @@ static void bench_rsaKeyGen_helper(int useDeviceID, int keySz)
count += times;
} while (bench_stats_check(start));
exit:
bench_stats_asym_finish("RSA", keySz, desc[2], useDeviceID, count,
bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
start, ret);
/* cleanup */
@@ -6232,19 +6233,18 @@ void bench_rsaKeyGen(int useDeviceID)
{
int k;
#if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
const int keySizes[2] = {1024, 2048};
static const word32 keySizes[2] = {1024, 2048};
#else
const int keySizes[1] = {2048};
static const word32 keySizes[1] = {2048};
#endif
for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
int keySz = keySizes[k];
bench_rsaKeyGen_helper(useDeviceID, keySz);
bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
}
}
void bench_rsaKeyGen_size(int useDeviceID, int keySz)
void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
{
bench_rsaKeyGen_helper(useDeviceID, keySz);
}
@@ -6358,7 +6358,7 @@ static unsigned char rsa_3072_sig[] = {
#endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING],
int rsaKeySz)
word32 rsaKeySz)
{
int ret = 0, i, times, count = 0, pending = 0;
word32 idx = 0;
@@ -6437,7 +6437,7 @@ static void bench_rsa_helper(int useDeviceID, RsaKey rsaKey[BENCH_MAX_PENDING],
count += times;
} while (bench_stats_check(start));
exit_rsa_verify:
bench_stats_asym_finish("RSA", rsaKeySz, desc[0],
bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
useDeviceID, count, start, ret);
#endif /* !WOLFSSL_RSA_VERIFY_ONLY */
@@ -6473,7 +6473,7 @@ exit_rsa_verify:
count += times;
} while (bench_stats_check(start));
exit_rsa_pub:
bench_stats_asym_finish("RSA", rsaKeySz, desc[1],
bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
useDeviceID, count, start, ret);
#endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
}
@@ -6503,7 +6503,7 @@ exit_rsa_pub:
count += times;
} while (bench_stats_check(start));
exit_rsa_sign:
bench_stats_asym_finish("RSA", rsaKeySz, desc[4], useDeviceID,
bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
count, start, ret);
if (ret < 0) {
@@ -6560,7 +6560,7 @@ exit_rsa_sign:
} while (bench_stats_check(start));
exit_rsa_verifyinline:
bench_stats_asym_finish("RSA", rsaKeySz, desc[5],
bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
useDeviceID, count, start, ret);
}
@@ -6580,7 +6580,7 @@ void bench_rsa(int useDeviceID)
int i;
RsaKey rsaKey[BENCH_MAX_PENDING];
int ret = 0;
int rsaKeySz = 0;
word32 rsaKeySz = 0;
const byte* tmp;
size_t bytes;
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
@@ -6675,7 +6675,7 @@ exit_bench_rsa:
#ifdef WOLFSSL_KEY_GEN
/* bench any size of RSA key */
void bench_rsa_key(int useDeviceID, int rsaKeySz)
void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
{
int ret = 0, i, pending = 0;
RsaKey rsaKey[BENCH_MAX_PENDING];
@@ -6706,7 +6706,7 @@ void bench_rsa_key(int useDeviceID, int rsaKeySz)
}
/* create the RSA key */
ret = wc_MakeRsaKey(&rsaKey[i], rsaKeySz, exp, &gRng);
ret = wc_MakeRsaKey(&rsaKey[i], (int)rsaKeySz, exp, &gRng);
if (ret == WC_PENDING_E) {
isPending[i] = 1;
pending = 1;
@@ -7495,7 +7495,7 @@ void bench_eccEncrypt(int curveId)
goto exit;
for (i = 0; i < (int)sizeof(msg); i++)
msg[i] = i;
msg[i] = (byte)i;
bench_stats_start(&count, &start);
do {
@@ -8931,12 +8931,12 @@ void bench_sphincsKeySign(byte level, byte optim)
#endif /* HAVE_GET_CYCLES */
void benchmark_configure(int block_size)
void benchmark_configure(word32 block_size)
{
/* must be greater than 0 */
if (block_size > 0) {
numBlocks = numBlocks * bench_size / block_size;
bench_size = (word32)block_size;
numBlocks = (int)((word32)numBlocks * bench_size / block_size);
bench_size = block_size;
}
}
@@ -9065,8 +9065,7 @@ static void Usage(void)
*/
static int string_matches(const char* arg, const char* str)
{
int len = (int)XSTRLEN(str) + 1;
return XSTRNCMP(arg, str, len) == 0;
return XSTRCMP(arg, str) == 0;
}
#endif /* MAIN_NO_ARGS */
@@ -9156,7 +9155,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv)
argc--;
argv++;
if (argc > 1) {
aes_aad_size = XATOI(argv[1]);
aes_aad_size = (word32)XATOI(argv[1]);
aes_aad_options |= AAD_SIZE_CUSTOM;
}
}
@@ -9298,7 +9297,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv)
}
else {
/* parse for block size */
benchmark_configure(XATOI(argv[1]));
benchmark_configure((word32)XATOI(argv[1]));
}
argc--;
argv++;

View File

@@ -43,7 +43,7 @@ int wolfcrypt_benchmark_main(int argc, char** argv);
/* individual benchmarks */
int benchmark_init(void);
int benchmark_free(void);
void benchmark_configure(int block_size);
void benchmark_configure(word32 block_size);
void bench_des(int useDeviceID);
void bench_arc4(int useDeviceID);
@@ -92,9 +92,9 @@ void bench_hmac_sha384(int useDeviceID);
void bench_hmac_sha512(int useDeviceID);
void bench_siphash(void);
void bench_rsaKeyGen(int useDeviceID);
void bench_rsaKeyGen_size(int useDeviceID, int keySz);
void bench_rsaKeyGen_size(int useDeviceID, word32 keySz);
void bench_rsa(int useDeviceID);
void bench_rsa_key(int useDeviceID, int keySz);
void bench_rsa_key(int useDeviceID, word32 keySz);
void bench_dh(int useDeviceID);
void bench_kyber(int type);
void bench_ecc_curve(int curveId);

View File

@@ -2893,7 +2893,7 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
aes->left = 0;
#endif
aes->keylen = keylen;
aes->keylen = (int)keylen;
aes->rounds = (keylen/4) + 6;
#ifdef WOLFSSL_AESNI
@@ -4564,7 +4564,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
{
int i;
for (i = ctrSz-1; i >= 0; i--) {
for (i = (int)ctrSz - 1; i >= 0; i--) {
if (++ctr[i])
break;
}
@@ -4683,12 +4683,12 @@ static void GenerateM0(Aes* aes)
#elif defined(GCM_TABLE_4BIT)
#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;
for (i = 15; i > 0; i--)
r8[i] = (z8[i-1] << 4) | (z8[i] >> 4);
r8[0] = z8[0] >> 4;
r8[i] = (byte)(z8[i-1] << 4) | (byte)(z8[i] >> 4);
r8[0] = (byte)(z8[0] >> 4);
}
#endif
@@ -7165,7 +7165,7 @@ int WARN_UNUSED_RESULT AES_GCM_decrypt_C(
/* ConstantCompare returns the cumulative bitwise or of the bitwise xor of
* 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
* constant time.
*/
@@ -8571,7 +8571,7 @@ int wc_AesGcmSetExtIV(Aes* aes, const byte* iv, word32 ivSz)
{
int ret = 0;
if (aes == NULL || iv == NULL || !CheckAesGcmIvSize(ivSz)) {
if (aes == NULL || iv == NULL || !CheckAesGcmIvSize((int)ivSz)) {
ret = BAD_FUNC_ARG;
}
@@ -8599,7 +8599,7 @@ int wc_AesGcmSetIV(Aes* aes, word32 ivSz,
{
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 != AES_IV_FIXED_SZ)) {

File diff suppressed because it is too large Load Diff

View File

@@ -228,8 +228,8 @@ ECC Curve Sizes:
#define MAX_ECC_BITS_USE MAX_ECC_BITS_NEEDED
#endif
#define ECC_KEY_MAX_BITS(key) \
(((key == NULL) || (key->dp == NULL)) ? MAX_ECC_BITS_USE \
: (key->dp->size * 8))
((((key) == NULL) || ((key)->dp == NULL)) ? MAX_ECC_BITS_USE \
: (unsigned)((key)->dp->size * 8))
/* forward declarations */
static int wc_ecc_new_point_ex(ecc_point** point, void* heap);
@@ -3020,7 +3020,7 @@ static int ecc_mulmod(const mp_int* k, ecc_point* P, ecc_point* Q,
err = mp_copy(k, kt);
}
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 */
for (i = 1; (err == MP_OKAY) && (i < t); i++) {
@@ -3040,13 +3040,13 @@ static int ecc_mulmod(const mp_int* k, ecc_point* P, ecc_point* Q,
}
#else
/* Swap R[0] and R[1] if other index is needed. */
swap ^= b;
swap ^= (int)b;
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)
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)
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;
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 ^= 1;
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)
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)
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
/* 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);
#else
/* 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)
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)
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)
err = ecc_projective_add_point_safe(R[0], R[2], R[0], a, modulus,
mp, &infinity);
/* Swap back if necessary. */
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)
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)
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
}
@@ -4584,7 +4584,7 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
#ifdef WOLFSSL_NO_MALLOC
ecc_point lcl_result;
#endif
word32 x = 0;
int x = 0;
mp_digit mp = 0;
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) {
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;
}
}
if (err == MP_OKAY) {
XMEMSET(out, 0, x);
err = mp_to_unsigned_bin(result->x,out +
XMEMSET(out, 0, (size_t)x);
err = mp_to_unsigned_bin(result->x, out +
(x - mp_unsigned_bin_size(result->x)));
}
*outlen = x;
*outlen = (word32)x;
mp_forcezero(result->x);
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;
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) {
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;
/* make up random string */
err = wc_RNG_GenerateBlock(rng, buf, size);
err = wc_RNG_GenerateBlock(rng, buf, (word32)size);
#ifdef WOLFSSL_CHECK_MEM_ZERO
wc_MemZero_Add("wc_ecc_gen_k buf", buf, size);
#endif
/* load random buffer data into k */
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 */
if (err == MP_OKAY) {
@@ -5285,7 +5285,7 @@ static int _ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key,
return err;
}
key->flags = flags;
key->flags = (byte)flags;
#ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) {
@@ -5870,7 +5870,7 @@ int wc_ecc_init_id(ecc_key* key, unsigned char* id, int len, void* heap,
if (ret == 0)
ret = wc_ecc_init_ex(key, heap, devId);
if (ret == 0 && id != NULL && len != 0) {
XMEMCPY(key->id, id, len);
XMEMCPY(key->id, id, (size_t)len);
key->idLen = len;
#ifdef WOLFSSL_SE050
/* Set SE050 ID from word32, populate ecc_key with public from SE050 */
@@ -5900,7 +5900,7 @@ int wc_ecc_init_label(ecc_key* key, const char* label, void* heap, int devId)
if (ret == 0)
ret = wc_ecc_init_ex(key, heap, devId);
if (ret == 0) {
XMEMCPY(key->label, label, labelLen);
XMEMCPY(key->label, label, (size_t)labelLen);
key->labelLen = labelLen;
}
@@ -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)
{
int err = MP_OKAY;
word32 orderBits;
int orderBits;
DECLARE_CURVE_SPECS(1);
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);
FREE_CURVE_SPECS();
return (int)orderBits;
return orderBits;
}
#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 */
if (err == MP_OKAY) {
/* 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 */
if ((WOLFSSL_BIT_SIZE * inlen) > orderBits)
@@ -7133,7 +7133,7 @@ int wc_ecc_gen_deterministic_k(const byte* hash, word32 hashSz,
#endif
VSz = KSz = hashSz;
qLen = xSz = h1len = mp_unsigned_bin_size(order);
qLen = xSz = h1len = (word32)mp_unsigned_bin_size(order);
/* 3.2 b. Set V = 0x01 0x01 ... */
XMEMSET(V, 0x01, VSz);
@@ -7142,7 +7142,7 @@ int wc_ecc_gen_deterministic_k(const byte* hash, word32 hashSz,
XMEMSET(K, 0x00, KSz);
mp_init(z1); /* always init z1 and free z1 */
ret = mp_to_unsigned_bin_len(priv, x, qLen);
ret = mp_to_unsigned_bin_len(priv, x, (int)qLen);
if (ret == 0) {
#ifdef WOLFSSL_CHECK_MEM_ZERO
wc_MemZero_Add("wc_ecc_gen_deterministic_k x", x, qLen);
@@ -7176,7 +7176,7 @@ int wc_ecc_gen_deterministic_k(const byte* hash, word32 hashSz,
#endif
{
/* use original hash and keep leading 0's */
mp_to_unsigned_bin_len(z1, h1, h1len);
mp_to_unsigned_bin_len(z1, h1, (int)h1len);
}
}
mp_free(z1);
@@ -7224,9 +7224,9 @@ int wc_ecc_gen_deterministic_k(const byte* hash, word32 hashSz,
if (ret == 0) {
int sz;
sz = MIN(qLen - xSz, VSz);
XMEMCPY(x + xSz, V, sz);
xSz += sz;
sz = (int)MIN(qLen - xSz, (size_t)VSz);
XMEMCPY(x + xSz, V, (size_t)sz);
xSz += (word32)sz;
}
else {
break; /* error case */
@@ -7241,7 +7241,7 @@ int wc_ecc_gen_deterministic_k(const byte* hash, word32 hashSz,
if ((ret == 0) && ((int)(xSz * WOLFSSL_BIT_SIZE) != qbits)) {
/* handle odd case where shift of 'k' is needed with RFC 6979
* k = bits2int(T) in section 3.2 h.3 */
mp_rshb(k, (xSz * WOLFSSL_BIT_SIZE) - qbits);
mp_rshb(k, ((int)xSz * WOLFSSL_BIT_SIZE) - qbits);
}
/* 3.2 step h.3 the key should be smaller than the order of base
@@ -7297,7 +7297,7 @@ int wc_ecc_set_deterministic(ecc_key* key, byte flag)
return BAD_FUNC_ARG;
}
key->deterministic = flag;
key->deterministic = flag ? 1 : 0;
return 0;
}
#endif /* end sign_ex and deterministic sign */
@@ -7656,7 +7656,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
ecc_point lcl_precomp[SHAMIR_PRECOMP_SZ];
#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
unsigned char tA[ECC_BUFSIZE];
unsigned char tB[ECC_BUFSIZE];
@@ -7750,8 +7750,8 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
#endif
/* get sizes */
lenA = mp_unsigned_bin_size(kA);
lenB = mp_unsigned_bin_size(kB);
lenA = (unsigned int)mp_unsigned_bin_size(kA);
lenB = (unsigned int)mp_unsigned_bin_size(kB);
len = MAX(lenA, lenB);
/* sanity check */
@@ -7863,7 +7863,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
/* if not both zero */
if ((nA != 0) || (nB != 0)) {
int i = nA + (nB<<2);
unsigned int i = nA + (nB<<2);
if (first == 1) {
/* if first, copy from table */
first = 0;
@@ -8110,6 +8110,8 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash,
}
#endif /* !NO_ASN */
#ifndef WOLF_CRYPTO_CB_ONLY_ECC
#if !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_PSOC6_CRYPTO) && \
!defined(WOLF_CRYPTO_CB_ONLY_ECC)
static int wc_ecc_check_r_s_range(ecc_key* key, mp_int* r, mp_int* s)
@@ -8142,7 +8144,6 @@ static int wc_ecc_check_r_s_range(ecc_key* key, mp_int* r, mp_int* s)
}
#endif /* !WOLFSSL_STM32_PKA && !WOLFSSL_PSOC6_CRYPTO */
#ifndef WOLF_CRYPTO_CB_ONLY_ECC
static int ecc_verify_hash_sp(mp_int *r, mp_int *s, const byte* hash,
word32 hashlen, int* res, ecc_key* key)
{
@@ -8333,7 +8334,7 @@ static int ecc_verify_hash(mp_int *r, mp_int *s, const byte* hash,
/* read hash */
if (err == MP_OKAY) {
/* we may need to truncate if hash is longer than key size */
unsigned int orderBits = mp_count_bits(curve->order);
unsigned int orderBits = (unsigned int)mp_count_bits(curve->order);
/* truncate down to byte size, may be all that's needed */
if ( (WOLFSSL_BIT_SIZE * hashlen) > orderBits)
@@ -8581,7 +8582,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
return err;
}
keySz = key->dp->size;
keySz = (word32)key->dp->size;
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) && \
defined(WOLFSSL_ASYNC_CRYPT_SW)
@@ -8830,14 +8831,14 @@ int wc_ecc_import_point_der_ex(const byte* in, word32 inLen,
/* calculate key size based on inLen / 2 if uncompressed or shortKeySize
* is true */
#ifdef HAVE_COMP_KEY
keysize = compressed && !shortKeySize ? inLen : inLen>>1;
keysize = (int)((compressed && !shortKeySize) ? inLen : inLen>>1);
#else
keysize = inLen>>1;
keysize = (int)(inLen>>1);
#endif
/* read data */
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
if (err == MP_OKAY && compressed == 1) { /* build y */
@@ -8980,7 +8981,7 @@ int wc_ecc_import_point_der_ex(const byte* in, word32 inLen,
#ifdef HAVE_COMP_KEY
if (compressed == 0)
#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)
err = mp_set(point->z, 1);
@@ -9034,7 +9035,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))
return ECC_BAD_ARG_E;
numlen = ecc_sets[curve_idx].size;
numlen = (word32)ecc_sets[curve_idx].size;
/* return length needed only */
if (point != NULL && out == NULL && outLen != NULL) {
@@ -9068,7 +9069,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
/* pad and store x */
XMEMSET(buf, 0, ECC_BUFSIZE);
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)
goto done;
XMEMCPY(out+1, buf, numlen);
@@ -9076,7 +9077,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
/* pad and store y */
XMEMSET(buf, 0, ECC_BUFSIZE);
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)
goto done;
XMEMCPY(out+1+numlen, buf, numlen);
@@ -9109,7 +9110,7 @@ int wc_ecc_export_point_der_compressed(const int curve_idx, ecc_point* point,
if ((curve_idx < 0) || (wc_ecc_is_valid_idx(curve_idx) == 0))
return ECC_BAD_ARG_E;
numlen = ecc_sets[curve_idx].size;
numlen = (word32)ecc_sets[curve_idx].size;
output_len = 1 + numlen; /* y point type + x */
/* return length needed only */
@@ -9145,7 +9146,7 @@ int wc_ecc_export_point_der_compressed(const int curve_idx, ecc_point* point,
/* pad and store x */
XMEMSET(buf, 0, ECC_BUFSIZE);
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)
goto done;
XMEMCPY(out+1, buf, numlen);
@@ -9177,8 +9178,8 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
/* return length needed only */
if (key != NULL && out == NULL && outLen != NULL) {
/* if key hasn't been setup assume max bytes for size estimation */
numlen = key->dp ? key->dp->size : MAX_ECC_BYTES;
*outLen = 1 + 2*numlen;
numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
*outLen = 1 + 2 * numlen;
return LENGTH_ONLY_E;
}
@@ -9208,7 +9209,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
return ECC_BAD_ARG_E;
}
numlen = key->dp->size;
numlen = (word32)key->dp->size;
/* verify room in out buffer */
if (*outLen < (1 + 2*numlen)) {
@@ -9217,8 +9218,8 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
}
/* verify public key length is less than key size */
pubxlen = mp_unsigned_bin_size(key->pubkey.x);
pubylen = mp_unsigned_bin_size(key->pubkey.y);
pubxlen = (word32)mp_unsigned_bin_size(key->pubkey.x);
pubylen = (word32)mp_unsigned_bin_size(key->pubkey.y);
if ((pubxlen > numlen) || (pubylen > numlen)) {
WOLFSSL_MSG("Public key x/y invalid!");
return BUFFER_E;
@@ -10049,14 +10050,14 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
#endif
/* determine key size */
keysize = (inLen>>1);
keysize = (int)(inLen>>1);
err = wc_ecc_set_curve(key, keysize, curve_id);
key->type = ECC_PUBLICKEY;
}
/* read data */
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
if (err == MP_OKAY && compressed == 1) { /* build y */
@@ -10192,7 +10193,8 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
if (compressed == 0)
#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)
@@ -10280,7 +10282,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) {
return ECC_BAD_ARG_E;
}
keySz = key->dp->size;
keySz = (word32)key->dp->size;
/* private key, d */
if (d != NULL) {
@@ -10437,7 +10439,7 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
wc_ecc_reset(key);
/* 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;
}
@@ -10771,7 +10773,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);
else
err = mp_read_unsigned_bin(key->pubkey.x, (const byte*)qx,
key->dp->size);
(word32)key->dp->size);
if (mp_isneg(key->pubkey.x)) {
WOLFSSL_MSG("Invalid Qx");
@@ -10788,7 +10790,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);
else
err = mp_read_unsigned_bin(key->pubkey.y, (const byte*)qy,
key->dp->size);
(word32)key->dp->size);
if (mp_isneg(key->pubkey.y)) {
WOLFSSL_MSG("Invalid Qy");
@@ -10946,7 +10948,7 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
#endif /* WOLFSSL_QNX_CAAM */
{
err = mp_read_unsigned_bin(&key->k, (const byte*)d,
key->dp->size);
(word32)key->dp->size);
}
}
#if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
@@ -11077,7 +11079,7 @@ static int ecc_public_key_size(ecc_key* key, word32* sz)
return BAD_FUNC_ARG;
/* 'Uncompressed' | x | y */
*sz = 1 + 2 * key->dp->size;
*sz = 1 + 2 * (word32)key->dp->size;
return 0;
}
@@ -11724,8 +11726,7 @@ static const struct {
/* find a hole and free as required, return -1 if no hole found */
static int find_hole(void)
{
unsigned x;
int y, z;
int x, y, z;
for (z = -1, y = INT_MAX, x = 0; x < FP_ENTRIES; x++) {
if (fp_cache[x].lru_count < y && fp_cache[x].lock == 0) {
z = x;
@@ -11745,7 +11746,7 @@ static int find_hole(void)
mp_clear(&fp_cache[z].mu);
wc_ecc_del_point(fp_cache[z].g);
fp_cache[z].g = NULL;
for (x = 0; x < (1U<<FP_LUT); x++) {
for (x = 0; x < (1<<FP_LUT); x++) {
wc_ecc_del_point(fp_cache[z].LUT[x]);
fp_cache[z].LUT[x] = NULL;
}
@@ -11851,7 +11852,7 @@ static int build_lut(int idx, mp_int* a, mp_int* modulus, mp_digit mp,
}
/* get bitlen and round up to next multiple of FP_LUT */
bitlen = mp_unsigned_bin_size(modulus) << 3;
bitlen = (unsigned)mp_unsigned_bin_size(modulus) << 3;
x = bitlen % FP_LUT;
if (x) {
bitlen += FP_LUT - x;
@@ -12026,7 +12027,7 @@ static int accel_fp_mul(int idx, const mp_int* k, ecc_point *R, mp_int* a,
/* if it's smaller than modulus we fine */
if (mp_unsigned_bin_size(k) > mp_unsigned_bin_size(modulus)) {
/* find order */
y = mp_unsigned_bin_size(modulus);
y = (unsigned)mp_unsigned_bin_size(modulus);
for (x = 0; ecc_sets[x].size; x++) {
if (y <= (unsigned)ecc_sets[x].size) break;
}
@@ -12048,10 +12049,10 @@ static int accel_fp_mul(int idx, const mp_int* k, ecc_point *R, mp_int* a,
}
/* get bitlen and round up to next multiple of FP_LUT */
bitlen = mp_unsigned_bin_size(modulus) << 3;
bitlen = (unsigned)mp_unsigned_bin_size(modulus) << 3;
x = bitlen % FP_LUT;
if (x) {
bitlen += FP_LUT - x;
bitlen += FP_LUT - (unsigned)x;
}
lut_gap = bitlen / FP_LUT;
@@ -12075,7 +12076,7 @@ static int accel_fp_mul(int idx, const mp_int* k, ecc_point *R, mp_int* a,
#endif
/* let's reverse kb so it's little endian */
x = 0;
y = mp_unsigned_bin_size(tk);
y = (unsigned)mp_unsigned_bin_size(tk);
if (y > 0) {
y -= 1;
}
@@ -12087,10 +12088,10 @@ static int accel_fp_mul(int idx, const mp_int* k, ecc_point *R, mp_int* a,
/* at this point we can start, yipee */
first = 1;
for (x = lut_gap-1; x >= 0; x--) {
for (x = (int)lut_gap-1; x >= 0; x--) {
/* extract FP_LUT bits from kb spread out by lut_gap bits and offset
by x bits from the start */
bitpos = x;
bitpos = (unsigned)x;
for (y = z = 0; y < FP_LUT; y++) {
z |= ((kb[bitpos>>3] >> (bitpos&7)) & 1) << y;
bitpos += lut_gap; /* it's y*lut_gap + x, but here we can avoid
@@ -12205,7 +12206,7 @@ static int accel_fp_mul2add(int idx1, int idx2,
/* if it's smaller than modulus we fine */
if (mp_unsigned_bin_size(kA) > mp_unsigned_bin_size(modulus)) {
/* find order */
y = mp_unsigned_bin_size(modulus);
y = (unsigned)mp_unsigned_bin_size(modulus);
for (x = 0; ecc_sets[x].size; x++) {
if (y <= (unsigned)ecc_sets[x].size) break;
}
@@ -12240,7 +12241,7 @@ static int accel_fp_mul2add(int idx1, int idx2,
/* if it's smaller than modulus we fine */
if (mp_unsigned_bin_size(kB) > mp_unsigned_bin_size(modulus)) {
/* find order */
y = mp_unsigned_bin_size(modulus);
y = (unsigned)mp_unsigned_bin_size(modulus);
for (x = 0; ecc_sets[x].size; x++) {
if (y <= (unsigned)ecc_sets[x].size) break;
}
@@ -12273,10 +12274,10 @@ static int accel_fp_mul2add(int idx1, int idx2,
#endif
/* get bitlen and round up to next multiple of FP_LUT */
bitlen = mp_unsigned_bin_size(modulus) << 3;
bitlen = (unsigned)mp_unsigned_bin_size(modulus) << 3;
x = bitlen % FP_LUT;
if (x) {
bitlen += FP_LUT - x;
bitlen += FP_LUT - (unsigned)x;
}
lut_gap = bitlen / FP_LUT;
@@ -12304,7 +12305,7 @@ static int accel_fp_mul2add(int idx1, int idx2,
/* let's reverse kb so it's little endian */
x = 0;
y = mp_unsigned_bin_size(tka);
y = (unsigned)mp_unsigned_bin_size(tka);
if (y > 0) {
y -= 1;
}
@@ -12328,7 +12329,7 @@ static int accel_fp_mul2add(int idx1, int idx2,
#endif
if ((err = mp_to_unsigned_bin(tkb, kb[1])) == MP_OKAY) {
x = 0;
y = mp_unsigned_bin_size(tkb);
y = (unsigned)mp_unsigned_bin_size(tkb);
if (y > 0) {
y -= 1;
}
@@ -12340,10 +12341,10 @@ static int accel_fp_mul2add(int idx1, int idx2,
/* at this point we can start, yipee */
first = 1;
for (x = lut_gap-1; x >= 0; x--) {
for (x = (int)lut_gap-1; x >= 0; x--) {
/* extract FP_LUT bits from kb spread out by lut_gap bits and
offset by x bits from the start */
bitpos = x;
bitpos = (unsigned)x;
for (y = zA = zB = 0; y < FP_LUT; y++) {
zA |= ((kb[0][bitpos>>3] >> (bitpos&7)) & 1) << y;
zB |= ((kb[1][bitpos>>3] >> (bitpos&7)) & 1) << y;
@@ -13099,7 +13100,7 @@ int wc_ecc_ctx_set_info(ecEncCtx* ctx, const byte* info, int sz)
return BAD_FUNC_ARG;
ctx->kdfInfo = info;
ctx->kdfInfoSz = sz;
ctx->kdfInfoSz = (word32)sz;
return 0;
}
@@ -13136,9 +13137,9 @@ int wc_ecc_ctx_set_peer_salt(ecEncCtx* ctx, const byte* salt)
/* mix half and half */
/* tmp stores 2nd half of client before overwrite */
XMEMCPY(tmp, ctx->clientSalt + halfSz, halfSz);
XMEMCPY(ctx->clientSalt + halfSz, ctx->serverSalt, halfSz);
XMEMCPY(ctx->serverSalt, tmp, halfSz);
XMEMCPY(tmp, ctx->clientSalt + halfSz, (size_t)halfSz);
XMEMCPY(ctx->clientSalt + halfSz, ctx->serverSalt, (size_t)halfSz);
XMEMCPY(ctx->serverSalt, tmp, (size_t)halfSz);
ctx->kdfSalt = ctx->clientSalt;
ctx->kdfSaltSz = EXCHANGE_SALT_SZ;
@@ -13324,9 +13325,9 @@ static int ecc_get_key_sizes(ecEncCtx* ctx, int* encKeySz, int* ivSz,
return BAD_FUNC_ARG;
#ifdef WOLFSSL_ECIES_OLD
*keysLen = *encKeySz + *ivSz + *digestSz;
*keysLen = *encKeySz + *ivSz + (int)*digestSz;
#else
*keysLen = *encKeySz + *digestSz;
*keysLen = *encKeySz + (int)*digestSz;
#endif
return 0;
@@ -13391,10 +13392,10 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
#ifndef WOLFSSL_ECIES_OLD
if (!compressed) {
pubKeySz = 1 + wc_ecc_size(privKey) * 2;
pubKeySz = 1 + (word32)wc_ecc_size(privKey) * 2;
}
else {
pubKeySz = 1 + wc_ecc_size(privKey);
pubKeySz = 1 + (word32)wc_ecc_size(privKey);
}
#else
(void) compressed; /* avoid unused parameter if WOLFSSL_ECIES_OLD is defined */
@@ -13495,7 +13496,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
case ecHKDF_SHA256 :
ret = wc_HKDF(WC_SHA256, sharedSecret, sharedSz, ctx->kdfSalt,
ctx->kdfSaltSz, ctx->kdfInfo, ctx->kdfInfoSz,
keys, keysLen);
keys, (word32)keysLen);
break;
default:
@@ -13516,7 +13517,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
macKey = encKey + encKeySz;
ret = wc_RNG_GenerateBlock(privKey->rng, encIv, ivSz);
#else
XMEMSET(iv, 0, ivSz);
XMEMSET(iv, 0, (size_t)ivSz);
encKey = keys + offset;
encIv = iv;
macKey = encKey + encKeySz;
@@ -13541,7 +13542,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
#endif
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) {
ret = wc_AesSetKey(aes, encKey, encKeySz, encIv,
ret = wc_AesSetKey(aes, encKey, (word32)encKeySz, encIv,
AES_ENCRYPTION);
if (ret == 0) {
ret = wc_AesCbcEncrypt(aes, out, msg, msgSz);
@@ -13584,7 +13585,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) {
ret = wc_AesSetKey(aes, encKey, encKeySz, ctr_iv,
ret = wc_AesSetKey(aes, encKey, (word32)encKeySz, ctr_iv,
AES_ENCRYPTION);
if (ret == 0) {
ret = wc_AesCtrEncrypt(aes, out, msg, msgSz);
@@ -13890,7 +13891,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
case ecHKDF_SHA256 :
ret = wc_HKDF(WC_SHA256, sharedSecret, sharedSz, ctx->kdfSalt,
ctx->kdfSaltSz, ctx->kdfInfo, ctx->kdfInfoSz,
keys, keysLen);
keys, (word32)keysLen);
break;
default:
@@ -13911,7 +13912,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
msgSz -= ivSz;
macKey = encKey + encKeySz;
#else
XMEMSET(iv, 0, ivSz);
XMEMSET(iv, 0, (size_t)ivSz);
encKey = keys + offset;
encIv = iv;
macKey = encKey + encKeySz;
@@ -13984,7 +13985,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
#endif
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) {
ret = wc_AesSetKey(aes, encKey, encKeySz, encIv,
ret = wc_AesSetKey(aes, encKey, (word32)encKeySz, encIv,
AES_DECRYPTION);
if (ret == 0) {
ret = wc_AesCbcDecrypt(aes, out, msg, msgSz-digestSz);
@@ -14023,7 +14024,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
XMEMCPY(ctr_iv, encIv, WOLFSSL_ECIES_GEN_IV_SIZE);
XMEMSET(ctr_iv + WOLFSSL_ECIES_GEN_IV_SIZE, 0,
AES_BLOCK_SIZE - WOLFSSL_ECIES_GEN_IV_SIZE);
ret = wc_AesSetKey(aes, encKey, encKeySz, ctr_iv,
ret = wc_AesSetKey(aes, encKey, (word32)encKeySz, ctr_iv,
AES_ENCRYPTION);
if (ret == 0) {
ret = wc_AesCtrEncrypt(aes, out, msg, msgSz-digestSz);
@@ -14528,7 +14529,7 @@ static int wc_ecc_export_x963_compressed(ecc_key* key, byte* out, word32* outLen
return ECC_BAD_ARG_E;
}
numlen = key->dp->size;
numlen = (word32)key->dp->size;
if (*outLen < (1 + numlen)) {
*outLen = 1 + numlen;
@@ -14546,8 +14547,9 @@ static int wc_ecc_export_x963_compressed(ecc_key* key, byte* out, word32* outLen
/* pad and store x */
XMEMSET(out+1, 0, numlen);
ret = mp_to_unsigned_bin(key->pubkey.x,
out+1 + (numlen - mp_unsigned_bin_size(key->pubkey.x)));
ret = mp_to_unsigned_bin(
key->pubkey.x,
out+1 + (numlen - (word32)mp_unsigned_bin_size(key->pubkey.x)));
*outLen = 1 + numlen;
return ret;
@@ -14635,8 +14637,7 @@ int wc_X963_KDF(enum wc_HashType type, const byte* secret, word32 secretSz,
const byte* sinfo, word32 sinfoSz, byte* out, word32 outSz)
{
int ret;
int digestSz, copySz;
int remaining = outSz;
word32 digestSz, copySz, remaining = outSz;
byte* outIdx;
byte counter[4];
byte tmp[WC_MAX_DIGEST_SIZE];
@@ -14656,9 +14657,10 @@ int wc_X963_KDF(enum wc_HashType type, const byte* secret, word32 secretSz,
type != WC_HASH_TYPE_SHA512)
return BAD_FUNC_ARG;
digestSz = wc_HashGetDigestSize(type);
if (digestSz < 0)
return digestSz;
ret = wc_HashGetDigestSize(type);
if (ret < 0)
return ret;
digestSz = (word32)ret;
#ifdef WOLFSSL_SMALL_STACK
hash = (wc_HashAlg*)XMALLOC(sizeof(wc_HashAlg), NULL,

View File

@@ -528,11 +528,15 @@ int wc_Hash(enum wc_HashType hash_type, const byte* data,
word32 data_len, byte* hash, word32 hash_len)
{
int ret = HASH_TYPE_E; /* Default to hash type error */
word32 dig_size;
int dig_size;
/* Validate hash buffer size */
dig_size = wc_HashGetDigestSize(hash_type);
if (hash_len < dig_size) {
if (dig_size < 0) {
return dig_size;
}
if (hash_len < (word32)dig_size) {
return BUFFER_E;
}

View File

@@ -340,7 +340,7 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
#ifdef WOLF_CRYPTO_CB
hmac->keyRaw = key; /* use buffer directly */
hmac->keyLen = length;
hmac->keyLen = (word16)length;
#endif
#ifdef WOLFSSL_MAXQ108X
@@ -1055,7 +1055,7 @@ int wc_HmacInit_Id(Hmac* hmac, unsigned char* id, int len, void* heap,
if (ret == 0)
ret = wc_HmacInit(hmac, heap, devId);
if (ret == 0) {
XMEMCPY(hmac->id, id, len);
XMEMCPY(hmac->id, id, (size_t)len);
hmac->idLen = len;
}
@@ -1078,7 +1078,7 @@ int wc_HmacInit_Label(Hmac* hmac, const char* label, void* heap, int devId)
if (ret == 0)
ret = wc_HmacInit(hmac, heap, devId);
if (ret == 0) {
XMEMCPY(hmac->label, label, labelLen);
XMEMCPY(hmac->label, label, (size_t)labelLen);
hmac->labelLen = labelLen;
}
@@ -1199,7 +1199,7 @@ int wolfSSL_GetHmacMaxSize(void)
#endif
int ret;
const byte* localSalt; /* either points to user input or tmp */
int hashSz;
word32 hashSz;
ret = wc_HmacSizeByType(type);
if (ret < 0) {
@@ -1213,7 +1213,7 @@ int wolfSSL_GetHmacMaxSize(void)
}
#endif
hashSz = ret;
hashSz = (word32)ret;
localSalt = salt;
if (localSalt == NULL) {
XMEMSET(tmp, 0, hashSz);
@@ -1259,9 +1259,15 @@ int wolfSSL_GetHmacMaxSize(void)
#endif
int ret = 0;
word32 outIdx = 0;
word32 hashSz = wc_HmacSizeByType(type);
word32 hashSz;
byte n = 0x1;
ret = wc_HmacSizeByType(type);
if (ret < 0) {
return ret;
}
hashSz = (word32)ret;
/* RFC 5869 states that the length of output keying material in
* octets must be L <= 255*HashLen or N = ceil(L/HashLen) */
@@ -1285,7 +1291,7 @@ int wolfSSL_GetHmacMaxSize(void)
}
while (outIdx < outSz) {
int tmpSz = (n == 1) ? 0 : hashSz;
word32 tmpSz = (n == 1) ? 0 : hashSz;
word32 left = outSz - outIdx;
ret = wc_HmacSetKey(myHmac, type, inKey, inKeySz);
@@ -1338,11 +1344,14 @@ int wolfSSL_GetHmacMaxSize(void)
byte* out, word32 outSz)
{
byte prk[WC_MAX_DIGEST_SIZE];
int hashSz = wc_HmacSizeByType(type);
word32 hashSz;
int ret;
if (hashSz < 0)
return BAD_FUNC_ARG;
ret = wc_HmacSizeByType(type);
if (ret < 0) {
return ret;
}
hashSz = (word32)ret;
ret = wc_HKDF_Extract(type, salt, saltSz, inKey, inKeySz, prk);
if (ret != 0)

View File

@@ -351,11 +351,11 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen,
* digest The type of digest to use.
* returns 0 on success, otherwise failure.
*/
int wc_Tls13_HKDF_Extract(byte* prk, const byte* salt, int saltLen,
byte* ikm, int ikmLen, int digest)
int wc_Tls13_HKDF_Extract(byte* prk, const byte* salt, word32 saltLen,
byte* ikm, word32 ikmLen, int digest)
{
int ret;
int len = 0;
word32 len = 0;
switch (digest) {
#ifndef NO_SHA256
@@ -425,7 +425,7 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen,
int digest)
{
int ret = 0;
int idx = 0;
word32 idx = 0;
#ifdef WOLFSSL_SMALL_STACK
byte* data;
#else
@@ -755,7 +755,7 @@ int wc_SSH_KDF(byte hashId, byte keyId, byte* key, word32 keySz,
byte kPad = 0;
byte pad = 0;
byte kSzFlat[LENGTH_SZ];
int digestSz;
word32 digestSz;
int ret;
if (key == NULL || keySz == 0 ||
@@ -766,10 +766,11 @@ int wc_SSH_KDF(byte hashId, byte keyId, byte* key, word32 keySz,
return BAD_FUNC_ARG;
}
digestSz = wc_HmacSizeByType(enmhashId);
if (digestSz <= 0) {
ret = wc_HmacSizeByType(enmhashId);
if (ret <= 0) {
return BAD_FUNC_ARG;
}
digestSz = (word32)ret;
if (k[0] & 0x80) kPad = 1;
c32toa(kSz + kPad, kSzFlat);

View File

@@ -330,8 +330,12 @@ WC_MISC_STATIC WC_INLINE void ForceZero(void* mem, word32 len)
len -= l;
while (l--) *z++ = 0;
#endif
for (w = (volatile word64*)z; len >= sizeof(*w); len -= sizeof(*w))
*w++ = 0;
for (w = (volatile word64*)z;
len >= sizeof(*w);
len -= (word32)sizeof(*w))
{
*w++ = 0;
}
z = (volatile byte*)w;
#endif
@@ -384,25 +388,25 @@ WC_MISC_STATIC WC_INLINE int ConstantCompare(const byte* a, const byte* b,
/* converts a 32 bit integer to 24 bit */
WC_MISC_STATIC WC_INLINE void c32to24(word32 in, word24 out)
{
out[0] = (in >> 16) & 0xff;
out[1] = (in >> 8) & 0xff;
out[2] = in & 0xff;
out[0] = (byte)((in >> 16) & 0xff);
out[1] = (byte)((in >> 8) & 0xff);
out[2] = (byte)(in & 0xff);
}
/* convert 16 bit integer to opaque */
WC_MISC_STATIC WC_INLINE void c16toa(word16 wc_u16, byte* c)
{
c[0] = (wc_u16 >> 8) & 0xff;
c[1] = wc_u16 & 0xff;
c[0] = (byte)((wc_u16 >> 8) & 0xff);
c[1] = (byte)(wc_u16 & 0xff);
}
/* convert 32 bit integer to opaque */
WC_MISC_STATIC WC_INLINE void c32toa(word32 wc_u32, byte* c)
{
c[0] = (wc_u32 >> 24) & 0xff;
c[1] = (wc_u32 >> 16) & 0xff;
c[2] = (wc_u32 >> 8) & 0xff;
c[3] = wc_u32 & 0xff;
c[0] = (byte)((wc_u32 >> 24) & 0xff);
c[1] = (byte)((wc_u32 >> 16) & 0xff);
c[2] = (byte)((wc_u32 >> 8) & 0xff);
c[3] = (byte)(wc_u32 & 0xff);
}
#endif
@@ -410,14 +414,16 @@ WC_MISC_STATIC WC_INLINE void c32toa(word32 wc_u32, byte* c)
/* 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_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 */
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 */
@@ -429,7 +435,10 @@ WC_MISC_STATIC WC_INLINE void ato16(const byte* c, word16* wc_u16)
/* convert opaque to 32 bit integer */
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 +483,31 @@ WC_MISC_STATIC WC_INLINE int ByteToHexStr(byte in, char* out)
/* Constant time - mask set when a > 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. */
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. */
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. */
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. */
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. */
@@ -510,25 +519,25 @@ WC_MISC_STATIC WC_INLINE byte ctMaskEq(int a, int b)
/* Constant time - sets 16 bit integer mask when a > 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 */
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. */
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. */
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. */
@@ -556,10 +565,17 @@ WC_MISC_STATIC WC_INLINE int ctMaskSelInt(byte m, int a, int b)
(a & ( (signed int)(signed char)m));
}
/* Constant time - select word32 a when mask is set and word32 b otherwise. */
WC_MISC_STATIC WC_INLINE word32 ctMaskSelWord32(byte m, word32 a, word32 b)
{
return (((word32)b & (word32)(~(signed int)(signed char)m)) |
((word32)a & (word32)( (signed int)(signed char)m)));
}
/* Constant time - bit set when a <= 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

View File

@@ -3820,7 +3820,7 @@ static int wc_PKCS7_VerifyContentMessageDigest(PKCS7* pkcs7,
/* compare generated to hash in messageDigest attribute */
if ((innerAttribSz != digestSz) ||
(XMEMCMP(attrib->value + idx, digestBuf, (word32)digestSz) != 0)) {
(XMEMCMP(attrib->value + idx, digestBuf, (size_t)digestSz) != 0)) {
WOLFSSL_MSG("Content digest does not match messageDigest attrib value");
#ifdef WOLFSSL_SMALL_STACK
XFREE(digest, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -11718,14 +11718,18 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
ret = ASN_PARSE_E;
}
blockKeySz = wc_PKCS7_GetOIDKeySize(encOID);
if (ret == 0 && blockKeySz < 0) {
ret = blockKeySz;
if (ret == 0) {
blockKeySz = wc_PKCS7_GetOIDKeySize(encOID);
if (blockKeySz < 0) {
ret = blockKeySz;
}
}
expBlockSz = wc_PKCS7_GetOIDBlockSize(encOID);
if (ret == 0 && expBlockSz < 0) {
ret = expBlockSz;
if (ret == 0) {
expBlockSz = wc_PKCS7_GetOIDBlockSize(encOID);
if (expBlockSz < 0) {
ret = expBlockSz;
}
}
/* get nonce, stored in OPTIONAL parameter of AlgoID
@@ -11868,8 +11872,25 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
pkiMsgSz = (pkcs7->stream->length > 0)? pkcs7->stream->length: inSz;
encryptedContentSz = pkcs7->stream->expected;
#else
pkiMsgSz = inSz;
#endif
if (expBlockSz == 0) {
#ifndef NO_PKCS7_STREAM
wc_PKCS7_StreamGetVar(pkcs7, &encOID, NULL, NULL);
#endif
if (encOID == 0)
expBlockSz = 1;
else {
expBlockSz = wc_PKCS7_GetOIDBlockSize(encOID);
if (expBlockSz < 0) {
ret = expBlockSz;
break;
}
}
}
/* AES-GCM/CCM does NOT require padding for plaintext content or
* AAD inputs RFC 5084 section 3.1 and 3.2, but we must alloc
* full blocks to ensure crypto only gets full blocks */

View File

@@ -778,7 +778,7 @@ int wc_Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes)
/* process full blocks */
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__)
int ret;
ret = poly1305_blocks(ctx, m, want);

View File

@@ -370,8 +370,8 @@ static int Hash_df(DRBG_internal* drbg, byte* out, word32 outSz, byte type,
{
int ret = DRBG_FAILURE;
byte ctr;
int i;
int len;
word32 i;
word32 len;
word32 bits = (outSz * 8); /* reverse byte order */
#ifdef WOLFSSL_SMALL_STACK_CACHE
wc_Sha256* sha = &drbg->sha256;
@@ -520,7 +520,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)
{
int i;
for (i = dataSz - 1; i >= 0; i--) {
for (i = (int)dataSz - 1; i >= 0; i--) {
data[i]++;
if (data[i] != 0) break;
}
@@ -537,8 +537,8 @@ static int Hash_gen(DRBG_internal* drbg, byte* out, word32 outSz, const byte* V)
byte data[DRBG_SEED_LEN];
byte digest[WC_SHA256_DIGEST_SIZE];
#endif
int i;
int len;
word32 i;
word32 len;
#ifdef WOLFSSL_SMALL_STACK_CACHE
wc_Sha256* sha = &drbg->sha256;
#else
@@ -621,9 +621,9 @@ static WC_INLINE void array_add(byte* d, word32 dLen, const byte* s, word32 sLen
int sIdx, dIdx;
word16 carry = 0;
dIdx = dLen - 1;
for (sIdx = sLen - 1; sIdx >= 0; sIdx--) {
carry += (word16)d[dIdx] + (word16)s[sIdx];
dIdx = (int)dLen - 1;
for (sIdx = (int)sLen - 1; sIdx >= 0; sIdx--) {
carry += (word16)(d[dIdx] + s[sIdx]);
d[dIdx] = (byte)carry;
carry >>= 8;
dIdx--;
@@ -779,7 +779,7 @@ int wc_RNG_TestSeed(const byte* seed, word32 seedSz)
while (seedIdx < seedSz - SEED_BLOCK_SZ) {
if (ConstantCompare(seed + seedIdx,
seed + seedIdx + scratchSz,
scratchSz) == 0) {
(int)scratchSz) == 0) {
ret = DRBG_CONT_FAILURE;
}
@@ -3753,7 +3753,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
break;
}
sz -= len;
sz -= (word32)len;
output += len;
if (sz) {

View File

@@ -373,7 +373,7 @@ int wc_InitRsaKey_Id(RsaKey* key, unsigned char* id, int len, void* heap,
if (ret == 0)
ret = wc_InitRsaKey_ex(key, heap, devId);
if (ret == 0 && id != NULL && len != 0) {
XMEMCPY(key->id, id, len);
XMEMCPY(key->id, id, (size_t)len);
key->idLen = len;
#ifdef WOLFSSL_SE050
/* Set SE050 ID from word32, populate RsaKey with public from SE050 */
@@ -403,7 +403,7 @@ int wc_InitRsaKey_Label(RsaKey* key, const char* label, void* heap, int devId)
if (ret == 0)
ret = wc_InitRsaKey_ex(key, heap, devId);
if (ret == 0) {
XMEMCPY(key->label, label, labelLen);
XMEMCPY(key->label, label, (size_t)labelLen);
key->labelLen = labelLen;
}
@@ -1141,7 +1141,7 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
void* heap)
{
int ret;
int hLen;
word32 hLen;
int psLen;
int i;
word32 idx;
@@ -1163,10 +1163,11 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
}
/* limit of label is the same as limit of hash function which is massive */
hLen = wc_HashGetDigestSize(hType);
if (hLen < 0) {
return hLen;
ret = wc_HashGetDigestSize(hType);
if (ret < 0) {
return ret;
}
hLen = (word32)ret;
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
lHash = (byte*)XMALLOC(hLen, heap, DYNAMIC_TYPE_RSA_BUFFER);
@@ -1181,7 +1182,7 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
#else
/* hLen should never be larger than lHash since size is max digest size,
but check before blindly calling wc_Hash */
if ((word32)hLen > sizeof(lHash)) {
if (hLen > sizeof(lHash)) {
WOLFSSL_MSG("OAEP lHash to small for digest!!");
return MEMORY_E;
}
@@ -1204,7 +1205,7 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
k = RSA key size
hLen = hash digest size -- will always be >= 0 at this point
*/
if ((word32)(2 * hLen + 2) > pkcsBlockLen) {
if ((2 * hLen + 2) > pkcsBlockLen) {
WOLFSSL_MSG("OAEP pad error hash to big for RSA key size");
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
@@ -1224,7 +1225,7 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
/* concatenate lHash || PS || 0x01 || msg */
idx = pkcsBlockLen - 1 - inputLen;
psLen = pkcsBlockLen - inputLen - 2 * hLen - 2;
psLen = (int)pkcsBlockLen - (int)inputLen - 2 * (int)hLen - 2;
if (pkcsBlockLen < inputLen) { /*make sure not writing over end of buffer */
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
@@ -1301,7 +1302,7 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
/* xor created seedMask with seed to make maskedSeed */
i = 0;
while (idx < (word32)(hLen + 1) && i < hLen) {
while (idx < (hLen + 1) && i < (int)hLen) {
pkcsBlock[idx] = pkcsBlock[idx] ^ seed[i++];
idx++;
}
@@ -1635,7 +1636,7 @@ static int RsaUnPad_OAEP(byte *pkcsBlock, unsigned int pkcsBlockLen,
byte **output, enum wc_HashType hType, int mgf,
byte* optLabel, word32 labelLen, void* heap)
{
int hLen;
word32 hLen;
int ret;
byte h[WC_MAX_DIGEST_SIZE]; /* max digest size */
word32 idx;
@@ -1653,10 +1654,11 @@ static int RsaUnPad_OAEP(byte *pkcsBlock, unsigned int pkcsBlockLen,
return BUFFER_E;
}
hLen = wc_HashGetDigestSize(hType);
if ((hLen < 0) || (pkcsBlockLen < (2 * (word32)hLen + 2))) {
ret = wc_HashGetDigestSize(hType);
if ((ret < 0) || (pkcsBlockLen < (2 * (word32)ret + 2))) {
return BAD_FUNC_ARG;
}
hLen = (word32)ret;
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
tmp = (byte*)XMALLOC(pkcsBlockLen, heap, DYNAMIC_TYPE_RSA_BUFFER);
@@ -1730,16 +1732,16 @@ static int RsaUnPad_OAEP(byte *pkcsBlock, unsigned int pkcsBlockLen,
these checks.
*/
ret = 0;
ret |= ConstantCompare(pkcsBlock + hLen + 1, h, hLen);
ret |= ConstantCompare(pkcsBlock + hLen + 1, h, (int)hLen);
ret += pkcsBlock[idx++] ^ 0x01; /* separator value is 0x01 */
ret += pkcsBlock[0] ^ 0x00; /* Y, the first value, should be 0 */
/* Return 0 data length on error. */
idx = ctMaskSelInt(ctMaskEq(ret, 0), idx, pkcsBlockLen);
idx = ctMaskSelWord32(ctMaskEq(ret, 0), idx, pkcsBlockLen);
/* adjust pointer to correct location in array and return size of M */
*output = (byte*)(pkcsBlock + idx);
return pkcsBlockLen - idx;
return (int)(pkcsBlockLen - idx);
}
#endif /* !WC_NO_RSA_OAEP */
@@ -1916,7 +1918,7 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
}
*output = (byte *)(pkcsBlock + i);
ret = pkcsBlockLen - i;
ret = (int)pkcsBlockLen - i;
}
#ifndef WOLFSSL_RSA_VERIFY_ONLY
else {
@@ -1928,21 +1930,22 @@ static int RsaUnPad(const byte *pkcsBlock, unsigned int pkcsBlockLen,
/* Decrypted with private key - unpad must be constant time. */
for (j = 2; j < pkcsBlockLen; j++) {
/* Update i if not passed the separator and at separator. */
i |= (~pastSep) & ctMask16Eq(pkcsBlock[j], 0x00) & (j + 1);
i |= (word16)(~pastSep) & ctMask16Eq(pkcsBlock[j], 0x00) &
(word16)(j + 1);
pastSep |= ctMask16Eq(pkcsBlock[j], 0x00);
}
/* Minimum of 11 bytes of pre-message data - including leading 0x00. */
invalid |= ctMaskLT(i, RSA_MIN_PAD_SZ);
/* Must have seen separator. */
invalid |= ~pastSep;
invalid |= (byte)~pastSep;
/* First byte must be 0x00. */
invalid |= ctMaskNotEq(pkcsBlock[0], 0x00);
/* Check against expected block type: padValue */
invalid |= ctMaskNotEq(pkcsBlock[1], padValue);
*output = (byte *)(pkcsBlock + i);
ret = ((int)-1 + (int)(invalid >> 7)) & (pkcsBlockLen - i);
ret = ((int)-1 + (int)(invalid >> 7)) & ((int)pkcsBlockLen - i);
}
#endif
@@ -2782,7 +2785,7 @@ static int RsaFunctionSync(const byte* in, word32 inLen, byte* out,
}
if (ret == 0) {
if (mp_to_unsigned_bin_len(tmp, out, *outLen) != MP_OKAY)
if (mp_to_unsigned_bin_len(tmp, out, (int)*outLen) != MP_OKAY)
ret = MP_TO_E;
}
#else
@@ -2803,11 +2806,14 @@ static int RsaFunctionSync(const byte* in, word32 inLen, byte* out,
static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
word32* outLen, int type, RsaKey* key, WC_RNG* rng)
{
#ifdef WOLFSSL_HAVE_SP_RSA
int ret;
#endif
word32 keyLen;
word32 keyLen = wc_RsaEncryptSize(key);
ret = wc_RsaEncryptSize(key);
if (ret < 0) {
return ret;
}
keyLen = (word32)ret;
if (inLen > keyLen) {
WOLFSSL_MSG("Expected that inLen be no longer RSA key length");
@@ -3187,8 +3193,7 @@ static int wc_RsaFunction_ex(const byte* in, word32 inLen, byte* out,
#ifndef WOLF_CRYPTO_CB_ONLY_RSA
if (ret != CRYPTOCB_UNAVAILABLE)
return ret;
/* fall-through when unavailable */
ret = 0; /* reset error code and try using software */
/* fall-through when unavailable and try using software */
#else
return ret;
#endif
@@ -3371,9 +3376,9 @@ static int RsaPublicEncryptEx(const byte* in, word32 inLen, byte* out,
#endif /* WOLFSSL_CRYPTOCELL */
key->state = RSA_STATE_ENCRYPT_PAD;
ret = wc_RsaPad_ex(in, inLen, out, sz, pad_value, rng, pad_type, hash,
mgf, label, labelSz, saltLen, mp_count_bits(&key->n),
key->heap);
ret = wc_RsaPad_ex(in, inLen, out, (word32)sz, pad_value, rng, pad_type,
hash, mgf, label, labelSz, saltLen,
mp_count_bits(&key->n), key->heap);
if (ret < 0) {
break;
}
@@ -3384,7 +3389,8 @@ static int RsaPublicEncryptEx(const byte* in, word32 inLen, byte* out,
case RSA_STATE_ENCRYPT_EXPTMOD:
key->dataLen = outLen;
ret = wc_RsaFunction(out, sz, out, &key->dataLen, rsa_type, key, rng);
ret = wc_RsaFunction(out, (word32)sz, out, &key->dataLen, rsa_type, key,
rng);
if (ret >= 0 || ret == WC_PENDING_E) {
key->state = RSA_STATE_ENCRYPT_RES;
@@ -3396,7 +3402,7 @@ static int RsaPublicEncryptEx(const byte* in, word32 inLen, byte* out,
FALL_THROUGH;
case RSA_STATE_ENCRYPT_RES:
ret = key->dataLen;
ret = (int)key->dataLen;
break;
default:
@@ -3588,8 +3594,8 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
for (j = 0; j < key->dataLen; j++) {
signed char c;
out[i] = key->data[j];
c = ctMaskGTE(j, start);
c &= ctMaskLT(i, outLen);
c = (signed char)ctMaskGTE((int)j, start);
c &= (signed char)ctMaskLT((int)i, (int)outLen);
/* 0 - no add, -1 add */
i += (word32)((byte)(-c));
}
@@ -3597,14 +3603,14 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
else
#endif
{
XMEMCPY(out, pad, ret);
XMEMCPY(out, pad, (size_t)ret);
}
}
else
*outPtr = pad;
#if !defined(WOLFSSL_RSA_VERIFY_ONLY)
ret = ctMaskSelInt(ctMaskLTE(ret, outLen), ret, RSA_BUFFER_E);
ret = ctMaskSelInt(ctMaskLTE(ret, (int)outLen), ret, RSA_BUFFER_E);
#ifndef WOLFSSL_RSA_DECRYPT_TO_0_LEN
ret = ctMaskSelInt(ctMaskNotEq(ret, 0), ret, RSA_BUFFER_E);
#endif
@@ -4545,7 +4551,7 @@ static int _CheckProbablePrime(mp_int* p, mp_int* q, mp_int* e, int nlen,
/* 4.4,5.5 - Check that prime >= (2^(1/2))(2^((nlen/2)-1))
* This is a comparison against lowerBound */
ret = mp_read_unsigned_bin(tmp1, lower_bound, nlen/16);
ret = mp_read_unsigned_bin(tmp1, lower_bound, (word32)nlen/16);
if (ret != MP_OKAY) goto notOkay;
ret = mp_cmp(prime, tmp1);
if (ret == MP_LT) goto exit;
@@ -4723,7 +4729,8 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
mp_int tmp2_buf, *tmp2 = &tmp2_buf;
mp_int tmp3_buf, *tmp3 = &tmp3_buf;
#endif /* WOLFSSL_SMALL_STACK */
int i, failCount, primeSz, isPrime = 0;
int i, failCount, isPrime = 0;
word32 primeSz;
byte* buf = NULL;
#endif /* !WOLFSSL_CRYPTOCELL && !WOLFSSL_SE050 */
int err;
@@ -4826,7 +4833,7 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
/* The failCount value comes from NIST FIPS 186-4, section B.3.3,
* process steps 4.7 and 5.8. */
failCount = 5 * (size / 2);
primeSz = size / 16; /* size is the size of n in bits.
primeSz = (word32)size / 16; /* size is the size of n in bits.
primeSz is in bytes. */
/* allocate buffer to work with */

View File

@@ -943,7 +943,7 @@ static int InitSha256(wc_Sha256* sha256)
S[i] = sha256->digest[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++)
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;
ret = wc_EncodeSignature(hash_data, hash_data, hash_len, oid);
ret = (int)wc_EncodeSignature(hash_data, hash_data, hash_len, oid);
if (ret > 0) {
*hash_enc_len = ret;
*hash_enc_len = (word32)ret;
ret = 0;
}
@@ -295,7 +295,7 @@ int wc_SignatureVerify(
WOLFSSL_MSG("wc_SignatureVerify: Invalid hash type/len");
return ret;
}
hash_enc_len = hash_len = ret;
hash_enc_len = hash_len = (word32)ret;
#ifndef NO_RSA
if (sig_type == WC_SIGNATURE_TYPE_RSA_W_ENC) {
@@ -429,7 +429,7 @@ int wc_SignatureGenerateHash_ex(
} while (ret == WC_PENDING_E);
#endif /* WOLFSSL_CRYPTOCELL */
if (ret >= 0) {
*sig_len = ret;
*sig_len = (word32)ret;
ret = 0; /* Success */
}
#else
@@ -494,7 +494,7 @@ int wc_SignatureGenerate_ex(
WOLFSSL_MSG("wc_SignatureGenerate: Invalid hash type/len");
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 (sig_type == WC_SIGNATURE_TYPE_RSA_W_ENC) {

View File

@@ -178,7 +178,7 @@ This library provides single precision (SP) integer math functions.
do { \
ALLOC_SP_INT(n, s, err, h); \
if ((err) == MP_OKAY) { \
(n)->size = (s); \
(n)->size = (unsigned int)(s); \
} \
} \
while (0)
@@ -245,7 +245,7 @@ do { \
int n##ii; \
(n)[0] = n##d; \
(n)[0]->size = (s); \
for (n##ii = 1; n##ii < (c); n##ii++) { \
for (n##ii = 1; n##ii < (int)(c); n##ii++) { \
(n)[n##ii] = MP_INT_NEXT((n)[n##ii-1], s); \
(n)[n##ii]->size = (s); \
} \
@@ -4682,7 +4682,7 @@ static void _sp_zero(sp_int* a)
* @param [out] a SP integer.
* @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;
@@ -4702,7 +4702,7 @@ static void _sp_init_size(sp_int* a, int size)
* @return MP_OKAY on success.
* @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;
@@ -4998,8 +4998,8 @@ int sp_exch(sp_int* a, sp_int* b)
ALLOC_SP_INT(t, a->used, err, NULL);
if (err == MP_OKAY) {
/* Cache allocated size of a and b. */
int asize = a->size;
int bsize = b->size;
unsigned int asize = a->size;
unsigned int bsize = b->size;
/* Copy all of SP int: t <= a, a <= b, b <= t. */
XMEMCPY(t, a, MP_INT_SIZEOF(a->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;
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);
/* Allocate temporary to hold masked xor of a and b. */
ALLOC_SP_INT(t, cnt, err, NULL);
if (err == MP_OKAY) {
/* 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) & (unsigned int)mask;
#ifdef WOLFSSL_SP_INT_NEGATIVE
t->sign = (int)((a->sign ^ b->sign) & mask);
t->sign = (a->sign ^ b->sign) & (unsigned int)mask;
#endif
/* 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. */
if (cnt != 4) {
/* Add checked bits and count in last 4 bits checked. */
bc += j + cnt;
bc += j + (unsigned int)cnt;
break;
}
}
}
return bc;
return (int)bc;
}
#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. */
r->dp[i] = a->dp[i] >> 1;
/* Set used to be all words seen. */
r->used = i + 1;
r->used = (unsigned int)i + 1;
/* Remove leading zeros. */
sp_clamp(r);
#ifdef WOLFSSL_SP_INT_NEGATIVE
@@ -7267,8 +7267,8 @@ int sp_addmod(const sp_int* a, const sp_int* b, const sp_int* m, sp_int* r)
{
int err = MP_OKAY;
/* Calculate used based on digits used in a and b. */
int used = ((a == NULL) || (b == NULL)) ? 1 :
((a->used >= b->used) ? a->used + 1 : b->used + 1);
unsigned int used = ((a == NULL) || (b == NULL)) ? 1 :
((a->used >= b->used) ? a->used + 1 : b->used + 1);
DECL_SP_INT(t, used);
/* Validate parameters. */
@@ -7749,7 +7749,7 @@ int sp_lshd(sp_int* a, int s)
/* Move up digits. */
XMEMMOVE(a->dp + s, a->dp, a->used * SP_WORD_SIZEOF);
/* Back fill with zeros. */
XMEMSET(a->dp, 0, s * SP_WORD_SIZEOF);
XMEMSET(a->dp, 0, (size_t)s * SP_WORD_SIZEOF);
/* Update used. */
a->used += (unsigned int)s;
/* Remove leading zeros. */
@@ -7780,7 +7780,7 @@ static int sp_lshb(sp_int* a, int n)
if (a->used != 0) {
/* 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. */
if (a->used + s >= a->size) {
@@ -8597,7 +8597,7 @@ static int _sp_mul(const sp_int* a, const sp_int* b, sp_int* r)
}
for (; k <= (a->used - 1) + (b->used - 1); k++) {
j = (int)(b->used - 1);
i = k - j;
i = k - (unsigned int)j;
for (; (i < a->used) && (j >= 0); i++, j--) {
SP_ASM_MUL_ADD(l, h, o, a->dp[i], b->dp[j]);
}
@@ -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[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_int_digit)w[1];
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[1] >>= SP_WORD_SIZE;
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[4];
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[3] >>= SP_WORD_SIZE;
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[8];
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[6] >>= SP_WORD_SIZE;
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[11];
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[10] >>= SP_WORD_SIZE;
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[13];
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[13] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[13];
w[14] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[14];
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[15] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[15];
r->dp[7] = w[0];
r->dp[7] = (sp_int_digit)w[0];
r->used = 8;
sp_clamp(r);
@@ -12094,9 +12094,10 @@ 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.
*/
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)) {
break;
}
if ((!sp_is_bit_set(e, (unsigned int)i)) ||
(j == CT_INV_MOD_PRE_CNT)) {
break;
}
}
/* 3. Set tmp to product of leading bits. */
err = sp_copy(pre[j-1], t);
@@ -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--) {
/* 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
* 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. */
preCnt = 1 << (winBits - 1);
/* Mask for calculating index into pre-computed table. */
mask = preCnt - 1;
mask = (sp_int_digit)preCnt - 1;
/* Allocate sp_ints for:
* - pre-computation table
@@ -13239,9 +13240,9 @@ static int _sp_exptmod_nct(const sp_int* b, const sp_int* e, const sp_int* m,
* - Montgomery form of base
*/
#ifndef WOLFSSL_SP_NO_MALLOC
ALLOC_DYN_SP_INT_ARRAY(t, m->used * 2 + 1, preCnt + 2, err, NULL);
ALLOC_DYN_SP_INT_ARRAY(t, m->used * 2 + 1, (size_t)preCnt + 2, err, NULL);
#else
ALLOC_SP_INT_ARRAY(t, m->used * 2 + 1, preCnt + 2, err, NULL);
ALLOC_SP_INT_ARRAY(t, m->used * 2 + 1, (size_t)preCnt + 2, err, NULL);
#endif
if (err == MP_OKAY) {
/* Set variables to use allocate memory. */
@@ -13411,7 +13412,7 @@ static int _sp_exptmod_nct(const sp_int* b, const sp_int* e, const sp_int* m,
n <<= winBits;
c -= winBits;
}
y &= mask;
y &= (int)mask;
}
/* 4.5. Montgomery multiply result by table entry. */
@@ -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[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_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[1] >>= SP_WORD_SIZE;
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[3];
r->dp[2] = w[0];
r->dp[2] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE;
w[2] >>= SP_WORD_SIZE;
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[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[4] >>= SP_WORD_SIZE;
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[7];
r->dp[4] = w[0];
r->dp[4] = (sp_int_digit)w[0];
w[0] >>= SP_WORD_SIZE;
w[6] >>= SP_WORD_SIZE;
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[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[8] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[8];
w[0] += (sp_int_digit)w[8];
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[9] >>= SP_WORD_SIZE;
w[0] += (sp_int_digit)w[9];
r->dp[7] = w[0];
r->dp[7] = (sp_int_digit)w[0];
r->used = 8;
sp_clamp(r);
@@ -16846,7 +16847,7 @@ static void _sp_mont_setup(const sp_int* m, sp_int_digit* rho)
x *= 1 + y;
/* 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.
@@ -16916,7 +16917,7 @@ int sp_mont_norm(sp_int* norm, const sp_int* m)
}
/* Smallest number greater than m of form 2^n. */
_sp_zero(norm);
err = sp_set_bit(norm, bits);
err = sp_set_bit(norm, (int)bits);
}
if (err == MP_OKAY) {
/* norm = 2^n % m */
@@ -17292,7 +17293,7 @@ static int _sp_read_radix_10(sp_int* a, const char* in)
break;
}
/* Add character value. */
err = _sp_add_d(a, ch, a);
err = _sp_add_d(a, (sp_int_digit)ch, a);
if (err != MP_OKAY) {
break;
}
@@ -17467,7 +17468,7 @@ int sp_tohex(const sp_int* a, char* str)
d = a->dp[i];
/* Write out all nibbles of digit. */
for (j = SP_WORD_SIZE - 4; j >= 0; j -= 4) {
*(str++) = (byte)ByteToHex((byte)(d >> j));
*(str++) = (char)ByteToHex((byte)(d >> j));
}
}
}
@@ -17750,7 +17751,7 @@ int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap)
}
/* Get number of digits required to handle required number of bytes. */
digits = (len + SP_WORD_SIZEOF - 1) / SP_WORD_SIZEOF;
digits = ((unsigned int)len + SP_WORD_SIZEOF - 1) / SP_WORD_SIZEOF;
/* Ensure result has space. */
if (r->size < digits) {
err = MP_VAL;
@@ -17811,7 +17812,7 @@ int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap)
fflush(stdout);
#endif /* SHOW_GEN */
/* Generate bytes into digit array. */
err = wc_RNG_GenerateBlock(rng, (byte*)r->dp, len);
err = wc_RNG_GenerateBlock(rng, (byte*)r->dp, (word32)len);
if (err != 0) {
err = MP_VAL;
break;
@@ -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. */
if ((err == MP_OKAY) && (!haveRes)) {
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(d, a->used * 2 + 1, 2);
@@ -18378,7 +18379,7 @@ static WC_INLINE int _sp_gcd(const sp_int* a, const sp_int* b, sp_int* r)
/* Used for swapping sp_ints. */
sp_int* s;
/* Determine maximum digit length numbers will reach. */
int used = (a->used >= b->used) ? a->used + 1 : b->used + 1;
unsigned int used = (a->used >= b->used) ? a->used + 1 : b->used + 1;
DECL_SP_INT_ARRAY(d, used, 3);
SAVE_VECTOR_REGISTERS(err = _svr_ret;);

View File

@@ -96,7 +96,7 @@ int get_digit_count(const mp_int* a)
if (a == NULL)
return 0;
return a->used;
return (int)a->used;
}
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
unsigned int mask = (unsigned int)0 - copy;
#else
mp_digit mask = (mp_digit)0 - copy;
mp_digit mask = (mp_digit)0 - (mp_digit)copy;
#endif
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 */
if (err == MP_OKAY)
err = mp_grow(b, a->used + 1);
err = mp_grow(b, (int)a->used + 1);
if (err == MP_OKAY) {
#if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
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.
*/
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++) {
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) & (unsigned int)mask;
#if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
defined(WOLFSSL_SP_INT_NEGATIVE)
b->sign ^= (a->sign ^ b->sign) & (int)mask;
b->sign ^= (a->sign ^ b->sign) & (unsigned int)mask;
#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 ret = 0;
int cnt = digits * sizeof(mp_digit);
int cnt = digits * (int)sizeof(mp_digit);
if (rng == NULL) {
ret = MISSING_RNG_E;
@@ -195,12 +195,12 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng)
ret = BAD_FUNC_ARG;
}
if (ret == MP_OKAY) {
a->used = digits;
a->used = (word32)digits;
}
#endif
/* fill the data with random bytes */
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) {
#ifdef USE_INTEGER_HEAP_MATH
@@ -264,7 +264,8 @@ int wc_export_int(mp_int* mp, byte* buf, word32* len, word32 keySz,
}
*len = keySz;
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;

View File

@@ -4845,7 +4845,7 @@ WOLFSSL_TEST_SUBROUTINE int hash_test(void)
for (i = 0; i < (int)(sizeof(typesHashBad)/sizeof(*typesHashBad)); i++) {
ret = wc_Hash(typesHashBad[i], data, sizeof(data), out, sizeof(out));
if (ret != BAD_FUNC_ARG && ret != BUFFER_E)
if ((ret != BAD_FUNC_ARG) && (ret != BUFFER_E) && (ret != HASH_TYPE_E))
return WC_TEST_RET_ENC_I(i);
}

View File

@@ -76,8 +76,8 @@ enum {
MAX_TLS13_HKDF_LABEL_SZ = 47 + WC_MAX_DIGEST_SIZE
};
WOLFSSL_API int wc_Tls13_HKDF_Extract(byte* prk, const byte* salt, int saltLen,
byte* ikm, int ikmLen, int digest);
WOLFSSL_API int wc_Tls13_HKDF_Extract(byte* prk, const byte* salt,
word32 saltLen, byte* ikm, word32 ikmLen, int digest);
WOLFSSL_API int wc_Tls13_HKDF_Expand_Label(byte* okm, word32 okmLen,
const byte* prk, word32 prkLen,

View File

@@ -128,6 +128,7 @@ WOLFSSL_LOCAL word16 ctMask16Eq(int a, int b);
WOLFSSL_LOCAL byte ctMaskNotEq(int a, int b);
WOLFSSL_LOCAL byte ctMaskSel(byte m, byte a, byte b);
WOLFSSL_LOCAL int ctMaskSelInt(byte m, int a, int b);
WOLFSSL_LOCAL word32 ctMaskSelWord32(byte m, word32 a, word32 b);
WOLFSSL_LOCAL byte ctSetLTE(int a, int b);
WOLFSSL_LOCAL void ctMaskCopy(byte mask, byte* dst, byte* src, word16 size);
WOLFSSL_LOCAL word32 MakeWordFromHash(const byte* hashID);

View File

@@ -667,12 +667,12 @@ typedef struct sp_ecc_ctx {
*
* @param [in] a SP integer to update.
*/
#define sp_clamp(a) \
do { \
int ii; \
for (ii = (a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
} \
(a)->used = ii + 1; \
#define sp_clamp(a) \
do { \
int ii; \
for (ii = (int)(a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
} \
(a)->used = (unsigned int)ii + 1; \
} while (0)
/* Check the compiled and linked math implementation are the same.
@@ -759,7 +759,7 @@ typedef struct sp_ecc_ctx {
/* Calculate the number of words required to support a number of bits. */
#define MP_BITS_CNT(bits) \
(((bits + SP_WORD_SIZE - 1) / SP_WORD_SIZE) * 2 + 1)
((((bits) + SP_WORD_SIZE - 1) / SP_WORD_SIZE) * 2 + 1)
#ifdef WOLFSSL_SMALL_STACK
/*
@@ -772,13 +772,13 @@ typedef struct sp_ecc_ctx {
#define DECL_MP_INT_SIZE(name, bits) \
sp_int* name = NULL
/* Allocate an mp_int of minimal size and zero out. */
#define NEW_MP_INT_SIZE(name, bits, heap, type) \
do { \
name = (mp_int*)XMALLOC(MP_INT_SIZEOF(MP_BITS_CNT(bits)), heap, type); \
if (name != NULL) { \
XMEMSET(name, 0, MP_INT_SIZEOF(MP_BITS_CNT(bits))); \
} \
} \
#define NEW_MP_INT_SIZE(name, bits, heap, type) \
do { \
(name) = (mp_int*)XMALLOC(MP_INT_SIZEOF(MP_BITS_CNT(bits)), heap, type); \
if ((name) != NULL) { \
XMEMSET(name, 0, MP_INT_SIZEOF(MP_BITS_CNT(bits))); \
} \
} \
while (0)
/* Dispose of dynamically allocated mp_int. */
#define FREE_MP_INT_SIZE(name, heap, type) \
@@ -891,7 +891,7 @@ typedef sp_int_digit mp_digit;
*/
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,
sp_int* n5, sp_int* n6);
MP_API void sp_free(sp_int* a);