aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-02-24 21:34:50 +0000
committerlloyd <[email protected]>2010-02-24 21:34:50 +0000
commit9efa59d4322babc444601052aa79f7b3fe304fd6 (patch)
tree720fdac9668ef4313af82d7f0f4bdecd15c73b0e /checks
parentb06a941a98f49172b203914810483589cf86cc76 (diff)
Remove the montgomery optimizations from GFpElement entirely.
This makes things even slower than they were before, but will make refactoring easier. And most of the montgomery code there was duplicates of other code that already existed in the codebase. Anything useful can be pulled back out from history later if needed.
Diffstat (limited to 'checks')
-rw-r--r--checks/ec_tests.cpp31
-rw-r--r--checks/gfpmath.cpp136
2 files changed, 27 insertions, 140 deletions
diff --git a/checks/ec_tests.cpp b/checks/ec_tests.cpp
index cf63cc529..3ff13a429 100644
--- a/checks/ec_tests.cpp
+++ b/checks/ec_tests.cpp
@@ -35,17 +35,6 @@ using namespace Botan;
namespace {
-void test_point_turn_on_sp_red_mul_simple()
- {
- std::cout << "." << std::flush;
-
- // setting up expected values
- EC_Domain_Params dom_pars(get_EC_Dom_Pars_by_oid("1.3.36.3.3.2.8.1.1.5"));
- PointGFp p(dom_pars.get_base_point());
- p.turn_on_sp_red_mul();
- CHECK(p.get_affine_x().get_value() != BigInt(0));
- }
-
void test_point_turn_on_sp_red_mul()
{
std::cout << "." << std::flush;
@@ -79,8 +68,6 @@ void test_point_turn_on_sp_red_mul()
PointGFp p_G2(p_G);
- p_G2.turn_on_sp_red_mul();
-
PointGFp r2 = d * p_G2;
CHECK_MESSAGE(r1 == r2, "error with point mul after extra turn on sp red mul");
CHECK(r1.get_affine_x().get_value() != BigInt("0"));
@@ -89,16 +76,12 @@ void test_point_turn_on_sp_red_mul()
PointGFp p_r2 = r2;
p_r1.mult2_in_place(); // wird für Fehler nicht gebraucht
- p_r2.turn_on_sp_red_mul(); // 1. t_o() macht nur p_r2 kaputt
- p_r2.turn_on_sp_red_mul(); // 2. t_o() macht auch p_r1 kaputt!!!
p_r2.mult2_in_place(); // wird für Fehler nicht gebraucht
CHECK_MESSAGE(p_r1.get_affine_x() == p_r2.get_affine_x(), "error with mult2 after extra turn on sp red mul");
CHECK(p_r1.get_affine_x().get_value() != BigInt("0"));
CHECK(p_r2.get_affine_x().get_value() != BigInt("0"));
r1.mult2_in_place();
- r2.turn_on_sp_red_mul();
- r2.turn_on_sp_red_mul();
r2.mult2_in_place();
CHECK_MESSAGE(r1 == r2, "error with mult2 after extra turn on sp red mul");
@@ -110,14 +93,10 @@ void test_point_turn_on_sp_red_mul()
CHECK_MESSAGE(r1 == r2, "error with op+= after extra turn on sp red mul");
- p_G2.turn_on_sp_red_mul();
-
r1 += p_G;
r2 += p_G2;
CHECK_MESSAGE(r1 == r2, "error with op+= after extra turn on sp red mul for both operands");
- p_G2.turn_on_sp_red_mul();
- r1.turn_on_sp_red_mul();
r1 += p_G;
r2 += p_G2;
@@ -196,7 +175,6 @@ void test_point_transformation ()
PointGFp q = p;
//turn on montg.
- p.turn_on_sp_red_mul();
CHECK_MESSAGE( p.get_jac_proj_x().get_value() == q.get_jac_proj_x().get_value(), "projective_x changed while turning on montg.!");
CHECK_MESSAGE( p.get_jac_proj_y().get_value() == q.get_jac_proj_y().get_value(), "projective_y changed while turning on montg.!");
CHECK_MESSAGE( p.get_jac_proj_z().get_value() == q.get_jac_proj_z().get_value(), "projective_z changed while turning on montg.!");
@@ -956,16 +934,12 @@ void test_gfp_curve_precomp_mres()
BigInt p = curve1.get_p();
GFpElement x(p, BigInt("2304042084023"));
GFpElement a1_or = curve1.get_a();
- CHECK(!a1_or.is_trf_to_mres());
- GFpElement b1_mr = curve1.get_mres_b();
- CHECK(b1_mr.is_trf_to_mres());
+ GFpElement b1_mr = curve1.get_b();
- GFpElement a2_mr = curve2.get_mres_a();
- CHECK(a2_mr.is_trf_to_mres());
+ GFpElement a2_mr = curve2.get_a();
GFpElement b2_or = curve2.get_b();
- CHECK(!b2_or.is_trf_to_mres());
GFpElement prodA = a1_or*b1_mr;
GFpElement prodB = a2_mr*b2_or;
@@ -1142,7 +1116,6 @@ void do_ec_tests(RandomNumberGenerator& rng)
{
std::cout << "Testing ECC: " << std::flush;
- test_point_turn_on_sp_red_mul_simple();
test_point_turn_on_sp_red_mul();
test_coordinates();
test_point_transformation ();
diff --git a/checks/gfpmath.cpp b/checks/gfpmath.cpp
index 439b9be9b..18aa4f341 100644
--- a/checks/gfpmath.cpp
+++ b/checks/gfpmath.cpp
@@ -41,11 +41,6 @@ bool test_turn_on_sp_red_mul()
GFpElement a2(23,15);
GFpElement b2(23,18);
- a2.turn_on_sp_red_mul();
- a2.turn_on_sp_red_mul();
- b2.turn_on_sp_red_mul();
- b2.turn_on_sp_red_mul();
-
GFpElement c2 = a2*b2;
if(c1 != c2)
@@ -119,14 +114,10 @@ bool test_deep_montgm()
//std::string s_value_b = "3";
BigInt bi_value_b(s_value_b);
- GFpElement gfp_a_trf(bi_prime, bi_value_a, true);
- GFpElement gfp_a_ntrf(bi_prime, bi_value_a, false);
- GFpElement gfp_b_trf(bi_prime, bi_value_b, true);
- GFpElement gfp_b_ntrf(bi_prime, bi_value_b, false);
-
- //CHECK(!gfp_b_trf.is_trf_to_mres());
- gfp_b_trf.get_mres();
- gfp_a_trf.get_mres();
+ GFpElement gfp_a_trf(bi_prime, bi_value_a);
+ GFpElement gfp_a_ntrf(bi_prime, bi_value_a);
+ GFpElement gfp_b_trf(bi_prime, bi_value_b);
+ GFpElement gfp_b_ntrf(bi_prime, bi_value_b);
GFpElement c_trf(gfp_a_trf * gfp_b_trf);
GFpElement c_ntrf(gfp_a_ntrf * gfp_b_ntrf);
@@ -151,21 +142,13 @@ bool test_gfp_div_small_numbers()
std::string s_value_b = "3";
BigInt bi_value_b(s_value_b);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
- GFpElement gfp_b(bi_prime, bi_value_b, true);
- GFpElement gfp_c(bi_prime, bi_value_b, false);
-
- CHECK(!gfp_a.is_trf_to_mres());
- //convert to montgomery
- gfp_b.get_mres();
- CHECK(gfp_b.is_trf_to_mres());
- CHECK(!gfp_c.is_trf_to_mres());
+ GFpElement gfp_a(bi_prime, bi_value_a);
+ GFpElement gfp_b(bi_prime, bi_value_b);
+ GFpElement gfp_c(bi_prime, bi_value_b);
GFpElement res_div_m = gfp_a / gfp_b;
- CHECK(res_div_m.is_trf_to_mres());
GFpElement res_div_n = gfp_a / gfp_c;
- CHECK(!res_div_n.is_trf_to_mres());
CHECK_MESSAGE(res_div_n.get_value() == res_div_m.get_value(), "transformed result is not equal to untransformed result");
CHECK_MESSAGE(gfp_a.get_value() == s_value_a, "GFpElement has changed while division operation");
@@ -202,12 +185,9 @@ bool test_gfp_basics()
std::string s_value_a = "3333333333333";
BigInt bi_value_a(s_value_a);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
+ GFpElement gfp_a(bi_prime, bi_value_a);
CHECK(gfp_a.get_p() == s_prime);
CHECK(gfp_a.get_value() == s_value_a);
- CHECK(!gfp_a.is_trf_to_mres());
- gfp_a.get_mres();
- CHECK(gfp_a.is_trf_to_mres());
return pass;
}
@@ -222,8 +202,8 @@ bool test_gfp_addSubNegate()
std::string s_value_a = "3333333333333";
BigInt bi_value_a(s_value_a);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
- GFpElement gfp_b(bi_prime, bi_value_a, true);
+ GFpElement gfp_a(bi_prime, bi_value_a);
+ GFpElement gfp_b(bi_prime, bi_value_a);
gfp_b.negate();
GFpElement zero = gfp_a + gfp_b;
@@ -246,21 +226,13 @@ bool test_gfp_mult()
std::string s_value_b = "4444444444444";
BigInt bi_value_b(s_value_b);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
- GFpElement gfp_b(bi_prime, bi_value_b, true);
- GFpElement gfp_c(bi_prime, bi_value_b, false);
-
- CHECK(!gfp_a.is_trf_to_mres());
- //convert to montgomery
- gfp_b.get_mres();
- CHECK(gfp_b.is_trf_to_mres());
- CHECK(!gfp_c.is_trf_to_mres());
+ GFpElement gfp_a(bi_prime, bi_value_a);
+ GFpElement gfp_b(bi_prime, bi_value_b);
+ GFpElement gfp_c(bi_prime, bi_value_b);
GFpElement res_mult_m = gfp_a * gfp_b;
- CHECK(res_mult_m.is_trf_to_mres());
GFpElement res_mult_n = gfp_a * gfp_c;
- CHECK(!res_mult_n.is_trf_to_mres());
if(res_mult_n != res_mult_m)
std::cout << gfp_a << " * " << gfp_b << " =? "
@@ -281,21 +253,13 @@ bool test_gfp_div()
std::string s_value_b = "4444444444444";
BigInt bi_value_b(s_value_b);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
- GFpElement gfp_b(bi_prime, bi_value_b, true);
- GFpElement gfp_c(bi_prime, bi_value_b, false);
-
- CHECK(!gfp_a.is_trf_to_mres());
- //convert to montgomery
- gfp_b.get_mres();
- CHECK(gfp_b.is_trf_to_mres());
- CHECK(!gfp_c.is_trf_to_mres());
+ GFpElement gfp_a(bi_prime, bi_value_a);
+ GFpElement gfp_b(bi_prime, bi_value_b);
+ GFpElement gfp_c(bi_prime, bi_value_b);
GFpElement res_div_m = gfp_a / gfp_b;
- CHECK(res_div_m.is_trf_to_mres());
GFpElement res_div_n = gfp_a / gfp_c;
- CHECK(!res_div_n.is_trf_to_mres());
CHECK_MESSAGE(res_div_n.get_value() == res_div_m.get_value(), "transformed result is not equal to untransformed result");
CHECK_MESSAGE(gfp_a.get_value() == s_value_a, "GFpElement has changed while division operation");
@@ -322,24 +286,13 @@ bool test_gfp_add()
std::string s_value_b = "4444444444444";
BigInt bi_value_b(s_value_b);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
- GFpElement gfp_b(bi_prime, bi_value_b, true);
- GFpElement gfp_c(bi_prime, bi_value_b, true);
-
- CHECK(!gfp_a.is_trf_to_mres());
- //convert to montgomery
- gfp_b.get_mres();
- CHECK(gfp_b.is_trf_to_mres());
- CHECK(!gfp_c.is_trf_to_mres());
+ GFpElement gfp_a(bi_prime, bi_value_a);
+ GFpElement gfp_b(bi_prime, bi_value_b);
+ GFpElement gfp_c(bi_prime, bi_value_b);
GFpElement res_add_m = gfp_a + gfp_b;
- CHECK(res_add_m.is_trf_to_mres());
GFpElement res_add_n = gfp_a + gfp_c;
- // commented out by patrick, behavior is clear:
- // rhs might be transformed, lhs never
- // for now, this behavior is only intern, doesn't matter for programm function
- // CHECK_MESSAGE(res_add_n.is_trf_to_mres(), "!! Falko: NO FAIL, wrong test, please repair"); // clear: rhs might be transformed, lhs never
CHECK(res_add_n.get_value() == res_add_m.get_value());
return pass;
@@ -358,30 +311,14 @@ bool test_gfp_sub()
std::string s_value_b = "4444444444444";
BigInt bi_value_b(s_value_b);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
- GFpElement gfp_b(bi_prime, bi_value_b, true);
- GFpElement gfp_c(bi_prime, bi_value_b, true);
-
- CHECK(!gfp_a.is_trf_to_mres());
- //convert to montgomery
- gfp_b.get_mres();
- CHECK(gfp_b.is_trf_to_mres());
- CHECK(!gfp_c.is_trf_to_mres());
+ GFpElement gfp_a(bi_prime, bi_value_a);
+ GFpElement gfp_b(bi_prime, bi_value_b);
+ GFpElement gfp_c(bi_prime, bi_value_b);
GFpElement res_sub_m = gfp_b - gfp_a;
- CHECK(res_sub_m.is_trf_to_mres());
- CHECK(gfp_a.is_trf_to_mres()); // added by Falko
GFpElement res_sub_n = gfp_c - gfp_a;
- // commented out by psona, behavior is clear:
- // rhs might be transformed, lhs never
- // for now, this behavior is only intern, doesn't matter for programm function
- // CHECK_MESSAGE(!res_sub_n.is_trf_to_mres(), "!! Falko: NO FAIL, wrong test, please repair"); // falsche
- // Erwartung: a wurde durch die operation oben auch
- // ins m-residue transformiert, daher passiert das hier auch mit
- // c, und das Ergebnis ist es auch
-
CHECK(res_sub_n.get_value() == res_sub_m.get_value());
return pass;
}
@@ -399,28 +336,9 @@ bool test_more_gfp_div()
std::string s_value_b = "4444444444444";
BigInt bi_value_b(s_value_b);
- GFpElement gfp_a(bi_prime, bi_value_a, true);
- GFpElement gfp_b_trf(bi_prime, bi_value_b, true);
- GFpElement gfp_b_ntrf(bi_prime, bi_value_b, false);
-
- CHECK(!gfp_b_trf.is_trf_to_mres());
- gfp_b_trf.get_mres();
- CHECK(gfp_b_trf.is_trf_to_mres());
-
- CHECK(!gfp_a.is_trf_to_mres());
-
- bool exc_ntrf = false;
- try
- {
- gfp_b_ntrf.get_mres();
- }
- catch(Botan::Illegal_Transformation e)
- {
- exc_ntrf = true;
- }
- CHECK(exc_ntrf);
-
- CHECK(!gfp_b_ntrf.is_trf_to_mres());
+ GFpElement gfp_a(bi_prime, bi_value_a);
+ GFpElement gfp_b_trf(bi_prime, bi_value_b);
+ GFpElement gfp_b_ntrf(bi_prime, bi_value_b);
CHECK_MESSAGE(gfp_b_trf == gfp_b_ntrf, "b is not equal to itself (trf)");
@@ -502,8 +420,6 @@ bool test_inv_in_place()
BigInt mod(173);
GFpElement a1(mod, 288);
- a1.turn_on_sp_red_mul();
- a1.get_mres(); // enforce the conversion
GFpElement a1_inv(a1);
a1_inv.inverse_in_place();
@@ -529,8 +445,6 @@ bool test_op_eq()
BigInt mod(173);
GFpElement a1(mod, 299);
- a1.turn_on_sp_red_mul();
- a1.get_mres(); // enforce the conversion
GFpElement a2(mod, 288);
CHECK_MESSAGE(a1 != a2, "error with GFpElement comparison");
return pass;