aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/gfpmath
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-02-25 20:23:53 +0000
committerlloyd <[email protected]>2010-02-25 20:23:53 +0000
commitaf032a6d4ddca89f8b33b41bffcfa1a62b92c73e (patch)
tree912cb663043d417075ccba87dedeb0fd3646cd21 /src/math/gfpmath
parent790bf7561888953c34b2f5264a326bdb46b1174a (diff)
Remove GFpElement from check_invariants, remove include
Diffstat (limited to 'src/math/gfpmath')
-rw-r--r--src/math/gfpmath/point_gfp.cpp35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp
index 42ad7ef51..dc55e2fa6 100644
--- a/src/math/gfpmath/point_gfp.cpp
+++ b/src/math/gfpmath/point_gfp.cpp
@@ -8,7 +8,6 @@
*/
#include <botan/point_gfp.h>
-#include <botan/gfp_element.h>
#include <botan/numthry.h>
namespace Botan {
@@ -252,32 +251,28 @@ void PointGFp::check_invariants() const
if(is_zero())
return;
- GFpElement point_x(curve.get_p(), coord_x);
- GFpElement point_y(curve.get_p(), coord_y);
- GFpElement point_z(curve.get_p(), coord_z);
+ Modular_Reducer mod_p(curve.get_p());
+
+ BigInt y2 = mod_p.square(coord_y);
+ BigInt x3 = mod_p.multiply(coord_x, mod_p.square(coord_x));
- const GFpElement y2 = point_y * point_y;
- const GFpElement x3 = point_x * point_x * point_x;
+ BigInt ax = mod_p.multiply(coord_x, curve.get_a());
- if(coord_z == BigInt(1))
+ if(coord_z == 1)
{
- GFpElement ax(curve.get_p(), curve.get_a());
- ax *= point_x;
+ if(mod_p.reduce(x3 + ax + curve.get_b()) != y2)
+ throw Illegal_Point("Invalid ECP point: y^2 != x^3 + a*x + b");
+ }
- GFpElement b(curve.get_p(), curve.get_b());
+ BigInt z2 = mod_p.square(coord_z);
+ BigInt z3 = mod_p.multiply(coord_z, z2);
- if(y2 != (x3 + ax + b))
- throw Illegal_Point();
- }
+ BigInt ax_z4 = mod_p.multiply(mod_p.multiply(z3, coord_z), ax);
- GFpElement Zpow2 = point_z * point_z;
- GFpElement Zpow3 = Zpow2 * point_z;
- GFpElement AZpow4 = Zpow3 * point_z * GFpElement(curve.get_p(), curve.get_a());
- const GFpElement aXZ4 = AZpow4 * point_x;
- const GFpElement bZ6 = GFpElement(curve.get_p(), curve.get_b()) * Zpow3 * Zpow3;
+ BigInt b_z6 = mod_p.multiply(curve.get_b(), mod_p.square(z3));
- if(y2 != (x3 + aXZ4 + bZ6))
- throw Illegal_Point();
+ if(y2 != mod_p.reduce(x3 + ax_z4 + b_z6))
+ throw Illegal_Point("Invalid ECP point: y^2 != x^3 + a*x*z^4 + b*z^6");
}
// swaps the states of *this and other, does not throw!