diff --git a/bn_deprecated.c b/bn_deprecated.c index 52196e76e..1306507ee 100644 --- a/bn_deprecated.c +++ b/bn_deprecated.c @@ -43,9 +43,9 @@ mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prim #ifdef BN_MP_RAND_DIGIT_C mp_err mp_rand_digit(mp_digit *r) { - mp_err ret = s_mp_rand_source(r, sizeof(mp_digit)); + mp_err err = s_mp_rand_source(r, sizeof(mp_digit)); *r &= MP_MASK; - return ret; + return err; } #endif #ifdef BN_FAST_MP_INVMOD_C diff --git a/bn_mp_2expt.c b/bn_mp_2expt.c index 993b4e3fb..0ae3df1bf 100644 --- a/bn_mp_2expt.c +++ b/bn_mp_2expt.c @@ -10,14 +10,14 @@ */ mp_err mp_2expt(mp_int *a, int b) { - mp_err res; + mp_err err; /* zero a as per default */ mp_zero(a); /* grow a to accomodate the single bit */ - if ((res = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) { + return err; } /* set the used count of where the bit will go */ diff --git a/bn_mp_abs.c b/bn_mp_abs.c index f2b05260a..00900bbdd 100644 --- a/bn_mp_abs.c +++ b/bn_mp_abs.c @@ -9,12 +9,12 @@ */ mp_err mp_abs(const mp_int *a, mp_int *b) { - mp_err res; + mp_err err; /* copy a to b */ if (a != b) { - if ((res = mp_copy(a, b)) != MP_OKAY) { - return res; + if ((err = mp_copy(a, b)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_add.c b/bn_mp_add.c index 1ded200ea..dfa78de50 100644 --- a/bn_mp_add.c +++ b/bn_mp_add.c @@ -7,7 +7,7 @@ mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c) { mp_sign sa, sb; - mp_err res; + mp_err err; /* get sign of both inputs */ sa = a->sign; @@ -18,7 +18,7 @@ mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c) /* both positive or both negative */ /* add their magnitudes, copy the sign */ c->sign = sa; - res = s_mp_add(a, b, c); + err = s_mp_add(a, b, c); } else { /* one positive, the other negative */ /* subtract the one with the greater magnitude from */ @@ -26,13 +26,13 @@ mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c) /* the sign of the one with the greater magnitude. */ if (mp_cmp_mag(a, b) == MP_LT) { c->sign = sb; - res = s_mp_sub(b, a, c); + err = s_mp_sub(b, a, c); } else { c->sign = sa; - res = s_mp_sub(a, b, c); + err = s_mp_sub(a, b, c); } } - return res; + return err; } #endif diff --git a/bn_mp_add_d.c b/bn_mp_add_d.c index f96674b62..5c0207708 100644 --- a/bn_mp_add_d.c +++ b/bn_mp_add_d.c @@ -6,14 +6,14 @@ /* single digit addition */ mp_err mp_add_d(const mp_int *a, mp_digit b, mp_int *c) { - mp_err res; + mp_err err; int ix, oldused; mp_digit *tmpa, *tmpc, mu; /* grow c as required */ if (c->alloc < (a->used + 1)) { - if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) { + return err; } } @@ -24,7 +24,7 @@ mp_err mp_add_d(const mp_int *a, mp_digit b, mp_int *c) a_.sign = MP_ZPOS; /* c = |a| - b */ - res = mp_sub_d(&a_, b, c); + err = mp_sub_d(&a_, b, c); /* fix sign */ c->sign = MP_NEG; @@ -32,7 +32,7 @@ mp_err mp_add_d(const mp_int *a, mp_digit b, mp_int *c) /* clamp */ mp_clamp(c); - return res; + return err; } /* old number of used digits in c */ diff --git a/bn_mp_addmod.c b/bn_mp_addmod.c index 9205b1c49..2636e2a63 100644 --- a/bn_mp_addmod.c +++ b/bn_mp_addmod.c @@ -6,19 +6,19 @@ /* d = a + b (mod c) */ mp_err mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d) { - mp_err res; + mp_err err; mp_int t; - if ((res = mp_init(&t)) != MP_OKAY) { - return res; + if ((err = mp_init(&t)) != MP_OKAY) { + return err; } - if ((res = mp_add(a, b, &t)) != MP_OKAY) { + if ((err = mp_add(a, b, &t)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } - res = mp_mod(&t, c, d); + err = mp_mod(&t, c, d); mp_clear(&t); - return res; + return err; } #endif diff --git a/bn_mp_and.c b/bn_mp_and.c index cca5ca807..c6c1efee6 100644 --- a/bn_mp_and.c +++ b/bn_mp_and.c @@ -7,19 +7,19 @@ mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c) { int ix, px; - mp_err res; + mp_err err; mp_int t; const mp_int *x; if (a->used > b->used) { - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, a)) != MP_OKAY) { + return err; } px = b->used; x = b; } else { - if ((res = mp_init_copy(&t, b)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, b)) != MP_OKAY) { + return err; } px = a->used; x = a; diff --git a/bn_mp_complement.c b/bn_mp_complement.c index 3a71adbbd..fef1423c5 100644 --- a/bn_mp_complement.c +++ b/bn_mp_complement.c @@ -6,7 +6,7 @@ /* b = ~a */ mp_err mp_complement(const mp_int *a, mp_int *b) { - mp_err res = mp_neg(a, b); - return (res == MP_OKAY) ? mp_sub_d(b, 1uL, b) : res; + mp_err err = mp_neg(a, b); + return (err == MP_OKAY) ? mp_sub_d(b, 1uL, b) : err; } #endif diff --git a/bn_mp_copy.c b/bn_mp_copy.c index 9e023bbf3..141dd0e09 100644 --- a/bn_mp_copy.c +++ b/bn_mp_copy.c @@ -7,7 +7,7 @@ mp_err mp_copy(const mp_int *a, mp_int *b) { int n; - mp_err res; + mp_err err; /* if dst == src do nothing */ if (a == b) { @@ -16,8 +16,8 @@ mp_err mp_copy(const mp_int *a, mp_int *b) /* grow dest */ if (b->alloc < a->used) { - if ((res = mp_grow(b, a->used)) != MP_OKAY) { - return res; + if ((err = mp_grow(b, a->used)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_decr.c b/bn_mp_decr.c index 2e85ecbdb..c6a1572c6 100644 --- a/bn_mp_decr.c +++ b/bn_mp_decr.c @@ -6,15 +6,15 @@ /* Decrement "a" by one like "a--". Changes input! */ mp_err mp_decr(mp_int *a) { - mp_err e = MP_OKAY; if (MP_IS_ZERO(a)) { mp_set(a,1uL); a->sign = MP_NEG; return MP_OKAY; } else if (a->sign == MP_NEG) { + mp_err err; a->sign = MP_ZPOS; - if ((e = mp_incr(a)) != MP_OKAY) { - return e; + if ((err = mp_incr(a)) != MP_OKAY) { + return err; } /* There is no -0 in LTM */ if (!MP_IS_ZERO(a)) { diff --git a/bn_mp_div.c b/bn_mp_div.c index 9bd80ead0..1bf4405fe 100644 --- a/bn_mp_div.c +++ b/bn_mp_div.c @@ -10,7 +10,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) { mp_int ta, tb, tq, q; int n, n2; - mp_err res; + mp_err err; /* is divisor zero ? */ if (MP_IS_ZERO(b)) { @@ -20,40 +20,40 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) /* if a < b then q=0, r = a */ if (mp_cmp_mag(a, b) == MP_LT) { if (d != NULL) { - res = mp_copy(a, d); + err = mp_copy(a, d); } else { - res = MP_OKAY; + err = MP_OKAY; } if (c != NULL) { mp_zero(c); } - return res; + return err; } /* init our temps */ - if ((res = mp_init_multi(&ta, &tb, &tq, &q, NULL)) != MP_OKAY) { - return res; + if ((err = mp_init_multi(&ta, &tb, &tq, &q, NULL)) != MP_OKAY) { + return err; } mp_set(&tq, 1uL); n = mp_count_bits(a) - mp_count_bits(b); - if (((res = mp_abs(a, &ta)) != MP_OKAY) || - ((res = mp_abs(b, &tb)) != MP_OKAY) || - ((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) || - ((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) { + if (((err = mp_abs(a, &ta)) != MP_OKAY) || + ((err = mp_abs(b, &tb)) != MP_OKAY) || + ((err = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) || + ((err = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) { goto LBL_ERR; } while (n-- >= 0) { if (mp_cmp(&tb, &ta) != MP_GT) { - if (((res = mp_sub(&ta, &tb, &ta)) != MP_OKAY) || - ((res = mp_add(&q, &tq, &q)) != MP_OKAY)) { + if (((err = mp_sub(&ta, &tb, &ta)) != MP_OKAY) || + ((err = mp_add(&q, &tq, &q)) != MP_OKAY)) { goto LBL_ERR; } } - if (((res = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) || - ((res = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) { + if (((err = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) || + ((err = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) { goto LBL_ERR; } } @@ -71,7 +71,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) } LBL_ERR: mp_clear_multi(&ta, &tb, &tq, &q, NULL); - return res; + return err; } #else @@ -94,7 +94,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) mp_int q, x, y, t1, t2; int n, t, i, norm; mp_sign neg; - mp_err res; + mp_err err; /* is divisor zero ? */ if (MP_IS_ZERO(b)) { @@ -104,34 +104,34 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) /* if a < b then q=0, r = a */ if (mp_cmp_mag(a, b) == MP_LT) { if (d != NULL) { - res = mp_copy(a, d); + err = mp_copy(a, d); } else { - res = MP_OKAY; + err = MP_OKAY; } if (c != NULL) { mp_zero(c); } - return res; + return err; } - if ((res = mp_init_size(&q, a->used + 2)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&q, a->used + 2)) != MP_OKAY) { + return err; } q.used = a->used + 2; - if ((res = mp_init(&t1)) != MP_OKAY) { + if ((err = mp_init(&t1)) != MP_OKAY) { goto LBL_Q; } - if ((res = mp_init(&t2)) != MP_OKAY) { + if ((err = mp_init(&t2)) != MP_OKAY) { goto LBL_T1; } - if ((res = mp_init_copy(&x, a)) != MP_OKAY) { + if ((err = mp_init_copy(&x, a)) != MP_OKAY) { goto LBL_T2; } - if ((res = mp_init_copy(&y, b)) != MP_OKAY) { + if ((err = mp_init_copy(&y, b)) != MP_OKAY) { goto LBL_X; } @@ -143,10 +143,10 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) norm = mp_count_bits(&y) % MP_DIGIT_BIT; if (norm < (MP_DIGIT_BIT - 1)) { norm = (MP_DIGIT_BIT - 1) - norm; - if ((res = mp_mul_2d(&x, norm, &x)) != MP_OKAY) { + if ((err = mp_mul_2d(&x, norm, &x)) != MP_OKAY) { goto LBL_Y; } - if ((res = mp_mul_2d(&y, norm, &y)) != MP_OKAY) { + if ((err = mp_mul_2d(&y, norm, &y)) != MP_OKAY) { goto LBL_Y; } } else { @@ -158,13 +158,13 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) t = y.used - 1; /* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */ - if ((res = mp_lshd(&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */ + if ((err = mp_lshd(&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */ goto LBL_Y; } while (mp_cmp(&x, &y) != MP_LT) { ++(q.dp[n - t]); - if ((res = mp_sub(&x, &y, &x)) != MP_OKAY) { + if ((err = mp_sub(&x, &y, &x)) != MP_OKAY) { goto LBL_Y; } } @@ -207,7 +207,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) t1.dp[0] = ((t - 1) < 0) ? 0u : 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) { + if ((err = mp_mul_d(&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) { goto LBL_Y; } @@ -219,27 +219,27 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) } while (mp_cmp_mag(&t1, &t2) == MP_GT); /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */ - if ((res = mp_mul_d(&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) { + if ((err = mp_mul_d(&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) { goto LBL_Y; } - if ((res = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) { + if ((err = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) { goto LBL_Y; } - if ((res = mp_sub(&x, &t1, &x)) != MP_OKAY) { + if ((err = mp_sub(&x, &t1, &x)) != MP_OKAY) { goto LBL_Y; } /* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */ if (x.sign == MP_NEG) { - if ((res = mp_copy(&y, &t1)) != MP_OKAY) { + if ((err = mp_copy(&y, &t1)) != MP_OKAY) { goto LBL_Y; } - if ((res = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) { + if ((err = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) { goto LBL_Y; } - if ((res = mp_add(&x, &t1, &x)) != MP_OKAY) { + if ((err = mp_add(&x, &t1, &x)) != MP_OKAY) { goto LBL_Y; } @@ -261,13 +261,13 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) } if (d != NULL) { - if ((res = mp_div_2d(&x, norm, &x, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&x, norm, &x, NULL)) != MP_OKAY) { goto LBL_Y; } mp_exch(&x, d); } - res = MP_OKAY; + err = MP_OKAY; LBL_Y: mp_clear(&y); @@ -279,7 +279,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) mp_clear(&t1); LBL_Q: mp_clear(&q); - return res; + return err; } #endif diff --git a/bn_mp_div_2.c b/bn_mp_div_2.c index a51510b09..2561e5aa2 100644 --- a/bn_mp_div_2.c +++ b/bn_mp_div_2.c @@ -7,12 +7,12 @@ mp_err mp_div_2(const mp_int *a, mp_int *b) { int x, oldused; - mp_err res; + mp_err err; /* copy */ if (b->alloc < a->used) { - if ((res = mp_grow(b, a->used)) != MP_OKAY) { - return res; + if ((err = mp_grow(b, a->used)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_div_2d.c b/bn_mp_div_2d.c index d8c2377bf..c47d5ce35 100644 --- a/bn_mp_div_2d.c +++ b/bn_mp_div_2d.c @@ -8,27 +8,27 @@ mp_err mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d) { mp_digit D, r, rr; int x; - mp_err res; + mp_err err; /* if the shift count is <= 0 then we do no work */ if (b <= 0) { - res = mp_copy(a, c); + err = mp_copy(a, c); if (d != NULL) { mp_zero(d); } - return res; + return err; } /* copy */ - if ((res = mp_copy(a, c)) != MP_OKAY) { - return res; + if ((err = mp_copy(a, c)) != MP_OKAY) { + return err; } /* 'a' should not be used after here - it might be the same as d */ /* get the remainder */ if (d != NULL) { - if ((res = mp_mod_2d(a, b, d)) != MP_OKAY) { - return res; + if ((err = mp_mod_2d(a, b, d)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_div_3.c b/bn_mp_div_3.c index bfa571062..3a23fdff2 100644 --- a/bn_mp_div_3.c +++ b/bn_mp_div_3.c @@ -9,14 +9,14 @@ mp_err mp_div_3(const mp_int *a, mp_int *c, mp_digit *d) mp_int q; mp_word w, t; mp_digit b; - mp_err res; + mp_err err; int ix; /* b = 2**MP_DIGIT_BIT / 3 */ b = ((mp_word)1 << (mp_word)MP_DIGIT_BIT) / (mp_word)3; - if ((res = mp_init_size(&q, a->used)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&q, a->used)) != MP_OKAY) { + return err; } q.used = a->used; @@ -57,7 +57,7 @@ mp_err mp_div_3(const mp_int *a, mp_int *c, mp_digit *d) } mp_clear(&q); - return res; + return err; } #endif diff --git a/bn_mp_div_d.c b/bn_mp_div_d.c index fcfe36a24..780aab66d 100644 --- a/bn_mp_div_d.c +++ b/bn_mp_div_d.c @@ -27,7 +27,7 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d) mp_int q; mp_word w; mp_digit t; - mp_err res; + mp_err err; int ix; /* cannot divide by zero */ @@ -65,8 +65,8 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d) #endif /* no easy answer [c'est la vie]. Just division */ - if ((res = mp_init_size(&q, a->used)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&q, a->used)) != MP_OKAY) { + return err; } q.used = a->used; @@ -94,7 +94,7 @@ mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d) } mp_clear(&q); - return res; + return err; } #endif diff --git a/bn_mp_export.c b/bn_mp_export.c index 5c8a49243..c9de48b80 100644 --- a/bn_mp_export.c +++ b/bn_mp_export.c @@ -9,14 +9,14 @@ mp_err mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, const mp_int *op) { - mp_err result; + mp_err err; size_t odd_nails, nail_bytes, i, j, bits, count; unsigned char odd_nail_mask; mp_int t; - if ((result = mp_init_copy(&t, op)) != MP_OKAY) { - return result; + if ((err = mp_init_copy(&t, op)) != MP_OKAY) { + return err; } if (endian == 0) { @@ -52,9 +52,9 @@ mp_err mp_export(void *rop, size_t *countp, int order, size_t size, *byte = (unsigned char)((j == ((size - nail_bytes) - 1u)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFFuL)); - if ((result = mp_div_2d(&t, (j == ((size - nail_bytes) - 1u)) ? (int)(8u - odd_nails) : 8, &t, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&t, (j == ((size - nail_bytes) - 1u)) ? (int)(8u - odd_nails) : 8, &t, NULL)) != MP_OKAY) { mp_clear(&t); - return result; + return err; } } } diff --git a/bn_mp_expt_d_ex.c b/bn_mp_expt_d_ex.c index f10e42b0c..fdabf8479 100644 --- a/bn_mp_expt_d_ex.c +++ b/bn_mp_expt_d_ex.c @@ -6,13 +6,13 @@ /* calculate c = a**b using a square-multiply algorithm */ mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) { - mp_err res; + mp_err err; unsigned int x; mp_int g; - if ((res = mp_init_copy(&g, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&g, a)) != MP_OKAY) { + return err; } /* set initial result */ @@ -22,17 +22,17 @@ mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) while (b > 0u) { /* if the bit is set multiply */ if ((b & 1u) != 0u) { - if ((res = mp_mul(c, &g, c)) != MP_OKAY) { + if ((err = mp_mul(c, &g, c)) != MP_OKAY) { mp_clear(&g); - return res; + return err; } } /* square */ if (b > 1u) { - if ((res = mp_sqr(&g, &g)) != MP_OKAY) { + if ((err = mp_sqr(&g, &g)) != MP_OKAY) { mp_clear(&g); - return res; + return err; } } @@ -42,16 +42,16 @@ mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) } else { for (x = 0; x < (unsigned)MP_DIGIT_BIT; x++) { /* square */ - if ((res = mp_sqr(c, c)) != MP_OKAY) { + if ((err = mp_sqr(c, c)) != MP_OKAY) { mp_clear(&g); - return res; + return err; } /* if the bit is set multiply */ if ((b & ((mp_digit)1 << (MP_DIGIT_BIT - 1))) != 0u) { - if ((res = mp_mul(c, &g, c)) != MP_OKAY) { + if ((err = mp_mul(c, &g, c)) != MP_OKAY) { mp_clear(&g); - return res; + return err; } } diff --git a/bn_mp_gcd.c b/bn_mp_gcd.c index e74372b08..53029baf3 100644 --- a/bn_mp_gcd.c +++ b/bn_mp_gcd.c @@ -8,7 +8,7 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c) { mp_int u, v; int k, u_lsb, v_lsb; - mp_err res; + mp_err err; /* either zero than gcd is the largest */ if (MP_IS_ZERO(a)) { @@ -19,11 +19,11 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c) } /* get copies of a and b we can modify */ - if ((res = mp_init_copy(&u, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&u, a)) != MP_OKAY) { + return err; } - if ((res = mp_init_copy(&v, b)) != MP_OKAY) { + if ((err = mp_init_copy(&v, b)) != MP_OKAY) { goto LBL_U; } @@ -37,24 +37,24 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c) if (k > 0) { /* divide the power of two out */ - if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) { goto LBL_V; } - if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) { goto LBL_V; } } /* divide any remaining factors of two out */ if (u_lsb != k) { - if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) { goto LBL_V; } } if (v_lsb != k) { - if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) { goto LBL_V; } } @@ -67,26 +67,26 @@ mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c) } /* subtract smallest from largest */ - if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) { + if ((err = s_mp_sub(&v, &u, &v)) != MP_OKAY) { goto LBL_V; } /* Divide out all factors of two */ - if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) { goto LBL_V; } } /* multiply by 2**k which we divided out at the beginning */ - if ((res = mp_mul_2d(&u, k, c)) != MP_OKAY) { + if ((err = mp_mul_2d(&u, k, c)) != MP_OKAY) { goto LBL_V; } c->sign = MP_ZPOS; - res = MP_OKAY; + err = MP_OKAY; LBL_V: mp_clear(&u); LBL_U: mp_clear(&v); - return res; + return err; } #endif diff --git a/bn_mp_get_int.c b/bn_mp_get_int.c index b046c3de4..e3571e1f5 100644 --- a/bn_mp_get_int.c +++ b/bn_mp_get_int.c @@ -7,6 +7,6 @@ unsigned long mp_get_int(const mp_int *a) { /* force result to 32-bits always so it is consistent on non 32-bit platforms */ - return mp_get_long(a) & 0xFFFFFFFFUL; + return mp_get_long(a) & 0xFFFFFFFFuL; } #endif diff --git a/bn_mp_get_long.c b/bn_mp_get_long.c index 4441d63d0..a800efb3d 100644 --- a/bn_mp_get_long.c +++ b/bn_mp_get_long.c @@ -19,7 +19,7 @@ unsigned long mp_get_long(const mp_int *a) /* get most significant digit of result */ res = (unsigned long)a->dp[i]; -#if (ULONG_MAX != 0xFFFFFFFFUL) || (MP_DIGIT_BIT < 32) +#if (ULONG_MAX != 0xFFFFFFFFuL) || (MP_DIGIT_BIT < 32) while (--i >= 0) { res = (res << MP_DIGIT_BIT) | (unsigned long)a->dp[i]; } diff --git a/bn_mp_import.c b/bn_mp_import.c index 37685be86..bd83b96c1 100644 --- a/bn_mp_import.c +++ b/bn_mp_import.c @@ -9,7 +9,7 @@ mp_err mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op) { - mp_err result; + mp_err err; size_t odd_nails, nail_bytes, i, j; unsigned char odd_nail_mask; @@ -38,8 +38,8 @@ mp_err mp_import(mp_int *rop, size_t count, int order, size_t size, (((order == 1) ? i : ((count - 1u) - i)) * size) + ((endian == 1) ? (j + nail_bytes) : (((size - 1u) - j) - nail_bytes))); - if ((result = mp_mul_2d(rop, (j == 0u) ? (int)(8u - odd_nails) : 8, rop)) != MP_OKAY) { - return result; + if ((err = mp_mul_2d(rop, (j == 0u) ? (int)(8u - odd_nails) : 8, rop)) != MP_OKAY) { + return err; } rop->dp[0] |= (j == 0u) ? (mp_digit)(byte & odd_nail_mask) : (mp_digit)byte; diff --git a/bn_mp_incr.c b/bn_mp_incr.c index 5e47d2c07..5d0039e0a 100644 --- a/bn_mp_incr.c +++ b/bn_mp_incr.c @@ -6,14 +6,14 @@ /* Increment "a" by one like "a++". Changes input! */ mp_err mp_incr(mp_int *a) { - mp_err e = MP_OKAY; if (MP_IS_ZERO(a)) { mp_set(a,1uL); return MP_OKAY; } else if (a->sign == MP_NEG) { + mp_err err; a->sign = MP_ZPOS; - if ((e = mp_decr(a)) != MP_OKAY) { - return e; + if ((err = mp_decr(a)) != MP_OKAY) { + return err; } /* There is no -0 in LTM */ if (!MP_IS_ZERO(a)) { diff --git a/bn_mp_init_copy.c b/bn_mp_init_copy.c index e30d5012e..1888203d2 100644 --- a/bn_mp_init_copy.c +++ b/bn_mp_init_copy.c @@ -6,16 +6,16 @@ /* creates "a" then copies b into it */ mp_err mp_init_copy(mp_int *a, const mp_int *b) { - mp_err res; + mp_err err; - if ((res = mp_init_size(a, b->used)) != MP_OKAY) { - return res; + if ((err = mp_init_size(a, b->used)) != MP_OKAY) { + return err; } - if ((res = mp_copy(b, a)) != MP_OKAY) { + if ((err = mp_copy(b, a)) != MP_OKAY) { mp_clear(a); } - return res; + return err; } #endif diff --git a/bn_mp_init_multi.c b/bn_mp_init_multi.c index 09fc25f87..d8390b5a0 100644 --- a/bn_mp_init_multi.c +++ b/bn_mp_init_multi.c @@ -7,7 +7,7 @@ mp_err mp_init_multi(mp_int *mp, ...) { - mp_err res = MP_OKAY; /* Assume ok until proven otherwise */ + mp_err err = MP_OKAY; /* Assume ok until proven otherwise */ int n = 0; /* Number of ok inits */ mp_int *cur_arg = mp; va_list args; @@ -28,14 +28,14 @@ mp_err mp_init_multi(mp_int *mp, ...) cur_arg = va_arg(clean_args, mp_int *); } va_end(clean_args); - res = MP_MEM; + err = MP_MEM; break; } n++; cur_arg = va_arg(args, mp_int *); } va_end(args); - return res; /* Assumed ok, if error flagged above. */ + return err; /* Assumed ok, if error flagged above. */ } #endif diff --git a/bn_mp_is_square.c b/bn_mp_is_square.c index 3142ac9a5..491b576f2 100644 --- a/bn_mp_is_square.c +++ b/bn_mp_is_square.c @@ -28,7 +28,7 @@ static const char rem_105[105] = { /* Store non-zero to ret if arg is square, and zero if not */ mp_err mp_is_square(const mp_int *arg, mp_bool *ret) { - mp_err res; + mp_err err; mp_digit c; mp_int t; unsigned long r; @@ -50,23 +50,23 @@ mp_err mp_is_square(const mp_int *arg, mp_bool *ret) } /* Next check mod 105 (3*5*7) */ - if ((res = mp_mod_d(arg, 105uL, &c)) != MP_OKAY) { - return res; + if ((err = mp_mod_d(arg, 105uL, &c)) != MP_OKAY) { + return err; } if (rem_105[c] == (char)1) { return MP_OKAY; } - if ((res = mp_init_set_int(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) { - return res; + if ((err = mp_init_set_int(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) { + return err; } - if ((res = mp_mod(arg, &t, &t)) != MP_OKAY) { + if ((err = mp_mod(arg, &t, &t)) != MP_OKAY) { goto LBL_ERR; } r = mp_get_int(&t); /* Check for other prime modules, note it's not an ERROR but we must - * free "t" so the easiest way is to goto LBL_ERR. We know that res + * free "t" so the easiest way is to goto LBL_ERR. We know that err * is already equal to MP_OKAY from the mp_mod call */ if (((1uL<<(r%11uL)) & 0x5C4uL) != 0uL) goto LBL_ERR; @@ -78,16 +78,16 @@ mp_err mp_is_square(const mp_int *arg, mp_bool *ret) if (((1uL<<(r%31uL)) & 0x6DE2B848uL) != 0uL) goto LBL_ERR; /* Final check - is sqr(sqrt(arg)) == arg ? */ - if ((res = mp_sqrt(arg, &t)) != MP_OKAY) { + if ((err = mp_sqrt(arg, &t)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sqr(&t, &t)) != MP_OKAY) { + if ((err = mp_sqr(&t, &t)) != MP_OKAY) { goto LBL_ERR; } *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO; LBL_ERR: mp_clear(&t); - return res; + return err; } #endif diff --git a/bn_mp_kronecker.c b/bn_mp_kronecker.c index 2b7fd6e6e..525a82034 100644 --- a/bn_mp_kronecker.c +++ b/bn_mp_kronecker.c @@ -20,7 +20,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) { mp_int a1, p1, r; - mp_err e = MP_OKAY; + mp_err err; int v, k; static const int table[8] = {0, 1, 0, -1, 0, -1, 0, 1}; @@ -28,31 +28,30 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) if (MP_IS_ZERO(p)) { if ((a->used == 1) && (a->dp[0] == 1u)) { *c = 1; - return e; } else { *c = 0; - return e; } + return MP_OKAY; } if (MP_IS_EVEN(a) && MP_IS_EVEN(p)) { *c = 0; - return e; + return MP_OKAY; } - if ((e = mp_init_copy(&a1, a)) != MP_OKAY) { - return e; + if ((err = mp_init_copy(&a1, a)) != MP_OKAY) { + return err; } - if ((e = mp_init_copy(&p1, p)) != MP_OKAY) { + if ((err = mp_init_copy(&p1, p)) != MP_OKAY) { goto LBL_KRON_0; } v = mp_cnt_lsb(&p1); - if ((e = mp_div_2d(&p1, v, &p1, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&p1, v, &p1, NULL)) != MP_OKAY) { goto LBL_KRON_1; } - if ((v & 0x1) == 0) { + if ((v & 1) == 0) { k = 1; } else { k = table[a->dp[0] & 7u]; @@ -65,7 +64,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) } } - if ((e = mp_init(&r)) != MP_OKAY) { + if ((err = mp_init(&r)) != MP_OKAY) { goto LBL_KRON_1; } @@ -81,11 +80,11 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) } v = mp_cnt_lsb(&a1); - if ((e = mp_div_2d(&a1, v, &a1, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&a1, v, &a1, NULL)) != MP_OKAY) { goto LBL_KRON; } - if ((v & 0x1) == 1) { + if ((v & 1) == 1) { k = k * table[p1.dp[0] & 7u]; } @@ -105,14 +104,14 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) } } - if ((e = mp_copy(&a1, &r)) != MP_OKAY) { + if ((err = mp_copy(&a1, &r)) != MP_OKAY) { goto LBL_KRON; } r.sign = MP_ZPOS; - if ((e = mp_mod(&p1, &r, &a1)) != MP_OKAY) { + if ((err = mp_mod(&p1, &r, &a1)) != MP_OKAY) { goto LBL_KRON; } - if ((e = mp_copy(&r, &p1)) != MP_OKAY) { + if ((err = mp_copy(&r, &p1)) != MP_OKAY) { goto LBL_KRON; } } @@ -124,7 +123,7 @@ mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c) LBL_KRON_0: mp_clear(&a1); - return e; + return err; } #endif diff --git a/bn_mp_lcm.c b/bn_mp_lcm.c index ef7ed12b1..c32b269e6 100644 --- a/bn_mp_lcm.c +++ b/bn_mp_lcm.c @@ -6,32 +6,32 @@ /* computes least common multiple as |a*b|/(a, b) */ mp_err mp_lcm(const mp_int *a, const mp_int *b, mp_int *c) { - mp_err res; + mp_err err; mp_int t1, t2; - if ((res = mp_init_multi(&t1, &t2, NULL)) != MP_OKAY) { - return res; + if ((err = mp_init_multi(&t1, &t2, NULL)) != MP_OKAY) { + return err; } /* t1 = get the GCD of the two inputs */ - if ((res = mp_gcd(a, b, &t1)) != MP_OKAY) { + if ((err = mp_gcd(a, b, &t1)) != MP_OKAY) { goto LBL_T; } /* divide the smallest by the GCD */ if (mp_cmp_mag(a, b) == MP_LT) { /* store quotient in t2 such that t2 * b is the LCM */ - if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) { + if ((err = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) { goto LBL_T; } - res = mp_mul(b, &t2, c); + err = mp_mul(b, &t2, c); } else { /* store quotient in t2 such that t2 * a is the LCM */ - if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) { + if ((err = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) { goto LBL_T; } - res = mp_mul(a, &t2, c); + err = mp_mul(a, &t2, c); } /* fix the sign to positive */ @@ -39,6 +39,6 @@ mp_err mp_lcm(const mp_int *a, const mp_int *b, mp_int *c) LBL_T: mp_clear_multi(&t1, &t2, NULL); - return res; + return err; } #endif diff --git a/bn_mp_lshd.c b/bn_mp_lshd.c index b8da2b6cc..d7b694456 100644 --- a/bn_mp_lshd.c +++ b/bn_mp_lshd.c @@ -7,7 +7,8 @@ mp_err mp_lshd(mp_int *a, int b) { int x; - mp_err res; + mp_err err; + mp_digit *top, *bottom; /* if its less than zero return */ if (b <= 0) { @@ -20,37 +21,34 @@ mp_err mp_lshd(mp_int *a, int b) /* grow to fit the new digits */ if (a->alloc < (a->used + b)) { - if ((res = mp_grow(a, a->used + b)) != MP_OKAY) { - return res; + if ((err = mp_grow(a, a->used + b)) != MP_OKAY) { + return err; } } - { - mp_digit *top, *bottom; + /* increment the used by the shift amount then copy upwards */ + a->used += b; - /* increment the used by the shift amount then copy upwards */ - a->used += b; + /* top */ + top = a->dp + a->used - 1; - /* top */ - top = a->dp + a->used - 1; + /* base */ + bottom = (a->dp + a->used - 1) - b; - /* base */ - bottom = (a->dp + a->used - 1) - b; - - /* much like mp_rshd this is implemented using a sliding window - * except the window goes the otherway around. Copying from - * the bottom to the top. see bn_mp_rshd.c for more info. - */ - for (x = a->used - 1; x >= b; x--) { - *top-- = *bottom--; - } + /* much like mp_rshd this is implemented using a sliding window + * except the window goes the otherway around. Copying from + * the bottom to the top. see bn_mp_rshd.c for more info. + */ + for (x = a->used - 1; x >= b; x--) { + *top-- = *bottom--; + } - /* zero the lower digits */ - top = a->dp; - for (x = 0; x < b; x++) { - *top++ = 0; - } + /* zero the lower digits */ + top = a->dp; + for (x = 0; x < b; x++) { + *top++ = 0; } + return MP_OKAY; } #endif diff --git a/bn_mp_mod.c b/bn_mp_mod.c index 3b0d38f24..18b4e6ba3 100644 --- a/bn_mp_mod.c +++ b/bn_mp_mod.c @@ -7,25 +7,25 @@ mp_err mp_mod(const mp_int *a, const mp_int *b, mp_int *c) { mp_int t; - mp_err res; + mp_err err; - if ((res = mp_init_size(&t, b->used)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&t, b->used)) != MP_OKAY) { + return err; } - if ((res = mp_div(a, b, NULL, &t)) != MP_OKAY) { + if ((err = mp_div(a, b, NULL, &t)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } if (MP_IS_ZERO(&t) || (t.sign == b->sign)) { - res = MP_OKAY; + err = MP_OKAY; mp_exch(&t, c); } else { - res = mp_add(b, &t, c); + err = mp_add(b, &t, c); } mp_clear(&t); - return res; + return err; } #endif diff --git a/bn_mp_mod_2d.c b/bn_mp_mod_2d.c index a02672f7d..5bf57a1a3 100644 --- a/bn_mp_mod_2d.c +++ b/bn_mp_mod_2d.c @@ -7,7 +7,7 @@ mp_err mp_mod_2d(const mp_int *a, int b, mp_int *c) { int x; - mp_err res; + mp_err err; /* if b is <= 0 then zero the int */ if (b <= 0) { @@ -21,8 +21,8 @@ mp_err mp_mod_2d(const mp_int *a, int b, mp_int *c) } /* copy */ - if ((res = mp_copy(a, c)) != MP_OKAY) { - return res; + if ((err = mp_copy(a, c)) != MP_OKAY) { + return err; } /* zero digits above the last digit of the modulus */ diff --git a/bn_mp_montgomery_calc_normalization.c b/bn_mp_montgomery_calc_normalization.c index 3648ab381..837978925 100644 --- a/bn_mp_montgomery_calc_normalization.c +++ b/bn_mp_montgomery_calc_normalization.c @@ -12,14 +12,14 @@ mp_err mp_montgomery_calc_normalization(mp_int *a, const mp_int *b) { int x, bits; - mp_err res; + mp_err err; /* how many bits of last digit does b use */ bits = mp_count_bits(b) % MP_DIGIT_BIT; if (b->used > 1) { - if ((res = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) { - return res; + if ((err = mp_2expt(a, ((b->used - 1) * MP_DIGIT_BIT) + bits - 1)) != MP_OKAY) { + return err; } } else { mp_set(a, 1uL); @@ -29,12 +29,12 @@ mp_err mp_montgomery_calc_normalization(mp_int *a, const mp_int *b) /* now compute C = A * B mod b */ for (x = bits - 1; x < (int)MP_DIGIT_BIT; x++) { - if ((res = mp_mul_2(a, a)) != MP_OKAY) { - return res; + if ((err = mp_mul_2(a, a)) != MP_OKAY) { + return err; } if (mp_cmp_mag(a, b) != MP_LT) { - if ((res = s_mp_sub(a, b, a)) != MP_OKAY) { - return res; + if ((err = s_mp_sub(a, b, a)) != MP_OKAY) { + return err; } } } diff --git a/bn_mp_montgomery_reduce.c b/bn_mp_montgomery_reduce.c index 2640873c0..52de86ecb 100644 --- a/bn_mp_montgomery_reduce.c +++ b/bn_mp_montgomery_reduce.c @@ -7,7 +7,7 @@ mp_err mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) { int ix, digs; - mp_err res; + mp_err err; mp_digit mu; /* can the fast reduction [comba] method be used? @@ -25,8 +25,8 @@ mp_err mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) /* grow the input as required */ if (x->alloc < digs) { - if ((res = mp_grow(x, digs)) != MP_OKAY) { - return res; + if ((err = mp_grow(x, digs)) != MP_OKAY) { + return err; } } x->used = digs; diff --git a/bn_mp_mul.c b/bn_mp_mul.c index 2fd9df0c5..e6f46bf04 100644 --- a/bn_mp_mul.c +++ b/bn_mp_mul.c @@ -6,7 +6,7 @@ /* high level multiplication (handles sign) */ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) { - mp_err res; + mp_err err; mp_sign neg; #ifdef BN_S_MP_BALANCE_MUL_C int len_b, len_a; @@ -38,7 +38,7 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) goto GO_ON; } - res = s_mp_balance_mul(a,b,c); + err = s_mp_balance_mul(a,b,c); goto END; GO_ON: @@ -47,13 +47,13 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) /* use Toom-Cook? */ #ifdef BN_S_MP_TOOM_MUL_C if (MP_MIN(a->used, b->used) >= MP_TOOM_MUL_CUTOFF) { - res = s_mp_toom_mul(a, b, c); + err = s_mp_toom_mul(a, b, c); } else #endif #ifdef BN_S_MP_KARATSUBA_MUL_C /* use Karatsuba? */ if (MP_MIN(a->used, b->used) >= MP_KARATSUBA_MUL_CUTOFF) { - res = s_mp_karatsuba_mul(a, b, c); + err = s_mp_karatsuba_mul(a, b, c); } else #endif { @@ -68,19 +68,19 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) #ifdef BN_S_MP_MUL_DIGS_FAST_C if ((digs < (int)MP_WARRAY) && (MP_MIN(a->used, b->used) <= MP_MAXFAST)) { - res = s_mp_mul_digs_fast(a, b, c, digs); + err = s_mp_mul_digs_fast(a, b, c, digs); } else #endif { #ifdef BN_S_MP_MUL_DIGS_C - res = s_mp_mul_digs(a, b, c, a->used + b->used + 1); + err = s_mp_mul_digs(a, b, c, a->used + b->used + 1); #else - res = MP_VAL; + err = MP_VAL; #endif } } END: c->sign = (c->used > 0) ? neg : MP_ZPOS; - return res; + return err; } #endif diff --git a/bn_mp_mul_2.c b/bn_mp_mul_2.c index eba23bfc8..bc0691a0d 100644 --- a/bn_mp_mul_2.c +++ b/bn_mp_mul_2.c @@ -7,12 +7,12 @@ mp_err mp_mul_2(const mp_int *a, mp_int *b) { int x, oldused; - mp_err res; + mp_err err; /* grow to accomodate result */ if (b->alloc < (a->used + 1)) { - if ((res = mp_grow(b, a->used + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(b, a->used + 1)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_mul_2d.c b/bn_mp_mul_2d.c index 9ff0d63d0..87354de20 100644 --- a/bn_mp_mul_2d.c +++ b/bn_mp_mul_2d.c @@ -7,25 +7,25 @@ mp_err mp_mul_2d(const mp_int *a, int b, mp_int *c) { mp_digit d; - mp_err res; + mp_err err; /* copy */ if (a != c) { - if ((res = mp_copy(a, c)) != MP_OKAY) { - return res; + if ((err = mp_copy(a, c)) != MP_OKAY) { + return err; } } if (c->alloc < (c->used + (b / MP_DIGIT_BIT) + 1)) { - if ((res = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, c->used + (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) { + return err; } } /* shift by as many digits in the bit count */ if (b >= MP_DIGIT_BIT) { - if ((res = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) { - return res; + if ((err = mp_lshd(c, b / MP_DIGIT_BIT)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_mul_d.c b/bn_mp_mul_d.c index fe7ec7b5a..b56dfa3c9 100644 --- a/bn_mp_mul_d.c +++ b/bn_mp_mul_d.c @@ -8,13 +8,13 @@ mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c) { mp_digit u, *tmpa, *tmpc; mp_word r; - mp_err res; + mp_err err; int ix, olduse; /* make sure c is big enough to hold a*b */ if (c->alloc < (a->used + 1)) { - if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_mulmod.c b/bn_mp_mulmod.c index 10a38dbfe..763f923b1 100644 --- a/bn_mp_mulmod.c +++ b/bn_mp_mulmod.c @@ -6,19 +6,19 @@ /* d = a * b (mod c) */ mp_err mp_mulmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d) { - mp_err res; + mp_err err; mp_int t; - if ((res = mp_init_size(&t, c->used)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&t, c->used)) != MP_OKAY) { + return err; } - if ((res = mp_mul(a, b, &t)) != MP_OKAY) { + if ((err = mp_mul(a, b, &t)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } - res = mp_mod(&t, c, d); + err = mp_mod(&t, c, d); mp_clear(&t); - return res; + return err; } #endif diff --git a/bn_mp_n_root_ex.c b/bn_mp_n_root_ex.c index 8705c6a68..a6ddfdb9b 100644 --- a/bn_mp_n_root_ex.c +++ b/bn_mp_n_root_ex.c @@ -17,23 +17,15 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) mp_int t1, t2, t3, a_; mp_ord cmp; int ilog2; - mp_err res; + mp_err err; /* input must be positive if b is even */ if (((b & 1u) == 0u) && (a->sign == MP_NEG)) { return MP_VAL; } - if ((res = mp_init(&t1)) != MP_OKAY) { - return res; - } - - if ((res = mp_init(&t2)) != MP_OKAY) { - goto LBL_T1; - } - - if ((res = mp_init(&t3)) != MP_OKAY) { - goto LBL_T2; + if ((err = mp_init_multi(&t1, &t2, &t3, NULL)) != MP_OKAY) { + return err; } /* if a is negative fudge the sign but keep track */ @@ -59,8 +51,8 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) if (b > (mp_digit)(INT_MAX/2)) { mp_set(c, 1uL); c->sign = a->sign; - res = MP_OKAY; - goto LBL_T3; + err = MP_OKAY; + goto LBL_ERR; } } #endif @@ -68,57 +60,57 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) if (ilog2 < (int)b) { mp_set(c, 1uL); c->sign = a->sign; - res = MP_OKAY; - goto LBL_T3; + err = MP_OKAY; + goto LBL_ERR; } ilog2 = ilog2 / ((int)b); if (ilog2 == 0) { mp_set(c, 1uL); c->sign = a->sign; - res = MP_OKAY; - goto LBL_T3; + err = MP_OKAY; + goto LBL_ERR; } /* Start value must be larger than root */ ilog2 += 2; - if ((res = mp_2expt(&t2,ilog2)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_2expt(&t2,ilog2)) != MP_OKAY) { + goto LBL_ERR; } do { /* t1 = t2 */ - if ((res = mp_copy(&t2, &t1)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_copy(&t2, &t1)) != MP_OKAY) { + goto LBL_ERR; } /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */ /* t3 = t1**(b-1) */ - if ((res = mp_expt_d_ex(&t1, b - 1u, &t3, fast)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_expt_d_ex(&t1, b - 1u, &t3, fast)) != MP_OKAY) { + goto LBL_ERR; } /* numerator */ /* t2 = t1**b */ - if ((res = mp_mul(&t3, &t1, &t2)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_mul(&t3, &t1, &t2)) != MP_OKAY) { + goto LBL_ERR; } /* t2 = t1**b - a */ - if ((res = mp_sub(&t2, &a_, &t2)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_sub(&t2, &a_, &t2)) != MP_OKAY) { + goto LBL_ERR; } /* denominator */ /* t3 = t1**(b-1) * b */ - if ((res = mp_mul_d(&t3, b, &t3)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_mul_d(&t3, b, &t3)) != MP_OKAY) { + goto LBL_ERR; } /* t3 = (t1**b - a)/(b * t1**(b-1)) */ - if ((res = mp_div(&t2, &t3, &t3, NULL)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_div(&t2, &t3, &t3, NULL)) != MP_OKAY) { + goto LBL_ERR; } - if ((res = mp_sub(&t1, &t3, &t2)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_sub(&t1, &t3, &t2)) != MP_OKAY) { + goto LBL_ERR; } /* Number of rounds is at most log_2(root). If it is more it @@ -132,17 +124,17 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) /* result can be off by a few so check */ /* Loop beneath can overshoot by one if found root is smaller than actual root */ for (;;) { - if ((res = mp_expt_d_ex(&t1, b, &t2, fast)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_expt_d_ex(&t1, b, &t2, fast)) != MP_OKAY) { + goto LBL_ERR; } cmp = mp_cmp(&t2, &a_); if (cmp == MP_EQ) { - res = MP_OKAY; - goto LBL_T3; + err = MP_OKAY; + goto LBL_ERR; } if (cmp == MP_LT) { - if ((res = mp_add_d(&t1, 1uL, &t1)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_add_d(&t1, 1uL, &t1)) != MP_OKAY) { + goto LBL_ERR; } } else { break; @@ -150,12 +142,12 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) } /* correct overshoot from above or from recurrence */ for (;;) { - if ((res = mp_expt_d_ex(&t1, b, &t2, fast)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_expt_d_ex(&t1, b, &t2, fast)) != MP_OKAY) { + goto LBL_ERR; } if (mp_cmp(&t2, &a_) == MP_GT) { - if ((res = mp_sub_d(&t1, 1uL, &t1)) != MP_OKAY) { - goto LBL_T3; + if ((err = mp_sub_d(&t1, 1uL, &t1)) != MP_OKAY) { + goto LBL_ERR; } } else { break; @@ -168,14 +160,10 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) /* set the sign of the result */ c->sign = a->sign; - res = MP_OKAY; + err = MP_OKAY; -LBL_T3: - mp_clear(&t3); -LBL_T2: - mp_clear(&t2); -LBL_T1: - mp_clear(&t1); - return res; +LBL_ERR: + mp_clear_multi(&t1, &t2, &t3, NULL); + return err; } #endif diff --git a/bn_mp_neg.c b/bn_mp_neg.c index 3ca20f87c..264d90097 100644 --- a/bn_mp_neg.c +++ b/bn_mp_neg.c @@ -6,10 +6,10 @@ /* b = -a */ mp_err mp_neg(const mp_int *a, mp_int *b) { - mp_err res; + mp_err err; if (a != b) { - if ((res = mp_copy(a, b)) != MP_OKAY) { - return res; + if ((err = mp_copy(a, b)) != MP_OKAY) { + return err; } } diff --git a/bn_mp_or.c b/bn_mp_or.c index 5ef3f5a6c..254a5f925 100644 --- a/bn_mp_or.c +++ b/bn_mp_or.c @@ -7,19 +7,19 @@ mp_err mp_or(const mp_int *a, const mp_int *b, mp_int *c) { int ix, px; - mp_err res; + mp_err err; mp_int t; const mp_int *x; if (a->used > b->used) { - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, a)) != MP_OKAY) { + return err; } px = b->used; x = b; } else { - if ((res = mp_init_copy(&t, b)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, b)) != MP_OKAY) { + return err; } px = a->used; x = a; diff --git a/bn_mp_prime_frobenius_underwood.c b/bn_mp_prime_frobenius_underwood.c index b437e5e12..c01e28003 100644 --- a/bn_mp_prime_frobenius_underwood.c +++ b/bn_mp_prime_frobenius_underwood.c @@ -28,12 +28,12 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) mp_int T1z, T2z, Np1z, sz, tz; int a, ap2, length, i, j; - mp_err e; + mp_err err; *result = MP_NO; - if ((e = mp_init_multi(&T1z, &T2z, &Np1z, &sz, &tz, NULL)) != MP_OKAY) { - return e; + if ((err = mp_init_multi(&T1z, &T2z, &Np1z, &sz, &tz, NULL)) != MP_OKAY) { + return err; } for (a = 0; a < LTM_FROBENIUS_UNDERWOOD_A; a++) { @@ -45,15 +45,15 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) /* (32764^2 - 4) < 2^31, no bigint for >MP_8BIT needed) */ mp_set_long(&T1z, (unsigned long)a); - if ((e = mp_sqr(&T1z, &T1z)) != MP_OKAY) { + if ((err = mp_sqr(&T1z, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_sub_d(&T1z, 4uL, &T1z)) != MP_OKAY) { + if ((err = mp_sub_d(&T1z, 4uL, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_kronecker(&T1z, N, &j)) != MP_OKAY) { + if ((err = mp_kronecker(&T1z, N, &j)) != MP_OKAY) { goto LBL_FU_ERR; } @@ -68,13 +68,13 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) } /* Tell it a composite and set return value accordingly */ if (a >= LTM_FROBENIUS_UNDERWOOD_A) { - e = MP_ITER; + err = MP_ITER; goto LBL_FU_ERR; } /* Composite if N and (a+4)*(2*a+5) are not coprime */ mp_set_long(&T1z, (unsigned long)((a+4)*((2*a)+5))); - if ((e = mp_gcd(N, &T1z, &T1z)) != MP_OKAY) { + if ((err = mp_gcd(N, &T1z, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } @@ -83,7 +83,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) } ap2 = a + 2; - if ((e = mp_add_d(N, 1uL, &Np1z)) != MP_OKAY) { + if ((err = mp_add_d(N, 1uL, &Np1z)) != MP_OKAY) { goto LBL_FU_ERR; } @@ -97,36 +97,36 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) * tz = ((tz-sz)*(tz+sz))%N; * sz = temp; */ - if ((e = mp_mul_2(&tz, &T2z)) != MP_OKAY) { + if ((err = mp_mul_2(&tz, &T2z)) != MP_OKAY) { goto LBL_FU_ERR; } /* a = 0 at about 50% of the cases (non-square and odd input) */ if (a != 0) { - if ((e = mp_mul_d(&sz, (mp_digit)a, &T1z)) != MP_OKAY) { + if ((err = mp_mul_d(&sz, (mp_digit)a, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_add(&T1z, &T2z, &T2z)) != MP_OKAY) { + if ((err = mp_add(&T1z, &T2z, &T2z)) != MP_OKAY) { goto LBL_FU_ERR; } } - if ((e = mp_mul(&T2z, &sz, &T1z)) != MP_OKAY) { + if ((err = mp_mul(&T2z, &sz, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_sub(&tz, &sz, &T2z)) != MP_OKAY) { + if ((err = mp_sub(&tz, &sz, &T2z)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_add(&sz, &tz, &sz)) != MP_OKAY) { + if ((err = mp_add(&sz, &tz, &sz)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_mul(&sz, &T2z, &tz)) != MP_OKAY) { + if ((err = mp_mul(&sz, &T2z, &tz)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_mod(&tz, N, &tz)) != MP_OKAY) { + if ((err = mp_mod(&tz, N, &tz)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_mod(&T1z, N, &sz)) != MP_OKAY) { + if ((err = mp_mod(&T1z, N, &sz)) != MP_OKAY) { goto LBL_FU_ERR; } if (s_mp_get_bit(&Np1z, (unsigned int)i) == MP_YES) { @@ -136,21 +136,21 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) * sz = temp */ if (a == 0) { - if ((e = mp_mul_2(&sz, &T1z)) != MP_OKAY) { + if ((err = mp_mul_2(&sz, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } } else { - if ((e = mp_mul_d(&sz, (mp_digit)ap2, &T1z)) != MP_OKAY) { + if ((err = mp_mul_d(&sz, (mp_digit)ap2, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } } - if ((e = mp_add(&T1z, &tz, &T1z)) != MP_OKAY) { + if ((err = mp_add(&T1z, &tz, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_mul_2(&tz, &T2z)) != MP_OKAY) { + if ((err = mp_mul_2(&tz, &T2z)) != MP_OKAY) { goto LBL_FU_ERR; } - if ((e = mp_sub(&T2z, &sz, &tz)) != MP_OKAY) { + if ((err = mp_sub(&T2z, &sz, &tz)) != MP_OKAY) { goto LBL_FU_ERR; } mp_exch(&sz, &T1z); @@ -158,7 +158,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) } mp_set_long(&T1z, (unsigned long)((2 * a) + 5)); - if ((e = mp_mod(&T1z, N, &T1z)) != MP_OKAY) { + if ((err = mp_mod(&T1z, N, &T1z)) != MP_OKAY) { goto LBL_FU_ERR; } if (MP_IS_ZERO(&sz) && (mp_cmp(&tz, &T1z) == MP_EQ)) { @@ -168,7 +168,7 @@ mp_err mp_prime_frobenius_underwood(const mp_int *N, mp_bool *result) LBL_FU_ERR: mp_clear_multi(&tz, &sz, &Np1z, &T2z, &T1z, NULL); - return e; + return err; } #endif diff --git a/bn_mp_prime_strong_lucas_selfridge.c b/bn_mp_prime_strong_lucas_selfridge.c index 389f62d10..5f288c86a 100644 --- a/bn_mp_prime_strong_lucas_selfridge.c +++ b/bn_mp_prime_strong_lucas_selfridge.c @@ -71,7 +71,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) mp_int Dz, gcd, Np1, Uz, Vz, U2mz, V2mz, Qmz, Q2mz, Qkdz, T1z, T2z, T3z, T4z, Q2kdz; /* CZ TODO: Some of them need the full 32 bit, hence the (temporary) exclusion of MP_8BIT */ int32_t D, Ds, J, sign, P, Q, r, s, u, Nbits; - mp_err e; + mp_err err; mp_bool oddness; *result = MP_NO; @@ -83,9 +83,9 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) included. */ - if ((e = mp_init_multi(&Dz, &gcd, &Np1, &Uz, &Vz, &U2mz, &V2mz, &Qmz, &Q2mz, &Qkdz, &T1z, &T2z, &T3z, &T4z, &Q2kdz, - NULL)) != MP_OKAY) { - return e; + if ((err = mp_init_multi(&Dz, &gcd, &Np1, &Uz, &Vz, &U2mz, &V2mz, &Qmz, &Q2mz, &Qkdz, &T1z, &T2z, &T3z, &T4z, &Q2kdz, + NULL)) != MP_OKAY) { + return err; } D = 5; @@ -95,7 +95,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) Ds = sign * D; sign = -sign; mp_set_long(&Dz, (unsigned long)D); - if ((e = mp_gcd(a, &Dz, &gcd)) != MP_OKAY) { + if ((err = mp_gcd(a, &Dz, &gcd)) != MP_OKAY) { goto LBL_LS_ERR; } /* if 1 < GCD < N then N is composite with factor "D", and @@ -107,7 +107,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) if (Ds < 0) { Dz.sign = MP_NEG; } - if ((e = mp_kronecker(&Dz, a, &J)) != MP_OKAY) { + if ((err = mp_kronecker(&Dz, a, &J)) != MP_OKAY) { goto LBL_LS_ERR; } @@ -117,7 +117,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) D += 2; if (D > (INT_MAX - 2)) { - e = MP_VAL; + err = MP_VAL; goto LBL_LS_ERR; } } @@ -157,7 +157,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) Baillie-PSW test based on the strong Lucas-Selfridge test should be more reliable. */ - if ((e = mp_add_d(a, 1uL, &Np1)) != MP_OKAY) { + if ((err = mp_add_d(a, 1uL, &Np1)) != MP_OKAY) { goto LBL_LS_ERR; } s = mp_cnt_lsb(&Np1); @@ -169,7 +169,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) * dividing an even number by two does not produce * any leftovers. */ - if ((e = mp_div_2d(&Np1, s, &Dz, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&Np1, s, &Dz, NULL)) != MP_OKAY) { goto LBL_LS_ERR; } /* We must now compute U_d and V_d. Since d is odd, the accumulated @@ -191,7 +191,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) if (Q < 0) { Q = -Q; mp_set_long(&Qmz, (unsigned long)Q); - if ((e = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) { + if ((err = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) { goto LBL_LS_ERR; } /* Initializes calculation of Q^d */ @@ -202,7 +202,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) Q = -Q; } else { mp_set_long(&Qmz, (unsigned long)Q); - if ((e = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) { + if ((err = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) { goto LBL_LS_ERR; } /* Initializes calculation of Q^d */ @@ -220,30 +220,30 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) * V_2m = V_m*V_m - 2*Q^m */ - if ((e = mp_mul(&U2mz, &V2mz, &U2mz)) != MP_OKAY) { + if ((err = mp_mul(&U2mz, &V2mz, &U2mz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mod(&U2mz, a, &U2mz)) != MP_OKAY) { + if ((err = mp_mod(&U2mz, a, &U2mz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_sqr(&V2mz, &V2mz)) != MP_OKAY) { + if ((err = mp_sqr(&V2mz, &V2mz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_sub(&V2mz, &Q2mz, &V2mz)) != MP_OKAY) { + if ((err = mp_sub(&V2mz, &Q2mz, &V2mz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mod(&V2mz, a, &V2mz)) != MP_OKAY) { + if ((err = mp_mod(&V2mz, a, &V2mz)) != MP_OKAY) { goto LBL_LS_ERR; } /* Must calculate powers of Q for use in V_2m, also for Q^d later */ - if ((e = mp_sqr(&Qmz, &Qmz)) != MP_OKAY) { + if ((err = mp_sqr(&Qmz, &Qmz)) != MP_OKAY) { goto LBL_LS_ERR; } /* prevents overflow */ /* CZ still necessary without a fixed prealloc'd mem.? */ - if ((e = mp_mod(&Qmz, a, &Qmz)) != MP_OKAY) { + if ((err = mp_mod(&Qmz, a, &Qmz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) { + if ((err = mp_mul_2(&Qmz, &Q2mz)) != MP_OKAY) { goto LBL_LS_ERR; } if (s_mp_get_bit(&Dz, (unsigned int)u) == MP_YES) { @@ -254,26 +254,26 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) * * Be careful with division by 2 (mod N)! */ - if ((e = mp_mul(&U2mz, &Vz, &T1z)) != MP_OKAY) { + if ((err = mp_mul(&U2mz, &Vz, &T1z)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mul(&Uz, &V2mz, &T2z)) != MP_OKAY) { + if ((err = mp_mul(&Uz, &V2mz, &T2z)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mul(&V2mz, &Vz, &T3z)) != MP_OKAY) { + if ((err = mp_mul(&V2mz, &Vz, &T3z)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mul(&U2mz, &Uz, &T4z)) != MP_OKAY) { + if ((err = mp_mul(&U2mz, &Uz, &T4z)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = s_mp_mul_si(&T4z, (long)Ds, &T4z)) != MP_OKAY) { + if ((err = s_mp_mul_si(&T4z, (long)Ds, &T4z)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) { + if ((err = mp_add(&T1z, &T2z, &Uz)) != MP_OKAY) { goto LBL_LS_ERR; } if (MP_IS_ODD(&Uz)) { - if ((e = mp_add(&Uz, a, &Uz)) != MP_OKAY) { + if ((err = mp_add(&Uz, a, &Uz)) != MP_OKAY) { goto LBL_LS_ERR; } } @@ -283,42 +283,42 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) * But mp_div_2() does not do so, it is truncating instead. */ oddness = MP_IS_ODD(&Uz) ? MP_YES : MP_NO; - if ((e = mp_div_2(&Uz, &Uz)) != MP_OKAY) { + if ((err = mp_div_2(&Uz, &Uz)) != MP_OKAY) { goto LBL_LS_ERR; } if ((Uz.sign == MP_NEG) && (oddness != MP_NO)) { - if ((e = mp_sub_d(&Uz, 1uL, &Uz)) != MP_OKAY) { + if ((err = mp_sub_d(&Uz, 1uL, &Uz)) != MP_OKAY) { goto LBL_LS_ERR; } } - if ((e = mp_add(&T3z, &T4z, &Vz)) != MP_OKAY) { + if ((err = mp_add(&T3z, &T4z, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } if (MP_IS_ODD(&Vz)) { - if ((e = mp_add(&Vz, a, &Vz)) != MP_OKAY) { + if ((err = mp_add(&Vz, a, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } } oddness = MP_IS_ODD(&Vz) ? MP_YES : MP_NO; - if ((e = mp_div_2(&Vz, &Vz)) != MP_OKAY) { + if ((err = mp_div_2(&Vz, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } if ((Vz.sign == MP_NEG) && (oddness != MP_NO)) { - if ((e = mp_sub_d(&Vz, 1uL, &Vz)) != MP_OKAY) { + if ((err = mp_sub_d(&Vz, 1uL, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } } - if ((e = mp_mod(&Uz, a, &Uz)) != MP_OKAY) { + if ((err = mp_mod(&Uz, a, &Uz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mod(&Vz, a, &Vz)) != MP_OKAY) { + if ((err = mp_mod(&Vz, a, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } /* Calculating Q^d for later use */ - if ((e = mp_mul(&Qkdz, &Qmz, &Qkdz)) != MP_OKAY) { + if ((err = mp_mul(&Qkdz, &Qmz, &Qkdz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mod(&Qkdz, a, &Qkdz)) != MP_OKAY) { + if ((err = mp_mod(&Qkdz, a, &Qkdz)) != MP_OKAY) { goto LBL_LS_ERR; } } @@ -343,18 +343,18 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) Lucas pseudoprime. */ /* Initialize 2*Q^(d*2^r) for V_2m */ - if ((e = mp_mul_2(&Qkdz, &Q2kdz)) != MP_OKAY) { + if ((err = mp_mul_2(&Qkdz, &Q2kdz)) != MP_OKAY) { goto LBL_LS_ERR; } for (r = 1; r < s; r++) { - if ((e = mp_sqr(&Vz, &Vz)) != MP_OKAY) { + if ((err = mp_sqr(&Vz, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_sub(&Vz, &Q2kdz, &Vz)) != MP_OKAY) { + if ((err = mp_sub(&Vz, &Q2kdz, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mod(&Vz, a, &Vz)) != MP_OKAY) { + if ((err = mp_mod(&Vz, a, &Vz)) != MP_OKAY) { goto LBL_LS_ERR; } if (MP_IS_ZERO(&Vz)) { @@ -363,20 +363,20 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result) } /* Calculate Q^{d*2^r} for next r (final iteration irrelevant). */ if (r < (s - 1)) { - if ((e = mp_sqr(&Qkdz, &Qkdz)) != MP_OKAY) { + if ((err = mp_sqr(&Qkdz, &Qkdz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mod(&Qkdz, a, &Qkdz)) != MP_OKAY) { + if ((err = mp_mod(&Qkdz, a, &Qkdz)) != MP_OKAY) { goto LBL_LS_ERR; } - if ((e = mp_mul_2(&Qkdz, &Q2kdz)) != MP_OKAY) { + if ((err = mp_mul_2(&Qkdz, &Q2kdz)) != MP_OKAY) { goto LBL_LS_ERR; } } } LBL_LS_ERR: mp_clear_multi(&Q2kdz, &T4z, &T3z, &T2z, &T1z, &Qkdz, &Q2mz, &Qmz, &V2mz, &U2mz, &Vz, &Uz, &Np1, &gcd, &Dz, NULL); - return e; + return err; } #endif #endif diff --git a/bn_mp_radix_size.c b/bn_mp_radix_size.c index ffcc3aae2..6d7f912a0 100644 --- a/bn_mp_radix_size.c +++ b/bn_mp_radix_size.c @@ -6,7 +6,7 @@ /* returns size of ASCII reprensentation */ mp_err mp_radix_size(const mp_int *a, int radix, int *size) { - mp_err res; + mp_err err; int digs; mp_int t; mp_digit d; @@ -38,8 +38,8 @@ mp_err mp_radix_size(const mp_int *a, int radix, int *size) } /* init a copy of the input */ - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, a)) != MP_OKAY) { + return err; } /* force temp to positive */ @@ -47,9 +47,9 @@ mp_err mp_radix_size(const mp_int *a, int radix, int *size) /* fetch out all of the digits */ while (!MP_IS_ZERO(&t)) { - if ((res = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) { + if ((err = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } ++digs; } diff --git a/bn_mp_rand.c b/bn_mp_rand.c index 9bb3f9e3b..1818dd08f 100644 --- a/bn_mp_rand.c +++ b/bn_mp_rand.c @@ -13,7 +13,7 @@ void mp_rand_source(mp_err(*source)(void *out, size_t size)) mp_err mp_rand(mp_int *a, int digits) { int i; - mp_err ret; + mp_err err; mp_zero(a); @@ -21,18 +21,18 @@ mp_err mp_rand(mp_int *a, int digits) return MP_OKAY; } - if ((ret = mp_grow(a, digits)) != MP_OKAY) { - return ret; + if ((err = mp_grow(a, digits)) != MP_OKAY) { + return err; } - if ((ret = s_mp_rand_source(a->dp, (size_t)digits * sizeof(mp_digit))) != MP_OKAY) { - return ret; + if ((err = s_mp_rand_source(a->dp, (size_t)digits * sizeof(mp_digit))) != MP_OKAY) { + return err; } /* TODO: We ensure that the highest digit is nonzero. Should this be removed? */ while ((a->dp[digits - 1] & MP_MASK) == 0) { - if ((ret = s_mp_rand_source(a->dp + digits - 1, sizeof(mp_digit))) != MP_OKAY) { - return ret; + if ((err = s_mp_rand_source(a->dp + digits - 1, sizeof(mp_digit))) != MP_OKAY) { + return err; } } diff --git a/bn_mp_read_radix.c b/bn_mp_read_radix.c index 57a00ccaa..de18e06fc 100644 --- a/bn_mp_read_radix.c +++ b/bn_mp_read_radix.c @@ -8,7 +8,7 @@ /* read a string [ASCII] in a given radix */ mp_err mp_read_radix(mp_int *a, const char *str, int radix) { - mp_err res; + mp_err err; int y; mp_sign neg; unsigned pos; @@ -55,11 +55,11 @@ mp_err mp_read_radix(mp_int *a, const char *str, int radix) if ((y == 0xff) || (y >= radix)) { break; } - if ((res = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) { - return res; + if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) { + return err; } - if ((res = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) { - return res; + if ((err = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) { + return err; } ++str; } diff --git a/bn_mp_read_signed_bin.c b/bn_mp_read_signed_bin.c index 6d868cfed..2e1639957 100644 --- a/bn_mp_read_signed_bin.c +++ b/bn_mp_read_signed_bin.c @@ -6,11 +6,11 @@ /* read signed bin, big endian, first byte is 0==positive or 1==negative */ mp_err mp_read_signed_bin(mp_int *a, const unsigned char *b, int c) { - mp_err res; + mp_err err; /* read magnitude */ - if ((res = mp_read_unsigned_bin(a, b + 1, c - 1)) != MP_OKAY) { - return res; + if ((err = mp_read_unsigned_bin(a, b + 1, c - 1)) != MP_OKAY) { + return err; } /* first byte is 0 for positive, non-zero for negative */ diff --git a/bn_mp_read_unsigned_bin.c b/bn_mp_read_unsigned_bin.c index ae4e8754c..17b273e00 100644 --- a/bn_mp_read_unsigned_bin.c +++ b/bn_mp_read_unsigned_bin.c @@ -6,12 +6,12 @@ /* reads a unsigned char array, assumes the msb is stored first [big endian] */ mp_err mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c) { - mp_err res; + mp_err err; /* make sure there are at least two digits */ if (a->alloc < 2) { - if ((res = mp_grow(a, 2)) != MP_OKAY) { - return res; + if ((err = mp_grow(a, 2)) != MP_OKAY) { + return err; } } @@ -20,8 +20,8 @@ mp_err mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c) /* read the bytes in */ while (c-- > 0) { - if ((res = mp_mul_2d(a, 8, a)) != MP_OKAY) { - return res; + if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) { + return err; } #ifndef MP_8BIT diff --git a/bn_mp_reduce.c b/bn_mp_reduce.c index 4b7852b3d..d5d3fb102 100644 --- a/bn_mp_reduce.c +++ b/bn_mp_reduce.c @@ -10,12 +10,12 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) { mp_int q; - mp_err res; + mp_err err; int um = m->used; /* q = x */ - if ((res = mp_init_copy(&q, x)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&q, x)) != MP_OKAY) { + return err; } /* q1 = x / b**(k-1) */ @@ -23,21 +23,21 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) /* according to HAC this optimization is ok */ if ((mp_digit)um > ((mp_digit)1 << (MP_DIGIT_BIT - 1))) { - if ((res = mp_mul(&q, mu, &q)) != MP_OKAY) { + if ((err = mp_mul(&q, mu, &q)) != MP_OKAY) { goto CLEANUP; } } else { #ifdef BN_S_MP_MUL_HIGH_DIGS_C - if ((res = s_mp_mul_high_digs(&q, mu, &q, um)) != MP_OKAY) { + if ((err = s_mp_mul_high_digs(&q, mu, &q, um)) != MP_OKAY) { goto CLEANUP; } #elif defined(BN_S_MP_MUL_HIGH_DIGS_FAST_C) - if ((res = s_mp_mul_high_digs_fast(&q, mu, &q, um)) != MP_OKAY) { + if ((err = s_mp_mul_high_digs_fast(&q, mu, &q, um)) != MP_OKAY) { goto CLEANUP; } #else { - res = MP_VAL; + err = MP_VAL; goto CLEANUP; } #endif @@ -47,32 +47,32 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) mp_rshd(&q, um + 1); /* x = x mod b**(k+1), quick (no division) */ - if ((res = mp_mod_2d(x, MP_DIGIT_BIT * (um + 1), x)) != MP_OKAY) { + if ((err = mp_mod_2d(x, MP_DIGIT_BIT * (um + 1), x)) != MP_OKAY) { goto CLEANUP; } /* q = q * m mod b**(k+1), quick (no division) */ - if ((res = s_mp_mul_digs(&q, m, &q, um + 1)) != MP_OKAY) { + if ((err = s_mp_mul_digs(&q, m, &q, um + 1)) != MP_OKAY) { goto CLEANUP; } /* x = x - q */ - if ((res = mp_sub(x, &q, x)) != MP_OKAY) { + if ((err = mp_sub(x, &q, x)) != MP_OKAY) { goto CLEANUP; } /* If x < 0, add b**(k+1) to it */ if (mp_cmp_d(x, 0uL) == MP_LT) { mp_set(&q, 1uL); - if ((res = mp_lshd(&q, um + 1)) != MP_OKAY) + if ((err = mp_lshd(&q, um + 1)) != MP_OKAY) goto CLEANUP; - if ((res = mp_add(x, &q, x)) != MP_OKAY) + if ((err = mp_add(x, &q, x)) != MP_OKAY) goto CLEANUP; } /* Back off if it's too big */ while (mp_cmp(x, m) != MP_LT) { - if ((res = s_mp_sub(x, m, x)) != MP_OKAY) { + if ((err = s_mp_sub(x, m, x)) != MP_OKAY) { goto CLEANUP; } } @@ -80,6 +80,6 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) CLEANUP: mp_clear(&q); - return res; + return err; } #endif diff --git a/bn_mp_reduce_2k.c b/bn_mp_reduce_2k.c index 0bf2ffb26..1cea6cb21 100644 --- a/bn_mp_reduce_2k.c +++ b/bn_mp_reduce_2k.c @@ -7,34 +7,34 @@ mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) { mp_int q; - mp_err res; + mp_err err; int p; - if ((res = mp_init(&q)) != MP_OKAY) { - return res; + if ((err = mp_init(&q)) != MP_OKAY) { + return err; } p = mp_count_bits(n); top: /* q = a/2**p, a = a mod 2**p */ - if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) { + if ((err = mp_div_2d(a, p, &q, a)) != MP_OKAY) { goto LBL_ERR; } if (d != 1u) { /* q = q * d */ - if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) { + if ((err = mp_mul_d(&q, d, &q)) != MP_OKAY) { goto LBL_ERR; } } /* a = a + q */ - if ((res = s_mp_add(a, &q, a)) != MP_OKAY) { + if ((err = s_mp_add(a, &q, a)) != MP_OKAY) { goto LBL_ERR; } if (mp_cmp_mag(a, n) != MP_LT) { - if ((res = s_mp_sub(a, n, a)) != MP_OKAY) { + if ((err = s_mp_sub(a, n, a)) != MP_OKAY) { goto LBL_ERR; } goto top; @@ -42,7 +42,7 @@ mp_err mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) LBL_ERR: mp_clear(&q); - return res; + return err; } #endif diff --git a/bn_mp_reduce_2k_l.c b/bn_mp_reduce_2k_l.c index b2905eda0..6a9f3d31b 100644 --- a/bn_mp_reduce_2k_l.c +++ b/bn_mp_reduce_2k_l.c @@ -10,32 +10,32 @@ mp_err mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) { mp_int q; - mp_err res; + mp_err err; int p; - if ((res = mp_init(&q)) != MP_OKAY) { - return res; + if ((err = mp_init(&q)) != MP_OKAY) { + return err; } p = mp_count_bits(n); top: /* q = a/2**p, a = a mod 2**p */ - if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) { + if ((err = mp_div_2d(a, p, &q, a)) != MP_OKAY) { goto LBL_ERR; } /* q = q * d */ - if ((res = mp_mul(&q, d, &q)) != MP_OKAY) { + if ((err = mp_mul(&q, d, &q)) != MP_OKAY) { goto LBL_ERR; } /* a = a + q */ - if ((res = s_mp_add(a, &q, a)) != MP_OKAY) { + if ((err = s_mp_add(a, &q, a)) != MP_OKAY) { goto LBL_ERR; } if (mp_cmp_mag(a, n) != MP_LT) { - if ((res = s_mp_sub(a, n, a)) != MP_OKAY) { + if ((err = s_mp_sub(a, n, a)) != MP_OKAY) { goto LBL_ERR; } goto top; @@ -43,7 +43,7 @@ mp_err mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d) LBL_ERR: mp_clear(&q); - return res; + return err; } #endif diff --git a/bn_mp_reduce_2k_setup.c b/bn_mp_reduce_2k_setup.c index bae80d9c9..2eaf7addf 100644 --- a/bn_mp_reduce_2k_setup.c +++ b/bn_mp_reduce_2k_setup.c @@ -6,23 +6,23 @@ /* determines the setup value */ mp_err mp_reduce_2k_setup(const mp_int *a, mp_digit *d) { - mp_err res; + mp_err err; mp_int tmp; int p; - if ((res = mp_init(&tmp)) != MP_OKAY) { - return res; + if ((err = mp_init(&tmp)) != MP_OKAY) { + return err; } p = mp_count_bits(a); - if ((res = mp_2expt(&tmp, p)) != MP_OKAY) { + if ((err = mp_2expt(&tmp, p)) != MP_OKAY) { mp_clear(&tmp); - return res; + return err; } - if ((res = s_mp_sub(&tmp, a, &tmp)) != MP_OKAY) { + if ((err = s_mp_sub(&tmp, a, &tmp)) != MP_OKAY) { mp_clear(&tmp); - return res; + return err; } *d = tmp.dp[0]; diff --git a/bn_mp_reduce_2k_setup_l.c b/bn_mp_reduce_2k_setup_l.c index 652942c16..4f9aa14d1 100644 --- a/bn_mp_reduce_2k_setup_l.c +++ b/bn_mp_reduce_2k_setup_l.c @@ -6,23 +6,23 @@ /* determines the setup value */ mp_err mp_reduce_2k_setup_l(const mp_int *a, mp_int *d) { - mp_err res; + mp_err err; mp_int tmp; - if ((res = mp_init(&tmp)) != MP_OKAY) { - return res; + if ((err = mp_init(&tmp)) != MP_OKAY) { + return err; } - if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) { + if ((err = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) { goto LBL_ERR; } - if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) { + if ((err = s_mp_sub(&tmp, a, d)) != MP_OKAY) { goto LBL_ERR; } LBL_ERR: mp_clear(&tmp); - return res; + return err; } #endif diff --git a/bn_mp_reduce_setup.c b/bn_mp_reduce_setup.c index 2e4f961b6..f02160fa5 100644 --- a/bn_mp_reduce_setup.c +++ b/bn_mp_reduce_setup.c @@ -8,9 +8,9 @@ */ mp_err mp_reduce_setup(mp_int *a, const mp_int *b) { - mp_err res; - if ((res = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) { - return res; + mp_err err; + if ((err = mp_2expt(a, b->used * 2 * MP_DIGIT_BIT)) != MP_OKAY) { + return err; } return mp_div(a, b, a, NULL); } diff --git a/bn_mp_rshd.c b/bn_mp_rshd.c index 2bbf597ed..1ab9ba4b8 100644 --- a/bn_mp_rshd.c +++ b/bn_mp_rshd.c @@ -7,6 +7,7 @@ void mp_rshd(mp_int *a, int b) { int x; + mp_digit *bottom, *top; /* if b <= 0 then ignore it */ if (b <= 0) { @@ -19,35 +20,31 @@ void mp_rshd(mp_int *a, int b) return; } - { - mp_digit *bottom, *top; + /* shift the digits down */ - /* shift the digits down */ + /* bottom */ + bottom = a->dp; - /* bottom */ - bottom = a->dp; + /* top [offset into digits] */ + top = a->dp + b; - /* top [offset into digits] */ - top = a->dp + b; + /* this is implemented as a sliding window where + * the window is b-digits long and digits from + * the top of the window are copied to the bottom + * + * e.g. - /* this is implemented as a sliding window where - * the window is b-digits long and digits from - * the top of the window are copied to the bottom - * - * e.g. - - b-2 | b-1 | b0 | b1 | b2 | ... | bb | ----> - /\ | ----> - \-------------------/ ----> - */ - for (x = 0; x < (a->used - b); x++) { - *bottom++ = *top++; - } + b-2 | b-1 | b0 | b1 | b2 | ... | bb | ----> + /\ | ----> + \-------------------/ ----> + */ + for (x = 0; x < (a->used - b); x++) { + *bottom++ = *top++; + } - /* zero the top digits */ - for (; x < a->used; x++) { - *bottom++ = 0; - } + /* zero the top digits */ + for (; x < a->used; x++) { + *bottom++ = 0; } /* remove excess digits */ diff --git a/bn_mp_set_double.c b/bn_mp_set_double.c index efb853375..9e00362ba 100644 --- a/bn_mp_set_double.c +++ b/bn_mp_set_double.c @@ -8,15 +8,15 @@ mp_err mp_set_double(mp_int *a, double b) { uint64_t frac; int exp; - mp_err res; + mp_err err; union { double dbl; uint64_t bits; } cast; cast.dbl = b; - exp = (int)((unsigned)(cast.bits >> 52) & 0x7FFU); - frac = (cast.bits & ((1ULL << 52) - 1ULL)) | (1ULL << 52); + exp = (int)((unsigned)(cast.bits >> 52) & 0x7FFu); + frac = (cast.bits & ((1uLL << 52) - 1uLL)) | (1uLL << 52); if (exp == 0x7FF) { /* +-inf, NaN */ return MP_VAL; @@ -25,12 +25,12 @@ mp_err mp_set_double(mp_int *a, double b) mp_set_long_long(a, frac); - res = (exp < 0) ? mp_div_2d(a, -exp, a, NULL) : mp_mul_2d(a, exp, a); - if (res != MP_OKAY) { - return res; + err = (exp < 0) ? mp_div_2d(a, -exp, a, NULL) : mp_mul_2d(a, exp, a); + if (err != MP_OKAY) { + return err; } - if (((cast.bits >> 63) != 0ULL) && !MP_IS_ZERO(a)) { + if (((cast.bits >> 63) != 0uLL) && !MP_IS_ZERO(a)) { a->sign = MP_NEG; } diff --git a/bn_mp_set_int.c b/bn_mp_set_int.c index a32258073..f0c7434d6 100644 --- a/bn_mp_set_int.c +++ b/bn_mp_set_int.c @@ -6,6 +6,6 @@ /* set a 32-bit const */ mp_err mp_set_int(mp_int *a, unsigned long b) { - return mp_set_long(a, b & 0xFFFFFFFFUL); + return mp_set_long(a, b & 0xFFFFFFFFuL); } #endif diff --git a/bn_mp_sqr.c b/bn_mp_sqr.c index e1e243c6c..7bb4c0b18 100644 --- a/bn_mp_sqr.c +++ b/bn_mp_sqr.c @@ -6,18 +6,18 @@ /* computes b = a*a */ mp_err mp_sqr(const mp_int *a, mp_int *b) { - mp_err res; + mp_err err; #ifdef BN_S_MP_TOOM_SQR_C /* use Toom-Cook? */ if (a->used >= MP_TOOM_SQR_CUTOFF) { - res = s_mp_toom_sqr(a, b); + err = s_mp_toom_sqr(a, b); /* Karatsuba? */ } else #endif #ifdef BN_S_MP_KARATSUBA_SQR_C if (a->used >= MP_KARATSUBA_SQR_CUTOFF) { - res = s_mp_karatsuba_sqr(a, b); + err = s_mp_karatsuba_sqr(a, b); } else #endif { @@ -25,18 +25,18 @@ mp_err mp_sqr(const mp_int *a, mp_int *b) /* can we use the fast comba multiplier? */ if ((((a->used * 2) + 1) < (int)MP_WARRAY) && (a->used < (MP_MAXFAST / 2))) { - res = s_mp_sqr_fast(a, b); + err = s_mp_sqr_fast(a, b); } else #endif { #ifdef BN_S_MP_SQR_C - res = s_mp_sqr(a, b); + err = s_mp_sqr(a, b); #else - res = MP_VAL; + err = MP_VAL; #endif } } b->sign = MP_ZPOS; - return res; + return err; } #endif diff --git a/bn_mp_sqrmod.c b/bn_mp_sqrmod.c index 30d7c46e8..b3c44e5cb 100644 --- a/bn_mp_sqrmod.c +++ b/bn_mp_sqrmod.c @@ -6,19 +6,19 @@ /* c = a * a (mod b) */ mp_err mp_sqrmod(const mp_int *a, const mp_int *b, mp_int *c) { - mp_err res; + mp_err err; mp_int t; - if ((res = mp_init(&t)) != MP_OKAY) { - return res; + if ((err = mp_init(&t)) != MP_OKAY) { + return err; } - if ((res = mp_sqr(a, &t)) != MP_OKAY) { + if ((err = mp_sqr(a, &t)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } - res = mp_mod(&t, b, c); + err = mp_mod(&t, b, c); mp_clear(&t); - return res; + return err; } #endif diff --git a/bn_mp_sqrt.c b/bn_mp_sqrt.c index 74769f507..82d682467 100644 --- a/bn_mp_sqrt.c +++ b/bn_mp_sqrt.c @@ -6,7 +6,7 @@ /* this function is less generic than mp_n_root, simpler and faster */ mp_err mp_sqrt(const mp_int *arg, mp_int *ret) { - mp_err res; + mp_err err; mp_int t1, t2; /* must be positive */ @@ -20,11 +20,11 @@ mp_err mp_sqrt(const mp_int *arg, mp_int *ret) return MP_OKAY; } - if ((res = mp_init_copy(&t1, arg)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t1, arg)) != MP_OKAY) { + return err; } - if ((res = mp_init(&t2)) != MP_OKAY) { + if ((err = mp_init(&t2)) != MP_OKAY) { goto E2; } @@ -32,24 +32,24 @@ mp_err mp_sqrt(const mp_int *arg, mp_int *ret) mp_rshd(&t1, t1.used/2); /* t1 > 0 */ - if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { + if ((err = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { goto E1; } - if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) { + if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY) { goto E1; } - if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) { + if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) { goto E1; } /* And now t1 > sqrt(arg) */ do { - if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { + if ((err = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) { goto E1; } - if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) { + if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY) { goto E1; } - if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) { + if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) { goto E1; } /* t1 >= sqrt(arg) >= t2 at this point */ @@ -61,7 +61,7 @@ mp_err mp_sqrt(const mp_int *arg, mp_int *ret) mp_clear(&t2); E2: mp_clear(&t1); - return res; + return err; } #endif diff --git a/bn_mp_sqrtmod_prime.c b/bn_mp_sqrtmod_prime.c index 6f28238cf..26770ae00 100644 --- a/bn_mp_sqrtmod_prime.c +++ b/bn_mp_sqrtmod_prime.c @@ -11,7 +11,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret) { - mp_err res; + mp_err err; int legendre; mp_int t1, C, Q, S, Z, M, T, R, two; mp_digit i; @@ -22,39 +22,39 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret) return MP_OKAY; } if (mp_cmp_d(prime, 2uL) == MP_EQ) return MP_VAL; /* prime must be odd */ - if ((res = mp_kronecker(n, prime, &legendre)) != MP_OKAY) return res; + if ((err = mp_kronecker(n, prime, &legendre)) != MP_OKAY) return err; if (legendre == -1) return MP_VAL; /* quadratic non-residue mod prime */ - if ((res = mp_init_multi(&t1, &C, &Q, &S, &Z, &M, &T, &R, &two, NULL)) != MP_OKAY) { - return res; + if ((err = mp_init_multi(&t1, &C, &Q, &S, &Z, &M, &T, &R, &two, NULL)) != MP_OKAY) { + return err; } /* SPECIAL CASE: if prime mod 4 == 3 - * compute directly: res = n^(prime+1)/4 mod prime + * compute directly: err = n^(prime+1)/4 mod prime * Handbook of Applied Cryptography algorithm 3.36 */ - if ((res = mp_mod_d(prime, 4uL, &i)) != MP_OKAY) goto cleanup; + if ((err = mp_mod_d(prime, 4uL, &i)) != MP_OKAY) goto cleanup; if (i == 3u) { - if ((res = mp_add_d(prime, 1uL, &t1)) != MP_OKAY) goto cleanup; - if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) goto cleanup; - if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) goto cleanup; - if ((res = mp_exptmod(n, &t1, prime, ret)) != MP_OKAY) goto cleanup; - res = MP_OKAY; + if ((err = mp_add_d(prime, 1uL, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_exptmod(n, &t1, prime, ret)) != MP_OKAY) goto cleanup; + err = MP_OKAY; goto cleanup; } /* NOW: Tonelli-Shanks algorithm */ /* factor out powers of 2 from prime-1, defining Q and S as: prime-1 = Q*2^S */ - if ((res = mp_copy(prime, &Q)) != MP_OKAY) goto cleanup; - if ((res = mp_sub_d(&Q, 1uL, &Q)) != MP_OKAY) goto cleanup; + if ((err = mp_copy(prime, &Q)) != MP_OKAY) goto cleanup; + if ((err = mp_sub_d(&Q, 1uL, &Q)) != MP_OKAY) goto cleanup; /* Q = prime - 1 */ mp_zero(&S); /* S = 0 */ while (MP_IS_EVEN(&Q)) { - if ((res = mp_div_2(&Q, &Q)) != MP_OKAY) goto cleanup; + if ((err = mp_div_2(&Q, &Q)) != MP_OKAY) goto cleanup; /* Q = Q / 2 */ - if ((res = mp_add_d(&S, 1uL, &S)) != MP_OKAY) goto cleanup; + if ((err = mp_add_d(&S, 1uL, &S)) != MP_OKAY) goto cleanup; /* S = S + 1 */ } @@ -62,49 +62,49 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret) mp_set_int(&Z, 2uL); /* Z = 2 */ while (1) { - if ((res = mp_kronecker(&Z, prime, &legendre)) != MP_OKAY) goto cleanup; + if ((err = mp_kronecker(&Z, prime, &legendre)) != MP_OKAY) goto cleanup; if (legendre == -1) break; - if ((res = mp_add_d(&Z, 1uL, &Z)) != MP_OKAY) goto cleanup; + if ((err = mp_add_d(&Z, 1uL, &Z)) != MP_OKAY) goto cleanup; /* Z = Z + 1 */ } - if ((res = mp_exptmod(&Z, &Q, prime, &C)) != MP_OKAY) goto cleanup; + if ((err = mp_exptmod(&Z, &Q, prime, &C)) != MP_OKAY) goto cleanup; /* C = Z ^ Q mod prime */ - if ((res = mp_add_d(&Q, 1uL, &t1)) != MP_OKAY) goto cleanup; - if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_add_d(&Q, 1uL, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_div_2(&t1, &t1)) != MP_OKAY) goto cleanup; /* t1 = (Q + 1) / 2 */ - if ((res = mp_exptmod(n, &t1, prime, &R)) != MP_OKAY) goto cleanup; + if ((err = mp_exptmod(n, &t1, prime, &R)) != MP_OKAY) goto cleanup; /* R = n ^ ((Q + 1) / 2) mod prime */ - if ((res = mp_exptmod(n, &Q, prime, &T)) != MP_OKAY) goto cleanup; + if ((err = mp_exptmod(n, &Q, prime, &T)) != MP_OKAY) goto cleanup; /* T = n ^ Q mod prime */ - if ((res = mp_copy(&S, &M)) != MP_OKAY) goto cleanup; + if ((err = mp_copy(&S, &M)) != MP_OKAY) goto cleanup; /* M = S */ mp_set_int(&two, 2uL); while (1) { - if ((res = mp_copy(&T, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_copy(&T, &t1)) != MP_OKAY) goto cleanup; i = 0; while (1) { if (mp_cmp_d(&t1, 1uL) == MP_EQ) break; - if ((res = mp_exptmod(&t1, &two, prime, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_exptmod(&t1, &two, prime, &t1)) != MP_OKAY) goto cleanup; i++; } if (i == 0u) { - if ((res = mp_copy(&R, ret)) != MP_OKAY) goto cleanup; - res = MP_OKAY; + if ((err = mp_copy(&R, ret)) != MP_OKAY) goto cleanup; + err = MP_OKAY; goto cleanup; } - if ((res = mp_sub_d(&M, i, &t1)) != MP_OKAY) goto cleanup; - if ((res = mp_sub_d(&t1, 1uL, &t1)) != MP_OKAY) goto cleanup; - if ((res = mp_exptmod(&two, &t1, prime, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_sub_d(&M, i, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_sub_d(&t1, 1uL, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_exptmod(&two, &t1, prime, &t1)) != MP_OKAY) goto cleanup; /* t1 = 2 ^ (M - i - 1) */ - if ((res = mp_exptmod(&C, &t1, prime, &t1)) != MP_OKAY) goto cleanup; + if ((err = mp_exptmod(&C, &t1, prime, &t1)) != MP_OKAY) goto cleanup; /* t1 = C ^ (2 ^ (M - i - 1)) mod prime */ - if ((res = mp_sqrmod(&t1, prime, &C)) != MP_OKAY) goto cleanup; + if ((err = mp_sqrmod(&t1, prime, &C)) != MP_OKAY) goto cleanup; /* C = (t1 * t1) mod prime */ - if ((res = mp_mulmod(&R, &t1, prime, &R)) != MP_OKAY) goto cleanup; + if ((err = mp_mulmod(&R, &t1, prime, &R)) != MP_OKAY) goto cleanup; /* R = (R * t1) mod prime */ - if ((res = mp_mulmod(&T, &C, prime, &T)) != MP_OKAY) goto cleanup; + if ((err = mp_mulmod(&T, &C, prime, &T)) != MP_OKAY) goto cleanup; /* T = (T * C) mod prime */ mp_set(&M, i); /* M = i */ @@ -112,7 +112,7 @@ mp_err mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret) cleanup: mp_clear_multi(&t1, &C, &Q, &S, &Z, &M, &T, &R, &two, NULL); - return res; + return err; } #endif diff --git a/bn_mp_sub.c b/bn_mp_sub.c index 00df09ecf..c1ea39e11 100644 --- a/bn_mp_sub.c +++ b/bn_mp_sub.c @@ -7,7 +7,7 @@ mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c) { mp_sign sa = a->sign, sb = b->sign; - mp_err res; + mp_err err; if (sa != sb) { /* subtract a negative from a positive, OR */ @@ -15,7 +15,7 @@ mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c) /* In either case, ADD their magnitudes, */ /* and use the sign of the first number. */ c->sign = sa; - res = s_mp_add(a, b, c); + err = s_mp_add(a, b, c); } else { /* subtract a positive from a positive, OR */ /* subtract a negative from a negative. */ @@ -25,16 +25,16 @@ mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c) /* Copy the sign from the first */ c->sign = sa; /* The first has a larger or equal magnitude */ - res = s_mp_sub(a, b, c); + err = s_mp_sub(a, b, c); } else { /* The result has the *opposite* sign from */ /* the first number. */ c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS; /* The second has a larger magnitude */ - res = s_mp_sub(b, a, c); + err = s_mp_sub(b, a, c); } } - return res; + return err; } #endif diff --git a/bn_mp_sub_d.c b/bn_mp_sub_d.c index c953b61e7..d82605283 100644 --- a/bn_mp_sub_d.c +++ b/bn_mp_sub_d.c @@ -7,13 +7,13 @@ mp_err mp_sub_d(const mp_int *a, mp_digit b, mp_int *c) { mp_digit *tmpa, *tmpc, mu; - mp_err res; + mp_err err; int ix, oldused; /* grow c as required */ if (c->alloc < (a->used + 1)) { - if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) { + return err; } } @@ -23,13 +23,13 @@ mp_err mp_sub_d(const mp_int *a, mp_digit b, mp_int *c) if (a->sign == MP_NEG) { mp_int a_ = *a; a_.sign = MP_ZPOS; - res = mp_add_d(&a_, b, c); + err = mp_add_d(&a_, b, c); c->sign = MP_NEG; /* clamp */ mp_clamp(c); - return res; + return err; } /* setup regs */ diff --git a/bn_mp_submod.c b/bn_mp_submod.c index f265eb164..61c2d0f95 100644 --- a/bn_mp_submod.c +++ b/bn_mp_submod.c @@ -6,19 +6,19 @@ /* d = a - b (mod c) */ mp_err mp_submod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d) { - mp_err res; + mp_err err; mp_int t; - if ((res = mp_init(&t)) != MP_OKAY) { - return res; + if ((err = mp_init(&t)) != MP_OKAY) { + return err; } - if ((res = mp_sub(a, b, &t)) != MP_OKAY) { + if ((err = mp_sub(a, b, &t)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } - res = mp_mod(&t, c, d); + err = mp_mod(&t, c, d); mp_clear(&t); - return res; + return err; } #endif diff --git a/bn_mp_tc_and.c b/bn_mp_tc_and.c index 6361f4c77..8f4a7244d 100644 --- a/bn_mp_tc_and.c +++ b/bn_mp_tc_and.c @@ -6,7 +6,7 @@ /* two complement and */ mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) { - mp_err res = MP_OKAY; + mp_err err = MP_OKAY; int bits, abits, bbits; mp_sign sa = a->sign, sb = b->sign; mp_int *mx = NULL, _mx, acpy, bcpy; @@ -15,38 +15,38 @@ mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) abits = mp_count_bits(a); bbits = mp_count_bits(b); bits = MP_MAX(abits, bbits); - res = mp_init_set_int(&_mx, 1uL); - if (res != MP_OKAY) { + err = mp_init_set_int(&_mx, 1uL); + if (err != MP_OKAY) { goto end; } mx = &_mx; - res = mp_mul_2d(mx, bits + 1, mx); - if (res != MP_OKAY) { + err = mp_mul_2d(mx, bits + 1, mx); + if (err != MP_OKAY) { goto end; } if (sa == MP_NEG) { - res = mp_init(&acpy); - if (res != MP_OKAY) { + err = mp_init(&acpy); + if (err != MP_OKAY) { goto end; } - res = mp_add(mx, a, &acpy); - if (res != MP_OKAY) { + err = mp_add(mx, a, &acpy); + if (err != MP_OKAY) { mp_clear(&acpy); goto end; } a = &acpy; } if (sb == MP_NEG) { - res = mp_init(&bcpy); - if (res != MP_OKAY) { + err = mp_init(&bcpy); + if (err != MP_OKAY) { goto end; } - res = mp_add(mx, b, &bcpy); - if (res != MP_OKAY) { + err = mp_add(mx, b, &bcpy); + if (err != MP_OKAY) { mp_clear(&bcpy); goto end; } @@ -54,10 +54,10 @@ mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) } } - res = mp_and(a, b, c); + err = mp_and(a, b, c); - if ((sa == MP_NEG) && (sb == MP_NEG) && (res == MP_OKAY)) { - res = mp_sub(c, mx, c); + if ((sa == MP_NEG) && (sb == MP_NEG) && (err == MP_OKAY)) { + err = mp_sub(c, mx, c); } end: @@ -73,6 +73,6 @@ mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) mp_clear(mx); } - return res; + return err; } #endif diff --git a/bn_mp_tc_div_2d.c b/bn_mp_tc_div_2d.c index fcb66b676..d7102083b 100644 --- a/bn_mp_tc_div_2d.c +++ b/bn_mp_tc_div_2d.c @@ -6,17 +6,17 @@ /* two complement right shift */ mp_err mp_tc_div_2d(const mp_int *a, int b, mp_int *c) { - mp_err res; + mp_err err; if (a->sign == MP_ZPOS) { return mp_div_2d(a, b, c, NULL); } - res = mp_add_d(a, 1uL, c); - if (res != MP_OKAY) { - return res; + err = mp_add_d(a, 1uL, c); + if (err != MP_OKAY) { + return err; } - res = mp_div_2d(c, b, c, NULL); - return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res; + err = mp_div_2d(c, b, c, NULL); + return (err == MP_OKAY) ? mp_sub_d(c, 1uL, c) : err; } #endif diff --git a/bn_mp_tc_or.c b/bn_mp_tc_or.c index e4cd756c7..2b9eeccfb 100644 --- a/bn_mp_tc_or.c +++ b/bn_mp_tc_or.c @@ -6,7 +6,7 @@ /* two complement or */ mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) { - mp_err res = MP_OKAY; + mp_err err = MP_OKAY; int bits, abits, bbits; mp_sign sa = a->sign, sb = b->sign; mp_int *mx = NULL, _mx, acpy, bcpy; @@ -15,38 +15,38 @@ mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) abits = mp_count_bits(a); bbits = mp_count_bits(b); bits = MP_MAX(abits, bbits); - res = mp_init_set_int(&_mx, 1uL); - if (res != MP_OKAY) { + err = mp_init_set_int(&_mx, 1uL); + if (err != MP_OKAY) { goto end; } mx = &_mx; - res = mp_mul_2d(mx, bits + 1, mx); - if (res != MP_OKAY) { + err = mp_mul_2d(mx, bits + 1, mx); + if (err != MP_OKAY) { goto end; } if (sa == MP_NEG) { - res = mp_init(&acpy); - if (res != MP_OKAY) { + err = mp_init(&acpy); + if (err != MP_OKAY) { goto end; } - res = mp_add(mx, a, &acpy); - if (res != MP_OKAY) { + err = mp_add(mx, a, &acpy); + if (err != MP_OKAY) { mp_clear(&acpy); goto end; } a = &acpy; } if (sb == MP_NEG) { - res = mp_init(&bcpy); - if (res != MP_OKAY) { + err = mp_init(&bcpy); + if (err != MP_OKAY) { goto end; } - res = mp_add(mx, b, &bcpy); - if (res != MP_OKAY) { + err = mp_add(mx, b, &bcpy); + if (err != MP_OKAY) { mp_clear(&bcpy); goto end; } @@ -54,10 +54,10 @@ mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) } } - res = mp_or(a, b, c); + err = mp_or(a, b, c); - if (((sa == MP_NEG) || (sb == MP_NEG)) && (res == MP_OKAY)) { - res = mp_sub(c, mx, c); + if (((sa == MP_NEG) || (sb == MP_NEG)) && (err == MP_OKAY)) { + err = mp_sub(c, mx, c); } end: @@ -73,6 +73,6 @@ mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) mp_clear(mx); } - return res; + return err; } #endif diff --git a/bn_mp_tc_xor.c b/bn_mp_tc_xor.c index 21d46df87..0af0ed24c 100644 --- a/bn_mp_tc_xor.c +++ b/bn_mp_tc_xor.c @@ -6,7 +6,7 @@ /* two complement xor */ mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) { - mp_err res = MP_OKAY; + mp_err err = MP_OKAY; int bits, abits, bbits; mp_sign sa = a->sign, sb = b->sign; mp_int *mx = NULL, _mx, acpy, bcpy; @@ -15,38 +15,38 @@ mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) abits = mp_count_bits(a); bbits = mp_count_bits(b); bits = MP_MAX(abits, bbits); - res = mp_init_set_int(&_mx, 1uL); - if (res != MP_OKAY) { + err = mp_init_set_int(&_mx, 1uL); + if (err != MP_OKAY) { goto end; } mx = &_mx; - res = mp_mul_2d(mx, bits + 1, mx); - if (res != MP_OKAY) { + err = mp_mul_2d(mx, bits + 1, mx); + if (err != MP_OKAY) { goto end; } if (sa == MP_NEG) { - res = mp_init(&acpy); - if (res != MP_OKAY) { + err = mp_init(&acpy); + if (err != MP_OKAY) { goto end; } - res = mp_add(mx, a, &acpy); - if (res != MP_OKAY) { + err = mp_add(mx, a, &acpy); + if (err != MP_OKAY) { mp_clear(&acpy); goto end; } a = &acpy; } if (sb == MP_NEG) { - res = mp_init(&bcpy); - if (res != MP_OKAY) { + err = mp_init(&bcpy); + if (err != MP_OKAY) { goto end; } - res = mp_add(mx, b, &bcpy); - if (res != MP_OKAY) { + err = mp_add(mx, b, &bcpy); + if (err != MP_OKAY) { mp_clear(&bcpy); goto end; } @@ -54,10 +54,10 @@ mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) } } - res = mp_xor(a, b, c); + err = mp_xor(a, b, c); - if ((((sa == MP_NEG) && (sb != MP_NEG)) || ((sa != MP_NEG) && (sb == MP_NEG))) && (res == MP_OKAY)) { - res = mp_sub(c, mx, c); + if ((((sa == MP_NEG) && (sb != MP_NEG)) || ((sa != MP_NEG) && (sb == MP_NEG))) && (err == MP_OKAY)) { + err = mp_sub(c, mx, c); } end: @@ -73,6 +73,6 @@ mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) mp_clear(mx); } - return res; + return err; } #endif diff --git a/bn_mp_to_signed_bin.c b/bn_mp_to_signed_bin.c index 6561ea817..73f37ca79 100644 --- a/bn_mp_to_signed_bin.c +++ b/bn_mp_to_signed_bin.c @@ -6,9 +6,9 @@ /* store in signed [big endian] format */ mp_err mp_to_signed_bin(const mp_int *a, unsigned char *b) { - mp_err res; - if ((res = mp_to_unsigned_bin(a, b + 1)) != MP_OKAY) { - return res; + mp_err err; + if ((err = mp_to_unsigned_bin(a, b + 1)) != MP_OKAY) { + return err; } b[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1; return MP_OKAY; diff --git a/bn_mp_to_unsigned_bin.c b/bn_mp_to_unsigned_bin.c index 6a036255a..093b01aa1 100644 --- a/bn_mp_to_unsigned_bin.c +++ b/bn_mp_to_unsigned_bin.c @@ -7,11 +7,11 @@ mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b) { int x; - mp_err res; + mp_err err; mp_int t; - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, a)) != MP_OKAY) { + return err; } x = 0; @@ -21,9 +21,9 @@ mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b) #else b[x++] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7)); #endif - if ((res = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) { + if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } } s_mp_reverse(b, x); diff --git a/bn_mp_toradix.c b/bn_mp_toradix.c index 856ff25ba..6322e91e1 100644 --- a/bn_mp_toradix.c +++ b/bn_mp_toradix.c @@ -6,7 +6,7 @@ /* stores a bignum as a ASCII string in a given radix (2..64) */ mp_err mp_toradix(const mp_int *a, char *str, int radix) { - mp_err res; + mp_err err; int digs; mp_int t; mp_digit d; @@ -24,8 +24,8 @@ mp_err mp_toradix(const mp_int *a, char *str, int radix) return MP_OKAY; } - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, a)) != MP_OKAY) { + return err; } /* if it is negative output a - */ @@ -37,9 +37,9 @@ mp_err mp_toradix(const mp_int *a, char *str, int radix) digs = 0; while (!MP_IS_ZERO(&t)) { - if ((res = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) { + if ((err = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } *str++ = mp_s_rmap[d]; ++digs; diff --git a/bn_mp_toradix_n.c b/bn_mp_toradix_n.c index 755952efb..bb8af882e 100644 --- a/bn_mp_toradix_n.c +++ b/bn_mp_toradix_n.c @@ -10,7 +10,7 @@ mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) { int digs; - mp_err res; + mp_err err; mp_int t; mp_digit d; char *_s = str; @@ -27,8 +27,8 @@ mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) return MP_OKAY; } - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, a)) != MP_OKAY) { + return err; } /* if it is negative output a - */ @@ -50,9 +50,9 @@ mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen) /* no more room */ break; } - if ((res = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) { + if ((err = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) { mp_clear(&t); - return res; + return err; } *str++ = mp_s_rmap[d]; ++digs; diff --git a/bn_mp_xor.c b/bn_mp_xor.c index a8a77781c..d64706254 100644 --- a/bn_mp_xor.c +++ b/bn_mp_xor.c @@ -7,19 +7,19 @@ mp_err mp_xor(const mp_int *a, const mp_int *b, mp_int *c) { int ix, px; - mp_err res; + mp_err err; mp_int t; const mp_int *x; if (a->used > b->used) { - if ((res = mp_init_copy(&t, a)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, a)) != MP_OKAY) { + return err; } px = b->used; x = b; } else { - if ((res = mp_init_copy(&t, b)) != MP_OKAY) { - return res; + if ((err = mp_init_copy(&t, b)) != MP_OKAY) { + return err; } px = a->used; x = a; diff --git a/bn_s_mp_add.c b/bn_s_mp_add.c index 83df1d37b..c946aa80d 100644 --- a/bn_s_mp_add.c +++ b/bn_s_mp_add.c @@ -7,7 +7,7 @@ mp_err s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) { const mp_int *x; - mp_err res; + mp_err err; int olduse, min, max; /* find sizes, we let |a| <= |b| which means we have to sort @@ -25,8 +25,8 @@ mp_err s_mp_add(const mp_int *a, const mp_int *b, mp_int *c) /* init result */ if (c->alloc < (max + 1)) { - if ((res = mp_grow(c, max + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, max + 1)) != MP_OKAY) { + return err; } } diff --git a/bn_s_mp_balance_mul.c b/bn_s_mp_balance_mul.c index f8de2ecce..efc1809f3 100644 --- a/bn_s_mp_balance_mul.c +++ b/bn_s_mp_balance_mul.c @@ -8,7 +8,7 @@ mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) { int count, len_a, len_b, nblocks, i, j, bsize; mp_int a0, tmp, A, B, r; - mp_err e; + mp_err err; len_a = a->used; len_b = b->used; @@ -16,12 +16,12 @@ mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) nblocks = MP_MAX(a->used, b->used) / MP_MIN(a->used, b->used); bsize = MP_MIN(a->used, b->used) ; - if ((e = mp_init_size(&a0, bsize + 2)) != MP_OKAY) { - return e; + if ((err = mp_init_size(&a0, bsize + 2)) != MP_OKAY) { + return err; } - if ((e = mp_init_multi(&tmp, &r, NULL)) != MP_OKAY) { + if ((err = mp_init_multi(&tmp, &r, NULL)) != MP_OKAY) { mp_clear(&a0); - return e; + return err; } /* Make sure that A is the larger one*/ @@ -41,15 +41,15 @@ mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) a0.used++; } /* Multiply with b */ - if ((e = mp_mul(&a0, &B, &tmp)) != MP_OKAY) { + if ((err = mp_mul(&a0, &B, &tmp)) != MP_OKAY) { goto LBL_ERR; } /* Shift tmp to the correct position */ - if ((e = mp_lshd(&tmp, bsize * i)) != MP_OKAY) { + if ((err = mp_lshd(&tmp, bsize * i)) != MP_OKAY) { goto LBL_ERR; } /* Add to output. No carry needed */ - if ((e = mp_add(&r, &tmp, &r)) != MP_OKAY) { + if ((err = mp_add(&r, &tmp, &r)) != MP_OKAY) { goto LBL_ERR; } } @@ -60,13 +60,13 @@ mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) a0.dp[count] = A.dp[ j++ ]; a0.used++; } - if ((e = mp_mul(&a0, &B, &tmp)) != MP_OKAY) { + if ((err = mp_mul(&a0, &B, &tmp)) != MP_OKAY) { goto LBL_ERR; } - if ((e = mp_lshd(&tmp, bsize * i)) != MP_OKAY) { + if ((err = mp_lshd(&tmp, bsize * i)) != MP_OKAY) { goto LBL_ERR; } - if ((e = mp_add(&r, &tmp, &r)) != MP_OKAY) { + if ((err = mp_add(&r, &tmp, &r)) != MP_OKAY) { goto LBL_ERR; } } @@ -74,6 +74,6 @@ mp_err s_mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c) mp_exch(&r,c); LBL_ERR: mp_clear_multi(&a0, &tmp, &r,NULL); - return e; + return err; } #endif diff --git a/bn_s_mp_invmod_fast.c b/bn_s_mp_invmod_fast.c index 111ecdd77..be7813c96 100644 --- a/bn_s_mp_invmod_fast.c +++ b/bn_s_mp_invmod_fast.c @@ -13,7 +13,7 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) { mp_int x, y, u, v, B, D; mp_sign neg; - mp_err res; + mp_err err; /* 2. [modified] b must be odd */ if (MP_IS_EVEN(b)) { @@ -21,31 +21,31 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) } /* init all our temps */ - if ((res = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) { - return res; + if ((err = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) { + return err; } /* x == modulus, y == value to invert */ - if ((res = mp_copy(b, &x)) != MP_OKAY) { + if ((err = mp_copy(b, &x)) != MP_OKAY) { goto LBL_ERR; } /* we need y = |a| */ - if ((res = mp_mod(a, b, &y)) != MP_OKAY) { + if ((err = mp_mod(a, b, &y)) != MP_OKAY) { goto LBL_ERR; } /* if one of x,y is zero return an error! */ if (MP_IS_ZERO(&x) || MP_IS_ZERO(&y)) { - res = MP_VAL; + err = MP_VAL; goto LBL_ERR; } /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */ - if ((res = mp_copy(&x, &u)) != MP_OKAY) { + if ((err = mp_copy(&x, &u)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(&y, &v)) != MP_OKAY) { + if ((err = mp_copy(&y, &v)) != MP_OKAY) { goto LBL_ERR; } mp_set(&D, 1uL); @@ -54,17 +54,17 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) /* 4. while u is even do */ while (MP_IS_EVEN(&u)) { /* 4.1 u = u/2 */ - if ((res = mp_div_2(&u, &u)) != MP_OKAY) { + if ((err = mp_div_2(&u, &u)) != MP_OKAY) { goto LBL_ERR; } /* 4.2 if B is odd then */ if (MP_IS_ODD(&B)) { - if ((res = mp_sub(&B, &x, &B)) != MP_OKAY) { + if ((err = mp_sub(&B, &x, &B)) != MP_OKAY) { goto LBL_ERR; } } /* B = B/2 */ - if ((res = mp_div_2(&B, &B)) != MP_OKAY) { + if ((err = mp_div_2(&B, &B)) != MP_OKAY) { goto LBL_ERR; } } @@ -72,18 +72,18 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) /* 5. while v is even do */ while (MP_IS_EVEN(&v)) { /* 5.1 v = v/2 */ - if ((res = mp_div_2(&v, &v)) != MP_OKAY) { + if ((err = mp_div_2(&v, &v)) != MP_OKAY) { goto LBL_ERR; } /* 5.2 if D is odd then */ if (MP_IS_ODD(&D)) { /* D = (D-x)/2 */ - if ((res = mp_sub(&D, &x, &D)) != MP_OKAY) { + if ((err = mp_sub(&D, &x, &D)) != MP_OKAY) { goto LBL_ERR; } } /* D = D/2 */ - if ((res = mp_div_2(&D, &D)) != MP_OKAY) { + if ((err = mp_div_2(&D, &D)) != MP_OKAY) { goto LBL_ERR; } } @@ -91,20 +91,20 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) /* 6. if u >= v then */ if (mp_cmp(&u, &v) != MP_LT) { /* u = u - v, B = B - D */ - if ((res = mp_sub(&u, &v, &u)) != MP_OKAY) { + if ((err = mp_sub(&u, &v, &u)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&B, &D, &B)) != MP_OKAY) { + if ((err = mp_sub(&B, &D, &B)) != MP_OKAY) { goto LBL_ERR; } } else { /* v - v - u, D = D - B */ - if ((res = mp_sub(&v, &u, &v)) != MP_OKAY) { + if ((err = mp_sub(&v, &u, &v)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&D, &B, &D)) != MP_OKAY) { + if ((err = mp_sub(&D, &B, &D)) != MP_OKAY) { goto LBL_ERR; } } @@ -118,31 +118,31 @@ mp_err s_mp_invmod_fast(const mp_int *a, const mp_int *b, mp_int *c) /* if v != 1 then there is no inverse */ if (mp_cmp_d(&v, 1uL) != MP_EQ) { - res = MP_VAL; + err = MP_VAL; goto LBL_ERR; } /* b is now the inverse */ neg = a->sign; while (D.sign == MP_NEG) { - if ((res = mp_add(&D, b, &D)) != MP_OKAY) { + if ((err = mp_add(&D, b, &D)) != MP_OKAY) { goto LBL_ERR; } } /* too big */ while (mp_cmp_mag(&D, b) != MP_LT) { - if ((res = mp_sub(&D, b, &D)) != MP_OKAY) { + if ((err = mp_sub(&D, b, &D)) != MP_OKAY) { goto LBL_ERR; } } mp_exch(&D, c); c->sign = neg; - res = MP_OKAY; + err = MP_OKAY; LBL_ERR: mp_clear_multi(&x, &y, &u, &v, &B, &D, NULL); - return res; + return err; } #endif diff --git a/bn_s_mp_invmod_slow.c b/bn_s_mp_invmod_slow.c index b006aed5c..faf62213c 100644 --- a/bn_s_mp_invmod_slow.c +++ b/bn_s_mp_invmod_slow.c @@ -7,7 +7,7 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) { mp_int x, y, u, v, A, B, C, D; - mp_err res; + mp_err err; /* b cannot be negative */ if ((b->sign == MP_NEG) || MP_IS_ZERO(b)) { @@ -15,30 +15,30 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) } /* init temps */ - if ((res = mp_init_multi(&x, &y, &u, &v, + if ((err = mp_init_multi(&x, &y, &u, &v, &A, &B, &C, &D, NULL)) != MP_OKAY) { - return res; + return err; } /* x = a, y = b */ - if ((res = mp_mod(a, b, &x)) != MP_OKAY) { + if ((err = mp_mod(a, b, &x)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(b, &y)) != MP_OKAY) { + if ((err = mp_copy(b, &y)) != MP_OKAY) { goto LBL_ERR; } /* 2. [modified] if x,y are both even then return an error! */ if (MP_IS_EVEN(&x) && MP_IS_EVEN(&y)) { - res = MP_VAL; + err = MP_VAL; goto LBL_ERR; } /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */ - if ((res = mp_copy(&x, &u)) != MP_OKAY) { + if ((err = mp_copy(&x, &u)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(&y, &v)) != MP_OKAY) { + if ((err = mp_copy(&y, &v)) != MP_OKAY) { goto LBL_ERR; } mp_set(&A, 1uL); @@ -48,24 +48,24 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) /* 4. while u is even do */ while (MP_IS_EVEN(&u)) { /* 4.1 u = u/2 */ - if ((res = mp_div_2(&u, &u)) != MP_OKAY) { + if ((err = mp_div_2(&u, &u)) != MP_OKAY) { goto LBL_ERR; } /* 4.2 if A or B is odd then */ if (MP_IS_ODD(&A) || MP_IS_ODD(&B)) { /* A = (A+y)/2, B = (B-x)/2 */ - if ((res = mp_add(&A, &y, &A)) != MP_OKAY) { + if ((err = mp_add(&A, &y, &A)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&B, &x, &B)) != MP_OKAY) { + if ((err = mp_sub(&B, &x, &B)) != MP_OKAY) { goto LBL_ERR; } } /* A = A/2, B = B/2 */ - if ((res = mp_div_2(&A, &A)) != MP_OKAY) { + if ((err = mp_div_2(&A, &A)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_div_2(&B, &B)) != MP_OKAY) { + if ((err = mp_div_2(&B, &B)) != MP_OKAY) { goto LBL_ERR; } } @@ -73,24 +73,24 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) /* 5. while v is even do */ while (MP_IS_EVEN(&v)) { /* 5.1 v = v/2 */ - if ((res = mp_div_2(&v, &v)) != MP_OKAY) { + if ((err = mp_div_2(&v, &v)) != MP_OKAY) { goto LBL_ERR; } /* 5.2 if C or D is odd then */ if (MP_IS_ODD(&C) || MP_IS_ODD(&D)) { /* C = (C+y)/2, D = (D-x)/2 */ - if ((res = mp_add(&C, &y, &C)) != MP_OKAY) { + if ((err = mp_add(&C, &y, &C)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&D, &x, &D)) != MP_OKAY) { + if ((err = mp_sub(&D, &x, &D)) != MP_OKAY) { goto LBL_ERR; } } /* C = C/2, D = D/2 */ - if ((res = mp_div_2(&C, &C)) != MP_OKAY) { + if ((err = mp_div_2(&C, &C)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_div_2(&D, &D)) != MP_OKAY) { + if ((err = mp_div_2(&D, &D)) != MP_OKAY) { goto LBL_ERR; } } @@ -98,28 +98,28 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) /* 6. if u >= v then */ if (mp_cmp(&u, &v) != MP_LT) { /* u = u - v, A = A - C, B = B - D */ - if ((res = mp_sub(&u, &v, &u)) != MP_OKAY) { + if ((err = mp_sub(&u, &v, &u)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&A, &C, &A)) != MP_OKAY) { + if ((err = mp_sub(&A, &C, &A)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&B, &D, &B)) != MP_OKAY) { + if ((err = mp_sub(&B, &D, &B)) != MP_OKAY) { goto LBL_ERR; } } else { /* v - v - u, C = C - A, D = D - B */ - if ((res = mp_sub(&v, &u, &v)) != MP_OKAY) { + if ((err = mp_sub(&v, &u, &v)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&C, &A, &C)) != MP_OKAY) { + if ((err = mp_sub(&C, &A, &C)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&D, &B, &D)) != MP_OKAY) { + if ((err = mp_sub(&D, &B, &D)) != MP_OKAY) { goto LBL_ERR; } } @@ -132,29 +132,29 @@ mp_err s_mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c) /* if v != 1 then there is no inverse */ if (mp_cmp_d(&v, 1uL) != MP_EQ) { - res = MP_VAL; + err = MP_VAL; goto LBL_ERR; } /* if its too low */ while (mp_cmp_d(&C, 0uL) == MP_LT) { - if ((res = mp_add(&C, b, &C)) != MP_OKAY) { + if ((err = mp_add(&C, b, &C)) != MP_OKAY) { goto LBL_ERR; } } /* too big */ while (mp_cmp_mag(&C, b) != MP_LT) { - if ((res = mp_sub(&C, b, &C)) != MP_OKAY) { + if ((err = mp_sub(&C, b, &C)) != MP_OKAY) { goto LBL_ERR; } } /* C is now the inverse */ mp_exch(&C, c); - res = MP_OKAY; + err = MP_OKAY; LBL_ERR: mp_clear_multi(&x, &y, &u, &v, &A, &B, &C, &D, NULL); - return res; + return err; } #endif diff --git a/bn_s_mp_montgomery_reduce_fast.c b/bn_s_mp_montgomery_reduce_fast.c index 4e69af67f..59a16e345 100644 --- a/bn_s_mp_montgomery_reduce_fast.c +++ b/bn_s_mp_montgomery_reduce_fast.c @@ -14,7 +14,7 @@ mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho) { int ix, olduse; - mp_err res; + mp_err err; mp_word W[MP_WARRAY]; if (x->used > (int)MP_WARRAY) { @@ -26,8 +26,8 @@ mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho) /* grow a as required */ if (x->alloc < (n->used + 1)) { - if ((res = mp_grow(x, n->used + 1)) != MP_OKAY) { - return res; + if ((err = mp_grow(x, n->used + 1)) != MP_OKAY) { + return err; } } diff --git a/bn_s_mp_mul_digs.c b/bn_s_mp_mul_digs.c index 109505bac..2f37e028f 100644 --- a/bn_s_mp_mul_digs.c +++ b/bn_s_mp_mul_digs.c @@ -10,7 +10,7 @@ mp_err s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) { mp_int t; - mp_err res; + mp_err err; int pa, pb, ix, iy; mp_digit u; mp_word r; @@ -22,8 +22,8 @@ mp_err s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) return s_mp_mul_digs_fast(a, b, c, digs); } - if ((res = mp_init_size(&t, digs)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&t, digs)) != MP_OKAY) { + return err; } t.used = digs; diff --git a/bn_s_mp_mul_digs_fast.c b/bn_s_mp_mul_digs_fast.c index 9c3776cdd..b2a287b02 100644 --- a/bn_s_mp_mul_digs_fast.c +++ b/bn_s_mp_mul_digs_fast.c @@ -22,14 +22,14 @@ mp_err s_mp_mul_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs) { int olduse, pa, ix, iz; - mp_err res; + mp_err err; mp_digit W[MP_WARRAY]; mp_word _W; /* grow the destination as required */ if (c->alloc < digs) { - if ((res = mp_grow(c, digs)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, digs)) != MP_OKAY) { + return err; } } diff --git a/bn_s_mp_mul_high_digs.c b/bn_s_mp_mul_high_digs.c index 7a13991b3..e83fa04cc 100644 --- a/bn_s_mp_mul_high_digs.c +++ b/bn_s_mp_mul_high_digs.c @@ -10,7 +10,7 @@ mp_err s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) { mp_int t; int pa, pb, ix, iy; - mp_err res; + mp_err err; mp_digit u; mp_word r; mp_digit tmpx, *tmpt, *tmpy; @@ -23,8 +23,8 @@ mp_err s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) } #endif - if ((res = mp_init_size(&t, a->used + b->used + 1)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&t, a->used + b->used + 1)) != MP_OKAY) { + return err; } t.used = a->used + b->used + 1; diff --git a/bn_s_mp_mul_high_digs_fast.c b/bn_s_mp_mul_high_digs_fast.c index 36cb2d169..a2c4fb692 100644 --- a/bn_s_mp_mul_high_digs_fast.c +++ b/bn_s_mp_mul_high_digs_fast.c @@ -15,15 +15,15 @@ mp_err s_mp_mul_high_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs) { int olduse, pa, ix, iz; - mp_err res; + mp_err err; mp_digit W[MP_WARRAY]; mp_word _W; /* grow the destination as required */ pa = a->used + b->used; if (c->alloc < pa) { - if ((res = mp_grow(c, pa)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, pa)) != MP_OKAY) { + return err; } } diff --git a/bn_s_mp_rand_platform.c b/bn_s_mp_rand_platform.c index a4da91215..a22558c3a 100644 --- a/bn_s_mp_rand_platform.c +++ b/bn_s_mp_rand_platform.c @@ -113,10 +113,10 @@ void (*ltm_rng_callback)(void); static mp_err s_read_ltm_rng(void *p, size_t n) { - unsigned long ret; + unsigned long res; if (ltm_rng == NULL) return MP_ERR; - ret = ltm_rng(p, n, ltm_rng_callback); - if (ret != n) return MP_ERR; + res = ltm_rng(p, n, ltm_rng_callback); + if (res != n) return MP_ERR; return MP_OKAY; } #endif @@ -128,29 +128,29 @@ mp_err s_mp_rand_platform(void *p, size_t n) return MP_OKAY; #else - mp_err ret = MP_ERR; + mp_err res = MP_ERR; #if defined(MP_WIN_CSP) - ret = s_read_win_csp(p, n); - if (ret == MP_OKAY) return ret; + res = s_read_win_csp(p, n); + if (res == MP_OKAY) return res; #endif #if defined(MP_GETRANDOM) - ret = s_read_getrandom(p, n); - if (ret == MP_OKAY) return ret; + res = s_read_getrandom(p, n); + if (res == MP_OKAY) return res; #endif #if defined(MP_DEV_URANDOM) - ret = s_read_dev_urandom(p, n); - if (ret == MP_OKAY) return ret; + res = s_read_dev_urandom(p, n); + if (res == MP_OKAY) return res; #endif #if defined(MP_PRNG_ENABLE_LTM_RNG) - ret = s_read_ltm_rng(p, n); - if (ret == MP_OKAY) return ret; + res = s_read_ltm_rng(p, n); + if (res == MP_OKAY) return res; #endif - return ret; + return res; #endif } diff --git a/bn_s_mp_sqr.c b/bn_s_mp_sqr.c index 650f461fd..505c9f053 100644 --- a/bn_s_mp_sqr.c +++ b/bn_s_mp_sqr.c @@ -8,13 +8,13 @@ mp_err s_mp_sqr(const mp_int *a, mp_int *b) { mp_int t; int ix, iy, pa; - mp_err res; + mp_err err; mp_word r; mp_digit u, tmpx, *tmpt; pa = a->used; - if ((res = mp_init_size(&t, (2 * pa) + 1)) != MP_OKAY) { - return res; + if ((err = mp_init_size(&t, (2 * pa) + 1)) != MP_OKAY) { + return err; } /* default used is maximum possible size */ diff --git a/bn_s_mp_sqr_fast.c b/bn_s_mp_sqr_fast.c index 95acd7a35..4a8a8912f 100644 --- a/bn_s_mp_sqr_fast.c +++ b/bn_s_mp_sqr_fast.c @@ -18,13 +18,13 @@ mp_err s_mp_sqr_fast(const mp_int *a, mp_int *b) int olduse, pa, ix, iz; mp_digit W[MP_WARRAY], *tmpx; mp_word W1; - mp_err res; + mp_err err; /* grow the destination as required */ pa = a->used + a->used; if (b->alloc < pa) { - if ((res = mp_grow(b, pa)) != MP_OKAY) { - return res; + if ((err = mp_grow(b, pa)) != MP_OKAY) { + return err; } } diff --git a/bn_s_mp_sub.c b/bn_s_mp_sub.c index d00e0e477..5672dab51 100644 --- a/bn_s_mp_sub.c +++ b/bn_s_mp_sub.c @@ -7,7 +7,7 @@ mp_err s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) { int olduse, min, max; - mp_err res; + mp_err err; /* find sizes */ min = b->used; @@ -15,8 +15,8 @@ mp_err s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c) /* init result */ if (c->alloc < max) { - if ((res = mp_grow(c, max)) != MP_OKAY) { - return res; + if ((err = mp_grow(c, max)) != MP_OKAY) { + return err; } } olduse = c->used; diff --git a/bn_s_mp_toom_mul.c b/bn_s_mp_toom_mul.c index 9f10761e7..74264986b 100644 --- a/bn_s_mp_toom_mul.c +++ b/bn_s_mp_toom_mul.c @@ -14,141 +14,141 @@ mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) { mp_int w0, w1, w2, w3, w4, tmp1, tmp2, a0, a1, a2, b0, b1, b2; int B; - mp_err res; + mp_err err; /* init temps */ - if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, + if ((err = mp_init_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &b0, &b1, &b2, &tmp1, &tmp2, NULL)) != MP_OKAY) { - return res; + return err; } /* B */ B = MP_MIN(a->used, b->used) / 3; /* a = a2 * B**2 + a1 * B + a0 */ - if ((res = mp_mod_2d(a, MP_DIGIT_BIT * B, &a0)) != MP_OKAY) { + if ((err = mp_mod_2d(a, MP_DIGIT_BIT * B, &a0)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(a, &a1)) != MP_OKAY) { + if ((err = mp_copy(a, &a1)) != MP_OKAY) { goto LBL_ERR; } mp_rshd(&a1, B); - if ((res = mp_mod_2d(&a1, MP_DIGIT_BIT * B, &a1)) != MP_OKAY) { + if ((err = mp_mod_2d(&a1, MP_DIGIT_BIT * B, &a1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(a, &a2)) != MP_OKAY) { + if ((err = mp_copy(a, &a2)) != MP_OKAY) { goto LBL_ERR; } mp_rshd(&a2, B*2); /* b = b2 * B**2 + b1 * B + b0 */ - if ((res = mp_mod_2d(b, MP_DIGIT_BIT * B, &b0)) != MP_OKAY) { + if ((err = mp_mod_2d(b, MP_DIGIT_BIT * B, &b0)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(b, &b1)) != MP_OKAY) { + if ((err = mp_copy(b, &b1)) != MP_OKAY) { goto LBL_ERR; } mp_rshd(&b1, B); - if ((res = mp_mod_2d(&b1, MP_DIGIT_BIT * B, &b1)) != MP_OKAY) { + if ((err = mp_mod_2d(&b1, MP_DIGIT_BIT * B, &b1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(b, &b2)) != MP_OKAY) { + if ((err = mp_copy(b, &b2)) != MP_OKAY) { goto LBL_ERR; } mp_rshd(&b2, B*2); /* w0 = a0*b0 */ - if ((res = mp_mul(&a0, &b0, &w0)) != MP_OKAY) { + if ((err = mp_mul(&a0, &b0, &w0)) != MP_OKAY) { goto LBL_ERR; } /* w4 = a2 * b2 */ - if ((res = mp_mul(&a2, &b2, &w4)) != MP_OKAY) { + if ((err = mp_mul(&a2, &b2, &w4)) != MP_OKAY) { goto LBL_ERR; } /* w1 = (a2 + 2(a1 + 2a0))(b2 + 2(b1 + 2b0)) */ - if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&b0, &tmp2)) != MP_OKAY) { + if ((err = mp_mul_2(&b0, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { + if ((err = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { + if ((err = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp2, &b2, &tmp2)) != MP_OKAY) { + if ((err = mp_add(&tmp2, &b2, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul(&tmp1, &tmp2, &w1)) != MP_OKAY) { + if ((err = mp_mul(&tmp1, &tmp2, &w1)) != MP_OKAY) { goto LBL_ERR; } /* w3 = (a0 + 2(a1 + 2a2))(b0 + 2(b1 + 2b2)) */ - if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&b2, &tmp2)) != MP_OKAY) { + if ((err = mp_mul_2(&b2, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { + if ((err = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { + if ((err = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { + if ((err = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul(&tmp1, &tmp2, &w3)) != MP_OKAY) { + if ((err = mp_mul(&tmp1, &tmp2, &w3)) != MP_OKAY) { goto LBL_ERR; } /* w2 = (a2 + a1 + a0)(b2 + b1 + b0) */ - if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&b2, &b1, &tmp2)) != MP_OKAY) { + if ((err = mp_add(&b2, &b1, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { + if ((err = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul(&tmp1, &tmp2, &w2)) != MP_OKAY) { + if ((err = mp_mul(&tmp1, &tmp2, &w2)) != MP_OKAY) { goto LBL_ERR; } @@ -165,101 +165,101 @@ mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) */ /* r1 - r4 */ - if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - r0 */ - if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r1/2 */ - if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) { + if ((err = mp_div_2(&w1, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3/2 */ - if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) { + if ((err = mp_div_2(&w3, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r2 - r0 - r4 */ - if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { goto LBL_ERR; } /* r1 - r2 */ - if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - r2 */ - if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r1 - 8r0 */ - if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - 8r4 */ - if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { goto LBL_ERR; } /* 3r2 - r1 - r3 */ - if ((res = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { + if ((err = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { goto LBL_ERR; } /* r1 - r2 */ - if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - r2 */ - if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r1/3 */ - if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { + if ((err = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { goto LBL_ERR; } /* r3/3 */ - if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { + if ((err = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { goto LBL_ERR; } /* at this point shift W[n] by B*n */ - if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) { + if ((err = mp_lshd(&w1, 1*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) { + if ((err = mp_lshd(&w2, 2*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) { + if ((err = mp_lshd(&w3, 3*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) { + if ((err = mp_lshd(&w4, 4*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&w0, &w1, c)) != MP_OKAY) { + if ((err = mp_add(&w0, &w1, c)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, c, c)) != MP_OKAY) { + if ((err = mp_add(&tmp1, c, c)) != MP_OKAY) { goto LBL_ERR; } @@ -267,7 +267,7 @@ mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c) mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &b0, &b1, &b2, &tmp1, &tmp2, NULL); - return res; + return err; } #endif diff --git a/bn_s_mp_toom_sqr.c b/bn_s_mp_toom_sqr.c index 24fb4d9f5..46020af79 100644 --- a/bn_s_mp_toom_sqr.c +++ b/bn_s_mp_toom_sqr.c @@ -8,89 +8,89 @@ mp_err s_mp_toom_sqr(const mp_int *a, mp_int *b) { mp_int w0, w1, w2, w3, w4, tmp1, a0, a1, a2; int B; - mp_err res; + mp_err err; /* init temps */ - if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL)) != MP_OKAY) { - return res; + if ((err = mp_init_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL)) != MP_OKAY) { + return err; } /* B */ B = a->used / 3; /* a = a2 * B**2 + a1 * B + a0 */ - if ((res = mp_mod_2d(a, MP_DIGIT_BIT * B, &a0)) != MP_OKAY) { + if ((err = mp_mod_2d(a, MP_DIGIT_BIT * B, &a0)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(a, &a1)) != MP_OKAY) { + if ((err = mp_copy(a, &a1)) != MP_OKAY) { goto LBL_ERR; } mp_rshd(&a1, B); - if ((res = mp_mod_2d(&a1, MP_DIGIT_BIT * B, &a1)) != MP_OKAY) { + if ((err = mp_mod_2d(&a1, MP_DIGIT_BIT * B, &a1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_copy(a, &a2)) != MP_OKAY) { + if ((err = mp_copy(a, &a2)) != MP_OKAY) { goto LBL_ERR; } mp_rshd(&a2, B*2); /* w0 = a0*a0 */ - if ((res = mp_sqr(&a0, &w0)) != MP_OKAY) { + if ((err = mp_sqr(&a0, &w0)) != MP_OKAY) { goto LBL_ERR; } /* w4 = a2 * a2 */ - if ((res = mp_sqr(&a2, &w4)) != MP_OKAY) { + if ((err = mp_sqr(&a2, &w4)) != MP_OKAY) { goto LBL_ERR; } /* w1 = (a2 + 2(a1 + 2a0))**2 */ - if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&a0, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sqr(&tmp1, &w1)) != MP_OKAY) { + if ((err = mp_sqr(&tmp1, &w1)) != MP_OKAY) { goto LBL_ERR; } /* w3 = (a0 + 2(a1 + 2a2))**2 */ - if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&a2, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sqr(&tmp1, &w3)) != MP_OKAY) { + if ((err = mp_sqr(&tmp1, &w3)) != MP_OKAY) { goto LBL_ERR; } /* w2 = (a2 + a1 + a0)**2 */ - if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sqr(&tmp1, &w2)) != MP_OKAY) { + if ((err = mp_sqr(&tmp1, &w2)) != MP_OKAY) { goto LBL_ERR; } @@ -106,107 +106,107 @@ mp_err s_mp_toom_sqr(const mp_int *a, mp_int *b) */ /* r1 - r4 */ - if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &w4, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - r0 */ - if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &w0, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r1/2 */ - if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) { + if ((err = mp_div_2(&w1, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3/2 */ - if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) { + if ((err = mp_div_2(&w3, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r2 - r0 - r4 */ - if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w0, &w2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w4, &w2)) != MP_OKAY) { goto LBL_ERR; } /* r1 - r2 */ - if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - r2 */ - if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r1 - 8r0 */ - if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - 8r4 */ - if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { + if ((err = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) { goto LBL_ERR; } /* 3r2 - r1 - r3 */ - if ((res = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { + if ((err = mp_mul_d(&w2, 3uL, &w2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w1, &w2)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { + if ((err = mp_sub(&w2, &w3, &w2)) != MP_OKAY) { goto LBL_ERR; } /* r1 - r2 */ - if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { + if ((err = mp_sub(&w1, &w2, &w1)) != MP_OKAY) { goto LBL_ERR; } /* r3 - r2 */ - if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { + if ((err = mp_sub(&w3, &w2, &w3)) != MP_OKAY) { goto LBL_ERR; } /* r1/3 */ - if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { + if ((err = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) { goto LBL_ERR; } /* r3/3 */ - if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { + if ((err = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) { goto LBL_ERR; } /* at this point shift W[n] by B*n */ - if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) { + if ((err = mp_lshd(&w1, 1*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) { + if ((err = mp_lshd(&w2, 2*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) { + if ((err = mp_lshd(&w3, 3*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) { + if ((err = mp_lshd(&w4, 4*B)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) { + if ((err = mp_add(&w0, &w1, b)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { + if ((err = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) { goto LBL_ERR; } - if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) { + if ((err = mp_add(&tmp1, b, b)) != MP_OKAY) { goto LBL_ERR; } LBL_ERR: mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL); - return res; + return err; } #endif diff --git a/callgraph.txt b/callgraph.txt index 4eb61ea68..29c15510c 100644 --- a/callgraph.txt +++ b/callgraph.txt @@ -3881,7 +3881,9 @@ BN_MP_NEG_C BN_MP_N_ROOT_C +--->BN_MP_N_ROOT_EX_C -| +--->BN_MP_INIT_C +| +--->BN_MP_INIT_MULTI_C +| | +--->BN_MP_INIT_C +| | +--->BN_MP_CLEAR_C | +--->BN_MP_COUNT_BITS_C | +--->BN_MP_SET_C | | +--->BN_MP_ZERO_C @@ -3897,8 +3899,6 @@ BN_MP_N_ROOT_C | | +--->BN_MP_MUL_C | | | +--->BN_S_MP_BALANCE_MUL_C | | | | +--->BN_MP_INIT_SIZE_C -| | | | +--->BN_MP_INIT_MULTI_C -| | | | | +--->BN_MP_CLEAR_C | | | | +--->BN_MP_CLEAR_C | | | | +--->BN_MP_LSHD_C | | | | | +--->BN_MP_GROW_C @@ -3913,8 +3913,6 @@ BN_MP_N_ROOT_C | | | | +--->BN_MP_EXCH_C | | | | +--->BN_MP_CLEAR_MULTI_C | | | +--->BN_S_MP_TOOM_MUL_C -| | | | +--->BN_MP_INIT_MULTI_C -| | | | | +--->BN_MP_CLEAR_C | | | | +--->BN_MP_MOD_2D_C | | | | | +--->BN_MP_ZERO_C | | | | | +--->BN_MP_CLAMP_C @@ -3982,7 +3980,6 @@ BN_MP_N_ROOT_C | | +--->BN_MP_CLEAR_C | | +--->BN_MP_SQR_C | | | +--->BN_S_MP_TOOM_SQR_C -| | | | +--->BN_MP_INIT_MULTI_C | | | | +--->BN_MP_MOD_2D_C | | | | | +--->BN_MP_ZERO_C | | | | | +--->BN_MP_CLAMP_C @@ -4044,8 +4041,6 @@ BN_MP_N_ROOT_C | +--->BN_MP_MUL_C | | +--->BN_S_MP_BALANCE_MUL_C | | | +--->BN_MP_INIT_SIZE_C -| | | +--->BN_MP_INIT_MULTI_C -| | | | +--->BN_MP_CLEAR_C | | | +--->BN_MP_CLEAR_C | | | +--->BN_MP_LSHD_C | | | | +--->BN_MP_GROW_C @@ -4060,8 +4055,6 @@ BN_MP_N_ROOT_C | | | +--->BN_MP_EXCH_C | | | +--->BN_MP_CLEAR_MULTI_C | | +--->BN_S_MP_TOOM_MUL_C -| | | +--->BN_MP_INIT_MULTI_C -| | | | +--->BN_MP_CLEAR_C | | | +--->BN_MP_MOD_2D_C | | | | +--->BN_MP_ZERO_C | | | | +--->BN_MP_CLAMP_C @@ -4140,8 +4133,6 @@ BN_MP_N_ROOT_C | +--->BN_MP_DIV_C | | +--->BN_MP_CMP_MAG_C | | +--->BN_MP_ZERO_C -| | +--->BN_MP_INIT_MULTI_C -| | | +--->BN_MP_CLEAR_C | | +--->BN_MP_ABS_C | | +--->BN_MP_MUL_2D_C | | | +--->BN_MP_GROW_C @@ -4164,6 +4155,7 @@ BN_MP_N_ROOT_C | | +--->BN_MP_CLEAR_MULTI_C | | | +--->BN_MP_CLEAR_C | | +--->BN_MP_INIT_SIZE_C +| | +--->BN_MP_INIT_C | | +--->BN_MP_INIT_COPY_C | | | +--->BN_MP_CLEAR_C | | +--->BN_MP_LSHD_C @@ -4182,11 +4174,14 @@ BN_MP_N_ROOT_C | | +--->BN_MP_GROW_C | | +--->BN_MP_CLAMP_C | +--->BN_MP_EXCH_C -| +--->BN_MP_CLEAR_C +| +--->BN_MP_CLEAR_MULTI_C +| | +--->BN_MP_CLEAR_C BN_MP_N_ROOT_EX_C -+--->BN_MP_INIT_C ++--->BN_MP_INIT_MULTI_C +| +--->BN_MP_INIT_C +| +--->BN_MP_CLEAR_C +--->BN_MP_COUNT_BITS_C +--->BN_MP_SET_C | +--->BN_MP_ZERO_C @@ -4202,8 +4197,6 @@ BN_MP_N_ROOT_EX_C | +--->BN_MP_MUL_C | | +--->BN_S_MP_BALANCE_MUL_C | | | +--->BN_MP_INIT_SIZE_C -| | | +--->BN_MP_INIT_MULTI_C -| | | | +--->BN_MP_CLEAR_C | | | +--->BN_MP_CLEAR_C | | | +--->BN_MP_LSHD_C | | | | +--->BN_MP_GROW_C @@ -4218,8 +4211,6 @@ BN_MP_N_ROOT_EX_C | | | +--->BN_MP_EXCH_C | | | +--->BN_MP_CLEAR_MULTI_C | | +--->BN_S_MP_TOOM_MUL_C -| | | +--->BN_MP_INIT_MULTI_C -| | | | +--->BN_MP_CLEAR_C | | | +--->BN_MP_MOD_2D_C | | | | +--->BN_MP_ZERO_C | | | | +--->BN_MP_CLAMP_C @@ -4287,7 +4278,6 @@ BN_MP_N_ROOT_EX_C | +--->BN_MP_CLEAR_C | +--->BN_MP_SQR_C | | +--->BN_S_MP_TOOM_SQR_C -| | | +--->BN_MP_INIT_MULTI_C | | | +--->BN_MP_MOD_2D_C | | | | +--->BN_MP_ZERO_C | | | | +--->BN_MP_CLAMP_C @@ -4349,8 +4339,6 @@ BN_MP_N_ROOT_EX_C +--->BN_MP_MUL_C | +--->BN_S_MP_BALANCE_MUL_C | | +--->BN_MP_INIT_SIZE_C -| | +--->BN_MP_INIT_MULTI_C -| | | +--->BN_MP_CLEAR_C | | +--->BN_MP_CLEAR_C | | +--->BN_MP_LSHD_C | | | +--->BN_MP_GROW_C @@ -4365,8 +4353,6 @@ BN_MP_N_ROOT_EX_C | | +--->BN_MP_EXCH_C | | +--->BN_MP_CLEAR_MULTI_C | +--->BN_S_MP_TOOM_MUL_C -| | +--->BN_MP_INIT_MULTI_C -| | | +--->BN_MP_CLEAR_C | | +--->BN_MP_MOD_2D_C | | | +--->BN_MP_ZERO_C | | | +--->BN_MP_CLAMP_C @@ -4445,8 +4431,6 @@ BN_MP_N_ROOT_EX_C +--->BN_MP_DIV_C | +--->BN_MP_CMP_MAG_C | +--->BN_MP_ZERO_C -| +--->BN_MP_INIT_MULTI_C -| | +--->BN_MP_CLEAR_C | +--->BN_MP_ABS_C | +--->BN_MP_MUL_2D_C | | +--->BN_MP_GROW_C @@ -4469,6 +4453,7 @@ BN_MP_N_ROOT_EX_C | +--->BN_MP_CLEAR_MULTI_C | | +--->BN_MP_CLEAR_C | +--->BN_MP_INIT_SIZE_C +| +--->BN_MP_INIT_C | +--->BN_MP_INIT_COPY_C | | +--->BN_MP_CLEAR_C | +--->BN_MP_LSHD_C @@ -4487,7 +4472,8 @@ BN_MP_N_ROOT_EX_C | +--->BN_MP_GROW_C | +--->BN_MP_CLAMP_C +--->BN_MP_EXCH_C -+--->BN_MP_CLEAR_C ++--->BN_MP_CLEAR_MULTI_C +| +--->BN_MP_CLEAR_C BN_MP_OR_C diff --git a/demo/test.c b/demo/test.c index 69c8fbc80..e7dd9ffa7 100644 --- a/demo/test.c +++ b/demo/test.c @@ -1239,7 +1239,7 @@ static int test_mp_reduce_2k_l(void) mp_copy(&b, &c); printf("Testing: mp_reduce_2k_l..."); fflush(stdout); - for (cnt = 0; cnt < (int)(1UL << 20); cnt++) { + for (cnt = 0; cnt < (int)(1uL << 20); cnt++) { mp_sqr(&b, &b); mp_add_d(&b, 1uL, &b); mp_reduce_2k_l(&b, &a, &d); diff --git a/tommath_class.h b/tommath_class.h index 880ea8bd2..f102f1c51 100644 --- a/tommath_class.h +++ b/tommath_class.h @@ -610,7 +610,7 @@ #endif #if defined(BN_MP_N_ROOT_EX_C) -# define BN_MP_INIT_C +# define BN_MP_INIT_MULTI_C # define BN_MP_COUNT_BITS_C # define BN_MP_SET_C # define BN_MP_2EXPT_C @@ -624,7 +624,7 @@ # define BN_MP_ADD_D_C # define BN_MP_SUB_D_C # define BN_MP_EXCH_C -# define BN_MP_CLEAR_C +# define BN_MP_CLEAR_MULTI_C #endif #if defined(BN_MP_NEG_C)