提交 a9fd78f9 编写于 作者: G Geoff Thorpe

bn_div() does some pretty nasty things with temporary variables,

constructing BIGNUM structures with pointers offset into other bignums
(among other things). This corrects some of it that is too plainly insane,
and tries to ensure that bignums are normalised when passed to other
functions.
上级 5f747c7f
...@@ -227,9 +227,10 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, ...@@ -227,9 +227,10 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
* This is the part that corresponds to the current * This is the part that corresponds to the current
* 'area' being divided */ * 'area' being divided */
BN_init(&wnum); BN_init(&wnum);
wnum.flags = BN_FLG_STATIC_DATA; /* prevent accidental "expands" */
wnum.d= &(snum->d[loop]); wnum.d= &(snum->d[loop]);
wnum.top= div_n; wnum.top= div_n;
wnum.dmax= snum->dmax+1; /* a bit of a lie */ wnum.dmax= snum->dmax - loop; /* so we don't step out of bounds */
/* Get the top 2 words of sdiv */ /* Get the top 2 words of sdiv */
/* i=sdiv->top; */ /* i=sdiv->top; */
...@@ -248,6 +249,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, ...@@ -248,6 +249,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
/* space for temp */ /* space for temp */
if (!bn_wexpand(tmp,(div_n+1))) goto err; if (!bn_wexpand(tmp,(div_n+1))) goto err;
bn_fix_top(&wnum);
if (BN_ucmp(&wnum,sdiv) >= 0) if (BN_ucmp(&wnum,sdiv) >= 0)
{ {
if (!BN_usub(&wnum,&wnum,sdiv)) goto err; if (!BN_usub(&wnum,&wnum,sdiv)) goto err;
...@@ -346,7 +348,7 @@ X) -> 0x%08X\n", ...@@ -346,7 +348,7 @@ X) -> 0x%08X\n",
#endif /* !BN_DIV3W */ #endif /* !BN_DIV3W */
l0=bn_mul_words(tmp->d,sdiv->d,div_n,q); l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
wnum.d--; wnum.top++; wnum.d--; wnum.top++; wnum.dmax++;
tmp->d[div_n]=l0; tmp->d[div_n]=l0;
/* XXX: Couldn't we replace this with; /* XXX: Couldn't we replace this with;
* tmp->top = div_n; * tmp->top = div_n;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册