aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/gfpmath
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/gfpmath')
-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;
};