From 8189f3294589f246f9810683242018c8f5c9caca Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Thu, 10 Aug 2023 13:53:41 +0800 Subject: [PATCH] improve aesni check for x86_64 `MBEDTLS_AESNI_C` does not depends on `MBEDTLS_HAVE_ASM` when intrinsic is available. And compiler relative checks only work on x86_64, it should be only checked on x86_64. Signed-off-by: Jerry Yu --- library/aes.c | 3 +-- library/aesni.h | 12 +++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/library/aes.c b/library/aes.c index 52e361a283..4cb9ce1c14 100644 --- a/library/aes.c +++ b/library/aes.c @@ -40,8 +40,7 @@ #endif #endif -#if defined(MBEDTLS_HAVE_ASM) && \ - (defined(__amd64__) || defined(__x86_64__)) +#if defined(__amd64__) || defined(__x86_64__) #if !defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_AES_USE_HARDWARE_ONLY) #error "MBEDTLS_AES_USE_HARDWARE_ONLY defined, but not all prerequisites" #endif diff --git a/library/aesni.h b/library/aesni.h index f461ae2887..da97023cbe 100644 --- a/library/aesni.h +++ b/library/aesni.h @@ -35,13 +35,13 @@ /* Can we do AESNI with inline assembly? * (Only implemented with gas syntax, only for 64-bit.) */ -#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \ - (defined(__amd64__) || defined(__x86_64__)) && \ - !defined(MBEDTLS_HAVE_X86_64) +#if !defined(MBEDTLS_HAVE_X86_64) && \ + (defined(__amd64__) || defined(__x86_64__) || \ + defined(_M_X64) || defined(_M_AMD64)) #define MBEDTLS_HAVE_X86_64 #endif -#if defined(MBEDTLS_AESNI_C) +#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) /* Can we do AESNI with intrinsics? * (Only implemented with certain compilers, only for certain targets.) @@ -67,8 +67,10 @@ * In the long run, we will likely remove the assembly implementation. */ #if defined(MBEDTLS_AESNI_HAVE_INTRINSICS) #define MBEDTLS_AESNI_HAVE_CODE 2 // via intrinsics -#elif defined(MBEDTLS_HAVE_X86_64) +#elif defined(MBEDTLS_HAVE_ASM) #define MBEDTLS_AESNI_HAVE_CODE 1 // via assembly +#else +#error "MBEDTLS_AESNI_C defined, but neither intrinsics nor assembly available" #endif #if defined(MBEDTLS_AESNI_HAVE_CODE)