diff options
author | Jack Lloyd <[email protected]> | 2016-08-31 17:09:23 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-09-01 13:20:05 -0400 |
commit | 858e3be10396e082901b612ee8c5e18cd3e47286 (patch) | |
tree | 6df7679900e75f1fee8c44340ac29fc742a92831 /src/lib/stream/chacha/chacha.cpp | |
parent | e4656be6a8e601b64c759906bacf543388b3cf22 (diff) |
SSE2 ChaCha
Diffstat (limited to 'src/lib/stream/chacha/chacha.cpp')
-rw-r--r-- | src/lib/stream/chacha/chacha.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp index 40da93029..97b6465f9 100644 --- a/src/lib/stream/chacha/chacha.cpp +++ b/src/lib/stream/chacha/chacha.cpp @@ -7,6 +7,7 @@ #include <botan/chacha.h> #include <botan/loadstor.h> +#include <botan/cpuid.h> namespace Botan { @@ -16,12 +17,18 @@ ChaCha::ChaCha(size_t rounds) : m_rounds(rounds) throw Invalid_Argument("ChaCha only supports 8, 12 or 20 rounds"); } -namespace { - -void chacha(byte output[64], const u32bit input[16], size_t rounds) +//static +void ChaCha::chacha(byte output[64], const u32bit input[16], size_t rounds) { BOTAN_ASSERT(rounds % 2 == 0, "Valid rounds"); + #if defined(BOTAN_TARGET_SUPPORTS_SSE2) + if(CPUID::has_sse2()) + { + return ChaCha::chacha_sse2(output, input, rounds); + } + #endif + u32bit x00 = input[ 0], x01 = input[ 1], x02 = input[ 2], x03 = input[ 3], x04 = input[ 4], x05 = input[ 5], x06 = input[ 6], x07 = input[ 7], x08 = input[ 8], x09 = input[ 9], x10 = input[10], x11 = input[11], @@ -67,7 +74,6 @@ void chacha(byte output[64], const u32bit input[16], size_t rounds) store_le(x14 + input[14], output + 4 * 14); store_le(x15 + input[15], output + 4 * 15); } -} /* * Combine cipher stream with message @@ -80,7 +86,7 @@ void ChaCha::cipher(const byte in[], byte out[], size_t length) length -= (m_buffer.size() - m_position); in += (m_buffer.size() - m_position); out += (m_buffer.size() - m_position); - chacha(m_buffer.data(), m_state.data(), m_rounds); + chacha_sse2(m_buffer.data(), m_state.data(), m_rounds); ++m_state[12]; m_state[13] += (m_state[12] == 0); @@ -176,7 +182,7 @@ void ChaCha::seek(u64bit offset) { if (m_state.size() == 0 && m_buffer.size() == 0) { - throw Invalid_State("You have to setup the stream cipher (key and iv)"); + throw Invalid_State("You have to setup the stream cipher (key and iv)"); } m_position = offset % m_buffer.size(); |