Skip to content

Commit

Permalink
Add benchmark for key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Sep 16, 2022
1 parent 855c8e6 commit d556a9d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ static void bench_sign_run(void* arg, int iters) {
}
}

static void bench_keygen_run(void* arg, int iters) {
int i;
bench_sign_data *data = (bench_sign_data*)arg;

for (i = 0; i < iters; i++) {
unsigned char pub33[33];
size_t len = 33;
secp256k1_pubkey pubkey;
CHECK(secp256k1_ec_pubkey_create(data->ctx, &pubkey, data->key));
CHECK(secp256k1_ec_pubkey_serialize(data->ctx, pub33, &len, &pubkey, SECP256K1_EC_COMPRESSED));
memcpy(data->key, pub33 + 1, 32);
data->key[17] ^= i;
}
}


#ifdef ENABLE_MODULE_ECDH
# include "modules/ecdh/bench_impl.h"
#endif
Expand Down Expand Up @@ -212,6 +228,7 @@ int main(int argc, char** argv) {
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);

if (d || have_flag(argc, argv, "ecdsa") || have_flag(argc, argv, "sign") || have_flag(argc, argv, "ecdsa_sign")) run_benchmark("ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, iters);
if (d || have_flag(argc, argv, "ec") || have_flag(argc, argv, "keygen") || have_flag(argc, argv, "ec_keygen")) run_benchmark("ec_keygen", bench_keygen_run, bench_sign_setup, NULL, &data, 10, iters);

secp256k1_context_destroy(data.ctx);

Expand Down

0 comments on commit d556a9d

Please sign in to comment.