@@ -36,10 +36,21 @@ extern const char CHACHA_AVX_FNAME[] = __FILE__;
3636# define MAYBE_CONST const
3737#endif
3838
39- #if (CRYPTOPP_AVX2_AVAILABLE)
39+ // VS2017 and global optimization bug. TODO, figure out when
40+ // we can re-enable full optimizations for VS2017. Also see
41+ // https://github.com/weidai11/cryptopp/issues/649 and
42+ // https://github.com/weidai11/cryptopp/issues/735. The
43+ // 649 issue affects AES but it is the same here. The 735
44+ // issue is ChaCha AVX2 cut-in where it surfaced again.
45+ #if (_MSC_VER >= 1910) && defined(NDEBUG)
46+ # pragma optimize("", off)
47+ # pragma optimize("ts", on)
48+ #endif
4049
4150ANONYMOUS_NAMESPACE_BEGIN
4251
52+ #if (CRYPTOPP_AVX2_AVAILABLE)
53+
4354template <unsigned int R>
4455inline __m256i RotateLeft (const __m256i val)
4556{
@@ -62,10 +73,14 @@ inline __m256i RotateLeft<16>(const __m256i val)
6273 return _mm256_shuffle_epi8 (val, mask);
6374}
6475
76+ #endif CRYPTOPP_AVX2_AVAILABLE
77+
6578ANONYMOUS_NAMESPACE_END
6679
6780NAMESPACE_BEGIN (CryptoPP)
6881
82+ #if (CRYPTOPP_AVX2_AVAILABLE)
83+
6984void ChaCha_OperateKeystream_AVX2 (const word32 *state, const byte* input, byte *output, unsigned int rounds)
7085{
7186 MAYBE_CONST __m128i* state_mm = (MAYBE_CONST __m128i*)(state);
@@ -358,6 +373,6 @@ void ChaCha_OperateKeystream_AVX2(const word32 *state, const byte* input, byte *
358373 }
359374}
360375
361- NAMESPACE_END
362-
363376#endif // CRYPTOPP_AVX2_AVAILABLE
377+
378+ NAMESPACE_END
0 commit comments