]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Add benchmarking of slh-dsa-sha2-128s.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 3 Jul 2025 16:13:16 +0000 (18:13 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sat, 5 Jul 2025 08:14:55 +0000 (10:14 +0200)
examples/hogweed-benchmark.c

index 5b7930d4837cc385bde953741007e1b3343f6f5e..927e106884804a4a925026fc68552312749e1c32 100644 (file)
@@ -870,7 +870,7 @@ struct slh_dsa_ctx
 };
 
 static void *
-bench_slh_dsa_init_s (unsigned size)
+bench_slh_dsa_init_shake_s (unsigned size)
 {
   struct slh_dsa_ctx *ctx;
   assert (size == 128);
@@ -888,7 +888,7 @@ bench_slh_dsa_init_s (unsigned size)
 }
 
 static void *
-bench_slh_dsa_init_f (unsigned size)
+bench_slh_dsa_init_shake_f (unsigned size)
 {
   struct slh_dsa_ctx *ctx;
   assert (size == 128);
@@ -905,6 +905,24 @@ bench_slh_dsa_init_f (unsigned size)
   return ctx;
 }
 
+static void *
+bench_slh_dsa_init_sha2_s (unsigned size)
+{
+  struct slh_dsa_ctx *ctx;
+  assert (size == 128);
+
+  ctx = xalloc (sizeof (*ctx));
+  memset (ctx->key, 1, SLH_DSA_128_KEY_SIZE);
+  memset (ctx->pub, 2, SLH_DSA_128_SEED_SIZE);
+  slh_dsa_sha2_128s_root (ctx->pub, ctx->key, ctx->pub + SLH_DSA_128_SEED_SIZE);
+  memset (ctx->msg, 3, sizeof (ctx->msg));
+  ctx->sig = xalloc (SLH_DSA_128S_SIGNATURE_SIZE);
+  slh_dsa_sha2_128s_sign (ctx->pub, ctx->key, sizeof (ctx->msg), ctx->msg, ctx->sig);
+  ctx->sign = slh_dsa_sha2_128s_sign;
+  ctx->verify = slh_dsa_sha2_128s_verify;
+  return ctx;
+}
+
 static void
 bench_slh_dsa_sign (void *p)
 {
@@ -959,8 +977,9 @@ struct alg alg_list[] = {
   { "curve", 448, bench_curve_init, bench_curve_mul_g, bench_curve_mul, bench_curve_clear },
   { "gostdsa",  256, bench_gostdsa_init, bench_gostdsa_sign, bench_gostdsa_verify, bench_gostdsa_clear },
   { "gostdsa",  512, bench_gostdsa_init, bench_gostdsa_sign, bench_gostdsa_verify, bench_gostdsa_clear },
-  { "slh-dsa-shake-s", 128, bench_slh_dsa_init_s, bench_slh_dsa_sign, bench_slh_dsa_verify, bench_slh_dsa_clear },
-  { "slh-dsa-shake-f", 128, bench_slh_dsa_init_f, bench_slh_dsa_sign, bench_slh_dsa_verify, bench_slh_dsa_clear },
+  { "slh-dsa-shake-s", 128, bench_slh_dsa_init_shake_s, bench_slh_dsa_sign, bench_slh_dsa_verify, bench_slh_dsa_clear },
+  { "slh-dsa-shake-f", 128, bench_slh_dsa_init_shake_f, bench_slh_dsa_sign, bench_slh_dsa_verify, bench_slh_dsa_clear },
+  { "slh-dsa-sha2-s", 128, bench_slh_dsa_init_sha2_s, bench_slh_dsa_sign, bench_slh_dsa_verify, bench_slh_dsa_clear },
 };
 
 #define numberof(x)  (sizeof (x) / sizeof ((x)[0]))