diff --git a/bn_fast_mp_montgomery_reduce.c b/bn_fast_mp_montgomery_reduce.c index 1f2acfc..d2d55a8 100644 --- a/bn_fast_mp_montgomery_reduce.c +++ b/bn_fast_mp_montgomery_reduce.c @@ -32,7 +32,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) olduse = x->used; /* grow a as required */ - if (x->alloc < n->used + 1) { + if (x->alloc < (n->used + 1)) { if ((res = mp_grow (x, n->used + 1)) != MP_OKAY) { return res; } @@ -57,7 +57,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) } /* zero the high words of W[a->used..m->used*2] */ - for (; ix < n->used * 2 + 1; ix++) { + for (; ix < ((n->used * 2) + 1); ix++) { *_W++ = 0; } } @@ -126,7 +126,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) /* alias for next word, where the carry goes */ _W = W + ++ix; - for (; ix <= n->used * 2 + 1; ix++) { + for (; ix <= ((n->used * 2) + 1); ix++) { *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT); } @@ -143,7 +143,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) /* alias for shifted double precision result */ _W = W + n->used; - for (ix = 0; ix < n->used + 1; ix++) { + for (ix = 0; ix < (n->used + 1); ix++) { *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK)); } diff --git a/bn_fast_s_mp_mul_digs.c b/bn_fast_s_mp_mul_digs.c index a32e9a2..aaad804 100644 --- a/bn_fast_s_mp_mul_digs.c +++ b/bn_fast_s_mp_mul_digs.c @@ -87,7 +87,7 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) { register mp_digit *tmpc; tmpc = c->dp; - for (ix = 0; ix < pa+1; ix++) { + for (ix = 0; ix < (pa + 1); ix++) { /* now extract the previous digit [below the carry] */ *tmpc++ = W[ix]; } diff --git a/bn_mp_2expt.c b/bn_mp_2expt.c index 1b72ab7..2845814 100644 --- a/bn_mp_2expt.c +++ b/bn_mp_2expt.c @@ -29,12 +29,12 @@ mp_2expt (mp_int * a, int b) mp_zero (a); /* grow a to accomodate the single bit */ - if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) { + if ((res = mp_grow (a, (b / DIGIT_BIT) + 1)) != MP_OKAY) { return res; } /* set the used count of where the bit will go */ - a->used = b / DIGIT_BIT + 1; + a->used = (b / DIGIT_BIT) + 1; /* put the single bit in its place */ a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT); diff --git a/bn_mp_add_d.c b/bn_mp_add_d.c index 81b0c28..4d4e1df 100644 --- a/bn_mp_add_d.c +++ b/bn_mp_add_d.c @@ -23,14 +23,14 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c) mp_digit *tmpa, *tmpc, mu; /* grow c as required */ - if (c->alloc < a->used + 1) { + if (c->alloc < (a->used + 1)) { if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) { return res; } } /* if a is negative and |a| >= b, call c = |a| - b */ - if (a->sign == MP_NEG && (a->used > 1 || a->dp[0] >= b)) { + if ((a->sign == MP_NEG) && ((a->used > 1) || (a->dp[0] >= b))) { /* temporarily fix sign of a */ a->sign = MP_ZPOS; diff --git a/bn_mp_clamp.c b/bn_mp_clamp.c index c75d553..d4fb70d 100644 --- a/bn_mp_clamp.c +++ b/bn_mp_clamp.c @@ -28,7 +28,7 @@ mp_clamp (mp_int * a) /* decrease used while the most significant digit is * zero. */ - while (a->used > 0 && a->dp[a->used - 1] == 0) { + while ((a->used > 0) && (a->dp[a->used - 1] == 0)) { --(a->used); } diff --git a/bn_mp_cnt_lsb.c b/bn_mp_cnt_lsb.c index b5a7a05..9d7eef8 100644 --- a/bn_mp_cnt_lsb.c +++ b/bn_mp_cnt_lsb.c @@ -31,7 +31,7 @@ int mp_cnt_lsb(mp_int *a) } /* scan lower digits until non-zero */ - for (x = 0; x < a->used && a->dp[x] == 0; x++) {} + for (x = 0; (x < a->used) && (a->dp[x] == 0); x++) {} q = a->dp[x]; x *= DIGIT_BIT; diff --git a/bn_mp_div.c b/bn_mp_div.c index da79523..db5fffb 100644 --- a/bn_mp_div.c +++ b/bn_mp_div.c @@ -71,7 +71,7 @@ int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d) /* now q == quotient and ta == remainder */ n = a->sign; - n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG); + n2 = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; if (c != NULL) { mp_exch(c, &q); c->sign = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2; @@ -213,7 +213,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) /* find left hand */ mp_zero (&t1); - t1.dp[0] = (t - 1 < 0) ? 0 : y.dp[t - 1]; + t1.dp[0] = ((t - 1) < 0) ? 0 : y.dp[t - 1]; t1.dp[1] = y.dp[t]; t1.used = 2; if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) { @@ -221,8 +221,8 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) } /* find right hand */ - t2.dp[0] = (i - 2 < 0) ? 0 : x.dp[i - 2]; - t2.dp[1] = (i - 1 < 0) ? 0 : x.dp[i - 1]; + t2.dp[0] = ((i - 2) < 0) ? 0 : x.dp[i - 2]; + t2.dp[1] = ((i - 1) < 0) ? 0 : x.dp[i - 1]; t2.dp[2] = x.dp[i]; t2.used = 3; } while (mp_cmp_mag(&t1, &t2) == MP_GT); @@ -261,7 +261,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) */ /* get sign before writing to c */ - x.sign = x.used == 0 ? MP_ZPOS : a->sign; + x.sign = (x.used == 0) ? MP_ZPOS : a->sign; if (c != NULL) { mp_clamp (&q); diff --git a/bn_mp_div_d.c b/bn_mp_div_d.c index 205a9b1..4df1d36 100644 --- a/bn_mp_div_d.c +++ b/bn_mp_div_d.c @@ -47,7 +47,7 @@ int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d) } /* quick outs */ - if (b == 1 || mp_iszero(a) == MP_YES) { + if ((b == 1) || (mp_iszero(a) == MP_YES)) { if (d != NULL) { *d = 0; } diff --git a/bn_mp_dr_reduce.c b/bn_mp_dr_reduce.c index caabf16..2273c79 100644 --- a/bn_mp_dr_reduce.c +++ b/bn_mp_dr_reduce.c @@ -40,7 +40,7 @@ mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k) m = n->used; /* ensure that "x" has at least 2m digits */ - if (x->alloc < m + m) { + if (x->alloc < (m + m)) { if ((err = mp_grow (x, m + m)) != MP_OKAY) { return err; } @@ -62,7 +62,7 @@ top: /* compute (x mod B**m) + k * [x/B**m] inline and inplace */ for (i = 0; i < m; i++) { - r = ((mp_word)*tmpx2++) * ((mp_word)k) + *tmpx1 + mu; + r = (((mp_word)*tmpx2++) * (mp_word)k) + *tmpx1 + mu; *tmpx1++ = (mp_digit)(r & MP_MASK); mu = (mp_digit)(r >> ((mp_word)DIGIT_BIT)); } diff --git a/bn_mp_export.c b/bn_mp_export.c index cb96bff..fd31301 100644 --- a/bn_mp_export.c +++ b/bn_mp_export.c @@ -37,7 +37,7 @@ int mp_export(void* rop, size_t* countp, int order, size_t size, } lint; lint.i = 0x01020304; - endian = (lint.c[0] == 4 ? -1 : 1); + endian = (lint.c[0] == 4) ? -1 : 1; } odd_nails = (nails % 8); @@ -48,14 +48,14 @@ int mp_export(void* rop, size_t* countp, int order, size_t size, nail_bytes = nails / 8; bits = mp_count_bits(&t); - count = bits / (size * 8 - nails) + ((bits % (size * 8 - nails) != 0) ? 1 : 0); + count = (bits / ((size * 8) - nails)) + (((bits % ((size * 8) - nails)) != 0) ? 1 : 0); for (i = 0; i < count; ++i) { for (j = 0; j < size; ++j) { unsigned char* byte = ( (unsigned char*)rop + - (order == -1 ? i : count - 1 - i) * size + - (endian == -1 ? j : size - 1 - j) + (((order == -1) ? i : (count - 1 - i)) * size) + + ((endian == -1) ? j : (size - 1 - j)) ); if (j >= (size - nail_bytes)) { @@ -63,9 +63,9 @@ int mp_export(void* rop, size_t* countp, int order, size_t size, continue; } - *byte = (unsigned char)(j == size - nail_bytes - 1 ? (t.dp[0] & odd_nail_mask) : t.dp[0] & 0xFF); + *byte = (unsigned char)((j == (size - nail_bytes - 1)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFF)); - if ((result = mp_div_2d(&t, (j == size - nail_bytes - 1 ? 8 - odd_nails : 8), &t, NULL)) != MP_OKAY) { + if ((result = mp_div_2d(&t, ((j == (size - nail_bytes - 1)) ? (8 - odd_nails) : 8), &t, NULL)) != MP_OKAY) { mp_clear(&t); return result; } diff --git a/bn_mp_exptmod.c b/bn_mp_exptmod.c index eeb0aa1..0973e44 100644 --- a/bn_mp_exptmod.c +++ b/bn_mp_exptmod.c @@ -89,7 +89,7 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y) /* if the modulus is odd or dr != 0 use the montgomery method */ #ifdef BN_MP_EXPTMOD_FAST_C - if (mp_isodd (P) == MP_YES || dr != 0) { + if ((mp_isodd (P) == MP_YES) || (dr != 0)) { return mp_exptmod_fast (G, X, P, Y, dr); } else { #endif diff --git a/bn_mp_exptmod_fast.c b/bn_mp_exptmod_fast.c index e5671e1..8d280bd 100644 --- a/bn_mp_exptmod_fast.c +++ b/bn_mp_exptmod_fast.c @@ -96,8 +96,8 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode /* automatically pick the comba one if available (saves quite a few calls/ifs) */ #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C - if (((P->used * 2 + 1) < MP_WARRAY) && - P->used < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { + if ((((P->used * 2) + 1) < MP_WARRAY) && + (P->used < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { redux = fast_mp_montgomery_reduce; } else #endif @@ -219,12 +219,12 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode * in the exponent. Technically this opt is not required but it * does lower the # of trivial squaring/reductions used */ - if (mode == 0 && y == 0) { + if ((mode == 0) && (y == 0)) { continue; } /* if the bit is zero and mode == 1 then we square */ - if (mode == 1 && y == 0) { + if ((mode == 1) && (y == 0)) { if ((err = mp_sqr (&res, &res)) != MP_OKAY) { goto LBL_RES; } @@ -266,7 +266,7 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode } /* if bits remain then square/multiply */ - if (mode == 2 && bitcpy > 0) { + if ((mode == 2) && (bitcpy > 0)) { /* square then multiply if the bit is set */ for (x = 0; x < bitcpy; x++) { if ((err = mp_sqr (&res, &res)) != MP_OKAY) { diff --git a/bn_mp_get_int.c b/bn_mp_get_int.c index d1addab..99fb850 100644 --- a/bn_mp_get_int.c +++ b/bn_mp_get_int.c @@ -26,7 +26,7 @@ unsigned long mp_get_int(mp_int * a) } /* get number of digits of the lsb we have to read */ - i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1; + i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; /* get most significant digit of result */ res = DIGIT(a,i); diff --git a/bn_mp_get_long.c b/bn_mp_get_long.c index ec64b2e..7c3d0fe 100644 --- a/bn_mp_get_long.c +++ b/bn_mp_get_long.c @@ -26,12 +26,12 @@ unsigned long mp_get_long(mp_int * a) } /* get number of digits of the lsb we have to read */ - i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1; + i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; /* get most significant digit of result */ res = DIGIT(a,i); -#if ULONG_MAX != 0xffffffffuL || DIGIT_BIT < 32 +#if (ULONG_MAX != 0xffffffffuL) || (DIGIT_BIT < 32) while (--i >= 0) { res = (res << DIGIT_BIT) | DIGIT(a,i); } diff --git a/bn_mp_get_long_long.c b/bn_mp_get_long_long.c index 49faf5e..4b959e6 100644 --- a/bn_mp_get_long_long.c +++ b/bn_mp_get_long_long.c @@ -26,7 +26,7 @@ unsigned long long mp_get_long_long (mp_int * a) } /* get number of digits of the lsb we have to read */ - i = MIN(a->used,(int)((sizeof(unsigned long long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1; + i = MIN(a->used,(int)(((sizeof(unsigned long long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; /* get most significant digit of result */ res = DIGIT(a,i); diff --git a/bn_mp_import.c b/bn_mp_import.c index 13b587c..2f97880 100644 --- a/bn_mp_import.c +++ b/bn_mp_import.c @@ -33,7 +33,7 @@ int mp_import(mp_int* rop, size_t count, int order, size_t size, } lint; lint.i = 0x01020304; - endian = (lint.c[0] == 4 ? -1 : 1); + endian = (lint.c[0] == 4) ? -1 : 1; } odd_nails = (nails % 8); @@ -44,19 +44,19 @@ int mp_import(mp_int* rop, size_t count, int order, size_t size, nail_bytes = nails / 8; for (i = 0; i < count; ++i) { - for (j = 0; j < size - nail_bytes; ++j) { + for (j = 0; j < (size - nail_bytes); ++j) { unsigned char byte = *( (unsigned char*)op + - (order == 1 ? i : count - 1 - i) * size + - (endian == 1 ? j + nail_bytes : size - 1 - j - nail_bytes) + (((order == 1) ? i : (count - 1 - i)) * size) + + ((endian == 1) ? (j + nail_bytes) : (size - 1 - j - nail_bytes)) ); if ( - (result = mp_mul_2d(rop, (j == 0 ? 8 - odd_nails : 8), rop)) != MP_OKAY) { + (result = mp_mul_2d(rop, ((j == 0) ? (8 - odd_nails) : 8), rop)) != MP_OKAY) { return result; } - rop->dp[0] |= (j == 0 ? (byte & odd_nail_mask) : byte); + rop->dp[0] |= (j == 0) ? (byte & odd_nail_mask) : byte; rop->used += 1; } } diff --git a/bn_mp_invmod.c b/bn_mp_invmod.c index c8e65d1..44951e5 100644 --- a/bn_mp_invmod.c +++ b/bn_mp_invmod.c @@ -19,7 +19,7 @@ int mp_invmod (mp_int * a, mp_int * b, mp_int * c) { /* b cannot be negative */ - if (b->sign == MP_NEG || mp_iszero(b) == MP_YES) { + if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) { return MP_VAL; } diff --git a/bn_mp_invmod_slow.c b/bn_mp_invmod_slow.c index 0f73820..a21f947 100644 --- a/bn_mp_invmod_slow.c +++ b/bn_mp_invmod_slow.c @@ -22,7 +22,7 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c) int res; /* b cannot be negative */ - if (b->sign == MP_NEG || mp_iszero(b) == MP_YES) { + if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) { return MP_VAL; } @@ -41,7 +41,7 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c) } /* 2. [modified] if x,y are both even then return an error! */ - if (mp_iseven (&x) == MP_YES && mp_iseven (&y) == MP_YES) { + if ((mp_iseven (&x) == MP_YES) && (mp_iseven (&y) == MP_YES)) { res = MP_VAL; goto LBL_ERR; } @@ -64,7 +64,7 @@ top: goto LBL_ERR; } /* 4.2 if A or B is odd then */ - if (mp_isodd (&A) == MP_YES || mp_isodd (&B) == MP_YES) { + if ((mp_isodd (&A) == MP_YES) || (mp_isodd (&B) == MP_YES)) { /* A = (A+y)/2, B = (B-x)/2 */ if ((res = mp_add (&A, &y, &A)) != MP_OKAY) { goto LBL_ERR; @@ -89,7 +89,7 @@ top: goto LBL_ERR; } /* 5.2 if C or D is odd then */ - if (mp_isodd (&C) == MP_YES || mp_isodd (&D) == MP_YES) { + if ((mp_isodd (&C) == MP_YES) || (mp_isodd (&D) == MP_YES)) { /* C = (C+y)/2, D = (D-x)/2 */ if ((res = mp_add (&C, &y, &C)) != MP_OKAY) { goto LBL_ERR; diff --git a/bn_mp_jacobi.c b/bn_mp_jacobi.c index 6a1155d..8be097a 100644 --- a/bn_mp_jacobi.c +++ b/bn_mp_jacobi.c @@ -73,9 +73,9 @@ int mp_jacobi (mp_int * a, mp_int * n, int *c) /* else set s=1 if p = 1/7 (mod 8) or s=-1 if p = 3/5 (mod 8) */ residue = n->dp[0] & 7; - if (residue == 1 || residue == 7) { + if ((residue == 1) || (residue == 7)) { s = 1; - } else if (residue == 3 || residue == 5) { + } else if ((residue == 3) || (residue == 5)) { s = -1; } } diff --git a/bn_mp_lshd.c b/bn_mp_lshd.c index 5952651..88bffe0 100644 --- a/bn_mp_lshd.c +++ b/bn_mp_lshd.c @@ -26,7 +26,7 @@ int mp_lshd (mp_int * a, int b) } /* grow to fit the new digits */ - if (a->alloc < a->used + b) { + if (a->alloc < (a->used + b)) { if ((res = mp_grow (a, a->used + b)) != MP_OKAY) { return res; } diff --git a/bn_mp_mod.c b/bn_mp_mod.c index c66ecb0..b67467d 100644 --- a/bn_mp_mod.c +++ b/bn_mp_mod.c @@ -31,7 +31,7 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c) return res; } - if (mp_iszero(&t) != MP_NO || t.sign == b->sign) { + if ((mp_iszero(&t) != MP_NO) || (t.sign == b->sign)) { res = MP_OKAY; mp_exch (&t, c); } else { diff --git a/bn_mp_mod_2d.c b/bn_mp_mod_2d.c index b515341..926f810 100644 --- a/bn_mp_mod_2d.c +++ b/bn_mp_mod_2d.c @@ -39,7 +39,7 @@ mp_mod_2d (mp_int * a, int b, mp_int * c) } /* zero digits above the last digit of the modulus */ - for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) { + for (x = (b / DIGIT_BIT) + (((b % DIGIT_BIT) == 0) ? 0 : 1); x < c->used; x++) { c->dp[x] = 0; } /* clear the digit that is not completely outside/inside the modulus */ diff --git a/bn_mp_montgomery_calc_normalization.c b/bn_mp_montgomery_calc_normalization.c index 4617492..ea87cbd 100644 --- a/bn_mp_montgomery_calc_normalization.c +++ b/bn_mp_montgomery_calc_normalization.c @@ -29,7 +29,7 @@ int mp_montgomery_calc_normalization (mp_int * a, mp_int * b) bits = mp_count_bits (b) % DIGIT_BIT; if (b->used > 1) { - if ((res = mp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1)) != MP_OKAY) { + if ((res = mp_2expt (a, ((b->used - 1) * DIGIT_BIT) + bits - 1)) != MP_OKAY) { return res; } } else { diff --git a/bn_mp_montgomery_reduce.c b/bn_mp_montgomery_reduce.c index 663fbe5..d2a65c2 100644 --- a/bn_mp_montgomery_reduce.c +++ b/bn_mp_montgomery_reduce.c @@ -28,10 +28,10 @@ mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) * than the available columns [255 per default] since carries * are fixed up in the inner loop. */ - digs = n->used * 2 + 1; + digs = (n->used * 2) + 1; if ((digs < MP_WARRAY) && - n->used < - (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { + (n->used < + (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { return fast_mp_montgomery_reduce (x, n, rho); } @@ -52,7 +52,7 @@ mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) * following inner loop to reduce the * input one digit at a time */ - mu = (mp_digit) (((mp_word)x->dp[ix]) * ((mp_word)rho) & MP_MASK); + mu = (mp_digit) (((mp_word)x->dp[ix] * (mp_word)rho) & MP_MASK); /* a = a + mu * m * b**i */ { @@ -72,8 +72,8 @@ mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) /* Multiply and add in place */ for (iy = 0; iy < n->used; iy++) { /* compute product and sum */ - r = ((mp_word)mu) * ((mp_word)*tmpn++) + - ((mp_word) u) + ((mp_word) * tmpx); + r = ((mp_word)mu * (mp_word)*tmpn++) + + (mp_word) u + (mp_word) *tmpx; /* get carry */ u = (mp_digit)(r >> ((mp_word) DIGIT_BIT)); diff --git a/bn_mp_montgomery_setup.c b/bn_mp_montgomery_setup.c index e27f739..264a2bd 100644 --- a/bn_mp_montgomery_setup.c +++ b/bn_mp_montgomery_setup.c @@ -36,15 +36,15 @@ mp_montgomery_setup (mp_int * n, mp_digit * rho) } x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ - x *= 2 - b * x; /* here x*a==1 mod 2**8 */ + x *= 2 - (b * x); /* here x*a==1 mod 2**8 */ #if !defined(MP_8BIT) - x *= 2 - b * x; /* here x*a==1 mod 2**16 */ + x *= 2 - (b * x); /* here x*a==1 mod 2**16 */ #endif #if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT)) - x *= 2 - b * x; /* here x*a==1 mod 2**32 */ + x *= 2 - (b * x); /* here x*a==1 mod 2**32 */ #endif #ifdef MP_64BIT - x *= 2 - b * x; /* here x*a==1 mod 2**64 */ + x *= 2 - (b * x); /* here x*a==1 mod 2**64 */ #endif /* rho = -1/m mod b */ diff --git a/bn_mp_mul.c b/bn_mp_mul.c index a22f6ed..ea53d5e 100644 --- a/bn_mp_mul.c +++ b/bn_mp_mul.c @@ -44,8 +44,8 @@ int mp_mul (mp_int * a, mp_int * b, mp_int * c) #ifdef BN_FAST_S_MP_MUL_DIGS_C if ((digs < MP_WARRAY) && - MIN(a->used, b->used) <= - (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { + (MIN(a->used, b->used) <= + (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { res = fast_s_mp_mul_digs (a, b, c, digs); } else #endif diff --git a/bn_mp_mul_2.c b/bn_mp_mul_2.c index f6c4c69..0859c64 100644 --- a/bn_mp_mul_2.c +++ b/bn_mp_mul_2.c @@ -21,7 +21,7 @@ int mp_mul_2(mp_int * a, mp_int * b) int x, res, oldused; /* grow to accomodate result */ - if (b->alloc < a->used + 1) { + if (b->alloc < (a->used + 1)) { if ((res = mp_grow (b, a->used + 1)) != MP_OKAY) { return res; } diff --git a/bn_mp_mul_2d.c b/bn_mp_mul_2d.c index 50d4563..9506814 100644 --- a/bn_mp_mul_2d.c +++ b/bn_mp_mul_2d.c @@ -28,8 +28,8 @@ int mp_mul_2d (mp_int * a, int b, mp_int * c) } } - if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) { - if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) { + if (c->alloc < (int)(c->used + (b / DIGIT_BIT) + 1)) { + if ((res = mp_grow (c, c->used + (b / DIGIT_BIT) + 1)) != MP_OKAY) { return res; } } diff --git a/bn_mp_mul_d.c b/bn_mp_mul_d.c index 37253ad..e77da5d 100644 --- a/bn_mp_mul_d.c +++ b/bn_mp_mul_d.c @@ -24,7 +24,7 @@ mp_mul_d (mp_int * a, mp_digit b, mp_int * c) int ix, res, olduse; /* make sure c is big enough to hold a*b */ - if (c->alloc < a->used + 1) { + if (c->alloc < (a->used + 1)) { if ((res = mp_grow (c, a->used + 1)) != MP_OKAY) { return res; } @@ -48,7 +48,7 @@ mp_mul_d (mp_int * a, mp_digit b, mp_int * c) /* compute columns */ for (ix = 0; ix < a->used; ix++) { /* compute product and carry sum for this term */ - r = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b); + r = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b); /* mask off higher bits to get a single digit */ *tmpc++ = (mp_digit) (r & ((mp_word) MP_MASK)); diff --git a/bn_mp_n_root_ex.c b/bn_mp_n_root_ex.c index ace6647..79d1dfb 100644 --- a/bn_mp_n_root_ex.c +++ b/bn_mp_n_root_ex.c @@ -31,7 +31,7 @@ int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast) int res, neg; /* input must be positive if b is even */ - if ((b & 1) == 0 && a->sign == MP_NEG) { + if (((b & 1) == 0) && (a->sign == MP_NEG)) { return MP_VAL; } diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c index 7687365..be5ebe4 100644 --- a/bn_mp_prime_is_prime.c +++ b/bn_mp_prime_is_prime.c @@ -31,7 +31,7 @@ int mp_prime_is_prime (mp_int * a, int t, int *result) *result = MP_NO; /* valid value of t? */ - if (t <= 0 || t > PRIME_SIZE) { + if ((t <= 0) || (t > PRIME_SIZE)) { return MP_VAL; } diff --git a/bn_mp_prime_miller_rabin.c b/bn_mp_prime_miller_rabin.c index f610ea5..7b5c8d2 100644 --- a/bn_mp_prime_miller_rabin.c +++ b/bn_mp_prime_miller_rabin.c @@ -67,10 +67,10 @@ int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result) } /* if y != 1 and y != n1 do */ - if (mp_cmp_d (&y, 1) != MP_EQ && mp_cmp (&y, &n1) != MP_EQ) { + if ((mp_cmp_d (&y, 1) != MP_EQ) && (mp_cmp (&y, &n1) != MP_EQ)) { j = 1; /* while j <= s-1 and y != n1 */ - while ((j <= (s - 1)) && mp_cmp (&y, &n1) != MP_EQ) { + while ((j <= (s - 1)) && (mp_cmp (&y, &n1) != MP_EQ)) { if ((err = mp_sqrmod (&y, a, &y)) != MP_OKAY) { goto LBL_Y; } diff --git a/bn_mp_prime_next_prime.c b/bn_mp_prime_next_prime.c index 3e08918..9951dc3 100644 --- a/bn_mp_prime_next_prime.c +++ b/bn_mp_prime_next_prime.c @@ -27,7 +27,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style) mp_int b; /* ensure t is valid */ - if (t <= 0 || t > PRIME_SIZE) { + if ((t <= 0) || (t > PRIME_SIZE)) { return MP_VAL; } @@ -129,7 +129,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style) y = 1; } } - } while (y == 1 && step < ((((mp_digit)1)<= ((((mp_digit)1)<= ((((mp_digit)1) << DIGIT_BIT) - kstep))) { continue; } diff --git a/bn_mp_prime_random_ex.c b/bn_mp_prime_random_ex.c index 9d96b67..1efc4fc 100644 --- a/bn_mp_prime_random_ex.c +++ b/bn_mp_prime_random_ex.c @@ -36,7 +36,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback int res, err, bsize, maskOR_msb_offset; /* sanity check the input */ - if (size <= 1 || t <= 0) { + if ((size <= 1) || (t <= 0)) { return MP_VAL; } diff --git a/bn_mp_radix_size.c b/bn_mp_radix_size.c index f35aa21..e5d7772 100644 --- a/bn_mp_radix_size.c +++ b/bn_mp_radix_size.c @@ -25,7 +25,7 @@ int mp_radix_size (mp_int * a, int radix, int *size) *size = 0; /* make sure the radix is in range */ - if (radix < 2 || radix > 64) { + if ((radix < 2) || (radix > 64)) { return MP_VAL; } @@ -36,7 +36,7 @@ int mp_radix_size (mp_int * a, int radix, int *size) /* special case for binary */ if (radix == 2) { - *size = mp_count_bits (a) + (a->sign == MP_NEG ? 1 : 0) + 1; + *size = mp_count_bits (a) + ((a->sign == MP_NEG) ? 1 : 0) + 1; return MP_OKAY; } diff --git a/bn_mp_read_radix.c b/bn_mp_read_radix.c index 390540e..5c9eb5e 100644 --- a/bn_mp_read_radix.c +++ b/bn_mp_read_radix.c @@ -25,7 +25,7 @@ int mp_read_radix (mp_int * a, const char *str, int radix) mp_zero(a); /* make sure the radix is ok */ - if (radix < 2 || radix > 64) { + if ((radix < 2) || (radix > 64)) { return MP_VAL; } diff --git a/bn_mp_sqr.c b/bn_mp_sqr.c index e39c518..10c6a5b 100644 --- a/bn_mp_sqr.c +++ b/bn_mp_sqr.c @@ -36,9 +36,9 @@ mp_sqr (mp_int * a, mp_int * b) { #ifdef BN_FAST_S_MP_SQR_C /* can we use the fast comba multiplier? */ - if ((a->used * 2 + 1) < MP_WARRAY && - a->used < - (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) { + if ((((a->used * 2) + 1) < MP_WARRAY) && + (a->used < + (1 << ((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT) - 1)))) { res = fast_s_mp_sqr (a, b); } else #endif diff --git a/bn_mp_sub_d.c b/bn_mp_sub_d.c index e1c613e..f5a932f 100644 --- a/bn_mp_sub_d.c +++ b/bn_mp_sub_d.c @@ -23,7 +23,7 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) int res, ix, oldused; /* grow c as required */ - if (c->alloc < a->used + 1) { + if (c->alloc < (a->used + 1)) { if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) { return res; } @@ -49,7 +49,7 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) tmpc = c->dp; /* if a <= b simply fix the single digit */ - if ((a->used == 1 && a->dp[0] <= b) || a->used == 0) { + if (((a->used == 1) && (a->dp[0] <= b)) || (a->used == 0)) { if (a->used == 1) { *tmpc++ = b - *tmpa; } else { @@ -67,13 +67,13 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) /* subtract first digit */ *tmpc = *tmpa++ - b; - mu = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1); + mu = *tmpc >> ((sizeof(mp_digit) * CHAR_BIT) - 1); *tmpc++ &= MP_MASK; /* handle rest of the digits */ for (ix = 1; ix < a->used; ix++) { *tmpc = *tmpa++ - mu; - mu = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1); + mu = *tmpc >> ((sizeof(mp_digit) * CHAR_BIT) - 1); *tmpc++ &= MP_MASK; } } diff --git a/bn_mp_toradix.c b/bn_mp_toradix.c index 0734353..f04352d 100644 --- a/bn_mp_toradix.c +++ b/bn_mp_toradix.c @@ -24,7 +24,7 @@ int mp_toradix (mp_int * a, char *str, int radix) char *_s = str; /* check range of the radix */ - if (radix < 2 || radix > 64) { + if ((radix < 2) || (radix > 64)) { return MP_VAL; } diff --git a/bn_mp_toradix_n.c b/bn_mp_toradix_n.c index 9710e5d..19b61d7 100644 --- a/bn_mp_toradix_n.c +++ b/bn_mp_toradix_n.c @@ -27,7 +27,7 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen) char *_s = str; /* check range of the maxlen, radix */ - if (maxlen < 2 || radix < 2 || radix > 64) { + if ((maxlen < 2) || (radix < 2) || (radix > 64)) { return MP_VAL; } diff --git a/bn_mp_unsigned_bin_size.c b/bn_mp_unsigned_bin_size.c index 637b041..0312625 100644 --- a/bn_mp_unsigned_bin_size.c +++ b/bn_mp_unsigned_bin_size.c @@ -19,7 +19,7 @@ int mp_unsigned_bin_size (mp_int * a) { int size = mp_count_bits (a); - return (size / 8 + ((size & 7) != 0 ? 1 : 0)); + return (size / 8) + (((size & 7) != 0) ? 1 : 0); } #endif diff --git a/bn_s_mp_add.c b/bn_s_mp_add.c index 4790cd9..47fdaf1 100644 --- a/bn_s_mp_add.c +++ b/bn_s_mp_add.c @@ -36,7 +36,7 @@ s_mp_add (mp_int * a, mp_int * b, mp_int * c) } /* init result */ - if (c->alloc < max + 1) { + if (c->alloc < (max + 1)) { if ((res = mp_grow (c, max + 1)) != MP_OKAY) { return res; } diff --git a/bn_s_mp_exptmod.c b/bn_s_mp_exptmod.c index 269a7ba..63e1b1e 100644 --- a/bn_s_mp_exptmod.c +++ b/bn_s_mp_exptmod.c @@ -164,12 +164,12 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode) * in the exponent. Technically this opt is not required but it * does lower the # of trivial squaring/reductions used */ - if (mode == 0 && y == 0) { + if ((mode == 0) && (y == 0)) { continue; } /* if the bit is zero and mode == 1 then we square */ - if (mode == 1 && y == 0) { + if ((mode == 1) && (y == 0)) { if ((err = mp_sqr (&res, &res)) != MP_OKAY) { goto LBL_RES; } @@ -211,7 +211,7 @@ int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode) } /* if bits remain then square/multiply */ - if (mode == 2 && bitcpy > 0) { + if ((mode == 2) && (bitcpy > 0)) { /* square then multiply if the bit is set */ for (x = 0; x < bitcpy; x++) { if ((err = mp_sqr (&res, &res)) != MP_OKAY) { diff --git a/bn_s_mp_mul_digs.c b/bn_s_mp_mul_digs.c index 69e11d6..bd8553d 100644 --- a/bn_s_mp_mul_digs.c +++ b/bn_s_mp_mul_digs.c @@ -29,8 +29,8 @@ int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) /* can we use the fast multiplier? */ if (((digs) < MP_WARRAY) && - MIN (a->used, b->used) < - (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { + (MIN (a->used, b->used) < + (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { return fast_s_mp_mul_digs (a, b, c, digs); } @@ -61,9 +61,9 @@ int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) /* compute the columns of the output and propagate the carry */ for (iy = 0; iy < pb; iy++) { /* compute the column as a mp_word */ - r = ((mp_word)*tmpt) + - ((mp_word)tmpx) * ((mp_word)*tmpy++) + - ((mp_word) u); + r = (mp_word)*tmpt + + ((mp_word)tmpx * (mp_word)*tmpy++) + + (mp_word)u; /* the new column is the lower part of the result */ *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK)); @@ -72,7 +72,7 @@ int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) u = (mp_digit) (r >> ((mp_word) DIGIT_BIT)); } /* set carry if it is placed below digs */ - if (ix + iy < digs) { + if ((ix + iy) < digs) { *tmpt = u; } } diff --git a/bn_s_mp_mul_high_digs.c b/bn_s_mp_mul_high_digs.c index 3e3b48e..153cea4 100644 --- a/bn_s_mp_mul_high_digs.c +++ b/bn_s_mp_mul_high_digs.c @@ -30,7 +30,7 @@ s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) /* can we use the fast multiplier? */ #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C if (((a->used + b->used + 1) < MP_WARRAY) - && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { + && (MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { return fast_s_mp_mul_high_digs (a, b, c, digs); } #endif @@ -57,9 +57,9 @@ s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) for (iy = digs - ix; iy < pb; iy++) { /* calculate the double precision result */ - r = ((mp_word)*tmpt) + - ((mp_word)tmpx) * ((mp_word)*tmpy++) + - ((mp_word) u); + r = (mp_word)*tmpt + + ((mp_word)tmpx * (mp_word)*tmpy++) + + (mp_word)u; /* get the lower part */ *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK)); diff --git a/bn_s_mp_sqr.c b/bn_s_mp_sqr.c index dd06b77..68c95bc 100644 --- a/bn_s_mp_sqr.c +++ b/bn_s_mp_sqr.c @@ -24,18 +24,18 @@ int s_mp_sqr (mp_int * a, mp_int * b) mp_digit u, tmpx, *tmpt; pa = a->used; - if ((res = mp_init_size (&t, 2*pa + 1)) != MP_OKAY) { + if ((res = mp_init_size (&t, (2 * pa) + 1)) != MP_OKAY) { return res; } /* default used is maximum possible size */ - t.used = 2*pa + 1; + t.used = (2 * pa) + 1; for (ix = 0; ix < pa; ix++) { /* first calculate the digit at 2*ix */ /* calculate double precision result */ - r = ((mp_word) t.dp[2*ix]) + - ((mp_word)a->dp[ix])*((mp_word)a->dp[ix]); + r = (mp_word)t.dp[2*ix] + + ((mp_word)a->dp[ix] * (mp_word)a->dp[ix]); /* store lower part in result */ t.dp[ix+ix] = (mp_digit) (r & ((mp_word) MP_MASK)); @@ -47,7 +47,7 @@ int s_mp_sqr (mp_int * a, mp_int * b) tmpx = a->dp[ix]; /* alias for where to store the results */ - tmpt = t.dp + (2*ix + 1); + tmpt = t.dp + ((2 * ix) + 1); for (iy = ix + 1; iy < pa; iy++) { /* first calculate the product */ diff --git a/bn_s_mp_sub.c b/bn_s_mp_sub.c index 4cf92d5..2dc7743 100644 --- a/bn_s_mp_sub.c +++ b/bn_s_mp_sub.c @@ -54,7 +54,7 @@ s_mp_sub (mp_int * a, mp_int * b, mp_int * c) * if a carry does occur it will propagate all the way to the * MSB. As a result a single shift is enough to get the carry */ - u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1)); + u = *tmpc >> ((mp_digit)((CHAR_BIT * sizeof(mp_digit)) - 1)); /* Clear carry from T[i] */ *tmpc++ &= MP_MASK; @@ -66,7 +66,7 @@ s_mp_sub (mp_int * a, mp_int * b, mp_int * c) *tmpc = *tmpa++ - u; /* U = carry bit of T[i] */ - u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1)); + u = *tmpc >> ((mp_digit)((CHAR_BIT * sizeof(mp_digit)) - 1)); /* Clear carry from T[i] */ *tmpc++ &= MP_MASK;