Skip to main content

dcrypt_hybrid/
lib.rs

1// File: crates/hybrid/src/lib.rs
2//! # dcrypt-hybrid
3//!
4//! Hybrid cryptographic schemes for the dcrypt library.
5//!
6//! This crate provides implementations of hybrid cryptographic primitives by composing
7//! classical and post-quantum schemes from other dcrypt crates. This is crucial for
8//! achieving post-quantum security for data-in-transit via "Harvest-Then-Decrypt"
9//! resistance.
10
11#![cfg_attr(not(feature = "std"), no_std)]
12#![forbid(unsafe_code)]
13
14extern crate alloc;
15
16#[cfg(test)]
17pub(crate) mod test_rng {
18    use core::sync::atomic::{AtomicU64, Ordering};
19    use dcrypt_internal::random::{
20        try_fill_bytes_zeroing_on_error, ChaCha20Rng, CryptoRng, Error, RngCore,
21    };
22
23    static NEXT_STREAM: AtomicU64 = AtomicU64::new(1);
24
25    pub struct TestRng;
26
27    impl RngCore for TestRng {
28        fn try_fill_bytes(&mut self, destination: &mut [u8]) -> Result<(), Error> {
29            let stream = NEXT_STREAM.fetch_add(1, Ordering::Relaxed);
30            let mut seed = [0u8; 32];
31            seed[..8].copy_from_slice(&stream.to_le_bytes());
32            let mut rng = ChaCha20Rng::from_seed(seed);
33            try_fill_bytes_zeroing_on_error(&mut rng, destination)
34        }
35    }
36
37    impl CryptoRng for TestRng {}
38}
39
40pub mod kem;
41pub mod sign;