Browse Source

Add separate accelerated() function for AES::GMAC.

Adam Ierymenko 5 years ago
parent
commit
3b773da8bc
3 changed files with 18 additions and 2 deletions
  1. 1 1
      core/AES.cpp
  2. 16 0
      core/AES.hpp
  3. 1 1
      core/Tests.cpp

+ 1 - 1
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));
 	return vrbitq_u8(veorq_u8(r0, t0));
 }
 }
 
 
-#endif
+#endif // ZT_AES_NEON
 
 
 #ifdef ZT_HAVE_UINT128
 #ifdef ZT_HAVE_UINT128
 
 

+ 16 - 0
core/AES.hpp

@@ -149,6 +149,22 @@ public:
 		friend class GMACSIVDecryptor;
 		friend class GMACSIVDecryptor;
 
 
 	public:
 	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)
 		 * Create a new instance of GMAC (must be initialized with init() before use)
 		 *
 		 *

+ 1 - 1
core/Tests.cpp

@@ -1115,7 +1115,7 @@ extern "C" const char *ZTT_crypto()
 
 
 		{
 		{
 			uint8_t tag[16];
 			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 aes(AES_GMAC_VECTOR_0_KEY);
 				AES::GMAC gmac(aes);
 				AES::GMAC gmac(aes);