diff options
author | Niels Möller <nisse@lysator.liu.se> | 2014-03-18 21:42:00 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2014-03-18 21:42:00 +0100 |
commit | a9b47a42f5a8a2d3e324075bf7bee52f403c6a2e (patch) | |
tree | 5ccdf3a769ece1c1b09e882fe837d8fdc9126c7f /nettle-internal.c | |
parent | 6bd43205b83e773d51d6b73abbcbb77c828a5eb5 (diff) | |
download | nettle-a9b47a42f5a8a2d3e324075bf7bee52f403c6a2e.tar.gz |
Define and use nettle_cipher_func, for block ciphers.
Diffstat (limited to 'nettle-internal.c')
-rw-r--r-- | nettle-internal.c | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/nettle-internal.c b/nettle-internal.c index 96e06f42..639a66ad 100644 --- a/nettle-internal.c +++ b/nettle-internal.c @@ -45,8 +45,8 @@ nettle_des = { DES_BLOCK_SIZE, DES_KEY_SIZE, (nettle_set_key_func *) des_set_key, (nettle_set_key_func *) des_set_key, - (nettle_crypt_func *) des_encrypt, - (nettle_crypt_func *) des_decrypt + (nettle_cipher_func *) des_encrypt, + (nettle_cipher_func *) des_decrypt }; const struct nettle_cipher @@ -55,8 +55,8 @@ nettle_des3 = { DES3_BLOCK_SIZE, DES3_KEY_SIZE, (nettle_set_key_func *) des3_set_key, (nettle_set_key_func *) des3_set_key, - (nettle_crypt_func *) des3_encrypt, - (nettle_crypt_func *) des3_decrypt + (nettle_cipher_func *) des3_encrypt, + (nettle_cipher_func *) des3_decrypt }; /* NOTE: This is not as nice as one might think, as we pretend @@ -67,54 +67,50 @@ nettle_blowfish128 = BLOWFISH_BLOCK_SIZE, BLOWFISH128_KEY_SIZE, (nettle_set_key_func *) blowfish128_set_key, (nettle_set_key_func *) blowfish128_set_key, - (nettle_crypt_func *) blowfish_encrypt, - (nettle_crypt_func *) blowfish_decrypt + (nettle_cipher_func *) blowfish_encrypt, + (nettle_cipher_func *) blowfish_decrypt }; -/* Sets a fix zero iv. For benchmarking only. */ -static void -chacha_set_key_hack(void *ctx, const uint8_t *key) -{ - static const uint8_t nonce[CHACHA_NONCE_SIZE]; - chacha_set_key (ctx, key); - chacha_set_nonce (ctx, nonce); -} -/* Claim zero block size, to classify as a stream cipher. */ -const struct nettle_cipher +const struct nettle_aead nettle_chacha = { "chacha", sizeof(struct chacha_ctx), - 0, CHACHA_KEY_SIZE, - chacha_set_key_hack, chacha_set_key_hack, + CHACHA_BLOCK_SIZE, CHACHA_KEY_SIZE, + CHACHA_NONCE_SIZE, 0, + (nettle_set_key_func *) chacha_set_key, + (nettle_set_key_func *) chacha_set_key, + (nettle_set_key_func *) chacha_set_nonce, + NULL, + (nettle_crypt_func *) chacha_crypt, (nettle_crypt_func *) chacha_crypt, - (nettle_crypt_func *) chacha_crypt + NULL, }; -/* Sets a fix zero iv. For benchmarking only. */ -static void -salsa20_set_key_hack(void *ctx, const uint8_t *key) -{ - static const uint8_t iv[SALSA20_IV_SIZE]; - salsa20_256_set_key (ctx, key); - salsa20_set_iv (ctx, iv); -} - -/* Claim zero block size, to classify as a stream cipher. */ -const struct nettle_cipher +const struct nettle_aead nettle_salsa20 = { "salsa20", sizeof(struct salsa20_ctx), - 0, SALSA20_256_KEY_SIZE, - salsa20_set_key_hack, salsa20_set_key_hack, + SALSA20_BLOCK_SIZE, SALSA20_256_KEY_SIZE, + SALSA20_NONCE_SIZE, 0, + (nettle_set_key_func *) salsa20_256_set_key, + (nettle_set_key_func *) salsa20_256_set_key, + (nettle_set_key_func *) salsa20_set_nonce, + NULL, (nettle_crypt_func *) salsa20_crypt, - (nettle_crypt_func *) salsa20_crypt + (nettle_crypt_func *) salsa20_crypt, + NULL, }; -const struct nettle_cipher +const struct nettle_aead nettle_salsa20r12 = { "salsa20r12", sizeof(struct salsa20_ctx), - 0, SALSA20_256_KEY_SIZE, - salsa20_set_key_hack, salsa20_set_key_hack, + SALSA20_BLOCK_SIZE, SALSA20_256_KEY_SIZE, + SALSA20_NONCE_SIZE, 0, + (nettle_set_key_func*) salsa20_256_set_key, + (nettle_set_key_func*) salsa20_256_set_key, + (nettle_set_key_func*) salsa20_set_nonce, + NULL, + (nettle_crypt_func *) salsa20r12_crypt, (nettle_crypt_func *) salsa20r12_crypt, - (nettle_crypt_func *) salsa20r12_crypt + NULL, }; |