]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Initial benchmarking of curve25519.
authorNiels Möller <nisse@lysator.liu.se>
Tue, 19 Aug 2014 08:08:04 +0000 (10:08 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Tue, 19 Aug 2014 08:08:04 +0000 (10:08 +0200)
ChangeLog
examples/ecc-benchmark.c

index e9d4a1db970ac031d0d646647719654367e4253d..404fd4e00a5b5420eb405f45d09cb5aeb0600ff1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-08-19  Niels Möller  <nisse@lysator.liu.se>
+
+       * examples/ecc-benchmark.c (bench_curve): Support benchmarking of
+       curve25519, for now handled as a special case.
+       (curves): Added nettle_curve25519.
+       (bench_dup_eh, bench_add_eh, bench_add_ehh, bench_mul_g_eh): New
+       functions.
+
 2014-08-18  Niels Möller  <nisse@lysator.liu.se>
 
        * testsuite/curve25519-dh-test.c (test_a): Use curve25519_mul.
index 0153b74460c5a0b2e8bcd4d44f698725cda942b3..51b560a0e5def714a472bd6ac050d8ede78fa8d6 100644 (file)
@@ -237,6 +237,41 @@ bench_mul_a (void *p)
   ecc_mul_a (ctx->ecc, 1, ctx->rp, ctx->ap, ctx->bp, ctx->tp);
 }
 
+static void
+bench_dup_eh (void *p)
+{
+  struct ecc_ctx *ctx = (struct ecc_ctx *) p;
+  ecc_dup_eh (ctx->ecc, ctx->rp, ctx->ap, ctx->tp);
+}
+
+static void
+bench_add_eh (void *p)
+{
+  struct ecc_ctx *ctx = (struct ecc_ctx *) p;
+  ecc_add_eh (ctx->ecc, ctx->rp, ctx->ap, ctx->bp, ctx->tp);
+}
+
+static void
+bench_add_ehh (void *p)
+{
+  struct ecc_ctx *ctx = (struct ecc_ctx *) p;
+  ecc_add_ehh (ctx->ecc, ctx->rp, ctx->ap, ctx->bp, ctx->tp);
+}
+
+static void
+bench_mul_g_eh (void *p)
+{
+  struct ecc_ctx *ctx = (struct ecc_ctx *) p;
+  ecc_mul_g_eh (ctx->ecc, ctx->rp, ctx->ap, ctx->tp);
+}
+
+static void
+bench_mul_a_eh (void *p)
+{
+  struct ecc_ctx *ctx = (struct ecc_ctx *) p;
+  ecc_mul_a_eh (ctx->ecc, ctx->rp, ctx->ap, ctx->bp, ctx->tp);
+}
+
 #if NETTLE_USE_MINI_GMP
 static void
 mpn_random (mp_limb_t *xp, mp_size_t n)
@@ -287,7 +322,7 @@ bench_curve (const struct ecc_curve *ecc)
   modp = time_function (bench_modp, &ctx);
   redc = ecc->redc ? time_function (bench_redc, &ctx) : 0;
 
-  modq = time_function (bench_modq, &ctx);
+  modq = ecc->modq ? time_function (bench_modq, &ctx) : 0;
 
   modinv = time_function (bench_modinv, &ctx);
 #if !NETTLE_USE_MINI_GMP
@@ -300,11 +335,23 @@ bench_curve (const struct ecc_curve *ecc)
 #else
   modinv_powm = 0;
 #endif
-  dup_jj = time_function (bench_dup_jj, &ctx);
-  add_jja = time_function (bench_add_jja, &ctx);
-  add_jjj = time_function (bench_add_jjj, &ctx);
-  mul_g = time_function (bench_mul_g, &ctx);
-  mul_a = time_function (bench_mul_a, &ctx);
+  if (ecc->bit_size == 255)
+    {
+      /* For now, curve25519 is a special case */
+      mul_g = time_function (bench_mul_g_eh, &ctx);
+      mul_a = time_function (bench_mul_a_eh, &ctx);
+      dup_jj = time_function (bench_dup_eh, &ctx);
+      add_jja = time_function (bench_add_eh, &ctx);
+      add_jjj = time_function (bench_add_ehh, &ctx);
+    }
+  else
+    {
+      dup_jj = time_function (bench_dup_jj, &ctx);
+      add_jja = time_function (bench_add_jja, &ctx);
+      add_jjj = time_function (bench_add_jjj, &ctx);
+      mul_g = time_function (bench_mul_g, &ctx);
+      mul_a = time_function (bench_mul_a, &ctx);
+    }
 
   free (ctx.rp);
   free (ctx.ap);
@@ -321,6 +368,7 @@ bench_curve (const struct ecc_curve *ecc)
 const struct ecc_curve * const curves[] = {
   &nettle_secp_192r1,
   &nettle_secp_224r1,
+  &nettle_curve25519,
   &nettle_secp_256r1,
   &nettle_secp_384r1,
   &nettle_secp_521r1,