Skip to content

Commit 05db3ae

Browse files
authored
Add zeroize support (#545)
1 parent 6243d29 commit 05db3ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+768
-1281
lines changed

.github/workflows/tiger.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
set-msrv:
2525
uses: RustCrypto/actions/.github/workflows/set-msrv.yml@master
2626
with:
27-
msrv: 1.71.0
27+
msrv: 1.74.0
2828

2929
build:
3030
needs: set-msrv

Cargo.lock

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ members = [
2626

2727
[profile.dev]
2828
opt-level = 2
29+
30+
[patch.crates-io]
31+
digest = { git = 'https://github.com/RustCrypto/traits' }

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Additionally all crates do not require the standard library (i.e. `no_std` capab
3232
| [Skein] | [`skein`] | [![crates.io](https://img.shields.io/crates/v/skein.svg)](https://crates.io/crates/skein) | [![Documentation](https://docs.rs/skein/badge.svg)](https://docs.rs/skein) | ![MSRV 1.71][msrv-1.71] | :green_heart: |
3333
| [SM3] (OSCCA GM/T 0004-2012) | [`sm3`] | [![crates.io](https://img.shields.io/crates/v/sm3.svg)](https://crates.io/crates/sm3) | [![Documentation](https://docs.rs/sm3/badge.svg)](https://docs.rs/sm3) | ![MSRV 1.71][msrv-1.71] | :green_heart: |
3434
| [Streebog] (GOST R 34.11-2012) | [`streebog`] | [![crates.io](https://img.shields.io/crates/v/streebog.svg)](https://crates.io/crates/streebog) | [![Documentation](https://docs.rs/streebog/badge.svg)](https://docs.rs/streebog) | ![MSRV 1.71][msrv-1.71] | :yellow_heart: |
35-
| [Tiger] | [`tiger`] | [![crates.io](https://img.shields.io/crates/v/tiger.svg)](https://crates.io/crates/tiger) | [![Documentation](https://docs.rs/tiger/badge.svg)](https://docs.rs/tiger) | ![MSRV 1.71][msrv-1.71] | :green_heart: |
35+
| [Tiger] | [`tiger`] | [![crates.io](https://img.shields.io/crates/v/tiger.svg)](https://crates.io/crates/tiger) | [![Documentation](https://docs.rs/tiger/badge.svg)](https://docs.rs/tiger) | ![MSRV 1.74][msrv-1.74] | :green_heart: |
3636
| [Whirlpool] | [`whirlpool`] | [![crates.io](https://img.shields.io/crates/v/whirlpool.svg)](https://crates.io/crates/whirlpool) | [![Documentation](https://docs.rs/whirlpool/badge.svg)](https://docs.rs/whirlpool) | ![MSRV 1.71][msrv-1.71] | :green_heart: |
3737

3838
NOTE: the [`blake3`] crate implements the `digest` traits used by the rest of the hashes in this repository, but is maintained by the BLAKE3 team.
@@ -235,6 +235,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
235235
[deps-link]: https://deps.rs/repo/github/RustCrypto/hashes
236236
[msrv-1.71]: https://img.shields.io/badge/rustc-1.71.0+-blue.svg
237237
[msrv-1.72]: https://img.shields.io/badge/rustc-1.72.0+-blue.svg
238+
[msrv-1.74]: https://img.shields.io/badge/rustc-1.74.0+-blue.svg
238239

239240
[//]: # (crates)
240241

ascon-hash/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![no_std]
2-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
32
#![doc = include_str!("../README.md")]
43
#![doc(
54
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
65
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
76
)]
7+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
88
#![warn(missing_docs)]
99

1010
use core::marker::PhantomData;

belt-hash/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ hex-literal = "0.4"
2424
default = ["oid", "std"]
2525
std = ["digest/std"]
2626
oid = ["digest/oid"]
27+
zeroize = ["digest/zeroize"]
28+
29+
[package.metadata.docs.rs]
30+
all-features = true
31+
rustdoc-args = ["--cfg", "docsrs"]

belt-hash/src/lib.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![no_std]
22
#![doc = include_str!("../README.md")]
3-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
43
#![doc(
54
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
65
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
76
)]
7+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
88
#![warn(missing_docs, rust_2018_idioms)]
99
#![forbid(unsafe_code)]
1010

@@ -24,6 +24,9 @@ use digest::{
2424
HashMarker, Output,
2525
};
2626

27+
#[cfg(feature = "zeroize")]
28+
use digest::zeroize::{Zeroize, ZeroizeOnDrop};
29+
2730
const U32_MASK: u128 = (1 << 32) - 1;
2831
const H0: [u32; 8] = [
2932
0xC8BA94B1, 0x3BF5080A, 0x8E006D36, 0xE45D4A58, 0x9DFA0485, 0xACC7B61B, 0xC2722E25, 0x0DCEFD02,
@@ -37,6 +40,9 @@ pub struct BeltHashCore {
3740
h: [u32; 8],
3841
}
3942

43+
/// BelT hasher state.
44+
pub type BeltHash = CoreWrapper<BeltHashCore>;
45+
4046
impl BeltHashCore {
4147
fn compress_block(&mut self, block: &Block<Self>) {
4248
let x1 = [
@@ -134,8 +140,19 @@ impl AssociatedOid for BeltHashCore {
134140
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.112.0.2.0.34.101.31.81");
135141
}
136142

137-
/// BelT hasher state.
138-
pub type BeltHash = CoreWrapper<BeltHashCore>;
143+
impl Drop for BeltHashCore {
144+
fn drop(&mut self) {
145+
#[cfg(feature = "zeroize")]
146+
{
147+
self.r.zeroize();
148+
self.s.zeroize();
149+
self.h.zeroize();
150+
}
151+
}
152+
}
153+
154+
#[cfg(feature = "zeroize")]
155+
impl ZeroizeOnDrop for BeltHashCore {}
139156

140157
/// Compression function described in the section 6.3.2
141158
#[inline(always)]

blake2/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ hex-literal = "0.4"
2222
[features]
2323
default = ["std"]
2424
std = ["digest/std"]
25+
zeroize = ["digest/zeroize"]
2526
reset = [] # Enable reset functionality
2627
#simd = []
2728
#simd_opt = ["simd"]
2829
#simd_asm = ["simd_opt"]
2930
size_opt = [] # Optimize for code size. Removes some `inline(always)`
31+
32+
[package.metadata.docs.rs]
33+
all-features = true
34+
rustdoc-args = ["--cfg", "docsrs"]

blake2/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
55
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
66
)]
7+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
78
#![warn(missing_docs, rust_2018_idioms)]
89
#![cfg_attr(feature = "simd", feature(platform_intrinsics, repr_simd))]
910
#![cfg_attr(feature = "simd", allow(incomplete_features))]
@@ -30,6 +31,9 @@ use digest::{
3031
#[cfg(feature = "reset")]
3132
use digest::{FixedOutputReset, Reset};
3233

34+
#[cfg(feature = "zeroize")]
35+
use digest::zeroize::{Zeroize, ZeroizeOnDrop};
36+
3337
mod as_bytes;
3438
mod consts;
3539

blake2/src/macros.rs

+35
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ macro_rules! blake2_impl {
246246
f.write_str(concat!(stringify!($name), " { ... }"))
247247
}
248248
}
249+
250+
impl Drop for $name {
251+
fn drop(&mut self) {
252+
#[cfg(feature = "zeroize")]
253+
{
254+
self.h.zeroize();
255+
self.t.zeroize();
256+
}
257+
}
258+
}
259+
#[cfg(feature = "zeroize")]
260+
impl ZeroizeOnDrop for $name {}
249261
};
250262
}
251263

@@ -429,5 +441,28 @@ macro_rules! blake2_mac_impl {
429441
write!(f, "{}{} {{ ... }}", stringify!($name), OutSize::USIZE)
430442
}
431443
}
444+
445+
impl<OutSize> Drop for $name<OutSize>
446+
where
447+
OutSize: ArraySize + IsLessOrEqual<$max_size>,
448+
LeEq<OutSize, $max_size>: NonZero,
449+
{
450+
fn drop(&mut self) {
451+
#[cfg(feature = "zeroize")]
452+
{
453+
// `self.core` zeroized by its `Drop` impl
454+
self.buffer.zeroize();
455+
#[cfg(feature = "reset")]
456+
self.key_block.zeroize();
457+
}
458+
}
459+
}
460+
#[cfg(feature = "zeroize")]
461+
impl<OutSize> ZeroizeOnDrop for $name<OutSize>
462+
where
463+
OutSize: ArraySize + IsLessOrEqual<$max_size>,
464+
LeEq<OutSize, $max_size>: NonZero,
465+
{
466+
}
432467
};
433468
}

blake2/src/simd/simdty.rs

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use crate::as_bytes::Safe;
1111

12+
#[cfg(feature = "zeroize")]
13+
use digest::zeroize::Zeroize;
14+
1215
#[cfg(feature = "simd")]
1316
macro_rules! decl_simd {
1417
($($decl:item)*) => {
@@ -50,6 +53,16 @@ decl_simd! {
5053
pub T, pub T, pub T, pub T);
5154
}
5255

56+
#[cfg(feature = "zeroize")]
57+
impl<T: Zeroize> Zeroize for Simd4<T> {
58+
fn zeroize(&mut self) {
59+
self.0.zeroize();
60+
self.1.zeroize();
61+
self.2.zeroize();
62+
self.3.zeroize();
63+
}
64+
}
65+
5366
pub type u64x2 = Simd2<u64>;
5467

5568
pub type u32x4 = Simd4<u32>;

fsb/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ hex-literal = "0.4"
2323
[features]
2424
default = ["std"]
2525
std = ["digest/std"]
26+
zeroize = ["digest/zeroize"]
27+
28+
[package.metadata.docs.rs]
29+
all-features = true
30+
rustdoc-args = ["--cfg", "docsrs"]

fsb/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
55
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
66
)]
7+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
78
#![forbid(unsafe_code)]
89
#![warn(missing_docs, rust_2018_idioms)]
910
#![allow(non_snake_case)]
@@ -27,6 +28,9 @@ use digest::{
2728
HashMarker, Output,
2829
};
2930

31+
#[cfg(feature = "zeroize")]
32+
use digest::zeroize::{Zeroize, ZeroizeOnDrop};
33+
3034
// FSB-160
3135
fsb_impl!(
3236
Fsb160,

fsb/src/macros.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ macro_rules! fsb_impl {
1212
state: [u8; $r / 8],
1313
}
1414

15+
#[doc=$full_doc]
16+
pub type $full_state = CoreWrapper<$state>;
17+
1518
impl HashMarker for $state {}
1619

1720
impl BlockSizeUser for $state {
@@ -79,8 +82,18 @@ macro_rules! fsb_impl {
7982
}
8083
}
8184

82-
#[doc=$full_doc]
83-
pub type $full_state = CoreWrapper<$state>;
85+
impl Drop for $state {
86+
fn drop(&mut self) {
87+
#[cfg(feature = "zeroize")]
88+
{
89+
self.state.zeroize();
90+
self.blocks_len.zeroize();
91+
}
92+
}
93+
}
94+
95+
#[cfg(feature = "zeroize")]
96+
impl ZeroizeOnDrop for $state {}
8497

8598
impl $state {
8699
const SIZE_OUTPUT_COMPRESS: usize = $r / 8;

gost94/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ hex-literal = "0.4"
2323
default = ["oid", "std"]
2424
std = ["digest/std"]
2525
oid = ["digest/oid"]
26+
zeroize = ["digest/zeroize"]
27+
28+
[package.metadata.docs.rs]
29+
all-features = true
30+
rustdoc-args = ["--cfg", "docsrs"]

gost94/src/gost94_core.rs

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use digest::{
1010
HashMarker, Output,
1111
};
1212

13+
#[cfg(feature = "zeroize")]
14+
use digest::zeroize::{Zeroize, ZeroizeOnDrop};
15+
1316
use crate::params::{Block, Gost94Params, SBox};
1417

1518
const C: Block = [
@@ -273,3 +276,17 @@ impl<P: Gost94Params> fmt::Debug for Gost94Core<P> {
273276
f.write_str("Core { .. }")
274277
}
275278
}
279+
280+
impl<P: Gost94Params> Drop for Gost94Core<P> {
281+
fn drop(&mut self) {
282+
#[cfg(feature = "zeroize")]
283+
{
284+
self.h.zeroize();
285+
self.n.zeroize();
286+
self.sigma.zeroize();
287+
}
288+
}
289+
}
290+
291+
#[cfg(feature = "zeroize")]
292+
impl<P: Gost94Params> ZeroizeOnDrop for Gost94Core<P> {}

gost94/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
55
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
66
)]
7+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
78
#![warn(missing_docs, rust_2018_idioms)]
89
#![forbid(unsafe_code)]
910

groestl/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ hex-literal = "0.4"
2222
[features]
2323
default = ["std"]
2424
std = ["digest/std"]
25+
zeroize = ["digest/zeroize"]
26+
27+
[package.metadata.docs.rs]
28+
all-features = true
29+
rustdoc-args = ["--cfg", "docsrs"]

0 commit comments

Comments
 (0)