Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeroize the IVs after use #143

Merged
merged 1 commit into from
Jun 6, 2023
Merged
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
3 changes: 3 additions & 0 deletions aws-lc-rs/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ fn encrypt_aes_ctr_mode(
let mut buffer = [0u8; AES_BLOCK_LEN];

aes_ctr128_encrypt(key, &mut iv, &mut buffer, in_out);
iv.zeroize();

Ok(context)
}
Expand Down Expand Up @@ -692,6 +693,7 @@ fn encrypt_aes_cbc_mode(
};

aes_cbc_encrypt(key, &mut iv, in_out);
iv.zeroize();

Ok(context)
}
Expand All @@ -716,6 +718,7 @@ fn decrypt_aes_cbc_mode(
};

aes_cbc_decrypt(key, &mut iv, in_out);
iv.zeroize();

Ok(context)
}
Expand Down
7 changes: 7 additions & 0 deletions aws-lc-rs/src/iv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use crate::error::Unspecified;
use crate::{error, rand};
use zeroize::Zeroize;

/// An initalization vector that must be unique for the lifetime of the associated key
/// it is used with.
Expand Down Expand Up @@ -53,6 +54,12 @@ impl<const L: usize> FixedLength<L> {
}
}

impl<const L: usize> Drop for FixedLength<L> {
fn drop(&mut self) {
self.0.zeroize();
}
}

impl<const L: usize> AsMut<[u8; L]> for FixedLength<L> {
#[inline]
fn as_mut(&mut self) -> &mut [u8; L] {
Expand Down