aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/math/gfpmath/point_gfp.cpp20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp
index febba412c..24aa8d8af 100644
--- a/src/math/gfpmath/point_gfp.cpp
+++ b/src/math/gfpmath/point_gfp.cpp
@@ -217,14 +217,10 @@ BigInt PointGFp::get_affine_x() const
if(is_zero())
throw Illegal_Transformation("cannot convert to affine");
- 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;
+ Modular_Reducer mod_p(curve.get_p());
- return z2.get_value();
+ BigInt z2 = mod_p.square(coord_z);
+ return mod_p.multiply(coord_x, inverse_mod(z2, curve.get_p()));
}
BigInt PointGFp::get_affine_y() const
@@ -232,14 +228,10 @@ BigInt PointGFp::get_affine_y() const
if(is_zero())
throw Illegal_Transformation("cannot convert to affine");
- 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;
+ Modular_Reducer mod_p(curve.get_p());
- return z3.get_value();
+ BigInt z3 = mod_p.multiply(coord_z, mod_p.square(coord_z));
+ return mod_p.multiply(coord_y, inverse_mod(z3, curve.get_p()));
}
// Is this the point at infinity?