From 0f2887265c4695c169ae9459cc887ebd3a4c8a74 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Mon, 21 Sep 2020 13:17:12 -0700 Subject: [PATCH] AES-NI/NEON detection for iOS Requires 64-bit CPU --- node/AES.cpp | 4 ++++ node/Constants.hpp | 6 ++++++ node/Utils.cpp | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/node/AES.cpp b/node/AES.cpp index 87ca39c83..2a1bac79a 100644 --- a/node/AES.cpp +++ b/node/AES.cpp @@ -18,6 +18,10 @@ #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif +#ifdef __APPLE__ +#include +#endif + #define Te1_r(x) ZT_ROR32(Te0[x], 8U) #define Te2_r(x) ZT_ROR32(Te0[x], 16U) #define Te3_r(x) ZT_ROR32(Te0[x], 24U) diff --git a/node/Constants.hpp b/node/Constants.hpp index 53b44dd42..660c8772d 100644 --- a/node/Constants.hpp +++ b/node/Constants.hpp @@ -112,12 +112,18 @@ #endif #if (defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(ZT_ARCH_ARM_HAS_NEON)) +#if defined(__APPLE__) && !defined(__LP64__) +#ifdef ZT_ARCH_ARM_HAS_NEON +#undef ZT_ARCH_ARM_HAS_NEON +#endif +#else #ifndef ZT_ARCH_ARM_HAS_NEON #define ZT_ARCH_ARM_HAS_NEON 1 #endif #include /*#include */ #endif +#endif // Define ZT_NO_TYPE_PUNNING to disable reckless casts on anything other than x86/x64. #if (!(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__I86__) || defined(__INTEL__) || defined(__386))) diff --git a/node/Utils.cpp b/node/Utils.cpp index 508e553e3..57a3d6612 100644 --- a/node/Utils.cpp +++ b/node/Utils.cpp @@ -42,6 +42,10 @@ #include "Mutex.hpp" #include "Salsa20.hpp" +#ifdef __APPLE__ +#include +#endif + namespace ZeroTier { const uint64_t Utils::ZERO256[4] = {0ULL,0ULL,0ULL,0ULL}; @@ -51,6 +55,13 @@ const char Utils::HEXCHARS[16] = { '0','1','2','3','4','5','6','7','8','9','a',' #ifdef ZT_ARCH_ARM_HAS_NEON Utils::ARMCapabilities::ARMCapabilities() noexcept { +#if TARGET_OS_IPHONE + this->aes = true; + this->crc32 = true; + this->pmull = true; + this->sha1 = true; + this->sha2 = true; +#else #ifdef HWCAP2_AES if (sizeof(void *) == 4) { const long hwcaps2 = getauxval(AT_HWCAP2); @@ -70,6 +81,7 @@ Utils::ARMCapabilities::ARMCapabilities() noexcept #ifdef HWCAP2_AES } #endif +#endif // TARGET_OS_IPHONE } const Utils::ARMCapabilities Utils::ARMCAP;