1#![cfg_attr(not(feature = "std"), no_std)]
3#![forbid(unsafe_code)]
4
5macro_rules! impl_zeroize_on_drop_tuple {
6 ($type:ty) => {
7 impl dcrypt_internal::zeroing::Zeroize for $type {
8 fn zeroize(&mut self) {
9 dcrypt_internal::zeroing::Zeroize::zeroize(&mut self.0);
10 }
11 }
12
13 impl Drop for $type {
14 fn drop(&mut self) {
15 dcrypt_internal::zeroing::Zeroize::zeroize(self);
16 }
17 }
18
19 impl dcrypt_internal::zeroing::ZeroizeOnDrop for $type {}
20 };
21}
22
23#[cfg(test)]
24pub(crate) mod test_rng {
25 use core::sync::atomic::{AtomicU64, Ordering};
26 use dcrypt_internal::random::{
27 try_fill_bytes_zeroing_on_error, ChaCha20Rng, CryptoRng, Error, RngCore,
28 };
29
30 static NEXT_STREAM: AtomicU64 = AtomicU64::new(1);
31
32 pub struct TestRng;
33
34 impl RngCore for TestRng {
35 fn try_fill_bytes(&mut self, destination: &mut [u8]) -> Result<(), Error> {
36 let stream = NEXT_STREAM.fetch_add(1, Ordering::Relaxed);
37 let mut seed = [0u8; 32];
38 seed[..8].copy_from_slice(&stream.to_le_bytes());
39 let mut rng = ChaCha20Rng::from_seed(seed);
40 try_fill_bytes_zeroing_on_error(&mut rng, destination)
41 }
42 }
43
44 impl CryptoRng for TestRng {}
45}
46
47#[cfg(not(feature = "std"))]
50extern crate alloc;
51
52pub mod ecies;
53pub mod error;
54
55pub use ecies::{EciesP224, EciesP256, EciesP384, EciesP521};
57pub use error::{Error, Result};