summaryrefslogtreecommitdiffstats
path: root/crypto/bn/bn_recp.c
diff options
context:
space:
mode:
authorAndy Polyakov <appro@openssl.org>2000-02-26 16:20:05 +0000
committerAndy Polyakov <appro@openssl.org>2000-02-26 16:20:05 +0000
commit63933136aba87932bea82b2a468f5b32b70a3636 (patch)
treea042c93bc19ce5a403eeb804e77c52fba1de73af /crypto/bn/bn_recp.c
parent6ee6fdf5555877d05a7188ed8902c52fea1f42c2 (diff)
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...
Diffstat (limited to 'crypto/bn/bn_recp.c')
-rw-r--r--crypto/bn/bn_recp.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/crypto/bn/bn_recp.c b/crypto/bn/bn_recp.c
index 20a6da4efd..a6d7900a3c 100644
--- a/crypto/bn/bn_recp.c
+++ b/crypto/bn/bn_recp.c
@@ -128,7 +128,7 @@ err:
int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
BN_CTX *ctx)
{
- int i,j,ret=0,ex;
+ int i,j,ret=0;
BIGNUM *a,*b,*d,*r;
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);
- if (i%2) i--;
- j=recp->num_bits*2;
- if (j > i)
- {
- i=j;
- ex=0;
- }
- else
- {
- ex=(i-j)/2;
- }
-
- j=i/2;
+ j=recp->num_bits<<1;
+ if (j>i) i=j;
+ j>>=1;
if (i != recp->shift)
recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
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_rshift(d,b,j+ex)) goto err;
+ if (!BN_rshift(d,b,i-j)) goto err;
d->neg=0;
if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
if (!BN_usub(r,m,b)) goto err;
r->neg=0;
- j=0;
#if 1
+ j=0;
while (BN_ucmp(r,&(recp->N)) >= 0)
{
if (j++ > 2)
{
-#if 1
+#if 0
/* work around some bug:
-1CC0E177F93042B29D309839F8019DB93404D7A395F1E162
5383BF622A20B17E1BAA999336988B82B93F5FB77B55B4B68