diff options
author | Geoff Thorpe <geoff@openssl.org> | 2004-06-17 20:03:56 +0000 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2004-06-17 20:03:56 +0000 |
commit | cf9056cfda3976fc53a630f9965b68569d656e27 (patch) | |
tree | 72bc98c2976677caf6bd1b886b00dce23591c7dc /crypto/bn/bn_word.c | |
parent | f7fc4ca1dd98153e8e21ecbd1fb4fd45c8a14011 (diff) |
BN_div_word() was breaking when called from BN_bn2dec() (actually, this is
the only function that uses it) because it would trip up an assertion in
bn_div_words() when first invoked. This also adds BN_div_word() testing to
bntest.
Submitted by: Nils Larsch
Reviewed by: Geoff Thorpe
Diffstat (limited to 'crypto/bn/bn_word.c')
-rw-r--r-- | crypto/bn/bn_word.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/crypto/bn/bn_word.c b/crypto/bn/bn_word.c index 7aa2a33d2d..1bcb37e292 100644 --- a/crypto/bn/bn_word.c +++ b/crypto/bn/bn_word.c @@ -87,7 +87,7 @@ BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w) BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w) { BN_ULONG ret = 0; - int i; + int i, j; bn_check_top(a); w &= BN_MASK2; @@ -98,6 +98,12 @@ BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w) if (a->top == 0) return 0; + /* normalize input (so bn_div_words doesn't complain) */ + j = BN_BITS2 - BN_num_bits_word(w); + w <<= j; + if (!BN_lshift(a, a, j)) + return 0; + for (i=a->top-1; i>=0; i--) { BN_ULONG l,d; @@ -109,6 +115,7 @@ BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w) } if ((a->top > 0) && (a->d[a->top-1] == 0)) a->top--; + ret >>= j; bn_check_top(a); return(ret); } |