+2014-03-18 Niels Möller <nisse@lysator.liu.se>
+
+ * nettle-types.h (nettle_cipher_func): New typedef, similar to
+ nettle_crypt_func, but with a const context, intended for block
+ ciphers.
+ * nettle-meta.h (struct nettle_cipher): Use the nettle_cipher_func
+ type.
+ * Many other files affected: aes*-meta.c, camellia*-meta.c,
+ cast128-meta.c, serpent-meta.c, twofish-meta.c, cbc.[ch],
+ ctr.[ch], ctr.[ch], des-compat.c, eax.[ch], gcm*.[ch],
+ nettle-internal.*, testsuite/aes-test.c,
+ examples/nettle-benchmark.c, examples/nettle-openssl.c.
+
2014-03-16 Niels Möller <nisse@lysator.liu.se>
* chacha-set-key.c: Include string.h.
AES_BLOCK_SIZE, AES128_KEY_SIZE,
(nettle_set_key_func *) aes128_set_encrypt_key,
(nettle_set_key_func *) aes128_set_decrypt_key,
- (nettle_crypt_func *) aes128_encrypt,
- (nettle_crypt_func *) aes128_decrypt
+ (nettle_cipher_func *) aes128_encrypt,
+ (nettle_cipher_func *) aes128_decrypt
};
AES_BLOCK_SIZE, AES192_KEY_SIZE,
(nettle_set_key_func *) aes192_set_encrypt_key,
(nettle_set_key_func *) aes192_set_decrypt_key,
- (nettle_crypt_func *) aes192_encrypt,
- (nettle_crypt_func *) aes192_decrypt
+ (nettle_cipher_func *) aes192_encrypt,
+ (nettle_cipher_func *) aes192_decrypt
};
AES_BLOCK_SIZE, AES256_KEY_SIZE,
(nettle_set_key_func *) aes256_set_encrypt_key,
(nettle_set_key_func *) aes256_set_decrypt_key,
- (nettle_crypt_func *) aes256_encrypt,
- (nettle_crypt_func *) aes256_decrypt
+ (nettle_cipher_func *) aes256_encrypt,
+ (nettle_cipher_func *) aes256_decrypt
};
ARCTWO_BLOCK_SIZE, bits/8, \
(nettle_set_key_func *) arctwo ## bits ## _set_key, \
(nettle_set_key_func *) arctwo ## bits ## _set_key, \
- (nettle_crypt_func *) arctwo_encrypt, \
- (nettle_crypt_func *) arctwo_decrypt, \
+ (nettle_cipher_func *) arctwo_encrypt, \
+ (nettle_cipher_func *) arctwo_decrypt, \
}
const struct nettle_cipher nettle_arctwo40
= ARCTWO(40);
ARCTWO_BLOCK_SIZE, 16,
(nettle_set_key_func *) arctwo128_set_key_gutmann,
(nettle_set_key_func *) arctwo128_set_key_gutmann,
- (nettle_crypt_func *) arctwo_encrypt,
- (nettle_crypt_func *) arctwo_decrypt,
+ (nettle_cipher_func *) arctwo_encrypt,
+ (nettle_cipher_func *) arctwo_decrypt,
};
CAMELLIA_BLOCK_SIZE, CAMELLIA128_KEY_SIZE,
(nettle_set_key_func *) camellia128_set_encrypt_key,
(nettle_set_key_func *) camellia128_set_decrypt_key,
- (nettle_crypt_func *) camellia128_crypt,
- (nettle_crypt_func *) camellia128_crypt
+ (nettle_cipher_func *) camellia128_crypt,
+ (nettle_cipher_func *) camellia128_crypt
};
CAMELLIA_BLOCK_SIZE, CAMELLIA192_KEY_SIZE,
(nettle_set_key_func *) camellia192_set_encrypt_key,
(nettle_set_key_func *) camellia192_set_decrypt_key,
- (nettle_crypt_func *) camellia256_crypt,
- (nettle_crypt_func *) camellia256_crypt
+ (nettle_cipher_func *) camellia256_crypt,
+ (nettle_cipher_func *) camellia256_crypt
};
CAMELLIA_BLOCK_SIZE, CAMELLIA256_KEY_SIZE,
(nettle_set_key_func *) camellia256_set_encrypt_key,
(nettle_set_key_func *) camellia256_set_decrypt_key,
- (nettle_crypt_func *) camellia256_crypt,
- (nettle_crypt_func *) camellia256_crypt
+ (nettle_cipher_func *) camellia256_crypt,
+ (nettle_cipher_func *) camellia256_crypt
};
CAST128_BLOCK_SIZE, CAST128_KEY_SIZE,
(nettle_set_key_func *) cast128_set_key,
(nettle_set_key_func *) cast128_set_key,
- (nettle_crypt_func *) cast128_encrypt,
- (nettle_crypt_func *) cast128_decrypt
+ (nettle_cipher_func *) cast128_encrypt,
+ (nettle_cipher_func *) cast128_decrypt
};
#include "nettle-internal.h"
void
-cbc_encrypt(void *ctx, nettle_crypt_func *f,
+cbc_encrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src)
#define CBC_BUFFER_LIMIT 512
void
-cbc_decrypt(void *ctx, nettle_crypt_func *f,
+cbc_decrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src)
#define cbc_decrypt nettle_cbc_decrypt
void
-cbc_encrypt(void *ctx, nettle_crypt_func *f,
+cbc_encrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
void
-cbc_decrypt(void *ctx, nettle_crypt_func *f,
+cbc_decrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
#define CBC_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_encrypt((void *) &(self)->ctx, \
- (nettle_crypt_func *) (f), \
+ (nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
- (length), (dst), (src)))
+ (length), (dst), (src)))
#define CBC_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_decrypt((void *) &(self)->ctx, \
- (nettle_crypt_func *) (f), \
+ (nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
- (length), (dst), (src)))
+ (length), (dst), (src)))
#ifdef __cplusplus
}
#define NBLOCKS 4
void
-ctr_crypt(void *ctx, nettle_crypt_func *f,
+ctr_crypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *ctr,
size_t length, uint8_t *dst,
const uint8_t *src)
#define ctr_crypt nettle_ctr_crypt
void
-ctr_crypt(void *ctx, nettle_crypt_func *f,
+ctr_crypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *ctr,
size_t length, uint8_t *dst,
const uint8_t *src);
#define CTR_CRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, NULL, NULL)) \
: ctr_crypt((void *) &(self)->ctx, \
- (nettle_crypt_func *) (f), \
+ (nettle_cipher_func *) (f), \
sizeof((self)->ctr), (self)->ctr, \
- (length), (dst), (src)))
+ (length), (dst), (src)))
#ifdef __cplusplus
}
switch (enc)
{
case DES_ENCRYPT:
- nettle_cbc_encrypt(ctx, (nettle_crypt_func *) des_encrypt,
+ nettle_cbc_encrypt(ctx, (nettle_cipher_func *) des_encrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
case DES_DECRYPT:
nettle_cbc_decrypt(ctx,
- (nettle_crypt_func *) des_decrypt,
+ (nettle_cipher_func *) des_decrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
switch (enc)
{
case DES_ENCRYPT:
- nettle_cbc_encrypt(&keys, (nettle_crypt_func *) des_compat_des3_encrypt,
+ nettle_cbc_encrypt(&keys, (nettle_cipher_func *) des_compat_des3_encrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
case DES_DECRYPT:
- nettle_cbc_decrypt(&keys, (nettle_crypt_func *) des_compat_des3_decrypt,
+ nettle_cbc_decrypt(&keys, (nettle_cipher_func *) des_compat_des3_decrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
static void
omac_update (union nettle_block16 *state, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, const uint8_t *data)
{
for (; length >= EAX_BLOCK_SIZE;
static void
omac_final (union nettle_block16 *state, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f)
+ const void *cipher, nettle_cipher_func *f)
{
block16_xor (state, &key->pad_block);
f (cipher, EAX_BLOCK_SIZE, state->b, state->b);
}
void
-eax_set_key (struct eax_key *key, void *cipher, nettle_crypt_func *f)
+eax_set_key (struct eax_key *key, const void *cipher, nettle_cipher_func *f)
{
static const union nettle_block16 zero_block;
f (cipher, EAX_BLOCK_SIZE, key->pad_block.b, zero_block.b);
void
eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t nonce_length, const uint8_t *nonce)
{
omac_init (&eax->omac_nonce, 0);
void
eax_update (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t data_length, const uint8_t *data)
{
omac_update (&eax->omac_data, key, cipher, f, data_length, data);
void
eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src)
{
ctr_crypt (cipher, f, EAX_BLOCK_SIZE, eax->ctr.b, length, dst, src);
void
eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src)
{
omac_update (&eax->omac_message, key, cipher, f, length, src);
void
eax_digest (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest)
{
assert (length > 0);
};
void
-eax_set_key (struct eax_key *key, void *cipher, nettle_crypt_func *f);
+eax_set_key (struct eax_key *key, const void *cipher, nettle_cipher_func *f);
void
eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t nonce_length, const uint8_t *nonce);
void
eax_update (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t data_length, const uint8_t *data);
void
eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
eax_digest (struct eax_ctx *eax, const struct eax_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest);
/* Put the cipher last, to get cipher-independent offsets for the EAX
do { \
(set_key)(&(ctx)->cipher, (data)); \
if (0) (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0); \
- eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_crypt_func *) encrypt); \
+ eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_cipher_func *) encrypt); \
} while (0)
#define EAX_SET_NONCE(ctx, encrypt, length, nonce) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_set_nonce (&(ctx)->eax, &(ctx)->key, \
- &(ctx)->cipher, (nettle_crypt_func *) (encrypt), \
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (nonce)))
#define EAX_UPDATE(ctx, encrypt, length, data) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_update (&(ctx)->eax, &(ctx)->key, \
- &(ctx)->cipher, (nettle_crypt_func *) (encrypt), \
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (data)))
#define EAX_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_encrypt (&(ctx)->eax, &(ctx)->key, \
- &(ctx)->cipher, (nettle_crypt_func *) (encrypt), \
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define EAX_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_decrypt (&(ctx)->eax, &(ctx)->key, \
- &(ctx)->cipher, (nettle_crypt_func *) (encrypt), \
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define EAX_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt) (&(ctx)->cipher, 0, (void *) 0, (void *) 0) \
: eax_digest (&(ctx)->eax, &(ctx)->key, \
- &(ctx)->cipher, (nettle_crypt_func *) (encrypt), \
+ &(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (digest)))
struct eax_aes128_ctx EAX_CTX(struct aes128_ctx);
struct bench_cipher_info
{
void *ctx;
- nettle_crypt_func *crypt;
+ nettle_cipher_func *crypt;
uint8_t *data;
};
struct bench_cbc_info
{
void *ctx;
- nettle_crypt_func *crypt;
+ nettle_cipher_func *crypt;
uint8_t *data;
AES_set_decrypt_key(key, 256, ctx);
}
-static nettle_crypt_func openssl_aes_encrypt;
+static nettle_cipher_func openssl_aes_encrypt;
static void
-openssl_aes_encrypt(void *ctx, size_t length,
+openssl_aes_encrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % AES_BLOCK_SIZE));
}
}
-static nettle_crypt_func openssl_aes_decrypt;
+static nettle_cipher_func openssl_aes_decrypt;
static void
-openssl_aes_decrypt(void *ctx, size_t length,
+openssl_aes_decrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % AES_BLOCK_SIZE));
BF_set_key(ctx, 16, key);
}
-static nettle_crypt_func openssl_bf_encrypt;
+static nettle_cipher_func openssl_bf_encrypt;
static void
-openssl_bf_encrypt(void *ctx, size_t length,
+openssl_bf_encrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % BF_BLOCK));
}
}
-static nettle_crypt_func openssl_bf_decrypt;
+static nettle_cipher_func openssl_bf_decrypt;
static void
-openssl_bf_decrypt(void *ctx, size_t length,
+openssl_bf_decrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % BF_BLOCK));
#define DES_BLOCK_SIZE 8
-static nettle_crypt_func openssl_des_encrypt;
+static nettle_cipher_func openssl_des_encrypt;
static void
-openssl_des_encrypt(void *ctx, size_t length,
+openssl_des_encrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % DES_BLOCK_SIZE));
while (length)
{
- DES_ecb_encrypt((void *) src, (void *) dst, ctx, DES_ENCRYPT);
+ DES_ecb_encrypt((void *) src, (void *) dst,
+ (void *) ctx, DES_ENCRYPT);
length -= DES_BLOCK_SIZE;
dst += DES_BLOCK_SIZE;
src += DES_BLOCK_SIZE;
}
}
-static nettle_crypt_func openssl_des_decrypt;
+static nettle_cipher_func openssl_des_decrypt;
static void
-openssl_des_decrypt(void *ctx, size_t length,
+openssl_des_decrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % DES_BLOCK_SIZE));
while (length)
{
- DES_ecb_encrypt((void *) src, (void *) dst, ctx, DES_DECRYPT);
+ DES_ecb_encrypt((void *) src, (void *) dst,
+ (void *) ctx, DES_DECRYPT);
length -= DES_BLOCK_SIZE;
dst += DES_BLOCK_SIZE;
src += DES_BLOCK_SIZE;
CAST_set_key(ctx, 16, key);
}
-static nettle_crypt_func openssl_cast_encrypt;
+static nettle_cipher_func openssl_cast_encrypt;
static void
-openssl_cast_encrypt(void *ctx, size_t length,
+openssl_cast_encrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % CAST_BLOCK));
}
}
-static nettle_crypt_func openssl_cast_decrypt;
+static nettle_cipher_func openssl_cast_decrypt;
static void
-openssl_cast_decrypt(void *ctx, size_t length,
+openssl_cast_decrypt(const void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % CAST_BLOCK));
{
aes_set_encrypt_key (&ctx->cipher, length, key);
gcm_set_key (&ctx->key, &ctx->cipher,
- (nettle_crypt_func *) aes_encrypt);
+ (nettle_cipher_func *) aes_encrypt);
}
void
*/
void
gcm_set_key(struct gcm_key *key,
- void *cipher, nettle_crypt_func *f)
+ const void *cipher, nettle_cipher_func *f)
{
/* Middle element if GCM_TABLE_BITS > 0, otherwise the first
element */
}
static void
-gcm_crypt(struct gcm_ctx *ctx, void *cipher, nettle_crypt_func *f,
+gcm_crypt(struct gcm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src)
{
uint8_t buffer[GCM_BLOCK_SIZE];
void
gcm_encrypt (struct gcm_ctx *ctx, const struct gcm_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src)
{
assert(ctx->data_size % GCM_BLOCK_SIZE == 0);
void
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src)
{
assert(ctx->data_size % GCM_BLOCK_SIZE == 0);
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest)
{
uint8_t buffer[GCM_BLOCK_SIZE];
uint64_t data_size;
};
-/* FIXME: Should use const for the cipher context. Then needs const for
- nettle_crypt_func, which also rules out using that abstraction for
- arcfour. */
void
gcm_set_key(struct gcm_key *key,
- void *cipher, nettle_crypt_func *f);
+ const void *cipher, nettle_cipher_func *f);
void
gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
void
gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
- void *cipher, nettle_crypt_func *f,
+ const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest);
/* Convenience macrology (not sure how useful it is) */
(set_key)(&(ctx)->cipher, (key)); \
if (0) (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0); \
gcm_set_key(&(ctx)->key, &(ctx)->cipher, \
- (nettle_crypt_func *) (encrypt)); \
+ (nettle_cipher_func *) (encrypt)); \
} while (0)
#define GCM_SET_IV(ctx, length, data) \
#define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
- (nettle_crypt_func *) (encrypt), \
+ (nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
- (nettle_crypt_func *) (encrypt), \
+ (nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
- (nettle_crypt_func *) (encrypt), \
+ (nettle_cipher_func *) (encrypt), \
(length), (digest)))
struct gcm_aes128_ctx GCM_CTX(struct aes128_ctx);
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
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
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,
};
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;
-
extern const struct nettle_cipher nettle_unified_aes128;
extern const struct nettle_cipher nettle_unified_aes192;
extern const struct nettle_cipher nettle_unified_aes256;
+/* Stream ciphers treated as aead algorithms with no authentication. */
+extern const struct nettle_aead nettle_chacha;
+extern const struct nettle_aead nettle_salsa20;
+extern const struct nettle_aead nettle_salsa20r12;
+
/* Glue to openssl, for comparative benchmarking. Code in
* examples/nettle-openssl.c. */
extern const struct nettle_cipher nettle_openssl_aes128;
extern const struct nettle_cipher nettle_openssl_aes192;
extern const struct nettle_cipher nettle_openssl_aes256;
-extern const struct nettle_cipher nettle_openssl_arcfour128;
extern const struct nettle_cipher nettle_openssl_blowfish128;
extern const struct nettle_cipher nettle_openssl_des;
extern const struct nettle_cipher nettle_openssl_cast128;
nettle_set_key_func *set_encrypt_key;
nettle_set_key_func *set_decrypt_key;
- nettle_crypt_func *encrypt;
- nettle_crypt_func *decrypt;
+ nettle_cipher_func *encrypt;
+ nettle_cipher_func *decrypt;
};
/* null-terminated list of ciphers implemented by this version of nettle */
/* Ciphers */
typedef void nettle_set_key_func(void *ctx, const uint8_t *key);
-/* Uses a void * for cipher contexts.
+/* For block ciphers, const context. */
+typedef void nettle_cipher_func(const void *ctx,
+ size_t length, uint8_t *dst,
+ const uint8_t *src);
- For block ciphers it would make sense with a const void * for the
- context, but we use the same typedef for stream ciphers where the
- internal state changes during the encryption. */
+/* Uses a void * for cipher contexts. Used for crypt operations where
+ the internal state changes during the encryption. */
typedef void nettle_crypt_func(void *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
SERPENT ## bits ##_KEY_SIZE, \
(nettle_set_key_func *) serpent ## bits ## _set_key, \
(nettle_set_key_func *) serpent ## bits ## _set_key, \
- (nettle_crypt_func *) serpent_encrypt, \
- (nettle_crypt_func *) serpent_decrypt \
+ (nettle_cipher_func *) serpent_encrypt, \
+ (nettle_cipher_func *) serpent_decrypt \
}
const struct nettle_cipher nettle_serpent128
AES_BLOCK_SIZE, AES ## bits ## _KEY_SIZE, \
unified_aes ## bits ##_set_encrypt_key, \
unified_aes ## bits ##_set_decrypt_key, \
- (nettle_crypt_func *) aes_encrypt, \
- (nettle_crypt_func *) aes_decrypt, \
+ (nettle_cipher_func *) aes_encrypt, \
+ (nettle_cipher_func *) aes_decrypt, \
}
const struct nettle_cipher nettle_unified_aes128
= UNIFIED_AES(128);
TWOFISH ## bits ## _KEY_SIZE, \
(nettle_set_key_func *) twofish ## bits ## _set_key, \
(nettle_set_key_func *) twofish ## bits ## _set_key, \
- (nettle_crypt_func *) twofish_encrypt, \
- (nettle_crypt_func *) twofish_decrypt \
+ (nettle_cipher_func *) twofish_encrypt, \
+ (nettle_cipher_func *) twofish_decrypt \
}
const struct nettle_cipher nettle_twofish128