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

Merge PR #605: Mayaqua: use "cpu_features" to check whether AES-NI is supported

This commit is contained in:
Davide Beatrici 2018-08-03 19:05:23 +02:00 committed by GitHub
commit 73371087ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 10 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/Mayaqua/cpu_features"]
path = src/Mayaqua/cpu_features
url = https://github.com/google/cpu_features.git

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

@ -146,10 +146,21 @@
#include <Mayaqua/Mayaqua.h>
#ifdef _MSC_VER
#include <intrin.h> // For __cpuid()
#else
#include <cpuid.h> // For __get_cpuid()
#endif
#include <intrin.h> // For __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;
#endif
#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;
}

@ -0,0 +1 @@
Subproject commit 26133d3b620c2c27f31d571efd27371100f891e9