Skip to content

Commit d68d816

Browse files
Add Customized trait for CSHAKE. Use new customized in tests.
1 parent 1f79203 commit d68d816

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
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, rust_2018_idioms)]
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
@@ -440,11 +440,6 @@ macro_rules! impl_cshake {
440440
pub type $full_name = CoreWrapper<$name>;
441441

442442
impl $name {
443-
/// Creates a new CSHAKE instance with the given customization.
444-
pub fn new(customization: &[u8]) -> Self {
445-
Self::new_with_function_name(&[], customization)
446-
}
447-
448443
/// Creates a new CSHAKE instance with the given function name and customization.
449444
/// Note that the function name is intended for use by NIST and should only be set to
450445
/// values defined by NIST. You probably don't need to use this function.
@@ -613,5 +608,12 @@ macro_rules! impl_cshake {
613608

614609
#[cfg(feature = "zeroize")]
615610
impl ZeroizeOnDrop for $reader {}
611+
612+
impl CustomizedInit for $name {
613+
#[inline]
614+
fn new_customized(customization: &[u8]) -> Self {
615+
Self::new_with_function_name(&[], customization)
616+
}
617+
}
616618
};
617619
}

sha3/tests/cshake.rs

+6-20
Original file line numberDiff line numberDiff line change
@@ -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)