From c4885092088431e7928e4459fda20cc0e8ceb201 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 18 Jul 2013 21:32:05 +0200 Subject: Add support for Salsa20. * src/gcrypt.h.in (GCRY_CIPHER_SALSA20): New. * cipher/salsa20.c: New. * configure.ac (available_ciphers): Add Salsa20. * cipher/cipher.c: Register Salsa20. (cipher_setiv): Allow to divert an IV to a cipher module. * src/cipher-proto.h (cipher_setiv_func_t): New. (cipher_extra_spec): Add field setiv. * src/cipher.h: Declare Salsa20 definitions. * tests/basic.c (check_stream_cipher): New. (check_stream_cipher_large_block): New. (check_cipher_modes): Run new test functions. (check_ciphers): Add simple test for Salsa20. Signed-off-by: Werner Koch --- cipher/cipher.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cipher/cipher.c') diff --git a/cipher/cipher.c b/cipher/cipher.c index d7ebea84..08d61655 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -103,6 +103,10 @@ static struct cipher_table_entry #ifdef USE_IDEA { &_gcry_cipher_spec_idea, &dummy_extra_spec, GCRY_CIPHER_IDEA }, +#endif +#if USE_SALSA20 + { &_gcry_cipher_spec_salsa20, + &_gcry_cipher_extraspec_salsa20, GCRY_CIPHER_SALSA20 }, #endif { NULL } }; @@ -845,8 +849,16 @@ cipher_setkey (gcry_cipher_hd_t c, byte *key, unsigned int keylen) /* Set the IV to be used for the encryption context C to IV with length IVLEN. The length should match the required length. */ static void -cipher_setiv( gcry_cipher_hd_t c, const byte *iv, unsigned ivlen ) +cipher_setiv (gcry_cipher_hd_t c, const byte *iv, unsigned ivlen) { + /* If the cipher has its own IV handler, we use only this one. This + is currently used for stream ciphers requiring a nonce. */ + if (c->extraspec && c->extraspec->setiv) + { + c->extraspec->setiv (&c->context.c, iv, ivlen); + return; + } + memset (c->u_iv.iv, 0, c->cipher->blocksize); if (iv) { -- cgit v1.2.1