This documentation is slowly being reviewed, so you may see some inconsistencies between sections.
For the complete documentation index, see llms.txt. This page is also available as Markdown.

ML-KEM-768

Purpose

When communicating with another party, you often need a way to establish a shared secret (symmetric) key without having an existing secure channel. An algorithm that allows this over a public (insecure) channel is called a key-establishment scheme.

Key encapsulation mechanisms (KEMs) are one type of key-establishment scheme, and they're the interface of choice for post-quantum algorithms, which protect against cryptographically relevant quantum computers (CRQCs). Even without a CRQC today, an adversary can capture encrypted data that relies on traditional key-establishment algorithms ready for decryption when such a CRQC becomes available (a store now, decrypt later attack).

Unlike a traditional key exchange, the sender's key pair isn't involved, a ciphertext needs to be sent to the recipient, and the shared secret is uniformly random. From the sending side, the algorithm is randomised rather than deterministic (the sender doesn't choose the shared secret).

Here is how it works when doing one trip of communication (real protocols often do multiple trips):

  1. Key generation: the recipient generates a key pair and shares the public key with the sender.

  2. Encapsulation: the sender uses the recipient's public key to generate a shared secret and an associated ciphertext. This ciphertext is sent to the recipient.

  3. Decapsulation: the recipient uses the ciphertext and their private key to compute the same shared secret.

ML-KEM-768 is the middle (192-bit) security strength variant of ML-KEM, which is one of the algorithms standardised by NIST as part of the Post-Quantum Cryptography (PQC) Standardization (competition) process. This variant provides protection against cryptanalysis advancements compared to ML-KEM-512 whilst being lighter (smaller parameters/marginally faster) than ML-KEM-1024. All variants are faster than traditional key exchange algorithms (e.g., X25519) but have larger parameters.

Usage

GenerateKeyPair

Fills a span with a randomly generated private key and another span with the associated public key.

Exceptions

ArgumentOutOfRangeException

publicKey has a length not equal to PublicKeySize.

ArgumentOutOfRangeException

privateKey has a length not equal to PrivateKeySize.

CryptographicException

Error generating key pair.

GenerateKeyPair

Fills a span with a private key generated using a random seed and another span with the associated public key.

Exceptions

ArgumentOutOfRangeException

publicKey has a length not equal to PublicKeySize.

ArgumentOutOfRangeException

privateKey has a length not equal to PrivateKeySize.

ArgumentOutOfRangeException

seed has a length not equal to SeedSize.

CryptographicException

Error generating key pair from seed.

Encapsulate

Fills a span with the computed shared secret and another span with the ciphertext to send to the recipient based on the recipient's public key.

Exceptions

ArgumentOutOfRangeException

sharedSecret has a length not equal to SharedSecretSize.

ArgumentOutOfRangeException

ciphertext has a length not equal to CiphertextSize.

ArgumentOutOfRangeException

recipientPublicKey has a length not equal to PublicKeySize.

CryptographicException

Invalid public key.

Decapsulate

Fills a span with the computed shared secret based on the recipient's private key and the ciphertext the recipient was sent.

Exceptions

ArgumentOutOfRangeException

sharedSecret has a length not equal to SharedSecretSize.

ArgumentOutOfRangeException

ciphertext has a length not equal to CiphertextSize.

ArgumentOutOfRangeException

recipientPrivateKey has a length not equal to PrivateKeySize.

CryptographicException

Error performing decapsulation.

Constants

These are used for validation and/or save you defining your own constants.

Notes

Encapsulation can error due to a check that the integers encoded in the public key are in the valid range. This sort of check is not performed for decapsulation.

Whilst the shared secret is 256 bits long, its security strength is actually 192 bits due to the security level of ML-KEM-768.

If you read about post-quantum algorithms, you may see the terms 'encapsulation key' and 'decapsulation key'. These mean 'public key' and 'private key' but are specific to KEMs.

Non-Interactive Pattern

This is a one-way pattern, so no back and forth between the sender and recipient is required. It's appropriate for offline applications (e.g., a file encryption program).

The recipient does not know who sent the message, and only the recipient can decrypt the message once the shared secret is erased from memory. This is the post-quantum equivalent of the N pattern. The security properties are discussed here.

  1. The sender encapsulates to the recipient's static public key. They use the shared secret as input keying material to a KDF. The output keying material is used as the key to encrypt a message using an AEAD.

  2. The KEM ciphertext is sent alongside the AEAD ciphertext to the recipient.

  3. The recipient decapsulates using their static private key and the ciphertext from the sender. They use the shared secret to derive the same key and decrypt the AEAD ciphertext.

Interactive Patterns

These are two-way patterns, so back and forth between the sender and recipient is required. They are appropriate for online applications and can provide better security properties than the one-way patterns.

Bilateral Authenticated Key Establishment

Both parties are authenticated using static KEM key pairs (e.g., associated with certificates, with each other's certificates exchanged and verified before the below). This achieves weak forward secrecy due to ephemeral key pair involvement.

  1. The sender generates an ephemeral key pair. They then encapsulate to the recipient's static public key. They send the ephemeral public key and static KEM ciphertext to the recipient.

  2. The recipient encapsulates to the sender's static public key and encapsulates to the sender's ephemeral public key, sending both KEM ciphertexts to the sender. They also decapsulate the static KEM ciphertext from the sender.

  3. The sender decapsulates the static and ephemeral KEM ciphertexts from the recipient.

  4. Both parties now have three shared secrets - two static (each other) and one ephemeral (recipient to sender). These are combined using a KDF, with the output keying material used with an AEAD.

Last updated