diff options
author | lloyd <[email protected]> | 2010-03-13 05:34:05 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-13 05:34:05 +0000 |
commit | 1d0538d6906f3f0695976da3fde65eb72e830afb (patch) | |
tree | 262ea8e9db1a07fbc80acfd7d280f47f1fa4b970 /src/math/numbertheory | |
parent | 7a3a641568e66eb7e39b5491bf41f84e1cb0df61 (diff) |
Inline/simplifiy monty mult
Diffstat (limited to 'src/math/numbertheory')
-rw-r--r-- | src/math/numbertheory/point_gfp.cpp | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index f30cfed8d..93714e219 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -15,28 +15,6 @@ namespace Botan { -namespace { - -void inner_montg_mult_sos(word result[], - const word a_bar[], const word b_bar[], - const word p[], - word p_dash, - u32bit s) - { - SecureVector<word> t; - t.grow_to(2*s+1); - - bigint_simple_mul(t, a_bar, s, b_bar, s); - - bigint_monty_redc(&t[0], t.size(), - p, s, - p_dash); - - copy_mem(&result[0], &t[s], s); - } - -} - PointGFp::PointGFp(const CurveGFp& curve) : curve(curve), coord_x(0), @@ -63,14 +41,18 @@ BigInt PointGFp::monty_mult(const BigInt& a, const BigInt& b) return result; const BigInt& p = curve.get_p(); - const u32bit s = p.sig_words(); + const u32bit p_size = p.sig_words(); + + const word p_dash = curve.get_p_dash(); - result.grow_to(s); + result.grow_to(p_size); - if(a > 0 && b > 0 && a < p && b < p && a.size() >= s && b.size() >= s) + SecureVector<word> t; + t.grow_to(2*p_size+1); + + if(a > 0 && b > 0 && a < p && b < p && a.size() >= p_size && b.size() >= p_size) { - inner_montg_mult_sos(result.get_reg(), a.data(), b.data(), - p.data(), curve.get_p_dash(), s); + bigint_simple_mul(t, a.data(), a.sig_words(), b.data(), b.sig_words()); } else { @@ -78,16 +60,18 @@ BigInt PointGFp::monty_mult(const BigInt& a, const BigInt& b) BigInt a2 = a; BigInt b2 = b; - a2.grow_to(s); - b2.grow_to(s); + a2.grow_to(p_size); + b2.grow_to(p_size); a2 = mod_p.reduce(a2); b2 = mod_p.reduce(b2); - inner_montg_mult_sos(result.get_reg(), a2.data(), b2.data(), - p.data(), curve.get_p_dash(), s); + bigint_simple_mul(t, a2.data(), a2.sig_words(), b2.data(), b2.sig_words()); } + bigint_monty_redc(&t[0], t.size(), p.data(), p_size, p_dash); + copy_mem(&result[0], &t[p_size], p_size); + return result; } |