1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
19#[non_exhaustive]
20pub enum Algorithm {
21 Rsa,
23 ElGamal,
25 Dsa,
27 Ecdh,
29 Ecdsa,
31 Eddsa,
33 Sm2,
35}
36
37impl Algorithm {
38 pub fn as_str(self) -> &'static str {
39 match self {
40 Algorithm::Rsa => "RSA",
41 Algorithm::ElGamal => "ELGAMAL",
42 Algorithm::Dsa => "DSA",
43 Algorithm::Ecdh => "ECDH",
44 Algorithm::Ecdsa => "ECDSA",
45 Algorithm::Eddsa => "EDDSA",
46 Algorithm::Sm2 => "SM2",
47 }
48 }
49
50 pub fn is_signature(self) -> bool {
54 matches!(
55 self,
56 Algorithm::Rsa | Algorithm::Dsa | Algorithm::Ecdsa | Algorithm::Eddsa | Algorithm::Sm2
57 )
58 }
59
60 pub fn is_encryption(self) -> bool {
64 matches!(
65 self,
66 Algorithm::Rsa | Algorithm::Ecdh | Algorithm::ElGamal | Algorithm::Sm2
67 )
68 }
69}
70
71#[cfg(feature = "pqc")]
77#[derive(Clone, Copy, Debug, PartialEq, Eq)]
78pub enum PqcAlgorithm {
79 MlKem768X25519,
81 MlKem1024X448,
82 MlKem768P384,
83 MlKem1024P521,
84 MlKem768Bp384,
85 MlKem1024Bp512,
86 MlDsa65Ed25519,
88 MlDsa87Ed448,
89 MlDsa65P384,
90 MlDsa87P521,
91 MlDsa65Bp384,
92 MlDsa87Bp512,
93 SlhDsaShake128f,
95 SlhDsaShake128s,
96 SlhDsaShake256s,
97}
98
99#[cfg(feature = "pqc")]
100impl PqcAlgorithm {
101 pub fn as_str(self) -> &'static str {
102 match self {
103 PqcAlgorithm::MlKem768X25519 => "ML-KEM-768+X25519",
104 PqcAlgorithm::MlKem1024X448 => "ML-KEM-1024+X448",
105 PqcAlgorithm::MlKem768P384 => "ML-KEM-768+ECDH-P384",
106 PqcAlgorithm::MlKem1024P521 => "ML-KEM-1024+ECDH-P521",
107 PqcAlgorithm::MlKem768Bp384 => "ML-KEM-768+ECDH-BP384",
108 PqcAlgorithm::MlKem1024Bp512 => "ML-KEM-1024+ECDH-BP512",
109 PqcAlgorithm::MlDsa65Ed25519 => "ML-DSA-65+ED25519",
110 PqcAlgorithm::MlDsa87Ed448 => "ML-DSA-87+ED448",
111 PqcAlgorithm::MlDsa65P384 => "ML-DSA-65+ECDSA-P384",
112 PqcAlgorithm::MlDsa87P521 => "ML-DSA-87+ECDSA-P521",
113 PqcAlgorithm::MlDsa65Bp384 => "ML-DSA-65+ECDSA-BP384",
114 PqcAlgorithm::MlDsa87Bp512 => "ML-DSA-87+ECDSA-BP512",
115 PqcAlgorithm::SlhDsaShake128f => "SLH-DSA-SHAKE-128f",
116 PqcAlgorithm::SlhDsaShake128s => "SLH-DSA-SHAKE-128s",
117 PqcAlgorithm::SlhDsaShake256s => "SLH-DSA-SHAKE-256s",
118 }
119 }
120}
121
122#[cfg(feature = "pqc")]
127pub fn librnp_supports_pqc() -> bool {
128 crate::security::supports_feature(
129 crate::security::FeatureType::PublicKeyAlgorithm,
130 "ML-KEM-768+X25519",
131 )
132 .unwrap_or(false)
133}
134
135#[derive(Clone, Copy, Debug, PartialEq, Eq)]
142#[non_exhaustive]
143pub enum Curve {
144 P256,
146 P384,
148 P521,
150 Ed25519,
152 Curve25519,
154 Bp256,
156 Bp384,
158 Bp512,
160 Secp256k1,
162 Sm2P256,
164}
165
166impl Curve {
167 pub fn as_str(self) -> &'static str {
168 match self {
169 Curve::P256 => "NIST P-256",
170 Curve::P384 => "NIST P-384",
171 Curve::P521 => "NIST P-521",
172 Curve::Ed25519 => "Ed25519",
173 Curve::Curve25519 => "Curve25519",
174 Curve::Bp256 => "brainpoolP256r1",
175 Curve::Bp384 => "brainpoolP384r1",
176 Curve::Bp512 => "brainpoolP512r1",
177 Curve::Secp256k1 => "secp256k1",
178 Curve::Sm2P256 => "SM2 P-256",
179 }
180 }
181}
182
183#[derive(Clone, Copy, Debug, PartialEq, Eq)]
190#[non_exhaustive]
191pub enum Hash {
192 Sha1,
193 Sha224,
194 Sha256,
195 Sha384,
196 Sha512,
197 Sha3_256,
198 Sha3_512,
199 Md5,
200 Ripemd160,
201 Sm3,
202}
203
204impl Hash {
205 pub fn as_str(self) -> &'static str {
206 match self {
207 Hash::Sha1 => "SHA1",
208 Hash::Sha224 => "SHA224",
209 Hash::Sha256 => "SHA256",
210 Hash::Sha384 => "SHA384",
211 Hash::Sha512 => "SHA512",
212 Hash::Sha3_256 => "SHA3-256",
213 Hash::Sha3_512 => "SHA3-512",
214 Hash::Md5 => "MD5",
215 Hash::Ripemd160 => "RIPEMD160",
216 Hash::Sm3 => "SM3",
217 }
218 }
219
220 pub fn digest_size(self) -> usize {
223 match self {
224 Hash::Sha1 | Hash::Ripemd160 => 20,
225 Hash::Sha224 => 28,
226 Hash::Sha256 | Hash::Sha3_256 | Hash::Sm3 => 32,
227 Hash::Sha384 => 48,
228 Hash::Sha512 | Hash::Sha3_512 => 64,
229 Hash::Md5 => 16,
230 }
231 }
232}
233
234#[derive(Clone, Copy, Debug, PartialEq, Eq)]
240#[non_exhaustive]
241pub enum Cipher {
242 Idea,
243 Tripledes,
244 Cast5,
245 Blowfish,
246 Aes128,
247 Aes192,
248 Aes256,
249 Twofish,
250 Camellia128,
251 Camellia192,
252 Camellia256,
253 Sm4,
254}
255
256impl Cipher {
257 pub fn as_str(self) -> &'static str {
258 match self {
259 Cipher::Idea => "IDEA",
260 Cipher::Tripledes => "TRIPLEDES",
261 Cipher::Cast5 => "CAST5",
262 Cipher::Blowfish => "BLOWFISH",
263 Cipher::Aes128 => "AES128",
264 Cipher::Aes192 => "AES192",
265 Cipher::Aes256 => "AES256",
266 Cipher::Twofish => "TWOFISH",
267 Cipher::Camellia128 => "CAMELLIA128",
268 Cipher::Camellia192 => "CAMELLIA192",
269 Cipher::Camellia256 => "CAMELLIA256",
270 Cipher::Sm4 => "SM4",
271 }
272 }
273
274 pub fn key_size(self) -> usize {
276 match self {
277 Cipher::Idea | Cipher::Cast5 | Cipher::Blowfish => 16,
278 Cipher::Tripledes => 24,
279 Cipher::Aes128 | Cipher::Camellia128 => 16,
280 Cipher::Aes192 | Cipher::Camellia192 => 24,
281 Cipher::Aes256 | Cipher::Camellia256 | Cipher::Twofish | Cipher::Sm4 => 32,
282 }
283 }
284
285 pub fn block_size(self) -> usize {
287 match self {
288 Cipher::Blowfish | Cipher::Cast5 | Cipher::Tripledes | Cipher::Idea => 8,
290 Cipher::Aes128
292 | Cipher::Aes192
293 | Cipher::Aes256
294 | Cipher::Camellia128
295 | Cipher::Camellia192
296 | Cipher::Camellia256
297 | Cipher::Twofish
298 | Cipher::Sm4 => 16,
299 }
300 }
301}
302
303#[derive(Clone, Copy, Debug, PartialEq, Eq)]
309#[non_exhaustive]
310pub enum Compression {
311 Zip,
312 Zlib,
313 Bzip2,
314}
315
316impl Compression {
317 pub fn as_str(self) -> &'static str {
318 match self {
319 Compression::Zip => "ZIP",
320 Compression::Zlib => "ZLIB",
321 Compression::Bzip2 => "BZIP2",
322 }
323 }
324}
325
326#[derive(Clone, Copy, Debug, PartialEq, Eq)]
332#[non_exhaustive]
333pub enum KeyUsage {
334 Certify,
335 Sign,
336 EncryptComms,
337 EncryptStorage,
338}
339
340impl KeyUsage {
341 pub fn as_str(self) -> &'static str {
342 match self {
343 KeyUsage::Certify => "certify",
344 KeyUsage::Sign => "sign",
345 KeyUsage::EncryptComms => "encrypt",
346 KeyUsage::EncryptStorage => "encrypt",
347 }
348 }
349}