From c20a428ca2f7c1ef96e642f55bb898010444c499 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 21 Nov 2018 09:03:38 -0500 Subject: Simplify Salsa20 xor loop --- src/lib/stream/salsa20/salsa20.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/lib') 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; } -- cgit v1.2.3