wolfcrypt/src/aes.c: in AES-XTS AESNI, use cautious strategy as in AESGCM_STREAM for SAVE_VECTOR_REGISTERS, due to random failures seen with DEBUG_VECTOR_REGISTER_ACCESS_FUZZING using the old per-call fallback strategy.

pull/7434/head
Daniel Pouzzner 2024-04-16 17:14:25 -05:00
parent b2f594e84b
commit 9f55dba2f2
1 changed files with 4 additions and 46 deletions

View File

@ -12726,19 +12726,8 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
{
#ifdef WOLFSSL_AESNI
#ifdef WC_AES_C_DYNAMIC_FALLBACK
int orig_use_aesni = aes->use_aesni;
#endif
if (aes->use_aesni && ((ret = SAVE_VECTOR_REGISTERS2()) != 0)) {
#ifdef WC_AES_C_DYNAMIC_FALLBACK
aes->use_aesni = 0;
xaes->tweak.use_aesni = 0;
#else
return ret;
#endif
}
if (aes->use_aesni) {
SAVE_VECTOR_REGISTERS(return _svr_ret;);
#if defined(HAVE_INTEL_AVX1)
if (IS_INTEL_AVX1(intel_flags)) {
AES_XTS_encrypt_avx1(in, out, sz, i,
@ -12756,23 +12745,13 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
(int)aes->rounds);
ret = 0;
}
RESTORE_VECTOR_REGISTERS();
}
else
#endif
{
ret = AesXtsEncrypt_sw(xaes, out, in, sz, i);
}
#ifdef WOLFSSL_AESNI
if (aes->use_aesni)
RESTORE_VECTOR_REGISTERS();
#ifdef WC_AES_C_DYNAMIC_FALLBACK
else if (orig_use_aesni) {
aes->use_aesni = orig_use_aesni;
xaes->tweak.use_aesni = orig_use_aesni;
}
#endif
#endif
}
return ret;
@ -12962,19 +12941,8 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
{
#ifdef WOLFSSL_AESNI
#ifdef WC_AES_C_DYNAMIC_FALLBACK
int orig_use_aesni = aes->use_aesni;
#endif
if (aes->use_aesni && ((ret = SAVE_VECTOR_REGISTERS2() != 0))) {
#ifdef WC_AES_C_DYNAMIC_FALLBACK
aes->use_aesni = 0;
xaes->tweak.use_aesni = 0;
#else
return ret;
#endif
}
if (aes->use_aesni) {
SAVE_VECTOR_REGISTERS(return _svr_ret;);
#if defined(HAVE_INTEL_AVX1)
if (IS_INTEL_AVX1(intel_flags)) {
AES_XTS_decrypt_avx1(in, out, sz, i,
@ -12992,6 +12960,7 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
(int)aes->rounds);
ret = 0;
}
RESTORE_VECTOR_REGISTERS();
}
else
#endif
@ -12999,17 +12968,6 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
ret = AesXtsDecrypt_sw(xaes, out, in, sz, i);
}
#ifdef WOLFSSL_AESNI
if (aes->use_aesni)
RESTORE_VECTOR_REGISTERS();
#ifdef WC_AES_C_DYNAMIC_FALLBACK
else if (orig_use_aesni) {
aes->use_aesni = orig_use_aesni;
xaes->tweak.use_aesni = orig_use_aesni;
}
#endif
#endif
return ret;
}
}