From 8172bc55f834485f67be271e02c1167981423621 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 22 Oct 2026 00:14:31 +0900 Subject: [PATCH] Fix FreeBSD ARM64 hardware acceleration detection Use elf_aux_info(AT_HWCAP) to detect AES and SHA-256 support. Keep software fallbacks when the query fails or capabilities are absent. --- src/Crypto/cpu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Crypto/cpu.c b/src/Crypto/cpu.c index 3934107d..653869d9 100644 --- a/src/Crypto/cpu.c +++ b/src/Crypto/cpu.c @@ -479,7 +479,7 @@ void DisableCPUExtendedFeatures () #endif #if CRYPTOPP_BOOL_ARMV8 -#if defined(__linux__) && defined(__aarch64__) +#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__aarch64__) #include #ifndef HWCAP_AES # define HWCAP_AES (1 << 3) @@ -498,6 +498,10 @@ VC_INLINE int CPU_QueryAES() #if defined(__linux__) && defined(__aarch64__) if ((getauxval(AT_HWCAP) & HWCAP_AES) != 0) return 1; +#elif defined(__FreeBSD__) && defined(__aarch64__) + unsigned long hwcap = 0; + if (elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)) == 0 && (hwcap & HWCAP_AES) != 0) + return 1; #elif defined(__APPLE__) && defined(__aarch64__) // Apple Sillcon (M1) and later return 1; @@ -522,6 +526,10 @@ VC_INLINE int CPU_QuerySHA2() #if defined(__linux__) && defined(__aarch64__) if ((getauxval(AT_HWCAP) & HWCAP_SHA2) != 0) return 1; +#elif defined(__FreeBSD__) && defined(__aarch64__) + unsigned long hwcap = 0; + if (elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)) == 0 && (hwcap & HWCAP_SHA2) != 0) + return 1; #elif defined(__APPLE__) && defined(__aarch64__) // Apple Sillcon (M1) and later return 1;