pub mod kdf;
pub mod kyber;
pub mod cipher_aes_gcm_siv;
pub mod cipher_aes_ctr;
pub mod cipher_aes_xts;
use crate::{cryptography::*, error::CryptError};
pub use kyber::key_controler::*;
pub mod cipher_aes;
pub mod cipher_xchacha;
pub mod cipher_xchacha_poly;
pub enum KeyControlVariant {
Kyber1024(KeyControl<KeyControKyber1024>),
Kyber768(KeyControl<KeyControKyber768>),
Kyber512(KeyControl<KeyControKyber512>),
}
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>;
}