From 5cab3fa67040f63f82d36a8e4112a3488d3b02aa Mon Sep 17 00:00:00 2001 From: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:58:17 -0600 Subject: [PATCH] Add zeroizing support for `MontyParams` (#706) --- src/modular/monty_form.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modular/monty_form.rs b/src/modular/monty_form.rs index 945a8c27..54f0d1a5 100644 --- a/src/modular/monty_form.rs +++ b/src/modular/monty_form.rs @@ -158,6 +158,18 @@ impl ConstantTimeEq for MontyParams { } } +#[cfg(feature = "zeroize")] +impl zeroize::Zeroize for MontyParams { + 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)] @@ -318,10 +330,10 @@ impl ConstantTimeEq for MontyForm { } } -/// NOTE: this does _not_ zeroize the parameters, in order to maintain some form of type consistency #[cfg(feature = "zeroize")] impl zeroize::Zeroize for MontyForm { fn zeroize(&mut self) { - self.montgomery_form.zeroize() + self.montgomery_form.zeroize(); + self.params.zeroize(); } }