1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//! Convenience API for cryptographic operations
//!
//! This module provides a unified, high-level API for encryption, decryption,
//! signing, and verification with automatic algorithm selection.
//!
//! ## Security: `_unverified` variants
//!
//! Most operations in this module come in two forms:
//!
//! 1. A **Zero-Trust-aware** form that takes `SecurityMode` (or an equivalent
//! parameter) and performs session validation before executing the
//! cryptographic operation — e.g.
//! `encrypt_aes_gcm(data, key, SecurityMode::Verified(&session))`.
//!
//! 2. An **`_unverified` shortcut** that skips session validation and executes
//! the operation directly — e.g. `encrypt_aes_gcm_unverified(data, key)`.
//! These wrappers exist for contexts where Zero Trust verification is not
//! applicable (e.g. local-only encryption, internal dispatch layers, KAT
//! reproduction) and for direct invocation from tests.
//!
//! ### What `_unverified` does NOT mean
//!
//! Crucially, `_unverified` refers ONLY to the absence of a `VerifiedSession`
//! audit chain. It does NOT mean any of:
//!
//! - **Skips cryptographic input validation.** Key length, nonce size,
//! AEAD tag length, signature shape, etc., are all still validated.
//! - **Skips constant-time guarantees.** Secret comparisons in `_unverified`
//! helpers still go through `subtle::ConstantTimeEq`.
//! - **Skips weak-key rejection.** `AeadError::WeakKey` still fires on the
//! all-zero key whether you call `encrypt_aes_gcm` or
//! `encrypt_aes_gcm_unverified`.
//! - **Skips Pattern 6 error opacity.** Adversary-reachable failures still
//! collapse to opaque variants in both forms.
//!
//! Treat the suffix as the moral equivalent of "no audit trail attached."
//!
//! **Production guidance:** prefer the `SecurityMode::Verified` form. Reach for
//! `_unverified` only when you have an explicit reason not to involve a
//! `VerifiedSession` — and make that reason reviewable at the call site.
//! The verified form also requires a `VerifiedSession` reference, which is
//! type-enforced and cannot be stumbled into; the `_unverified` form carries
//! the word "unverified" in its name so that code review can catch accidental
//! use.
//!
//! ## Unified API
//!
//! All operations use `CryptoConfig` for configuration:
//!
//! ```no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use latticearc::unified_api::{
//! encrypt, decrypt, generate_signing_keypair, sign_with_key, verify,
//! CryptoConfig, UseCase, EncryptKey, DecryptKey,
//! };
//! # let message = b"example message";
//!
//! // Hybrid encryption (recommended - ML-KEM-768 + X25519 + AES-256-GCM)
//! let (pk, sk) = latticearc::generate_hybrid_keypair()?;
//! let encrypted = encrypt(b"data", EncryptKey::Hybrid(&pk),
//! CryptoConfig::new().use_case(UseCase::FileStorage))?;
//! let plaintext = decrypt(&encrypted, DecryptKey::Hybrid(&sk), CryptoConfig::new())?;
//!
//! // Symmetric encryption (AES-256-GCM). Generate a fresh key — `[0u8; 32]`
//! // is rejected by the AEAD constructor as a weak key.
//! let key = latticearc::primitives::rand::random_bytes(32);
//! let encrypted = encrypt(b"data", EncryptKey::Symmetric(&key),
//! CryptoConfig::new().force_scheme(latticearc::CryptoScheme::Symmetric))?;
//! let plaintext = decrypt(&encrypted, DecryptKey::Symmetric(&key), CryptoConfig::new())?;
//!
//! // Sign (generate keypair once, sign with persistent key)
//! let (pk, sk, scheme) = generate_signing_keypair(CryptoConfig::new())?.into_parts();
//! let signed = sign_with_key(message, sk.as_ref(), pk.as_ref(), CryptoConfig::new())?;
//!
//! // Verify
//! let is_valid = verify(&signed, CryptoConfig::new())?;
//! # Ok(())
//! # }
//! ```
//!
//! ## With Zero Trust Session
//!
//! ```no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use latticearc::unified_api::{encrypt, CryptoConfig, UseCase, VerifiedSession, EncryptKey};
//! # let pk_ed = [0u8; 32];
//! # let sk_ed = [0u8; 32];
//!
//! let session = VerifiedSession::establish(&pk_ed, &sk_ed)?;
//! let (pk, _sk) = latticearc::generate_hybrid_keypair()?;
//! let encrypted = encrypt(b"data", EncryptKey::Hybrid(&pk),
//! CryptoConfig::new()
//! .session(&session)
//! .use_case(UseCase::FileStorage))?;
//! # Ok(())
//! # }
//! ```
pub
pub
// ============================================================================
// Unified API
// ============================================================================
pub use ;
// ============================================================================
// Hybrid Key Generation (ML-KEM + X25519)
// ============================================================================
pub use ;
// ============================================================================
// Hybrid Signatures (ML-DSA-65 + Ed25519)
// ============================================================================
pub use ;
// ============================================================================
// Key Generation (no options needed - creates credentials)
// ============================================================================
pub use ;
// ============================================================================
// Hashing (stateless operations)
// ============================================================================
pub use ;
// ============================================================================
// Low-Level Primitives (for advanced use cases)
// ============================================================================
// Ed25519
pub use ;
// ECDSA-P384
pub use ;
// AES-GCM
pub use ;
pub use ;
// Post-Quantum KEM (ML-KEM)
pub use ;
// Post-Quantum Signatures (ML-DSA, SLH-DSA, FN-DSA)
pub use ;
// ============================================================================
// Unverified Variants (for low-level primitives)
// ============================================================================
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;