Trait Kem

Source
pub trait Kem {
    type PublicKey: AsRef<[u8]> + AsMut<[u8]> + Clone;
    type SecretKey: Zeroize + AsRef<[u8]> + AsMut<[u8]> + Clone;
    type SharedSecret: Zeroize + AsRef<[u8]> + AsMut<[u8]> + Clone;
    type Ciphertext: AsRef<[u8]> + AsMut<[u8]> + Clone;
    type KeyPair: Clone;

    // Required methods
    fn name() -> &'static str;
    fn keypair<R: CryptoRng + RngCore>(rng: &mut R) -> Result<Self::KeyPair>;
    fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey;
    fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey;
    fn encapsulate<R: CryptoRng + RngCore>(
        rng: &mut R,
        public_key: &Self::PublicKey,
    ) -> Result<(Self::Ciphertext, Self::SharedSecret)>;
    fn decapsulate(
        secret_key: &Self::SecretKey,
        ciphertext: &Self::Ciphertext,
    ) -> Result<Self::SharedSecret>;
}
Expand description

Trait for Key Encapsulation Mechanism (KEM) with domain-specific types

Required Associated Types§

Source

type PublicKey: AsRef<[u8]> + AsMut<[u8]> + Clone

Public key type with appropriate constraints

Source

type SecretKey: Zeroize + AsRef<[u8]> + AsMut<[u8]> + Clone

Secret key type with security guarantees

Source

type SharedSecret: Zeroize + AsRef<[u8]> + AsMut<[u8]> + Clone

Shared secret type with security guarantees

Source

type Ciphertext: AsRef<[u8]> + AsMut<[u8]> + Clone

Ciphertext type for the encapsulated key

Source

type KeyPair: Clone

Keypair type for efficient storage of related keys

Required Methods§

Source

fn name() -> &'static str

Returns the KEM algorithm name

Source

fn keypair<R: CryptoRng + RngCore>(rng: &mut R) -> Result<Self::KeyPair>

Generate a new keypair

Source

fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey

Extract public key from keypair

Source

fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey

Extract secret key from keypair

Source

fn encapsulate<R: CryptoRng + RngCore>( rng: &mut R, public_key: &Self::PublicKey, ) -> Result<(Self::Ciphertext, Self::SharedSecret)>

Encapsulate a shared secret using the recipient’s public key

Source

fn decapsulate( secret_key: &Self::SecretKey, ciphertext: &Self::Ciphertext, ) -> Result<Self::SharedSecret>

Decapsulate a shared secret using the private key

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§