Skip to main content

KEMEncapsulator

Trait KEMEncapsulator 

Source
pub trait KEMEncapsulator<PK: KEMPublicKey<PK_LEN>, const PK_LEN: usize, const CT_LEN: usize, const SS_LEN: usize>: Sized {
    // Required methods
    fn encaps(pk: &PK) -> Result<(KeyMaterial<SS_LEN>, [u8; CT_LEN]), KEMError>;
    fn encaps_rng(
        pk: &PK,
        rng: &mut dyn RNG,
    ) -> Result<(KeyMaterial<SS_LEN>, [u8; CT_LEN]), KEMError>;
}
Expand description

A Key Encapsulation Mechanism (KEM) is defined as a set of three operations: key generation, encapsulation, and decapsulation.

This trait represents the encapsulation operation performed by the holder of the public key. Decapsulation operations are performed by the corresponding KEMDecapsulator trait, and key generation is provided as an inherent associated function directly on the algorithm struct. There are several reasons for this split: first is architectural; some complex algorithms may benefit from having the encapsulation and decapsulation implementations split into separate modules. Second is for compliance: sometimes a policy soft-deprecates an algorithm so that new ciphertexts can no longer be created, but existing ciphertexts can still be decapsulated. Splitting the traits makes this policy easier to enforce.

The arrays used to encode public keys, ciphertexts, and shared secrets are statically-sized because this allows us to safely remove runtime checks for array lengths, which overall reduces the fallibility of the library. This design choice could make this trait complicated to apply to a KEM algorithm that does not have fixed sizes for the encodings of these objects.

Required Methods§

Source

fn encaps(pk: &PK) -> Result<(KeyMaterial<SS_LEN>, [u8; CT_LEN]), KEMError>

Performs an encapsulation against the given public key. Sources randomness from the library’s default OS-backed RNG. Returns the ciphertext and derived shared secret.

Source

fn encaps_rng( pk: &PK, rng: &mut dyn RNG, ) -> Result<(KeyMaterial<SS_LEN>, [u8; CT_LEN]), KEMError>

Performs an encapsulation against the given public key. Sources randomness from the provided RNG. Returns the ciphertext and derived shared secret.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§