crypto_dispatch/algorithms/
x_wing.rs1use crate::AlgorithmError;
6use crypto_core::Algorithm;
7use zeroize::Zeroizing;
8
9pub struct XWing768Algo;
11
12pub struct XWing1024Algo;
14
15impl XWing768Algo {
16 pub const ALG: Algorithm = Algorithm::XWing768;
18
19 pub fn generate_keypair() -> Result<(Vec<u8>, Zeroizing<Vec<u8>>), AlgorithmError> {
21 crypto_x_wing::generate_x_wing_768_keypair().map_err(AlgorithmError::from)
22 }
23
24 pub fn encapsulate(public_key: &[u8]) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>), AlgorithmError> {
26 let (ciphertext, shared_secret) =
27 crypto_x_wing::x_wing_768_encapsulate(public_key).map_err(AlgorithmError::from)?;
28 Ok((shared_secret, ciphertext))
29 }
30
31 pub fn decapsulate(
33 ciphertext: &[u8],
34 secret_key: &[u8],
35 ) -> Result<Zeroizing<Vec<u8>>, AlgorithmError> {
36 crypto_x_wing::x_wing_768_decapsulate(ciphertext, secret_key).map_err(AlgorithmError::from)
37 }
38}
39
40impl XWing1024Algo {
41 pub const ALG: Algorithm = Algorithm::XWing1024;
43
44 pub fn generate_keypair() -> Result<(Vec<u8>, Zeroizing<Vec<u8>>), AlgorithmError> {
46 crypto_x_wing::generate_x_wing_1024_keypair().map_err(AlgorithmError::from)
47 }
48
49 pub fn encapsulate(public_key: &[u8]) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>), AlgorithmError> {
51 let (ciphertext, shared_secret) =
52 crypto_x_wing::x_wing_1024_encapsulate(public_key).map_err(AlgorithmError::from)?;
53 Ok((shared_secret, ciphertext))
54 }
55
56 pub fn decapsulate(
58 ciphertext: &[u8],
59 secret_key: &[u8],
60 ) -> Result<Zeroizing<Vec<u8>>, AlgorithmError> {
61 crypto_x_wing::x_wing_1024_decapsulate(ciphertext, secret_key).map_err(AlgorithmError::from)
62 }
63}