diff options
author | lloyd <[email protected]> | 2010-03-15 19:07:55 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-15 19:07:55 +0000 |
commit | 953ea754b875f297c7ba8af9baf72a436552b235 (patch) | |
tree | 2f598bdc6dfdaa77a09da7177abea77a4a99a7e9 /src/math/numbertheory/point_gfp.cpp | |
parent | ddf2d1af53b96da47ceee166f5527eaaa16f8928 (diff) |
Modify to allow better memory caching
Diffstat (limited to 'src/math/numbertheory/point_gfp.cpp')
-rw-r--r-- | src/math/numbertheory/point_gfp.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index 0148d9b3e..1c38a502c 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -31,11 +31,15 @@ PointGFp::PointGFp(const CurveGFp& curve, const BigInt& x, const BigInt& y) : coord_z = mod_p.reduce(curve.get_r()); } -BigInt PointGFp::monty_mult(const BigInt& a, const BigInt& b, - MemoryRegion<word>& workspace) const +void PointGFp::monty_mult(BigInt& z, + const BigInt& x, const BigInt& y, + MemoryRegion<word>& workspace) const { - if(a.is_zero() || b.is_zero()) - return 0; + if(x.is_zero() || y.is_zero()) + { + z = 0; + return; + } const BigInt& p = curve.get_p(); const u32bit p_size = curve.get_p_words(); @@ -44,24 +48,24 @@ BigInt PointGFp::monty_mult(const BigInt& a, const BigInt& b, workspace.clear(); bigint_mul(workspace, workspace.size(), 0, - a.data(), a.size(), a.sig_words(), - b.data(), b.size(), b.sig_words()); + x.data(), x.size(), x.sig_words(), + y.data(), y.size(), y.sig_words()); bigint_monty_redc(workspace, workspace.size(), p.data(), p_size, p_dash); - BigInt result; - result.grow_to(p_size); - copy_mem(result.get_reg().begin(), &workspace[p_size], p_size); - - return result; + z.get_reg().resize(p_size); + copy_mem(z.get_reg().begin(), &workspace[p_size], p_size); } -BigInt PointGFp::monty_sqr(const BigInt& x, - MemoryRegion<word>& workspace) const +void PointGFp::monty_sqr(BigInt& z, const BigInt& x, + MemoryRegion<word>& workspace) const { if(x.is_zero()) - return 0; + { + z = 0; + return; + } const BigInt& p = curve.get_p(); const u32bit p_size = curve.get_p_words(); @@ -75,11 +79,8 @@ BigInt PointGFp::monty_sqr(const BigInt& x, bigint_monty_redc(workspace, workspace.size(), p.data(), p_size, p_dash); - BigInt result; - result.grow_to(p_size); - copy_mem(result.get_reg().begin(), &workspace[p_size], p_size); - - return result; + z.get_reg().resize(p_size); + copy_mem(z.get_reg().begin(), &workspace[p_size], p_size); } void PointGFp::add(const PointGFp& rhs, |