diff --git a/src/gen_headers/main.py b/src/gen_headers/main.py index d2c2442..e8847f3 100644 --- a/src/gen_headers/main.py +++ b/src/gen_headers/main.py @@ -17,12 +17,27 @@ from decaf_h import decaf_h from crypto_h import crypto_h from crypto_hxx import crypto_hxx from f_field_h import f_field_h +from curve_data import curve_data root_hxx_code = "\n".join(( "#include <%s>" % name for name in sorted(gend_files) if re.match("^decaf/decaf_\d+.hxx$",name) )) +root_hxx_code += """ + +namespace decaf { + template class Run> + void run_for_all_curves() { +""" +root_hxx_code += "\n".join(( + " Run<%s>::run();" % cd["cxx_ns"] + for cd in sorted(curve_data.values(), key=lambda x:x["c_ns"]) +)) +root_hxx_code += """ + } +} +""" decaf_root_hxx = gen_file( public = True, per = "global", diff --git a/test/bench_decaf.cxx b/test/bench_decaf.cxx index e92bb8c..78b0077 100644 --- a/test/bench_decaf.cxx +++ b/test/bench_decaf.cxx @@ -387,6 +387,9 @@ static void micro() { }; /* template struct Benches */ +template struct Macro { static void run() { Benches::macro(); } }; +template struct Micro { static void run() { Benches::micro(); } }; + int main(int argc, char **argv) { bool micro = false; @@ -422,13 +425,10 @@ int main(int argc, char **argv) { strobe.encrypt_no_auth(Buffer(b1024,1024),Buffer(b1024,1024)); } - Benches::micro(); - Benches::micro(); + run_for_all_curves(); } - - Benches::macro(); - Benches::macro(); - + + run_for_all_curves(); printf("\n"); Benchmark::calib(); diff --git a/test/test_ct.cxx b/test/test_ct.cxx index 81c2f54..1b09c66 100644 --- a/test/test_ct.cxx +++ b/test/test_ct.cxx @@ -134,27 +134,21 @@ static void test_crypto() { } } -}; /* template */ +static void run() { + printf("Testing %s:\n",Group::name()); + test_arithmetic(); + test_elligator(); + test_ec(); + test_cfrg(); + test_crypto(); + printf("\n"); +} + +}; /* template struct Tests */ int main(int argc, char **argv) { (void) argc; (void) argv; - VALGRIND_MAKE_MEM_UNDEFINED(undef_str, strlen(undef_str)); - - printf("Testing %s:\n",IsoEd25519::name()); - Tests::test_arithmetic(); - Tests::test_elligator(); - Tests::test_ec(); - Tests::test_cfrg(); - Tests::test_crypto(); - - printf("\n"); - printf("Testing %s:\n", Ed448Goldilocks::name()); - Tests::test_arithmetic(); - Tests::test_elligator(); - Tests::test_ec(); - Tests::test_cfrg(); - Tests::test_crypto(); - + run_for_all_curves(); return 0; } diff --git a/test/test_decaf.cxx b/test/test_decaf.cxx index 295e281..96bf2b4 100644 --- a/test/test_decaf.cxx +++ b/test/test_decaf.cxx @@ -489,6 +489,20 @@ static void test_cfrg_vectors() { } } + +static void run() { + printf("Testing %s:\n",Group::name()); + test_arithmetic(); + test_elligator(); + test_ec(); + test_cfrg_crypto(); + test_cfrg_vectors(); + test_crypto(); + printf("\n"); +} + + + }; /* template struct Tests */ template<> const uint8_t Tests::rfc7748_1[32] = { @@ -566,30 +580,10 @@ const uint8_t elli_patho_448[56] = { }; template<> const Block Tests::elli_patho(elli_patho_448,56); template<> const Block Tests::elli_patho(NULL,0); - - int main(int argc, char **argv) { (void) argc; (void) argv; - - printf("Testing %s:\n",IsoEd25519::name()); - Tests::test_arithmetic(); - Tests::test_elligator(); - Tests::test_ec(); - Tests::test_cfrg_crypto(); - Tests::test_cfrg_vectors(); - Tests::test_crypto(); - - printf("\n"); - printf("Testing %s:\n", Ed448Goldilocks::name()); - Tests::test_arithmetic(); - Tests::test_elligator(); - Tests::test_ec(); - Tests::test_cfrg_crypto(); - Tests::test_cfrg_vectors(); - Tests::test_crypto(); - + run_for_all_curves(); if (passing) printf("Passed all tests.\n"); - return passing ? 0 : 1; }