Commit 60f3e677 authored by Niels Möller's avatar Niels Möller

Support salsa20 in nettle-benchmark.

parent 4403177a
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...
......
......@@ -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
};
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment