aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/stream/chacha/chacha.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/stream/chacha/chacha.cpp')
-rw-r--r--src/lib/stream/chacha/chacha.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp
index 33db7ac92..419f8f67a 100644
--- a/src/lib/stream/chacha/chacha.cpp
+++ b/src/lib/stream/chacha/chacha.cpp
@@ -135,8 +135,17 @@ void ChaCha::set_iv(const byte iv[], size_t length)
m_state[12] = 0;
m_state[13] = 0;
- m_state[14] = load_le<u32bit>(iv, 0);
- m_state[15] = load_le<u32bit>(iv, 1);
+ if(length == 8)
+ {
+ m_state[14] = load_le<u32bit>(iv, 0);
+ m_state[15] = load_le<u32bit>(iv, 1);
+ }
+ else if(length == 12)
+ {
+ m_state[13] = load_le<u32bit>(iv, 0);
+ m_state[14] = load_le<u32bit>(iv, 1);
+ m_state[15] = load_le<u32bit>(iv, 2);
+ }
chacha(&m_buffer[0], &m_state[0]);
++m_state[12];