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§
- Private
Key768 - An ML-KEM-768 private key.
- Private
Key1024 - An ML-KEM-1024 private key.
- Public
Key768 - An ML-KEM-768 public key.
- Public
Key1024 - 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.