mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Some AES NEON reorg.
This commit is contained in:
parent
71b72a1ef2
commit
b4d0307d9e
2 changed files with 22 additions and 14 deletions
13
core/AES.cpp
13
core/AES.cpp
|
@ -744,8 +744,8 @@ void AES::CTR::crypt(const void *const input, unsigned int len) noexcept
|
|||
}
|
||||
#endif // ZT_AES_AESNI
|
||||
|
||||
#ifdef ZT_ARCH_ARM_HAS_NEON
|
||||
if (true) {
|
||||
#ifdef ZT_AES_NEON
|
||||
if (s_hasNeonAes) {
|
||||
uint8x16_t dd = vld1q_u8(reinterpret_cast<uint8_t *>(_ctr));
|
||||
const uint32x4_t one = {0,0,0,1};
|
||||
|
||||
|
@ -842,7 +842,7 @@ void AES::CTR::crypt(const void *const input, unsigned int len) noexcept
|
|||
vst1q_u8(reinterpret_cast<uint8_t *>(_ctr), dd);
|
||||
return;
|
||||
}
|
||||
#endif // ZT_ARCH_ARM_HAS_NEON
|
||||
#endif // ZT_AES_NEON
|
||||
|
||||
uint64_t keyStream[2];
|
||||
uint32_t ctr = Utils::ntoh(reinterpret_cast<uint32_t *>(_ctr)[3]);
|
||||
|
@ -1330,7 +1330,10 @@ void AES::_decrypt_aesni(const void *in, void *out) const noexcept
|
|||
|
||||
#endif // ZT_AES_AESNI
|
||||
|
||||
#ifdef ZT_ARCH_ARM_HAS_NEON
|
||||
#ifdef ZT_AES_NEON
|
||||
|
||||
const bool AES::s_hasNeonAes = true;
|
||||
const bool AES::s_hasNeonGcm = true;
|
||||
|
||||
#define ZT_INIT_ARMNEON_CRYPTO_SUBWORD(w) ((uint32_t)s_sbox[w & 0xffU] + ((uint32_t)s_sbox[(w >> 8U) & 0xffU] << 8U) + ((uint32_t)s_sbox[(w >> 16U) & 0xffU] << 16U) + ((uint32_t)s_sbox[(w >> 24U) & 0xffU] << 24U))
|
||||
#define ZT_INIT_ARMNEON_CRYPTO_ROTWORD(w) (((w) << 8U) | ((w) >> 24U))
|
||||
|
@ -1411,6 +1414,6 @@ void AES::_decrypt_armneon_crypto(const void *const in, void *const out) const n
|
|||
vst1q_u8(reinterpret_cast<uint8_t *>(out), tmp);
|
||||
}
|
||||
|
||||
#endif // ZT_ARCH_ARM_HAS_NEON
|
||||
#endif // ZT_AES_NEON
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
23
core/AES.hpp
23
core/AES.hpp
|
@ -21,6 +21,9 @@
|
|||
#if !defined(ZT_AES_NO_ACCEL) && defined(ZT_ARCH_X64)
|
||||
#define ZT_AES_AESNI 1
|
||||
#endif
|
||||
#if !defined(ZT_AES_NO_ACCEL) && defined(ZT_ARCH_ARM_HAS_NEON)
|
||||
#define ZT_AES_NEON 1
|
||||
#endif
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
|
@ -75,8 +78,8 @@ public:
|
|||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef ZT_ARCH_ARM_HAS_NEON
|
||||
if (true) {
|
||||
#ifdef ZT_AES_NEON
|
||||
if (s_hasNeonAes) {
|
||||
_init_armneon_crypto(reinterpret_cast<const uint8_t *>(key));
|
||||
return;
|
||||
}
|
||||
|
@ -98,8 +101,8 @@ public:
|
|||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef ZT_ARCH_ARM_HAS_NEON
|
||||
if (true) {
|
||||
#ifdef ZT_AES_NEON
|
||||
if (s_hasNeonAes) {
|
||||
_encrypt_armneon_crypto(in, out);
|
||||
return;
|
||||
}
|
||||
|
@ -121,8 +124,8 @@ public:
|
|||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef ZT_ARCH_ARM_HAS_NEON
|
||||
if (true) {
|
||||
#ifdef ZT_AES_NEON
|
||||
if (s_hasNeonAes) {
|
||||
_decrypt_armneon_crypto(in, out);
|
||||
return;
|
||||
}
|
||||
|
@ -521,7 +524,7 @@ private:
|
|||
} ni;
|
||||
#endif
|
||||
|
||||
#ifdef ZT_ARCH_ARM_HAS_NEON
|
||||
#ifdef ZT_AES_NEON
|
||||
struct
|
||||
{
|
||||
uint8x16_t ek[15];
|
||||
|
@ -540,11 +543,13 @@ private:
|
|||
|
||||
#ifdef ZT_AES_AESNI
|
||||
void _init_aesni(const uint8_t key[32]) noexcept;
|
||||
void _encrypt_aesni(const void *const in, void *const out) const noexcept;
|
||||
void _encrypt_aesni(const void *in, void *out) const noexcept;
|
||||
void _decrypt_aesni(const void *in, void *out) const noexcept;
|
||||
#endif
|
||||
|
||||
#ifdef ZT_ARCH_ARM_HAS_NEON
|
||||
#ifdef ZT_AES_NEON
|
||||
static const bool s_hasNeonAes;
|
||||
static const bool s_hasNeonGcm;
|
||||
void _init_armneon_crypto(const uint8_t key[32]) noexcept;
|
||||
void _encrypt_armneon_crypto(const void *const in, void *const out) const noexcept;
|
||||
void _decrypt_armneon_crypto(const void *const in, void *const out) const noexcept;
|
||||
|
|
Loading…
Add table
Reference in a new issue