1use quantaegis_core::{Error, Result};
4
5#[repr(u16)]
7#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
8pub enum KemAlgorithm {
9 MlKem512 = 0x0101,
11 MlKem768 = 0x0102,
13 MlKem1024 = 0x0103,
15 XWing = 0x0201,
17}
18
19impl KemAlgorithm {
20 #[inline]
22 pub const fn wire_id(self) -> u16 {
23 self as u16
24 }
25
26 pub const fn from_wire_id(id: u16) -> Result<Self> {
28 match id {
29 0x0101 => Ok(Self::MlKem512),
30 0x0102 => Ok(Self::MlKem768),
31 0x0103 => Ok(Self::MlKem1024),
32 0x0201 => Ok(Self::XWing),
33 _ => Err(Error::InvalidCiphertext),
34 }
35 }
36
37 #[inline]
39 pub const fn name(self) -> &'static str {
40 match self {
41 Self::MlKem512 => "ML-KEM-512",
42 Self::MlKem768 => "ML-KEM-768",
43 Self::MlKem1024 => "ML-KEM-1024",
44 Self::XWing => "X-Wing",
45 }
46 }
47
48 #[inline]
50 pub const fn nist_category(self) -> u8 {
51 match self {
52 Self::MlKem512 => 1,
53 Self::MlKem768 | Self::XWing => 3,
54 Self::MlKem1024 => 5,
55 }
56 }
57
58 #[inline]
60 pub const fn is_hybrid(self) -> bool {
61 matches!(self, Self::XWing)
62 }
63
64 #[inline]
66 pub const fn oid(self) -> Option<&'static str> {
67 match self {
68 Self::MlKem512 => Some("2.16.840.1.101.3.4.4.1"),
69 Self::MlKem768 => Some("2.16.840.1.101.3.4.4.2"),
70 Self::MlKem1024 => Some("2.16.840.1.101.3.4.4.3"),
71 Self::XWing => None,
72 }
73 }
74}
75
76#[repr(u8)]
78#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
79pub enum AeadAlgorithm {
80 #[default]
82 Aes256Gcm = 0x01,
83 ChaCha20Poly1305 = 0x02,
85}
86
87impl AeadAlgorithm {
88 #[inline]
90 pub const fn wire_id(self) -> u8 {
91 self as u8
92 }
93
94 pub const fn from_wire_id(id: u8) -> Result<Self> {
96 match id {
97 0x01 => Ok(Self::Aes256Gcm),
98 0x02 => Ok(Self::ChaCha20Poly1305),
99 _ => Err(Error::InvalidCiphertext),
100 }
101 }
102
103 #[inline]
105 pub const fn name(self) -> &'static str {
106 match self {
107 Self::Aes256Gcm => "AES-256-GCM",
108 Self::ChaCha20Poly1305 => "ChaCha20-Poly1305",
109 }
110 }
111}
112
113#[repr(u16)]
115#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
116pub enum SignatureAlgorithm {
117 MlDsa44 = 0x0301,
119 MlDsa65 = 0x0302,
121 MlDsa87 = 0x0303,
123 SlhDsaShake128s = 0x0401,
125 SlhDsaShake128f = 0x0402,
127 SlhDsaShake192s = 0x0403,
129 SlhDsaShake192f = 0x0404,
131 SlhDsaShake256s = 0x0405,
133 SlhDsaShake256f = 0x0406,
135 MlDsa65Ed25519 = 0x0501,
137}
138
139impl SignatureAlgorithm {
140 #[inline]
142 pub const fn wire_id(self) -> u16 {
143 self as u16
144 }
145
146 pub const fn from_wire_id(id: u16) -> Result<Self> {
148 match id {
149 0x0301 => Ok(Self::MlDsa44),
150 0x0302 => Ok(Self::MlDsa65),
151 0x0303 => Ok(Self::MlDsa87),
152 0x0401 => Ok(Self::SlhDsaShake128s),
153 0x0402 => Ok(Self::SlhDsaShake128f),
154 0x0403 => Ok(Self::SlhDsaShake192s),
155 0x0404 => Ok(Self::SlhDsaShake192f),
156 0x0405 => Ok(Self::SlhDsaShake256s),
157 0x0406 => Ok(Self::SlhDsaShake256f),
158 0x0501 => Ok(Self::MlDsa65Ed25519),
159 _ => Err(Error::InvalidSignature),
160 }
161 }
162
163 #[inline]
165 pub const fn name(self) -> &'static str {
166 match self {
167 Self::MlDsa44 => "ML-DSA-44",
168 Self::MlDsa65 => "ML-DSA-65",
169 Self::MlDsa87 => "ML-DSA-87",
170 Self::SlhDsaShake128s => "SLH-DSA-SHAKE-128s",
171 Self::SlhDsaShake128f => "SLH-DSA-SHAKE-128f",
172 Self::SlhDsaShake192s => "SLH-DSA-SHAKE-192s",
173 Self::SlhDsaShake192f => "SLH-DSA-SHAKE-192f",
174 Self::SlhDsaShake256s => "SLH-DSA-SHAKE-256s",
175 Self::SlhDsaShake256f => "SLH-DSA-SHAKE-256f",
176 Self::MlDsa65Ed25519 => "MLDSA65-Ed25519-SHA512",
177 }
178 }
179
180 #[inline]
182 pub const fn nist_category(self) -> u8 {
183 match self {
184 Self::SlhDsaShake128s | Self::SlhDsaShake128f => 1,
185 Self::MlDsa44 => 2,
186 Self::MlDsa65
187 | Self::SlhDsaShake192s
188 | Self::SlhDsaShake192f
189 | Self::MlDsa65Ed25519 => 3,
190 Self::MlDsa87 | Self::SlhDsaShake256s | Self::SlhDsaShake256f => 5,
191 }
192 }
193
194 #[inline]
196 pub const fn is_hybrid(self) -> bool {
197 matches!(self, Self::MlDsa65Ed25519)
198 }
199
200 #[inline]
202 pub const fn oid(self) -> Option<&'static str> {
203 match self {
204 Self::MlDsa44 => Some("2.16.840.1.101.3.4.3.17"),
205 Self::MlDsa65 => Some("2.16.840.1.101.3.4.3.18"),
206 Self::MlDsa87 => Some("2.16.840.1.101.3.4.3.19"),
207 Self::SlhDsaShake128s => Some("2.16.840.1.101.3.4.3.26"),
208 Self::SlhDsaShake128f => Some("2.16.840.1.101.3.4.3.27"),
209 Self::SlhDsaShake192s => Some("2.16.840.1.101.3.4.3.28"),
210 Self::SlhDsaShake192f => Some("2.16.840.1.101.3.4.3.29"),
211 Self::SlhDsaShake256s => Some("2.16.840.1.101.3.4.3.30"),
212 Self::SlhDsaShake256f => Some("2.16.840.1.101.3.4.3.31"),
213 Self::MlDsa65Ed25519 => None,
214 }
215 }
216}