Skip to content

Commit

Permalink
Improve symbol allocation for benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
schanzen committed Apr 19, 2024
1 parent 837ba91 commit ec0bec2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
20 changes: 10 additions & 10 deletions test/bbs_e2e_sign_n_proof.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,60 +82,60 @@ bbs_e2e_sign_n_proof ()
bbs_secret_key sk;
bbs_public_key pk;

BBS_BENCH_START ()
BBS_BENCH_START (keygen)
if (BBS_OK != bbs_keygen_full[cipher_suite_index] (sk, pk))
{
puts ("Error during key generation");
return 1;
}
BBS_BENCH_END ("bbs_keygen_full")
BBS_BENCH_END (keygen, "bbs_keygen_full")

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 ()
BBS_BENCH_START (sign)
if (BBS_OK != sign[cipher_suite_index] (sk, pk, sig, (uint8_t*) header, strlen (header), 2, msg1,
strlen (msg1), msg2, strlen (msg2)))
{
puts ("Error during signing");
return 1;
}
BBS_BENCH_END ("bbs_sign (2 messages, 1 header)")
BBS_BENCH_END (sign, "bbs_sign (2 messages, 1 header)")

BBS_BENCH_START ()
BBS_BENCH_START (verify)
if (BBS_OK != verify[cipher_suite_index] (pk, sig, (uint8_t*) header, strlen (header), 2, msg1,
strlen (msg1), msg2, strlen (msg2)))
{
puts ("Error during signature verification");
return 1;
}
BBS_BENCH_END ("bbs_verify (2 messages, 1 header)")
BBS_BENCH_END (verify, "bbs_verify (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 ()
BBS_BENCH_START (proof_gen)
if (BBS_OK != proof_gen[cipher_suite_index] (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 ("bbs_proof_gen (2 messages, 1 header, 1 disclosed index)")
BBS_BENCH_END (proof_gen, "bbs_proof_gen (2 messages, 1 header, 1 disclosed index)")

BBS_BENCH_START ()
BBS_BENCH_START (proof_verify)
if (BBS_OK != proof_verify[cipher_suite_index] (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 ("bbs_proof_verify (2 messages, 1 header, 1 disclosed index)")
BBS_BENCH_END (proof_verify, "bbs_proof_verify (2 messages, 1 header, 1 disclosed index)")

}
return 0;
Expand Down
6 changes: 2 additions & 4 deletions test/bbs_fix_proof_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ bbs_fix_proof_gen ()
}

uint8_t proof1[BBS_PROOF_LEN (0)];
BBS_BENCH_START ()
BBS_BENCH_START (mocked_proof_gen)
if (BBS_OK != mocked_proof_gen (test_case, test_case.proof1_public_key,
test_case.proof1_signature, proof1,
test_case.proof1_header,
Expand All @@ -419,7 +419,7 @@ bbs_fix_proof_gen ()
puts ("Error during proof 1 generation");
return 1;
}
BBS_BENCH_END ("Valid Single Message Proof");
BBS_BENCH_END (mocked_proof_gen, "Valid Single Message Proof");
ASSERT_EQ_PTR ("proof 1 generation",
proof1,
test_case.proof1_proof,
Expand Down Expand Up @@ -448,7 +448,6 @@ bbs_fix_proof_gen ()
puts ("Error during proof 2 generation");
return 1;
}
BBS_BENCH_END ("Valid Multi-Message, All Messages Disclosed Proof")
ASSERT_EQ_PTR ("proof 2 generation",
proof2,
test_case.proof2_proof,
Expand Down Expand Up @@ -478,7 +477,6 @@ bbs_fix_proof_gen ()
puts ("Error during proof 3 generation");
return 1;
}
BBS_BENCH_END ("Valid Multi-Message, Some Messages Disclosed Proof")
ASSERT_EQ_PTR ("proof 3 generation",
proof3,
test_case.proof3_proof,
Expand Down
24 changes: 11 additions & 13 deletions test/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@
}


struct timespec tp_start;

struct timespec tp_end;

#ifdef ENABLE_BENCHMARK
#define BBS_BENCH_START() \
clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_start);
#define BBS_BENCH_END(hint) \
clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_end); \
fprintf (stdout, "%s: %" PRIu64 " ns\n", hint, \
(((uint64_t) tp_end.tv_sec * 1000000000) + tp_end.tv_nsec) - \
(((uint64_t) tp_start.tv_sec * 1000000000) + tp_start.tv_nsec));
#define BBS_BENCH_START(hint) \
struct timespec tp_start_ ## hint; \
struct timespec tp_end_ ## hint; \
clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_start_ ## hint);
#define BBS_BENCH_END(hint,info) \
clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_end_ ## hint); \
fprintf (stdout, "%s: %" PRIu64 " ns\n", info, \
(((uint64_t) tp_end_ ## hint.tv_sec * 1000000000) + tp_end_ ## hint.tv_nsec) - \
(((uint64_t) tp_start_ ## hint.tv_sec * 1000000000) + tp_start_ ## hint .tv_nsec));
#else
#define BBS_BENCH_START()
#define BBS_BENCH_END(hint)
#define BBS_BENCH_START(hint)
#define BBS_BENCH_END(hint, info)
#endif
#endif /* TEST_UTIL_H */

0 comments on commit ec0bec2

Please sign in to comment.