1use crate::{ArraySize, Ciphertext, Seed, SharedKey};
4use core::fmt::Debug;
5use hybrid_array::Array;
6use kem::{Decapsulate, Encapsulate};
7use rand_core::CryptoRng;
8
9#[cfg(feature = "deterministic")]
10use crate::B32;
11
12pub trait EncodedSizeUser {
14 type EncodedSize: ArraySize;
16
17 fn from_bytes(enc: &Encoded<Self>) -> Self;
19
20 fn as_bytes(&self) -> Encoded<Self>;
22}
23
24pub type Encoded<T> = Array<u8, <T as EncodedSizeUser>::EncodedSize>;
26
27#[cfg(feature = "deterministic")]
30pub trait EncapsulateDeterministic<EK, SS> {
31 type Error: Debug;
33
34 fn encapsulate_deterministic(&self, m: &B32) -> Result<(EK, SS), Self::Error>;
40}
41
42pub trait KemCore: Clone {
44 type SharedKeySize: ArraySize;
46
47 type CiphertextSize: ArraySize;
49
50 type DecapsulationKey: Decapsulate<Ciphertext<Self>, SharedKey<Self>>
52 + EncodedSizeUser
53 + Debug
54 + PartialEq;
55
56 type EncapsulationKey: Encapsulate<Ciphertext<Self>, SharedKey<Self>>
58 + EncodedSizeUser
59 + Clone
60 + Debug
61 + PartialEq;
62
63 fn generate<R: CryptoRng + ?Sized>(
65 rng: &mut R,
66 ) -> (Self::DecapsulationKey, Self::EncapsulationKey);
67
68 fn from_seed(seed: Seed) -> (Self::DecapsulationKey, Self::EncapsulationKey);
71}