Implement SHA256 acceleration on ARM64 platforms using CPU instructions

This commit is contained in:
Mounir IDRASSI committed 2025-01-26 16:21:13 +01:00
1 parent 5ff256a53d
commit 247c98d954
12 files changed
+267

No files matched your search

+29
View File
@@ -475,9 +475,13 @@ void DisableCPUExtendedFeatures ()
#ifndef HWCAP_AES
# define HWCAP_AES (1 << 3)
#endif
#ifndef HWCAP_SHA2
# define HWCAP_SHA2 (1 << 6)
#endif
#endif
volatile int g_hasAESARM = 0;
volatile int g_hasSHA256ARM = 0;
inline int CPU_QueryAES()
{
@@ -503,9 +507,34 @@ inline int CPU_QueryAES()
#endif
}
inline int CPU_QuerySHA2()
{
#if defined(CRYPTOPP_ARM_SHA2_AVAILABLE)
#if defined(__linux__) && defined(__aarch64__)
if ((getauxval(AT_HWCAP) & HWCAP_SHA2) != 0)
return 1;
#elif defined(__APPLE__) && defined(__aarch64__)
// Apple Sillcon (M1) and later
return 1;
#elif defined(_WIN32) && defined(_M_ARM64)
#ifdef TC_WINDOWS_DRIVER
if (ExIsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0)
return 1;
#else
if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0)
return 1;
#endif
#endif
return 0;
#else
return 0;
#endif
}
void DetectArmFeatures()
{
g_hasAESARM = CPU_QueryAES();
g_hasSHA256ARM = CPU_QuerySHA2();
}
#endif