pub trait Kem {
type EncapsulationKey;
type DecapsulationKey;
type Ciphertext;
type SharedSecret;
// Required methods
fn keygen<R: CryptoRng + ?Sized>(
rng: &mut R,
) -> Result<(Self::EncapsulationKey, Self::DecapsulationKey)>;
fn encaps<R: CryptoRng + ?Sized>(
ek: &Self::EncapsulationKey,
rng: &mut R,
) -> Result<(Self::Ciphertext, Self::SharedSecret)>;
fn decaps(
dk: &Self::DecapsulationKey,
ct: &Self::Ciphertext,
) -> Result<Self::SharedSecret>;
}Expand description
Uniform interface for Key Encapsulation Mechanisms (KEMs).
§Secret-Output Staging Note
Returning secret keys or shared secrets by value (-> Result<...>) in safe Rust can leave an
unzeroized copy in a callee’s return staging slot when moved into the caller’s return place.
Zeroization-critical callers (including quantaegis-fips) should prefer concrete in-place
keygen_into, encaps_into, and decaps_into methods where provided by the parameter set.
Required Associated Types§
Sourcetype EncapsulationKey
type EncapsulationKey
Public encapsulation key type.
Sourcetype DecapsulationKey
type DecapsulationKey
Private decapsulation key type (must zeroize on drop).
Sourcetype Ciphertext
type Ciphertext
Encapsulated ciphertext type.
Established shared secret type (must zeroize on drop).
Required Methods§
Sourcefn keygen<R: CryptoRng + ?Sized>(
rng: &mut R,
) -> Result<(Self::EncapsulationKey, Self::DecapsulationKey)>
fn keygen<R: CryptoRng + ?Sized>( rng: &mut R, ) -> Result<(Self::EncapsulationKey, Self::DecapsulationKey)>
Generates a fresh (EncapsulationKey, DecapsulationKey) key pair using rng.
For zeroization-critical callers avoiding safe-Rust return-slot staging copies of the
decapsulation key, prefer the concrete parameter set’s keygen_into method.
Sourcefn encaps<R: CryptoRng + ?Sized>(
ek: &Self::EncapsulationKey,
rng: &mut R,
) -> Result<(Self::Ciphertext, Self::SharedSecret)>
fn encaps<R: CryptoRng + ?Sized>( ek: &Self::EncapsulationKey, rng: &mut R, ) -> Result<(Self::Ciphertext, Self::SharedSecret)>
Encapsulates a fresh shared secret to ek using randomness from rng.
For zeroization-critical callers avoiding safe-Rust return-slot staging copies of the
shared secret, prefer the concrete parameter set’s encaps_into method.
Sourcefn decaps(
dk: &Self::DecapsulationKey,
ct: &Self::Ciphertext,
) -> Result<Self::SharedSecret>
fn decaps( dk: &Self::DecapsulationKey, ct: &Self::Ciphertext, ) -> Result<Self::SharedSecret>
Decapsulates ct using dk.
For IND-CCA2 KEMs such as ML-KEM, decapsulation of a valid-length but tampered ciphertext succeeds via constant-time implicit rejection rather than returning an error.
For zeroization-critical callers avoiding safe-Rust return-slot staging copies of the
shared secret, prefer the concrete parameter set’s decaps_into method.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".