diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/data/pubkey/ecc.vec | 21 | ||||
-rw-r--r-- | src/tests/test_ecdsa.cpp | 48 | ||||
-rw-r--r-- | src/tests/tests.cpp | 1 | ||||
-rw-r--r-- | src/tests/tests.h | 1 | ||||
-rw-r--r-- | src/tests/unit_ecc.cpp | 80 |
5 files changed, 148 insertions, 3 deletions
diff --git a/src/tests/data/pubkey/ecc.vec b/src/tests/data/pubkey/ecc.vec new file mode 100644 index 000000000..887d27ba5 --- /dev/null +++ b/src/tests/data/pubkey/ecc.vec @@ -0,0 +1,21 @@ + +Group = secp256k1 +m = 0xAA5E28D6A97A2479A65527F7290311A3624D4CC0FA1578598EE3C2613BF99522 +X = 0x34F9460F0E4F08393D192B3C5133A6BA099AA0AD9FD54EBCCFACDFA239FF49C6 +Y = 0x0B71EA9BD730FD8923F6D25A7A91E7DD7728A960686CB5A901BB419E0F2CA232 + +m = 0x7E2B897B8CEBC6361663AD410835639826D590F393D90A9538881735256DFAE3 +X = 0xD74BF844B0862475103D96A611CF2D898447E288D34B360BC885CB8CE7C00575 +Y = 0x131C670D414C4546B88AC3FF664611B1C38CEB1C21D76369D7A7A0969D61D97D + +m = 0x6461E6DF0FE7DFD05329F41BF771B86578143D4DD1F7866FB4CA7E97C5FA945D +X = 0xE8AECC370AEDD953483719A116711963CE201AC3EB21D3F3257BB48668C6A72F +Y = 0xC25CAF2F0EBA1DDB2F0F3F47866299EF907867B7D27E95B3873BF98397B24EE1 + +m = 0x376A3A2CDCD12581EFFF13EE4AD44C4044B8A0524C42422A7E1E181E4DEECCEC +X = 0x14890E61FCD4B0BD92E5B36C81372CA6FED471EF3AA60A3E415EE4FE987DABA1 +Y = 0x297B858D9F752AB42D3BCA67EE0EB6DCD1C2B7B0DBE23397E66ADC272263F982 + +m = 0x1B22644A7BE026548810C378D0B2994EEFA6D2B9881803CB02CEFF865287D1B9 +X = 0xF73C65EAD01C5126F28F442D087689BFA08E12763E0CEC1D35B01751FD735ED3 +Y = 0xF449A8376906482A84ED01479BD18882B919C140D638307F0C0934BA12590BDE diff --git a/src/tests/test_ecdsa.cpp b/src/tests/test_ecdsa.cpp index f9e83f117..9b256bf9c 100644 --- a/src/tests/test_ecdsa.cpp +++ b/src/tests/test_ecdsa.cpp @@ -34,9 +34,57 @@ size_t ecdsa_sig_kat(const std::string& group_id, return validate_signature(verify, sign, "DSA/" + hash, msg, rng, nonce, signature); } +size_t ecc_point_mul(const std::string& group_id, + const std::string& m_s, + const std::string& X_s, + const std::string& Y_s) + { + EC_Group group(OIDS::lookup(group_id)); + + const BigInt m(m_s); + const BigInt X(X_s); + const BigInt Y(Y_s); + + PointGFp p = group.get_base_point() * m; + + size_t fails = 0; + + if(p.get_affine_x() != X) + { + std::cout << p.get_affine_x() << " != " << X << "\n"; + ++fails; + } + + if(p.get_affine_y() != Y) + { + std::cout << p.get_affine_y() << " != " << Y << "\n"; + ++fails; + } + + return fails; + } + } + #endif +size_t test_ecc_pointmul() + { + size_t fails = 0; + +#if defined(BOTAN_HAS_ECC_GROUP) + std::ifstream ecc_mul(PK_TEST_DATA_DIR "/ecc.vec"); + + fails += run_tests_bb(ecc_mul, "ECC Point Mult", "Y", false, + [](std::map<std::string, std::string> m) -> size_t + { + return ecc_point_mul(m["Group"], m["m"], m["X"], m["Y"]); + }); +#endif + + return fails; + } + size_t test_ecdsa() { size_t fails = 0; diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 20aaa32d2..e7143430a 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -258,6 +258,7 @@ int main(int argc, char* argv[]) DEF_TEST(dh); DEF_TEST(dlies); DEF_TEST(elgamal); + DEF_TEST(ecc_pointmul); DEF_TEST(ecdsa); DEF_TEST(gost_3410); diff --git a/src/tests/tests.h b/src/tests/tests.h index 850a973c1..6763368d0 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -64,6 +64,7 @@ size_t test_nr(); size_t test_dh(); size_t test_dlies(); size_t test_elgamal(); +size_t test_ecc_pointmul(); size_t test_ecdsa(); size_t test_gost_3410(); diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp index 666802a89..9153ba1b9 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -22,8 +22,8 @@ using namespace Botan; -#define CHECK_MESSAGE(expr, print) try { if(!(expr)) { ++fails; std::cout << print << "\n"; }} catch(std::exception& e) { std::cout << __FUNCTION__ << ": " << e.what() << "\n"; } -#define CHECK(expr) try { if(!(expr)) { ++fails; std::cout << #expr << "\n"; } } catch(std::exception& e) { std::cout << __FUNCTION__ << ": " << e.what() << "\n"; } +#define CHECK_MESSAGE(expr, print) try { if(!(expr)) { ++fails; std::cout << "FAILURE: " << print << "\n"; }} catch(std::exception& e) { std::cout << __FUNCTION__ << ": " << e.what() << "\n"; } +#define CHECK(expr) try { if(!(expr)) { ++fails; std::cout << "FAILURE: " << #expr << "\n"; } } catch(std::exception& e) { std::cout << __FUNCTION__ << ": " << e.what() << "\n"; } namespace { @@ -807,9 +807,81 @@ size_t test_curve_cp_ctor() return 0; } -} +size_t randomized_test(RandomNumberGenerator& rng, const EC_Group& group) + { + const BigInt a = BigInt::random_integer(rng, 2, group.get_order()); + const BigInt b = BigInt::random_integer(rng, 2, group.get_order()); + const BigInt c = a + b; + + PointGFp P = group.get_base_point() * a; + PointGFp Q = group.get_base_point() * b; + PointGFp R = group.get_base_point() * c; + + PointGFp A1 = P + Q; + PointGFp A2 = Q + P; + + size_t fails = 0; + + CHECK(A1 == R); + CHECK(A2 == R); + + return fails; + } + +size_t randomized_test() + { + AutoSeeded_RNG rng; + size_t fails = 0; + + const std::vector<std::string> groups = { + "brainpool160r1", + "brainpool192r1", + "brainpool224r1", + "brainpool256r1", + "brainpool320r1", + "brainpool384r1", + "brainpool512r1", + "gost_256A", + "gost_256A", + "secp112r1", + "secp112r2", + "secp128r1", + "secp128r2", + "secp160k1", + "secp160r1", + "secp160r2", + "secp192k1", + "secp192r1", + "secp224k1", + "secp224r1", + "secp256k1", + "secp256r1", + "secp384r1", + "secp521r1", + "x962_p192v2", + "x962_p192v3", + "x962_p239v1", + "x962_p239v2", + "x962_p239v3" + }; + + for(auto&& group_name : groups) + { + EC_Group group(group_name); + + PointGFp inf = group.get_base_point() * group.get_order(); + CHECK(inf.is_zero()); + + for(size_t i = 0; i != 32; ++i) + fails += randomized_test(rng, group); + } + + return fails; + } #endif +} + size_t test_ecc_unit() { size_t fails = 0; @@ -839,6 +911,8 @@ size_t test_ecc_unit() fails += test_point_swap(); fails += test_mult_sec_mass(); fails += test_curve_cp_ctor(); + fails += randomized_test(); + test_report("ECC", 0, fails); #endif |