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.
This commit is contained in:
Mounir IDRASSI
2026-10-22 00:17:31 +09:00
parent 937d82eee6
commit 8172bc55f8
+9 -1
View File
@@ -479,7 +479,7 @@ void DisableCPUExtendedFeatures ()
#endif
#if CRYPTOPP_BOOL_ARMV8
#if defined(__linux__) && defined(__aarch64__)
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__aarch64__)
#include <sys/auxv.h>
#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;