diff options
author | Niels Möller <nisse@lysator.liu.se> | 2012-03-30 22:05:49 +0200 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2012-03-30 22:05:49 +0200 |
commit | 60f3e6778c6b690ca627012f92df27b0eb0f32f3 (patch) | |
tree | 93499aac2f2183104e388abf803c026711667c10 | |
parent | 4403177a7d529dd73c8e5a10ad8df77b112d45cb (diff) | |
download | nettle-60f3e6778c6b690ca627012f92df27b0eb0f32f3.tar.gz |
Support salsa20 in nettle-benchmark.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | examples/nettle-benchmark.c | 21 | ||||
-rw-r--r-- | nettle-internal.c | 22 | ||||
-rw-r--r-- | nettle-internal.h | 7 |
4 files changed, 52 insertions, 6 deletions
@@ -1,5 +1,13 @@ 2012-03-30 Niels Möller <nisse@lysator.liu.se> + * nettle-internal.c (nettle_salsa20): Cipher struct for + benchmarking only. Sets a fix zero IV, and ignores block size. + * nettle-internal.h (nettle_salsa20): Declare it. + + * examples/nettle-benchmark.c (block_cipher_p): New function. + (time_cipher): Use block_cipher_p. + (main): Include salsa20 in benchmark. + * Makefile.in (soname link): Fixed logic. (nettle_SOURCES): Removed nettle-internal.c, so that it's not parrt of the library... diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index 424ef19f..3ac2841f 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -433,6 +433,23 @@ time_gcm(void) time_function(bench_cipher, &cinfo)); } +static int +prefix_p(const char *prefix, const char *s) +{ + size_t i; + for (i = 0; prefix[i]; i++) + if (prefix[i] != s[i]) + return 0; + return 1; +} + +static int +block_cipher_p(const struct nettle_cipher *cipher) +{ + /* Don't use nettle cbc and ctr for openssl ciphers. */ + return cipher->block_size > 0 && !prefix_p("openssl", cipher->name); +} + static void time_cipher(const struct nettle_cipher *cipher) { @@ -472,8 +489,7 @@ time_cipher(const struct nettle_cipher *cipher) time_function(bench_cipher, &info)); } - /* Don't use nettle cbc to benchmark openssl ciphers */ - if (cipher->block_size && cipher->name[0] != 'o') + if (block_cipher_p(cipher)) { uint8_t *iv = xalloc(cipher->block_size); @@ -619,6 +635,7 @@ main(int argc, char **argv) &nettle_des3, &nettle_serpent256, &nettle_twofish128, &nettle_twofish192, &nettle_twofish256, + &nettle_salsa20, NULL }; diff --git a/nettle-internal.c b/nettle-internal.c index b789a572..93199a98 100644 --- a/nettle-internal.c +++ b/nettle-internal.c @@ -35,9 +35,10 @@ #include "blowfish.h" #include "des.h" #include "gcm.h" +#include "salsa20.h" /* DES uses a different signature for the key set function. We ignore - the return value incicating weak keys. */ + the return value indicating weak keys. */ static void des_set_key_hack(void *ctx, unsigned length, const uint8_t *key) { @@ -77,6 +78,25 @@ nettle_des3 = { const struct nettle_cipher nettle_blowfish128 = _NETTLE_CIPHER(blowfish, BLOWFISH, 128); +/* Sets a fix zero iv. For benchmarking only. */ +static void +salsa20_set_key_hack(void *ctx, unsigned length, const uint8_t *key) +{ + static const uint8_t iv[SALSA20_IV_SIZE]; + salsa20_set_key (ctx, length, key); + salsa20_set_iv (ctx, SALSA20_IV_SIZE, iv); +} + +/* Claim zero block size, to classify as a stream cipher. */ +const struct nettle_cipher +nettle_salsa20 = { + "salsa20", sizeof(struct salsa20_ctx), + 0, SALSA20_KEY_SIZE, + salsa20_set_key_hack, salsa20_set_key_hack, + (nettle_crypt_func *) salsa20_crypt, + (nettle_crypt_func *) salsa20_crypt +}; + const struct nettle_aead nettle_gcm_aes128 = _NETTLE_AEAD(gcm, GCM, aes, 128); const struct nettle_aead diff --git a/nettle-internal.h b/nettle-internal.h index efad02a8..88822393 100644 --- a/nettle-internal.h +++ b/nettle-internal.h @@ -59,9 +59,10 @@ extern const struct nettle_cipher nettle_des3; extern const struct nettle_cipher nettle_blowfish128; -/* Glue to openssl, for comparative benchmarking. The corresponding - * code is not included in the nettle library, as that would make the - * shared library depend on openssl. Instead, look at +/* For benchmarking only, sets no iv and lies about the block size. */ +extern const struct nettle_cipher nettle_salsa20; + +/* Glue to openssl, for comparative benchmarking. Code in * examples/nettle-openssl.c. */ extern const struct nettle_cipher nettle_openssl_aes128; extern const struct nettle_cipher nettle_openssl_aes192; |