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] 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