forked from wolfSSL/wolfssl
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.
This commit is contained in:
@ -12726,19 +12726,8 @@ int wc_AesXtsEncrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
|
|||||||
|
|
||||||
{
|
{
|
||||||
#ifdef WOLFSSL_AESNI
|
#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) {
|
if (aes->use_aesni) {
|
||||||
|
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||||
#if defined(HAVE_INTEL_AVX1)
|
#if defined(HAVE_INTEL_AVX1)
|
||||||
if (IS_INTEL_AVX1(intel_flags)) {
|
if (IS_INTEL_AVX1(intel_flags)) {
|
||||||
AES_XTS_encrypt_avx1(in, out, sz, i,
|
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);
|
(int)aes->rounds);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
RESTORE_VECTOR_REGISTERS();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ret = AesXtsEncrypt_sw(xaes, out, in, sz, i);
|
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;
|
return ret;
|
||||||
@ -12962,19 +12941,8 @@ int wc_AesXtsDecrypt(XtsAes* xaes, byte* out, const byte* in, word32 sz,
|
|||||||
|
|
||||||
{
|
{
|
||||||
#ifdef WOLFSSL_AESNI
|
#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) {
|
if (aes->use_aesni) {
|
||||||
|
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||||
#if defined(HAVE_INTEL_AVX1)
|
#if defined(HAVE_INTEL_AVX1)
|
||||||
if (IS_INTEL_AVX1(intel_flags)) {
|
if (IS_INTEL_AVX1(intel_flags)) {
|
||||||
AES_XTS_decrypt_avx1(in, out, sz, i,
|
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);
|
(int)aes->rounds);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
RESTORE_VECTOR_REGISTERS();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#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);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user