pub trait KemComponent {
// Required methods
fn kem_id(&self) -> KemId;
fn ek_len(&self) -> usize;
fn ct_len(&self) -> usize;
fn ss_len(&self) -> usize;
fn generate_recipient_keypair(
&self,
) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>)>;
fn encapsulate(
&self,
recipient_ek: &[u8],
) -> Result<(Vec<u8>, Zeroizing<Vec<u8>>)>;
fn decapsulate(
&self,
decap_key: &[u8],
ct: &[u8],
) -> Result<Zeroizing<Vec<u8>>>;
fn seed_len(&self) -> usize;
fn recipient_from_seed(
&self,
seed: &[u8],
) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>)>;
}Expand description
One KEM component of a hybrid suite.
Object-safe and byte-oriented: the combiner iterates &[&dyn KemComponent],
and components have heterogeneous key/ciphertext types, so all material
crosses the trait boundary as bytes. Shared secrets are wrapped in
[Zeroizing].
Required Methods§
Sourcefn generate_recipient_keypair(&self) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>)>
fn generate_recipient_keypair(&self) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>)>
Generate a recipient keypair, returning (decap_key_bytes, encap_key_bytes).
Sourcefn encapsulate(
&self,
recipient_ek: &[u8],
) -> Result<(Vec<u8>, Zeroizing<Vec<u8>>)>
fn encapsulate( &self, recipient_ek: &[u8], ) -> Result<(Vec<u8>, Zeroizing<Vec<u8>>)>
Encapsulate to recipient_ek, returning (ciphertext, shared_secret).
Sourcefn decapsulate(&self, decap_key: &[u8], ct: &[u8]) -> Result<Zeroizing<Vec<u8>>>
fn decapsulate(&self, decap_key: &[u8], ct: &[u8]) -> Result<Zeroizing<Vec<u8>>>
Decapsulate ct with decap_key, returning the shared secret.
Sourcefn seed_len(&self) -> usize
fn seed_len(&self) -> usize
Byte length of the deterministic seed consumed by
KemComponent::recipient_from_seed.
Sourcefn recipient_from_seed(
&self,
seed: &[u8],
) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>)>
fn recipient_from_seed( &self, seed: &[u8], ) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>)>
Deterministically derive a recipient keypair from seed (length
KemComponent::seed_len), returning (decap_key_bytes, encap_key_bytes).
Stable identity keys (e.g. #mesh-kem) use this so they survive restarts,
unlike the OsRng KemComponent::generate_recipient_keypair.