diff options
Diffstat (limited to 'src/test/bench.c')
-rw-r--r-- | src/test/bench.c | 78 |
1 files changed, 71 insertions, 7 deletions
diff --git a/src/test/bench.c b/src/test/bench.c index cf8ba4a48e..de7e4e557c 100644 --- a/src/test/bench.c +++ b/src/test/bench.c @@ -21,6 +21,10 @@ const char tor_git_revision[] = ""; #include "onion.h" #include "relay.h" #include "config.h" +#ifdef CURVE25519_ENABLED +#include "crypto_curve25519.h" +#include "onion_ntor.h" +#endif #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) static uint64_t nanostart; @@ -122,7 +126,7 @@ bench_onion_TAP(void) crypto_dh_free(dh_out); } end = perftime(); - printf("Client-side, part 1: %f msec.\n", NANOCOUNT(start, end, iters)/1e6); + printf("Client-side, part 1: %f usec.\n", NANOCOUNT(start, end, iters)/1e3); onion_skin_create(key, &dh_out, os); start = perftime(); @@ -131,8 +135,8 @@ bench_onion_TAP(void) onion_skin_server_handshake(os, key, NULL, or, key_out, sizeof(key_out)); } end = perftime(); - printf("Server-side, key guessed right: %f msec\n", - NANOCOUNT(start, end, iters)/1e6); + printf("Server-side, key guessed right: %f usec\n", + NANOCOUNT(start, end, iters)/1e3); start = perftime(); for (i = 0; i < iters; ++i) { @@ -140,8 +144,8 @@ bench_onion_TAP(void) onion_skin_server_handshake(os, key2, key, or, key_out, sizeof(key_out)); } end = perftime(); - printf("Server-side, key guessed wrong: %f msec.\n", - NANOCOUNT(start, end, iters)/1e6); + printf("Server-side, key guessed wrong: %f usec.\n", + NANOCOUNT(start, end, iters)/1e3); start = perftime(); for (i = 0; i < iters; ++i) { @@ -153,12 +157,69 @@ bench_onion_TAP(void) tor_assert(s == 0); } end = perftime(); - printf("Client-side, part 2: %f msec.\n", - NANOCOUNT(start, end, iters)/1e6); + printf("Client-side, part 2: %f usec.\n", + NANOCOUNT(start, end, iters)/1e3); crypto_pk_free(key); } +#ifdef CURVE25519_ENABLED +static void +bench_onion_ntor(void) +{ + const int iters = 1<<10; + int i; + curve25519_keypair_t keypair1, keypair2; + uint64_t start, end; + uint8_t os[NTOR_ONIONSKIN_LEN]; + uint8_t or[NTOR_REPLY_LEN]; + ntor_handshake_state_t *state = NULL; + uint8_t nodeid[DIGEST_LEN]; + di_digest256_map_t *keymap = NULL; + + curve25519_secret_key_generate(&keypair1.seckey, 0); + curve25519_public_key_generate(&keypair1.pubkey, &keypair1.seckey); + curve25519_secret_key_generate(&keypair2.seckey, 0); + curve25519_public_key_generate(&keypair2.pubkey, &keypair2.seckey); + dimap_add_entry(&keymap, keypair1.pubkey.public_key, &keypair1); + dimap_add_entry(&keymap, keypair2.pubkey.public_key, &keypair2); + + reset_perftime(); + start = perftime(); + for (i = 0; i < iters; ++i) { + onion_skin_ntor_create(nodeid, &keypair1.pubkey, &state, os); + ntor_handshake_state_free(state); + } + end = perftime(); + printf("Client-side, part 1: %f usec.\n", NANOCOUNT(start, end, iters)/1e3); + + onion_skin_ntor_create(nodeid, &keypair1.pubkey, &state, os); + start = perftime(); + for (i = 0; i < iters; ++i) { + uint8_t key_out[CPATH_KEY_MATERIAL_LEN]; + onion_skin_ntor_server_handshake(os, keymap, nodeid, or, + key_out, sizeof(key_out)); + } + end = perftime(); + printf("Server-side: %f usec\n", + NANOCOUNT(start, end, iters)/1e3); + + start = perftime(); + for (i = 0; i < iters; ++i) { + uint8_t key_out[CPATH_KEY_MATERIAL_LEN]; + int s; + s = onion_skin_ntor_client_handshake(state, or, key_out, sizeof(key_out)); + tor_assert(s == 0); + } + end = perftime(); + printf("Client-side, part 2: %f usec.\n", + NANOCOUNT(start, end, iters)/1e3); + + ntor_handshake_state_free(state); + dimap_free(keymap, NULL); +} +#endif + static void bench_cell_aes(void) { @@ -325,6 +386,9 @@ static struct benchmark_t benchmarks[] = { ENT(dmap), ENT(aes), ENT(onion_TAP), +#ifdef CURVE25519_ENABLED + ENT(onion_ntor), +#endif ENT(cell_aes), ENT(cell_ops), {NULL,NULL,0} |