From 6f83a4fb7dfbbd1652524be36e3b3261ba13bc33 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 15 Nov 2017 23:05:30 -0500 Subject: Switch to intrinsic operation instead of casts for GCM SSE2 XOR's --- gcm.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'gcm.cpp') diff --git a/gcm.cpp b/gcm.cpp index a773e3f4..72d23890 100644 --- a/gcm.cpp +++ b/gcm.cpp @@ -67,7 +67,7 @@ void GCM_Base::GCTR::IncrementCounterBy256() IncrementCounterByOne(m_counterArray+BlockSize()-4, 3); } -inline static void Xor16(byte *a, const byte *b, const byte *c) +static inline void Xor16(byte *a, const byte *b, const byte *c) { CRYPTOPP_ASSERT(IsAlignedOn(a,GetAlignmentOf())); CRYPTOPP_ASSERT(IsAlignedOn(b,GetAlignmentOf())); @@ -77,19 +77,17 @@ inline static void Xor16(byte *a, const byte *b, const byte *c) } #if CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE -inline static void GCM_Xor16_SSE2(byte *a, const byte *b, const byte *c) +static inline void GCM_Xor16_SSE2(byte *a, const byte *b, const byte *c) { -// SunCC 5.14 crash (bewildering since asserts are not in effect in release builds) -// Also see http://github.com/weidai11/cryptopp/issues/226 and http://github.com/weidai11/cryptopp/issues/284 -# if __SUNPRO_CC - *M128_CAST(a) = _mm_xor_si128(*M128_CAST(b), *M128_CAST(c)); -# elif CRYPTOPP_SSE2_INTRIN_AVAILABLE - CRYPTOPP_ASSERT(IsAlignedOn(a,GetAlignmentOf<__m128i>())); - CRYPTOPP_ASSERT(IsAlignedOn(b,GetAlignmentOf<__m128i>())); - CRYPTOPP_ASSERT(IsAlignedOn(c,GetAlignmentOf<__m128i>())); - *M128_CAST(a) = _mm_xor_si128(*M128_CAST(b), *M128_CAST(c)); -# else - asm ("movdqa %1, %%xmm0; pxor %2, %%xmm0; movdqa %%xmm0, %0;" : "=m" (a[0]) : "m"(b[0]), "m"(c[0])); +// SunCC 5.14 crash. Also see http://github.com/weidai11/cryptopp/issues/226 +// and http://github.com/weidai11/cryptopp/issues/284 +# if CRYPTOPP_SSE2_ASM_AVAILABLE && !defined(__SUNPRO_CC) + asm ("movdqa %1, %%xmm0; pxor %2, %%xmm0; movdqa %%xmm0, %0;" + : "=m" (a[0]) : "m"(b[0]), "m"(c[0])); +# else // CRYPTOPP_SSE2_INTRIN_AVAILABLE + _mm_store_si128(M128_CAST(a), _mm_xor_si128( + _mm_load_si128(CONST_M128_CAST(b)), + _mm_load_si128(CONST_M128_CAST(c)))); # endif } #endif @@ -101,14 +99,11 @@ const unsigned int s_cltableSizeInBlocks = 8; extern void GCM_ReverseHashBufferIfNeeded_CLMUL(byte *hashBuffer); #endif // CRYPTOPP_CLMUL_AVAILABLE -#if CRYPTOPP_ARM_PMULL_AVAILABLE -extern void GCM_ReverseHashBufferIfNeeded_PMULL(byte *hashBuffer); -#endif - #if CRYPTOPP_ARM_PMULL_AVAILABLE extern void GCM_SetKeyWithoutResync_PMULL(const byte *hashKey, byte *mulTable, unsigned int tableSize); extern size_t GCM_AuthenticateBlocks_PMULL(const byte *data, size_t len, const byte *mtable, byte *hbuffer); const unsigned int s_cltableSizeInBlocks = 8; +extern void GCM_ReverseHashBufferIfNeeded_PMULL(byte *hashBuffer); #endif // CRYPTOPP_ARM_PMULL_AVAILABLE void GCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) -- cgit v1.2.1