-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9df59b
commit 2982606
Showing
4 changed files
with
302 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "fixtures.h" | ||
#include "test_util.h" | ||
#include <string.h> | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#include "fixtures.h" | ||
#include "test_util.h" | ||
#include <string.h> | ||
|
||
#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; | ||
} |
Oops, something went wrong.