From a520be22aa3aa6a61676a09c8e9a5a75d65ae4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Wed, 29 Jun 2011 15:36:15 +0200 Subject: [PATCH] (bench_ctr): New function. (time_cipher): Also benchmark CTR mode. Rev: nettle/examples/nettle-benchmark.c:1.21 --- examples/nettle-benchmark.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index 7004d8b8..630fa414 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -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); -- GitLab