Add missing bn_check_top()s to bn_gf2m.c and remove some miscellaneous
white-space.
This commit is contained in:
parent
998ae048e7
commit
e7e5fe4705
@ -288,6 +288,9 @@ int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
|
|||||||
int i;
|
int i;
|
||||||
const BIGNUM *at, *bt;
|
const BIGNUM *at, *bt;
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
|
bn_check_top(b);
|
||||||
|
|
||||||
if (a->top < b->top) { at = b; bt = a; }
|
if (a->top < b->top) { at = b; bt = a; }
|
||||||
else { at = a; bt = b; }
|
else { at = a; bt = b; }
|
||||||
|
|
||||||
@ -323,6 +326,8 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[])
|
|||||||
int n, dN, d0, d1;
|
int n, dN, d0, d1;
|
||||||
BN_ULONG zz, *z;
|
BN_ULONG zz, *z;
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
|
|
||||||
if (!p[0])
|
if (!p[0])
|
||||||
/* reduction mod 1 => return 0 */
|
/* reduction mod 1 => return 0 */
|
||||||
return BN_zero(r);
|
return BN_zero(r);
|
||||||
@ -397,7 +402,6 @@ int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
bn_correct_top(r);
|
bn_correct_top(r);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,6 +416,8 @@ int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
const int max = BN_num_bits(p);
|
const int max = BN_num_bits(p);
|
||||||
unsigned int *arr=NULL;
|
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;
|
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
|
||||||
ret = BN_GF2m_poly2arr(p, arr, max);
|
ret = BN_GF2m_poly2arr(p, arr, max);
|
||||||
if (!ret || ret > max)
|
if (!ret || ret > max)
|
||||||
@ -436,12 +442,14 @@ int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig
|
|||||||
BIGNUM *s;
|
BIGNUM *s;
|
||||||
BN_ULONG x1, x0, y1, y0, zz[4];
|
BN_ULONG x1, x0, y1, y0, zz[4];
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
|
bn_check_top(b);
|
||||||
|
|
||||||
if (a == b)
|
if (a == b)
|
||||||
{
|
{
|
||||||
return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
|
return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
if ((s = BN_CTX_get(ctx)) == NULL) goto err;
|
if ((s = BN_CTX_get(ctx)) == NULL) goto err;
|
||||||
|
|
||||||
@ -472,7 +480,6 @@ int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsig
|
|||||||
err:
|
err:
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute the product of two polynomials a and b, reduce modulo p, and store
|
/* Compute the product of two polynomials a and b, reduce modulo p, and store
|
||||||
@ -487,6 +494,9 @@ int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
const int max = BN_num_bits(p);
|
const int max = BN_num_bits(p);
|
||||||
unsigned int *arr=NULL;
|
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;
|
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
|
||||||
ret = BN_GF2m_poly2arr(p, arr, max);
|
ret = BN_GF2m_poly2arr(p, arr, max);
|
||||||
if (!ret || ret > max)
|
if (!ret || ret > max)
|
||||||
@ -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;
|
int i, ret = 0;
|
||||||
BIGNUM *s;
|
BIGNUM *s;
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
if ((s = BN_CTX_get(ctx)) == NULL) return 0;
|
if ((s = BN_CTX_get(ctx)) == NULL) return 0;
|
||||||
if (!bn_wexpand(s, 2 * a->top)) goto err;
|
if (!bn_wexpand(s, 2 * a->top)) goto err;
|
||||||
@ -539,6 +550,9 @@ int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
const int max = BN_num_bits(p);
|
const int max = BN_num_bits(p);
|
||||||
unsigned int *arr=NULL;
|
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;
|
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
|
||||||
ret = BN_GF2m_poly2arr(p, arr, max);
|
ret = BN_GF2m_poly2arr(p, arr, max);
|
||||||
if (!ret || ret > max)
|
if (!ret || ret > max)
|
||||||
@ -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;
|
BIGNUM *b, *c, *u, *v, *tmp;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
|
bn_check_top(p);
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
|
|
||||||
b = BN_CTX_get(ctx);
|
b = BN_CTX_get(ctx);
|
||||||
@ -624,6 +641,7 @@ int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const unsigned int p[], BN_
|
|||||||
BIGNUM *field;
|
BIGNUM *field;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
bn_check_top(xx);
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
if ((field = BN_CTX_get(ctx)) == NULL) goto err;
|
if ((field = BN_CTX_get(ctx)) == NULL) goto err;
|
||||||
if (!BN_GF2m_arr2poly(p, field)) goto err;
|
if (!BN_GF2m_arr2poly(p, field)) goto err;
|
||||||
@ -646,6 +664,10 @@ int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p
|
|||||||
BIGNUM *xinv = NULL;
|
BIGNUM *xinv = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
bn_check_top(y);
|
||||||
|
bn_check_top(x);
|
||||||
|
bn_check_top(p);
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
xinv = BN_CTX_get(ctx);
|
xinv = BN_CTX_get(ctx);
|
||||||
if (xinv == NULL) goto err;
|
if (xinv == NULL) goto err;
|
||||||
@ -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;
|
BIGNUM *a, *b, *u, *v;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
bn_check_top(y);
|
||||||
|
bn_check_top(x);
|
||||||
|
bn_check_top(p);
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
|
|
||||||
a = BN_CTX_get(ctx);
|
a = BN_CTX_get(ctx);
|
||||||
@ -742,6 +768,9 @@ int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, const uns
|
|||||||
BIGNUM *field;
|
BIGNUM *field;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
bn_check_top(yy);
|
||||||
|
bn_check_top(xx);
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
if ((field = BN_CTX_get(ctx)) == NULL) goto err;
|
if ((field = BN_CTX_get(ctx)) == NULL) goto err;
|
||||||
if (!BN_GF2m_arr2poly(p, field)) goto err;
|
if (!BN_GF2m_arr2poly(p, field)) goto err;
|
||||||
@ -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;
|
int ret = 0, i, n;
|
||||||
BIGNUM *u;
|
BIGNUM *u;
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
|
bn_check_top(b);
|
||||||
|
|
||||||
if (BN_is_zero(b))
|
if (BN_is_zero(b))
|
||||||
return(BN_one(r));
|
return(BN_one(r));
|
||||||
|
|
||||||
if (BN_abs_is_word(b, 1))
|
if (BN_abs_is_word(b, 1))
|
||||||
return (BN_copy(r, a) != NULL);
|
return (BN_copy(r, a) != NULL);
|
||||||
|
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
if ((u = BN_CTX_get(ctx)) == NULL) goto err;
|
if ((u = BN_CTX_get(ctx)) == NULL) goto err;
|
||||||
|
|
||||||
@ -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;
|
if (!BN_copy(r, u)) goto err;
|
||||||
bn_check_top(r);
|
bn_check_top(r);
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
BN_CTX_end(ctx);
|
BN_CTX_end(ctx);
|
||||||
return ret;
|
return ret;
|
||||||
@ -807,6 +836,9 @@ int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
const int max = BN_num_bits(p);
|
const int max = BN_num_bits(p);
|
||||||
unsigned int *arr=NULL;
|
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;
|
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
|
||||||
ret = BN_GF2m_poly2arr(p, arr, max);
|
ret = BN_GF2m_poly2arr(p, arr, max);
|
||||||
if (!ret || ret > max)
|
if (!ret || ret > max)
|
||||||
@ -830,6 +862,8 @@ int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
BIGNUM *u;
|
BIGNUM *u;
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
|
|
||||||
if (!p[0])
|
if (!p[0])
|
||||||
/* reduction mod 1 => return 0 */
|
/* reduction mod 1 => return 0 */
|
||||||
return BN_zero(r);
|
return BN_zero(r);
|
||||||
@ -859,6 +893,8 @@ int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
const int max = BN_num_bits(p);
|
const int max = BN_num_bits(p);
|
||||||
unsigned int *arr=NULL;
|
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;
|
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
|
||||||
ret = BN_GF2m_poly2arr(p, arr, max);
|
ret = BN_GF2m_poly2arr(p, arr, max);
|
||||||
if (!ret || ret > max)
|
if (!ret || ret > max)
|
||||||
@ -882,6 +918,8 @@ int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const unsigned int p
|
|||||||
unsigned int j;
|
unsigned int j;
|
||||||
BIGNUM *a, *z, *rho, *w, *w2, *tmp;
|
BIGNUM *a, *z, *rho, *w, *w2, *tmp;
|
||||||
|
|
||||||
|
bn_check_top(a_);
|
||||||
|
|
||||||
if (!p[0])
|
if (!p[0])
|
||||||
/* reduction mod 1 => return 0 */
|
/* reduction mod 1 => return 0 */
|
||||||
return BN_zero(r);
|
return BN_zero(r);
|
||||||
@ -966,6 +1004,8 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
const int max = BN_num_bits(p);
|
const int max = BN_num_bits(p);
|
||||||
unsigned int *arr=NULL;
|
unsigned int *arr=NULL;
|
||||||
|
bn_check_top(a);
|
||||||
|
bn_check_top(p);
|
||||||
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) *
|
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) *
|
||||||
max)) == NULL) goto err;
|
max)) == NULL) goto err;
|
||||||
ret = BN_GF2m_poly2arr(p, arr, max);
|
ret = BN_GF2m_poly2arr(p, arr, max);
|
||||||
@ -1025,6 +1065,7 @@ int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
bn_check_top(a);
|
||||||
BN_zero(a);
|
BN_zero(a);
|
||||||
for (i = 0; p[i] != 0; i++)
|
for (i = 0; p[i] != 0; i++)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user