#[cfg(feature = "legacy-pqclean")]
pub mod kdf;
pub mod kyber;
#[cfg(feature = "cgv2-compat")]
pub mod hub;
#[cfg(feature = "legacy-aes")]
pub mod cipher_aes;
#[cfg(feature = "aes-ctr")]
pub mod cipher_aes_ctr;
#[cfg(any(feature = "aes-gcm-siv-cipher", feature = "legacy-pqclean"))]
pub mod cipher_aes_gcm_siv;
#[cfg(feature = "aes-xts")]
pub mod cipher_aes_xts;
pub mod cipher_xchacha;
pub mod cipher_xchacha_poly;
use crate::error::CryptError;
#[cfg(feature = "legacy-pqclean")]
pub use kyber::key_controler::*;
#[cfg(feature = "legacy-pqclean")]
use crate::cryptography::KeyEncapMechanism;
#[cfg(feature = "legacy-pqclean")]
pub enum KeyControlVariant {
Kyber1024(KeyControl<KeyControKyber1024>),
Kyber768(KeyControl<KeyControKyber768>),
Kyber512(KeyControl<KeyControKyber512>),
}
#[cfg(feature = "legacy-pqclean")]
impl KeyControlVariant {
pub fn new(keytype: KeyEncapMechanism) -> Self {
match keytype {
KeyEncapMechanism::Kyber1024 => {
Self::Kyber1024(KeyControl::<KeyControKyber1024>::new())
}
KeyEncapMechanism::Kyber768 => Self::Kyber768(KeyControl::<KeyControKyber768>::new()),
KeyEncapMechanism::Kyber512 => Self::Kyber512(KeyControl::<KeyControKyber512>::new()),
}
}
pub fn encap(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>), CryptError> {
match self {
KeyControlVariant::Kyber1024(k) => k.encap(public_key),
KeyControlVariant::Kyber768(k) => k.encap(public_key),
KeyControlVariant::Kyber512(k) => k.encap(public_key),
}
}
pub fn decap(&self, secret_key: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>, CryptError> {
match self {
KeyControlVariant::Kyber1024(k) => k.decap(secret_key, ciphertext),
KeyControlVariant::Kyber768(k) => k.decap(secret_key, ciphertext),
KeyControlVariant::Kyber512(k) => k.decap(secret_key, ciphertext),
}
}
}
pub trait CryptographicFunctions {
fn encrypt(&mut self, public_key: Vec<u8>) -> Result<(Vec<u8>, Vec<u8>), CryptError>;
fn decrypt(&mut self, secret_key: Vec<u8>, ciphertext: Vec<u8>) -> Result<Vec<u8>, CryptError>;
}