aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/stream/chacha/chacha.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-12-29 02:15:35 +0000
committerlloyd <[email protected]>2014-12-29 02:15:35 +0000
commit05b6811827fe7f4e107a9339142f6aec56f0f202 (patch)
treef38c9ac13990f0ddf000f9ce6a23d002c8e8321f /src/lib/stream/chacha/chacha.cpp
parent6322dc69fcf9f3effed4e51de90b3f5b163db47e (diff)
Support 96 bit nonces in ChaCha20 as specified in draft-irtf-cfrg-chacha20-poly1305-03
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];