From 6267657492199576ff6ac83b2b80f2cb47e3c372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Tro=C3=9Fbach?= Date: Fri, 11 Sep 2026 13:01:03 +0200 Subject: [PATCH] Use AES hardware support on Apple arm64 and with GCC on aarch64 On 64-bit Apple ARM platforms the NEON AES code was compiled, but the runtime check always reported that no hardware support is available, so the table-based software implementation was used. With GCC on aarch64 no hardware code path was compiled at all, unless the crypto extension was enabled via compiler flags. - Report AES hardware support on 64-bit Apple ARM platforms (macOS, iOS, iPadOS, tvOS, watchOS, visionOS) - Enable the NEON AES code path for GCC >= 6 on aarch64 via a function target attribute, analogous to the existing clang handling --- src/aes_hardware.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/aes_hardware.c b/src/aes_hardware.c index 0a966e34..8c190e50 100644 --- a/src/aes_hardware.c +++ b/src/aes_hardware.c @@ -41,6 +41,13 @@ #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) && (defined(__x86_64__) || defined(__i386)) #define HAS_AES_HARDWARE AES_HARDWARE_NI + +#elif (__GNUC__ >= 6) && defined(__aarch64__) +#define HAS_AES_HARDWARE AES_HARDWARE_NEON + +/* Crypto extension in AArch64 can be enabled using __attribute__((target)) */ +#define USE_GCC_ATTR_TARGET_AARCH64 + #endif @@ -461,6 +468,10 @@ aesDecryptCBC(const unsigned char* in, #define FUNC_ISA __attribute__ ((target("neon,crypto"))) #endif /* USE_CLANG_ATTR_TARGET_AARCH64 */ +#ifdef USE_GCC_ATTR_TARGET_AARCH64 +#define FUNC_ISA __attribute__ ((target("+crypto"))) +#endif /* USE_GCC_ATTR_TARGET_AARCH64 */ + /* FUNCtion attributes for ISA (Instruction Set Architecture) */ #ifndef FUNC_ISA #define FUNC_ISA @@ -497,6 +508,18 @@ aesHardwareAvailableOnPlatform() return (int) IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE); } +#elif defined(__APPLE__) && (defined(__aarch64__) || defined(__arm64__)) + +/* +** All 64-bit ARM processors used by Apple (A7 and later, M1 and later) +** implement the ARMv8 cryptographic extensions +*/ +static int +aesHardwareAvailableOnPlatform() +{ + return 1; +} + #else static int