aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-02-25 19:30:50 +0000
committerlloyd <[email protected]>2010-02-25 19:30:50 +0000
commite784e695aafc47060bf62a9e92042cc56556e8c6 (patch)
treeb29a7a83c3126db0ab83e0c621d1cfdaa1e915ce
parentdbb4e78def8ad22d0ca811f632d3838e0348c7d9 (diff)
There was only one caller of set_z_to_one (which was get_z_to_one) and
only one caller of get_z_to_one (in operator*=). Inline into operator*= and remove.
-rw-r--r--src/math/gfpmath/point_gfp.cpp69
-rw-r--r--src/math/gfpmath/point_gfp.h15
2 files changed, 24 insertions, 60 deletions
diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp
index cf1e8a882..034289190 100644
--- a/src/math/gfpmath/point_gfp.cpp
+++ b/src/math/gfpmath/point_gfp.cpp
@@ -181,10 +181,31 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar)
}
if(!H.is_zero()) // cannot convert if H == O
- *this = H.get_z_to_one();
- else
- *this = H;
+ {
+ /**
+ * Convert H to an equivalent point with z == 1, thus x and y
+ * correspond to their affine coordinates
+ */
+ if(H.coord_z != 1)
+ {
+ GFpElement point_x(curve.get_p(), H.coord_x);
+ GFpElement point_y(curve.get_p(), H.coord_y);
+ GFpElement point_z(curve.get_p(), H.coord_z);
+
+ // Converts to affine coordinates
+ GFpElement z = inverse(point_z);
+ GFpElement z2 = z * z;
+ z *= z2;
+ GFpElement x = point_x * z2;
+ GFpElement y = point_y * z;
+
+ H.coord_x = x.get_value();
+ H.coord_y = y.get_value();
+ H.coord_z = 1;
+ }
+ }
+ *this = H;
return *this;
}
@@ -237,48 +258,6 @@ PointGFp& PointGFp::mult2_in_place()
return *this;
}
-/**
-* returns a point equivalent to *this but were
-* Z has value one, i.e. x and y correspond to
-* their values in affine coordinates
-*/
-PointGFp PointGFp::get_z_to_one()
- {
- return PointGFp(*this).set_z_to_one();
- }
-
-/**
-* changes the representation of *this so that
-* Z has value one, i.e. x and y correspond to
-* their values in affine coordinates.
-* returns *this.
-*/
-const PointGFp& PointGFp::set_z_to_one()
- {
- if(coord_z.is_zero())
- throw Illegal_Transformation("cannot convert 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 z2 = z * z;
- z *= z2;
- GFpElement x = point_x * z2;
- GFpElement y = point_y * z;
-
- coord_x = x.get_value();
- coord_y = y.get_value();
- coord_z = 1;
- }
-
- return *this;
- }
-
BigInt PointGFp::get_affine_x() const
{
if(is_zero())
diff --git a/src/math/gfpmath/point_gfp.h b/src/math/gfpmath/point_gfp.h
index 87cc0a3d7..a8c6e733c 100644
--- a/src/math/gfpmath/point_gfp.h
+++ b/src/math/gfpmath/point_gfp.h
@@ -165,21 +165,6 @@ class BOTAN_DLL PointGFp
*/
bool operator==(const PointGFp& other) const;
private:
- /**
- * Set z coordinate to one.
- * @return *this
- */
- const PointGFp& set_z_to_one();
-
- /**
- * Return a point
- * where the coordinates are transformed
- * so that z equals one,
- * thus x and y have just the affine values.
- * @result *this
- */
- PointGFp get_z_to_one();
-
CurveGFp curve;
BigInt coord_x, coord_y, coord_z;
};