From 78f288d5c9cf06b6fb648cb770b9058aaaba9d8c Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Mon, 17 Oct 2011 23:35:00 +0000 Subject: bn_mont.c: get corner cases right in updated BN_from_montgomery_word. --- crypto/bn/bn_mont.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crypto/bn/bn_mont.c') diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c index 5bf1f0213c..e6f6e3f0f8 100644 --- a/crypto/bn/bn_mont.c +++ b/crypto/bn/bn_mont.c @@ -196,9 +196,9 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) /* clear the top words of T */ #if 1 for (i=r->top; id[i]=0; + rp[i]=0; #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 r->top=max; @@ -225,10 +225,10 @@ static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) #else v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2); #endif - if ((rp[nl] = (rp[nl]+v+carry)&BN_MASK2) < v) - carry = 1; - else - carry = 0; + v = (v+carry+rp[nl])&BN_MASK2; + carry |= (v != rp[nl]); + carry &= (v <= rp[nl]); + rp[nl]=v; } if (bn_wexpand(ret,nl) == NULL) return(0); -- cgit v1.2.3