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 | |
parent | ddf2d1af53b96da47ceee166f5527eaaa16f8928 (diff) |
Modify to allow better memory caching
-rw-r--r-- | src/math/numbertheory/point_gfp.cpp | 39 | ||||
-rw-r--r-- | src/math/numbertheory/point_gfp.h | 34 |
2 files changed, 52 insertions, 21 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, diff --git a/src/math/numbertheory/point_gfp.h b/src/math/numbertheory/point_gfp.h index f5cb11157..f597990ff 100644 --- a/src/math/numbertheory/point_gfp.h +++ b/src/math/numbertheory/point_gfp.h @@ -158,7 +158,23 @@ class BOTAN_DLL PointGFp * @param workspace temp space */ BigInt monty_mult(const BigInt& x, const BigInt& y, - MemoryRegion<word>& workspace) const; + MemoryRegion<word>& workspace) const + { + BigInt result; + monty_mult(result, x, y, workspace); + return result; + } + + /** + * Montgomery multiplication/reduction + * @param z output + * @param x first multiplicand + * @param y second multiplicand + * @param workspace temp space + */ + void monty_mult(BigInt& z, + const BigInt& x, const BigInt& y, + MemoryRegion<word>& workspace) const; /** * Montgomery squaring/reduction @@ -166,7 +182,21 @@ class BOTAN_DLL PointGFp * @param workspace temp space */ BigInt monty_sqr(const BigInt& x, - MemoryRegion<word>& workspace) const; + MemoryRegion<word>& workspace) const + { + BigInt result; + monty_sqr(result, x, workspace); + return result; + } + + /** + * Montgomery squaring/reduction + * @param z output + * @param x multiplicand + * @param workspace temp space + */ + void monty_sqr(BigInt& z, const BigInt& x, + MemoryRegion<word>& workspace) const; /** * Point addition |