mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-01-31 11:29:17 +01:00
Merge pull request #7031 from douzzer/20231201-openssl-compat-fixes
20231201-openssl-compat-fixes
This commit is contained in:
@@ -114,7 +114,6 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
#pragma warning(disable: 4127)
|
||||
#endif
|
||||
|
||||
|
||||
/* Define AES implementation includes and functions */
|
||||
#if defined(STM32_CRYPTO)
|
||||
/* STM32F2/F4/F7/L4/L5/H7/WB55 hardware AES support for ECB, CBC, CTR and GCM modes */
|
||||
@@ -132,6 +131,12 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
CRYP_KeyInitTypeDef keyInit;
|
||||
#endif
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_STM32_CUBEMX
|
||||
ret = wc_Stm32_Aes_Init(aes, &hcryp);
|
||||
if (ret != 0)
|
||||
@@ -227,6 +232,12 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
CRYP_KeyInitTypeDef keyInit;
|
||||
#endif
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_STM32_CUBEMX
|
||||
ret = wc_Stm32_Aes_Init(aes, &hcryp);
|
||||
if (ret != 0)
|
||||
@@ -343,6 +354,12 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
if (wolfSSL_CryptHwMutexLock() == 0) {
|
||||
LTC_AES_EncryptEcb(LTC_BASE, inBlock, outBlock, AES_BLOCK_SIZE,
|
||||
key, keySize);
|
||||
@@ -360,6 +377,12 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
if (wolfSSL_CryptHwMutexLock() == 0) {
|
||||
LTC_AES_DecryptEcb(LTC_BASE, inBlock, outBlock, AES_BLOCK_SIZE,
|
||||
key, keySize, kLTC_EncryptKey);
|
||||
@@ -384,6 +407,14 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
static WARN_UNUSED_RESULT int wc_AesEncrypt(
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (wolfSSL_CryptHwMutexLock() == 0) {
|
||||
#ifdef FREESCALE_MMCAU_CLASSIC
|
||||
if ((wc_ptr_t)outBlock % WOLFSSL_MMCAU_ALIGNMENT) {
|
||||
@@ -403,6 +434,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
if (wolfSSL_CryptHwMutexLock() == 0) {
|
||||
#ifdef FREESCALE_MMCAU_CLASSIC
|
||||
if ((wc_ptr_t)outBlock % WOLFSSL_MMCAU_ALIGNMENT) {
|
||||
@@ -428,6 +466,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
static WARN_UNUSED_RESULT int wc_AesEncrypt(
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
/* Thread mutex protection handled in Pic32Crypto */
|
||||
return wc_Pic32AesCrypt(aes->key, aes->keylen, NULL, 0,
|
||||
outBlock, inBlock, AES_BLOCK_SIZE,
|
||||
@@ -439,6 +484,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
/* Thread mutex protection handled in Pic32Crypto */
|
||||
return wc_Pic32AesCrypt(aes->key, aes->keylen, NULL, 0,
|
||||
outBlock, inBlock, AES_BLOCK_SIZE,
|
||||
@@ -454,6 +506,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
ret = wolfSSL_CryptHwMutexLock();
|
||||
if (ret == 0) {
|
||||
ret = nrf51_aes_encrypt(inBlock, (byte*)aes->key, aes->rounds,
|
||||
@@ -489,6 +548,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
/* Thread mutex protection handled in esp_aes_hw_InUse */
|
||||
#ifdef NEED_AES_HW_FALLBACK
|
||||
if (wc_esp32AesSupportedKeyLen(aes)) {
|
||||
@@ -507,6 +573,11 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
/* Thread mutex protection handled in esp_aes_hw_InUse */
|
||||
#ifdef NEED_AES_HW_FALLBACK
|
||||
if (wc_esp32AesSupportedKeyLen(aes)) {
|
||||
@@ -700,6 +771,14 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
static WARN_UNUSED_RESULT int wc_AesEncrypt(
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret =
|
||||
wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return wc_AesEncryptDirect(aes, outBlock, inBlock);
|
||||
}
|
||||
|
||||
@@ -842,6 +921,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
static WARN_UNUSED_RESULT int wc_AesEncrypt(
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return AES_ECB_encrypt(aes, inBlock, outBlock, AES_BLOCK_SIZE);
|
||||
}
|
||||
#endif
|
||||
@@ -850,6 +936,13 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
|
||||
static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
Aes* aes, const byte* inBlock, byte* outBlock)
|
||||
{
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return AES_ECB_decrypt(aes, inBlock, outBlock, AES_BLOCK_SIZE);
|
||||
}
|
||||
#endif
|
||||
@@ -2671,6 +2764,14 @@ static WARN_UNUSED_RESULT int wc_AesEncrypt(
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
r = aes->rounds >> 1;
|
||||
|
||||
if (r > 7 || r == 0) {
|
||||
@@ -3413,6 +3514,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
r = aes->rounds >> 1;
|
||||
|
||||
if (r > 7 || r == 0) {
|
||||
@@ -3505,6 +3614,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
rk = aes->key;
|
||||
aes->keylen = keylen;
|
||||
aes->rounds = keylen/4 + 6;
|
||||
@@ -3578,6 +3695,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
if (aes == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
aes->keylen = keylen;
|
||||
aes->rounds = keylen/4 + 6;
|
||||
XMEMCPY(aes->key, userKey, keylen);
|
||||
@@ -3599,6 +3724,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
if (aes == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (checkKeyLen) {
|
||||
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
|
||||
return BAD_FUNC_ARG;
|
||||
@@ -3643,6 +3776,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
if (aes == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (checkKeyLen) {
|
||||
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
|
||||
return BAD_FUNC_ARG;
|
||||
@@ -3722,6 +3863,12 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
if (aes == NULL || keylen != 16)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
aes->keylen = keylen;
|
||||
aes->rounds = keylen/4 + 6;
|
||||
XMEMCPY(aes->key, userKey, keylen);
|
||||
@@ -3754,6 +3901,14 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_AES_128)
|
||||
if (keylen == 16) {
|
||||
return BAD_FUNC_ARG;
|
||||
@@ -3797,6 +3952,16 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
|
||||
keylen != AES_256_KEY_SIZE)) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret2 =
|
||||
wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret2 < 0)
|
||||
return ret2;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(AES_MAX_KEY_SIZE)
|
||||
if (keylen > (AES_MAX_KEY_SIZE/8)) {
|
||||
return BAD_FUNC_ARG;
|
||||
@@ -4140,6 +4305,14 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
|
||||
word32 localSz = 32;
|
||||
#endif
|
||||
|
||||
if (aes == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
switch (keylen) {
|
||||
#if defined(AES_MAX_KEY_SIZE) && AES_MAX_KEY_SIZE >= 128 && \
|
||||
defined(WOLFSSL_AES_128)
|
||||
@@ -4460,6 +4633,14 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
||||
if (aes == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
{
|
||||
int ret = wc_debug_CipherLifecycleCheck(aes->CipherLifecycleTag, 0);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (iv)
|
||||
XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
|
||||
else
|
||||
@@ -10018,10 +10199,6 @@ int wc_AesGcmDecryptFinal(Aes* aes, const byte* authTag, word32 authTagSz)
|
||||
VECTOR_REGISTERS_POP;
|
||||
}
|
||||
|
||||
/* reset the state */
|
||||
if (ret == 0)
|
||||
wc_AesFree(aes);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* HAVE_AES_DECRYPT || HAVE_AESGCM_DECRYPT */
|
||||
@@ -10986,6 +11163,12 @@ int wc_AesInit(Aes* aes, void* heap, int devId)
|
||||
#if defined(WOLFSSL_RENESAS_FSPSM)
|
||||
XMEMSET(&aes->ctx, 0, sizeof(aes->ctx));
|
||||
#endif
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
if (ret == 0)
|
||||
ret = wc_debug_CipherLifecycleInit(&aes->CipherLifecycleTag, aes->heap);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -11041,6 +11224,10 @@ void wc_AesFree(Aes* aes)
|
||||
if (aes == NULL)
|
||||
return;
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
(void)wc_debug_CipherLifecycleFree(&aes->CipherLifecycleTag, aes->heap, 1);
|
||||
#endif
|
||||
|
||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)
|
||||
wolfAsync_DevCtxFree(&aes->asyncDev, WOLFSSL_ASYNC_MARKER_AES);
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||
@@ -11096,17 +11283,16 @@ void wc_AesFree(Aes* aes)
|
||||
wc_MAXQ10XX_AesFree(aes);
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_CHECK_MEM_ZERO
|
||||
wc_MemZero_Check(aes, sizeof(Aes));
|
||||
#endif
|
||||
|
||||
#if ((defined(WOLFSSL_RENESAS_FSPSM_TLS) || \
|
||||
defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)) && \
|
||||
!defined(NO_WOLFSSL_RENESAS_FSPSM_AES))
|
||||
wc_fspsm_Aesfree(aes);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_CHECK_MEM_ZERO
|
||||
wc_MemZero_Check(aes, sizeof(Aes));
|
||||
#endif
|
||||
}
|
||||
|
||||
int wc_AesGetKeySize(Aes* aes, word32* keySize)
|
||||
{
|
||||
@@ -12066,6 +12252,24 @@ int wc_AesKeyUnWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
|
||||
/* Galios Field to use */
|
||||
#define GF_XTS 0x87
|
||||
|
||||
int wc_AesXtsInit(XtsAes* aes, void* heap, int devId)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (aes == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if ((ret = wc_AesInit(&aes->tweak, heap, devId)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
if ((ret = wc_AesInit(&aes->aes, heap, devId)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is to help with setting keys to correct encrypt or decrypt type.
|
||||
*
|
||||
* tweak AES key for tweak in XTS
|
||||
@@ -12077,12 +12281,9 @@ int wc_AesKeyUnWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
|
||||
* heap heap hint to use for memory. Can be NULL
|
||||
* devId id to use with async crypto. Can be 0
|
||||
*
|
||||
* Note: is up to user to call wc_AesFree on tweak and aes key when done.
|
||||
*
|
||||
* return 0 on success
|
||||
*/
|
||||
int wc_AesXtsSetKey(XtsAes* aes, const byte* key, word32 len, int dir,
|
||||
void* heap, int devId)
|
||||
int wc_AesXtsSetKeyNoInit(XtsAes* aes, const byte* key, word32 len, int dir)
|
||||
{
|
||||
word32 keySz;
|
||||
int ret = 0;
|
||||
@@ -12091,13 +12292,6 @@ int wc_AesXtsSetKey(XtsAes* aes, const byte* key, word32 len, int dir,
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if ((ret = wc_AesInit(&aes->tweak, heap, devId)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
if ((ret = wc_AesInit(&aes->aes, heap, devId)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
keySz = len/2;
|
||||
if (keySz != 16 && keySz != 32) {
|
||||
WOLFSSL_MSG("Unsupported key size");
|
||||
@@ -12123,6 +12317,33 @@ int wc_AesXtsSetKey(XtsAes* aes, const byte* key, word32 len, int dir,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Combined call to wc_AesXtsInit() and wc_AesXtsSetKeyNoInit().
|
||||
*
|
||||
* Note: is up to user to call wc_AesXtsFree when done.
|
||||
*
|
||||
* return 0 on success
|
||||
*/
|
||||
int wc_AesXtsSetKey(XtsAes* aes, const byte* key, word32 len, int dir,
|
||||
void* heap, int devId)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (aes == NULL || key == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
ret = wc_AesXtsInit(aes, heap, devId);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = wc_AesXtsSetKeyNoInit(aes, key, len, dir);
|
||||
|
||||
if (ret != 0)
|
||||
wc_AesXtsFree(aes);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* This is used to free up resources used by Aes structs
|
||||
*
|
||||
@@ -13027,6 +13248,7 @@ int wc_AesEaxEncryptAuth(const byte* key, word32 keySz, byte* out,
|
||||
AesEax *eax = &eax_mem;
|
||||
#endif
|
||||
int ret;
|
||||
int eaxInited = 0;
|
||||
|
||||
if (key == NULL || out == NULL || in == NULL || nonce == NULL
|
||||
|| authTag == NULL || authIn == NULL) {
|
||||
@@ -13047,6 +13269,7 @@ int wc_AesEaxEncryptAuth(const byte* key, word32 keySz, byte* out,
|
||||
authIn, authInSz)) != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
eaxInited = 1;
|
||||
|
||||
if ((ret = wc_AesEaxEncryptUpdate(eax, out, in, inSz, NULL, 0)) != 0) {
|
||||
goto cleanup;
|
||||
@@ -13057,7 +13280,8 @@ int wc_AesEaxEncryptAuth(const byte* key, word32 keySz, byte* out,
|
||||
}
|
||||
|
||||
cleanup:
|
||||
wc_AesEaxFree(eax);
|
||||
if (eaxInited)
|
||||
wc_AesEaxFree(eax);
|
||||
#if defined(WOLFSSL_SMALL_STACK)
|
||||
XFREE(eax, NULL, DYNAMIC_TYPE_AES_EAX);
|
||||
#endif
|
||||
@@ -13087,6 +13311,7 @@ int wc_AesEaxDecryptAuth(const byte* key, word32 keySz, byte* out,
|
||||
AesEax *eax = &eax_mem;
|
||||
#endif
|
||||
int ret;
|
||||
int eaxInited = 0;
|
||||
|
||||
if (key == NULL || out == NULL || in == NULL || nonce == NULL
|
||||
|| authTag == NULL || authIn == NULL) {
|
||||
@@ -13108,6 +13333,7 @@ int wc_AesEaxDecryptAuth(const byte* key, word32 keySz, byte* out,
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
eaxInited = 1;
|
||||
|
||||
if ((ret = wc_AesEaxDecryptUpdate(eax, out, in, inSz, NULL, 0)) != 0) {
|
||||
goto cleanup;
|
||||
@@ -13118,7 +13344,8 @@ int wc_AesEaxDecryptAuth(const byte* key, word32 keySz, byte* out,
|
||||
}
|
||||
|
||||
cleanup:
|
||||
wc_AesEaxFree(eax);
|
||||
if (eaxInited)
|
||||
wc_AesEaxFree(eax);
|
||||
#if defined(WOLFSSL_SMALL_STACK)
|
||||
XFREE(eax, NULL, DYNAMIC_TYPE_AES_EAX);
|
||||
#endif
|
||||
@@ -13141,6 +13368,9 @@ int wc_AesEaxInit(AesEax* eax,
|
||||
{
|
||||
int ret = 0;
|
||||
word32 cmacSize;
|
||||
int aesInited = 0;
|
||||
int nonceCmacInited = 0;
|
||||
int aadCmacInited = 0;
|
||||
|
||||
if (eax == NULL || key == NULL || nonce == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
@@ -13149,14 +13379,16 @@ int wc_AesEaxInit(AesEax* eax,
|
||||
XMEMSET(eax->prefixBuf, 0, sizeof(eax->prefixBuf));
|
||||
|
||||
if ((ret = wc_AesInit(&eax->aes, NULL, INVALID_DEVID)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
aesInited = 1;
|
||||
|
||||
if ((ret = wc_AesSetKey(&eax->aes,
|
||||
key,
|
||||
keySz,
|
||||
NULL,
|
||||
AES_ENCRYPTION)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -13170,26 +13402,27 @@ int wc_AesEaxInit(AesEax* eax,
|
||||
NULL)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
nonceCmacInited = 1;
|
||||
|
||||
if ((ret = wc_CmacUpdate(&eax->nonceCmac,
|
||||
eax->prefixBuf,
|
||||
sizeof(eax->prefixBuf))) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((ret = wc_CmacUpdate(&eax->nonceCmac, nonce, nonceSz)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
cmacSize = AES_BLOCK_SIZE;
|
||||
if ((ret = wc_CmacFinal(&eax->nonceCmac,
|
||||
eax->nonceCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((ret = wc_AesSetIV(&eax->aes, eax->nonceCmacFinal)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -13204,18 +13437,19 @@ int wc_AesEaxInit(AesEax* eax,
|
||||
keySz,
|
||||
WC_CMAC_AES,
|
||||
NULL)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
aadCmacInited = 1;
|
||||
|
||||
if ((ret = wc_CmacUpdate(&eax->aadCmac,
|
||||
eax->prefixBuf,
|
||||
sizeof(eax->prefixBuf))) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (authIn != NULL) {
|
||||
if ((ret = wc_CmacUpdate(&eax->aadCmac, authIn, authInSz)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13230,13 +13464,24 @@ int wc_AesEaxInit(AesEax* eax,
|
||||
keySz,
|
||||
WC_CMAC_AES,
|
||||
NULL)) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((ret = wc_CmacUpdate(&eax->ciphertextCmac,
|
||||
eax->prefixBuf,
|
||||
sizeof(eax->prefixBuf))) != 0) {
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
if (ret != 0) {
|
||||
if (aesInited)
|
||||
wc_AesFree(&eax->aes);
|
||||
if (nonceCmacInited)
|
||||
wc_CmacFree(&eax->nonceCmac);
|
||||
if (aadCmacInited)
|
||||
wc_CmacFree(&eax->aadCmac);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -13367,17 +13612,17 @@ int wc_AesEaxEncryptFinal(AesEax* eax, byte* authTag, word32 authTagSz)
|
||||
|
||||
/* Complete the OMAC for the ciphertext */
|
||||
cmacSize = AES_BLOCK_SIZE;
|
||||
if ((ret = wc_CmacFinal(&eax->ciphertextCmac,
|
||||
eax->ciphertextCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
if ((ret = wc_CmacFinalNoFree(&eax->ciphertextCmac,
|
||||
eax->ciphertextCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Complete the OMAC for auth data */
|
||||
cmacSize = AES_BLOCK_SIZE;
|
||||
if ((ret = wc_CmacFinal(&eax->aadCmac,
|
||||
eax->aadCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
if ((ret = wc_CmacFinalNoFree(&eax->aadCmac,
|
||||
eax->aadCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -13424,17 +13669,17 @@ int wc_AesEaxDecryptFinal(AesEax* eax,
|
||||
|
||||
/* Complete the OMAC for the ciphertext */
|
||||
cmacSize = AES_BLOCK_SIZE;
|
||||
if ((ret = wc_CmacFinal(&eax->ciphertextCmac,
|
||||
eax->ciphertextCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
if ((ret = wc_CmacFinalNoFree(&eax->ciphertextCmac,
|
||||
eax->ciphertextCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Complete the OMAC for auth data */
|
||||
cmacSize = AES_BLOCK_SIZE;
|
||||
if ((ret = wc_CmacFinal(&eax->aadCmac,
|
||||
eax->aadCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
if ((ret = wc_CmacFinalNoFree(&eax->aadCmac,
|
||||
eax->aadCmacFinal,
|
||||
&cmacSize)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -13471,8 +13716,8 @@ int wc_AesEaxDecryptFinal(AesEax* eax,
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees the underlying AES context. Must be called when done using the AES EAX
|
||||
* context structure
|
||||
* Frees the underlying CMAC and AES contexts. Must be called when done using
|
||||
* the AES EAX context structure.
|
||||
*
|
||||
* Returns 0 on success
|
||||
* Returns error code on failure
|
||||
@@ -13483,6 +13728,8 @@ int wc_AesEaxFree(AesEax* eax)
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
(void)wc_CmacFree(&eax->ciphertextCmac);
|
||||
(void)wc_CmacFree(&eax->aadCmac);
|
||||
wc_AesFree(&eax->aes);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -223,8 +223,24 @@ int wc_CmacUpdate(Cmac* cmac, const byte* in, word32 inSz)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wc_CmacFree(Cmac* cmac)
|
||||
{
|
||||
if (cmac == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
#if defined(WOLFSSL_HASH_KEEP)
|
||||
/* TODO: msg is leaked if wc_CmacFinal() is not called
|
||||
* e.g. when multiple calls to wc_CmacUpdate() and one fails but
|
||||
* wc_CmacFinal() not called. */
|
||||
if (cmac->msg != NULL) {
|
||||
XFREE(cmac->msg, cmac->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
}
|
||||
#endif
|
||||
wc_AesFree(&cmac->aes);
|
||||
ForceZero(cmac, sizeof(Cmac));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wc_CmacFinal(Cmac* cmac, byte* out, word32* outSz)
|
||||
int wc_CmacFinalNoFree(Cmac* cmac, byte* out, word32* outSz)
|
||||
{
|
||||
int ret;
|
||||
const byte* subKey;
|
||||
@@ -276,21 +292,18 @@ int wc_CmacFinal(Cmac* cmac, byte* out, word32* outSz)
|
||||
XMEMCPY(out, cmac->digest, *outSz);
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HASH_KEEP)
|
||||
/* TODO: msg is leaked if wc_CmacFinal() is not called
|
||||
* e.g. when multiple calls to wc_CmacUpdate() and one fails but
|
||||
* wc_CmacFinal() not called. */
|
||||
if (cmac->msg != NULL) {
|
||||
XFREE(cmac->msg, cmac->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
cmac->msg = NULL;
|
||||
}
|
||||
#endif
|
||||
wc_AesFree(&cmac->aes);
|
||||
ForceZero(cmac, sizeof(Cmac));
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wc_CmacFinal(Cmac* cmac, byte* out, word32* outSz) {
|
||||
int ret;
|
||||
|
||||
if (cmac == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
ret = wc_CmacFinalNoFree(cmac, out, outSz);
|
||||
(void)wc_CmacFree(cmac);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wc_AesCmacGenerate(byte* out, word32* outSz,
|
||||
const byte* in, word32 inSz,
|
||||
|
||||
@@ -1225,19 +1225,18 @@ int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
IncCtr((byte*)ctx->cipher.aes.reg, ctx->cipher.aes.nonceSz);
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
/* Reinitialize for subsequent wolfSSL_EVP_Cipher calls. */
|
||||
if (wc_AesGcmInit(&ctx->cipher.aes, NULL, 0,
|
||||
(byte*)ctx->cipher.aes.reg,
|
||||
(word32)ctx->ivSz) != 0) {
|
||||
WOLFSSL_MSG("wc_AesGcmInit failed");
|
||||
ret = WOLFSSL_FAILURE;
|
||||
}
|
||||
else {
|
||||
ret = WOLFSSL_SUCCESS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
if (ret == 0)
|
||||
ret = WOLFSSL_SUCCESS;
|
||||
else
|
||||
ret = WOLFSSL_FAILURE;
|
||||
|
||||
/* Reinitialize for subsequent wolfSSL_EVP_Cipher calls. */
|
||||
if (wc_AesGcmInit(&ctx->cipher.aes, NULL, 0,
|
||||
(byte*)ctx->cipher.aes.reg,
|
||||
(word32)ctx->ivSz) != 0)
|
||||
{
|
||||
WOLFSSL_MSG("wc_AesGcmInit failed");
|
||||
ret = WOLFSSL_FAILURE;
|
||||
}
|
||||
#endif /* WOLFSSL_AESGCM_STREAM */
|
||||
@@ -4841,7 +4840,7 @@ static const struct cipher{
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AES_OFB
|
||||
#ifdef WOLFSSL_AES_OFB
|
||||
#ifdef WOLFSSL_AES_128
|
||||
{AES_128_OFB_TYPE, EVP_AES_128_OFB, NID_aes_128_ofb},
|
||||
#endif
|
||||
@@ -4853,7 +4852,7 @@ static const struct cipher{
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AES_XTS
|
||||
#ifdef WOLFSSL_AES_XTS
|
||||
#ifdef WOLFSSL_AES_128
|
||||
{AES_128_XTS_TYPE, EVP_AES_128_XTS, NID_aes_128_xts},
|
||||
#endif
|
||||
@@ -6075,34 +6074,34 @@ void wolfSSL_EVP_init(void)
|
||||
}
|
||||
|
||||
/* WOLFSSL_SUCCESS on ok */
|
||||
int wolfSSL_EVP_CIPHER_CTX_cleanup(WOLFSSL_EVP_CIPHER_CTX* ctx)
|
||||
static int wolfSSL_EVP_CIPHER_CTX_cleanup_cipher(
|
||||
WOLFSSL_EVP_CIPHER_CTX* ctx)
|
||||
{
|
||||
int ret = WOLFSSL_SUCCESS;
|
||||
WOLFSSL_ENTER("wolfSSL_EVP_CIPHER_CTX_cleanup");
|
||||
if (ctx) {
|
||||
#if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
|
||||
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
|
||||
switch (ctx->cipherType) {
|
||||
#if (defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)) || \
|
||||
defined(HAVE_AESCCM) || \
|
||||
defined(HAVE_AESCBC) || \
|
||||
defined(HAVE_AES_CBC) || \
|
||||
defined(WOLFSSL_AES_COUNTER) || \
|
||||
defined(HAVE_AES_ECB) || \
|
||||
defined(HAVE_AES_CFB) || \
|
||||
defined(HAVE_AES_OFB) || \
|
||||
defined(WOLFSSL_AES_CFB) || \
|
||||
defined(WOLFSSL_AES_OFB) || \
|
||||
defined(WOLFSSL_AES_XTS)
|
||||
|
||||
#if defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)
|
||||
#if defined(HAVE_AESGCM)
|
||||
case AES_128_GCM_TYPE:
|
||||
case AES_192_GCM_TYPE:
|
||||
case AES_256_GCM_TYPE:
|
||||
#endif /* HAVE_AESGCM && WOLFSSL_AESGCM_STREAM */
|
||||
#endif /* HAVE_AESGCM */
|
||||
#if defined(HAVE_AESCCM)
|
||||
case AES_128_CCM_TYPE:
|
||||
case AES_192_CCM_TYPE:
|
||||
case AES_256_CCM_TYPE:
|
||||
#endif /* HAVE_AESCCM */
|
||||
#ifdef HAVE_AESCBC
|
||||
#ifdef HAVE_AES_CBC
|
||||
case AES_128_CBC_TYPE:
|
||||
case AES_192_CBC_TYPE:
|
||||
case AES_256_CBC_TYPE:
|
||||
@@ -6117,7 +6116,7 @@ void wolfSSL_EVP_init(void)
|
||||
case AES_192_ECB_TYPE:
|
||||
case AES_256_ECB_TYPE:
|
||||
#endif
|
||||
#ifdef HAVE_AES_CFB
|
||||
#ifdef WOLFSSL_AES_CFB
|
||||
case AES_128_CFB1_TYPE:
|
||||
case AES_192_CFB1_TYPE:
|
||||
case AES_256_CFB1_TYPE:
|
||||
@@ -6128,17 +6127,21 @@ void wolfSSL_EVP_init(void)
|
||||
case AES_192_CFB128_TYPE:
|
||||
case AES_256_CFB128_TYPE:
|
||||
#endif
|
||||
#ifdef HAVE_AES_OFB
|
||||
#ifdef WOLFSSL_AES_OFB
|
||||
case AES_128_OFB_TYPE:
|
||||
case AES_192_OFB_TYPE:
|
||||
case AES_256_OFB_TYPE:
|
||||
#endif
|
||||
wc_AesFree(&ctx->cipher.aes);
|
||||
ctx->flags &= ~WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
break;
|
||||
#ifdef WOLFSSL_AES_XTS
|
||||
case AES_128_XTS_TYPE:
|
||||
case AES_256_XTS_TYPE:
|
||||
#endif
|
||||
wc_AesFree(&ctx->cipher.aes);
|
||||
wc_AesXtsFree(&ctx->cipher.xts);
|
||||
ctx->flags &= ~WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
break;
|
||||
#endif
|
||||
#endif /* AES */
|
||||
#ifdef HAVE_ARIA
|
||||
case ARIA_128_GCM_TYPE:
|
||||
@@ -6177,7 +6180,16 @@ void wolfSSL_EVP_init(void)
|
||||
wc_Sm4Free(&ctx->cipher.sm4);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wolfSSL_EVP_CIPHER_CTX_cleanup(WOLFSSL_EVP_CIPHER_CTX* ctx)
|
||||
{
|
||||
int ret = WOLFSSL_SUCCESS;
|
||||
WOLFSSL_ENTER("wolfSSL_EVP_CIPHER_CTX_cleanup");
|
||||
if (ctx) {
|
||||
wolfSSL_EVP_CIPHER_CTX_cleanup_cipher(ctx);
|
||||
ctx->cipherType = WOLFSSL_EVP_CIPH_TYPE_INIT; /* not yet initialized */
|
||||
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
||||
if (ctx->key) {
|
||||
@@ -6362,6 +6374,13 @@ void wolfSSL_EVP_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
ret = WOLFSSL_FAILURE;
|
||||
else
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
|
||||
#ifndef WOLFSSL_AESGCM_STREAM
|
||||
if (ret == WOLFSSL_SUCCESS && key &&
|
||||
wc_AesGcmSetKey(&ctx->cipher.aes, key, ctx->keyLen)) {
|
||||
@@ -6486,7 +6505,7 @@ void wolfSSL_EVP_init(void)
|
||||
(byte*)ctx->cipher.aes.reg,
|
||||
(word32)ctx->ivSz) != 0) {
|
||||
WOLFSSL_MSG("wc_AesGcmInit failed");
|
||||
return WOLFSSL_FATAL_ERROR;
|
||||
return WOLFSSL_FAILURE;
|
||||
}
|
||||
ctx->authIncIv = 0;
|
||||
}
|
||||
@@ -6562,6 +6581,16 @@ void wolfSSL_EVP_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0) {
|
||||
WOLFSSL_MSG("wc_AesInit() failed");
|
||||
ret = WOLFSSL_FAILURE;
|
||||
} else
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS && key &&
|
||||
wc_AesCcmSetKey(&ctx->cipher.aes, key, (word32)ctx->keyLen)) {
|
||||
WOLFSSL_MSG("wc_AesCcmSetKey() failed");
|
||||
@@ -6737,6 +6766,7 @@ void wolfSSL_EVP_init(void)
|
||||
XMEMSET(&ctx->cipher, 0, sizeof(ctx->cipher));
|
||||
ctx->flags = 0;
|
||||
}
|
||||
|
||||
/* always clear buffer state */
|
||||
ctx->bufUsed = 0;
|
||||
ctx->lastUsed = 0;
|
||||
@@ -6761,11 +6791,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->ivSz = AES_BLOCK_SIZE;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -6790,6 +6821,11 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->ivSz = AES_BLOCK_SIZE;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0);
|
||||
@@ -6815,6 +6851,11 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->ivSz = AES_BLOCK_SIZE;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 0);
|
||||
@@ -6872,7 +6913,8 @@ void wolfSSL_EVP_init(void)
|
||||
|| ctx->cipherType == AES_256_CCM_TYPE ||
|
||||
(type && EVP_CIPHER_TYPE_MATCHES(type, EVP_AES_256_CCM))
|
||||
#endif
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (EvpCipherInitAesCCM(ctx, type, key, iv, enc)
|
||||
!= WOLFSSL_SUCCESS) {
|
||||
return WOLFSSL_FAILURE;
|
||||
@@ -6896,6 +6938,11 @@ void wolfSSL_EVP_init(void)
|
||||
#endif
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 1);
|
||||
@@ -6924,6 +6971,11 @@ void wolfSSL_EVP_init(void)
|
||||
#endif
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 1);
|
||||
@@ -6952,6 +7004,11 @@ void wolfSSL_EVP_init(void)
|
||||
#endif
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 1);
|
||||
@@ -6978,6 +7035,11 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = AES_BLOCK_SIZE;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
NULL, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1);
|
||||
@@ -6997,6 +7059,11 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = AES_BLOCK_SIZE;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
NULL, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1);
|
||||
@@ -7016,6 +7083,11 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = AES_BLOCK_SIZE;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
NULL, ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, 1);
|
||||
@@ -7037,11 +7109,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7065,11 +7138,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7093,11 +7167,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0){
|
||||
@@ -7125,11 +7200,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7153,11 +7229,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7181,11 +7258,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0){
|
||||
@@ -7213,11 +7291,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7241,11 +7320,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7269,11 +7349,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0){
|
||||
@@ -7303,11 +7384,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7331,11 +7413,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0)
|
||||
@@ -7359,11 +7442,12 @@ void wolfSSL_EVP_init(void)
|
||||
ctx->block_size = 1;
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
if (key) {
|
||||
ret = wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
if (wc_AesInit(&ctx->cipher.aes, NULL, INVALID_DEVID) != 0)
|
||||
return WOLFSSL_FAILURE;
|
||||
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
if (key) {
|
||||
ret = AesSetKey_ex(&ctx->cipher.aes, key, (word32)ctx->keyLen,
|
||||
iv, AES_ENCRYPTION, 0);
|
||||
if (ret != 0){
|
||||
@@ -7380,7 +7464,7 @@ void wolfSSL_EVP_init(void)
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_AES_256 */
|
||||
#endif /* HAVE_AES_OFB */
|
||||
#endif /* WOLFSSL_AES_OFB */
|
||||
#ifdef WOLFSSL_AES_XTS
|
||||
#ifdef WOLFSSL_AES_128
|
||||
if (ctx->cipherType == AES_128_XTS_TYPE ||
|
||||
@@ -7402,10 +7486,20 @@ void wolfSSL_EVP_init(void)
|
||||
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
ret = wc_AesXtsInit(&ctx->cipher.xts, NULL, 0);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("wc_AesXtsInit() failed");
|
||||
return WOLFSSL_FAILURE;
|
||||
}
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
|
||||
if (key) {
|
||||
ret = wc_AesXtsSetKey(&ctx->cipher.xts, key,
|
||||
ret = wc_AesXtsSetKeyNoInit(&ctx->cipher.xts, key,
|
||||
(word32)ctx->keyLen,
|
||||
ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, NULL, 0);
|
||||
ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("wc_AesXtsSetKey() failed");
|
||||
return WOLFSSL_FAILURE;
|
||||
@@ -7433,10 +7527,20 @@ void wolfSSL_EVP_init(void)
|
||||
|
||||
if (enc == 0 || enc == 1)
|
||||
ctx->enc = enc ? 1 : 0;
|
||||
|
||||
if (! (ctx->flags & WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED)) {
|
||||
ret = wc_AesXtsInit(&ctx->cipher.xts, NULL, 0);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("wc_AesXtsInit() failed");
|
||||
return WOLFSSL_FAILURE;
|
||||
}
|
||||
ctx->flags |= WOLFSSL_EVP_CIPH_LOW_LEVEL_INITED;
|
||||
}
|
||||
|
||||
if (key) {
|
||||
ret = wc_AesXtsSetKey(&ctx->cipher.xts, key,
|
||||
ret = wc_AesXtsSetKeyNoInit(&ctx->cipher.xts, key,
|
||||
(word32)ctx->keyLen,
|
||||
ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION, NULL, 0);
|
||||
ctx->enc ? AES_ENCRYPTION : AES_DECRYPTION);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("wc_AesXtsSetKey() failed");
|
||||
return WOLFSSL_FAILURE;
|
||||
@@ -7444,7 +7548,7 @@ void wolfSSL_EVP_init(void)
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_AES_256 */
|
||||
#endif /* HAVE_AES_XTS */
|
||||
#endif /* WOLFSSL_AES_XTS */
|
||||
#endif /* NO_AES */
|
||||
#if defined(HAVE_ARIA)
|
||||
if (ctx->cipherType == ARIA_128_GCM_TYPE ||
|
||||
|
||||
@@ -1438,6 +1438,70 @@ void __attribute__((no_instrument_function))
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WC_DEBUG_CIPHER_LIFECYCLE
|
||||
static const byte wc_debug_cipher_lifecycle_tag_value[] =
|
||||
{ 'W', 'o', 'l', 'f' };
|
||||
|
||||
WOLFSSL_LOCAL int wc_debug_CipherLifecycleInit(
|
||||
void **CipherLifecycleTag,
|
||||
void *heap)
|
||||
{
|
||||
if (CipherLifecycleTag == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
*CipherLifecycleTag = (void *)XMALLOC(
|
||||
sizeof(wc_debug_cipher_lifecycle_tag_value),
|
||||
heap,
|
||||
DYNAMIC_TYPE_DEBUG_TAG);
|
||||
if (*CipherLifecycleTag == NULL)
|
||||
return MEMORY_E;
|
||||
XMEMCPY(*CipherLifecycleTag,
|
||||
wc_debug_cipher_lifecycle_tag_value,
|
||||
sizeof(wc_debug_cipher_lifecycle_tag_value));
|
||||
return 0;
|
||||
}
|
||||
|
||||
WOLFSSL_LOCAL int wc_debug_CipherLifecycleCheck(
|
||||
void *CipherLifecycleTag,
|
||||
int abort_p)
|
||||
{
|
||||
int ret;
|
||||
if (CipherLifecycleTag == NULL) {
|
||||
ret = BAD_STATE_E;
|
||||
goto out;
|
||||
}
|
||||
if (XMEMCMP(CipherLifecycleTag,
|
||||
wc_debug_cipher_lifecycle_tag_value,
|
||||
sizeof(wc_debug_cipher_lifecycle_tag_value)) != 0)
|
||||
{
|
||||
ret = BAD_STATE_E;
|
||||
goto out;
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
if ((ret < 0) && abort_p)
|
||||
abort();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(
|
||||
void **CipherLifecycleTag,
|
||||
void *heap,
|
||||
int abort_p)
|
||||
{
|
||||
int ret;
|
||||
if (CipherLifecycleTag == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
ret = wc_debug_CipherLifecycleCheck(*CipherLifecycleTag, abort_p);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
XFREE(*CipherLifecycleTag, heap, DYNAMIC_TYPE_DEBUG_TAG);
|
||||
*CipherLifecycleTag = NULL;
|
||||
return 0;
|
||||
}
|
||||
#endif /* WC_DEBUG_CIPHER_LIFECYCLE */
|
||||
|
||||
#ifdef DEBUG_VECTOR_REGISTER_ACCESS
|
||||
THREAD_LS_T int wc_svr_count = 0;
|
||||
THREAD_LS_T const char *wc_svr_last_file = NULL;
|
||||
|
||||
@@ -58,6 +58,14 @@ static int wc_AesSetup(Aes* aes, const char* type, const char* name, int ivSz, i
|
||||
byte* key = (byte*)aes->key;
|
||||
#endif
|
||||
|
||||
if (aes->alFd <= 0) {
|
||||
aes->alFd = wc_Afalg_Socket();
|
||||
if (aes->alFd < 0) {
|
||||
WOLFSSL_MSG("Unable to open an AF_ALG socket");
|
||||
return WC_AFALG_SOCK_E;
|
||||
}
|
||||
}
|
||||
|
||||
aes->rdFd = wc_Afalg_CreateRead(aes->alFd, type, name);
|
||||
if (aes->rdFd < 0) {
|
||||
WOLFSSL_MSG("Unable to accept and get AF_ALG read socket");
|
||||
|
||||
Reference in New Issue
Block a user