Commit dc2227ac authored by Niels Möller's avatar Niels Möller

New interface for AES-192.

parent bb2131cb
......@@ -16,6 +16,8 @@
* 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
......
......@@ -67,6 +67,8 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
aes-set-encrypt-key.c aes-set-decrypt-key.c aes-meta.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 \
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 \
......
......@@ -355,3 +355,13 @@ aes128_decrypt(const struct aes128_ctx *ctx,
_aes_decrypt(_AES128_ROUNDS, ctx->keys, &_aes_decrypt_table,
length, dst, src);
}
void
aes192_decrypt(const struct aes192_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src)
{
assert(!(length % AES_BLOCK_SIZE) );
_aes_decrypt(_AES192_ROUNDS, ctx->keys, &_aes_decrypt_table,
length, dst, src);
}
......@@ -53,3 +53,13 @@ aes128_encrypt(const struct aes128_ctx *ctx,
_aes_encrypt(_AES128_ROUNDS, ctx->keys, &_aes_encrypt_table,
length, dst, src);
}
void
aes192_encrypt(const struct aes192_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src)
{
assert(!(length % AES_BLOCK_SIZE) );
_aes_encrypt(_AES192_ROUNDS, ctx->keys, &_aes_encrypt_table,
length, dst, src);
}
......@@ -28,8 +28,5 @@
#include "aes.h"
const struct nettle_cipher nettle_aes192
= _NETTLE_CIPHER_SEP(aes, AES, 192);
const struct nettle_cipher nettle_aes256
= _NETTLE_CIPHER_SEP(aes, AES, 256);
......@@ -5,7 +5,7 @@
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
* Copyright (C) 2001, 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
......@@ -43,6 +43,11 @@ extern "C" {
#define aes128_invert_key nettle_aes128invert_key
#define aes128_encrypt nettle_aes128encrypt
#define aes128_decrypt nettle_aes128decrypt
#define aes192_set_encrypt_key nettle_aes192set_encrypt_key
#define aes192_set_decrypt_key nettle_aes192set_decrypt_key
#define aes192_invert_key nettle_aes192invert_key
#define aes192_encrypt nettle_aes192encrypt
#define aes192_decrypt nettle_aes192decrypt
#define AES_BLOCK_SIZE 16
......@@ -110,6 +115,27 @@ aes128_decrypt(const struct aes128_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
struct aes192_ctx
{
uint32_t keys[4 * (_AES192_ROUNDS + 1)];
};
void
aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
void
aes192_set_decrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
void
aes192_invert_key(struct aes192_ctx *dst,
const struct aes192_ctx *src);
void
aes192_encrypt(const struct aes192_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
aes192_decrypt(const struct aes192_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
......
/* aes192-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 aes192_set_encrypt_key_wrapper;
static nettle_set_key_func aes192_set_decrypt_key_wrapper;
static void
aes192_set_encrypt_key_wrapper (void *ctx, size_t length, const uint8_t *key)
{
assert (length == AES192_KEY_SIZE);
aes192_set_encrypt_key (ctx, key);
}
static void
aes192_set_decrypt_key_wrapper (void *ctx, size_t length, const uint8_t *key)
{
assert (length == AES192_KEY_SIZE);
aes192_set_decrypt_key (ctx, key);
}
const struct nettle_cipher nettle_aes192 =
{ "aes192", sizeof(struct aes192_ctx),
AES_BLOCK_SIZE, AES192_KEY_SIZE,
aes192_set_encrypt_key_wrapper,
aes192_set_decrypt_key_wrapper,
(nettle_crypt_func *) aes192_encrypt,
(nettle_crypt_func *) aes192_decrypt
};
/* aes192-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
aes192_invert_key (struct aes192_ctx *dst, const struct aes192_ctx *src)
{
_aes_invert (_AES192_ROUNDS, dst->keys, src->keys);
}
void
aes192_set_decrypt_key(struct aes192_ctx *ctx, const uint8_t *key)
{
aes192_set_encrypt_key (ctx, key);
aes192_invert_key (ctx, ctx);
}
/* aes192-set-encrypt-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"
void
aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key)
{
_aes_set_key (_AES192_ROUNDS, AES192_KEY_SIZE / 4, ctx->keys, key);
}
......@@ -117,3 +117,5 @@ nettle_gcm_aes256 = _NETTLE_AEAD(gcm, GCM, aes, 256);
const struct nettle_cipher nettle_unified_aes128
= _NETTLE_CIPHER_SEP(aes, AES, 128);
const struct nettle_cipher nettle_unified_aes192
= _NETTLE_CIPHER_SEP(aes, AES, 192);
......@@ -65,6 +65,7 @@ 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;
/* Glue to openssl, for comparative benchmarking. Code in
* examples/nettle-openssl.c. */
......
......@@ -84,15 +84,13 @@ test_main(void)
SHEX("CE52AF650D088CA5 59425223F4D32694"));
/* 192 bit keys */
test_cipher(&nettle_aes192,
SHEX("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"),
SHEX("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
SHEX("DFF4945E0336DF4C 1C56BC700EFF837F"));
test_cipher2(&nettle_aes192, &nettle_unified_aes192,
SHEX("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C"),
SHEX("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
SHEX("DFF4945E0336DF4C 1C56BC700EFF837F"));
/* 256 bit keys */
/* 256 bit keys */
test_cipher(&nettle_aes256,
SHEX("0001020305060708 0A0B0C0D0F101112"
"14151617191A1B1C 1E1F202123242526"),
......@@ -131,16 +129,16 @@ test_main(void)
/* F.1.3 ECB-AES192-Encrypt */
test_cipher(&nettle_aes192,
SHEX("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"),
SHEX("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
SHEX("bd334f1d6e45f25ff712a214571fa5cc"
"974104846d0ad3ad7734ecb3ecee4eef"
"ef7afd2270e2e60adce0ba2face6444e"
"9a4b41ba738d6c72fb16691603c18e0e"));
test_cipher2(&nettle_aes192, &nettle_unified_aes192,
SHEX("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"),
SHEX("6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"),
SHEX("bd334f1d6e45f25ff712a214571fa5cc"
"974104846d0ad3ad7734ecb3ecee4eef"
"ef7afd2270e2e60adce0ba2face6444e"
"9a4b41ba738d6c72fb16691603c18e0e"));
/* F.1.5 ECB-AES256-Encrypt */
test_cipher(&nettle_aes256,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment