diff --git a/bn_mp_ilogb.c b/bn_mp_ilogb.c index 6669eb84d..ff237dd35 100644 --- a/bn_mp_ilogb.c +++ b/bn_mp_ilogb.c @@ -42,7 +42,7 @@ static mp_digit s_digit_ilogb(mp_digit base, mp_digit n) while (((mp_digit)(high - low)) > 1uL) { mid = (low + high) >> 1; - bracket_mid = bracket_low * s_pow(base, mid - low) ; + bracket_mid = bracket_low * s_pow(base, (mp_word)(mid - low)); if (N < bracket_mid) { high = mid ; diff --git a/bn_mp_montgomery_reduce.c b/bn_mp_montgomery_reduce.c index 52de86ecb..ffe8341ee 100644 --- a/bn_mp_montgomery_reduce.c +++ b/bn_mp_montgomery_reduce.c @@ -17,8 +17,8 @@ mp_err mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) * are fixed up in the inner loop. */ digs = (n->used * 2) + 1; - if ((digs < (int)MP_WARRAY) && - (x->used <= (int)MP_WARRAY) && + if ((digs < MP_WARRAY) && + (x->used <= MP_WARRAY) && (n->used < MP_MAXFAST)) { return s_mp_montgomery_reduce_fast(x, n, rho); } diff --git a/bn_mp_mul.c b/bn_mp_mul.c index e6f46bf04..f0ca04af4 100644 --- a/bn_mp_mul.c +++ b/bn_mp_mul.c @@ -66,7 +66,7 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) int digs = a->used + b->used + 1; #ifdef BN_S_MP_MUL_DIGS_FAST_C - if ((digs < (int)MP_WARRAY) && + if ((digs < MP_WARRAY) && (MP_MIN(a->used, b->used) <= MP_MAXFAST)) { err = s_mp_mul_digs_fast(a, b, c, digs); } else diff --git a/bn_mp_prime_rand.c b/bn_mp_prime_rand.c index dbf39750c..1cfe514db 100644 --- a/bn_mp_prime_rand.c +++ b/bn_mp_prime_rand.c @@ -45,7 +45,7 @@ mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_pr } /* calc the maskAND value for the MSbyte*/ - maskAND = ((size&7) == 0) ? 0xFF : (unsigned char)(0xFF >> (8 - (size & 7))); + maskAND = ((size&7) == 0) ? 0xFFu : (unsigned char)(0xFFu >> (8 - (size & 7))); /* calc the maskOR_msb */ maskOR_msb = 0; @@ -55,9 +55,9 @@ mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_pr } /* get the maskOR_lsb */ - maskOR_lsb = 1; + maskOR_lsb = 1u; if ((flags & MP_PRIME_BBS) != 0) { - maskOR_lsb |= 3; + maskOR_lsb |= 3u; } do { diff --git a/bn_mp_rand.c b/bn_mp_rand.c index 1818dd08f..7e9052c2b 100644 --- a/bn_mp_rand.c +++ b/bn_mp_rand.c @@ -30,7 +30,7 @@ mp_err mp_rand(mp_int *a, int digits) } /* TODO: We ensure that the highest digit is nonzero. Should this be removed? */ - while ((a->dp[digits - 1] & MP_MASK) == 0) { + while ((a->dp[digits - 1] & MP_MASK) == 0u) { if ((err = s_mp_rand_source(a->dp + digits - 1, sizeof(mp_digit))) != MP_OKAY) { return err; } diff --git a/bn_mp_sqr.c b/bn_mp_sqr.c index 7bb4c0b18..d4c7d171b 100644 --- a/bn_mp_sqr.c +++ b/bn_mp_sqr.c @@ -23,7 +23,7 @@ mp_err mp_sqr(const mp_int *a, mp_int *b) { #ifdef BN_S_MP_SQR_FAST_C /* can we use the fast comba multiplier? */ - if ((((a->used * 2) + 1) < (int)MP_WARRAY) && + if ((((a->used * 2) + 1) < MP_WARRAY) && (a->used < (MP_MAXFAST / 2))) { err = s_mp_sqr_fast(a, b); } else diff --git a/bn_s_mp_exptmod.c b/bn_s_mp_exptmod.c index b1cc0e948..5d5510fc8 100644 --- a/bn_s_mp_exptmod.c +++ b/bn_s_mp_exptmod.c @@ -146,7 +146,7 @@ mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y } /* grab the next msb from the exponent */ - y = (buf >> (mp_digit)(MP_DIGIT_BIT - 1)) & 1; + y = (buf >> (mp_digit)(MP_DIGIT_BIT - 1)) & 1uL; buf <<= (mp_digit)1; /* if the bit is zero and mode == 0 then we ignore it diff --git a/bn_s_mp_exptmod_fast.c b/bn_s_mp_exptmod_fast.c index 6b4483c09..43a2ba116 100644 --- a/bn_s_mp_exptmod_fast.c +++ b/bn_s_mp_exptmod_fast.c @@ -85,7 +85,7 @@ mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_i /* automatically pick the comba one if available (saves quite a few calls/ifs) */ #ifdef BN_S_MP_MONTGOMERY_REDUCE_FAST_C - if ((((P->used * 2) + 1) < (int)MP_WARRAY) && + if ((((P->used * 2) + 1) < MP_WARRAY) && (P->used < MP_MAXFAST)) { redux = s_mp_montgomery_reduce_fast; } else @@ -200,7 +200,7 @@ mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_i } /* grab the next msb from the exponent */ - y = (mp_digit)(buf >> (MP_DIGIT_BIT - 1)) & 1; + y = (mp_digit)(buf >> (MP_DIGIT_BIT - 1)) & 1uL; buf <<= (mp_digit)1; /* if the bit is zero and mode == 0 then we ignore it diff --git a/bn_s_mp_montgomery_reduce_fast.c b/bn_s_mp_montgomery_reduce_fast.c index 59a16e345..843ad124f 100644 --- a/bn_s_mp_montgomery_reduce_fast.c +++ b/bn_s_mp_montgomery_reduce_fast.c @@ -17,7 +17,7 @@ mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho) mp_err err; mp_word W[MP_WARRAY]; - if (x->used > (int)MP_WARRAY) { + if (x->used > MP_WARRAY) { return MP_VAL; } diff --git a/bn_s_mp_mul_digs.c b/bn_s_mp_mul_digs.c index 2f37e028f..64509d4cb 100644 --- a/bn_s_mp_mul_digs.c +++ b/bn_s_mp_mul_digs.c @@ -17,7 +17,7 @@ mp_err s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) mp_digit tmpx, *tmpt, *tmpy; /* can we use the fast multiplier? */ - if ((digs < (int)MP_WARRAY) && + if ((digs < MP_WARRAY) && (MP_MIN(a->used, b->used) < MP_MAXFAST)) { return s_mp_mul_digs_fast(a, b, c, digs); } diff --git a/bn_s_mp_mul_high_digs.c b/bn_s_mp_mul_high_digs.c index e83fa04cc..e5e1ba472 100644 --- a/bn_s_mp_mul_high_digs.c +++ b/bn_s_mp_mul_high_digs.c @@ -17,7 +17,7 @@ mp_err s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) /* can we use the fast multiplier? */ #ifdef BN_S_MP_MUL_HIGH_DIGS_FAST_C - if (((a->used + b->used + 1) < (int)MP_WARRAY) + if (((a->used + b->used + 1) < MP_WARRAY) && (MP_MIN(a->used, b->used) < MP_MAXFAST)) { return s_mp_mul_high_digs_fast(a, b, c, digs); } diff --git a/tommath.h b/tommath.h index 8e68c4e06..9334efff4 100644 --- a/tommath.h +++ b/tommath.h @@ -171,7 +171,7 @@ TOOM_SQR_CUTOFF; #endif /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ -#define PRIVATE_MP_WARRAY (1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1)) +#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1)) #define MP_WARRAY (MP_DEPRECATED_PRAGMA("MP_WARRAY is an internal macro") PRIVATE_MP_WARRAY) #if defined(__GNUC__) && __GNUC__ >= 4