Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions aes-kw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ rust-version = "1.85"
[dependencies]
aes = "0.9"
const-oid = { version = "0.10", optional = true }
zeroize = { version = "1.5.6", optional = true, default-features = false }

[dev-dependencies]
hex-literal = "1"

[features]
default = ["oid"]
oid = ["dep:const-oid"]
zeroize = ["dep:zeroize", "aes/zeroize"]

[package.metadata.docs.rs]
all-features = true
Expand Down
3 changes: 3 additions & 0 deletions aes-kw/src/kw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,6 @@ impl<C: BlockCipherDecrypt<BlockSize = U16>> AesKw<C> {
Ok(buf)
}
}

#[cfg(feature = "zeroize")]
impl<C: zeroize::ZeroizeOnDrop> zeroize::ZeroizeOnDrop for AesKw<C> {}
3 changes: 3 additions & 0 deletions aes-kw/src/kwp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,6 @@ impl<C: BlockCipherDecrypt<BlockSize = U16>> AesKwp<C> {
.map(|res| res.try_into().unwrap())
}
}

#[cfg(feature = "zeroize")]
impl<C: zeroize::ZeroizeOnDrop> zeroize::ZeroizeOnDrop for AesKwp<C> {}
3 changes: 3 additions & 0 deletions aes-kw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub use aes;
pub use aes::cipher;
pub use aes::cipher::{KeyInit, common::InnerInit};

#[cfg(feature = "zeroize")]
pub use zeroize;

/// AES-128 key wrapping
pub type KwAes128 = AesKw<aes::Aes128>;
/// AES-192 key wrapping
Expand Down
13 changes: 13 additions & 0 deletions aes-kw/tests/kw_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,16 @@ fn error_integrity_check_failed() {

assert_eq!(res, Err(Error::IntegrityCheckFailed));
}

#[cfg(feature = "zeroize")]
#[test]
fn zeroize_on_drop() {
use zeroize::ZeroizeOnDrop;

fn assert_zeroize_on_drop<T: ZeroizeOnDrop>(_: T) {}

let key256 = hex!("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
let key128 = hex!("000102030405060708090A0B0C0D0E0F");
assert_zeroize_on_drop(KwAes256::new(&key256.into()));
assert_zeroize_on_drop(KwAes128::new(&key128.into()));
}
Loading