#[cfg(feature = "kv1")]
#[cfg_attr(docsrs, doc(cfg(feature = "kv1")))]
pub mod kiltz_vahlis_one;
#[cfg(feature = "cgwfo")]
#[cfg_attr(docsrs, doc(cfg(feature = "cgwfo")))]
pub mod cgw_fo;
#[cfg(feature = "cgwkv")]
#[cfg_attr(docsrs, doc(cfg(feature = "cgwkv")))]
pub mod cgw_kv;
#[cfg(feature = "mkem")]
#[cfg_attr(docsrs, doc(cfg(feature = "mkem")))]
pub mod mkem;
use crate::util::*;
use crate::{Compress, Derive};
use core::ops::BitXorAssign;
use pg_curve::Gt;
use rand::{CryptoRng, Rng};
pub const SS_BYTES: usize = 32;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SharedSecret(pub [u8; SS_BYTES]);
impl From<&Gt> for SharedSecret {
fn from(el: &Gt) -> Self {
SharedSecret(shake256::<SS_BYTES>(&el.to_compressed()))
}
}
impl BitXorAssign for SharedSecret {
fn bitxor_assign(&mut self, rhs: Self) {
for i in 0..SS_BYTES {
self.0[i] ^= rhs.0[i];
}
}
}
#[derive(Debug)]
pub struct Error;
pub trait IBKEM: Clone {
const IDENTIFIER: &'static str;
type Pk: Compress;
type Sk: Compress;
type Usk: Compress;
type Ct: Compress + Default;
type Id: Copy + Default + Derive;
const PK_BYTES: usize;
const SK_BYTES: usize;
const USK_BYTES: usize;
const CT_BYTES: usize;
fn setup<R: Rng + CryptoRng>(rng: &mut R) -> (Self::Pk, Self::Sk);
fn extract_usk<R: Rng + CryptoRng>(
pk: Option<&Self::Pk>,
sk: &Self::Sk,
id: &Self::Id,
rng: &mut R,
) -> Self::Usk;
fn encaps<R: Rng + CryptoRng>(
pk: &Self::Pk,
id: &Self::Id,
rng: &mut R,
) -> (Self::Ct, SharedSecret);
fn decaps(
mpk: Option<&Self::Pk>,
usk: &Self::Usk,
ct: &Self::Ct,
) -> Result<SharedSecret, Error>;
}