Skip to content

Commit

Permalink
Impl zeroize without using zeroize_derive (#143)
Browse files Browse the repository at this point in the history
The `zeroize_derive` crate has quite a few dependencies, and in
particular `syn` is a fairly large one with not-insignificant compile
times.

Together with dignifiedquire/num-bigint#35, this will remove the
following dependencies from the dependency tree:

- `proc-macro2`
- `quote`
- `syn`
- `synstructure`
- `zeroize_derive`
  • Loading branch information
tarcieri committed Feb 2, 2022
1 parent 6717592 commit 7395997
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ subtle = { version = "2.1.1", default-features = false }
digest = { version = "0.10.0", default-features = false }
pkcs1 = { version = "0.3.3", default-features = false, features = ["pkcs8"] }
pkcs8 = { version = "0.8", default-features = false }

[dependencies.zeroize]
version = ">=1, <1.5" # zeroize 1.4 is MSRV 1.51+
features = ["alloc", "zeroize_derive"]
zeroize = { version = "1", features = ["alloc"] }

[dependencies.serde_crate]
package = "serde"
Expand Down
10 changes: 9 additions & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Drop for PrecomputedValues {
}

/// Contains the precomputed Chinese remainder theorem values.
#[derive(Debug, Clone, Zeroize)]
#[derive(Debug, Clone)]
pub(crate) struct CRTValue {
/// D mod (prime - 1)
pub(crate) exp: BigInt,
Expand All @@ -148,6 +148,14 @@ pub(crate) struct CRTValue {
pub(crate) r: BigInt,
}

impl Zeroize for CRTValue {
fn zeroize(&mut self) {
self.exp.zeroize();
self.coeff.zeroize();
self.r.zeroize();
}
}

impl From<RsaPrivateKey> for RsaPublicKey {
fn from(private_key: RsaPrivateKey) -> Self {
(&private_key).into()
Expand Down

0 comments on commit 7395997

Please sign in to comment.