From 2d1dd244a6714687c97736a809e9dd31f506306c Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 25 Feb 2010 02:01:06 +0000 Subject: Convert PointGFp::get_affine_{x,y} to return just the BigInt value --- src/math/gfpmath/point_gfp.cpp | 28 +++++++++++++++++----------- src/math/gfpmath/point_gfp.h | 4 ++-- 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'src/math') diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp index e32cd14d8..f76853085 100644 --- a/src/math/gfpmath/point_gfp.cpp +++ b/src/math/gfpmath/point_gfp.cpp @@ -278,22 +278,28 @@ const PointGFp& PointGFp::set_z_to_one() return *this; } -GFpElement PointGFp::get_affine_x() const +BigInt PointGFp::get_affine_x() const { if(is_zero()) throw Illegal_Transformation("cannot convert to affine"); GFpElement z2 = mZ * mZ; - return mX * z2.inverse_in_place(); + z2.inverse_in_place(); + z2 *= mX; + + return z2.get_value(); } -GFpElement PointGFp::get_affine_y() const +BigInt PointGFp::get_affine_y() const { if(is_zero()) throw Illegal_Transformation("cannot convert to affine"); GFpElement z3 = mZ * mZ * mZ; - return mY * z3.inverse_in_place(); + z3.inverse_in_place(); + z3 *= mY; + + return z3.get_value(); } // Is this the point at infinity? @@ -385,7 +391,7 @@ PointGFp operator*(const PointGFp& point, const BigInt& scalar) SecureVector EC2OSP(const PointGFp& point, byte format) { if(format == PointGFp::UNCOMPRESSED) - return result = encode_uncompressed(point); + return encode_uncompressed(point); else if(format == PointGFp::COMPRESSED) return encode_compressed(point); else if(format == PointGFp::HYBRID) @@ -412,10 +418,10 @@ SecureVector encode_compressed(const PointGFp& point) l /= 8; SecureVector result (l+1); result[0] = 2; - BigInt x = point.get_affine_x().get_value(); + BigInt x = point.get_affine_x(); SecureVector bX = BigInt::encode_1363(x, l); result.copy(1, bX.begin(), bX.size()); - BigInt y = point.get_affine_y().get_value(); + BigInt y = point.get_affine_y(); if(y.get_bit(0)) { result[0] |= 1; @@ -440,8 +446,8 @@ SecureVector encode_uncompressed(const PointGFp& point) l /= 8; SecureVector result (2*l+1); result[0] = 4; - BigInt x = point.get_affine_x().get_value(); - BigInt y = point.get_affine_y().get_value(); + BigInt x = point.get_affine_x(); + BigInt y = point.get_affine_y(); SecureVector bX = BigInt::encode_1363(x, l); SecureVector bY = BigInt::encode_1363(y, l); result.copy(1, bX.begin(), l); @@ -467,8 +473,8 @@ SecureVector encode_hybrid(const PointGFp& point) l /= 8; SecureVector result (2*l+1); result[0] = 6; - BigInt x = point.get_affine_x().get_value(); - BigInt y = point.get_affine_y().get_value(); + BigInt x = point.get_affine_x(); + BigInt y = point.get_affine_y(); SecureVector bX = BigInt::encode_1363(x, l); SecureVector bY = BigInt::encode_1363(y, l); result.copy(1, bX.begin(), bX.size()); diff --git a/src/math/gfpmath/point_gfp.h b/src/math/gfpmath/point_gfp.h index 9c67ae53c..9f29896cb 100644 --- a/src/math/gfpmath/point_gfp.h +++ b/src/math/gfpmath/point_gfp.h @@ -121,13 +121,13 @@ class BOTAN_DLL PointGFp * get affine x coordinate * @result affine x coordinate */ - GFpElement get_affine_x() const; + BigInt get_affine_x() const; /** * get affine y coordinate * @result affine y coordinate */ - GFpElement get_affine_y() const; + BigInt get_affine_y() const; /** * get the jacobian projective x coordinate -- cgit v1.2.3