aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/stream/chacha
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-11-21 08:54:00 -0500
committerJack Lloyd <[email protected]>2018-11-21 08:54:00 -0500
commit2c1b53a1c93d54992ebcb509d771842ce1d6c598 (patch)
tree2de318ffb61981f73b2b3fe3ee69a8e8574f8515 /src/lib/stream/chacha
parent00a33abd87b981827b86b26d477bc261ff9a6a16 (diff)
Slight simplification to ChaCha loop
Diffstat (limited to 'src/lib/stream/chacha')
-rw-r--r--src/lib/stream/chacha/chacha.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp
index a1355cbe6..327454d79 100644
--- a/src/lib/stream/chacha/chacha.cpp
+++ b/src/lib/stream/chacha/chacha.cpp
@@ -176,11 +176,14 @@ void ChaCha::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);
chacha_x8(m_buffer.data(), m_state.data(), m_rounds);
+
+ length -= available;
+ in += available;
+ out += available;
m_position = 0;
}
@@ -195,10 +198,13 @@ void ChaCha::write_keystream(uint8_t out[], size_t length)
while(length >= m_buffer.size() - m_position)
{
- copy_mem(out, &m_buffer[m_position], m_buffer.size() - m_position);
- length -= (m_buffer.size() - m_position);
- out += (m_buffer.size() - m_position);
+ const size_t available = m_buffer.size() - m_position;
+
+ copy_mem(out, &m_buffer[m_position], available);
chacha_x8(m_buffer.data(), m_state.data(), m_rounds);
+
+ length -= available;
+ out += available;
m_position = 0;
}