Skip to content

Commit b6d5aff

Browse files
committed
turbo-shake: fix zeroize
1 parent 8850ac5 commit b6d5aff

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

turbo-shake/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ impl<Rate: BlockSizes, const DS: u8> fmt::Debug for TurboShake<Rate, DS> {
159159
}
160160
}
161161

162+
impl<Rate: BlockSizes, const DS: u8> Drop for TurboShake<Rate, DS> {
163+
fn drop(&mut self) {
164+
#[cfg(feature = "zeroize")]
165+
{
166+
use digest::zeroize::Zeroize;
167+
self.state.zeroize();
168+
// self.buffer is zeroized by its `Drop`
169+
}
170+
}
171+
}
172+
162173
#[cfg(feature = "zeroize")]
163174
impl<Rate: BlockSizes, const DS: u8> digest::zeroize::ZeroizeOnDrop for TurboShake<Rate, DS> {}
164175

@@ -199,6 +210,20 @@ impl<Rate: BlockSizes> fmt::Debug for TurboShakeReader<Rate> {
199210
}
200211
}
201212

213+
impl<Rate: BlockSizes> Drop for TurboShakeReader<Rate> {
214+
fn drop(&mut self) {
215+
#[cfg(feature = "zeroize")]
216+
{
217+
use digest::zeroize::Zeroize;
218+
self.state.zeroize();
219+
// self.buffer is zeroized by its `Drop`
220+
}
221+
}
222+
}
223+
224+
#[cfg(feature = "zeroize")]
225+
impl<Rate: BlockSizes> digest::zeroize::ZeroizeOnDrop for TurboShakeReader<Rate> {}
226+
202227
/// TurboSHAKE128 hasher with domain separator.
203228
pub type TurboShake128<const DS: u8 = DEFAULT_DS> = TurboShake<U168, DS>;
204229
/// TurboSHAKE256 hasher with domain separator.

0 commit comments

Comments
 (0)