Loading crypto/bn/bn_gf2m.c +70 −29 Original line number Diff line number Diff line Loading @@ -288,6 +288,9 @@ int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) int i; const BIGNUM *at, *bt; bn_check_top(a); bn_check_top(b); if (a->top < b->top) { at = b; bt = a; } else { at = a; bt = b; } Loading Loading @@ -323,6 +326,8 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]) int n, dN, d0, d1; BN_ULONG zz, *z; bn_check_top(a); if (!p[0]) /* reduction mod 1 => return 0 */ return BN_zero(r); Loading Loading @@ -397,7 +402,6 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]) } bn_correct_top(r); return 1; } Loading @@ -412,6 +416,8 @@ int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p) int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -436,12 +442,14 @@ int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig BIGNUM *s; BN_ULONG x1, x0, y1, y0, zz[4]; bn_check_top(a); bn_check_top(b); if (a == b) { return BN_GF2m_mod_sqr_arr(r, a, p, ctx); } BN_CTX_start(ctx); if ((s = BN_CTX_get(ctx)) == NULL) goto err; Loading Loading @@ -472,7 +480,6 @@ int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig err: BN_CTX_end(ctx); return ret; } /* Compute the product of two polynomials a and b, reduce modulo p, and store Loading @@ -487,6 +494,9 @@ int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(b); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -508,6 +518,7 @@ int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_C int i, ret = 0; BIGNUM *s; bn_check_top(a); BN_CTX_start(ctx); if ((s = BN_CTX_get(ctx)) == NULL) return 0; if (!bn_wexpand(s, 2 * a->top)) goto err; Loading Loading @@ -539,6 +550,9 @@ int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -564,6 +578,9 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) BIGNUM *b, *c, *u, *v, *tmp; int ret = 0; bn_check_top(a); bn_check_top(p); BN_CTX_start(ctx); b = BN_CTX_get(ctx); Loading Loading @@ -624,6 +641,7 @@ int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const unsigned int p[], BN_ BIGNUM *field; int ret = 0; bn_check_top(xx); BN_CTX_start(ctx); if ((field = BN_CTX_get(ctx)) == NULL) goto err; if (!BN_GF2m_arr2poly(p, field)) goto err; Loading @@ -646,6 +664,10 @@ int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p BIGNUM *xinv = NULL; int ret = 0; bn_check_top(y); bn_check_top(x); bn_check_top(p); BN_CTX_start(ctx); xinv = BN_CTX_get(ctx); if (xinv == NULL) goto err; Loading @@ -671,6 +693,10 @@ int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p BIGNUM *a, *b, *u, *v; int ret = 0; bn_check_top(y); bn_check_top(x); bn_check_top(p); BN_CTX_start(ctx); a = BN_CTX_get(ctx); Loading Loading @@ -742,6 +768,9 @@ int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, const uns BIGNUM *field; int ret = 0; bn_check_top(yy); bn_check_top(xx); BN_CTX_start(ctx); if ((field = BN_CTX_get(ctx)) == NULL) goto err; if (!BN_GF2m_arr2poly(p, field)) goto err; Loading @@ -764,13 +793,15 @@ int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig int ret = 0, i, n; BIGNUM *u; bn_check_top(a); bn_check_top(b); if (BN_is_zero(b)) return(BN_one(r)); if (BN_abs_is_word(b, 1)) return (BN_copy(r, a) != NULL); BN_CTX_start(ctx); if ((u = BN_CTX_get(ctx)) == NULL) goto err; Loading @@ -787,9 +818,7 @@ int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig } if (!BN_copy(r, u)) goto err; bn_check_top(r); ret = 1; err: BN_CTX_end(ctx); return ret; Loading @@ -807,6 +836,9 @@ int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(b); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -830,6 +862,8 @@ int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_ int ret = 0; BIGNUM *u; bn_check_top(a); if (!p[0]) /* reduction mod 1 => return 0 */ return BN_zero(r); Loading Loading @@ -859,6 +893,8 @@ int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -882,6 +918,8 @@ int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const unsigned int p unsigned int j; BIGNUM *a, *z, *rho, *w, *w2, *tmp; bn_check_top(a_); if (!p[0]) /* reduction mod 1 => return 0 */ return BN_zero(r); Loading Loading @@ -966,6 +1004,8 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX * int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); Loading Loading @@ -1025,6 +1065,7 @@ int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a) { int i; bn_check_top(a); BN_zero(a); for (i = 0; p[i] != 0; i++) { Loading Loading
crypto/bn/bn_gf2m.c +70 −29 Original line number Diff line number Diff line Loading @@ -288,6 +288,9 @@ int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) int i; const BIGNUM *at, *bt; bn_check_top(a); bn_check_top(b); if (a->top < b->top) { at = b; bt = a; } else { at = a; bt = b; } Loading Loading @@ -323,6 +326,8 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]) int n, dN, d0, d1; BN_ULONG zz, *z; bn_check_top(a); if (!p[0]) /* reduction mod 1 => return 0 */ return BN_zero(r); Loading Loading @@ -397,7 +402,6 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]) } bn_correct_top(r); return 1; } Loading @@ -412,6 +416,8 @@ int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p) int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -436,12 +442,14 @@ int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig BIGNUM *s; BN_ULONG x1, x0, y1, y0, zz[4]; bn_check_top(a); bn_check_top(b); if (a == b) { return BN_GF2m_mod_sqr_arr(r, a, p, ctx); } BN_CTX_start(ctx); if ((s = BN_CTX_get(ctx)) == NULL) goto err; Loading Loading @@ -472,7 +480,6 @@ int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig err: BN_CTX_end(ctx); return ret; } /* Compute the product of two polynomials a and b, reduce modulo p, and store Loading @@ -487,6 +494,9 @@ int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(b); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -508,6 +518,7 @@ int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_C int i, ret = 0; BIGNUM *s; bn_check_top(a); BN_CTX_start(ctx); if ((s = BN_CTX_get(ctx)) == NULL) return 0; if (!bn_wexpand(s, 2 * a->top)) goto err; Loading Loading @@ -539,6 +550,9 @@ int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -564,6 +578,9 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) BIGNUM *b, *c, *u, *v, *tmp; int ret = 0; bn_check_top(a); bn_check_top(p); BN_CTX_start(ctx); b = BN_CTX_get(ctx); Loading Loading @@ -624,6 +641,7 @@ int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const unsigned int p[], BN_ BIGNUM *field; int ret = 0; bn_check_top(xx); BN_CTX_start(ctx); if ((field = BN_CTX_get(ctx)) == NULL) goto err; if (!BN_GF2m_arr2poly(p, field)) goto err; Loading @@ -646,6 +664,10 @@ int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p BIGNUM *xinv = NULL; int ret = 0; bn_check_top(y); bn_check_top(x); bn_check_top(p); BN_CTX_start(ctx); xinv = BN_CTX_get(ctx); if (xinv == NULL) goto err; Loading @@ -671,6 +693,10 @@ int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p BIGNUM *a, *b, *u, *v; int ret = 0; bn_check_top(y); bn_check_top(x); bn_check_top(p); BN_CTX_start(ctx); a = BN_CTX_get(ctx); Loading Loading @@ -742,6 +768,9 @@ int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, const uns BIGNUM *field; int ret = 0; bn_check_top(yy); bn_check_top(xx); BN_CTX_start(ctx); if ((field = BN_CTX_get(ctx)) == NULL) goto err; if (!BN_GF2m_arr2poly(p, field)) goto err; Loading @@ -764,13 +793,15 @@ int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig int ret = 0, i, n; BIGNUM *u; bn_check_top(a); bn_check_top(b); if (BN_is_zero(b)) return(BN_one(r)); if (BN_abs_is_word(b, 1)) return (BN_copy(r, a) != NULL); BN_CTX_start(ctx); if ((u = BN_CTX_get(ctx)) == NULL) goto err; Loading @@ -787,9 +818,7 @@ int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig } if (!BN_copy(r, u)) goto err; bn_check_top(r); ret = 1; err: BN_CTX_end(ctx); return ret; Loading @@ -807,6 +836,9 @@ int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(b); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -830,6 +862,8 @@ int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_ int ret = 0; BIGNUM *u; bn_check_top(a); if (!p[0]) /* reduction mod 1 => return 0 */ return BN_zero(r); Loading Loading @@ -859,6 +893,8 @@ int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); if (!ret || ret > max) Loading @@ -882,6 +918,8 @@ int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const unsigned int p unsigned int j; BIGNUM *a, *z, *rho, *w, *w2, *tmp; bn_check_top(a_); if (!p[0]) /* reduction mod 1 => return 0 */ return BN_zero(r); Loading Loading @@ -966,6 +1004,8 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX * int ret = 0; const int max = BN_num_bits(p); unsigned int *arr=NULL; bn_check_top(a); bn_check_top(p); if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err; ret = BN_GF2m_poly2arr(p, arr, max); Loading Loading @@ -1025,6 +1065,7 @@ int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a) { int i; bn_check_top(a); BN_zero(a); for (i = 0; p[i] != 0; i++) { Loading