Skip to content

Commit 4033405

Browse files
committed
sha3: Add hazmat TSHK API new_with_round_count
1 parent a16eb1b commit 4033405

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

sha3/src/macros.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,36 @@ macro_rules! impl_turbo_shake {
240240
#[allow(non_camel_case_types)]
241241
pub struct $name {
242242
domain_separation: u8,
243+
round_count: usize,
243244
state: Sha3State,
244245
}
245246

246247
impl $name {
247248
/// Creates a new TurboSHAKE instance with the given domain separation.
248249
/// Note that the domain separation needs to be a byte with a value in
249-
/// the range [0x01, . . . , 0x7F]
250+
/// the range [0x01, . . . , 0x7F].
250251
pub fn new(domain_separation: u8) -> Self {
251252
assert!((0x01..=0x7F).contains(&domain_separation));
252253
Self {
253254
domain_separation,
255+
round_count: TURBO_SHAKE_ROUND_COUNT,
254256
state: Sha3State::new(TURBO_SHAKE_ROUND_COUNT),
255257
}
256258
}
259+
260+
/// Creates a new TurboSHAKE instance with the given domain separation
261+
/// and round_count.
262+
/// This is a low-level "hazmat" API.
263+
/// Note that the domain separation needs to be a byte with a value in
264+
/// the range [0x01, . . . , 0x7F].
265+
pub fn new_with_round_count(domain_separation: u8, round_count: usize) -> Self {
266+
assert!((0x01..=0x7F).contains(&domain_separation));
267+
Self {
268+
domain_separation,
269+
round_count,
270+
state: Sha3State::new(round_count),
271+
}
272+
}
257273
}
258274

259275
impl HashMarker for $name {}
@@ -296,7 +312,7 @@ macro_rules! impl_turbo_shake {
296312
impl Reset for $name {
297313
#[inline]
298314
fn reset(&mut self) {
299-
*self = Self::new(self.domain_separation);
315+
*self = Self::new_with_round_count(self.domain_separation, self.round_count);
300316
}
301317
}
302318

0 commit comments

Comments
 (0)