bn_mont.c: get corner cases right in updated BN_from_montgomery_word.
This commit is contained in:
parent
8329e2e776
commit
78f288d5c9
@ -196,9 +196,9 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
|
|||||||
/* clear the top words of T */
|
/* clear the top words of T */
|
||||||
#if 1
|
#if 1
|
||||||
for (i=r->top; i<max; i++) /* memset? XXX */
|
for (i=r->top; i<max; i++) /* memset? XXX */
|
||||||
r->d[i]=0;
|
rp[i]=0;
|
||||||
#else
|
#else
|
||||||
memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
|
memset(&(rp[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
r->top=max;
|
r->top=max;
|
||||||
@ -225,10 +225,10 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
|
|||||||
#else
|
#else
|
||||||
v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
|
v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
|
||||||
#endif
|
#endif
|
||||||
if ((rp[nl] = (rp[nl]+v+carry)&BN_MASK2) < v)
|
v = (v+carry+rp[nl])&BN_MASK2;
|
||||||
carry = 1;
|
carry |= (v != rp[nl]);
|
||||||
else
|
carry &= (v <= rp[nl]);
|
||||||
carry = 0;
|
rp[nl]=v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bn_wexpand(ret,nl) == NULL) return(0);
|
if (bn_wexpand(ret,nl) == NULL) return(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user