aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/math/gfpmath/gfp_element.cpp1
-rw-r--r--src/math/gfpmath/point_gfp.cpp83
-rw-r--r--src/math/gfpmath/point_gfp.h5
-rw-r--r--src/pubkey/ec_dompar/ec_dompar.h2
4 files changed, 56 insertions, 35 deletions
diff --git a/src/math/gfpmath/gfp_element.cpp b/src/math/gfpmath/gfp_element.cpp
index fbc2021e9..bd86c6f3e 100644
--- a/src/math/gfpmath/gfp_element.cpp
+++ b/src/math/gfpmath/gfp_element.cpp
@@ -2,6 +2,7 @@
* Arithmetic for prime fields GF(p)
*
* (C) 2007 Martin Doering, Christoph Ludwig, Falko Strenzke
+* 2008-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp
index b8fe3351b..fbe5d5406 100644
--- a/src/math/gfpmath/point_gfp.cpp
+++ b/src/math/gfpmath/point_gfp.cpp
@@ -8,6 +8,7 @@
*/
#include <botan/point_gfp.h>
+#include <botan/gfp_element.h>
#include <botan/numthry.h>
namespace Botan {
@@ -81,19 +82,27 @@ PointGFp& PointGFp::operator+=(const PointGFp& rhs)
return *this;
}
- GFpElement U1 = point_x();
- GFpElement S1 = point_y();
+ GFpElement point_x(curve.get_p(), coord_x);
+ GFpElement point_y(curve.get_p(), coord_y);
+ GFpElement point_z(curve.get_p(), coord_z);
- GFpElement rhs_z2 = rhs.point_z() * rhs.point_z();
+ GFpElement rhs_point_x(curve.get_p(), rhs.coord_x);
+ GFpElement rhs_point_y(curve.get_p(), rhs.coord_y);
+ GFpElement rhs_point_z(curve.get_p(), rhs.coord_z);
+
+ GFpElement U1 = point_x;
+ GFpElement S1 = point_y;
+
+ GFpElement rhs_z2 = rhs_point_z * rhs_point_z;
U1 *= rhs_z2;
- S1 *= rhs_z2 * rhs.point_z();
+ S1 *= rhs_z2 * rhs_point_z;
- GFpElement U2 = rhs.point_x();
- GFpElement S2 = rhs.point_y();
+ GFpElement U2 = rhs_point_x;
+ GFpElement S2 = rhs_point_y;
- GFpElement lhs_z2 = point_z() * point_z();
+ GFpElement lhs_z2 = point_z * point_z;
U2 *= lhs_z2;
- S2 *= lhs_z2 * point_z();
+ S2 *= lhs_z2 * point_z;
GFpElement H(U2 - U1);
GFpElement r(S2 - S1);
@@ -122,7 +131,7 @@ PointGFp& PointGFp::operator+=(const PointGFp& rhs)
GFpElement y(r * (U2-x) - z);
- z = (point_z() * rhs.point_z()) * H;
+ z = (point_z * rhs_point_z) * H;
coord_x = x.get_value();
coord_y = y.get_value();
@@ -201,9 +210,13 @@ PointGFp& PointGFp::mult2_in_place()
return *this;
}
- GFpElement Y_squared = point_y()*point_y();
+ GFpElement point_x(curve.get_p(), coord_x);
+ GFpElement point_y(curve.get_p(), coord_y);
+ GFpElement point_z(curve.get_p(), coord_z);
- GFpElement S = point_x() * Y_squared;
+ GFpElement Y_squared = point_y*point_y;
+
+ GFpElement S = point_x * Y_squared;
GFpElement x = S + S;
@@ -211,11 +224,11 @@ PointGFp& PointGFp::mult2_in_place()
GFpElement a_z4(curve.get_p(), curve.get_a());
- GFpElement z2 = point_z() * point_z();
+ GFpElement z2 = point_z * point_z;
a_z4 *= z2;
a_z4 *= z2;
- GFpElement y(point_x() * point_x());
+ GFpElement y(point_x * point_x);
GFpElement M(y + y + y + a_z4);
@@ -231,7 +244,7 @@ PointGFp& PointGFp::mult2_in_place()
y = M * (S - x) - U;
- z = point_y() * point_z();
+ z = point_y * point_z;
z = z + z;
@@ -265,12 +278,16 @@ const PointGFp& PointGFp::set_z_to_one()
if(coord_z != 1)
{
+ GFpElement point_x(curve.get_p(), coord_x);
+ GFpElement point_y(curve.get_p(), coord_y);
+ GFpElement point_z(curve.get_p(), coord_z);
+
// Converts to affine coordinates
- GFpElement z = inverse(point_z());
+ GFpElement z = inverse(point_z);
GFpElement z2 = z * z;
z *= z2;
- GFpElement x = point_x() * z2;
- GFpElement y = point_y() * z;
+ GFpElement x = point_x * z2;
+ GFpElement y = point_y * z;
coord_x = x.get_value();
coord_y = y.get_value();
@@ -285,9 +302,12 @@ BigInt PointGFp::get_affine_x() const
if(is_zero())
throw Illegal_Transformation("cannot convert to affine");
- GFpElement z2 = point_z() * point_z();
+ GFpElement point_x(curve.get_p(), coord_x);
+ GFpElement point_z(curve.get_p(), coord_z);
+
+ GFpElement z2 = point_z * point_z;
z2.inverse_in_place();
- z2 *= point_x();
+ z2 *= point_x;
return z2.get_value();
}
@@ -297,9 +317,12 @@ BigInt PointGFp::get_affine_y() const
if(is_zero())
throw Illegal_Transformation("cannot convert to affine");
- GFpElement z3 = point_z() * point_z() * point_z();
+ GFpElement point_y(curve.get_p(), coord_y);
+ GFpElement point_z(curve.get_p(), coord_z);
+
+ GFpElement z3 = point_z * point_z * point_z;
z3.inverse_in_place();
- z3 *= point_y();
+ z3 *= point_y;
return z3.get_value();
}
@@ -322,13 +345,17 @@ void PointGFp::check_invariants() const
if(is_zero())
return;
- const GFpElement y2 = point_y() * point_y();
- const GFpElement x3 = point_x() * point_x() * point_x();
+ GFpElement point_x(curve.get_p(), coord_x);
+ GFpElement point_y(curve.get_p(), coord_y);
+ GFpElement point_z(curve.get_p(), coord_z);
+
+ const GFpElement y2 = point_y * point_y;
+ const GFpElement x3 = point_x * point_x * point_x;
if(coord_z == BigInt(1))
{
GFpElement ax(curve.get_p(), curve.get_a());
- ax *= point_x();
+ ax *= point_x;
GFpElement b(curve.get_p(), curve.get_b());
@@ -336,10 +363,10 @@ void PointGFp::check_invariants() const
throw Illegal_Point();
}
- GFpElement Zpow2 = point_z() * point_z();
- GFpElement Zpow3 = Zpow2 * point_z();
- GFpElement AZpow4 = Zpow3 * point_z() * GFpElement(curve.get_p(), curve.get_a());
- const GFpElement aXZ4 = AZpow4 * point_x();
+ GFpElement Zpow2 = point_z * point_z;
+ GFpElement Zpow3 = Zpow2 * point_z;
+ GFpElement AZpow4 = Zpow3 * point_z * GFpElement(curve.get_p(), curve.get_a());
+ const GFpElement aXZ4 = AZpow4 * point_x;
const GFpElement bZ6 = GFpElement(curve.get_p(), curve.get_b()) * Zpow3 * Zpow3;
if(y2 != (x3 + aXZ4 + bZ6))
diff --git a/src/math/gfpmath/point_gfp.h b/src/math/gfpmath/point_gfp.h
index 6613da2e2..9c593b5fd 100644
--- a/src/math/gfpmath/point_gfp.h
+++ b/src/math/gfpmath/point_gfp.h
@@ -11,7 +11,6 @@
#define BOTAN_POINT_GFP_H__
#include <botan/curve_gfp.h>
-#include <botan/gfp_element.h>
#include <vector>
namespace Botan {
@@ -174,10 +173,6 @@ class BOTAN_DLL PointGFp
*/
bool operator==(const PointGFp& other) const;
private:
- GFpElement point_x() const { return GFpElement(curve.get_p(), coord_x); }
- GFpElement point_y() const { return GFpElement(curve.get_p(), coord_y); }
- GFpElement point_z() const { return GFpElement(curve.get_p(), coord_z); }
-
CurveGFp curve;
BigInt coord_x, coord_y, coord_z;
};
diff --git a/src/pubkey/ec_dompar/ec_dompar.h b/src/pubkey/ec_dompar/ec_dompar.h
index 5f03f1c5f..f5f573ba9 100644
--- a/src/pubkey/ec_dompar/ec_dompar.h
+++ b/src/pubkey/ec_dompar/ec_dompar.h
@@ -11,9 +11,7 @@
#define BOTAN_ECC_DOMAIN_PARAMETERS_H__
#include <botan/point_gfp.h>
-#include <botan/gfp_element.h>
#include <botan/curve_gfp.h>
-#include <botan/bigint.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/alg_id.h>