diff --git a/ChangeLog b/ChangeLog index 20c7d2b5ebe549be511674a8d769bcac3af1222f..95024c77ffae6ccb6599a6720fb9365affb37685 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-09-06 Niels Möller <nisse@lysator.liu.se> + + * examples/hogweed-benchmark.c (bench_curve25519_mul_g) + (bench_curve25519_mul, bench_curve25519): New functions. + (main): Added benchmarking of curve25519 functions. + 2014-09-03 Niels Möller <nisse@lysator.liu.se> * Makefile.in: Revert 2013-02-06 Makefile changes: use a single diff --git a/examples/hogweed-benchmark.c b/examples/hogweed-benchmark.c index b9dca3d96cda62c61f9d9af89d794f25456debbc..3d7b5855cd91df4588c01c05bb465051ded14c79 100644 --- a/examples/hogweed-benchmark.c +++ b/examples/hogweed-benchmark.c @@ -47,6 +47,7 @@ #include "dsa.h" #include "rsa.h" +#include "curve25519.h" #include "nettle-meta.h" #include "sexp.h" @@ -649,6 +650,48 @@ bench_openssl_ecdsa_clear (void *p) } #endif +struct curve25519_ctx +{ + char x[CURVE25519_SIZE]; + char s[CURVE25519_SIZE]; +}; + +static void +bench_curve25519_mul_g (void *p) +{ + struct curve25519_ctx *ctx = p; + char q[CURVE25519_SIZE]; + curve25519_mul_g (q, ctx->s); +} + +static void +bench_curve25519_mul (void *p) +{ + struct curve25519_ctx *ctx = p; + char q[CURVE25519_SIZE]; + if (!curve25519_mul (q, ctx->s, ctx->x)) + die ("Internal error, curve25519_mul failed.\n"); +} + +static void +bench_curve25519 (void) +{ + double mul_g; + double mul; + struct knuth_lfib_ctx lfib; + struct curve25519_ctx ctx; + knuth_lfib_init (&lfib, 2); + + knuth_lfib_random (&lfib, sizeof(ctx.s), ctx.s); + curve25519_mul_g (ctx.x, ctx.s); + + mul_g = time_function (bench_curve25519_mul_g, &ctx); + mul = time_function (bench_curve25519_mul, &ctx); + + printf("%15s %4d %9.4f %9.4f\n", + "curve25519", 255, 1e-3/mul_g, 1e-3/mul); +} + struct alg alg_list[] = { { "rsa", 1024, bench_rsa_init, bench_rsa_sign, bench_rsa_verify, bench_rsa_clear }, { "rsa", 2048, bench_rsa_init, bench_rsa_sign, bench_rsa_verify, bench_rsa_clear }, @@ -693,5 +736,8 @@ main (int argc, char **argv) if (!filter || strstr (alg_list[i].name, filter)) bench_alg (&alg_list[i]); + if (!filter || strstr("curve25519", filter)) + bench_curve25519(); + return EXIT_SUCCESS; }