summaryrefslogtreecommitdiff
path: root/chacha.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-10-24 11:00:35 -0400
committerJeffrey Walton <noloader@gmail.com>2018-10-24 11:00:35 -0400
commit18dcbdf514298d7097934d9a1d2e9032f14b54b7 (patch)
tree9e420d118ad0cde18ddec44457e6c4cd720232a0 /chacha.cpp
parentd230999b408740d604b136bdfa28f1a60b0211fe (diff)
downloadcryptopp-git-18dcbdf514298d7097934d9a1d2e9032f14b54b7.tar.gz
Move input xor to ChaCha_OperateKeystream_SSE2
This picks up about 0.2 cpb in ChaCha::OperateKeystream. It may not sound like much but it puts SSE2 intrinsics version on par with the ASM version of Salsa20. Salsa20 leads ChaCha by 0.1 to 0.15 cpb, which equates to about 50 MB/s.
Diffstat (limited to 'chacha.cpp')
-rw-r--r--chacha.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/chacha.cpp b/chacha.cpp
index 7293c2a9..080ccbfd 100644
--- a/chacha.cpp
+++ b/chacha.cpp
@@ -12,11 +12,7 @@
NAMESPACE_BEGIN(CryptoPP)
#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);
+extern void ChaCha_OperateKeystream_SSE2(const word32 *state, const byte* input, byte *output, unsigned int rounds, bool xorInput);
#endif
#define CHACHA_QUARTER_ROUND(a,b,c,d) \
@@ -38,6 +34,10 @@ std::string ChaCha_Policy::AlgorithmProvider() const
if (HasSSE2())
return "SSE2";
#endif
+#if (CRYPTOPP_ARM_NEON_AVAILABLE)
+ if (HasNEON())
+ return "NEON";
+#endif
return "C++";
}
@@ -96,9 +96,17 @@ unsigned int ChaCha_Policy::GetOptimalBlockSize() const
return 4*BYTES_PER_ITERATION;
else
#endif
+#if (CRYPTOPP_ARM_NEON_AVAILABLE)
+ if (HasNEON())
+ return 4*BYTES_PER_ITERATION;
+ else
+#endif
return BYTES_PER_ITERATION;
}
+// OperateKeystream always produces a key stream. The key stream is written
+// to output. Optionally a message may be supplied to xor with the key stream.
+// The message is input, and output = output ^ input.
void ChaCha_Policy::OperateKeystream(KeystreamOperation operation,
byte *output, const byte *input, size_t iterationCount)
{
@@ -107,10 +115,8 @@ void ChaCha_Policy::OperateKeystream(KeystreamOperation operation,
{
while (iterationCount >= 4)
{
- ChaCha_OperateKeystream_SSE2(m_state, output, m_rounds);
-
- if ((operation & INPUT_NULL) != INPUT_NULL)
- xorbuf(output, input, 4*BYTES_PER_ITERATION);
+ bool xorInput = (operation & INPUT_NULL) != INPUT_NULL;
+ ChaCha_OperateKeystream_SSE2(m_state, input, output, m_rounds, xorInput);
m_state[12] += 4;
if (m_state[12] < 4)