From 66c1362e74d1e519821f13f77297be8b4b12cd6e Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 22 Feb 2018 11:43:53 +0100 Subject: drbg-aes: use the new nettle APIs for AES Signed-off-by: Nikos Mavrogiannopoulos --- lib/nettle/int/drbg-aes.c | 22 +++++++++++----------- lib/nettle/int/drbg-aes.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/nettle/int/drbg-aes.c b/lib/nettle/int/drbg-aes.c index f8b693bcd1..625ae80ab9 100644 --- a/lib/nettle/int/drbg-aes.c +++ b/lib/nettle/int/drbg-aes.c @@ -1,6 +1,6 @@ /* drbg-aes.c */ -/* Copyright (C) 2013, 2014 Red Hat +/* Copyright (C) 2013-2018 Red Hat * * This file is part of GnuTLS. * @@ -15,9 +15,7 @@ * 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. + * along with this program. If not, see */ #include @@ -28,18 +26,20 @@ #include #include #include +#include int drbg_aes_init(struct drbg_aes_ctx *ctx, unsigned entropy_size, const uint8_t * entropy, unsigned pstring_size, const uint8_t * pstring) { - uint8_t tmp[DRBG_AES_KEY_SIZE]; + uint8_t tmp[AES256_KEY_SIZE]; + assert(AES256_KEY_SIZE == DRBG_AES_KEY_SIZE); memset(ctx, 0, sizeof(*ctx)); memset(tmp, 0, sizeof(tmp)); - aes_set_encrypt_key(&ctx->key, DRBG_AES_KEY_SIZE, tmp); + aes256_set_encrypt_key(&ctx->key, tmp); return drbg_aes_reseed(ctx, entropy_size, entropy, pstring_size, pstring); @@ -56,14 +56,14 @@ drbg_aes_update(struct drbg_aes_ctx *ctx, while (len < DRBG_AES_SEED_SIZE) { INCREMENT(sizeof(ctx->v), ctx->v); - aes_encrypt(&ctx->key, AES_BLOCK_SIZE, t, ctx->v); + aes256_encrypt(&ctx->key, AES_BLOCK_SIZE, t, ctx->v); t += AES_BLOCK_SIZE; len += AES_BLOCK_SIZE; } memxor(tmp, pdata, DRBG_AES_SEED_SIZE); - aes_set_encrypt_key(&ctx->key, DRBG_AES_KEY_SIZE, tmp); + aes256_set_encrypt_key(&ctx->key, tmp); memcpy(ctx->v, &tmp[DRBG_AES_KEY_SIZE], AES_BLOCK_SIZE); @@ -148,7 +148,7 @@ int drbg_aes_generate(struct drbg_aes_ctx *ctx, unsigned length, uint8_t * dst, */ if (ctx->prev_block_present == 0) { INCREMENT(sizeof(ctx->v), ctx->v); - aes_encrypt(&ctx->key, AES_BLOCK_SIZE, ctx->prev_block, ctx->v); + aes256_encrypt(&ctx->key, AES_BLOCK_SIZE, ctx->prev_block, ctx->v); ctx->prev_block_present = 1; } @@ -158,7 +158,7 @@ int drbg_aes_generate(struct drbg_aes_ctx *ctx, unsigned length, uint8_t * dst, left -= AES_BLOCK_SIZE, dst += AES_BLOCK_SIZE) { INCREMENT(sizeof(ctx->v), ctx->v); - aes_encrypt(&ctx->key, AES_BLOCK_SIZE, dst, ctx->v); + aes256_encrypt(&ctx->key, AES_BLOCK_SIZE, dst, ctx->v); /* if detected loop */ if (memcmp(dst, ctx->prev_block, AES_BLOCK_SIZE) == 0) { @@ -172,7 +172,7 @@ int drbg_aes_generate(struct drbg_aes_ctx *ctx, unsigned length, uint8_t * dst, if (left > 0) { /* partial fill */ INCREMENT(sizeof(ctx->v), ctx->v); - aes_encrypt(&ctx->key, AES_BLOCK_SIZE, tmp, ctx->v); + aes256_encrypt(&ctx->key, AES_BLOCK_SIZE, tmp, ctx->v); /* if detected loop */ if (memcmp(tmp, ctx->prev_block, AES_BLOCK_SIZE) == 0) { diff --git a/lib/nettle/int/drbg-aes.h b/lib/nettle/int/drbg-aes.h index 72608defe8..1d421a69e9 100644 --- a/lib/nettle/int/drbg-aes.h +++ b/lib/nettle/int/drbg-aes.h @@ -38,7 +38,7 @@ ; \ } while (0) -#define DRBG_AES_KEY_SIZE 32 +#define DRBG_AES_KEY_SIZE AES256_KEY_SIZE #define DRBG_AES_SEED_SIZE (AES_BLOCK_SIZE+DRBG_AES_KEY_SIZE) /* This is the CTR-AES-256-based random-number generator from SP800-90A. @@ -46,7 +46,7 @@ struct drbg_aes_ctx { unsigned seeded; /* The current key */ - struct aes_ctx key; + struct aes256_ctx key; uint8_t v[AES_BLOCK_SIZE]; -- cgit v1.2.1