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
102impl Algorithm {
103 #[must_use]
114 pub fn from_id(id: u16) -> Option<Self> {
115 match id {
116 0x0050 => Some(Self::Classical),
117 0x0051 => Some(Self::PasswordClassical),
118 0x0100 => Some(Self::Hybrid),
119 0x0200 => Some(Self::PostQuantum),
120 0x0201 => Some(Self::MultiAlgorithm),
121 0x0202 => Some(Self::MlKem1024),
122 0x0203 => Some(Self::MultiKem),
123 0x0204 => Some(Self::MultiKemTriple),
124 0x0205 => Some(Self::QuadLayer),
125 0x0206 => Some(Self::LatticeCodeHybrid),
126 0x0207 => Some(Self::Pq3Stack),
127 0x0300 => Some(Self::MaxSecureLightweight),
128 0x0301 => Some(Self::MaxSecurePurePq),
129 0x0302 => Some(Self::MaxSecureHybrid),
130 0x0303 => Some(Self::MaxSecureStateless),
131 0x0304 => Some(Self::MaxSecureCryptoAgile),
132 0x0305 => Some(Self::MaxSecurePqcZk),
133 0x0306 => Some(Self::MaxSecureHybridTransition),
134 0x0400 => Some(Self::FnDsa512Compact),
135 0x0401 => Some(Self::FnDsa1024Security),
136 0x0402 => Some(Self::FnDsaFpHardened),
137 0x0403 => Some(Self::FnDsaDualSignature),
138 0x0404 => Some(Self::FnDsaTransition),
139 0x0405 => Some(Self::FnDsaZk),
140 0x0406 => Some(Self::FnDsaZkStack),
141 0x0407 => Some(Self::FnDsaTransitionStack),
142 0x0500 => Some(Self::QuantumLatticeFusion),
143 0x0501 => Some(Self::PostZkHomomorphic),
144 0x0502 => Some(Self::QuantumResistantConsensus),
145 0x0503 => Some(Self::EntropyOrchestrated),
146 0x0504 => Some(Self::LatticeCodeHybridFn),
147 0x0505 => Some(Self::AiSynthesizedCryptoAgile),
148 0x0506 => Some(Self::Experimental),
149 0x0600 => Some(Self::Hqc128),
150 0x0601 => Some(Self::Hqc192),
151 0x0602 => Some(Self::Hqc256),
152 _ => None,
153 }
154 }
155
156 #[must_use]
166 pub const fn as_id(self) -> u16 {
167 self as u16
168 }
169
170 #[must_use]
180 pub const fn name(self) -> &'static str {
181 match self {
182 Self::Classical => "Classical",
183 Self::PasswordClassical => "Password Classical",
184 Self::Hybrid => "Hybrid",
185 Self::PostQuantum => "Post-Quantum",
186 Self::MultiAlgorithm => "Multi-Algorithm",
187 Self::MlKem1024 => "ML-KEM-1024",
188 Self::MultiKem => "Multi-KEM Dual Layer",
189 Self::MultiKemTriple => "Multi-KEM Triple Layer",
190 Self::QuadLayer => "Quad-Layer",
191 Self::LatticeCodeHybrid => "Lattice-Code Hybrid",
192 Self::Pq3Stack => "PQ3-Stack",
193 Self::MaxSecureLightweight => "Max Secure: PQ Lightweight",
194 Self::MaxSecurePurePq => "Max Secure: Pure PQ",
195 Self::MaxSecureHybrid => "Max Secure: Hybrid",
196 Self::MaxSecureStateless => "Max Secure: Stateless",
197 Self::MaxSecureCryptoAgile => "Max Secure: Crypto-Agile",
198 Self::MaxSecurePqcZk => "Max Secure: PQC + ZK",
199 Self::FnDsa512Compact => "FN-DSA 512: Compact",
200 Self::FnDsa1024Security => "FN-DSA 1024: High-Security",
201 Self::FnDsaFpHardened => "FN-DSA: Floating-Point Hardened",
202 Self::FnDsaDualSignature => "FN-DSA: Dual Signature",
203 Self::FnDsaTransition => "FN-DSA: Transition Stack",
204 Self::FnDsaZk => "FN-DSA + ZK Stack",
205 Self::FnDsaZkStack => "FN-DSA + ZK Stack Enhanced",
206 Self::FnDsaTransitionStack => "FN-DSA: Transition Stack Enhanced",
207 Self::MaxSecureHybridTransition => "Max Secure: Hybrid Transition",
208 Self::QuantumLatticeFusion => "Quantum-Inspired Lattice Fusion",
209 Self::PostZkHomomorphic => "Post-ZK Homomorphic",
210 Self::QuantumResistantConsensus => "Quantum-Resistant Consensus",
211 Self::EntropyOrchestrated => "Entropy-Orchestrated",
212 Self::LatticeCodeHybridFn => "Lattice-Code Hybrid FN",
213 Self::AiSynthesizedCryptoAgile => "AI-Synthesized Crypto-Agile",
214 Self::Experimental => "Experimental Engine",
215 Self::Hqc128 => "HQC-128",
216 Self::Hqc192 => "HQC-192",
217 Self::Hqc256 => "HQC-256",
218 }
219 }
220
221 #[must_use]
226 pub const fn is_experimental(self) -> bool {
227 matches!(
228 self,
229 Self::QuantumLatticeFusion
230 | Self::PostZkHomomorphic
231 | Self::QuantumResistantConsensus
232 | Self::EntropyOrchestrated
233 | Self::LatticeCodeHybridFn
234 | Self::AiSynthesizedCryptoAgile
235 | Self::Experimental
236 )
237 }
238
239 #[must_use]
243 pub fn all() -> Vec<Self> {
244 vec![
245 Self::Classical,
246 Self::PasswordClassical,
247 Self::Hybrid,
248 Self::PostQuantum,
249 Self::MultiAlgorithm,
250 Self::MlKem1024,
251 Self::MultiKem,
252 Self::MultiKemTriple,
253 Self::QuadLayer,
254 Self::LatticeCodeHybrid,
255 Self::Pq3Stack,
256 Self::MaxSecureLightweight,
257 Self::MaxSecurePurePq,
258 Self::MaxSecureHybrid,
259 Self::MaxSecureStateless,
260 Self::MaxSecureCryptoAgile,
261 Self::MaxSecurePqcZk,
262 Self::MaxSecureHybridTransition,
263 Self::FnDsa512Compact,
264 Self::FnDsa1024Security,
265 Self::FnDsaFpHardened,
266 Self::FnDsaDualSignature,
267 Self::FnDsaTransition,
268 Self::FnDsaZk,
269 Self::FnDsaZkStack,
270 Self::FnDsaTransitionStack,
271 Self::QuantumLatticeFusion,
272 Self::PostZkHomomorphic,
273 Self::QuantumResistantConsensus,
274 Self::EntropyOrchestrated,
275 Self::LatticeCodeHybridFn,
276 Self::AiSynthesizedCryptoAgile,
277 Self::Experimental,
278 Self::Hqc128,
279 Self::Hqc192,
280 Self::Hqc256,
281 ]
282 }
283}
284
285#[cfg(test)]
286mod tests {
287 use super::*;
288
289 #[test]
290 fn test_algorithm_roundtrip() {
291 for algo in Algorithm::all() {
292 let id = algo.as_id();
293 let recovered = Algorithm::from_id(id).unwrap();
294 assert_eq!(algo, recovered);
295 }
296 }
297
298 #[test]
299 fn test_invalid_algorithm_id() {
300 assert!(Algorithm::from_id(0xFFFF).is_none());
301 }
302
303 #[test]
304 fn test_experimental_detection() {
305 assert!(Algorithm::QuantumLatticeFusion.is_experimental());
306 assert!(!Algorithm::Hybrid.is_experimental());
307 }
308}