diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2d00432..ac74a43 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,17 +20,26 @@ add_executable(bbs-test-fixtures-suite-bls12-381-shake-256 ${fixture-tests} fixt target_compile_definitions(bbs-test-fixtures-suite-bls12-381-shake-256 PUBLIC LIBBBS_TEST_SUITE_SHAKE256) add_executable(bbs-test-fixtures-suite-bls12-381-sha-256 ${fixture-tests} fixtures.c) target_compile_definitions(bbs-test-fixtures-suite-bls12-381-sha-256 PUBLIC LIBBBS_TEST_SUITE_SHA256) -#add_executable(bbs-test-fixtures ${fixture-tests} fixtures.c) target_link_libraries(bbs-test-fixtures-suite-bls12-381-sha-256 PRIVATE bbs) target_link_libraries(bbs-test-fixtures-suite-bls12-381-shake-256 PRIVATE bbs) -add_executable(bbs-test-e2e ${e2e-tests}) -target_link_libraries(bbs-test-e2e PRIVATE bbs) +add_executable(bbs-test-e2e-suite-bls12-381-sha-256 ${e2e-tests}) +target_compile_definitions(bbs-test-e2e-suite-bls12-381-sha-256 PUBLIC LIBBBS_TEST_SUITE_SHAKE256) +add_executable(bbs-test-e2e-suite-bls12-381-shake-256 ${e2e-tests}) +target_compile_definitions(bbs-test-e2e-suite-bls12-381-shake-256 PUBLIC LIBBBS_TEST_SUITE_SHAKE256) +target_link_libraries(bbs-test-e2e-suite-bls12-381-sha-256 PRIVATE bbs) +target_link_libraries(bbs-test-e2e-suite-bls12-381-shake-256 PRIVATE bbs) -add_executable(bbs-test-bench ${bench-tests}) -target_link_libraries(bbs-test-bench PRIVATE bbs) -target_compile_definitions(bbs-test-bench PUBLIC ENABLE_BENCHMARK) -add_custom_target(bench COMMAND bbs-test-bench) +add_executable(bbs-test-bench-suite-bls12-381-sha-256 ${bench-tests}) +target_link_libraries(bbs-test-bench-suite-bls12-381-sha-256 PRIVATE bbs) +target_compile_definitions(bbs-test-bench-suite-bls12-381-sha-256 PUBLIC ENABLE_BENCHMARK) +target_compile_definitions(bbs-test-bench-suite-bls12-381-sha-256 PUBLIC LIBBBS_TEST_SUITE_SHA256) +add_executable(bbs-test-bench-suite-bls12-381-shake-256 ${bench-tests}) +target_link_libraries(bbs-test-bench-suite-bls12-381-shake-256 PRIVATE bbs) +target_compile_definitions(bbs-test-bench-suite-bls12-381-shake-256 PUBLIC ENABLE_BENCHMARK) +target_compile_definitions(bbs-test-bench-suite-bls12-381-shake-256 PUBLIC LIBBBS_TEST_SUITE_SHAKE256) +# Do not automatically bench the e2e test as it has too many iterations +add_custom_target(bench COMMAND bbs-test-bench-suite-bls12-381-shake-256 bbs_bench_individual COMMAND bbs-test-bench-suite-bls12-381-sha-256 bbs_bench_individual) foreach(test ${BBS_FIX_TESTS}) get_filename_component(TName ${test} NAME_WE) @@ -44,7 +53,12 @@ endforeach() foreach(test ${BBS_E2E_TESTS}) get_filename_component(TName ${test} NAME_WE) - add_test(NAME ${TName} COMMAND bbs-test-e2e ${TName}) + add_test(NAME ${TName}-suite-bls12-381-shake-256 COMMAND bbs-test-e2e-suite-bls12-381-shake-256 ${TName}) +endforeach() + +foreach(test ${BBS_E2E_TESTS}) + get_filename_component(TName ${test} NAME_WE) + add_test(NAME ${TName}-suite-bls12-381-sha-256 COMMAND bbs-test-e2e-suite-bls12-381-sha-256 ${TName}) endforeach() #foreach(test ${BBS_BENCH_TESTS}) diff --git a/test/bbs_bench_e2e.c b/test/bbs_bench_e2e.c index a3582ae..f3650c7 100644 --- a/test/bbs_bench_e2e.c +++ b/test/bbs_bench_e2e.c @@ -14,6 +14,11 @@ bbs_bench_e2e () #define USE_HEADER 0 char msg1[MSG_LEN_END]; char msg2[MSG_LEN_END]; +#ifdef LIBBBS_TEST_SUITE_SHA256 + bbs_cipher_suite_t *suite = bbs_sha256_cipher_suite; +#elif LIBBBS_TEST_SUITE_SHAKE256 + bbs_cipher_suite_t *suite = bbs_shake256_cipher_suite; +#endif for (int j = 0; j < MSG_LEN_END; j++) { msg1[j] = (char) rand (); @@ -48,7 +53,7 @@ bbs_bench_e2e () bbs_secret_key sk; bbs_public_key pk; - if (BBS_OK != bbs_sha256_keygen_full (sk, pk)) + if (BBS_OK != bbs_keygen_full (suite, sk, pk)) { puts ("Error during key generation"); return 1; @@ -61,7 +66,7 @@ bbs_bench_e2e () static char header[] = ""; #endif - if (BBS_OK != bbs_sha256_sign (sk, pk, sig, (uint8_t*) header, + if (BBS_OK != bbs_sign (suite, sk, pk, sig, (uint8_t*) header, strlen (header), 2, msg1, msg_len, msg2, msg_len)) { @@ -69,7 +74,7 @@ bbs_bench_e2e () return 1; } - if (BBS_OK != bbs_sha256_verify (pk, sig, (uint8_t*) header, + if (BBS_OK != bbs_verify (suite, pk, sig, (uint8_t*) header, strlen (header), 2, msg1, msg_len, msg2, msg_len)) { @@ -81,7 +86,7 @@ bbs_bench_e2e () uint64_t disclosed_indexes[] = {0}; static char ph[] = "I am a challenge nonce!"; - if (BBS_OK != bbs_sha256_proof_gen (pk, sig, proof, + if (BBS_OK != bbs_proof_gen (suite, pk, sig, proof, (uint8_t*) header, strlen (header), (uint8_t*) ph, strlen (ph), disclosed_indexes, @@ -92,7 +97,7 @@ bbs_bench_e2e () return 1; } - if (BBS_OK != bbs_sha256_proof_verify (pk, proof, BBS_PROOF_LEN (1), + if (BBS_OK != bbs_proof_verify (suite, pk, proof, BBS_PROOF_LEN (1), (uint8_t*) header, strlen (header), (uint8_t*) ph, strlen (ph), @@ -108,4 +113,4 @@ bbs_bench_e2e () } return 0; -} \ No newline at end of file +} diff --git a/test/bbs_bench_individual.c b/test/bbs_bench_individual.c index 869afa3..f64fe63 100644 --- a/test/bbs_bench_individual.c +++ b/test/bbs_bench_individual.c @@ -8,14 +8,19 @@ int bbs_bench_individual () { - #define CIPHERSUITE shake256 +#ifdef LIBBBS_TEST_SUITE_SHA256 +#define CIPHERSUITE sha256 + printf ("Benchmarking %s \n", "BLS12-381-SHA-256"); +#elif LIBBBS_TEST_SUITE_SHAKE256 +#define CIPHERSUITE shake256 + printf ("Benchmarking %s \n", "BLS12-381-SHAKE-256"); +#endif // Use an additional macro to ensure full expansion before concatenation #define CONCAT_INTERNAL(a, b, c) a ## _ ## b ## _ ## c #define BBS_EXECUTE(cipher_suite, function) CONCAT_INTERNAL (bbs, cipher_suite, function) #define USE_HEADER 0 - printf ("Benchmarking %s \n", TOSTRING (CIPHERSUITE)); printf ("Include header: %d \n", USE_HEADER); #define ITERATIONS 1000 diff --git a/test/bbs_e2e_sign_n_proof.c b/test/bbs_e2e_sign_n_proof.c index c26c83e..5266adc 100644 --- a/test/bbs_e2e_sign_n_proof.c +++ b/test/bbs_e2e_sign_n_proof.c @@ -5,82 +5,79 @@ int bbs_e2e_sign_n_proof () { - bbs_cipher_suite_t *cipher_suites[] = { bbs_shake256_cipher_suite, bbs_sha256_cipher_suite }; +#ifdef LIBBBS_TEST_SUITE_SHAKE256 + bbs_cipher_suite_t *suite = bbs_shake256_cipher_suite; +#elif LIBBS_TEST_SUITE_SHA256 + bbs_cipher_suite_t *suite = bbs_sha256_cipher_suite; +#endif - for (int cipher_suite_index = 0; cipher_suite_index < 2; cipher_suite_index++) + if (core_init () != RLC_OK) { - char *cipher_suite_names[] = {"SHA256", "SHAKE256"}; - bbs_cipher_suite_t *suite = cipher_suites[cipher_suite_index]; - printf("Testing cipher suite %s\n", cipher_suite_names[cipher_suite_index]); - if (core_init () != RLC_OK) - { - core_clean (); - return 1; - } - if (pc_param_set_any () != RLC_OK) - { - core_clean (); - return 1; - } - - bbs_secret_key sk; - bbs_public_key pk; + core_clean (); + return 1; + } + if (pc_param_set_any () != RLC_OK) + { + core_clean (); + return 1; + } - BBS_BENCH_START (keygen) - if (BBS_OK != bbs_keygen_full (suite, sk, pk)) - { - puts ("Error during key generation"); - return 1; - } - BBS_BENCH_END (keygen, "bbs_keygen_full") + bbs_secret_key sk; + bbs_public_key pk; - bbs_signature sig; - static char msg1[] = "I am a message"; - static char msg2[] = "And so am I. Crazy..."; - static char header[] = "But I am a header!"; + BBS_BENCH_START (keygen) + if (BBS_OK != bbs_keygen_full (suite, sk, pk)) + { + puts ("Error during key generation"); + return 1; + } + BBS_BENCH_END (keygen, "bbs_keygen_full") - BBS_BENCH_START (sign) - if (BBS_OK != bbs_sign (suite, sk, pk, sig, (uint8_t*) header, strlen (header), 2, msg1, - strlen (msg1), msg2, strlen (msg2))) - { - puts ("Error during signing"); - return 1; - } - BBS_BENCH_END (sign, "bbs_sign (2 messages, 1 header)") + bbs_signature sig; + static char msg1[] = "I am a message"; + static char msg2[] = "And so am I. Crazy..."; + static char header[] = "But I am a header!"; - BBS_BENCH_START (verify) - if (BBS_OK != bbs_verify (suite, pk, sig, (uint8_t*) header, strlen (header), 2, msg1, - strlen (msg1), msg2, strlen (msg2))) - { - puts ("Error during signature verification"); - return 1; - } - BBS_BENCH_END (verify, "bbs_verify (2 messages, 1 header)") + BBS_BENCH_START (sign) + if (BBS_OK != bbs_sign (suite, sk, pk, sig, (uint8_t*) header, strlen (header), 2, msg1, + strlen (msg1), msg2, strlen (msg2))) + { + puts ("Error during signing"); + return 1; + } + BBS_BENCH_END (sign, "bbs_sign (2 messages, 1 header)") - uint8_t proof[BBS_PROOF_LEN (1)]; - uint64_t disclosed_indexes[] = {0}; - static char ph[] = "I am a challenge nonce!"; + BBS_BENCH_START (verify) + if (BBS_OK != bbs_verify (suite, pk, sig, (uint8_t*) header, strlen (header), 2, msg1, + strlen (msg1), msg2, strlen (msg2))) + { + puts ("Error during signature verification"); + return 1; + } + BBS_BENCH_END (verify, "bbs_verify (2 messages, 1 header)") - BBS_BENCH_START (proof_gen) - if (BBS_OK != bbs_proof_gen(suite, pk, sig, proof, (uint8_t*) header, strlen (header), - (uint8_t*) ph, strlen (ph), disclosed_indexes, 1, 2, - msg1, strlen (msg1), msg2, strlen (msg2))) - { - puts ("Error during proof generation"); - return 1; - } - BBS_BENCH_END (proof_gen, "bbs_proof_gen (2 messages, 1 header, 1 disclosed index)") + uint8_t proof[BBS_PROOF_LEN (1)]; + uint64_t disclosed_indexes[] = {0}; + static char ph[] = "I am a challenge nonce!"; - BBS_BENCH_START (proof_verify) - if (BBS_OK != bbs_proof_verify(suite, pk, proof, BBS_PROOF_LEN (1), (uint8_t*) header, - strlen (header), (uint8_t*) ph, strlen (ph), - disclosed_indexes, 1, 2, msg1, strlen (msg1))) - { - puts ("Error during proof verification"); - return 1; - } - BBS_BENCH_END (proof_verify, "bbs_proof_verify (2 messages, 1 header, 1 disclosed index)") + BBS_BENCH_START (proof_gen) + if (BBS_OK != bbs_proof_gen(suite, pk, sig, proof, (uint8_t*) header, strlen (header), + (uint8_t*) ph, strlen (ph), disclosed_indexes, 1, 2, + msg1, strlen (msg1), msg2, strlen (msg2))) + { + puts ("Error during proof generation"); + return 1; + } + BBS_BENCH_END (proof_gen, "bbs_proof_gen (2 messages, 1 header, 1 disclosed index)") + BBS_BENCH_START (proof_verify) + if (BBS_OK != bbs_proof_verify(suite, pk, proof, BBS_PROOF_LEN (1), (uint8_t*) header, + strlen (header), (uint8_t*) ph, strlen (ph), + disclosed_indexes, 1, 2, msg1, strlen (msg1))) + { + puts ("Error during proof verification"); + return 1; } + BBS_BENCH_END (proof_verify, "bbs_proof_verify (2 messages, 1 header, 1 disclosed index)") return 0; }