diff --git a/ChangeLog b/ChangeLog index cee70a0a3772ae9078699012b0459f12dc2fc0e6..6c675955386bc8956f31177ea8d4b3aabcb05b3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2014-01-27 Niels Möller + * 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. diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index 6de7dbcf70b8cd45914bf035b05392466e240b4c..9bb19e4af430fcdd648c96e414943ac3cb3c8629 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -680,7 +680,7 @@ main(int argc, char **argv) &nettle_des3, &nettle_serpent256, &nettle_twofish128, &nettle_twofish192, &nettle_twofish256, - &nettle_salsa20, &nettle_salsa20r12, + &nettle_salsa20, &nettle_salsa20r12, &nettle_chacha, NULL }; diff --git a/nettle-internal.c b/nettle-internal.c index 40f2dd453c026460fcf0e9fefac92fb692ca5a33..bdc9ef82c79aeadc66db5cc2054049a2361e502a 100644 --- a/nettle-internal.c +++ b/nettle-internal.c @@ -36,6 +36,7 @@ #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 @@ -79,6 +80,25 @@ nettle_des3 = { 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) diff --git a/nettle-internal.h b/nettle-internal.h index b5a168e579c0ebbbdcf957e2a13578cb2d54dda9..3528b24462d0f9e01f66777ebf93874c901d8a1a 100644 --- a/nettle-internal.h +++ b/nettle-internal.h @@ -61,6 +61,7 @@ extern const struct nettle_cipher nettle_des3; 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;