aboutsummaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-13 09:16:33 +0000
committerlloyd <[email protected]>2010-03-13 09:16:33 +0000
commit25f27853f11c7c676aab69a41640669193b346e9 (patch)
tree2a46fa3fcea823934149409129be496f395d35ac /src/math
parent135f1eab8a81ffce41d57441dbe09e78eb75948d (diff)
Share workspace among calls to mult2
Diffstat (limited to 'src/math')
-rw-r--r--src/math/numbertheory/point_gfp.cpp17
-rw-r--r--src/math/numbertheory/point_gfp.h2
2 files changed, 9 insertions, 10 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp
index f7433a1cc..e02b8e87e 100644
--- a/src/math/numbertheory/point_gfp.cpp
+++ b/src/math/numbertheory/point_gfp.cpp
@@ -107,7 +107,7 @@ PointGFp& PointGFp::operator+=(const PointGFp& rhs)
{
if(r.is_zero())
{
- mult2();
+ mult2(ws);
return *this;
}
@@ -154,6 +154,8 @@ PointGFp& PointGFp::operator-=(const PointGFp& rhs)
PointGFp& PointGFp::operator*=(const BigInt& scalar)
{
+ SecureVector<word> ws(2 * curve.get_p().sig_words() + 1);
+
if(scalar.abs() <= 2) // special cases for small values
{
u32bit value = scalar.abs().to_u32bit();
@@ -167,7 +169,7 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar)
}
else if(value == 2)
{
- this->mult2();
+ this->mult2(ws);
if(scalar.is_negative())
this->negate();
}
@@ -190,8 +192,8 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar)
{
u32bit twobits = scalar.get_substring(scalar_bits - i - 2, 2);
- H.mult2();
- H.mult2();
+ H.mult2(ws);
+ H.mult2(ws);
if(twobits == 3)
H += P3;
@@ -203,7 +205,7 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar)
if(scalar_bits % 2)
{
- H.mult2();
+ H.mult2(ws);
if(scalar.get_bit(0))
H += P;
}
@@ -213,7 +215,7 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar)
}
// *this *= 2
-void PointGFp::mult2()
+void PointGFp::mult2(MemoryRegion<word>& ws)
{
if(is_zero())
return;
@@ -225,8 +227,6 @@ void PointGFp::mult2()
const Modular_Reducer& mod_p = curve.mod_p();
- SecureVector<word> ws(2 * curve.get_p().sig_words() + 1);
-
BigInt y_2 = monty_mult(coord_y, coord_y, ws);
BigInt S = mod_p.reduce(4 * monty_mult(coord_x, y_2, ws));
@@ -243,7 +243,6 @@ void PointGFp::mult2()
BigInt U = mod_p.reduce(monty_mult(y_2, y_2, ws) << 3);
BigInt y = monty_mult(M, S - x, ws) - U;
-
if(y.is_negative())
y += curve.get_p();
diff --git a/src/math/numbertheory/point_gfp.h b/src/math/numbertheory/point_gfp.h
index 6172d4322..0dbd5d319 100644
--- a/src/math/numbertheory/point_gfp.h
+++ b/src/math/numbertheory/point_gfp.h
@@ -149,7 +149,7 @@ class BOTAN_DLL PointGFp
/**
* Point doubling
*/
- void mult2();
+ void mult2(MemoryRegion<word>& workspace);
CurveGFp curve;
BigInt coord_x, coord_y, coord_z;