diff options
author | lloyd <[email protected]> | 2010-03-19 18:21:34 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-19 18:21:34 +0000 |
commit | 602fb0e763cfaa2caa62b3b239d021efc767d567 (patch) | |
tree | 062a11e60698bdad68ef28b21e34f964cbd41cc7 /checks | |
parent | dab16b79c89e54e9551d30dcf54ca89432932dce (diff) |
Replace PointGFp::check_invaraints, which would either return silently
or throw an exception, with PointGFp::on_the_curve, which returns a bool.
Update callers.
This showed several cases where check_invaraints was being called
multiple times, for instance when decoding a point with OS2ECP,
check_invaraints was called; many callers of OS2ECP would then call
check_invaraints again on the same object.
Diffstat (limited to 'checks')
-rw-r--r-- | checks/ec_tests.cpp | 32 | ||||
-rw-r--r-- | checks/ecdsa.cpp | 4 |
2 files changed, 20 insertions, 16 deletions
diff --git a/checks/ec_tests.cpp b/checks/ec_tests.cpp index b3111455d..9362aa371 100644 --- a/checks/ec_tests.cpp +++ b/checks/ec_tests.cpp @@ -147,7 +147,8 @@ void test_coordinates() PointGFp p0 = p_G; PointGFp p1 = p_G * 2; PointGFp point_exp(secp160r1, exp_affine_x, exp_affine_y); - point_exp.check_invariants(); + if(!point_exp.on_the_curve()) + throw Internal_Error("Point not on the curve"); CHECK_MESSAGE( p1.get_affine_x() == exp_affine_x, " p1_x = " << p1.get_affine_x() << "\n" << "exp_x = " << exp_affine_x << "\n"); CHECK_MESSAGE( p1.get_affine_y() == exp_affine_y, " p1_y = " << p1.get_affine_y() << "\n" << "exp_y = " << exp_affine_y << "\n"); @@ -246,7 +247,8 @@ void test_zeropoint() BigInt("16984103820118642236896513183038186009872590470"), BigInt("1373093393927139016463695321221277758035357890939")); - p1.check_invariants(); + if(!p1.on_the_curve()) + throw Internal_Error("Point not on the curve"); p1 -= p1; CHECK_MESSAGE( p1.is_zero(), "p - q with q = p is not zero!"); @@ -294,7 +296,8 @@ void test_calc_with_zeropoint() BigInt("16984103820118642236896513183038186009872590470"), BigInt("1373093393927139016463695321221277758035357890939")); - p.check_invariants(); + if(!p.on_the_curve()) + throw Internal_Error("Point not on the curve"); CHECK_MESSAGE( !p.is_zero(), "created is zeropoint, shouldn't be!"); PointGFp zero(curve); @@ -618,7 +621,8 @@ void test_enc_dec_uncompressed_521_prime_too_large() try { p_G = std::auto_ptr<PointGFp>(new PointGFp(OS2ECP ( sv_G_secp_uncomp, secp521r1))); - p_G->check_invariants(); + if(!p_G->on_the_curve()) + throw Internal_Error("Point not on the curve"); } catch (std::exception e) { @@ -626,11 +630,6 @@ void test_enc_dec_uncompressed_521_prime_too_large() } CHECK_MESSAGE(exc, "attempt of creation of point on curve with too high prime did not throw an exception"); - //SecureVector<byte> sv_result = EC2OSP(p_G, PointGFp::UNCOMPRESSED); - //string result = hex_encode(sv_result.begin(), sv_result.size()); - //string exp_result = hex_encode(sv_G_secp_uncomp.begin(), sv_G_secp_uncomp.size()); - - //CHECK_MESSAGE( sv_result == sv_G_secp_uncomp, "\ncalc. result = " << result << "\nexp. result = " << exp_result << "\n"); } void test_gfp_store_restore() @@ -673,7 +672,8 @@ void test_cdc_curve_33() bool exc = false; try { - p_G.check_invariants(); + if(!p_G.on_the_curve()) + throw Internal_Error("Point not on the curve"); } catch (std::exception) { @@ -698,11 +698,14 @@ void test_more_zeropoint() BigInt("16984103820118642236896513183038186009872590470"), BigInt("1373093393927139016463695321221277758035357890939")); - p1.check_invariants(); + if(!p1.on_the_curve()) + throw Internal_Error("Point not on the curve"); PointGFp minus_p1 = -p1; - minus_p1.check_invariants(); + if(!minus_p1.on_the_curve()) + throw Internal_Error("Point not on the curve"); PointGFp shouldBeZero = p1 + minus_p1; - shouldBeZero.check_invariants(); + if(!shouldBeZero.on_the_curve()) + throw Internal_Error("Point not on the curve"); BigInt y1 = p1.get_affine_y(); y1 = curve.get_p() - y1; @@ -713,7 +716,8 @@ void test_more_zeropoint() "problem with minus_p1 : y"); PointGFp zero(curve); - zero.check_invariants(); + if(!zero.on_the_curve()) + throw Internal_Error("Point not on the curve"); CHECK_MESSAGE(p1 + zero == p1, "addition of zero modified point"); CHECK_MESSAGE( shouldBeZero.is_zero(), "p - q with q = p is not zero!"); diff --git a/checks/ecdsa.cpp b/checks/ecdsa.cpp index d46ebb25e..3d2ee37f3 100644 --- a/checks/ecdsa.cpp +++ b/checks/ecdsa.cpp @@ -304,7 +304,8 @@ void test_create_and_verify(RandomNumberGenerator& rng) PointGFp p_G = OS2ECP ( sv_G_secp_comp, curve ); EC_Domain_Params dom_params(curve, p_G, bi_order_g, BigInt(1)); - p_G.check_invariants(); + if(!p_G.on_the_curve()) + throw Internal_Error("Point not on the curve"); ECDSA_PrivateKey key_odd_oid(rng, dom_params); std::string key_odd_oid_str = PKCS8::PEM_encode(key_odd_oid); @@ -359,7 +360,6 @@ void test_curve_registry(RandomNumberGenerator& rng) { OID oid(oids[i]); EC_Domain_Params dom_pars(oid); - dom_pars.get_base_point().check_invariants(); ECDSA_PrivateKey ecdsa(rng, dom_pars); PK_Signer signer(ecdsa, "EMSA1(SHA-1)"); |