diff --git a/crc-simd.cpp b/crc-simd.cpp index f1f61288..10eb206c 100644 --- a/crc-simd.cpp +++ b/crc-simd.cpp @@ -15,6 +15,13 @@ # undef CRYPTOPP_ARM_CRC32_AVAILABLE #endif +#if defined(__linux__) +# include +# ifndef HWCAP_CRC32 +# define HWCAP_CRC32 (1 << 7) +# endif +#endif + #if (CRYPTOPP_SSE42_AVAILABLE) # include "nmmintrin.h" #endif @@ -71,6 +78,11 @@ bool CPU_TryCRC32_ARMV8() } return result; #else +# if defined(__linux__) + if (getauxval(AT_HWCAP) & HWCAP_CRC32) + return true; +# endif + // longjmp and clobber warnings. Volatile is required. // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 volatile bool result = true; diff --git a/gcm-simd.cpp b/gcm-simd.cpp index 366597a4..78b4ebbe 100644 --- a/gcm-simd.cpp +++ b/gcm-simd.cpp @@ -15,6 +15,13 @@ # undef CRYPTOPP_ARM_PMULL_AVAILABLE #endif +#if defined(__linux__) +# include +# ifndef HWCAP_PMULL +# define HWCAP_PMULL (1 << 4) +# endif +#endif + #if (CRYPTOPP_CLMUL_AVAILABLE) # include "tmmintrin.h" # include "wmmintrin.h" @@ -204,6 +211,11 @@ bool CPU_TryPMULL_ARMV8() } return result; # else +# if defined(__linux__) + if (getauxval(AT_HWCAP) & HWCAP_PMULL) + return true; +# endif + // longjmp and clobber warnings. Volatile is required. // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 volatile bool result = true; diff --git a/neon.cpp b/neon.cpp index 0b55e464..6b155ecb 100644 --- a/neon.cpp +++ b/neon.cpp @@ -9,6 +9,13 @@ #include "pch.h" #include "config.h" +#if defined(__linux__) +# include +# ifndef HWCAP_ASIMD +# define HWCAP_ASIMD (1 << 1) +# endif +#endif + #if (CRYPTOPP_ARM_NEON_AVAILABLE) # include "arm_neon.h" #endif @@ -63,6 +70,11 @@ bool CPU_TryNEON_ARM() } return result; # else +# if defined(__linux__) && (defined(__aarch32__) || defined(__aarch64__)) + if (getauxval(AT_HWCAP) & HWCAP_ASIMD) + return true; +# endif + // longjmp and clobber warnings. Volatile is required. // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 volatile bool result = true; diff --git a/rijndael-simd.cpp b/rijndael-simd.cpp index 9f577473..871f6095 100644 --- a/rijndael-simd.cpp +++ b/rijndael-simd.cpp @@ -20,6 +20,13 @@ # undef CRYPTOPP_ARM_AES_AVAILABLE #endif +#if defined(__linux__) +# include +# ifndef HWCAP_AES +# define HWCAP_AES (1 << 3) +# endif +#endif + #if (CRYPTOPP_SSE41_AVAILABLE) // Hack... Apple conflates SSE4.1 and SSE4.2. Without __SSE4_2__, // Apple fails the compile with "SSE4.2 instruction set not enabled" @@ -94,6 +101,11 @@ bool CPU_TryAES_ARMV8() } return result; # else +# if defined(__linux__) + if (getauxval(AT_HWCAP) & HWCAP_AES) + return true; +# endif + // longjmp and clobber warnings. Volatile is required. // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 volatile bool result = true; diff --git a/sha-simd.cpp b/sha-simd.cpp index a7377bed..7b8368a5 100644 --- a/sha-simd.cpp +++ b/sha-simd.cpp @@ -15,6 +15,16 @@ # undef CRYPTOPP_ARM_SHA_AVAILABLE #endif +#if defined(__linux__) +# include +# ifndef HWCAP_SHA1 +# define HWCAP_SHA1 (1 << 5) +# endif +# ifndef HWCAP_SHA2 +# define HWCAP_SHA2 (1 << 6) +# endif +#endif + #if (CRYPTOPP_SSE42_AVAILABLE) # include "nmmintrin.h" #endif @@ -75,6 +85,11 @@ bool CPU_TrySHA1_ARMV8() } return result; # else +# if defined(__linux__) + if (getauxval(AT_HWCAP) & HWCAP_SHA1) + return true; +# endif + // longjmp and clobber warnings. Volatile is required. // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 volatile bool result = true; @@ -133,6 +148,11 @@ bool CPU_TrySHA2_ARMV8() } return result; #else +# if defined(__linux__) + if (getauxval(AT_HWCAP) & HWCAP_SHA2) + return true; +# endif + // longjmp and clobber warnings. Volatile is required. // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854 volatile bool result = true;