use core::fmt::Debug; use digest::ExtendableOutput; #[cfg(feature = "reset")] use digest::ExtendableOutputReset;
#[cfg(feature = "reset")] pub(crate) fn cshake_reset_test<D, F>(input: &[u8], output: &[u8], new: F) -> Option<&'color:blue'>'static str> where
D: ExtendableOutputReset + Debug + Clone,
F: Fn() -> D,
{ letmut hasher = new(); letmut buf = [0u8; 1024]; let buf = &mut buf[..output.len()]; // Test that it works when accepting the message all at once
hasher.update(input); letmut 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 in1..core::cmp::min(17, input.len()) { letmut hasher = new(); 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
}
pub(crate) fn cshake_test<D, F>(input: &[u8], output: &[u8], new: F) -> Option<&'static str> where
D: ExtendableOutput + Debug + Clone,
F: Fn() -> D,
{ letmut hasher = new(); letmut buf = [0u8; 1024]; let buf = &mut buf[..output.len()]; // Test that it works when accepting the message all at once
hasher.update(input); letmut hasher2 = hasher.clone();
hasher.finalize_xof_into(buf); if buf != output { return Some("whole message");
}
buf.iter_mut().for_each(|b| *b = 0);
// Test that it works when accepting the message in chunks for n in1..core::cmp::min(17, input.len()) { letmut hasher = new(); 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);
}
None
}
macro_rules! new_cshake_test {
($name:ident, $test_name:expr, $hasher:ty, $hasher_core:ty, $test_func:ident $(,)?) => { #[test] fn $name() { use digest::dev::blobby::Blob3Iterator; let data = include_bytes!(concat!("data/", $test_name, ".blb"));
for (i, row) in Blob3Iterator::new(data).unwrap().enumerate() { let [customization, input, output] = row.unwrap(); iflet Some(desc) = $test_func(input, output, || {
<$hasher>::from_core(<$hasher_core>::new(customization))
}) {
panic!( "\n\
Failed test №{}: {}\n\
input:\t{:?}\n\
output:\t{:?}\n",
i, desc, input, output,
);
}
}
}
};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.