diff options
Diffstat (limited to 'src/lib/stream')
-rw-r--r-- | src/lib/stream/chacha/chacha.cpp | 5 | ||||
-rw-r--r-- | src/lib/stream/ctr/ctr.cpp | 2 | ||||
-rw-r--r-- | src/lib/stream/ofb/ofb.cpp | 2 | ||||
-rw-r--r-- | src/lib/stream/rc4/rc4.cpp | 2 | ||||
-rw-r--r-- | src/lib/stream/salsa20/info.txt | 2 | ||||
-rw-r--r-- | src/lib/stream/salsa20/salsa20.cpp | 19 |
6 files changed, 23 insertions, 9 deletions
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp index 52e5eaaf4..0f1e082cf 100644 --- a/src/lib/stream/chacha/chacha.cpp +++ b/src/lib/stream/chacha/chacha.cpp @@ -222,10 +222,7 @@ std::string ChaCha::name() const void ChaCha::seek(uint64_t offset) { - if (m_state.size() == 0 && m_buffer.size() == 0) - { - throw Invalid_State("You have to setup the stream cipher (key and iv)"); - } + verify_key_set(m_state.empty() == false); // Find the block offset uint64_t counter = offset / 64; diff --git a/src/lib/stream/ctr/ctr.cpp b/src/lib/stream/ctr/ctr.cpp index 463119caf..21e62fb4b 100644 --- a/src/lib/stream/ctr/ctr.cpp +++ b/src/lib/stream/ctr/ctr.cpp @@ -174,6 +174,8 @@ void CTR_BE::add_counter(const uint64_t counter) void CTR_BE::seek(uint64_t offset) { + verify_key_set(m_iv.empty() == false); + const uint64_t base_counter = m_ctr_blocks * (offset / m_counter.size()); zeroise(m_counter); diff --git a/src/lib/stream/ofb/ofb.cpp b/src/lib/stream/ofb/ofb.cpp index 5a2d63dd4..75b7048aa 100644 --- a/src/lib/stream/ofb/ofb.cpp +++ b/src/lib/stream/ofb/ofb.cpp @@ -66,6 +66,6 @@ void OFB::set_iv(const uint8_t iv[], size_t iv_len) void OFB::seek(uint64_t) { - throw Exception("OFB does not support seeking"); + throw Not_Implemented("OFB does not support seeking"); } } diff --git a/src/lib/stream/rc4/rc4.cpp b/src/lib/stream/rc4/rc4.cpp index 60565d445..cce09d183 100644 --- a/src/lib/stream/rc4/rc4.cpp +++ b/src/lib/stream/rc4/rc4.cpp @@ -115,6 +115,6 @@ RC4::RC4(size_t s) : m_SKIP(s) {} void RC4::seek(uint64_t) { - throw Exception("RC4 does not support seeking"); + throw Not_Implemented("RC4 does not support seeking"); } } diff --git a/src/lib/stream/salsa20/info.txt b/src/lib/stream/salsa20/info.txt index 3c7fed8fe..8e9bfa568 100644 --- a/src/lib/stream/salsa20/info.txt +++ b/src/lib/stream/salsa20/info.txt @@ -1,3 +1,3 @@ <defines> -SALSA20 -> 20131128 +SALSA20 -> 20171114 </defines> diff --git a/src/lib/stream/salsa20/salsa20.cpp b/src/lib/stream/salsa20/salsa20.cpp index 3f93cee94..ce22adcb7 100644 --- a/src/lib/stream/salsa20/salsa20.cpp +++ b/src/lib/stream/salsa20/salsa20.cpp @@ -234,8 +234,23 @@ void Salsa20::clear() m_position = 0; } -void Salsa20::seek(uint64_t) +void Salsa20::seek(uint64_t offset) { - throw Not_Implemented("Salsa20::seek"); + verify_key_set(m_state.empty() == false); + + // Find the block offset + const uint64_t counter = offset / 64; + uint8_t counter8[8]; + store_le(counter, counter8); + + m_state[8] = load_le<uint32_t>(counter8, 0); + m_state[9] += load_le<uint32_t>(counter8, 1); + + salsa20(m_buffer.data(), m_state.data()); + + ++m_state[8]; + m_state[9] += (m_state[8] == 0); + + m_position = offset % 64; } } |