Skip to content

Fix issue with ARM ASM with AES CFB/OFB not initializing the "left" member #8099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3726,8 +3726,8 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
#if !defined(WOLFSSL_STM32_CUBEMX) || defined(STM32_HAL_V2)
ByteReverseWords(rk, rk, keylen);
#endif
#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif
return wc_AesSetIV(aes, iv);
Expand Down Expand Up @@ -3807,8 +3807,8 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
if (iv)
XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);

#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif

Expand Down Expand Up @@ -3838,8 +3838,8 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
aes->rounds = keylen/4 + 6;
XMEMCPY(aes->key, userKey, keylen);

#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif

Expand Down Expand Up @@ -3890,8 +3890,8 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
if (rk == NULL)
return BAD_FUNC_ARG;

#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif

Expand Down Expand Up @@ -3971,8 +3971,8 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
XMEMCPY(aes->key, userKey, keylen);
ret = nrf51_aes_set_key(userKey);

#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif

Expand Down Expand Up @@ -4028,7 +4028,8 @@ static WARN_UNUSED_RESULT int wc_AesDecrypt(
aes->rounds = keylen/4 + 6;

XMEMCPY(aes->key, userKey, keylen);
#if defined(WOLFSSL_AES_COUNTER)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif
return wc_AesSetIV(aes, iv);
Expand Down Expand Up @@ -4520,8 +4521,8 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
#endif
}

#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif

Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/port/Renesas/renesas_fspsm_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
return BAD_FUNC_ARG;
}

#ifdef WOLFSSL_AES_COUNTER
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif

Expand Down
8 changes: 5 additions & 3 deletions wolfcrypt/src/port/arm/armv8-aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
}
#endif

#ifdef WOLFSSL_AES_COUNTER
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif /* WOLFSSL_AES_COUNTER */

Expand Down Expand Up @@ -16581,9 +16582,10 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
XMEMCPY(aes->devKey, userKey, keylen);
}
#endif
#ifdef WOLFSSL_AES_COUNTER
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif /* WOLFSSL_AES_COUNTER */
#endif

aes->keylen = keylen;
aes->rounds = keylen/4 + 6;
Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/port/caam/caam_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 len,
return ret;
}

#ifdef WOLFSSL_AES_COUNTER
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif

Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/port/devcrypto/devcrypto_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,
aes->keylen = keylen;
aes->rounds = keylen/4 + 6;

#ifdef WOLFSSL_AES_COUNTER
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif
aes->ctx.cfd = -1;
Expand Down
12 changes: 6 additions & 6 deletions wolfcrypt/src/port/riscv/riscv-64-aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 keyLen, const byte* iv,
if (ret == 0) {
/* Finish setting the AES object. */
aes->keylen = keyLen;
#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif
}
Expand Down Expand Up @@ -1770,8 +1770,8 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 keyLen, const byte* iv,
if (ret == 0) {
/* Finish setting the AES object. */
aes->keylen = keyLen;
#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif
}
Expand Down Expand Up @@ -2978,8 +2978,8 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 keyLen, const byte* iv,

if (ret == 0) {
/* Initialize fields. */
#if defined(WOLFSSL_AES_CFB) || defined(WOLFSSL_AES_COUNTER) || \
defined(WOLFSSL_AES_OFB)
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif
aes->keylen = (int)keyLen;
Expand Down
3 changes: 2 additions & 1 deletion wolfcrypt/src/port/ti/ti-aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv, int dir)
aes->rounds = len / 4 + 6;

XMEMCPY(aes->key, key, len);
#ifdef WOLFSSL_AES_COUNTER
#if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
aes->left = 0;
#endif
return AesSetIV(aes, iv);
Expand Down
Loading