Skip to content

Commit

Permalink
add zeroize API to AES port
Browse files Browse the repository at this point in the history
this was missed on an earlier pass
  • Loading branch information
bunnie committed Feb 10, 2024
1 parent eb26e53 commit a3f8ff6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions services/aes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description = "AES library for Xous"
# Dependency versions enforced by Cargo.lock.
[dependencies]
cipher = "0.4.2"
zeroize = { version = "1.6.0", optional = true, default_features = false }

[features]
hazmat = [] # Expose cryptographically hazardous APIs
Expand Down
17 changes: 17 additions & 0 deletions services/aes/src/soft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ macro_rules! define_aes_impl {
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(stringify!($name)) }
}

impl Drop for $name {
#[inline]
fn drop(&mut self) {
#[cfg(feature = "zeroize")]
zeroize::Zeroize::zeroize(&mut self.keys);
}
}

#[cfg(feature = "zeroize")]
impl zeroize::ZeroizeOnDrop for $name {}

#[doc=$doc]
///block cipher (encrypt-only)
#[derive(Clone)]
Expand Down Expand Up @@ -155,6 +166,9 @@ macro_rules! define_aes_impl {
}
}

#[cfg(feature = "zeroize")]
impl zeroize::ZeroizeOnDrop for $name_enc {}

#[doc=$doc]
///block cipher (decrypt-only)
#[derive(Clone)]
Expand Down Expand Up @@ -213,6 +227,9 @@ macro_rules! define_aes_impl {
}
}

#[cfg(feature = "zeroize")]
impl zeroize::ZeroizeOnDrop for $name_dec {}

pub(crate) struct $name_back_enc<'a>(&'a $name);

impl<'a> BlockSizeUser for $name_back_enc<'a> {
Expand Down

0 comments on commit a3f8ff6

Please sign in to comment.