1use serde::{Deserialize, Serialize};
4
5pub type AlgorithmId = u16;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
13#[repr(u16)]
14pub enum Algorithm {
15 Classical = 0x0050,
18 PasswordClassical = 0x0051,
20
21 Hybrid = 0x0100,
24
25 PostQuantum = 0x0200,
28 MultiAlgorithm = 0x0201,
30 MlKem1024 = 0x0202,
32 MultiKem = 0x0203,
34 MultiKemTriple = 0x0204,
36 QuadLayer = 0x0205,
38 LatticeCodeHybrid = 0x0206,
40 Pq3Stack = 0x0207,
42
43 MaxSecureLightweight = 0x0300,
46 MaxSecurePurePq = 0x0301,
48 MaxSecureHybrid = 0x0302,
50 MaxSecureStateless = 0x0303,
52 MaxSecureCryptoAgile = 0x0304,
54 MaxSecurePqcZk = 0x0305,
56 MaxSecureHybridTransition = 0x0306,
58
59 FnDsa512Compact = 0x0400,
62 FnDsa1024Security = 0x0401,
64 FnDsaFpHardened = 0x0402,
66 FnDsaDualSignature = 0x0403,
68 FnDsaTransition = 0x0404,
70 FnDsaZk = 0x0405,
72 FnDsaZkStack = 0x0406,
74 FnDsaTransitionStack = 0x0407,
76
77 QuantumLatticeFusion = 0x0500,
80 PostZkHomomorphic = 0x0501,
82 QuantumResistantConsensus = 0x0502,
84 EntropyOrchestrated = 0x0503,
86 LatticeCodeHybridFn = 0x0504,
88 AiSynthesizedCryptoAgile = 0x0505,
90 Experimental = 0x0506,
92
93 Hqc128 = 0x0600,
96 Hqc192 = 0x0601,
98 Hqc256 = 0x0602,
100
101 MlKem512 = 0x0700,
104 MlKem768 = 0x0701,
106
107 MlDsa44 = 0x0800,
110 MlDsa65 = 0x0801,
112 MlDsa87 = 0x0802,
114
115 SlhDsaSha2_128s = 0x0900,
118 SlhDsaSha2_128f = 0x0901,
120 SlhDsaSha2_192s = 0x0902,
122 SlhDsaSha2_192f = 0x0903,
124 SlhDsaSha2_256s = 0x0904,
126 SlhDsaSha2_256f = 0x0905,
128}
129
130impl Algorithm {
131 #[must_use]
142 pub fn from_id(id: u16) -> Option<Self> {
143 match id {
144 0x0050 => Some(Self::Classical),
145 0x0051 => Some(Self::PasswordClassical),
146 0x0100 => Some(Self::Hybrid),
147 0x0200 => Some(Self::PostQuantum),
148 0x0201 => Some(Self::MultiAlgorithm),
149 0x0202 => Some(Self::MlKem1024),
150 0x0203 => Some(Self::MultiKem),
151 0x0204 => Some(Self::MultiKemTriple),
152 0x0205 => Some(Self::QuadLayer),
153 0x0206 => Some(Self::LatticeCodeHybrid),
154 0x0207 => Some(Self::Pq3Stack),
155 0x0300 => Some(Self::MaxSecureLightweight),
156 0x0301 => Some(Self::MaxSecurePurePq),
157 0x0302 => Some(Self::MaxSecureHybrid),
158 0x0303 => Some(Self::MaxSecureStateless),
159 0x0304 => Some(Self::MaxSecureCryptoAgile),
160 0x0305 => Some(Self::MaxSecurePqcZk),
161 0x0306 => Some(Self::MaxSecureHybridTransition),
162 0x0400 => Some(Self::FnDsa512Compact),
163 0x0401 => Some(Self::FnDsa1024Security),
164 0x0402 => Some(Self::FnDsaFpHardened),
165 0x0403 => Some(Self::FnDsaDualSignature),
166 0x0404 => Some(Self::FnDsaTransition),
167 0x0405 => Some(Self::FnDsaZk),
168 0x0406 => Some(Self::FnDsaZkStack),
169 0x0407 => Some(Self::FnDsaTransitionStack),
170 0x0500 => Some(Self::QuantumLatticeFusion),
171 0x0501 => Some(Self::PostZkHomomorphic),
172 0x0502 => Some(Self::QuantumResistantConsensus),
173 0x0503 => Some(Self::EntropyOrchestrated),
174 0x0504 => Some(Self::LatticeCodeHybridFn),
175 0x0505 => Some(Self::AiSynthesizedCryptoAgile),
176 0x0506 => Some(Self::Experimental),
177 0x0600 => Some(Self::Hqc128),
178 0x0601 => Some(Self::Hqc192),
179 0x0602 => Some(Self::Hqc256),
180 0x0700 => Some(Self::MlKem512),
181 0x0701 => Some(Self::MlKem768),
182 0x0800 => Some(Self::MlDsa44),
183 0x0801 => Some(Self::MlDsa65),
184 0x0802 => Some(Self::MlDsa87),
185 0x0900 => Some(Self::SlhDsaSha2_128s),
186 0x0901 => Some(Self::SlhDsaSha2_128f),
187 0x0902 => Some(Self::SlhDsaSha2_192s),
188 0x0903 => Some(Self::SlhDsaSha2_192f),
189 0x0904 => Some(Self::SlhDsaSha2_256s),
190 0x0905 => Some(Self::SlhDsaSha2_256f),
191 _ => None,
192 }
193 }
194
195 #[must_use]
205 pub const fn as_id(self) -> u16 {
206 self as u16
207 }
208
209 #[must_use]
219 pub const fn name(self) -> &'static str {
220 match self {
221 Self::Classical => "Classical",
222 Self::PasswordClassical => "Password Classical",
223 Self::Hybrid => "Hybrid",
224 Self::PostQuantum => "Post-Quantum",
225 Self::MultiAlgorithm => "Multi-Algorithm",
226 Self::MlKem1024 => "ML-KEM-1024",
227 Self::MultiKem => "Multi-KEM Dual Layer",
228 Self::MultiKemTriple => "Multi-KEM Triple Layer",
229 Self::QuadLayer => "Quad-Layer",
230 Self::LatticeCodeHybrid => "Lattice-Code Hybrid",
231 Self::Pq3Stack => "PQ3-Stack",
232 Self::MaxSecureLightweight => "Max Secure: PQ Lightweight",
233 Self::MaxSecurePurePq => "Max Secure: Pure PQ",
234 Self::MaxSecureHybrid => "Max Secure: Hybrid",
235 Self::MaxSecureStateless => "Max Secure: Stateless",
236 Self::MaxSecureCryptoAgile => "Max Secure: Crypto-Agile",
237 Self::MaxSecurePqcZk => "Max Secure: PQC + ZK",
238 Self::FnDsa512Compact => "FN-DSA 512: Compact",
239 Self::FnDsa1024Security => "FN-DSA 1024: High-Security",
240 Self::FnDsaFpHardened => "FN-DSA: Floating-Point Hardened",
241 Self::FnDsaDualSignature => "FN-DSA: Dual Signature",
242 Self::FnDsaTransition => "FN-DSA: Transition Stack",
243 Self::FnDsaZk => "FN-DSA + ZK Stack",
244 Self::FnDsaZkStack => "FN-DSA + ZK Stack Enhanced",
245 Self::FnDsaTransitionStack => "FN-DSA: Transition Stack Enhanced",
246 Self::MaxSecureHybridTransition => "Max Secure: Hybrid Transition",
247 Self::QuantumLatticeFusion => "Quantum-Inspired Lattice Fusion",
248 Self::PostZkHomomorphic => "Post-ZK Homomorphic",
249 Self::QuantumResistantConsensus => "Quantum-Resistant Consensus",
250 Self::EntropyOrchestrated => "Entropy-Orchestrated",
251 Self::LatticeCodeHybridFn => "Lattice-Code Hybrid FN",
252 Self::AiSynthesizedCryptoAgile => "AI-Synthesized Crypto-Agile",
253 Self::Experimental => "Experimental Engine",
254 Self::Hqc128 => "HQC-128",
255 Self::Hqc192 => "HQC-192",
256 Self::Hqc256 => "HQC-256",
257 Self::MlKem512 => "ML-KEM-512",
258 Self::MlKem768 => "ML-KEM-768",
259 Self::MlDsa44 => "ML-DSA-44",
260 Self::MlDsa65 => "ML-DSA-65",
261 Self::MlDsa87 => "ML-DSA-87",
262 Self::SlhDsaSha2_128s => "SLH-DSA-SHA2-128s",
263 Self::SlhDsaSha2_128f => "SLH-DSA-SHA2-128f",
264 Self::SlhDsaSha2_192s => "SLH-DSA-SHA2-192s",
265 Self::SlhDsaSha2_192f => "SLH-DSA-SHA2-192f",
266 Self::SlhDsaSha2_256s => "SLH-DSA-SHA2-256s",
267 Self::SlhDsaSha2_256f => "SLH-DSA-SHA2-256f",
268 }
269 }
270
271 #[must_use]
276 pub const fn is_experimental(self) -> bool {
277 matches!(
278 self,
279 Self::QuantumLatticeFusion
280 | Self::PostZkHomomorphic
281 | Self::QuantumResistantConsensus
282 | Self::EntropyOrchestrated
283 | Self::LatticeCodeHybridFn
284 | Self::AiSynthesizedCryptoAgile
285 | Self::Experimental
286 )
287 }
288
289 #[must_use]
293 pub fn all() -> Vec<Self> {
294 vec![
295 Self::Classical,
296 Self::PasswordClassical,
297 Self::Hybrid,
298 Self::PostQuantum,
299 Self::MultiAlgorithm,
300 Self::MlKem1024,
301 Self::MultiKem,
302 Self::MultiKemTriple,
303 Self::QuadLayer,
304 Self::LatticeCodeHybrid,
305 Self::Pq3Stack,
306 Self::MaxSecureLightweight,
307 Self::MaxSecurePurePq,
308 Self::MaxSecureHybrid,
309 Self::MaxSecureStateless,
310 Self::MaxSecureCryptoAgile,
311 Self::MaxSecurePqcZk,
312 Self::MaxSecureHybridTransition,
313 Self::FnDsa512Compact,
314 Self::FnDsa1024Security,
315 Self::FnDsaFpHardened,
316 Self::FnDsaDualSignature,
317 Self::FnDsaTransition,
318 Self::FnDsaZk,
319 Self::FnDsaZkStack,
320 Self::FnDsaTransitionStack,
321 Self::QuantumLatticeFusion,
322 Self::PostZkHomomorphic,
323 Self::QuantumResistantConsensus,
324 Self::EntropyOrchestrated,
325 Self::LatticeCodeHybridFn,
326 Self::AiSynthesizedCryptoAgile,
327 Self::Experimental,
328 Self::Hqc128,
329 Self::Hqc192,
330 Self::Hqc256,
331 Self::MlKem512,
332 Self::MlKem768,
333 Self::MlDsa44,
334 Self::MlDsa65,
335 Self::MlDsa87,
336 Self::SlhDsaSha2_128s,
337 Self::SlhDsaSha2_128f,
338 Self::SlhDsaSha2_192s,
339 Self::SlhDsaSha2_192f,
340 Self::SlhDsaSha2_256s,
341 Self::SlhDsaSha2_256f,
342 ]
343 }
344}
345
346#[cfg(test)]
347mod tests {
348 use super::*;
349
350 #[test]
351 fn test_algorithm_roundtrip() {
352 for algo in Algorithm::all() {
353 let id = algo.as_id();
354 let recovered = Algorithm::from_id(id).unwrap();
355 assert_eq!(algo, recovered);
356 }
357 }
358
359 #[test]
360 fn test_invalid_algorithm_id() {
361 assert!(Algorithm::from_id(0xFFFF).is_none());
362 }
363
364 #[test]
365 fn test_experimental_detection() {
366 assert!(Algorithm::QuantumLatticeFusion.is_experimental());
367 assert!(!Algorithm::Hybrid.is_experimental());
368 }
369}