2014-01-27 Niels Möller <nisse@lysator.liu.se>
+ * examples/nettle-benchmark.c (main): Add benchmarking of chacha.
+ * nettle-internal.c (nettle_chacha): New const struct, for the
+ benchmark.
+
Chacha implementation, based on contribution by Joachim
Strömbergson.
* chacha.h: New file.
&nettle_des3,
&nettle_serpent256,
&nettle_twofish128, &nettle_twofish192, &nettle_twofish256,
- &nettle_salsa20, &nettle_salsa20r12,
+ &nettle_salsa20, &nettle_salsa20r12, &nettle_chacha,
NULL
};
#include "des.h"
#include "eax.h"
#include "gcm.h"
+#include "chacha.h"
#include "salsa20.h"
/* DES uses a different signature for the key set function. We ignore
const struct nettle_cipher
nettle_blowfish128 = _NETTLE_CIPHER(blowfish, BLOWFISH, 128);
+/* Sets a fix zero iv. For benchmarking only. */
+static void
+chacha_set_key_hack(void *ctx, size_t length, const uint8_t *key)
+{
+ static const uint8_t iv[CHACHA_IV_SIZE];
+ chacha_set_key (ctx, length, key);
+ chacha_set_iv (ctx, iv);
+}
+
+/* Claim zero block size, to classify as a stream cipher. */
+const struct nettle_cipher
+nettle_chacha = {
+ "chacha", sizeof(struct chacha_ctx),
+ 0, CHACHA_KEY_SIZE,
+ chacha_set_key_hack, chacha_set_key_hack,
+ (nettle_crypt_func *) chacha_crypt,
+ (nettle_crypt_func *) chacha_crypt
+};
+
/* Sets a fix zero iv. For benchmarking only. */
static void
salsa20_set_key_hack(void *ctx, size_t length, const uint8_t *key)
extern const struct nettle_cipher nettle_blowfish128;
/* For benchmarking only, sets no iv and lies about the block size. */
+extern const struct nettle_cipher nettle_chacha;
extern const struct nettle_cipher nettle_salsa20;
extern const struct nettle_cipher nettle_salsa20r12;