quantacore/lib.rs
1//! # QuantaCore SDK for Rust
2//!
3//! Rust bindings for the QUAC 100 Post-Quantum Cryptographic Accelerator.
4//!
5//! ## Features
6//!
7//! - **ML-KEM (Kyber)**: Post-quantum key encapsulation (512, 768, 1024)
8//! - **ML-DSA (Dilithium)**: Post-quantum digital signatures (44, 65, 87)
9//! - **QRNG**: Quantum random number generation
10//! - **Hardware Hashing**: SHA-2, SHA-3, SHAKE, HMAC, HKDF
11//! - **HSM Key Storage**: Secure key management
12//!
13//! ## Quick Start
14//!
15//! ```no_run
16//! use quantacore::{initialize, cleanup, open_first_device, KemAlgorithm};
17//!
18//! fn main() -> quantacore::Result<()> {
19//! // Initialize library
20//! initialize()?;
21//!
22//! // Open device
23//! let device = open_first_device()?;
24//!
25//! // Get KEM subsystem
26//! let kem = device.kem();
27//!
28//! // Generate ML-KEM-768 key pair
29//! let keypair = kem.generate_keypair(KemAlgorithm::MlKem768)?;
30//! println!("Public key: {} bytes", keypair.public_key().len());
31//!
32//! // Encapsulate
33//! let (ciphertext, shared_secret) = kem.encapsulate(
34//! keypair.public_key(),
35//! KemAlgorithm::MlKem768
36//! )?;
37//!
38//! // Decapsulate
39//! let decap_secret = kem.decapsulate(
40//! keypair.secret_key(),
41//! &ciphertext,
42//! KemAlgorithm::MlKem768
43//! )?;
44//!
45//! assert_eq!(shared_secret, decap_secret);
46//!
47//! // Cleanup
48//! drop(device);
49//! cleanup()?;
50//!
51//! Ok(())
52//! }
53//! ```
54//!
55//! ## Error Handling
56//!
57//! All fallible operations return `quantacore::Result<T>`, which is an alias
58//! for `std::result::Result<T, QuacError>`.
59//!
60//! ## Thread Safety
61//!
62//! The library is thread-safe. Multiple threads can use the same `Device`
63//! instance concurrently.
64
65#![cfg_attr(docsrs, feature(doc_cfg))]
66#![warn(missing_docs)]
67#![warn(rust_2018_idioms)]
68
69// Modules
70mod error;
71mod ffi;
72mod types;
73mod library;
74mod device;
75mod kem;
76mod sign;
77mod hash;
78mod random;
79mod keys;
80pub mod utils;
81
82// Re-exports
83pub use error::{QuacError, ErrorCode, Result};
84pub use types::{
85 KemAlgorithm,
86 SignAlgorithm,
87 HashAlgorithm,
88 KeyType,
89 KeyUsage,
90 InitFlags,
91};
92pub use library::{LibraryContext,
93 initialize,
94 initialize_with_flags,
95 cleanup,
96 is_initialized,
97 get_version,
98 get_build_info,
99 get_device_count,
100 enumerate_devices,
101 open_device,
102 open_first_device,
103};
104pub use device::{Device, DeviceInfo, DeviceStatus};
105pub use kem::{Kem, KeyPair, EncapsulationResult};
106pub use sign::{Sign, SignatureKeyPair};
107pub use hash::{Hash, HashContext};
108pub use random::{Random, EntropyStatus};
109pub use keys::{Keys, KeyInfo};
110
111/// Library version
112pub const VERSION: &str = env!("CARGO_PKG_VERSION");
113
114/// Crate prelude for convenient imports
115pub mod prelude {
116 //! Convenient imports for common use cases.
117 //!
118 //! ```
119 //! use quantacore::prelude::*;
120 //! ```
121
122 pub use crate::{
123 initialize,
124 cleanup,
125 open_first_device,
126 KemAlgorithm,
127 SignAlgorithm,
128 HashAlgorithm,
129 Result,
130 QuacError,
131 };
132}
133
134#[cfg(test)]
135mod tests {
136 use super::*;
137
138 #[test]
139 fn test_version() {
140 assert!(!VERSION.is_empty());
141 }
142}