From a482e83c24a47bd1cf655c9afddc7518018d5723 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Thu, 11 Apr 2013 15:12:31 +0200
Subject: [PATCH] Added umac benchmarking.

---
 ChangeLog                   |  3 +++
 examples/nettle-benchmark.c | 49 +++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 80af73fb..ac2f4997 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-04-11  Niels Möller  <nisse@lysator.liu.se>
 
+	* examples/nettle-benchmark.c (time_umac): New function.
+	(main): Call it.
+
 	* umac-set-key.c (_umac_set_key): Drop byteswapping of l3_key2, it
 	can be xored directly to the pad in native byteorder.
 	* umac-l3.c (_umac_l3): Drop key_2 argument, let caller do that
diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c
index 852baef8..5be3d49b 100644
--- a/examples/nettle-benchmark.c
+++ b/examples/nettle-benchmark.c
@@ -55,6 +55,7 @@
 #include "sha2.h"
 #include "sha3.h"
 #include "twofish.h"
+#include "umac.h"
 
 #include "nettle-meta.h"
 #include "nettle-internal.h"
@@ -352,6 +353,51 @@ time_hash(const struct nettle_hash *hash)
   free(info.ctx);
 }
 
+static void
+time_umac(void)
+{
+  static uint8_t data[BENCH_BLOCK];
+  struct bench_hash_info info;
+  struct umac32_ctx ctx32;
+  struct umac64_ctx ctx64;
+  struct umac96_ctx ctx96;
+  struct umac128_ctx ctx128;
+  
+  uint8_t key[16];
+
+  umac32_set_key (&ctx32, key);
+  info.ctx = &ctx32;
+  info.update = (nettle_hash_update_func *) umac32_update;
+  info.data = data;
+
+  display("umac32", "update", UMAC_BLOCK_SIZE,
+	  time_function(bench_hash, &info));
+
+  umac64_set_key (&ctx64, key);
+  info.ctx = &ctx64;
+  info.update = (nettle_hash_update_func *) umac64_update;
+  info.data = data;
+
+  display("umac64", "update", UMAC_BLOCK_SIZE,
+	  time_function(bench_hash, &info));
+
+  umac96_set_key (&ctx96, key);
+  info.ctx = &ctx96;
+  info.update = (nettle_hash_update_func *) umac96_update;
+  info.data = data;
+
+  display("umac96", "update", UMAC_BLOCK_SIZE,
+	  time_function(bench_hash, &info));
+
+  umac128_set_key (&ctx128, key);
+  info.ctx = &ctx128;
+  info.update = (nettle_hash_update_func *) umac128_update;
+  info.data = data;
+
+  display("umac128", "update", UMAC_BLOCK_SIZE,
+	  time_function(bench_hash, &info));
+}
+
 static void
 time_gcm(void)
 {
@@ -669,6 +715,9 @@ main(int argc, char **argv)
     if (!alg || strstr(hashes[i]->name, alg))
       time_hash(hashes[i]);
 
+  if (!alg || strstr ("umac", alg))
+    time_umac();
+
   for (i = 0; ciphers[i]; i++)
     if (!alg || strstr(ciphers[i]->name, alg))
       time_cipher(ciphers[i]);
-- 
GitLab