2013-06-25 Niels Möller <nisse@lysator.liu.se>
+ * aes-meta.c: Deleted file.
+
+ Analogous changes for new aes192 and aes256 interface.
+
* aes.h (struct aes128_ctx): New aes128 declarations.
* aes-decrypt.c (aes128_decrypt): New function.
* aes-encrypt.c (aes128_encrypt): New function.
* testsuite/aes-test.c (test_cipher2): New function.
(test_main): Test both nettle_aes128 and nettle_unified_aes128.
- Analogous changes för aes192.
-
2013-05-22 Niels Möller <nisse@lysator.liu.se>
* Makefile.in (nettle_SOURCES): Added aes-invert-internal.c and
nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
aes-encrypt-internal.c aes-encrypt.c aes-encrypt-table.c \
aes-invert-internal.c aes-set-key-internal.c \
- aes-set-encrypt-key.c aes-set-decrypt-key.c aes-meta.c \
+ aes-set-encrypt-key.c aes-set-decrypt-key.c \
aes128-set-encrypt-key.c aes128-set-decrypt-key.c \
aes128-meta.c \
aes192-set-encrypt-key.c aes192-set-decrypt-key.c \
aes192-meta.c \
+ aes256-set-encrypt-key.c aes256-set-decrypt-key.c \
+ aes256-meta.c \
arcfour.c arcfour-crypt.c arcfour-meta.c \
arctwo.c arctwo-meta.c gosthash94-meta.c \
base16-encode.c base16-decode.c base16-meta.c \
_aes_decrypt(_AES192_ROUNDS, ctx->keys, &_aes_decrypt_table,
length, dst, src);
}
+
+void
+aes256_decrypt(const struct aes256_ctx *ctx,
+ size_t length, uint8_t *dst,
+ const uint8_t *src)
+{
+ assert(!(length % AES_BLOCK_SIZE) );
+ _aes_decrypt(_AES256_ROUNDS, ctx->keys, &_aes_decrypt_table,
+ length, dst, src);
+}
_aes_encrypt(_AES192_ROUNDS, ctx->keys, &_aes_encrypt_table,
length, dst, src);
}
+
+void
+aes256_encrypt(const struct aes256_ctx *ctx,
+ size_t length, uint8_t *dst,
+ const uint8_t *src)
+{
+ assert(!(length % AES_BLOCK_SIZE) );
+ _aes_encrypt(_AES256_ROUNDS, ctx->keys, &_aes_encrypt_table,
+ length, dst, src);
+}
#define aes192_invert_key nettle_aes192invert_key
#define aes192_encrypt nettle_aes192encrypt
#define aes192_decrypt nettle_aes192decrypt
+#define aes256_set_encrypt_key nettle_aes256_set_encrypt_key
+#define aes256_set_decrypt_key nettle_aes256_set_decrypt_key
+#define aes256_invert_key nettle_aes256_invert_key
+#define aes256_encrypt nettle_aes256_encrypt
+#define aes256_decrypt nettle_aes256_decrypt
#define AES_BLOCK_SIZE 16
size_t length, uint8_t *dst,
const uint8_t *src);
+struct aes256_ctx
+{
+ uint32_t keys[4 * (_AES256_ROUNDS + 1)];
+};
+
+void
+aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
+void
+aes256_set_decrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
+void
+aes256_invert_key(struct aes256_ctx *dst,
+ const struct aes256_ctx *src);
+void
+aes256_encrypt(const struct aes256_ctx *ctx,
+ size_t length, uint8_t *dst,
+ const uint8_t *src);
+void
+aes256_decrypt(const struct aes256_ctx *ctx,
+ size_t length, uint8_t *dst,
+ const uint8_t *src);
+
#ifdef __cplusplus
}
#endif
--- /dev/null
+/* aes256-meta.c */
+
+/* nettle, low-level cryptographics library
+ *
+ * Copyright (C) 2013 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 <assert.h>
+
+#include "nettle-meta.h"
+
+#include "aes.h"
+
+static nettle_set_key_func aes256_set_encrypt_key_wrapper;
+static nettle_set_key_func aes256_set_decrypt_key_wrapper;
+
+static void
+aes256_set_encrypt_key_wrapper (void *ctx, size_t length, const uint8_t *key)
+{
+ assert (length == AES256_KEY_SIZE);
+ aes256_set_encrypt_key (ctx, key);
+}
+
+static void
+aes256_set_decrypt_key_wrapper (void *ctx, size_t length, const uint8_t *key)
+{
+ assert (length == AES256_KEY_SIZE);
+ aes256_set_decrypt_key (ctx, key);
+}
+
+const struct nettle_cipher nettle_aes256 =
+ { "aes256", sizeof(struct aes256_ctx),
+ AES_BLOCK_SIZE, AES256_KEY_SIZE,
+ aes256_set_encrypt_key_wrapper,
+ aes256_set_decrypt_key_wrapper,
+ (nettle_crypt_func *) aes256_encrypt,
+ (nettle_crypt_func *) aes256_decrypt
+ };
--- /dev/null
+/* aes256-set-decrypt-key.c
+ *
+ * Key setup for the aes/rijndael block cipher.
+ */
+
+/* nettle, low-level cryptographics library
+ *
+ * Copyright (C) 2013, 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 <assert.h>
+
+#include "aes-internal.h"
+#include "macros.h"
+
+void
+aes256_invert_key (struct aes256_ctx *dst, const struct aes256_ctx *src)
+{
+ _aes_invert (_AES256_ROUNDS, dst->keys, src->keys);
+}
+
+void
+aes256_set_decrypt_key(struct aes256_ctx *ctx, const uint8_t *key)
+{
+ aes256_set_encrypt_key (ctx, key);
+ aes256_invert_key (ctx, ctx);
+}
-/* aes-meta.c */
+/* aes256-set-encrypt-key.c
+ *
+ * Key setup for the aes/rijndael block cipher.
+ */
/* nettle, low-level cryptographics library
*
- * Copyright (C) 2002 Niels Möller
+ * Copyright (C) 2013, 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
# include "config.h"
#endif
-#include "nettle-meta.h"
+#include <assert.h>
-#include "aes.h"
+#include "aes-internal.h"
-const struct nettle_cipher nettle_aes256
-= _NETTLE_CIPHER_SEP(aes, AES, 256);
+void
+aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *key)
+{
+ _aes_set_key (_AES256_ROUNDS, AES256_KEY_SIZE / 4, ctx->keys, key);
+}
const struct nettle_cipher nettle_unified_aes192
= _NETTLE_CIPHER_SEP(aes, AES, 192);
+
+const struct nettle_cipher nettle_unified_aes256
+= _NETTLE_CIPHER_SEP(aes, AES, 256);
extern const struct nettle_cipher nettle_unified_aes128;
extern const struct nettle_cipher nettle_unified_aes192;
+extern const struct nettle_cipher nettle_unified_aes256;
/* Glue to openssl, for comparative benchmarking. Code in
* examples/nettle-openssl.c. */
SHEX("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
SHEX("DFF4945E0336DF4C 1C56BC700EFF837F"));
- /* 256 bit keys */
- test_cipher(&nettle_aes256,
- SHEX("0001020305060708 0A0B0C0D0F101112"
- "14151617191A1B1C 1E1F202123242526"),
- SHEX("834EADFCCAC7E1B30664B1ABA44815AB"),
- SHEX("1946DABF6A03A2A2 C3D0B05080AED6FC"));
+ /* 256 bit keys */
+ test_cipher2(&nettle_aes256, &nettle_unified_aes256,
+ SHEX("0001020305060708 0A0B0C0D0F101112"
+ "14151617191A1B1C 1E1F202123242526"),
+ SHEX("834EADFCCAC7E1B30664B1ABA44815AB"),
+ SHEX("1946DABF6A03A2A2 C3D0B05080AED6FC"));
/* This test case has been problematic with the CBC test case */
- test_cipher(&nettle_aes256,
- SHEX("8d ae 93 ff fc 78 c9 44"
- "2a bd 0c 1e 68 bc a6 c7"
- "05 c7 84 e3 5a a9 11 8b"
- "d3 16 aa 54 9b 44 08 9e"),
- SHEX("a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"),
- /* In the cbc test, I once got the bad value
- * "b2 a0 6c d2 2f df 7d 2c 26 d2 42 88 8f 20 74 a2" */
- SHEX("1f 94 fc 85 f2 36 21 06"
- "4a ea e3 c9 cc 38 01 0e"));
+ test_cipher2(&nettle_aes256, &nettle_unified_aes256,
+ SHEX("8d ae 93 ff fc 78 c9 44"
+ "2a bd 0c 1e 68 bc a6 c7"
+ "05 c7 84 e3 5a a9 11 8b"
+ "d3 16 aa 54 9b 44 08 9e"),
+ SHEX("a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"),
+ /* In the cbc test, I once got the bad value
+ * "b2 a0 6c d2 2f df 7d 2c 26 d2 42 88 8f 20 74 a2" */
+ SHEX("1f 94 fc 85 f2 36 21 06"
+ "4a ea e3 c9 cc 38 01 0e"));
/* From draft NIST spec on AES modes.
*
"9a4b41ba738d6c72fb16691603c18e0e"));
/* F.1.5 ECB-AES256-Encrypt */
- test_cipher(&nettle_aes256,
- SHEX("603deb1015ca71be2b73aef0857d7781"
- "1f352c073b6108d72d9810a30914dff4"),
- SHEX("6bc1bee22e409f96e93d7e117393172a"
- "ae2d8a571e03ac9c9eb76fac45af8e51"
- "30c81c46a35ce411e5fbc1191a0a52ef"
- "f69f2445df4f9b17ad2b417be66c3710"),
- SHEX("f3eed1bdb5d2a03c064b5a7e3db181f8"
- "591ccb10d410ed26dc5ba74a31362870"
- "b6ed21b99ca6f4f9f153e7b1beafed1d"
- "23304b7a39f9f3ff067d8d8f9e24ecc7"));
+ test_cipher2(&nettle_aes256, &nettle_unified_aes256,
+ SHEX("603deb1015ca71be2b73aef0857d7781"
+ "1f352c073b6108d72d9810a30914dff4"),
+ SHEX("6bc1bee22e409f96e93d7e117393172a"
+ "ae2d8a571e03ac9c9eb76fac45af8e51"
+ "30c81c46a35ce411e5fbc1191a0a52ef"
+ "f69f2445df4f9b17ad2b417be66c3710"),
+ SHEX("f3eed1bdb5d2a03c064b5a7e3db181f8"
+ "591ccb10d410ed26dc5ba74a31362870"
+ "b6ed21b99ca6f4f9f153e7b1beafed1d"
+ "23304b7a39f9f3ff067d8d8f9e24ecc7"));
/* Test aes_invert_key with src != dst */
test_invert(SHEX("0001020305060708 0A0B0C0D0F101112"),