diff options
author | Geoff Thorpe <geoff@openssl.org> | 2003-11-13 16:03:14 +0100 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2003-11-13 16:03:14 +0100 |
commit | 9dde17e8b43980d193dd7c117edeca9c602c41ab (patch) | |
tree | d1b95e748c22019dbb40c57c3fb077dbb17ee2b7 /crypto/bn/bn_shift.c | |
parent | General improvements to the ec_asn1.c code. This squashes at least one bug (diff) | |
download | openssl-9dde17e8b43980d193dd7c117edeca9c602c41ab.tar.xz openssl-9dde17e8b43980d193dd7c117edeca9c602c41ab.zip |
This rewrites two "for" loops in BN_rshift() - equality with zero is
generally a more efficient comparison than comparing two integers, and the
first of these two loops was off-by-one (copying one too many values). This
change also removes a superfluous assignment that would set an unused word
to zero (and potentially allow an overrun in some cases).
Submitted by: Nils Larsch
Reviewed by: Geoff Thorpe
Diffstat (limited to 'crypto/bn/bn_shift.c')
-rw-r--r-- | crypto/bn/bn_shift.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/crypto/bn/bn_shift.c b/crypto/bn/bn_shift.c index 69c03570bd..de9312dce2 100644 --- a/crypto/bn/bn_shift.c +++ b/crypto/bn/bn_shift.c @@ -200,13 +200,13 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) if (rb == 0) { - for (i=j+1; i > 0; i--) + for (i=j; i != 0; i--) *(t++)= *(f++); } else { l= *(f++); - for (i=1; i<j; i++) + for (i=j-1; i != 0; i--) { tmp =(l>>rb)&BN_MASK2; l= *(f++); @@ -214,7 +214,6 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) } *(t++) =(l>>rb)&BN_MASK2; } - *t=0; bn_correct_top(r); bn_check_top(r); return(1); |