diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/math/numbertheory/point_gfp.cpp | 44 | ||||
-rw-r--r-- | src/math/numbertheory/point_gfp.h | 42 |
2 files changed, 35 insertions, 51 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp index 53e1d2ac7..bed08eb39 100644 --- a/src/math/numbertheory/point_gfp.cpp +++ b/src/math/numbertheory/point_gfp.cpp @@ -164,14 +164,6 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar) return *this; } -PointGFp& PointGFp::negate() - { - if(!is_zero()) - coord_y = curve.get_p() - coord_y; - - return *this; - } - // *this *= 2 void PointGFp::mult2() { @@ -229,12 +221,6 @@ BigInt PointGFp::get_affine_y() const return mod_p.multiply(coord_y, inverse_mod(z3, curve.get_p())); } -// Is this the point at infinity? -bool PointGFp::is_zero() const - { - return(coord_x.is_zero() && coord_z.is_zero()); - } - void PointGFp::check_invariants() const { /* @@ -288,36 +274,6 @@ bool PointGFp::operator==(const PointGFp& other) const get_curve() == other.get_curve()); } -// arithmetic operators -PointGFp operator+(const PointGFp& lhs, PointGFp const& rhs) - { - PointGFp tmp(lhs); - return tmp += rhs; - } - -PointGFp operator-(const PointGFp& lhs, PointGFp const& rhs) - { - PointGFp tmp(lhs); - return tmp -= rhs; - } - -PointGFp operator-(const PointGFp& lhs) - { - return PointGFp(lhs).negate(); - } - -PointGFp operator*(const BigInt& scalar, const PointGFp& point) - { - PointGFp result(point); - return result *= scalar; - } - -PointGFp operator*(const PointGFp& point, const BigInt& scalar) - { - PointGFp result(point); - return result *= scalar; - } - // encoding and decoding SecureVector<byte> EC2OSP(const PointGFp& point, byte format) { diff --git a/src/math/numbertheory/point_gfp.h b/src/math/numbertheory/point_gfp.h index 3596fe129..3bb763d44 100644 --- a/src/math/numbertheory/point_gfp.h +++ b/src/math/numbertheory/point_gfp.h @@ -103,7 +103,12 @@ class BOTAN_DLL PointGFp * Negate this point * @return *this */ - PointGFp& negate(); + PointGFp& negate() + { + if(!is_zero()) + coord_y = curve.get_p() - coord_y; + return *this; + } /** * Return base curve of this point @@ -145,7 +150,8 @@ class BOTAN_DLL PointGFp * Is this the point at infinity? * @result true, if this point is at infinity, false otherwise. */ - bool is_zero() const; + bool is_zero() const + { return (coord_x.is_zero() && coord_z.is_zero()); } /** * Checks whether the point is to be found on the underlying curve. @@ -182,12 +188,34 @@ inline bool operator!=(const PointGFp& lhs, const PointGFp& rhs) } // arithmetic operators -PointGFp BOTAN_DLL operator+(const PointGFp& lhs, const PointGFp& rhs); -PointGFp BOTAN_DLL operator-(const PointGFp& lhs, const PointGFp& rhs); -PointGFp BOTAN_DLL operator-(const PointGFp& lhs); +inline PointGFp operator-(const PointGFp& lhs) + { + return PointGFp(lhs).negate(); + } -PointGFp BOTAN_DLL operator*(const BigInt& scalar, const PointGFp& point); -PointGFp BOTAN_DLL operator*(const PointGFp& point, const BigInt& scalar); +inline PointGFp operator+(const PointGFp& lhs, const PointGFp& rhs) + { + PointGFp tmp(lhs); + return tmp += rhs; + } + +inline PointGFp operator-(const PointGFp& lhs, const PointGFp& rhs) + { + PointGFp tmp(lhs); + return tmp -= rhs; + } + +inline PointGFp operator*(const BigInt& scalar, const PointGFp& point) + { + PointGFp result(point); + return result *= scalar; + } + +inline PointGFp operator*(const PointGFp& point, const BigInt& scalar) + { + PointGFp result(point); + return result *= scalar; + } // encoding and decoding SecureVector<byte> BOTAN_DLL EC2OSP(const PointGFp& point, byte format); |