Skip to content

Commit

Permalink
Add zeroizing support for MontyParams (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert authored Dec 2, 2024
1 parent 5ac4b3e commit 5cab3fa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/modular/monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ impl<const LIMBS: usize> ConstantTimeEq for MontyParams<LIMBS> {
}
}

#[cfg(feature = "zeroize")]
impl<const LIMBS: usize> zeroize::Zeroize for MontyParams<LIMBS> {
fn zeroize(&mut self) {
self.modulus.zeroize();
self.one.zeroize();
self.r2.zeroize();
self.r3.zeroize();
self.mod_neg_inv.zeroize();
self.mod_leading_zeros.zeroize();
}
}

/// An integer in Montgomery form represented using `LIMBS` limbs.
/// The odd modulus is set at runtime.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -318,10 +330,10 @@ impl<const LIMBS: usize> ConstantTimeEq for MontyForm<LIMBS> {
}
}

/// NOTE: this does _not_ zeroize the parameters, in order to maintain some form of type consistency
#[cfg(feature = "zeroize")]
impl<const LIMBS: usize> zeroize::Zeroize for MontyForm<LIMBS> {
fn zeroize(&mut self) {
self.montgomery_form.zeroize()
self.montgomery_form.zeroize();
self.params.zeroize();
}
}

0 comments on commit 5cab3fa

Please sign in to comment.