aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-11-21 09:03:38 -0500
committerJack Lloyd <[email protected]>2018-11-21 09:03:38 -0500
commitc20a428ca2f7c1ef96e642f55bb898010444c499 (patch)
tree7fcf7f4ed89831b51e8789cdeb94115f50a1220f /src/lib
parent08072ba76b9308c8bd4d7491d88836f95fc3342f (diff)
Simplify Salsa20 xor loop
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/stream/salsa20/salsa20.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/lib/stream/salsa20/salsa20.cpp b/src/lib/stream/salsa20/salsa20.cpp
index cc1d80568..7e22b37be 100644
--- a/src/lib/stream/salsa20/salsa20.cpp
+++ b/src/lib/stream/salsa20/salsa20.cpp
@@ -111,15 +111,18 @@ void Salsa20::cipher(const uint8_t in[], uint8_t out[], size_t length)
while(length >= m_buffer.size() - m_position)
{
- xor_buf(out, in, &m_buffer[m_position], m_buffer.size() - m_position);
- length -= (m_buffer.size() - m_position);
- in += (m_buffer.size() - m_position);
- out += (m_buffer.size() - m_position);
+ const size_t available = m_buffer.size() - m_position;
+
+ xor_buf(out, in, &m_buffer[m_position], available);
salsa_core(m_buffer.data(), m_state.data(), 20);
++m_state[8];
m_state[9] += (m_state[8] == 0);
+ length -= available;
+ in += available;
+ out += available;
+
m_position = 0;
}