1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Mayaqua: use "cpu_features" to check whether AES-NI is supported

This commit is contained in:
Davide Beatrici 2018-08-03 14:17:20 +02:00
parent 2a37d6aa7b
commit d3af4d6f26
2 changed files with 38 additions and 10 deletions

View File

@ -19,7 +19,11 @@ find_package(ZLIB REQUIRED)
# In some cases libiconv is not included in libc
find_library(LIB_ICONV iconv)
target_link_libraries(mayaqua OpenSSL::SSL OpenSSL::Crypto Threads::Threads ZLIB::ZLIB)
add_subdirectory(cpu_features)
target_include_directories(mayaqua PRIVATE cpu_features/include)
target_link_libraries(mayaqua cpu_features OpenSSL::SSL OpenSSL::Crypto Threads::Threads ZLIB::ZLIB)
if(LIB_ICONV)
target_link_libraries(mayaqua ${LIB_ICONV})

View File

@ -147,9 +147,20 @@
#ifdef _MSC_VER
#include <intrin.h> // For __cpuid()
#else
#include <cpuid.h> // For __get_cpuid()
#else // _MSC_VER
#include "cpu_features_macros.h"
#if defined(CPU_FEATURES_ARCH_X86)
#include "cpuinfo_x86.h"
#elif defined(CPU_FEATURES_ARCH_ARM)
#include "cpuinfo_arm.h"
#elif defined(CPU_FEATURES_ARCH_AARCH64)
#include "cpuinfo_aarch64.h"
#elif defined(CPU_FEATURES_ARCH_MIPS)
#include "cpuinfo_mips.h"
#elif defined(CPU_FEATURES_ARCH_PPC)
#include "cpuinfo_ppc.h"
#endif
#endif // _MSC_VER
LOCK *openssl_lock = NULL;
@ -4222,11 +4233,24 @@ bool IsAesNiSupported()
int regs[4]; // EAX, EBX, ECX, EDX
__cpuid(regs, 1);
supported = (regs[2] >> 25) & 1;
#else
uint32_t eax, ebx, ecx, edx;
__get_cpuid(1, &eax, &ebx, &ecx, &edx);
supported = (ecx & bit_AES) > 0;
#else // _MSC_VER
#if defined(CPU_FEATURES_ARCH_X86)
const X86Features features = GetX86Info().features;
supported = features.aes;
#elif defined(CPU_FEATURES_ARCH_ARM)
const ArmFeatures features = GetArmInfo().features;
supported = features.aes;
#elif defined(CPU_FEATURES_ARCH_AARCH64)
const Aarch64Features features = GetAarch64Info().features;
supported = features.aes;
#elif defined(CPU_FEATURES_ARCH_MIPS)
const MipsFeatures features = GetMipsInfo().features;
supported = features.aes;
#elif defined(CPU_FEATURES_ARCH_PPC)
const PPCFeatures features = GetPPCInfo().features;
supported = features.aes;
#endif
#endif // _MSC_VER
return supported;
}