aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/stream/salsa20
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-11-14 09:57:58 -0500
committerJack Lloyd <[email protected]>2017-11-14 09:57:58 -0500
commit72a5d030625341cc372b5a7ced454dd6d309f3e5 (patch)
tree1ae06b31b2e9e760915a186ace3cee169be1b9fd /src/lib/stream/salsa20
parent1091bd40435bd5e01cab27f488c03f0a7d2e38d7 (diff)
Support seeking in Salsa20
Add a test that StreamCipher::seek throws if not keyed.
Diffstat (limited to 'src/lib/stream/salsa20')
-rw-r--r--src/lib/stream/salsa20/info.txt2
-rw-r--r--src/lib/stream/salsa20/salsa20.cpp19
2 files changed, 18 insertions, 3 deletions
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;
}
}