summaryrefslogtreecommitdiffstats
path: root/rust/vendor/digest/src/dev/xof.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
commita0aa2307322cd47bbf416810ac0292925e03be87 (patch)
tree37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/digest/src/dev/xof.rs
parentInitial commit. (diff)
downloadsuricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz
suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/vendor/digest/src/dev/xof.rs')
-rw-r--r--rust/vendor/digest/src/dev/xof.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/rust/vendor/digest/src/dev/xof.rs b/rust/vendor/digest/src/dev/xof.rs
new file mode 100644
index 0000000..9e5d07a
--- /dev/null
+++ b/rust/vendor/digest/src/dev/xof.rs
@@ -0,0 +1,51 @@
+use crate::ExtendableOutputReset;
+use core::fmt::Debug;
+
+/// Resettable XOF test
+pub fn xof_reset_test<D>(input: &[u8], output: &[u8]) -> Option<&'static str>
+where
+ D: ExtendableOutputReset + Default + Debug + Clone,
+{
+ let mut hasher = D::default();
+ let mut buf = [0u8; 1024];
+ let buf = &mut buf[..output.len()];
+ // Test that it works when accepting the message all at once
+ hasher.update(input);
+ let mut hasher2 = hasher.clone();
+ hasher.finalize_xof_into(buf);
+ if buf != output {
+ return Some("whole message");
+ }
+ buf.iter_mut().for_each(|b| *b = 0);
+
+ // Test if reset works correctly
+ hasher2.reset();
+ hasher2.update(input);
+ hasher2.finalize_xof_reset_into(buf);
+ if buf != output {
+ return Some("whole message after reset");
+ }
+ buf.iter_mut().for_each(|b| *b = 0);
+
+ // Test that it works when accepting the message in chunks
+ for n in 1..core::cmp::min(17, input.len()) {
+ let mut hasher = D::default();
+ for chunk in input.chunks(n) {
+ hasher.update(chunk);
+ hasher2.update(chunk);
+ }
+ hasher.finalize_xof_into(buf);
+ if buf != output {
+ return Some("message in chunks");
+ }
+ buf.iter_mut().for_each(|b| *b = 0);
+
+ hasher2.finalize_xof_reset_into(buf);
+ if buf != output {
+ return Some("message in chunks");
+ }
+ buf.iter_mut().for_each(|b| *b = 0);
+ }
+
+ None
+}