Skip to main content

KemComponent

Trait KemComponent 

Source
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§

Source

fn kem_id(&self) -> KemId

Stable identifier for this component.

Source

fn ek_len(&self) -> usize

Recipient encapsulation-key length in bytes.

Source

fn ct_len(&self) -> usize

Ciphertext length in bytes.

Source

fn ss_len(&self) -> usize

Shared-secret length in bytes.

Source

fn generate_recipient_keypair(&self) -> Result<(Zeroizing<Vec<u8>>, Vec<u8>)>

Generate a recipient keypair, returning (decap_key_bytes, encap_key_bytes).

Source

fn encapsulate( &self, recipient_ek: &[u8], ) -> Result<(Vec<u8>, Zeroizing<Vec<u8>>)>

Encapsulate to recipient_ek, returning (ciphertext, shared_secret).

Source

fn decapsulate(&self, decap_key: &[u8], ct: &[u8]) -> Result<Zeroizing<Vec<u8>>>

Decapsulate ct with decap_key, returning the shared secret.

Source

fn seed_len(&self) -> usize

Byte length of the deterministic seed consumed by KemComponent::recipient_from_seed.

Source

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.

Implementors§