Skip to content
Open
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
34 changes: 30 additions & 4 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -18632,6 +18632,12 @@ static int AesXtsInitTweak_sw(XtsAes* xaes, byte* i) {

#endif /* WOLFSSL_AESXTS_STREAM */

/* The aarch64 crypto-extension lane of the streaming entry points. */
#if defined(__aarch64__) && defined(WOLFSSL_ARMASM) && \
!defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)
#define WC_AES_XTS_STREAM_AARCH64
#endif

#if !defined(WOLFSSL_ARMASM) || (!defined(__aarch64__) && \
defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)) || \
defined(WOLFSSL_ARM32_AES_DISPATCH) || defined(WOLFSSL_AESXTS_STREAM)
Expand Down Expand Up @@ -18999,15 +19005,16 @@ static int AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 s
{
int ret;

#if defined(WOLFSSL_AESNI)
#if defined(WOLFSSL_AESNI) || defined(WC_AES_XTS_STREAM_AARCH64)
Aes *aes;
#endif

if (xaes == NULL || out == NULL || in == NULL) {
return BAD_FUNC_ARG;
}

#if defined(WOLFSSL_AESNI)
#if defined(WOLFSSL_AESNI) || defined(WC_AES_XTS_STREAM_AARCH64)
/* Encryption always uses xaes->aes, both key layouts. */
aes = &xaes->aes;
#endif

Expand Down Expand Up @@ -19087,6 +19094,15 @@ static int AesXtsEncryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 s
}
else
#endif /* WOLFSSL_AESNI */
#ifdef WC_AES_XTS_STREAM_AARCH64
/* Same lane the one-shot wc_AesXtsEncrypt() takes. */
if (aes->use_aes_hw_crypto) {
AES_XTS_encrypt_update_AARCH64(in, out, sz, (byte*)aes->key,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aarch64 streaming XTS lane enabled for the MASM backend, which lacks the new routines · Logic errors

WC_AES_XTS_STREAM_AARCH64 is gated only on __aarch64__ && WOLFSSL_ARMASM && !WOLFSSL_ARMASM_NO_HW_CRYPTO, but armv8-aes-asm.asm (assembled by armasm64 for MSVC ARM64, where settings.h:429 maps _M_ARM64 to __aarch64__) defines no AES_XTS_encrypt_update_AARCH64/AES_XTS_decrypt_update_AARCH64. Those builds fail to link with WOLFSSL_AESXTS_STREAM.

Fix: Regenerate armv8-aes-asm.asm with the two streaming routines in this PR, or exclude the MASM backend from WC_AES_XTS_STREAM_AARCH64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MASM routines are added in #11370 and https://github.com/wolfSSL/scripts/pull/670. This is simply Fenrir being blind to the other two PR's, once both "J" branches are merged this will resolve, we can hold back the "L" branches till "J's" merge and re-run Fenrir.

stream->tweak_block, (byte*)aes->tmp, aes->rounds);
ret = 0;
}
else
#endif
{
ret = AesXtsEncryptUpdate_sw(xaes, out, in, sz, stream->tweak_block);
}
Expand Down Expand Up @@ -19568,15 +19584,15 @@ static int AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 s
struct XtsAesStreamData *stream)
{
int ret;
#if defined(WOLFSSL_AESNI)
#if defined(WOLFSSL_AESNI) || defined(WC_AES_XTS_STREAM_AARCH64)
Aes *aes;
#endif

if (xaes == NULL || out == NULL || in == NULL) {
return BAD_FUNC_ARG;
}

#if defined(WOLFSSL_AESNI)
#if defined(WOLFSSL_AESNI) || defined(WC_AES_XTS_STREAM_AARCH64)
#ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
aes = &xaes->aes_decrypt;
#else
Expand Down Expand Up @@ -19650,6 +19666,16 @@ static int AesXtsDecryptUpdate(XtsAes* xaes, byte* out, const byte* in, word32 s
}
else
#endif /* WOLFSSL_AESNI */
#ifdef WC_AES_XTS_STREAM_AARCH64
/* Same lane the one-shot wc_AesXtsDecrypt() takes. aes is the
* decrypt context resolved above, never xaes->aes. */
if (aes->use_aes_hw_crypto) {
AES_XTS_decrypt_update_AARCH64(in, out, sz, (byte*)aes->key,
stream->tweak_block, (byte*)aes->tmp, aes->rounds);
ret = 0;
}
else
#endif
{
ret = AesXtsDecryptUpdate_sw(xaes, out, in, sz,
stream->tweak_block);
Expand Down
Loading
Loading