From d230999b408740d604b136bdfa28f1a60b0211fe Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 24 Oct 2018 01:11:45 -0400 Subject: [PATCH] Fix ChaCha compile on ARM and MIPS --- chacha-simd.cpp | 10 +++++----- chacha.cpp | 14 +++++++++----- chacha.h | 3 --- config.h | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/chacha-simd.cpp b/chacha-simd.cpp index f0eb6efa..58d2b786 100644 --- a/chacha-simd.cpp +++ b/chacha-simd.cpp @@ -17,7 +17,7 @@ #include "chacha.h" #include "misc.h" -#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE) +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) # include # include #endif @@ -38,7 +38,7 @@ extern const char CHACHA_SIMD_FNAME[] = __FILE__; ANONYMOUS_NAMESPACE_BEGIN -#if defined(CRYPTOPP_SSE2_INTRIN_AVAILABLE) +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) template inline __m128i RotateLeft(const __m128i val) @@ -46,13 +46,13 @@ inline __m128i RotateLeft(const __m128i val) return _mm_or_si128(_mm_slli_epi32(val, R), _mm_srli_epi32(val, 32-R)); } -#endif // CRYPTOPP_SSE2_INTRIN_AVAILABLE +#endif // (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) ANONYMOUS_NAMESPACE_END NAMESPACE_BEGIN(CryptoPP) -#if defined(CRYPTOPP_SSE2_INTRIN_AVAILABLE) +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) void ChaCha_OperateKeystream_SSE2(const word32 *state, byte *message, unsigned int rounds) { @@ -283,6 +283,6 @@ void ChaCha_OperateKeystream_SSE2(const word32 *state, byte *message, unsigned i _mm_storeu_si128(message_mm + 15, r3_3); } -#endif // CRYPTOPP_SSE2_INTRIN_AVAILABLE +#endif // (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) NAMESPACE_END diff --git a/chacha.cpp b/chacha.cpp index 6ae78c4b..7293c2a9 100644 --- a/chacha.cpp +++ b/chacha.cpp @@ -11,10 +11,14 @@ NAMESPACE_BEGIN(CryptoPP) -#if defined(CRYPTOPP_SSE2_INTRIN_AVAILABLE) +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) extern void ChaCha_OperateKeystream_SSE2(const word32 *state, byte *message, unsigned int rounds); #endif +#if (CRYPTOPP_ARM_NEON_AVAILABLE) +extern void ChaCha_OperateKeystream_NEON(const word32 *state, byte *message, unsigned int rounds); +#endif + #define CHACHA_QUARTER_ROUND(a,b,c,d) \ a += b; d ^= a; d = rotlConstant<16,word32>(d); \ c += d; b ^= c; b = rotlConstant<12,word32>(b); \ @@ -30,7 +34,7 @@ void ChaCha_TestInstantiations() std::string ChaCha_Policy::AlgorithmProvider() const { -#if CRYPTOPP_SSE2_INTRIN_AVAILABLE +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) if (HasSSE2()) return "SSE2"; #endif @@ -77,7 +81,7 @@ void ChaCha_Policy::SeekToIteration(lword iterationCount) unsigned int ChaCha_Policy::GetAlignment() const { -#if CRYPTOPP_SSE2_INTRIN_AVAILABLE +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) if (HasSSE2()) return 16; else @@ -87,7 +91,7 @@ unsigned int ChaCha_Policy::GetAlignment() const unsigned int ChaCha_Policy::GetOptimalBlockSize() const { -#if CRYPTOPP_SSE2_INTRIN_AVAILABLE +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) if (HasSSE2()) return 4*BYTES_PER_ITERATION; else @@ -98,7 +102,7 @@ unsigned int ChaCha_Policy::GetOptimalBlockSize() const void ChaCha_Policy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) { -#if CRYPTOPP_SSE2_INTRIN_AVAILABLE +#if (CRYPTOPP_SSE2_INTRIN_AVAILABLE || CRYPTOPP_SSE2_ASM_AVAILABLE) if (HasSSE2()) { while (iterationCount >= 4) diff --git a/chacha.h b/chacha.h index 54cbc6a4..d66127a8 100644 --- a/chacha.h +++ b/chacha.h @@ -37,11 +37,8 @@ protected: void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); bool CipherIsRandomAccess() const {return true;} void SeekToIteration(lword iterationCount); - -#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) unsigned int GetAlignment() const; unsigned int GetOptimalBlockSize() const; -#endif std::string AlgorithmProvider() const; diff --git a/config.h b/config.h index 02afb031..9cc22a35 100644 --- a/config.h +++ b/config.h @@ -496,7 +496,7 @@ NAMESPACE_END #define CRYPTOPP_SSE2_ASM_AVAILABLE 1 #endif - #if !defined(CRYPTOPP_DISABLE_SSSE3) && (_MSC_VER >= 1500 || defined(__SSSE3__)) + #if !defined(CRYPTOPP_DISABLE_SSSE3) && (_MSC_VER >= 1500 || CRYPTOPP_GCC_VERSION >= 40300 || defined(__SSSE3__)) #define CRYPTOPP_SSSE3_ASM_AVAILABLE 1 #endif #endif @@ -510,7 +510,7 @@ NAMESPACE_END #endif // 32-bit SunCC does not enable SSE2 by default. -#if !defined(CRYPTOPP_DISABLE_ASM) && (defined(_MSC_VER) || defined(__SSE2__)) +#if !defined(CRYPTOPP_DISABLE_ASM) && (defined(_MSC_VER) || CRYPTOPP_GCC_VERSION >= 30300 || defined(__SSE2__)) #define CRYPTOPP_SSE2_INTRIN_AVAILABLE 1 #endif