aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <lloyd@randombit.net>2010-03-13 09:37:26 +0000
committerlloyd <lloyd@randombit.net>2010-03-13 09:37:26 +0000
commit0dd2c107e4ed8ec3c207d1ae9e4ef21702f9d2ba (patch)
treec2de762f4a2040f9fe4cae69770113ad194816e0 /src
parent25f27853f11c7c676aab69a41640669193b346e9 (diff)
Save workspace for addition calls inside operator*=
Diffstat (limited to 'src')
-rw-r--r--src/math/numbertheory/point_gfp.cpp43
-rw-r--r--src/math/numbertheory/point_gfp.h5
2 files changed, 28 insertions, 20 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp
index e02b8e87e..2d57b98b2 100644
--- a/src/math/numbertheory/point_gfp.cpp
+++ b/src/math/numbertheory/point_gfp.cpp
@@ -74,23 +74,20 @@ BigInt PointGFp::monty_mult(const BigInt& a, const BigInt& b,
return result;
}
-
-// arithmetic operators
-PointGFp& PointGFp::operator+=(const PointGFp& rhs)
+void PointGFp::add(const PointGFp& rhs, MemoryRegion<word>& ws)
{
- if(rhs.is_zero())
- return *this;
-
if(is_zero())
{
- *this = rhs;
- return *this;
+ coord_x = rhs.coord_x;
+ coord_y = rhs.coord_y;
+ coord_z = rhs.coord_z;
+ return;
}
+ else if(rhs.is_zero())
+ return;
const Modular_Reducer& mod_p = curve.mod_p();
- SecureVector<word> ws(2 * curve.get_p().sig_words() + 1);
-
BigInt rhs_z2 = monty_mult(rhs.coord_z, rhs.coord_z, ws);
BigInt U1 = monty_mult(coord_x, rhs_z2, ws);
BigInt S1 = monty_mult(coord_y, monty_mult(rhs.coord_z, rhs_z2, ws), ws);
@@ -108,11 +105,11 @@ PointGFp& PointGFp::operator+=(const PointGFp& rhs)
if(r.is_zero())
{
mult2(ws);
- return *this;
+ return;
}
*this = PointGFp(curve); // setting myself to zero
- return *this;
+ return;
}
U2 = monty_mult(H, H, ws);
@@ -136,7 +133,13 @@ PointGFp& PointGFp::operator+=(const PointGFp& rhs)
coord_x = x;
coord_y = y;
coord_z = z;
+ }
+// arithmetic operators
+PointGFp& PointGFp::operator+=(const PointGFp& rhs)
+ {
+ SecureVector<word> ws(2 * curve.get_p().sig_words() + 1);
+ add(rhs, ws);
return *this;
}
@@ -190,24 +193,24 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar)
for(u32bit i = 0; i < scalar_bits - 1; i += 2)
{
- u32bit twobits = scalar.get_substring(scalar_bits - i - 2, 2);
+ u32bit nibble = scalar.get_substring(scalar_bits - i - 2, 2);
H.mult2(ws);
H.mult2(ws);
- if(twobits == 3)
- H += P3;
- else if(twobits == 2)
- H += P2;
- else if(twobits == 1)
- H += P;
+ if(nibble == 3)
+ H.add(P3, ws);
+ else if(nibble == 2)
+ H.add(P2, ws);
+ else if(nibble == 1)
+ H.add(P, ws);
}
if(scalar_bits % 2)
{
H.mult2(ws);
if(scalar.get_bit(0))
- H += P;
+ H.add(P, ws);
}
*this = H;
diff --git a/src/math/numbertheory/point_gfp.h b/src/math/numbertheory/point_gfp.h
index 0dbd5d319..eaebccf49 100644
--- a/src/math/numbertheory/point_gfp.h
+++ b/src/math/numbertheory/point_gfp.h
@@ -147,6 +147,11 @@ class BOTAN_DLL PointGFp
MemoryRegion<word>& workspace);
/**
+ * Point addition
+ */
+ void add(const PointGFp& other, MemoryRegion<word>& workspace);
+
+ /**
* Point doubling
*/
void mult2(MemoryRegion<word>& workspace);