VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/cpu.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2025-01-17 00:58:54 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2025-01-17 00:58:54 +0100
commit54bd81999007b467420acab780c704c91bc1b057 (patch)
treefb2e3dbc899e6acd89f82406d6712508c015e1c8 /src/Crypto/cpu.c
parentc79f8102e094f512ac5c706fa30a2741d697b003 (diff)
downloadVeraCrypt-54bd81999007b467420acab780c704c91bc1b057.tar.gz
VeraCrypt-54bd81999007b467420acab780c704c91bc1b057.zip
Windows/Linux/macOS: implement AES hardware support on ARM64 (ARMv8)
Diffstat (limited to 'src/Crypto/cpu.c')
-rw-r--r--src/Crypto/cpu.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Crypto/cpu.c b/src/Crypto/cpu.c
index e611e9bb..85278a92 100644
--- a/src/Crypto/cpu.c
+++ b/src/Crypto/cpu.c
@@ -469,3 +469,41 @@ void DisableCPUExtendedFeatures ()
#endif
+#if CRYPTOPP_BOOL_ARMV8
+
+volatile int g_hasAESARM = 0;
+
+#ifndef HWCAP_AES
+# define HWCAP_AES (1 << 3)
+#endif
+
+inline int CPU_QueryAES()
+{
+#if defined(CRYPTOPP_ARM_AES_AVAILABLE)
+#if defined(__linux__) && defined(__aarch64__)
+ if ((getauxval(AT_HWCAP) & HWCAP_AES) != 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();
+}
+
+#endif \ No newline at end of file