diff options
author | lloyd <[email protected]> | 2006-08-17 21:38:53 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-08-17 21:38:53 +0000 |
commit | 23df9aa184130ea94a7708ba01ec2798c7d73426 (patch) | |
tree | 77f2f9c6a551a56f61258d2ff342af6b5b8d7989 /src | |
parent | 779893630cecab2dd0788a4ab332e42b4a7937e8 (diff) |
Create a slightly higher level wrapper around bigint_monty_redc, save a
few lines.
Diffstat (limited to 'src')
-rw-r--r-- | src/powm_mnt.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/powm_mnt.cpp b/src/powm_mnt.cpp index d28bfacfe..f527927b5 100644 --- a/src/powm_mnt.cpp +++ b/src/powm_mnt.cpp @@ -14,13 +14,19 @@ namespace { /************************************************* * Montgomery Reduction * *************************************************/ -void montgomery_reduce(word z[], u32bit z_size, - const word x[], u32bit x_size, word u) +inline void montgomery_reduce(BigInt& out, MemoryRegion<word>& z_buf, + const BigInt& x_bn, u32bit x_size, word u) { + const word* x = x_bn.data(); + word* z = z_buf.begin(); + u32bit z_size = z_buf.size(); + bigint_monty_redc(z, z_size, x, x_size, u); if(bigint_cmp(z + x_size, x_size + 1, x, x_size) >= 0) bigint_sub2(z + x_size, x_size + 1, x, x_size); + + out.get_reg().set(z + x_size, x_size + 1); } /************************************************* @@ -83,9 +89,7 @@ void Montgomery_Exponentiator::set_base(const BigInt& base) g[0].data(), g[0].size(), g[0].sig_words(), R2.data(), R2.size(), R2.sig_words()); - montgomery_reduce(z.begin(), z.size(), modulus.data(), mod_words, - mod_prime); - g[0].get_reg().set(z + mod_words, mod_words + 1); + montgomery_reduce(g[0], z, modulus, mod_words, mod_prime); const BigInt& x = g[0]; const u32bit x_sig = x.sig_words(); @@ -100,10 +104,7 @@ void Montgomery_Exponentiator::set_base(const BigInt& base) x.data(), x.size(), x_sig, y.data(), y.size(), y_sig); - montgomery_reduce(z.begin(), z.size(), modulus.data(), mod_words, - mod_prime); - - g[j].get_reg().set(z + mod_words, mod_words + 1); + montgomery_reduce(g[j], z, modulus, mod_words, mod_prime); } } @@ -126,9 +127,7 @@ BigInt Montgomery_Exponentiator::execute() const bigint_sqr(z.begin(), z.size(), workspace, x.data(), x.size(), x.sig_words()); - montgomery_reduce(z.begin(), z.size(), modulus.data(), mod_words, - mod_prime); - x.get_reg().set(z + mod_words, mod_words + 1); + montgomery_reduce(x, z, modulus, mod_words, mod_prime); } u32bit nibble = exp.get_substring(window_bits*(j-1), window_bits); @@ -141,18 +140,14 @@ BigInt Montgomery_Exponentiator::execute() const x.data(), x.size(), x.sig_words(), y.data(), y.size(), y.sig_words()); - montgomery_reduce(z.begin(), z.size(), modulus.data(), mod_words, - mod_prime); - x.get_reg().set(z + mod_words, mod_words + 1); + montgomery_reduce(x, z, modulus, mod_words, mod_prime); } } z.clear(); z.copy(x.data(), x.size()); - montgomery_reduce(z.begin(), z.size(), modulus.data(), mod_words, - mod_prime); - x.get_reg().set(z + mod_words, mod_words + 1); + montgomery_reduce(x, z, modulus, mod_words, mod_prime); return x; } |