From 3b773da8bc3f079d4ae9c3b59d50176d3f221023 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 29 Jul 2020 21:52:07 -0700 Subject: [PATCH] Add separate accelerated() function for AES::GMAC. --- core/AES.cpp | 2 +- core/AES.hpp | 16 ++++++++++++++++ core/Tests.cpp | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/AES.cpp b/core/AES.cpp index 745940b4f..d605c0a66 100644 --- a/core/AES.cpp +++ b/core/AES.cpp @@ -47,7 +47,7 @@ ZT_INLINE uint8x16_t s_clmul_armneon_crypto(uint8x16_t a8, const uint8x16_t y, c return vrbitq_u8(veorq_u8(r0, t0)); } -#endif +#endif // ZT_AES_NEON #ifdef ZT_HAVE_UINT128 diff --git a/core/AES.hpp b/core/AES.hpp index 8a2ef811f..056be7892 100644 --- a/core/AES.hpp +++ b/core/AES.hpp @@ -149,6 +149,22 @@ public: friend class GMACSIVDecryptor; public: + /** + * @return True if this system has hardware GMAC acceleration + */ + static ZT_INLINE bool accelerated() + { +#ifdef ZT_AES_AESNI + return Utils::CPUID.aes; +#else +#ifdef ZT_AES_NEON + return Utils::ARMCAP.pmull; +#else + return false; +#endif +#endif + } + /** * Create a new instance of GMAC (must be initialized with init() before use) * diff --git a/core/Tests.cpp b/core/Tests.cpp index a5c569739..ad01c5c29 100644 --- a/core/Tests.cpp +++ b/core/Tests.cpp @@ -1115,7 +1115,7 @@ extern "C" const char *ZTT_crypto() { uint8_t tag[16]; - ZT_T_PRINTF("[crypto] Testing AES-GMAC (hardware acceleration: %s)... ", AES::accelerated() ? "enabled" : "disabled"); + ZT_T_PRINTF("[crypto] Testing AES-GMAC (hardware acceleration: %s)... ", AES::GMAC::accelerated() ? "enabled" : "disabled"); { AES aes(AES_GMAC_VECTOR_0_KEY); AES::GMAC gmac(aes);