Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Derive a shared secret with ML-KEM

ML-KEM is the key encapsulation mechanism defined in FIPS 203. The recipient generates an encapsulation key ek to share and a decapsulation key dk to keep private. The sender encapsulates with ek, sends the resulting ciphertext ct, and keeps the shared secret. The recipient decapsulates ct with dk to obtain the same 32-byte shared secret. The scheme’s security rests on the difficulty of recovering a secret from noisy equations over a lattice.

How it works · ML-KEM key and ciphertext flow

Parameter setPublic key (bytes)Ciphertext (bytes)Python class
ML-KEM-512800768MlKem512
ML-KEM-76811841088MlKem768
ML-KEM-102415681568MlKem1024
from quantaegis import MlKem768

ek, dk = MlKem768.keygen()
ct, sender_secret = MlKem768.encaps(ek)
assert MlKem768.decaps(dk, ct) == sender_secret

If a ciphertext of the correct length fails the internal consistency check, decapsulation returns an alternative 32-byte value derived from the private key and the ciphertext. This is called implicit rejection. The return value is 32 bytes in either case, with no separate indication of whether the check passed. When receiving encrypted application data, use the SDK’s Envelope.open, which also verifies the authentication tag. Encryption example · Rust API · FIPS 203