diff options
author | Niels Möller <nisse@lysator.liu.se> | 2014-02-13 07:25:51 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2014-02-13 07:25:51 +0100 |
commit | c6ce389e5fa32c848c06e96bff81c55d626f9118 (patch) | |
tree | 2b14c33192eb6c5304841adc7f634f5ef56ae7d5 | |
parent | 63108e98cbe0395f49bd45e0f8a0138fde02a466 (diff) | |
download | nettle-c6ce389e5fa32c848c06e96bff81c55d626f9118.tar.gz |
Make eax_aes128 interface public.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | eax-aes128-meta.c | 50 | ||||
-rw-r--r-- | eax-aes128.c | 70 | ||||
-rw-r--r-- | eax.h | 38 | ||||
-rw-r--r-- | examples/nettle-benchmark.c | 1 | ||||
-rw-r--r-- | nettle-internal.c | 69 | ||||
-rw-r--r-- | nettle-internal.h | 30 | ||||
-rw-r--r-- | nettle-meta.h | 1 |
9 files changed, 172 insertions, 106 deletions
@@ -1,5 +1,21 @@ 2014-02-13 Niels Möller <nisse@lysator.liu.se> + * Makefile.in (nettle_SOURCES): Added eax-aes128.c + eax-aes128-meta.c. + * examples/nettle-benchmark.c: Include eax.h. + * nettle-meta.h (nettle_eax_aes128): Declare, moved from + nettle-internal.h. + * eax.h: Declare eax_aes128_ctx and related functions. Moved from + nettle-internal.h + (EAX_IV_SIZE): New constant. + * eax-aes128-meta.c (nettle_eax_aes128): Moved definition to new + file. + * eax-aes128.c (eax_aes128_set_key, eax_aes128_set_nonce) + (eax_aes128_update, eax_aes128_encrypt, eax_aes128_decrypt) + (eax_aes128_digest): Moved functions to a new file. + * nettle-internal.c: ... from old location. + * nettle-internal.h: Moved eax declarations elsewhere. + * tools/nettle-pbkdf2.c (main): Added missing deallocation. 2014-02-12 Niels Möller <nisse@lysator.liu.se> diff --git a/Makefile.in b/Makefile.in index dbb07aa6..18090053 100644 --- a/Makefile.in +++ b/Makefile.in @@ -91,7 +91,8 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \ chacha-poly1305.c chacha-poly1305-meta.c \ chacha-set-key.c chacha-set-nonce.c \ chacha128-set-key.c chacha256-set-key.c \ - ctr.c des.c des3.c des-compat.c eax.c \ + ctr.c des.c des3.c des-compat.c \ + eax.c eax-aes128.c eax-aes128-meta.c \ gcm.c gcm-aes.c \ gcm-aes128.c gcm-aes128-meta.c \ gcm-aes192.c gcm-aes192-meta.c \ diff --git a/eax-aes128-meta.c b/eax-aes128-meta.c new file mode 100644 index 00000000..09b76b76 --- /dev/null +++ b/eax-aes128-meta.c @@ -0,0 +1,50 @@ +/* eax-aes128-meta.c + */ + +/* nettle, low-level cryptographics library + * + * Copyright (C) 2013, 2014 Niels Möller + * + * The nettle library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * The nettle library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the nettle library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02111-1301, USA. + */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "eax.h" +#include "nettle-meta.h" + +static nettle_set_key_func eax_aes128_set_nonce_wrapper; +static void +eax_aes128_set_nonce_wrapper (void *ctx, const uint8_t *nonce) +{ + eax_aes128_set_nonce (ctx, EAX_IV_SIZE, nonce); +} + +const struct nettle_aead +nettle_eax_aes128 = + { "eax_aes128", sizeof(struct eax_aes128_ctx), + EAX_BLOCK_SIZE, AES128_KEY_SIZE, + EAX_IV_SIZE, EAX_DIGEST_SIZE, + (nettle_set_key_func *) eax_aes128_set_key, + (nettle_set_key_func *) eax_aes128_set_key, + eax_aes128_set_nonce_wrapper, + (nettle_hash_update_func *) eax_aes128_update, + (nettle_crypt_func *) eax_aes128_encrypt, + (nettle_crypt_func *) eax_aes128_decrypt, + (nettle_hash_digest_func *) eax_aes128_digest + }; diff --git a/eax-aes128.c b/eax-aes128.c new file mode 100644 index 00000000..3050bf92 --- /dev/null +++ b/eax-aes128.c @@ -0,0 +1,70 @@ +/* eax-aes128.c + */ + +/* nettle, low-level cryptographics library + * + * Copyright (C) 2013, 2014 Niels Möller + * + * The nettle library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * The nettle library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the nettle library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02111-1301, USA. + */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "eax.h" + +void +eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key) +{ + EAX_SET_KEY(ctx, + aes128_set_encrypt_key, aes128_encrypt, + key); +} + +void +eax_aes128_set_nonce(struct eax_aes128_ctx *ctx, + size_t length, const uint8_t *iv) +{ + EAX_SET_NONCE(ctx, aes128_encrypt, length, iv); +} + +void +eax_aes128_update(struct eax_aes128_ctx *ctx, size_t length, const uint8_t *data) +{ + EAX_UPDATE(ctx, aes128_encrypt, length, data); +} + +void +eax_aes128_encrypt(struct eax_aes128_ctx *ctx, + size_t length, uint8_t *dst, const uint8_t *src) +{ + EAX_ENCRYPT(ctx, aes128_encrypt, length, dst, src); +} + +void +eax_aes128_decrypt(struct eax_aes128_ctx *ctx, + size_t length, uint8_t *dst, const uint8_t *src) +{ + EAX_DECRYPT(ctx, aes128_encrypt, length, dst, src); +} + +void +eax_aes128_digest(struct eax_aes128_ctx *ctx, + size_t length, uint8_t *digest) +{ + EAX_DIGEST(ctx, aes128_encrypt, length, digest); +} @@ -40,18 +40,20 @@ extern "C" { #define eax_decrypt nettle_eax_decrypt #define eax_digest nettle_eax_digest -#define eax_aes_set_key nettle_eax_aes_set_key -#define eax_aes_set_nonce nettle_eax_aes_set_nonce -#define eax_aes_update nettle_eax_aes_update -#define eax_aes_encrypt nettle_eax_aes_encrypt -#define eax_aes_decrypt nettle_eax_aes_decrypt -#define eax_aes_digest nettle_eax_aes_digest +#define eax_aes128_set_key nettle_eax_aes128_set_key +#define eax_aes128_set_nonce nettle_eax_aes128_set_nonce +#define eax_aes128_update nettle_eax_aes128_update +#define eax_aes128_encrypt nettle_eax_aes128_encrypt +#define eax_aes128_decrypt nettle_eax_aes128_decrypt +#define eax_aes128_digest nettle_eax_aes128_digest /* Restricted to block ciphers with 128 bit block size. FIXME: Reflect this in naming? */ #define EAX_BLOCK_SIZE 16 #define EAX_DIGEST_SIZE 16 +/* FIXME: Reasonable default? */ +#define EAX_IV_SIZE 16 /* Values independent of message and nonce */ struct eax_key @@ -138,6 +140,30 @@ eax_digest (struct eax_ctx *eax, const struct eax_key *key, &(ctx)->cipher, (nettle_crypt_func *) (encrypt), \ (length), (digest))) +struct eax_aes128_ctx EAX_CTX(struct aes128_ctx); + +void +eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key); + +void +eax_aes128_set_nonce(struct eax_aes128_ctx *ctx, + size_t length, const uint8_t *iv); + +void +eax_aes128_update(struct eax_aes128_ctx *ctx, + size_t length, const uint8_t *data); + +void +eax_aes128_encrypt(struct eax_aes128_ctx *ctx, + size_t length, uint8_t *dst, const uint8_t *src); + +void +eax_aes128_decrypt(struct eax_aes128_ctx *ctx, + size_t length, uint8_t *dst, const uint8_t *src); + +void +eax_aes128_digest(struct eax_aes128_ctx *ctx, size_t length, uint8_t *digest); + #ifdef __cplusplus } #endif diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index d66ce71e..5cf7f625 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -47,6 +47,7 @@ #include "cbc.h" #include "ctr.h" #include "des.h" +#include "eax.h" #include "gcm.h" #include "memxor.h" #include "salsa20.h" diff --git a/nettle-internal.c b/nettle-internal.c index 3970685b..6b56b1db 100644 --- a/nettle-internal.c +++ b/nettle-internal.c @@ -34,8 +34,6 @@ #include "nettle-internal.h" #include "blowfish.h" #include "des.h" -#include "eax.h" -#include "gcm.h" #include "chacha.h" #include "salsa20.h" @@ -120,70 +118,3 @@ nettle_salsa20r12 = { (nettle_crypt_func *) salsa20r12_crypt }; - -/* eax-aes128 */ -void -eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key) -{ - EAX_SET_KEY(ctx, - aes128_set_encrypt_key, aes128_encrypt, - key); -} - -void -eax_aes128_set_nonce(struct eax_aes128_ctx *ctx, - size_t length, const uint8_t *iv) -{ - EAX_SET_NONCE(ctx, aes128_encrypt, length, iv); -} - -void -eax_aes128_update(struct eax_aes128_ctx *ctx, size_t length, const uint8_t *data) -{ - EAX_UPDATE(ctx, aes128_encrypt, length, data); -} - -void -eax_aes128_encrypt(struct eax_aes128_ctx *ctx, - size_t length, uint8_t *dst, const uint8_t *src) -{ - EAX_ENCRYPT(ctx, aes128_encrypt, length, dst, src); -} - -void -eax_aes128_decrypt(struct eax_aes128_ctx *ctx, - size_t length, uint8_t *dst, const uint8_t *src) -{ - EAX_DECRYPT(ctx, aes128_encrypt, length, dst, src); -} - -void -eax_aes128_digest(struct eax_aes128_ctx *ctx, - size_t length, uint8_t *digest) -{ - EAX_DIGEST(ctx, aes128_encrypt, length, digest); -} - -/* FIXME: Reasonable default? */ -#define EAX_IV_SIZE 16 - -static nettle_set_key_func eax_aes128_set_nonce_wrapper; -static void -eax_aes128_set_nonce_wrapper (void *ctx, const uint8_t *nonce) -{ - eax_aes128_set_nonce (ctx, EAX_IV_SIZE, nonce); -} - -const struct nettle_aead -nettle_eax_aes128 = - { "eax_aes128", sizeof(struct eax_aes128_ctx), - EAX_BLOCK_SIZE, AES128_KEY_SIZE, - EAX_IV_SIZE, EAX_DIGEST_SIZE, - (nettle_set_key_func *) eax_aes128_set_key, - (nettle_set_key_func *) eax_aes128_set_key, - eax_aes128_set_nonce_wrapper, - (nettle_hash_update_func *) eax_aes128_update, - (nettle_crypt_func *) eax_aes128_encrypt, - (nettle_crypt_func *) eax_aes128_decrypt, - (nettle_hash_digest_func *) eax_aes128_digest - }; diff --git a/nettle-internal.h b/nettle-internal.h index 22d2b9e1..d91a81f9 100644 --- a/nettle-internal.h +++ b/nettle-internal.h @@ -29,8 +29,6 @@ #include "nettle-meta.h" -#include "eax.h" - /* Temporary allocation, for systems that don't support alloca. Note * that the allocation requests should always be reasonably small, so * that they can fit on the stack. For non-alloca systems, we use a @@ -82,32 +80,4 @@ extern const struct nettle_cipher nettle_openssl_cast128; extern const struct nettle_hash nettle_openssl_md5; extern const struct nettle_hash nettle_openssl_sha1; - -/* Tentative interface. */ -struct eax_aes128_ctx EAX_CTX(struct aes128_ctx); - -void -eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key); - -void -eax_aes128_set_nonce(struct eax_aes128_ctx *ctx, - size_t length, const uint8_t *iv); - -void -eax_aes128_update(struct eax_aes128_ctx *ctx, - size_t length, const uint8_t *data); - -void -eax_aes128_encrypt(struct eax_aes128_ctx *ctx, - size_t length, uint8_t *dst, const uint8_t *src); - -void -eax_aes128_decrypt(struct eax_aes128_ctx *ctx, - size_t length, uint8_t *dst, const uint8_t *src); - -void -eax_aes128_digest(struct eax_aes128_ctx *ctx, size_t length, uint8_t *digest); - -extern const struct nettle_aead nettle_eax_aes128; - #endif /* NETTLE_INTERNAL_H_INCLUDED */ diff --git a/nettle-meta.h b/nettle-meta.h index f167b54e..4e33e79f 100644 --- a/nettle-meta.h +++ b/nettle-meta.h @@ -151,6 +151,7 @@ extern const struct nettle_aead nettle_gcm_aes128; extern const struct nettle_aead nettle_gcm_aes192; extern const struct nettle_aead nettle_gcm_aes256; extern const struct nettle_aead nettle_chacha_poly1305; +extern const struct nettle_aead nettle_eax_aes128; struct nettle_armor { |