diff options
author | lloyd <[email protected]> | 2010-03-13 09:53:22 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-13 09:53:22 +0000 |
commit | 967ca8ef302c69eea5a982c5371ccd05de410931 (patch) | |
tree | 9f16249c06e8a6712de60a93c0586eef6d5e0f4e /src/math/numbertheory | |
parent | 0dd2c107e4ed8ec3c207d1ae9e4ef21702f9d2ba (diff) |
Always keep coord_{x,y,z} < p, so don't ever have to copy or use reducer
in monty_mult()
Diffstat (limited to 'src/math/numbertheory')
-rw-r--r-- | src/math/numbertheory/point_gfp.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index 2d57b98b2..15a979d89 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -9,8 +9,6 @@ #include <botan/point_gfp.h> #include <botan/numthry.h> -#include <botan/mp_asm.h> -#include <botan/mp_asmi.h> #include <botan/mp_core.h> namespace Botan { @@ -30,7 +28,7 @@ PointGFp::PointGFp(const CurveGFp& curve, const BigInt& x, const BigInt& y) : coord_x = mod_p.multiply(curve.get_r(), x); coord_y = mod_p.multiply(curve.get_r(), y); - coord_z = curve.get_r(); + coord_z = mod_p.reduce(curve.get_r()); } BigInt PointGFp::monty_mult(const BigInt& a, const BigInt& b, @@ -40,29 +38,15 @@ BigInt PointGFp::monty_mult(const BigInt& a, const BigInt& b, return 0; const BigInt& p = curve.get_p(); - const u32bit p_size = p.sig_words(); + const u32bit p_size = (workspace.size() - 1) / 2; const word p_dash = curve.get_p_dash(); workspace.clear(); - if(a > 0 && b > 0 && a < p && b < p) - { - bigint_simple_mul(workspace, - a.data(), a.sig_words(), - b.data(), b.sig_words()); - } - else - { - const Modular_Reducer& mod_p = curve.mod_p(); - - BigInt a2 = mod_p.reduce(a); - BigInt b2 = mod_p.reduce(b); - - bigint_simple_mul(workspace, - a2.data(), a2.sig_words(), - b2.data(), b2.sig_words()); - } + bigint_simple_mul(workspace, + a.data(), a.sig_words(), + b.data(), b.sig_words()); bigint_monty_redc(workspace, workspace.size(), p.data(), p_size, p_dash); @@ -245,7 +229,11 @@ void PointGFp::mult2(MemoryRegion<word>& ws) BigInt U = mod_p.reduce(monty_mult(y_2, y_2, ws) << 3); - BigInt y = monty_mult(M, S - x, ws) - U; + S -= x; + while(S.is_negative()) + S += curve.get_p(); + + BigInt y = monty_mult(M, S, ws) - U; if(y.is_negative()) y += curve.get_p(); |