Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sha3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![forbid(unsafe_code)]
#![warn(missing_docs)]

pub use digest::{self, Digest};
pub use digest::{self, CustomizedInit, Digest};

use core::fmt;
use digest::{
Expand Down
12 changes: 7 additions & 5 deletions sha3/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,6 @@ macro_rules! impl_cshake {
pub type $full_name = CoreWrapper<$name>;

impl $name {
/// Creates a new CSHAKE instance with the given customization.
pub fn new(customization: &[u8]) -> Self {
Self::new_with_function_name(&[], customization)
}

/// Creates a new CSHAKE instance with the given function name and customization.
/// Note that the function name is intended for use by NIST and should only be set to
/// values defined by NIST. You probably don't need to use this function.
Expand Down Expand Up @@ -642,5 +637,12 @@ macro_rules! impl_cshake {

#[cfg(feature = "zeroize")]
impl ZeroizeOnDrop for $reader {}

impl CustomizedInit for $name {
#[inline]
fn new_customized(customization: &[u8]) -> Self {
Self::new_with_function_name(&[], customization)
}
}
};
}
28 changes: 7 additions & 21 deletions sha3/tests/cshake.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt::Debug;
use digest::ExtendableOutput;
#[cfg(feature = "reset")]
use digest::ExtendableOutputReset;
use digest::{CustomizedInit, ExtendableOutput};

#[cfg(feature = "reset")]
pub(crate) fn cshake_reset_test<D, F>(input: &[u8], output: &[u8], new: F) -> Option<&'static str>
Expand Down Expand Up @@ -88,17 +88,17 @@ where
}

macro_rules! new_cshake_test {
($name:ident, $test_name:expr, $hasher:ty, $hasher_core:ty, $test_func:ident $(,)?) => {
($name:ident, $test_name:expr, $hasher: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();
if let Some(desc) = $test_func(input, output, || {
<$hasher>::from_core(<$hasher_core>::new(customization))
}) {
if let Some(desc) =
$test_func(input, output, || <$hasher>::new_customized(customization))
{
panic!(
"\n\
Failed test №{}: {}\n\
Expand All @@ -117,29 +117,15 @@ new_cshake_test!(
cshake128_reset,
"cshake128",
sha3::CShake128,
sha3::CShake128Core,
cshake_reset_test
);
#[cfg(feature = "reset")]
new_cshake_test!(
cshake256_reset,
"cshake256",
sha3::CShake256,
sha3::CShake256Core,
cshake_reset_test
);

new_cshake_test!(
cshake128,
"cshake128",
sha3::CShake128,
sha3::CShake128Core,
cshake_test
);
new_cshake_test!(
cshake256,
"cshake256",
sha3::CShake256,
sha3::CShake256Core,
cshake_test
);
new_cshake_test!(cshake128, "cshake128", sha3::CShake128, cshake_test);
new_cshake_test!(cshake256, "cshake256", sha3::CShake256, cshake_test);
Loading