]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
(bench_ctr): New function.
authorNiels Möller <nisse@lysator.liu.se>
Wed, 29 Jun 2011 13:36:15 +0000 (15:36 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Wed, 29 Jun 2011 13:36:15 +0000 (15:36 +0200)
(time_cipher): Also benchmark CTR mode.

Rev: nettle/examples/nettle-benchmark.c:1.21

examples/nettle-benchmark.c

index 7004d8b8dca9fd74c237a86305fae03abb1387e1..630fa414cfea6601619b94278d45bb66b828c35d 100644 (file)
@@ -43,6 +43,7 @@
 #include "blowfish.h"
 #include "cast128.h"
 #include "cbc.h"
+#include "ctr.h"
 #include "des.h"
 #include "gcm.h"
 #include "memxor.h"
@@ -269,6 +270,15 @@ bench_cbc_decrypt(void *arg)
              BENCH_BLOCK, info->data, info->data);
 }
 
+static void
+bench_ctr(void *arg)
+{
+  struct bench_cbc_info *info = arg;
+  ctr_crypt(info->ctx, info->crypt,
+           info->block_size, info->iv,
+           BENCH_BLOCK, info->data, info->data);
+}
+
 /* Set data[i] = floor(sqrt(i)) */
 static void
 init_data(uint8_t *data)
@@ -499,6 +509,24 @@ time_cipher(const struct nettle_cipher *cipher)
        display(cipher->name, "CBC decrypt", cipher->block_size,
                time_function(bench_cbc_decrypt, &info));
       }
+
+      /* Do CTR mode */
+      {
+        struct bench_cbc_info info;
+       info.ctx = ctx;
+       info.crypt = cipher->encrypt;
+       info.data = data;
+       info.block_size = cipher->block_size;
+       info.iv = iv;
+    
+        memset(iv, 0, sizeof(iv));
+    
+        cipher->set_encrypt_key(ctx, cipher->key_size, key);
+
+       display(cipher->name, "CTR", cipher->block_size,
+               time_function(bench_ctr, &info));       
+      }
+      
       free(iv);
     }
   free(ctx);