diff options
Diffstat (limited to 'src/lib/stream/salsa20/salsa20.cpp')
-rw-r--r-- | src/lib/stream/salsa20/salsa20.cpp | 11 |
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; } |