diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-25 10:13:25 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-25 15:08:32 -0400 |
commit | 6dbd451b9f7542b16f64415a57a1af26723f8645 (patch) | |
tree | aec0d67f6f497410499ddcf19051db3aa636fc37 /src/test | |
parent | 9b43a4a122770c7dcb221d11ca7b5799a8274d49 (diff) | |
download | tor-6dbd451b9f7542b16f64415a57a1af26723f8645.tar.gz tor-6dbd451b9f7542b16f64415a57a1af26723f8645.zip |
Add benchmarks for ed25519 functions
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/bench.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/bench.c b/src/test/bench.c index f6c33626f2..98e45d2e00 100644 --- a/src/test/bench.c +++ b/src/test/bench.c @@ -30,6 +30,7 @@ const char tor_git_revision[] = ""; #include "crypto_curve25519.h" #include "onion_ntor.h" #endif +#include "crypto_ed25519.h" #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) static uint64_t nanostart; @@ -79,6 +80,9 @@ perftime(void) #define NANOCOUNT(start,end,iters) \ ( ((double)((end)-(start))) / (iters) ) +#define MICROCOUNT(start,end,iters) \ + ( NANOCOUNT((start), (end), (iters)) / 1000.0 ) + /** Run AES performance benchmarks. */ static void bench_aes(void) @@ -235,6 +239,63 @@ bench_onion_ntor(void) #endif static void +bench_ed25519(void) +{ + uint64_t start, end; + const int iters = 1<<12; + int i; + const uint8_t msg[] = "but leaving, could not tell what they had heard"; + ed25519_signature_t sig; + ed25519_keypair_t kp; + curve25519_keypair_t curve_kp; + ed25519_public_key_t pubkey_tmp; + + ed25519_secret_key_generate(&kp.seckey, 0); + start = perftime(); + for (i = 0; i < iters; ++i) { + ed25519_public_key_generate(&kp.pubkey, &kp.seckey); + } + end = perftime(); + printf("Generate public key: %.2f usec\n", + MICROCOUNT(start, end, iters)); + + start = perftime(); + for (i = 0; i < iters; ++i) { + ed25519_sign(&sig, msg, sizeof(msg), &kp); + } + end = perftime(); + printf("Sign a short message: %.2f usec\n", + MICROCOUNT(start, end, iters)); + + start = perftime(); + for (i = 0; i < iters; ++i) { + ed25519_checksig(&sig, msg, sizeof(msg), &kp.pubkey); + } + end = perftime(); + printf("Verify signature: %.2f usec\n", + MICROCOUNT(start, end, iters)); + + curve25519_keypair_generate(&curve_kp, 0); + start = perftime(); + for (i = 0; i < iters; ++i) { + ed25519_public_key_from_curve25519_public_key(&pubkey_tmp, + &curve_kp.pubkey, 1); + } + end = perftime(); + printf("Convert public point from curve25519: %.2f usec\n", + MICROCOUNT(start, end, iters)); + + curve25519_keypair_generate(&curve_kp, 0); + start = perftime(); + for (i = 0; i < iters; ++i) { + ed25519_public_blind(&pubkey_tmp, &kp.pubkey, msg); + } + end = perftime(); + printf("Blind a public key: %.2f usec\n", + MICROCOUNT(start, end, iters)); +} + +static void bench_cell_aes(void) { uint64_t start, end; @@ -515,6 +576,7 @@ static struct benchmark_t benchmarks[] = { #ifdef CURVE25519_ENABLED ENT(onion_ntor), #endif + ENT(ed25519), ENT(cell_aes), ENT(cell_ops), ENT(dh), |