diff --git a/Cargo.lock b/Cargo.lock index 3c62511c..602db27f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,11 +208,32 @@ dependencies = [ "serde_json", ] +[[package]] +name = "zerocopy" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2bd783c6247b80c3ac2267afe3042452f184478184264e0c1532bbf59adcb7" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56feebc4664bdb37f39c0b1b8fc8fa2f5648e3ec5f9cf4344978b4b7ca561fff" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zeroize" version = "1.6.0" dependencies = [ "serde", + "zerocopy", "zeroize_derive", ] diff --git a/zeroize/Cargo.toml b/zeroize/Cargo.toml index ed6f5286..41f0bf64 100644 --- a/zeroize/Cargo.toml +++ b/zeroize/Cargo.toml @@ -20,6 +20,7 @@ rust-version = "1.60" [dependencies] serde = { version = "1.0", default-features = false, optional = true } zeroize_derive = { version = "1.3", path = "derive", optional = true } +zerocopy = { version = "0.7.19", default-features = false, features = ["simd"] } [features] default = ["alloc"] diff --git a/zeroize/src/aarch64.rs b/zeroize/src/aarch64.rs index 07744d01..57e461b8 100644 --- a/zeroize/src/aarch64.rs +++ b/zeroize/src/aarch64.rs @@ -7,6 +7,8 @@ use crate::{atomic_fence, volatile_write, Zeroize}; use core::arch::aarch64::*; +use zerocopy::FromZeroes; + macro_rules! impl_zeroize_for_simd_register { ($($type:ty),* $(,)?) => { $( @@ -14,7 +16,7 @@ macro_rules! impl_zeroize_for_simd_register { impl Zeroize for $type { #[inline] fn zeroize(&mut self) { - volatile_write(self, unsafe { core::mem::zeroed() }); + volatile_write(self, Self::new_zeroed()); atomic_fence(); } } diff --git a/zeroize/src/x86.rs b/zeroize/src/x86.rs index 5e4bfcb3..8c19bbad 100644 --- a/zeroize/src/x86.rs +++ b/zeroize/src/x86.rs @@ -8,6 +8,8 @@ use core::arch::x86::*; #[cfg(target_arch = "x86_64")] use core::arch::x86_64::*; +use zerocopy::FromZeroes; + macro_rules! impl_zeroize_for_simd_register { ($($type:ty),* $(,)?) => { $( @@ -15,7 +17,7 @@ macro_rules! impl_zeroize_for_simd_register { impl Zeroize for $type { #[inline] fn zeroize(&mut self) { - volatile_write(self, unsafe { core::mem::zeroed() }); + volatile_write(self, Self::new_zeroed()); atomic_fence(); } }