Skip to content

Commit 4997227

Browse files
authored
belt-kwp: add optional zeroize support (#88)
1 parent 9f475e5 commit 4997227

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

belt-kwp/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## 0.2.0 (UNRELEASED)
8+
### Added
9+
- Optional `zeroize` support ([#88])
10+
811
### Removed
912
- `std` and `alloc` crate features ([#87])
13+
- Implementation of `Copy` for `BeltKwp` ([#88])
1014

1115
[#87]: https://github.com/RustCrypto/key-wraps/pull/87
16+
[#88]: https://github.com/RustCrypto/key-wraps/pull/88
1217

1318
## 0.1.1 (2026-05-27)
1419
### Changed

belt-kwp/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ rust-version = "1.85"
1313

1414
[dependencies]
1515
belt-block = "0.2"
16+
zeroize = { version = "1.8", optional = true, default-features = false }
1617

1718
[dev-dependencies]
1819
hex-literal = "1"
1920

21+
[features]
22+
zeroize = ["dep:zeroize", "belt-block/zeroize"]
23+
2024
[package.metadata.docs.rs]
2125
all-features = true

belt-kwp/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub type WrappedKey<N> = Array<u8, Sum<N, IvLen>>;
2929
pub const IV_LEN: usize = IvLen::USIZE;
3030

3131
/// BelT Key Wrap instance as defined in STB 34.101.34-2020.
32-
#[derive(Clone, Copy, PartialEq)]
32+
#[derive(Clone, PartialEq)]
3333
pub struct BeltKwp {
3434
key: [u32; 8],
3535
}
@@ -206,6 +206,19 @@ impl KeySizeUser for BeltKwp {
206206
}
207207
}
208208

209+
impl Drop for BeltKwp {
210+
fn drop(&mut self) {
211+
#[cfg(feature = "zeroize")]
212+
{
213+
use zeroize::Zeroize;
214+
self.key.zeroize();
215+
}
216+
}
217+
}
218+
219+
#[cfg(feature = "zeroize")]
220+
impl zeroize::ZeroizeOnDrop for BeltKwp {}
221+
209222
/// Errors emitted from the wrap and unwrap operations.
210223
#[derive(Debug)]
211224
pub enum Error {

0 commit comments

Comments
 (0)