Changes between 0.9.7c and 0.9.8 [xx XXX xxxx]
+ *) BN_zero() only needs to set 'top' and 'neg' to zero for correct results,
+ and this should never fail. So the return value from the use of
+ BN_set_word() (which can fail due to needless expansion) is now deprecated;
+ if OPENSSL_NO_DEPRECATED is defined, BN_zero() is a void macro.
+ [Geoff Thorpe]
+
*) BN_CTX_get() should return zero-valued bignums, providing the same
initialised value as BN_new().
[Geoff Thorpe, suggested by Ulf Möller]
if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
if (BN_is_zero(&(val[0])))
{
- ret = BN_zero(r);
+ BN_zero(r);
+ ret = 1;
goto err;
}
aa=a;
if (BN_is_zero(aa))
{
- ret = BN_zero(rr);
+ BN_zero(rr);
+ ret = 1;
goto err;
}
if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
}
if (a == 0)
{
- ret = BN_zero(rr);
+ BN_zero(rr);
+ ret = 1;
return ret;
}
if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
if (BN_is_zero(&(val[0])))
{
- ret = BN_zero(r);
+ BN_zero(r);
+ ret = 1;
goto err;
}
a_mod_m = a1;
if (BN_is_zero(a_mod_m))
{
- ret = BN_zero(rr);
+ BN_zero(rr);
+ ret = 1;
goto err;
}
a_mod_m = a2;
if (BN_is_zero(a_mod_m))
{
- ret = BN_zero(rr);
+ BN_zero(rr);
+ ret = 1;
goto err;
}
if (!BN_to_montgomery(&(val2[0]),a_mod_m,mont,ctx)) goto err;
bn_check_top(a);
if (!p[0])
+ {
/* reduction mod 1 => return 0 */
- return BN_zero(r);
+ BN_zero(r);
+ return 1;
+ }
/* Since the algorithm does reduction in the r value, if a != r, copy
* the contents of a into r so we can do reduction in r.
if (v == NULL) goto err;
if (!BN_one(b)) goto err;
- if (!BN_zero(c)) goto err;
if (!BN_GF2m_mod(u, a, p)) goto err;
if (!BN_copy(v, p)) goto err;
if (!BN_GF2m_mod(u, y, p)) goto err;
if (!BN_GF2m_mod(a, x, p)) goto err;
if (!BN_copy(b, p)) goto err;
- if (!BN_zero(v)) goto err;
while (!BN_is_odd(a))
{
bn_check_top(a);
if (!p[0])
+ {
/* reduction mod 1 => return 0 */
- return BN_zero(r);
+ BN_zero(r);
+ return 1;
+ }
BN_CTX_start(ctx);
if ((u = BN_CTX_get(ctx)) == NULL) goto err;
- if (!BN_zero(u)) goto err;
if (!BN_set_bit(u, p[0] - 1)) goto err;
ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);
bn_check_top(r);
bn_check_top(a_);
if (!p[0])
+ {
/* reduction mod 1 => return 0 */
- return BN_zero(r);
+ BN_zero(r);
+ return 1;
+ }
BN_CTX_start(ctx);
a = BN_CTX_get(ctx);
if (BN_is_zero(a))
{
- ret = BN_zero(r);
+ BN_zero(r);
+ ret = 1;
goto err;
}
{
if (!BN_rand(rho, p[0], 0, 0)) goto err;
if (!BN_GF2m_mod_arr(rho, rho, p)) goto err;
- if (!BN_zero(z)) goto err;
+ BN_zero(z);
if (!BN_copy(w, rho)) goto err;
for (j = 1; j <= p[0] - 1; j++)
{
BN_ULONG buf[2];
mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
- if (!(BN_zero(R))) goto err;
+ BN_zero(R);
if (!(BN_set_bit(R,BN_BITS2))) goto err; /* R */
buf[0]=mod->d[0]; /* tmod = N mod word size */
#else /* !MONT_WORD */
{ /* bignum version */
mont->ri=BN_num_bits(&mont->N);
- if (!BN_zero(R)) goto err;
+ BN_zero(R);
if (!BN_set_bit(R,mont->ri)) goto err; /* R = 2^ri */
/* Ri = R^-1 mod N*/
if ((BN_mod_inverse(&Ri,R,&mont->N,ctx)) == NULL)
#endif
/* setup RR for conversions */
- if (!BN_zero(&(mont->RR))) goto err;
+ BN_zero(&(mont->RR));
if (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;
if (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;
if ((al == 0) || (bl == 0))
{
- if (!BN_zero(r)) goto err;
+ BN_zero(r);
return(1);
}
top=al+bl;
if (r != rr) BN_copy(r,rr);
ret=1;
err:
- BN_CTX_end(ctx);
bn_check_top(r);
+ BN_CTX_end(ctx);
return(ret);
}
top = BN_ucmp(field, a);
if (top == 0)
- return BN_zero(r);
+ {
+ BN_zero(r);
+ return 1;
+ }
else if (top > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
tmp_int = BN_ucmp(field, a);
if (tmp_int == 0)
- return BN_zero(r);
+ {
+ BN_zero(r);
+ return 1;
+ }
else if (tmp_int > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
tmp_int = BN_ucmp(field, a);
if (tmp_int == 0)
- return BN_zero(r);
+ {
+ BN_zero(r);
+ return 1;
+ }
else if (tmp_int > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
tmp_int = BN_ucmp(field, a);
if (tmp_int == 0)
- return BN_zero(r);
+ {
+ BN_zero(r);
+ return 1;
+ }
else if (tmp_int > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
/* BN_is_bit_set(range, n - 1) always holds */
if (n == 1)
- {
- if (!BN_zero(r)) return 0;
- }
+ BN_zero(r);
else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3))
{
/* range = 100..._2,
int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
{
if (!BN_copy(&(recp->N),d)) return 0;
- if (!BN_zero(&(recp->Nr))) return 0;
+ BN_zero(&(recp->Nr));
recp->num_bits=BN_num_bits(d);
recp->shift=0;
return(1);
if (BN_ucmp(m,&(recp->N)) < 0)
{
- if (!BN_zero(d)) return 0;
+ BN_zero(d);
if (!BN_copy(r,m)) return 0;
BN_CTX_end(ctx);
return(1);
BN_init(&t);
- if (!BN_zero(&t)) goto err;
if (!BN_set_bit(&t,len)) goto err;
if (!BN_div(r,NULL,&t,m,ctx)) goto err;
if (al <= 0)
{
r->top=0;
- return(1);
+ return 1;
}
BN_CTX_start(ctx);
rr=(a != r) ? r : BN_CTX_get(ctx);
tmp=BN_CTX_get(ctx);
- if (tmp == NULL) goto err;
+ if (!rr || !tmp) goto err;
- max=(al+al);
+ max = 2 * al; /* Non-zero (from above) */
if (bn_wexpand(rr,max+1) == NULL) goto err;
if (al == 4)
#endif
}
- rr->top=max;
rr->neg=0;
- if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
+ /* If the most-significant half of the top word of 'a' is zero, then
+ * the square of 'a' will max-1 words. */
+ if(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))
+ rr->top = max - 1;
+ else
+ rr->top = max;
if (rr != r) BN_copy(r,rr);
ret = 1;
err:
+ if(rr) bn_check_top(rr);
+ if(tmp) bn_check_top(tmp);
BN_CTX_end(ctx);
- bn_check_top(r);
return(ret);
}
if (BN_is_zero(t))
{
/* special case: a == 0 (mod p) */
- if (!BN_zero(ret)) goto end;
+ BN_zero(ret);
err = 0;
goto end;
}
if (BN_is_zero(x))
{
/* special case: a == 0 (mod p) */
- if (!BN_zero(ret)) goto end;
+ BN_zero(ret);
err = 0;
goto end;
}
if (BN_is_zero(z1))
{
- if (!BN_zero(x2)) return 0;
- if (!BN_zero(z2)) return 0;
+ BN_zero(x2);
+ BN_zero(z2);
return 1;
}
int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
{
point->Z_is_one = 0;
- return (BN_zero(&point->Z));
+ BN_zero(&point->Z);
+ return 1;
}
if (order != NULL)
{ if (!BN_copy(&group->order, order)) return 0; }
else
- { if (!BN_zero(&group->order)) return 0; }
+ BN_zero(&group->order);
if (cofactor != NULL)
{ if (!BN_copy(&group->cofactor, cofactor)) return 0; }
else
- { if (!BN_zero(&group->cofactor)) return 0; }
+ BN_zero(&group->cofactor);
return 1;
}
int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
{
point->Z_is_one = 0;
- return (BN_zero(&point->Z));
+ BN_zero(&point->Z);
+ return 1;
}
else
{
/* a is the inverse of b */
- if (!BN_zero(&r->Z)) goto end;
+ BN_zero(&r->Z);
r->Z_is_one = 0;
ret = 1;
goto end;
if (EC_POINT_is_at_infinity(group, a))
{
- if (!BN_zero(&r->Z)) return 0;
+ BN_zero(&r->Z);
r->Z_is_one = 0;
return 1;
}