Skip to content

Commit 5bb7d44

Browse files
Add Customized trait for CSHAKE. Use new customized in tests.
1 parent 0d0369f commit 5bb7d44

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

sha3/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![forbid(unsafe_code)]
99
#![warn(missing_docs)]
1010

11-
pub use digest::{self, Digest};
11+
pub use digest::{self, CustomizedInit, Digest};
1212

1313
use core::fmt;
1414
use digest::{

sha3/src/macros.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,6 @@ macro_rules! impl_cshake {
469469
pub type $full_name = CoreWrapper<$name>;
470470

471471
impl $name {
472-
/// Creates a new CSHAKE instance with the given customization.
473-
pub fn new(customization: &[u8]) -> Self {
474-
Self::new_with_function_name(&[], customization)
475-
}
476-
477472
/// Creates a new CSHAKE instance with the given function name and customization.
478473
/// Note that the function name is intended for use by NIST and should only be set to
479474
/// values defined by NIST. You probably don't need to use this function.
@@ -642,5 +637,12 @@ macro_rules! impl_cshake {
642637

643638
#[cfg(feature = "zeroize")]
644639
impl ZeroizeOnDrop for $reader {}
640+
641+
impl CustomizedInit for $name {
642+
#[inline]
643+
fn new_customized(customization: &[u8]) -> Self {
644+
Self::new_with_function_name(&[], customization)
645+
}
646+
}
645647
};
646648
}

sha3/tests/cshake.rs

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::fmt::Debug;
2-
use digest::ExtendableOutput;
2+
use digest::{ExtendableOutput, CustomizedInit};
33
#[cfg(feature = "reset")]
44
use digest::ExtendableOutputReset;
55

@@ -88,17 +88,17 @@ where
8888
}
8989

9090
macro_rules! new_cshake_test {
91-
($name:ident, $test_name:expr, $hasher:ty, $hasher_core:ty, $test_func:ident $(,)?) => {
91+
($name:ident, $test_name:expr, $hasher:ty, $test_func:ident $(,)?) => {
9292
#[test]
9393
fn $name() {
9494
use digest::dev::blobby::Blob3Iterator;
9595
let data = include_bytes!(concat!("data/", $test_name, ".blb"));
9696

9797
for (i, row) in Blob3Iterator::new(data).unwrap().enumerate() {
9898
let [customization, input, output] = row.unwrap();
99-
if let Some(desc) = $test_func(input, output, || {
100-
<$hasher>::from_core(<$hasher_core>::new(customization))
101-
}) {
99+
if let Some(desc) =
100+
$test_func(input, output, || <$hasher>::new_customized(customization))
101+
{
102102
panic!(
103103
"\n\
104104
Failed test №{}: {}\n\
@@ -117,29 +117,15 @@ new_cshake_test!(
117117
cshake128_reset,
118118
"cshake128",
119119
sha3::CShake128,
120-
sha3::CShake128Core,
121120
cshake_reset_test
122121
);
123122
#[cfg(feature = "reset")]
124123
new_cshake_test!(
125124
cshake256_reset,
126125
"cshake256",
127126
sha3::CShake256,
128-
sha3::CShake256Core,
129127
cshake_reset_test
130128
);
131129

132-
new_cshake_test!(
133-
cshake128,
134-
"cshake128",
135-
sha3::CShake128,
136-
sha3::CShake128Core,
137-
cshake_test
138-
);
139-
new_cshake_test!(
140-
cshake256,
141-
"cshake256",
142-
sha3::CShake256,
143-
sha3::CShake256Core,
144-
cshake_test
145-
);
130+
new_cshake_test!(cshake128, "cshake128", sha3::CShake128, cshake_test);
131+
new_cshake_test!(cshake256, "cshake256", sha3::CShake256, cshake_test);

0 commit comments

Comments
 (0)