diff --git a/ctaocrypt/src/aes.c b/ctaocrypt/src/aes.c index c598d8c8b..f21e7a1a2 100644 --- a/ctaocrypt/src/aes.c +++ b/ctaocrypt/src/aes.c @@ -859,30 +859,12 @@ int AesSetIV(Aes* aes, const byte* iv) } -int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv, - int dir) +static int AesSetKeyLocal(Aes* aes, const byte* userKey, word32 keylen, + const byte* iv, int dir) { word32 temp, *rk = aes->key; unsigned int i = 0; - if (!((keylen == 16) || (keylen == 24) || (keylen == 32))) - return BAD_FUNC_ARG; - -#ifdef CYASSL_AESNI - if (checkAESNI == 0) { - haveAESNI = Check_CPU_support_AES(); - checkAESNI = 1; - } - if (haveAESNI) { - if (iv) - XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE); - if (dir == AES_ENCRYPTION) - return AES_set_encrypt_key(userKey, keylen * 8, aes); - else - return AES_set_decrypt_key(userKey, keylen * 8, aes); - } -#endif /* CYASSL_AESNI */ - aes->rounds = keylen/4 + 6; XMEMCPY(rk, userKey, keylen); @@ -1008,6 +990,32 @@ int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv, } +int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv, + int dir) +{ + + if (!((keylen == 16) || (keylen == 24) || (keylen == 32))) + return BAD_FUNC_ARG; + +#ifdef CYASSL_AESNI + if (checkAESNI == 0) { + haveAESNI = Check_CPU_support_AES(); + checkAESNI = 1; + } + if (haveAESNI) { + if (iv) + XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE); + if (dir == AES_ENCRYPTION) + return AES_set_encrypt_key(userKey, keylen * 8, aes); + else + return AES_set_decrypt_key(userKey, keylen * 8, aes); + } +#endif /* CYASSL_AESNI */ + + return AesSetKeyLocal(aes, userKey, keylen, iv, dir); +} + + static void AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock) { word32 s0, s1, s2, s3; @@ -1547,9 +1555,12 @@ void AesGcmSetKey(Aes* aes, const byte* key, word32 len, { byte fullIV[AES_BLOCK_SIZE]; + if (!((len == 16) || (len == 24) || (len == 32))) + return; + XMEMSET(fullIV, 0, AES_BLOCK_SIZE); XMEMCPY(fullIV, implicitIV, IMPLICIT_IV_SZ); - AesSetKey(aes, key, len, fullIV, AES_ENCRYPTION); + AesSetKeyLocal(aes, key, len, fullIV, AES_ENCRYPTION); XMEMSET(fullIV, 0, AES_BLOCK_SIZE); AesEncrypt(aes, fullIV, aes->H);