Skip to content

Commit

Permalink
chore: protect public key zeroization against updates (#235)
Browse files Browse the repository at this point in the history
Ristretto public key zeroizing is done manually due to the use of
`OnceCell`. I recently came across a [clever design
pattern](https://github.com/BLAKE3-team/BLAKE3/blob/master/src/lib.rs#L447-L466)
that uses destructuring. The idea is that future changes to the
underlying struct will trigger a compiler error to ensure that the
zeroization implementation is also updated.

This PR implements such a change.
  • Loading branch information
AaronFeickert authored Oct 13, 2024
1 parent 00120e6 commit 998c91a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ristretto/ristretto_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,13 @@ impl RistrettoPublicKey {
impl Zeroize for RistrettoPublicKey {
/// Zeroizes both the point and (if it exists) the compressed point
fn zeroize(&mut self) {
self.point.zeroize();
// This destructuring is to trigger a compiler error on future updates!
let Self { point, compressed } = self;

point.zeroize();

// Need to empty the cell
if let Some(mut compressed) = self.compressed.take() {
if let Some(mut compressed) = compressed.take() {
compressed.zeroize();
}
}
Expand Down

0 comments on commit 998c91a

Please sign in to comment.