From b359dd27e45e1a9608daa8ba5b99ac535c51b6e7 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Fri, 10 Feb 2023 11:14:06 +1000 Subject: [PATCH] AES ECB/CTR/XTS: enable AES-NI usage Perform multiple blocks of encryption/decryption in assembly call with ECB. This improves performance of ECB, CTR and XTS on Intel x64. --- wolfcrypt/src/aes.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index a5a119e91..63928bafe 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -10915,6 +10915,14 @@ static WARN_UNUSED_RESULT int _AesEcbEncrypt( #ifdef WOLFSSL_IMXRT_DCP if (aes->keylen == 16) return DCPAesEcbEncrypt(aes, out, in, sz); +#endif +#ifdef WOLFSSL_AESNI + if (haveAESNI && aes->use_aesni) { + SAVE_VECTOR_REGISTERS(return _svr_ret;); + AES_ECB_encrypt(in, out, sz, (byte*)aes->key, aes->rounds); + RESTORE_VECTOR_REGISTERS(); + blocks = 0; + } #endif while (blocks > 0) { int ret = wc_AesEncryptDirect(aes, out, in); @@ -10943,6 +10951,14 @@ static WARN_UNUSED_RESULT int _AesEcbDecrypt( #ifdef WOLFSSL_IMXRT_DCP if (aes->keylen == 16) return DCPAesEcbDecrypt(aes, out, in, sz); +#endif +#ifdef WOLFSSL_AESNI + if (haveAESNI && aes->use_aesni) { + SAVE_VECTOR_REGISTERS(return _svr_ret;); + AES_ECB_decrypt(in, out, sz, (byte*)aes->key, aes->rounds); + RESTORE_VECTOR_REGISTERS(); + blocks = 0; + } #endif while (blocks > 0) { int ret = wc_AesDecryptDirect(aes, out, in);