From f9df59b68dc1cf8930380fb52f95a87f15c5c5c5 Mon Sep 17 00:00:00 2001 From: Stephan Schmiedmayer <56692976+StephanSchmiedmayer@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:36:43 +0200 Subject: [PATCH 1/6] Add basic benchmark --- test/CMakeLists.txt | 1 + test/bbs_e2e_bench.c | 108 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 test/bbs_e2e_bench.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8415dee..4e3c78b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,6 +12,7 @@ set(BBS_FIX_TESTS create_test_sourcelist(fixture-tests bbs-test-fixtures.c ${BBS_FIX_TESTS}) set(BBS_E2E_TESTS bbs_e2e_sign_n_proof.c) +set(BBS_BENCH_TESTS bbs_e2e_sign_n_proof.c, bbs_e2e_bench.c) create_test_sourcelist(e2e-tests bbs-test-e2e.c ${BBS_E2E_TESTS}) diff --git a/test/bbs_e2e_bench.c b/test/bbs_e2e_bench.c new file mode 100644 index 0000000..62bd9be --- /dev/null +++ b/test/bbs_e2e_bench.c @@ -0,0 +1,108 @@ +#include "fixtures.h" +#include "test_util.h" +#include + +int +bbs_e2e_bench () +{ + BBS_BENCH_START(e2e) + + 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; + + if (BBS_OK != bbs_sha256_keygen_full (sk, pk)) + { + puts ("Error during key generation"); + return 1; + } + + 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!"; + static char header[] = ""; + + if (BBS_OK != bbs_sha256_sign (sk, + pk, + sig, + (uint8_t*) header, + strlen (header), + 2, + msg1, + strlen (msg1), + msg2, + strlen (msg2))) + { + puts ("Error during signing"); + return 1; + } + + if (BBS_OK != bbs_sha256_verify (pk, + sig, + (uint8_t*) header, + strlen (header), + 2, + msg1, + strlen (msg1), + msg2, + strlen (msg2))) + { + puts ("Error during signature verification"); + return 1; + } + + uint8_t proof[BBS_PROOF_LEN (1)]; + uint64_t disclosed_indexes[] = {0}; + static char ph[] = "I am a challenge nonce!"; + + if (BBS_OK != bbs_sha256_proof_gen (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; + } + + if (BBS_OK != bbs_sha256_proof_verify (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(e2e, "bbs_e2e_sign_n_proof") + + return 0; +} \ No newline at end of file From 29826060cbceb5c8f40cc50f071cbab594507e9b Mon Sep 17 00:00:00 2001 From: Stephan Schmiedmayer <56692976+StephanSchmiedmayer@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:46:25 +0200 Subject: [PATCH 2/6] Add e2e bench testsuite --- test/CMakeLists.txt | 19 ++-- test/bbs_bench_e2e.c | 114 +++++++++++++++++++++++ test/bbs_bench_individual.c | 176 ++++++++++++++++++++++++++++++++++++ test/bbs_e2e_bench.c | 108 ---------------------- 4 files changed, 302 insertions(+), 115 deletions(-) create mode 100644 test/bbs_bench_e2e.c create mode 100644 test/bbs_bench_individual.c delete mode 100644 test/bbs_e2e_bench.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4e3c78b..bd95cde 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,12 +9,12 @@ set(BBS_FIX_TESTS bbs_fix_hash_to_scalar.c bbs_fix_expand_message.c) -create_test_sourcelist(fixture-tests bbs-test-fixtures.c ${BBS_FIX_TESTS}) - set(BBS_E2E_TESTS bbs_e2e_sign_n_proof.c) -set(BBS_BENCH_TESTS bbs_e2e_sign_n_proof.c, bbs_e2e_bench.c) +set(BBS_BENCH_TESTS bbs_bench_e2e.c bbs_bench_individual.c) +create_test_sourcelist(fixture-tests bbs-test-fixtures.c ${BBS_FIX_TESTS}) create_test_sourcelist(e2e-tests bbs-test-e2e.c ${BBS_E2E_TESTS}) +create_test_sourcelist(bench-tests bbs-test-bench.c ${BBS_BENCH_TESTS}) add_executable(bbs-test-fixtures ${fixture-tests} fixtures.c) target_link_libraries(bbs-test-fixtures PRIVATE bbs) @@ -22,10 +22,10 @@ target_link_libraries(bbs-test-fixtures PRIVATE bbs) add_executable(bbs-test-e2e ${e2e-tests}) target_link_libraries(bbs-test-e2e PRIVATE bbs) -add_executable(bbs-test-e2e-bench ${e2e-tests}) -target_link_libraries(bbs-test-e2e-bench PRIVATE bbs) -target_compile_definitions(bbs-test-e2e-bench PUBLIC ENABLE_BENCHMARK) -add_custom_target(bench COMMAND bbs-test-e2e-bench) +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) foreach(test ${BBS_FIX_TESTS}) get_filename_component(TName ${test} NAME_WE) @@ -36,3 +36,8 @@ foreach(test ${BBS_E2E_TESTS}) get_filename_component(TName ${test} NAME_WE) add_test(NAME ${TName} COMMAND bbs-test-e2e ${TName}) endforeach() + +foreach(test ${BBS_BENCH_TESTS}) + get_filename_component(TName ${test} NAME_WE) + add_test(NAME ${TName} COMMAND bbs-test-bench ${TName}) +endforeach() diff --git a/test/bbs_bench_e2e.c b/test/bbs_bench_e2e.c new file mode 100644 index 0000000..fe1e309 --- /dev/null +++ b/test/bbs_bench_e2e.c @@ -0,0 +1,114 @@ +#include "fixtures.h" +#include "test_util.h" +#include + +int +bbs_bench_e2e () +{ + #define ITERATIONS_START 100 + #define ITERATIONS_END 110 + #define ITERATIONS_STEP 10 + #define MSG_LEN_START 1024 + #define MSG_LEN_END 135168 + #define MSG_LEN_STEP 1024 + #define USE_HEADER 0 + char msg1[ITERATIONS_END][MSG_LEN_END]; + char msg2[ITERATIONS_END][MSG_LEN_END]; + for (int i = 0; i < ITERATIONS_END; i++) + { + for (int j = 0; j < MSG_LEN_END; j++) + { + msg1[i][j] = (char) rand (); + msg2[i][j] = (char) rand (); + } + } + for (int iterations_count = ITERATIONS_START; + iterations_count < ITERATIONS_END; + iterations_count += ITERATIONS_STEP) + { + for (int msg_len = MSG_LEN_START; msg_len < MSG_LEN_END; msg_len += MSG_LEN_STEP) + { + printf ( + "%d iterations BBS e2e sign and proof (2 messages, each %d bytes, include header %d, reveal message 0 (1/2).", + iterations_count, + msg_len, + USE_HEADER); + BBS_BENCH_START (e2e) + + if (core_init () != RLC_OK) + { + core_clean (); + return 1; + } + if (pc_param_set_any () != RLC_OK) + { + core_clean (); + return 1; + } + + for (int i = 0; i < iterations_count; i++) + { + bbs_secret_key sk; + bbs_public_key pk; + + if (BBS_OK != bbs_sha256_keygen_full (sk, pk)) + { + puts ("Error during key generation"); + return 1; + } + + bbs_signature sig; + #if USE_HEADER + static char header[] = "But I am a header!"; + #else + static char header[] = ""; + #endif + + if (BBS_OK != bbs_sha256_sign (sk, pk, sig, (uint8_t*) header, + strlen (header), 2, msg1[i], msg_len, + msg2[i], msg_len)) + { + puts ("Error during signing"); + return 1; + } + + if (BBS_OK != bbs_sha256_verify (pk, sig, (uint8_t*) header, + strlen (header), 2, msg1[i], + msg_len, msg2[i], msg_len)) + { + puts ("Error during signature verification"); + return 1; + } + + uint8_t proof[BBS_PROOF_LEN (1)]; + uint64_t disclosed_indexes[] = {0}; + static char ph[] = "I am a challenge nonce!"; + + if (BBS_OK != bbs_sha256_proof_gen (pk, sig, proof, + (uint8_t*) header, + strlen (header), (uint8_t*) ph, + strlen (ph), disclosed_indexes, + 1, 2, msg1[i], msg_len, msg2[i], + msg_len)) + { + puts ("Error during proof generation"); + return 1; + } + + if (BBS_OK != bbs_sha256_proof_verify (pk, proof, BBS_PROOF_LEN (1), + (uint8_t*) header, + strlen (header), + (uint8_t*) ph, strlen (ph), + disclosed_indexes, 1, 2, + msg1[i], msg_len)) + { + puts ("Error during proof verification"); + return 1; + } + } + BBS_BENCH_END (e2e, "bbs_e2e_sign_n_proof") + } + } + + return 0; +} \ No newline at end of file diff --git a/test/bbs_bench_individual.c b/test/bbs_bench_individual.c new file mode 100644 index 0000000..a4fb84a --- /dev/null +++ b/test/bbs_bench_individual.c @@ -0,0 +1,176 @@ +#include "fixtures.h" +#include "test_util.h" +#include + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) + +int +bbs_bench_individual () +{ + #define CIPHERSUITE sha256 + // 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 100 + + if (core_init () != RLC_OK) + { + core_clean (); + return 1; + } + if (pc_param_set_any () != RLC_OK) + { + core_clean (); + return 1; + } + + // - MARK: Key generation + bbs_secret_key sk[ITERATIONS]; + bbs_public_key pk[ITERATIONS]; + + printf ("%s key generation %d iterations.\n", TOSTRING(CIPHERSUITE), ITERATIONS); + + BBS_BENCH_START (key_gen) + for (int i = 0; i < ITERATIONS; i++) + { + if (BBS_OK != BBS_EXECUTE(CIPHERSUITE, keygen_full) (sk[i], pk[i])) + { + puts ("Error during key generation"); + return 1; + } + } + BBS_BENCH_END (key_gen, "Key generation (SK & PK)") + + // - MARK: Signing + + #define MSG_LEN 64 + + char msg1[ITERATIONS][MSG_LEN]; + char msg2[ITERATIONS][MSG_LEN]; + bbs_signature sig[ITERATIONS]; + + for (int i = 0; i < ITERATIONS; i++) + { + for (int j = 0; j < MSG_LEN; j++) + { + msg1[i][j] = (char) rand (); + msg2[i][j] = (char) rand (); + } + } + #if USE_HEADER + static char header[] = "But I am a header!"; + #else + static char header[] = ""; + #endif + + printf ("%s signing %d iterations of %d messages each of size %d bytes.\n", + TOSTRING(CIPHERSUITE), ITERATIONS, + 2, + MSG_LEN); + + BBS_BENCH_START (sign) + for (int i = 0; i < ITERATIONS; i++) + { + if (BBS_OK != BBS_EXECUTE(CIPHERSUITE, sign) (sk[i], pk[i], sig[i], (uint8_t*) header, strlen (header), 2, + msg1[i], MSG_LEN, msg2[i], MSG_LEN)) + { + puts ("Error during signing"); + return 1; + } + } + BBS_BENCH_END (sign, "Signing") + + // - MARK: Verification + printf ("%s verification %d iterations of %d messages each of size %d bytes.\n", + TOSTRING(CIPHERSUITE), ITERATIONS, + 2, + MSG_LEN); + BBS_BENCH_START (verify) + for (int i = 0; i < ITERATIONS; i++) + { + if (BBS_OK != bbs_sha256_verify (pk[i], sig[i], (uint8_t*) header, strlen (header), 2, + msg1[i], MSG_LEN, msg2[i], MSG_LEN)) + { + puts ("Error during signature verification"); + return 1; + } + } + BBS_BENCH_END (verify, "Verification") + + // - MARK: Proof generation + uint8_t proof[ITERATIONS][BBS_PROOF_LEN (1)]; + uint64_t disclosed_indexes[] = {0}; + #define RANDOM_NONCE_SIZE 23 + static uint8_t random_nonces[ITERATIONS][RANDOM_NONCE_SIZE]; + for (int i = 0; i < ITERATIONS; i++) + { + for (int j = 0; j < 23; j++) + { + random_nonces[i][j] = (uint8_t) rand (); + } + } + + printf ("%s proof generation %d iterations of %d messages each of size %d bytes disclosing first message only.\n", + TOSTRING(CIPHERSUITE), ITERATIONS, + 2, + MSG_LEN); + BBS_BENCH_START (proof_gen) + for (int i = 0; i < ITERATIONS; i++) + { + if (BBS_OK != BBS_EXECUTE(CIPHERSUITE, proof_gen) (pk[i], + sig[i], + proof[i], + (uint8_t*) header, + strlen (header), + (uint8_t*) random_nonces[i], + RANDOM_NONCE_SIZE, + disclosed_indexes, + 1, + 2, + msg1[i], + MSG_LEN, + msg2[i], + MSG_LEN)) + { + puts ("Error during proof generation"); + return 1; + } + } + BBS_BENCH_END (proof_gen, "Proof generation") + + // - MARK: Proof verification + printf ("%s proof verification %d iterations of %d messages each of size %d bytes disclosing first message only.\n", + TOSTRING(CIPHERSUITE), ITERATIONS, + 2, + MSG_LEN); + BBS_BENCH_START (proof_verify) + for (int i = 0; i < ITERATIONS; i++) + { + if (BBS_OK != bbs_sha256_proof_verify (pk[i], + proof[i], + BBS_PROOF_LEN (1), + (uint8_t*) header, + strlen (header), + (uint8_t*) random_nonces[i], + RANDOM_NONCE_SIZE, + disclosed_indexes, + 1, + 2, + msg1[i], + MSG_LEN)) + { + puts ("Error during proof verification"); + return 1; + } + } + BBS_BENCH_END (proof_verify, "Proof verification") + + return 0; +} \ No newline at end of file diff --git a/test/bbs_e2e_bench.c b/test/bbs_e2e_bench.c deleted file mode 100644 index 62bd9be..0000000 --- a/test/bbs_e2e_bench.c +++ /dev/null @@ -1,108 +0,0 @@ -#include "fixtures.h" -#include "test_util.h" -#include - -int -bbs_e2e_bench () -{ - BBS_BENCH_START(e2e) - - 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; - - if (BBS_OK != bbs_sha256_keygen_full (sk, pk)) - { - puts ("Error during key generation"); - return 1; - } - - 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!"; - static char header[] = ""; - - if (BBS_OK != bbs_sha256_sign (sk, - pk, - sig, - (uint8_t*) header, - strlen (header), - 2, - msg1, - strlen (msg1), - msg2, - strlen (msg2))) - { - puts ("Error during signing"); - return 1; - } - - if (BBS_OK != bbs_sha256_verify (pk, - sig, - (uint8_t*) header, - strlen (header), - 2, - msg1, - strlen (msg1), - msg2, - strlen (msg2))) - { - puts ("Error during signature verification"); - return 1; - } - - uint8_t proof[BBS_PROOF_LEN (1)]; - uint64_t disclosed_indexes[] = {0}; - static char ph[] = "I am a challenge nonce!"; - - if (BBS_OK != bbs_sha256_proof_gen (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; - } - - if (BBS_OK != bbs_sha256_proof_verify (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(e2e, "bbs_e2e_sign_n_proof") - - return 0; -} \ No newline at end of file From a0d4cdb85a701c9bdd4f14d5577fc7862fb594ec Mon Sep 17 00:00:00 2001 From: Stephan Schmiedmayer <56692976+StephanSchmiedmayer@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:47:55 +0200 Subject: [PATCH 3/6] update readme --- README.md | 24 ++++++++++++++++++------ test/bbs_bench_e2e.c | 25 +++++++++++-------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fe53417..3c2cc21 100644 --- a/README.md +++ b/README.md @@ -13,21 +13,33 @@ Dependencies: - `gmp` - `cmake` (build only) -### Installation - ```zsh mkdir build cd build cmake .. +``` + +### Installation + +Within `build`: + +```zsh make install ``` ### Test +Within `build`: + ```zsh -mkdir build -cd build -cmake .. -make -j +make make test ``` + +### Benchmark + +Within `build`: + +```zsh +make bench +``` diff --git a/test/bbs_bench_e2e.c b/test/bbs_bench_e2e.c index fe1e309..a3582ae 100644 --- a/test/bbs_bench_e2e.c +++ b/test/bbs_bench_e2e.c @@ -12,15 +12,12 @@ bbs_bench_e2e () #define MSG_LEN_END 135168 #define MSG_LEN_STEP 1024 #define USE_HEADER 0 - char msg1[ITERATIONS_END][MSG_LEN_END]; - char msg2[ITERATIONS_END][MSG_LEN_END]; - for (int i = 0; i < ITERATIONS_END; i++) + char msg1[MSG_LEN_END]; + char msg2[MSG_LEN_END]; + for (int j = 0; j < MSG_LEN_END; j++) { - for (int j = 0; j < MSG_LEN_END; j++) - { - msg1[i][j] = (char) rand (); - msg2[i][j] = (char) rand (); - } + msg1[j] = (char) rand (); + msg2[j] = (char) rand (); } for (int iterations_count = ITERATIONS_START; iterations_count < ITERATIONS_END; @@ -65,16 +62,16 @@ bbs_bench_e2e () #endif if (BBS_OK != bbs_sha256_sign (sk, pk, sig, (uint8_t*) header, - strlen (header), 2, msg1[i], msg_len, - msg2[i], msg_len)) + strlen (header), 2, msg1, msg_len, + msg2, msg_len)) { puts ("Error during signing"); return 1; } if (BBS_OK != bbs_sha256_verify (pk, sig, (uint8_t*) header, - strlen (header), 2, msg1[i], - msg_len, msg2[i], msg_len)) + strlen (header), 2, msg1, + msg_len, msg2, msg_len)) { puts ("Error during signature verification"); return 1; @@ -88,7 +85,7 @@ bbs_bench_e2e () (uint8_t*) header, strlen (header), (uint8_t*) ph, strlen (ph), disclosed_indexes, - 1, 2, msg1[i], msg_len, msg2[i], + 1, 2, msg1, msg_len, msg2, msg_len)) { puts ("Error during proof generation"); @@ -100,7 +97,7 @@ bbs_bench_e2e () strlen (header), (uint8_t*) ph, strlen (ph), disclosed_indexes, 1, 2, - msg1[i], msg_len)) + msg1, msg_len)) { puts ("Error during proof verification"); return 1; From 1dab40fc024566a80cc359df219353eaa5ba21b7 Mon Sep 17 00:00:00 2001 From: Stephan Schmiedmayer <56692976+StephanSchmiedmayer@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:52:53 +0200 Subject: [PATCH 4/6] Add benchmark results to readme --- README.md | 14 ++++++ test/bbs_bench_individual.c | 93 ++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 3c2cc21..0da4693 100644 --- a/README.md +++ b/README.md @@ -43,3 +43,17 @@ Within `build`: ```zsh make bench ``` + +Benchmark on Apple M1 Pro 2021 16GB: + +- 2 messages each of size 64 bytes +- Disclosing first message only +- Runtime averaged over 1000 iterations + +| Function | SHA256 (ms) | SHAKE256 (ms) | +| ------------------------ | ----------- | ------------- | +| key generation (SK & PK) | 0,174 | 0,172 | +| sign | 1,995 | 1,888 | +| verify | 3,877 | 3,829 | +| proof generation | 3,289 | 3,220 | +| proof verification | 4,532 | 4,482 | diff --git a/test/bbs_bench_individual.c b/test/bbs_bench_individual.c index a4fb84a..c3b0b74 100644 --- a/test/bbs_bench_individual.c +++ b/test/bbs_bench_individual.c @@ -3,22 +3,22 @@ #include #define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) +#define TOSTRING(x) STRINGIFY (x) int bbs_bench_individual () { - #define CIPHERSUITE sha256 + #define CIPHERSUITE sha256 // 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 CONCAT_INTERNAL(a, b, c) a ## _ ## b ## _ ## c + #define BBS_EXECUTE(cipher_suite, function) CONCAT_INTERNAL (bbs, cipher_suite, function) - #define USE_HEADER 0 + #define USE_HEADER 0 - printf("Benchmarking %s \n", TOSTRING(CIPHERSUITE)); + printf ("Benchmarking %s \n", TOSTRING (CIPHERSUITE)); printf ("Include header: %d \n", USE_HEADER); - #define ITERATIONS 100 + #define ITERATIONS 1000 if (core_init () != RLC_OK) { @@ -35,12 +35,12 @@ bbs_bench_individual () bbs_secret_key sk[ITERATIONS]; bbs_public_key pk[ITERATIONS]; - printf ("%s key generation %d iterations.\n", TOSTRING(CIPHERSUITE), ITERATIONS); + printf ("%s key generation %d iterations.\n", TOSTRING (CIPHERSUITE), ITERATIONS); BBS_BENCH_START (key_gen) for (int i = 0; i < ITERATIONS; i++) { - if (BBS_OK != BBS_EXECUTE(CIPHERSUITE, keygen_full) (sk[i], pk[i])) + if (BBS_OK != BBS_EXECUTE (CIPHERSUITE, keygen_full) (sk[i], pk[i])) { puts ("Error during key generation"); return 1; @@ -50,7 +50,7 @@ bbs_bench_individual () // - MARK: Signing - #define MSG_LEN 64 + #define MSG_LEN 64 char msg1[ITERATIONS][MSG_LEN]; char msg2[ITERATIONS][MSG_LEN]; @@ -71,15 +71,15 @@ bbs_bench_individual () #endif printf ("%s signing %d iterations of %d messages each of size %d bytes.\n", - TOSTRING(CIPHERSUITE), ITERATIONS, - 2, - MSG_LEN); + TOSTRING (CIPHERSUITE), ITERATIONS, 2, MSG_LEN); BBS_BENCH_START (sign) for (int i = 0; i < ITERATIONS; i++) { - if (BBS_OK != BBS_EXECUTE(CIPHERSUITE, sign) (sk[i], pk[i], sig[i], (uint8_t*) header, strlen (header), 2, - msg1[i], MSG_LEN, msg2[i], MSG_LEN)) + if (BBS_OK != BBS_EXECUTE (CIPHERSUITE, sign) (sk[i], pk[i], sig[i], + (uint8_t*) header, strlen (header), + 2, msg1[i], MSG_LEN, msg2[i], + MSG_LEN)) { puts ("Error during signing"); return 1; @@ -89,14 +89,12 @@ bbs_bench_individual () // - MARK: Verification printf ("%s verification %d iterations of %d messages each of size %d bytes.\n", - TOSTRING(CIPHERSUITE), ITERATIONS, - 2, - MSG_LEN); + TOSTRING (CIPHERSUITE), ITERATIONS, 2, MSG_LEN); BBS_BENCH_START (verify) for (int i = 0; i < ITERATIONS; i++) { - if (BBS_OK != bbs_sha256_verify (pk[i], sig[i], (uint8_t*) header, strlen (header), 2, - msg1[i], MSG_LEN, msg2[i], MSG_LEN)) + if (BBS_OK != BBS_EXECUTE (CIPHERSUITE, verify) (pk[i], sig[i], (uint8_t*) header, strlen (header), + 2, msg1[i], MSG_LEN, msg2[i], MSG_LEN)) { puts ("Error during signature verification"); return 1; @@ -105,8 +103,8 @@ bbs_bench_individual () BBS_BENCH_END (verify, "Verification") // - MARK: Proof generation - uint8_t proof[ITERATIONS][BBS_PROOF_LEN (1)]; - uint64_t disclosed_indexes[] = {0}; + uint8_t proof[ITERATIONS][BBS_PROOF_LEN (1)]; + uint64_t disclosed_indexes[] = {0}; #define RANDOM_NONCE_SIZE 23 static uint8_t random_nonces[ITERATIONS][RANDOM_NONCE_SIZE]; for (int i = 0; i < ITERATIONS; i++) @@ -117,27 +115,23 @@ bbs_bench_individual () } } - printf ("%s proof generation %d iterations of %d messages each of size %d bytes disclosing first message only.\n", - TOSTRING(CIPHERSUITE), ITERATIONS, + printf ( + "%s proof generation %d iterations of %d messages each of size %d bytes disclosing first message only.\n", + TOSTRING (CIPHERSUITE), + ITERATIONS, 2, MSG_LEN); BBS_BENCH_START (proof_gen) for (int i = 0; i < ITERATIONS; i++) { - if (BBS_OK != BBS_EXECUTE(CIPHERSUITE, proof_gen) (pk[i], - sig[i], - proof[i], - (uint8_t*) header, - strlen (header), - (uint8_t*) random_nonces[i], - RANDOM_NONCE_SIZE, - disclosed_indexes, - 1, - 2, - msg1[i], - MSG_LEN, - msg2[i], - MSG_LEN)) + if (BBS_OK != BBS_EXECUTE (CIPHERSUITE, proof_gen) (pk[i], sig[i], proof[i], + (uint8_t*) header, + strlen (header), + (uint8_t*) random_nonces[i], + RANDOM_NONCE_SIZE, + disclosed_indexes, 1, 2, + msg1[i], MSG_LEN, msg2[i], + MSG_LEN)) { puts ("Error during proof generation"); return 1; @@ -146,25 +140,20 @@ bbs_bench_individual () BBS_BENCH_END (proof_gen, "Proof generation") // - MARK: Proof verification - printf ("%s proof verification %d iterations of %d messages each of size %d bytes disclosing first message only.\n", - TOSTRING(CIPHERSUITE), ITERATIONS, + printf ( + "%s proof verification %d iterations of %d messages each of size %d bytes disclosing first message only.\n", + TOSTRING (CIPHERSUITE), + ITERATIONS, 2, MSG_LEN); BBS_BENCH_START (proof_verify) for (int i = 0; i < ITERATIONS; i++) { - if (BBS_OK != bbs_sha256_proof_verify (pk[i], - proof[i], - BBS_PROOF_LEN (1), - (uint8_t*) header, - strlen (header), - (uint8_t*) random_nonces[i], - RANDOM_NONCE_SIZE, - disclosed_indexes, - 1, - 2, - msg1[i], - MSG_LEN)) + if (BBS_OK != BBS_EXECUTE(CIPHERSUITE, proof_verify) (pk[i], proof[i], BBS_PROOF_LEN (1), + (uint8_t*) header, strlen (header), + (uint8_t*) random_nonces[i], + RANDOM_NONCE_SIZE, disclosed_indexes, 1, 2, + msg1[i], MSG_LEN)) { puts ("Error during proof verification"); return 1; From f1f2754dd4c48a6fba1a19cb16e7393ffb9d88a8 Mon Sep 17 00:00:00 2001 From: Stephan Schmiedmayer <56692976+StephanSchmiedmayer@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:53:08 +0200 Subject: [PATCH 5/6] Add xsltproc dependency note to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0da4693..2c69e99 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Provides a library `libbbs` implementing the `BLS12381-SHA-256` and `BLS12-381-S Dependencies: - `gmp` +- `xsltproc` (indirect dependency of XKCP Keccak hash library) - `cmake` (build only) ```zsh From a125963dfb280389b0c54d9d23caed97d12d999e Mon Sep 17 00:00:00 2001 From: Stephan Schmiedmayer <56692976+StephanSchmiedmayer@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:55:05 +0200 Subject: [PATCH 6/6] Improve benchmark description in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c69e99..6df54e9 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Benchmark on Apple M1 Pro 2021 16GB: - 2 messages each of size 64 bytes - Disclosing first message only -- Runtime averaged over 1000 iterations +- Runtime averaged over 1000 iterations without warmup | Function | SHA256 (ms) | SHAKE256 (ms) | | ------------------------ | ----------- | ------------- |