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