use crate::AlgorithmError;
use crypto_core::Algorithm;
use zeroize::Zeroizing;
pub struct XWing768Algo;
pub struct XWing1024Algo;
impl XWing768Algo {
pub const ALG: Algorithm = Algorithm::XWing768;
pub fn generate_keypair() -> Result<(Vec<u8>, Zeroizing<Vec<u8>>), AlgorithmError> {
crypto_x_wing::generate_x_wing_768_keypair().map_err(AlgorithmError::from)
}
pub fn encapsulate(public_key: &[u8]) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>), AlgorithmError> {
let (ciphertext, shared_secret) =
crypto_x_wing::x_wing_768_encapsulate(public_key).map_err(AlgorithmError::from)?;
Ok((shared_secret, ciphertext))
}
pub fn decapsulate(
ciphertext: &[u8],
secret_key: &[u8],
) -> Result<Zeroizing<Vec<u8>>, AlgorithmError> {
crypto_x_wing::x_wing_768_decapsulate(ciphertext, secret_key).map_err(AlgorithmError::from)
}
}
impl XWing1024Algo {
pub const ALG: Algorithm = Algorithm::XWing1024;
pub fn generate_keypair() -> Result<(Vec<u8>, Zeroizing<Vec<u8>>), AlgorithmError> {
crypto_x_wing::generate_x_wing_1024_keypair().map_err(AlgorithmError::from)
}
pub fn encapsulate(public_key: &[u8]) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>), AlgorithmError> {
let (ciphertext, shared_secret) =
crypto_x_wing::x_wing_1024_encapsulate(public_key).map_err(AlgorithmError::from)?;
Ok((shared_secret, ciphertext))
}
pub fn decapsulate(
ciphertext: &[u8],
secret_key: &[u8],
) -> Result<Zeroizing<Vec<u8>>, AlgorithmError> {
crypto_x_wing::x_wing_1024_decapsulate(ciphertext, secret_key).map_err(AlgorithmError::from)
}
}