Skip to main content

Module mlkem

Module mlkem 

Source
Expand description

ML-KEM

ML-KEM is a post-quantum key encapsulation mechanism, specified in FIPS 203. A KEM works like public-key encryption, except that the encrypted message is always a random key chosen by the algorithm.

use bssl_crypto::mlkem;

// Generate a key pair.
let (serialized_public_key, private_key, private_seed) = mlkem::PrivateKey768::generate();

// Send `serialized_public_key` to the sender. The sender parses it:
let public_key = mlkem::PublicKey768::parse(&serialized_public_key).unwrap();

// Generate and encrypt a shared secret key to that public key.
let (ciphertext, shared_key) = public_key.encapsulate();

// Send `ciphertext` to the holder of the private key.
let shared_key2 = private_key.decapsulate(&ciphertext).unwrap();
assert_eq!(shared_key, shared_key2);

// `shared_key` would then be used with an algorithm from the `aead` module
// to encrypt and authenticate data. The two keys may not match and so it's
// critical to use an authenticated encryption mechanism to confirm the key.

Structs§

PrivateKey768
An ML-KEM-768 private key.
PrivateKey1024
An ML-KEM-1024 private key.
PublicKey768
An ML-KEM-768 public key.
PublicKey1024
An ML-KEM-1024 public key.

Constants§

CIPHERTEXT_BYTES_768
The number of bytes in the ML-KEM-768 ciphertext.
CIPHERTEXT_BYTES_1024
The number of bytes in the ML-KEM-1024 ciphertext.
PUBLIC_KEY_BYTES_768
The number of bytes in an encoded ML-KEM-768 public key.
PUBLIC_KEY_BYTES_1024
The number of bytes in an encoded ML-KEM-1024 public key.
SEED_BYTES
The number of bytes in an ML-KEM seed.
SHARED_SECRET_BYTES
The number of bytes in an ML-KEM shared secret.