diff options
author | lloyd <[email protected]> | 2011-06-07 13:36:26 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-06-07 13:36:26 +0000 |
commit | ad7aad3eb232499dfa6b74a66d6aff29c9ceb77c (patch) | |
tree | 9e2dbb5ffe8a847613536d3d7bebae3985abf774 /src | |
parent | 07a288e9077d4722426225fb057c5e414e00e40b (diff) |
Simplify Montgomery setup here a bit
Diffstat (limited to 'src')
-rw-r--r-- | src/math/numbertheory/powm_mnt.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp index adc4e0c42..8993f4ba9 100644 --- a/src/math/numbertheory/powm_mnt.cpp +++ b/src/math/numbertheory/powm_mnt.cpp @@ -128,14 +128,12 @@ Montgomery_Exponentiator::Montgomery_Exponentiator(const BigInt& mod, mod_words = modulus.sig_words(); - BigInt mod_prime_bn(BigInt::Power2, MP_WORD_BITS); - mod_prime = (mod_prime_bn - inverse_mod(modulus, mod_prime_bn)).word_at(0); + BigInt r(BigInt::Power2, mod_words * BOTAN_MP_WORD_BITS); + mod_prime = (((r * inverse_mod(r, mod)) - 1) / mod).word_at(0); - R_mod = BigInt(BigInt::Power2, MP_WORD_BITS * mod_words); - R_mod %= modulus; + R_mod = r % modulus; - R2 = BigInt(BigInt::Power2, 2 * MP_WORD_BITS * mod_words); - R2 %= modulus; + R2 = (R_mod * R_mod) % modulus; } } |