diff --git a/Cargo.toml b/Cargo.toml index 8835755..6f6309b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ default = ["std"] rand = ["dep:rand", "crypto-bigint/rand_core"] serde = ["dep:serde", "crypto-bigint/serde"] -zeroize = ["dep:zeroize"] +zeroize = ["dep:zeroize", "crypto-bigint/zeroize"] std = ["num-traits/std", "ark-std/std", "ark-ff/std", "serde/std", "rand/std", "zeroize/std"] ark_std = ["dep:ark-std"] diff --git a/src/field/ark_ff_field.rs b/src/field/ark_ff_field.rs index a069e3e..ea6ef0f 100644 --- a/src/field/ark_ff_field.rs +++ b/src/field/ark_ff_field.rs @@ -430,6 +430,17 @@ impl UniformRand for ArkField { } } +// +// Zeroize +// + +#[cfg(feature = "zeroize")] +impl zeroize::Zeroize for ArkField { + fn zeroize(&mut self) { + self.0.zeroize() + } +} + // // Traits from ark-ff // @@ -492,12 +503,6 @@ impl AdditiveGroup for ArkField { const ZERO: Self = ::ZERO; } -impl zeroize::Zeroize for ArkField { - fn zeroize(&mut self) { - self.0.zeroize() - } -} - impl ArkWrappedField for ArkField { type BasePrimeField = F::BasePrimeField; diff --git a/src/field/ark_ff_fp.rs b/src/field/ark_ff_fp.rs index 90136ed..cd852c2 100644 --- a/src/field/ark_ff_fp.rs +++ b/src/field/ark_ff_fp.rs @@ -516,6 +516,17 @@ impl, const N: usize> UniformRand for Fp { } } +// +// Zeroize +// + +#[cfg(feature = "zeroize")] +impl, const N: usize> zeroize::Zeroize for Fp { + fn zeroize(&mut self) { + self.0.zeroize() + } +} + // // Traits from ark-ff // @@ -578,12 +589,6 @@ impl, const N: usize> AdditiveGroup for Fp { const ZERO: Self = ::ZERO; } -impl, const N: usize> zeroize::Zeroize for Fp { - fn zeroize(&mut self) { - self.0.zeroize() - } -} - impl, const N: usize> ArkWrappedField for Fp { type BasePrimeField = Self; diff --git a/src/field/crypto_bigint_boxed_monty.rs b/src/field/crypto_bigint_boxed_monty.rs index 63d3230..a14a0c5 100644 --- a/src/field/crypto_bigint_boxed_monty.rs +++ b/src/field/crypto_bigint_boxed_monty.rs @@ -480,6 +480,17 @@ impl PrimeField for BoxedMontyField { } } +// +// Zeroize +// + +#[cfg(feature = "zeroize")] +impl zeroize::Zeroize for BoxedMontyField { + fn zeroize(&mut self) { + self.0.zeroize() + } +} + #[allow(clippy::arithmetic_side_effects, clippy::cast_lossless)] #[cfg(test)] mod tests { diff --git a/src/field/crypto_bigint_const_monty.rs b/src/field/crypto_bigint_const_monty.rs index ebb1a7e..4b84627 100644 --- a/src/field/crypto_bigint_const_monty.rs +++ b/src/field/crypto_bigint_const_monty.rs @@ -597,6 +597,17 @@ where } } +// +// Zeroize +// + +#[cfg(feature = "zeroize")] +impl, const LIMBS: usize> zeroize::Zeroize for ConstMontyField { + fn zeroize(&mut self) { + self.0.zeroize() + } +} + // // Traits from crypto_bigint // @@ -644,12 +655,6 @@ impl, const LIMBS: usize> Retrieve for ConstMontyField, const LIMBS: usize> zeroize::DefaultIsZeroes - for ConstMontyField -{ -} - // // Predefined fields of various sizes for convenience // diff --git a/src/field/crypto_bigint_monty.rs b/src/field/crypto_bigint_monty.rs index 0fc95b0..8ef8046 100644 --- a/src/field/crypto_bigint_monty.rs +++ b/src/field/crypto_bigint_monty.rs @@ -538,6 +538,17 @@ impl PrimeField for MontyField { } } +// +// Zeroize +// + +#[cfg(feature = "zeroize")] +impl zeroize::Zeroize for MontyField { + fn zeroize(&mut self) { + self.0.zeroize() + } +} + // // Predefined fields of various sizes for convenience // diff --git a/src/ring/crypto_bigint_int.rs b/src/ring/crypto_bigint_int.rs index 4c60edc..1f3567d 100644 --- a/src/ring/crypto_bigint_int.rs +++ b/src/ring/crypto_bigint_int.rs @@ -553,6 +553,7 @@ impl TryFrom<&crypto_bigint::Uint zeroize::DefaultIsZeroes for Int {} + // // Traits from crypto_bigint // diff --git a/src/semiring/boolean.rs b/src/semiring/boolean.rs index e3eb90d..b82ec06 100644 --- a/src/semiring/boolean.rs +++ b/src/semiring/boolean.rs @@ -367,6 +367,13 @@ impl Distribution for StandardUniform { } } +// +// Zeroize +// + +#[cfg(feature = "zeroize")] +impl zeroize::DefaultIsZeroes for Boolean {} + // // Tests // diff --git a/src/semiring/crypto_bigint_uint.rs b/src/semiring/crypto_bigint_uint.rs index 3936ebe..843595e 100644 --- a/src/semiring/crypto_bigint_uint.rs +++ b/src/semiring/crypto_bigint_uint.rs @@ -599,6 +599,13 @@ where } } +// +// Zeroize +// + +#[cfg(feature = "zeroize")] +impl zeroize::DefaultIsZeroes for Uint {} + // // Traits from crypto_bigint //