diff --git a/src/modules/bppp/tests_impl.h b/src/modules/bppp/tests_impl.h index 6764694c..85d1c1ca 100644 --- a/src/modules/bppp/tests_impl.h +++ b/src/modules/bppp/tests_impl.h @@ -15,6 +15,7 @@ #include "bppp_transcript_impl.h" #include "test_vectors/verify.h" #include "test_vectors/prove.h" +#include "../../unit_test.h" static void test_bppp_generators_api(void) { secp256k1_bppp_generators *gens; @@ -649,15 +650,7 @@ static void norm_arg_prove_vectors(void) { #undef IDX_TO_TEST -static void run_bppp_tests(void) { - test_log_exp(); - test_norm_util_helpers(); - test_serialize_two_points(); - test_bppp_generators_api(); - test_bppp_generators_fixed(); - test_bppp_tagged_hash(); - - norm_arg_verify_zero_len(); +static void norm_arg_test_all(void) { norm_arg_test(1, 1); norm_arg_test(1, 64); norm_arg_test(64, 1); @@ -665,9 +658,20 @@ static void run_bppp_tests(void) { norm_arg_test(32, 64); norm_arg_test(64, 32); norm_arg_test(64, 64); - - norm_arg_verify_vectors(); - norm_arg_prove_vectors(); } +/* --- Test registry --- */ +static const struct tf_test_entry tests_bppp[] = { + CASE1(test_log_exp), + CASE1(test_norm_util_helpers), + CASE1(test_serialize_two_points), + CASE1(test_bppp_generators_api), + CASE1(test_bppp_generators_fixed), + CASE1(test_bppp_tagged_hash), + CASE1(norm_arg_verify_zero_len), + CASE1(norm_arg_test_all), + CASE1(norm_arg_verify_vectors), + CASE1(norm_arg_prove_vectors), +}; + #endif diff --git a/src/modules/ecdsa_adaptor/tests_impl.h b/src/modules/ecdsa_adaptor/tests_impl.h index a3360223..e2293adc 100644 --- a/src/modules/ecdsa_adaptor/tests_impl.h +++ b/src/modules/ecdsa_adaptor/tests_impl.h @@ -2,6 +2,7 @@ #define SECP256K1_MODULE_ECDSA_ADAPTOR_TESTS_H #include "../../../include/secp256k1_ecdsa_adaptor.h" +#include "../../unit_test.h" static void rand_scalar(secp256k1_scalar *scalar) { unsigned char buf32[32]; @@ -27,7 +28,7 @@ static void dleq_nonce_bitflip(unsigned char **args, size_t n_flip, size_t n_byt CHECK(secp256k1_scalar_eq(&k1, &k2) == 0); } -static void dleq_tests(void) { +static void dleq_tests_internal(void) { secp256k1_scalar s, e, sk, k; secp256k1_ge gen2, p1, p2; unsigned char *args[5]; @@ -850,7 +851,7 @@ static void test_ecdsa_adaptor_api(void) { CHECK_ILLEGAL(CTX, secp256k1_ecdsa_adaptor_recover(CTX, deckey, &sig, asig, &zero_pk)); } -static void adaptor_tests(void) { +static void adaptor_tests_internal(void) { unsigned char seckey[32]; secp256k1_pubkey pubkey; unsigned char msg[32]; @@ -1050,7 +1051,7 @@ static void adaptor_tests(void) { } } -static void multi_hop_lock_tests(void) { +static void multi_hop_lock_tests_internal(void) { unsigned char seckey_a[32]; unsigned char seckey_b[32]; unsigned char pop[32]; @@ -1124,21 +1125,18 @@ static void multi_hop_lock_tests(void) { CHECK(secp256k1_memcmp_var(buf, pop, 32) == 0); } -static void run_ecdsa_adaptor_tests(void) { - int i; - run_nonce_function_ecdsa_adaptor_tests(); +/* --- Test registry --- */ +REPEAT_TEST(dleq_tests) +REPEAT_TEST(adaptor_tests) +REPEAT_TEST(multi_hop_lock_tests) - test_ecdsa_adaptor_api(); - test_ecdsa_adaptor_spec_vectors(); - for (i = 0; i < COUNT; i++) { - dleq_tests(); - } - for (i = 0; i < COUNT; i++) { - adaptor_tests(); - } - for (i = 0; i < COUNT; i++) { - multi_hop_lock_tests(); - } -} +static const struct tf_test_entry tests_ecdsa_adaptor[] = { + CASE1(run_nonce_function_ecdsa_adaptor_tests), + CASE1(test_ecdsa_adaptor_api), + CASE1(test_ecdsa_adaptor_spec_vectors), + CASE1(dleq_tests), + CASE1(adaptor_tests), + CASE1(multi_hop_lock_tests), +}; #endif /* SECP256K1_MODULE_ECDSA_ADAPTOR_TESTS_H */ diff --git a/src/modules/ecdsa_s2c/tests_impl.h b/src/modules/ecdsa_s2c/tests_impl.h index f84443f3..d13e5164 100644 --- a/src/modules/ecdsa_s2c/tests_impl.h +++ b/src/modules/ecdsa_s2c/tests_impl.h @@ -8,6 +8,7 @@ #define SECP256K1_MODULE_ECDSA_S2C_TESTS_H #include "../../../include/secp256k1_ecdsa_s2c.h" +#include "../../unit_test.h" static void test_ecdsa_s2c_tagged_hash(void) { unsigned char tag_data[] = {'s', '2', 'c', '/', 'e', 'c', 'd', 's', 'a', '/', 'd', 'a', 't', 'a'}; @@ -323,15 +324,15 @@ static void test_ecdsa_anti_exfil(void) { } } -static void run_ecdsa_s2c_tests(void) { - run_s2c_opening_test(); - test_ecdsa_s2c_tagged_hash(); - test_ecdsa_s2c_api(); - test_ecdsa_s2c_fixed_vectors(); - test_ecdsa_s2c_sign_verify(); - - test_ecdsa_anti_exfil_signer_commit(); - test_ecdsa_anti_exfil(); -} +/* --- Test registry --- */ +static const struct tf_test_entry tests_ecdsa_s2c[] = { + CASE1(run_s2c_opening_test), + CASE1(test_ecdsa_s2c_tagged_hash), + CASE1(test_ecdsa_s2c_api), + CASE1(test_ecdsa_s2c_fixed_vectors), + CASE1(test_ecdsa_s2c_sign_verify), + CASE1(test_ecdsa_anti_exfil_signer_commit), + CASE1(test_ecdsa_anti_exfil) +}; #endif /* SECP256K1_MODULE_ECDSA_S2C_TESTS_H */ diff --git a/src/modules/generator/tests_impl.h b/src/modules/generator/tests_impl.h index bd8a0d92..c9f60c0f 100644 --- a/src/modules/generator/tests_impl.h +++ b/src/modules/generator/tests_impl.h @@ -14,6 +14,7 @@ #include "../../scalar.h" #include "../../testrand.h" #include "../../util.h" +#include "../../unit_test.h" #include "../../../include/secp256k1_generator.h" @@ -228,7 +229,7 @@ static void test_pedersen_api(void) { CHECK_ILLEGAL(CTX, secp256k1_pedersen_blind_generator_blind_sum(CTX, &val, &blind_ptr, NULL, 1, 0)); } -static void test_pedersen(void) { +static void test_pedersen_internal(void) { secp256k1_pedersen_commitment commits[19]; const secp256k1_pedersen_commitment *cptr[19]; unsigned char blinds[32*19]; @@ -310,19 +311,17 @@ static void test_pedersen_commitment_fixed_vector(void) { CHECK(!secp256k1_pedersen_commitment_parse(CTX, &parse, result)); } +/* --- Test registry --- */ +REPEAT_TEST(test_pedersen) -static void run_generator_tests(void) { - int i; - - test_shallue_van_de_woestijne(); - test_generator_fixed_vector(); - test_generator_api(); - test_generator_generate(); - test_pedersen_api(); - test_pedersen_commitment_fixed_vector(); - for (i = 0; i < COUNT / 2 + 1; i++) { - test_pedersen(); - } -} +static const struct tf_test_entry tests_generator[] = { + CASE1(test_shallue_van_de_woestijne), + CASE1(test_generator_fixed_vector), + CASE1(test_generator_api), + CASE1(test_generator_generate), + CASE1(test_pedersen), + CASE1(test_pedersen_api), + CASE1(test_pedersen_commitment_fixed_vector), +}; #endif diff --git a/src/modules/rangeproof/tests_impl.h b/src/modules/rangeproof/tests_impl.h index e0686f90..74d9f3fd 100644 --- a/src/modules/rangeproof/tests_impl.h +++ b/src/modules/rangeproof/tests_impl.h @@ -13,10 +13,11 @@ #include "../../scalar.h" #include "../../testrand.h" #include "../../util.h" +#include "../../unit_test.h" #include "../../../include/secp256k1_rangeproof.h" -static void test_rangeproof_api(void) { +static void test_rangeproof_api_internal(void) { unsigned char proof[5134]; unsigned char blind[32]; secp256k1_pedersen_commitment commit; @@ -121,7 +122,7 @@ static void test_rangeproof_api(void) { CHECK(secp256k1_rangeproof_max_size(CTX, UINT64_MAX, 0) == 5134); } -static void test_borromean(void) { +static void test_borromean_internal(void) { unsigned char e0[32]; secp256k1_scalar s[64]; secp256k1_gej pubs[64]; @@ -1346,24 +1347,25 @@ static void test_rangeproof_fixed_vectors_reproducible(void) { } } -static void run_rangeproof_tests(void) { - int i; - for (i = 0; i < COUNT; i++) { - test_rangeproof_api(); - } - +static void test_single_value_proof_all(void) { test_single_value_proof(0); test_single_value_proof(12345678); test_single_value_proof(UINT64_MAX); - - test_rangeproof_fixed_vectors(); - test_rangeproof_fixed_vectors_reproducible(); - for (i = 0; i < COUNT / 2 + 1; i++) { - test_borromean(); - } - test_rangeproof(); - test_rangeproof_null_blinder(); - test_multiple_generators(); } +/* --- Test registry --- */ +REPEAT_TEST(test_rangeproof_api) +REPEAT_TEST(test_borromean) + +static const struct tf_test_entry tests_rangeproof[] = { + CASE1(test_rangeproof_api), + CASE1(test_single_value_proof_all), + CASE1(test_rangeproof_fixed_vectors), + CASE1(test_rangeproof_fixed_vectors_reproducible), + CASE1(test_borromean), + CASE1(test_rangeproof), + CASE1(test_rangeproof_null_blinder), + CASE1(test_multiple_generators), +}; + #endif diff --git a/src/modules/schnorrsig_halfagg/tests_impl.h b/src/modules/schnorrsig_halfagg/tests_impl.h index b93999b6..29d39b2c 100644 --- a/src/modules/schnorrsig_halfagg/tests_impl.h +++ b/src/modules/schnorrsig_halfagg/tests_impl.h @@ -2,6 +2,7 @@ #define SECP256K1_MODULE_SCHNORRSIG_HALFAGG_TESTS_H #include "../../../include/secp256k1_schnorrsig_halfagg.h" +#include "../../unit_test.h" #define N_MAX 50 @@ -34,7 +35,7 @@ void test_schnorrsig_aggregate_input_helper(secp256k1_xonly_pubkey *pubkeys, uns * aggregate some of them in one shot, and then * aggregate the others incrementally to the already aggregated ones. * The aggregate signature should verify after both steps. */ -void test_schnorrsig_aggregate(void) { +void test_schnorrsig_aggregate_internal(void) { secp256k1_xonly_pubkey pubkeys[N_MAX]; unsigned char msgs32[N_MAX*32]; unsigned char sigs64[N_MAX*64]; @@ -165,7 +166,7 @@ void test_schnorrsig_aggverify_spec_vectors(void) { } } -static void test_schnorrsig_aggregate_api(void) { +static void test_schnorrsig_aggregate_api_internal(void) { size_t n = testrand_int(N_MAX + 1); size_t n_initial = testrand_int(n + 1); size_t n_new = n - n_initial; @@ -241,7 +242,7 @@ static void test_schnorrsig_aggregate_api(void) { /* In this test, we make sure that trivial attempts to break * the security of verification do not work. */ -static void test_schnorrsig_aggregate_unforge(void) { +static void test_schnorrsig_aggregate_unforge_internal(void) { secp256k1_xonly_pubkey pubkeys[N_MAX]; unsigned char msgs32[N_MAX*32]; unsigned char sigs64[N_MAX*64]; @@ -297,7 +298,7 @@ static void test_schnorrsig_aggregate_unforge(void) { /* In this test, we make sure that the algorithms properly reject * for overflowing and non parseable values. */ -static void test_schnorrsig_aggregate_overflow(void) { +static void test_schnorrsig_aggregate_overflow_internal(void) { secp256k1_xonly_pubkey pubkeys[N_MAX]; unsigned char msgs32[N_MAX*32]; unsigned char sigs64[N_MAX*64]; @@ -317,19 +318,20 @@ static void test_schnorrsig_aggregate_overflow(void) { } } -static void run_schnorrsig_halfagg_tests(void) { - int i; +/* --- Test registry --- */ +REPEAT_TEST(test_schnorrsig_aggregate) +REPEAT_TEST(test_schnorrsig_aggregate_api) +REPEAT_TEST(test_schnorrsig_aggregate_unforge) +REPEAT_TEST(test_schnorrsig_aggregate_overflow) - test_schnorrsig_sha256_tagged_aggregate(); - test_schnorrsig_aggverify_spec_vectors(); - - for (i = 0; i < COUNT; i++) { - test_schnorrsig_aggregate(); - test_schnorrsig_aggregate_api(); - test_schnorrsig_aggregate_unforge(); - test_schnorrsig_aggregate_overflow(); - } -} +static const struct tf_test_entry tests_schnorrsig_halfagg[] = { + CASE1(test_schnorrsig_sha256_tagged_aggregate), + CASE1(test_schnorrsig_aggverify_spec_vectors), + CASE1(test_schnorrsig_aggregate), + CASE1(test_schnorrsig_aggregate_api), + CASE1(test_schnorrsig_aggregate_unforge), + CASE1(test_schnorrsig_aggregate_overflow), +}; #undef N_MAX diff --git a/src/modules/surjection/tests_impl.h b/src/modules/surjection/tests_impl.h index e609d170..731e2fd4 100644 --- a/src/modules/surjection/tests_impl.h +++ b/src/modules/surjection/tests_impl.h @@ -9,6 +9,7 @@ #include "../../testrand.h" #include "../../group.h" +#include "../../unit_test.h" #include "../../../include/secp256k1_generator.h" #include "../../../include/secp256k1_rangeproof.h" #include "../../../include/secp256k1_surjectionproof.h" @@ -627,22 +628,29 @@ static void test_fixed_vectors(void) { CHECK(!secp256k1_surjectionproof_parse(CTX, &proof, bad, total5_used3_len)); } -static void run_surjection_tests(void) { - test_surjectionproof_api(); - test_input_eq_output(); - test_fixed_vectors(); - +static void test_input_selection_all(void) { test_input_selection(0); test_input_selection(1); test_input_selection(5); test_input_selection(SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS); - - test_input_selection_distribution(); - test_gen_verify(10, 3); - test_gen_verify(SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS, SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS); - test_no_used_inputs_verify(); - test_bad_serialize(); - test_bad_parse(); } +static void test_gen_verify_all(void) { + test_gen_verify(10, 3); + test_gen_verify(SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS, SECP256K1_SURJECTIONPROOF_MAX_USED_INPUTS); +} + +/* --- Test registry --- */ +static const struct tf_test_entry tests_surjection[] = { + CASE1(test_surjectionproof_api), + CASE1(test_input_eq_output), + CASE1(test_fixed_vectors), + CASE1(test_input_selection_all), + CASE1(test_input_selection_distribution), + CASE1(test_gen_verify_all), + CASE1(test_no_used_inputs_verify), + CASE1(test_bad_serialize), + CASE1(test_bad_parse), +}; + #endif diff --git a/src/modules/whitelist/tests_impl.h b/src/modules/whitelist/tests_impl.h index 38f91e18..9cbb8287 100644 --- a/src/modules/whitelist/tests_impl.h +++ b/src/modules/whitelist/tests_impl.h @@ -8,6 +8,7 @@ #define SECP256K1_MODULE_WHITELIST_TESTS_H #include "../../../include/secp256k1_whitelist.h" +#include "../../unit_test.h" static void test_whitelist_end_to_end_internal(const unsigned char *summed_seckey, const unsigned char *online_seckey, const secp256k1_pubkey *online_pubkeys, const secp256k1_pubkey *offline_pubkeys, const secp256k1_pubkey *sub_pubkey, const size_t signer_i, const size_t n_keys) { unsigned char serialized[32 + 4 + 32 * SECP256K1_WHITELIST_MAX_N_KEYS] = {0}; @@ -148,16 +149,20 @@ static void test_whitelist_bad_serialize(void) { CHECK(secp256k1_whitelist_signature_serialize(CTX, serialized, &serialized_len, &sig) == 0); } -static void run_whitelist_tests(void) { - int i; - test_whitelist_bad_parse(); - test_whitelist_bad_serialize(); - for (i = 0; i < COUNT; i++) { - test_whitelist_end_to_end(1, 1); - test_whitelist_end_to_end(10, 1); - test_whitelist_end_to_end(50, 1); - test_whitelist_end_to_end(SECP256K1_WHITELIST_MAX_N_KEYS, 0); - } +static void test_whitelist_end_to_end_all_internal(void) { + test_whitelist_end_to_end(1, 1); + test_whitelist_end_to_end(10, 1); + test_whitelist_end_to_end(50, 1); + test_whitelist_end_to_end(SECP256K1_WHITELIST_MAX_N_KEYS, 0); } +/* --- Test registry --- */ +REPEAT_TEST(test_whitelist_end_to_end_all) + +static const struct tf_test_entry tests_whitelist[] = { + CASE1(test_whitelist_bad_parse), + CASE1(test_whitelist_bad_serialize), + CASE1(test_whitelist_end_to_end_all), +}; + #endif diff --git a/src/tests.c b/src/tests.c index f7ef46fe..7c1a03f8 100644 --- a/src/tests.c +++ b/src/tests.c @@ -7982,6 +7982,31 @@ static const struct tf_test_module registry_modules[] = { #endif #ifdef ENABLE_MODULE_ELLSWIFT MAKE_TEST_MODULE(ellswift), +#endif + /* --- ZKP-SPECIFIC MODULES --- */ +#ifdef ENABLE_MODULE_SCHNORRSIG_HALFAGG + MAKE_TEST_MODULE(schnorrsig_halfagg), +#endif +#ifdef ENABLE_MODULE_BPPP + MAKE_TEST_MODULE(bppp), +#endif +#ifdef ENABLE_MODULE_GENERATOR + MAKE_TEST_MODULE(generator), +#endif +#ifdef ENABLE_MODULE_RANGEPROOF + MAKE_TEST_MODULE(rangeproof), +#endif +#ifdef ENABLE_MODULE_WHITELIST + MAKE_TEST_MODULE(whitelist), +#endif +#ifdef ENABLE_MODULE_SURJECTIONPROOF + MAKE_TEST_MODULE(surjection), +#endif +#ifdef ENABLE_MODULE_ECDSA_ADAPTOR + MAKE_TEST_MODULE(ecdsa_adaptor), +#endif +#ifdef ENABLE_MODULE_ECDSA_S2C + MAKE_TEST_MODULE(ecdsa_s2c), #endif MAKE_TEST_MODULE(utils), };