BN_div_recp fix. I've ran divtest for 10 mins and it didn't exhibit a
single fault:-) Needless to mention that bnbug.c posted couple of days ago passes as well...
This commit is contained in:
parent
6ee6fdf555
commit
63933136ab
@ -128,7 +128,7 @@ err:
|
|||||||
int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
|
int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
|
||||||
BN_CTX *ctx)
|
BN_CTX *ctx)
|
||||||
{
|
{
|
||||||
int i,j,ret=0,ex;
|
int i,j,ret=0;
|
||||||
BIGNUM *a,*b,*d,*r;
|
BIGNUM *a,*b,*d,*r;
|
||||||
|
|
||||||
BN_CTX_start(ctx);
|
BN_CTX_start(ctx);
|
||||||
@ -158,40 +158,30 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
i=BN_num_bits(m);
|
i=BN_num_bits(m);
|
||||||
if (i%2) i--;
|
|
||||||
|
|
||||||
j=recp->num_bits*2;
|
j=recp->num_bits<<1;
|
||||||
if (j > i)
|
if (j>i) i=j;
|
||||||
{
|
j>>=1;
|
||||||
i=j;
|
|
||||||
ex=0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ex=(i-j)/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
j=i/2;
|
|
||||||
|
|
||||||
if (i != recp->shift)
|
if (i != recp->shift)
|
||||||
recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
|
recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
|
||||||
i,ctx);
|
i,ctx);
|
||||||
|
|
||||||
if (!BN_rshift(a,m,j-ex)) goto err;
|
if (!BN_rshift(a,m,j)) goto err;
|
||||||
if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
|
if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
|
||||||
if (!BN_rshift(d,b,j+ex)) goto err;
|
if (!BN_rshift(d,b,i-j)) goto err;
|
||||||
d->neg=0;
|
d->neg=0;
|
||||||
if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
|
if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
|
||||||
if (!BN_usub(r,m,b)) goto err;
|
if (!BN_usub(r,m,b)) goto err;
|
||||||
r->neg=0;
|
r->neg=0;
|
||||||
|
|
||||||
j=0;
|
|
||||||
#if 1
|
#if 1
|
||||||
|
j=0;
|
||||||
while (BN_ucmp(r,&(recp->N)) >= 0)
|
while (BN_ucmp(r,&(recp->N)) >= 0)
|
||||||
{
|
{
|
||||||
if (j++ > 2)
|
if (j++ > 2)
|
||||||
{
|
{
|
||||||
#if 1
|
#if 0
|
||||||
/* work around some bug:
|
/* work around some bug:
|
||||||
-1CC0E177F93042B29D309839F8019DB93404D7A395F1E162
|
-1CC0E177F93042B29D309839F8019DB93404D7A395F1E162
|
||||||
5383BF622A20B17E1BAA999336988B82B93F5FB77B55B4B68
|
5383BF622A20B17E1BAA999336988B82B93F5FB77B55B4B68
|
||||||
|
Loading…
x
Reference in New Issue
Block a user