Expand description
§Key Encapsulation Mechanism
A KEM interface.
For ECDH structs, check the libcrux_ecdh crate.
Available algorithms:
Algorithm::X25519: x25519 ECDH KEM. Also see [libcrux::ecdh#x25519].Algorithm::Secp256r1: NIST P256 ECDH KEM. Also see [libcrux::ecdh#P256].Algorithm::MlKem512: ML-KEM 512 from FIPS 203.Algorithm::MlKem768: ML-KEM 768 from FIPS 203.Algorithm::MlKem1024: ML-KEM 1024 from FIPS 203.Algorithm::X25519MlKem768Draft00: Hybrid x25519 - ML-KEM 768 draft kem for hpke.Algorithm::XWingKemDraft06: Hybrid x25519 - ML-KEM 768 draft xwing kem for hpke.
use libcrux_kem::*;
use rand::TryRngCore;
use rand::rngs::OsRng;
let mut os_rng = OsRng;
let mut rng = os_rng.unwrap_mut();
let (sk_a, pk_a) = key_gen(Algorithm::MlKem768, &mut rng).unwrap();
let received_pk = pk_a.encode();
let pk = PublicKey::decode(Algorithm::MlKem768, &received_pk).unwrap();
let (ss_b, ct_b) = pk.encapsulate(&mut rng).unwrap();
let received_ct = ct_b.encode();
let ct_a = Ct::decode(Algorithm::MlKem768, &received_ct).unwrap();
let ss_a = ct_a.decapsulate(&sk_a).unwrap();
assert_eq!(ss_b.encode(), ss_a.encode());Structs§
- MlKem512
- The ML-KEM 512 algorithms
- MlKem768
- The ML-KEM 768 algorithms
- MlKem1024
- The ML-KEM 1024 algorithms
- MlKem
Ciphertext - An ML-KEM Ciphertext
- MlKem
KeyPair - An ML-KEM key pair
- P256
- X25519
- X25519
MlKem768 Draft00 Private Key - An ML-KEM768-x25519 private key.
- X25519
MlKem768 Draft00 Public Key - An ML-KEM768-x25519 public key.
- XWing
- XWing
KemDraft06 Private Key - An X-Wing private key.
- XWing
KemDraft06 Public Key - An X-Wing public key.
Enums§
- Algorithm
- KEM Algorithms
- Ct
- A KEM ciphertext
- Error
- Private
Key - A KEM private key.
- Public
Key - A KEM public key.
- Ss
- A KEM shared secret
Functions§
- key_gen
- Generate a key pair for the
Algorithmusing the provided rng. - key_
gen_ derand - Generate a key pair for the
Algorithmusing the provided rng. - secret_
to_ public - Compute the public key for a private key of the given
Algorithm. Applicable only to X25519 and secp256r1.
Type Aliases§
- MlKem512
Ciphertext - An ML-KEM 512 Ciphertext
- MlKem512
Private Key - An ML-KEM 512 Private key
- MlKem512
Public Key - An ML-KEM 512 Public key
- MlKem768
Ciphertext - An ML-KEM 768 Ciphertext
- MlKem768
Private Key - An ML-KEM 768 Private key
- MlKem768
Public Key - An ML-KEM 768 Public key
- MlKem1024
Ciphertext - An ML-KEM 1024 Ciphertext
- MlKem1024
Private Key - An ML-KEM 1024 Private key
- MlKem1024
Public Key - An ML-KEM 1024 Public key