Skip to content

Commit

Permalink
Zeroize HKDF key on drop
Browse files Browse the repository at this point in the history
  • Loading branch information
tofay committed Nov 21, 2024
1 parent b82e85a commit 7558d13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ openssl-sys = "0.9.104"
rustls = { version = "0.23.0", default-features = false }
rustls-webpki = { version = "0.102.2", default-features = false }
once_cell = "1.8.0"
zeroize = "1.8.1"

[features]
default = ["tls12"]
Expand Down
7 changes: 7 additions & 0 deletions src/hkdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustls::crypto::hmac::{Hmac as _, Tag};
use rustls::crypto::tls13::{
Hkdf as RustlsHkdf, HkdfExpander as RustlsHkdfExpander, OkmBlock, OutputLengthError,
};
use zeroize::Zeroize;

const MAX_MD_SIZE: usize = openssl_sys::EVP_MAX_MD_SIZE as usize;

Expand Down Expand Up @@ -124,6 +125,12 @@ fn add_hkdf_info<T>(ctx: &mut PkeyCtxRef<T>, info: &[&[u8]]) -> Result<(), Error
Ok(())
}

impl Drop for HkdfExpander {
fn drop(&mut self) {
self.private_key.zeroize();
}
}

#[cfg(test)]
mod test {
use rustls::crypto::tls13::Hkdf;
Expand Down

0 comments on commit 7558d13

Please sign in to comment.