dcrypt/
lib.rs

1//! # dcrypt
2//!
3//! A modular cryptographic library providing both traditional and post-quantum algorithms.
4//!
5//! ## Usage
6//!
7//! Add this to your `Cargo.toml`:
8//!
9//! ```toml
10//! [dependencies]
11//! dcrypt = "0.11.0-beta.1"
12//! ```
13//!
14//! ## Features
15//!
16//! - `traditional` (default): Traditional cryptographic algorithms
17//! - `post-quantum`: Post-quantum cryptographic algorithms  
18//! - `hybrid`: Hybrid constructions combining traditional and post-quantum
19//! - `full`: All features enabled
20//!
21//! ## Crate Structure
22//!
23//! This is a facade crate that re-exports functionality from several sub-crates:
24//!
25//! - [`dcrypt-algorithms`]: Core algorithms (AES, SHA, etc.)
26//! - [`dcrypt-symmetric`]: Symmetric encryption
27//! - [`dcrypt-kem`]: Key Encapsulation Mechanisms
28//! - [`dcrypt-sign`]: Digital signatures
29//! - [`dcrypt-pke`]: Public Key Encryption
30//! - [`dcrypt-hybrid`]: Hybrid constructions
31//!
32//! ## Example Usage
33//! 
34//! ```rust,no_run
35//! # #[cfg(feature = "sign")]
36//! # {
37//! // Using through the main crate (requires 'sign' feature)
38//! use dcrypt::api::Signature;
39//! use dcrypt::sign::dilithium::{DilithiumSigningKey, DilithiumVerifyingKey};
40//! # }
41//! 
42//! // Or using the prelude (always available)
43//! use dcrypt::prelude::*;
44//! ```
45
46#![cfg_attr(not(feature = "std"), no_std)]
47
48// Core re-exports (always available)
49pub use dcrypt_api as api;
50pub use dcrypt_common as common;
51pub use dcrypt_internal as internal;
52pub use dcrypt_params as params;
53
54// Re-export commonly used items from api at the crate root for convenience
55pub use api::{Error, Result};
56
57// Feature-gated re-exports
58#[cfg(feature = "algorithms")]
59pub use dcrypt_algorithms as algorithms;
60
61#[cfg(feature = "symmetric")]
62pub use dcrypt_symmetric as symmetric;
63
64#[cfg(feature = "kem")]
65pub use dcrypt_kem as kem;
66
67#[cfg(feature = "sign")]
68pub use dcrypt_sign as sign;
69
70#[cfg(feature = "pke")]
71pub use dcrypt_pke as pke;
72
73#[cfg(feature = "hybrid")]
74pub use dcrypt_hybrid as hybrid;
75
76// Re-export commonly used traits at the crate root for easier access
77#[cfg(feature = "sign")]
78pub use api::Signature;
79
80// Also re-export the traits module for direct trait access
81pub use api::traits;
82
83/// Common imports for dcrypt users
84pub mod prelude {
85    // Re-export error types
86    pub use crate::api::{Error, Result};
87
88    // Re-export core traits from api
89    pub use crate::api::{
90        AuthenticatedCipher, BlockCipher, HashAlgorithm, Kem, KeyDerivationFunction, Serialize,
91        Signature, StreamCipher, SymmetricCipher,
92    };
93    
94    // Re-export all traits from api::traits if they exist
95    pub use crate::api::traits::*;
96
97    // Re-export security types
98    pub use crate::common::{EphemeralSecret, SecretBuffer, SecureZeroingType, ZeroizeGuard};
99
100    // Re-export memory safety utilities
101    pub use crate::common::{SecureCompare, SecureOperation, SecureOperationExt};
102
103    // Conditional re-exports based on features
104    #[cfg(any(feature = "std", feature = "alloc"))]
105    pub use crate::common::SecureOperationBuilder;
106
107    #[cfg(feature = "alloc")]
108    pub use crate::common::SecretVec;
109
110    #[cfg(any(feature = "std", feature = "alloc"))]
111    pub use crate::common::{CurveParams, ECPoint};
112    
113    // Note: Specific algorithm implementations should be imported directly from their modules
114    // For example:
115    // - use dcrypt::kem::ecdh::p256::{EcdhP256PublicKey, EcdhP256SecretKey};
116    // - use dcrypt::sign::dilithium::{DilithiumSigningKey, DilithiumVerifyingKey};
117    // - use dcrypt::pke::ecies::p256::{EciesP256PublicKey, EciesP256Ciphertext};
118}
119
120// Test that imports work correctly
121#[cfg(test)]
122mod tests {
123    #[test]
124    #[cfg(feature = "sign")]
125    fn test_sign_imports() {
126        // This should compile if the imports are working
127        use crate::api::Signature as SignatureTrait;
128        use crate::sign;
129        
130        // Type annotations to ensure we can access the module
131        let _: Option<&dyn SignatureTrait> = None;
132    }
133    
134    #[test] 
135    #[cfg(feature = "full")]
136    fn test_full_imports() {
137        // Test that all modules are accessible with full features
138        use crate::{algorithms, api, common, hybrid, internal, kem, params, pke, sign, symmetric};
139        
140        // Just checking that the modules exist
141        let _ = api::Error;
142    }
143}