From a89280ac91cc6d58bd3ad1d942d6810756bf0cf5 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 16 Nov 2017 13:27:57 -0700 Subject: [PATCH] fix AES ECB sanity checks --- wolfcrypt/src/aes.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 8ec6e3f69..f8e0b7308 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -2979,25 +2979,33 @@ int wc_AesSetIV(Aes* aes, const byte* iv) #ifdef HAVE_AES_ECB int wc_AesEcbEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) { + word32 blocks = sz / AES_BLOCK_SIZE; + if ((in == NULL) || (out == NULL) || (aes == NULL)) return BAD_FUNC_ARG; - while (sz>0) { + while (blocks>0) { wc_AesEncryptDirect(aes, out, in); out += AES_BLOCK_SIZE; in += AES_BLOCK_SIZE; sz -= AES_BLOCK_SIZE; + blocks--; } return 0; } + + int wc_AesEcbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz) { + word32 blocks = sz / AES_BLOCK_SIZE; + if ((in == NULL) || (out == NULL) || (aes == NULL)) return BAD_FUNC_ARG; - while (sz>0) { + while (blocks>0) { wc_AesDecryptDirect(aes, out, in); out += AES_BLOCK_SIZE; in += AES_BLOCK_SIZE; sz -= AES_BLOCK_SIZE; + blocks--; } return 0; }