summaryrefslogtreecommitdiff
path: root/cipher/cipher.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-07-18 21:32:05 +0200
committerWerner Koch <wk@gnupg.org>2013-07-18 21:32:05 +0200
commitc4885092088431e7928e4459fda20cc0e8ceb201 (patch)
tree3282d123480be1f0cbdc3e92832f91ac26ae9a0d /cipher/cipher.c
parentf6d6e0200fa823d377a342efacaf3d61e4303dc3 (diff)
downloadlibgcrypt-c4885092088431e7928e4459fda20cc0e8ceb201.tar.gz
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 <wk@gnupg.org>
Diffstat (limited to 'cipher/cipher.c')
-rw-r--r--cipher/cipher.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/cipher/cipher.c b/cipher/cipher.c
index d7ebea84..08d61655 100644
--- a/cipher/cipher.c
+++ b/cipher/cipher.c
@@ -104,6 +104,10 @@ static struct cipher_table_entry
{ &_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)
{