aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
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
parent6322dc69fcf9f3effed4e51de90b3f5b163db47e (diff)
Support 96 bit nonces in ChaCha20 as specified in draft-irtf-cfrg-chacha20-poly1305-03
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/stream/chacha/chacha.cpp13
-rw-r--r--src/lib/stream/chacha/chacha.h2
2 files changed, 12 insertions, 3 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];
diff --git a/src/lib/stream/chacha/chacha.h b/src/lib/stream/chacha/chacha.h
index b7d720685..c7c11771d 100644
--- a/src/lib/stream/chacha/chacha.h
+++ b/src/lib/stream/chacha/chacha.h
@@ -23,7 +23,7 @@ class BOTAN_DLL ChaCha : public StreamCipher
void set_iv(const byte iv[], size_t iv_len);
bool valid_iv_length(size_t iv_len) const
- { return (iv_len == 8); }
+ { return (iv_len == 8 || iv_len == 12); }
Key_Length_Specification key_spec() const
{