mod ccs_from_ibe;
mod dual_regev;
mod dual_regev_discrete_gauss;
mod k_pke;
mod lpr;
mod regev;
mod regev_discrete_gauss;
mod ring_lpr;
pub use ccs_from_ibe::CCSfromIBE;
pub use dual_regev::DualRegev;
pub use dual_regev_discrete_gauss::DualRegevWithDiscreteGaussianRegularity;
pub use k_pke::KPKE;
pub use lpr::LPR;
use qfall_math::integer::Z;
pub use regev::Regev;
pub use regev_discrete_gauss::RegevWithDiscreteGaussianRegularity;
pub use ring_lpr::RingLPR;
pub trait PKEncryptionScheme {
type PublicKey;
type SecretKey;
type Cipher;
fn key_gen(&self) -> (Self::PublicKey, Self::SecretKey);
fn enc(&self, pk: &Self::PublicKey, message: impl Into<Z>) -> Self::Cipher;
fn dec(&self, sk: &Self::SecretKey, cipher: &Self::Cipher) -> Z;
}
pub trait PKEncryptionSchemeMut {
type PublicKey;
type SecretKey;
type Cipher;
fn key_gen(&mut self) -> (Self::PublicKey, Self::SecretKey);
fn enc(&mut self, pk: &Self::PublicKey, message: impl Into<Z>) -> Self::Cipher;
fn dec(&mut self, sk: &Self::SecretKey, cipher: &Self::Cipher) -> Z;
}
pub trait GenericMultiBitEncryption: PKEncryptionScheme {
fn enc_multiple_bits(&self, pk: &Self::PublicKey, message: impl Into<Z>) -> Vec<Self::Cipher> {
let message: Z = message.into().abs();
let bits = message.to_bits();
let mut out = vec![];
for bit in bits {
if bit {
out.push(self.enc(pk, Z::ONE));
} else {
out.push(self.enc(pk, Z::ZERO));
}
}
out
}
fn dec_multiple_bits(&self, sk: &Self::SecretKey, cipher: &[Self::Cipher]) -> Z {
let mut bits = vec![];
for item in cipher {
if self.dec(sk, item) == Z::ZERO {
bits.push(false);
} else {
bits.push(true);
}
}
Z::from_bits(&bits)
}
}