Merge pull request #1239 from JacobBarthelmeh/AES

fix AES ECB sanity checks
This commit is contained in:
toddouska 2017-11-16 13:57:47 -08:00 committed by GitHub
commit 8badc334ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2979,25 +2979,33 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
#ifdef HAVE_AES_ECB #ifdef HAVE_AES_ECB
int wc_AesEcbEncrypt(Aes* aes, byte* out, const byte* in, word32 sz) 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)) if ((in == NULL) || (out == NULL) || (aes == NULL))
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
while (sz>0) { while (blocks>0) {
wc_AesEncryptDirect(aes, out, in); wc_AesEncryptDirect(aes, out, in);
out += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE; in += AES_BLOCK_SIZE;
sz -= AES_BLOCK_SIZE; sz -= AES_BLOCK_SIZE;
blocks--;
} }
return 0; return 0;
} }
int wc_AesEcbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz) 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)) if ((in == NULL) || (out == NULL) || (aes == NULL))
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
while (sz>0) { while (blocks>0) {
wc_AesDecryptDirect(aes, out, in); wc_AesDecryptDirect(aes, out, in);
out += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE; in += AES_BLOCK_SIZE;
sz -= AES_BLOCK_SIZE; sz -= AES_BLOCK_SIZE;
blocks--;
} }
return 0; return 0;
} }