Skip to content

Commit 7395997

Browse files
authored
Impl zeroize without using zeroize_derive (#143)
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`
1 parent 6717592 commit 7395997

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ subtle = { version = "2.1.1", default-features = false }
2222
digest = { version = "0.10.0", default-features = false }
2323
pkcs1 = { version = "0.3.3", default-features = false, features = ["pkcs8"] }
2424
pkcs8 = { version = "0.8", default-features = false }
25-
26-
[dependencies.zeroize]
27-
version = ">=1, <1.5" # zeroize 1.4 is MSRV 1.51+
28-
features = ["alloc", "zeroize_derive"]
25+
zeroize = { version = "1", features = ["alloc"] }
2926

3027
[dependencies.serde_crate]
3128
package = "serde"

src/key.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Drop for PrecomputedValues {
138138
}
139139

140140
/// Contains the precomputed Chinese remainder theorem values.
141-
#[derive(Debug, Clone, Zeroize)]
141+
#[derive(Debug, Clone)]
142142
pub(crate) struct CRTValue {
143143
/// D mod (prime - 1)
144144
pub(crate) exp: BigInt,
@@ -148,6 +148,14 @@ pub(crate) struct CRTValue {
148148
pub(crate) r: BigInt,
149149
}
150150

151+
impl Zeroize for CRTValue {
152+
fn zeroize(&mut self) {
153+
self.exp.zeroize();
154+
self.coeff.zeroize();
155+
self.r.zeroize();
156+
}
157+
}
158+
151159
impl From<RsaPrivateKey> for RsaPublicKey {
152160
fn from(private_key: RsaPrivateKey) -> Self {
153161
(&private_key).into()

0 commit comments

Comments
 (0)