diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/math/gfpmath/curve_gfp.h | 7 | ||||
-rw-r--r-- | src/math/gfpmath/point_gfp.cpp | 12 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/math/gfpmath/curve_gfp.h b/src/math/gfpmath/curve_gfp.h index cc1d42290..6010183b8 100644 --- a/src/math/gfpmath/curve_gfp.h +++ b/src/math/gfpmath/curve_gfp.h @@ -10,7 +10,7 @@ #ifndef BOTAN_GFP_CURVE_H__ #define BOTAN_GFP_CURVE_H__ -#include <botan/bigint.h> +#include <botan/numthry.h> namespace Botan { @@ -28,7 +28,7 @@ class BOTAN_DLL CurveGFp * @param b second coefficient */ CurveGFp(const BigInt& p, const BigInt& a, const BigInt& b) : - p(p), a(a), b(b) {} + p(p), a(a), b(b), reducer_p(p) {} // CurveGFp(const CurveGFp& other) = default; // CurveGFp& operator=(const CurveGFp& other) = default; @@ -51,6 +51,8 @@ class BOTAN_DLL CurveGFp */ const BigInt& get_p() const { return p; } + const Modular_Reducer& mod_p() const { return reducer_p; } + /** * swaps the states of *this and other, does not throw * @param other The curve to swap values with @@ -69,6 +71,7 @@ class BOTAN_DLL CurveGFp private: BigInt p, a, b; + Modular_Reducer reducer_p; }; inline bool operator!=(const CurveGFp& lhs, const CurveGFp& rhs) diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp index dc55e2fa6..c28b1eb62 100644 --- a/src/math/gfpmath/point_gfp.cpp +++ b/src/math/gfpmath/point_gfp.cpp @@ -50,7 +50,7 @@ PointGFp& PointGFp::operator+=(const PointGFp& rhs) return *this; } - Modular_Reducer mod_p(curve.get_p()); + const Modular_Reducer& mod_p = curve.mod_p(); BigInt rhs_z2 = mod_p.square(rhs.coord_z); BigInt U1 = mod_p.multiply(coord_x, rhs_z2); @@ -148,7 +148,7 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar) */ if(H.coord_z != 1) { - Modular_Reducer mod_p(curve.get_p()); + const Modular_Reducer& mod_p = curve.mod_p(); BigInt z_inv = inverse_mod(H.coord_z, curve.get_p()); @@ -183,7 +183,7 @@ void PointGFp::mult2_in_place() return; } - Modular_Reducer mod_p(curve.get_p()); + const Modular_Reducer& mod_p = curve.mod_p(); BigInt y_2 = mod_p.square(coord_y); @@ -216,7 +216,7 @@ BigInt PointGFp::get_affine_x() const if(is_zero()) throw Illegal_Transformation("cannot convert to affine"); - Modular_Reducer mod_p(curve.get_p()); + const Modular_Reducer& mod_p = curve.mod_p(); BigInt z2 = mod_p.square(coord_z); return mod_p.multiply(coord_x, inverse_mod(z2, curve.get_p())); @@ -227,7 +227,7 @@ BigInt PointGFp::get_affine_y() const if(is_zero()) throw Illegal_Transformation("cannot convert to affine"); - Modular_Reducer mod_p(curve.get_p()); + const Modular_Reducer& mod_p = curve.mod_p(); BigInt z3 = mod_p.multiply(coord_z, mod_p.square(coord_z)); return mod_p.multiply(coord_y, inverse_mod(z3, curve.get_p())); @@ -251,7 +251,7 @@ void PointGFp::check_invariants() const if(is_zero()) return; - Modular_Reducer mod_p(curve.get_p()); + const Modular_Reducer& mod_p = curve.mod_p(); BigInt y2 = mod_p.square(coord_y); BigInt x3 = mod_p.multiply(coord_x, mod_p.square(coord_x)); |