Skip to main content

saorsa_pqc/api/
mod.rs

1//! Comprehensive API for Post-Quantum Cryptography
2//!
3//! This module provides a clean, simple interface to all FIPS-certified
4//! post-quantum algorithms without requiring users to manage RNG or other
5//! implementation details.
6
7pub mod aead;
8pub mod errors;
9pub mod hash;
10pub mod hmac;
11pub mod hpke;
12pub mod kdf;
13pub mod kem;
14pub mod sig; // Renamed from dsa for consistency
15pub mod slh;
16pub mod symmetric;
17pub mod traits;
18
19pub use errors::{PqcError, PqcResult};
20pub use kdf::{helpers, HkdfSha3_256, HkdfSha3_512, KdfAlgorithm};
21pub use kem::{
22    ml_kem_1024, ml_kem_512, ml_kem_768, MlKem, MlKemCiphertext, MlKemPublicKey, MlKemSecretKey,
23    MlKemSharedSecret, MlKemVariant,
24};
25pub use sig::{
26    ml_dsa_44, ml_dsa_65, ml_dsa_87, MlDsa, MlDsaPublicKey, MlDsaSecretKey, MlDsaSignature,
27    MlDsaVariant,
28};
29pub use slh::{
30    slh_dsa_sha2_128f, slh_dsa_sha2_128s, slh_dsa_sha2_192s, slh_dsa_sha2_256s, SlhDsa,
31    SlhDsaPublicKey, SlhDsaSecretKey, SlhDsaSignature, SlhDsaVariant,
32};
33pub use symmetric::{ChaCha20Poly1305, SecureKey};
34
35/// Initialize the cryptographic RNG system
36/// This should be called once at application startup
37///
38/// # Errors
39/// Returns an error if the system RNG cannot be accessed.
40pub fn init() -> PqcResult<()> {
41    // Verify RNG is available
42    use rand_core::{OsRng, RngCore};
43
44    let mut test_bytes = [0u8; 32];
45    OsRng.fill_bytes(&mut test_bytes);
46
47    Ok(())
48}
49
50/// Get library version and capabilities
51#[must_use]
52pub const fn version() -> &'static str {
53    env!("CARGO_PKG_VERSION")
54}
55
56/// Get supported algorithms
57#[must_use]
58pub fn supported_algorithms() -> SupportedAlgorithms {
59    SupportedAlgorithms {
60        ml_kem: vec![
61            MlKemVariant::MlKem512,
62            MlKemVariant::MlKem768,
63            MlKemVariant::MlKem1024,
64        ],
65        ml_dsa: vec![
66            MlDsaVariant::MlDsa44,
67            MlDsaVariant::MlDsa65,
68            MlDsaVariant::MlDsa87,
69        ],
70        slh_dsa: vec![
71            SlhDsaVariant::Sha2_128s,
72            SlhDsaVariant::Sha2_128f,
73            SlhDsaVariant::Sha2_192s,
74            SlhDsaVariant::Sha2_192f,
75            SlhDsaVariant::Sha2_256s,
76            SlhDsaVariant::Sha2_256f,
77            SlhDsaVariant::Shake128s,
78            SlhDsaVariant::Shake128f,
79            SlhDsaVariant::Shake192s,
80            SlhDsaVariant::Shake192f,
81            SlhDsaVariant::Shake256s,
82            SlhDsaVariant::Shake256f,
83        ],
84        symmetric: vec!["ChaCha20-Poly1305 (256-bit, quantum-secure)".into()],
85    }
86}
87
88/// Information about supported algorithm variants
89#[derive(Debug, Clone)]
90pub struct SupportedAlgorithms {
91    /// Supported ML-KEM variants
92    pub ml_kem: Vec<MlKemVariant>,
93    /// Supported ML-DSA variants
94    pub ml_dsa: Vec<MlDsaVariant>,
95    /// Supported SLH-DSA variants
96    pub slh_dsa: Vec<SlhDsaVariant>,
97    /// Supported symmetric encryption algorithms
98    pub symmetric: Vec<String>,
99}
100
101#[cfg(test)]
102#[allow(clippy::unwrap_used, clippy::expect_used)]
103mod tests {
104    use super::*;
105
106    #[test]
107    fn test_init() {
108        assert!(init().is_ok());
109    }
110
111    #[test]
112    fn test_version() {
113        assert!(!version().is_empty());
114    }
115
116    #[test]
117    #[allow(clippy::indexing_slicing)]
118    fn test_supported_algorithms() {
119        let algos = supported_algorithms();
120        assert_eq!(algos.ml_kem.len(), 3);
121        assert_eq!(algos.ml_dsa.len(), 3);
122        assert_eq!(algos.slh_dsa.len(), 12);
123        assert_eq!(algos.symmetric.len(), 1);
124        assert!(algos.symmetric[0].contains("ChaCha20-Poly1305"));
125    }
126}