Documentation

CslibFrontier.Crypto.Protocols.KEM.MLKEM

ML-KEM: the FIPS 203 implicit-rejection wrapper #

ML-KEM turns K-PKE into a key-encapsulation mechanism by a Fujisaki–Okamoto-style transform with implicit rejection (NIST, Section 6, Algorithms 16–18):

The wrapper is stated for any ExplicitCoinPKE, and the re-encryption check is the existing FujisakiOkamoto.decT with coin function m ↦ (G(m ‖ h)).2 (decapsWith_eq). Unlike FujisakiOkamoto.Scheme.decapsNotBot, which derives keys as H(m, c) and rejection keys from a message-space seed, ML-KEM takes the shared key from G without hashing c, binds the public key into G through H(ek), and derives rejection keys from an independent seed z.

G, H and J are arbitrary functions; no random-oracle security statement is made here. G returns the encryption coins directly, where FIPS 203 returns a seed expanded by PRF and SamplePolyCBD. The input checks of FIPS 203, Section 7 (encapsulation-key modulus check, decapsulation-key hash check H(ek) = h, length checks) are not modelled; the typed keys make the length and modulus checks vacuous, but the hash check is simply omitted.

Main definitions #

Main results #

References #

An ML-KEM decapsulation key: the PKE secret key, the public key, its hash H(pk) and the implicit-rejection seed z.

  • sk : SK

    PKE secret key dk_PKE.

  • pk : PK

    Public (encapsulation) key ek, kept for the re-encryption check.

  • pkHash : Hk

    Stored hash h = H(ek).

  • seed : Z

    Implicit-rejection seed z.

@[instance_reducible]
instance Cslib.Crypto.Protocols.MLKEMTransform.instDecidableEqDecapsKey {PK✝ SK✝ Hk✝ Z✝ : Type} [DecidableEq PK✝] [DecidableEq SK✝] [DecidableEq Hk✝] [DecidableEq Z✝] :
DecidableEq (DecapsKey PK✝ SK✝ Hk✝ Z✝)
def Cslib.Crypto.Protocols.MLKEMTransform.instDecidableEqDecapsKey.decEq {PK✝ SK✝ Hk✝ Z✝ : Type} [DecidableEq PK✝] [DecidableEq SK✝] [DecidableEq Hk✝] [DecidableEq Z✝] (x✝ x✝¹ : DecapsKey PK✝ SK✝ Hk✝ Z✝) :
Decidable (x✝ = x✝¹)
def Cslib.Crypto.Protocols.MLKEMTransform.keyGenWith {PK SK M R CT Hk Z : Type} (pke : ExplicitCoinPKE PK SK M R CT) (sampleSeed : ProbComp Z) (H : PK → Hk) :
ProbComp (PK × DecapsKey PK SK Hk Z)

Key generation: run the PKE key generation, sample the seed z, and store H(pk).

def Cslib.Crypto.Protocols.MLKEMTransform.encapsWith {PK SK M R CT Hk K : Type} (pke : ExplicitCoinPKE PK SK M R CT) (sampleMsg : ProbComp M) (G : M × Hk → K × R) (H : PK → Hk) (pk : PK) :
ProbComp (CT × K)

Encapsulation: sample m, derive (K, r) = G(m ‖ H(pk)), and output (Enc(pk, m; r), K).

def Cslib.Crypto.Protocols.MLKEMTransform.decapsWith {PK SK M R CT Hk Z K : Type} [DecidableEq CT] (pke : ExplicitCoinPKE PK SK M R CT) (G : M × Hk → K × R) (J : Z × CT → K) (dk : DecapsKey PK SK Hk Z) (c : CT) :
K

Decapsulation with implicit rejection: accept m' through the re-encryption check decT with coins (G(m' ‖ h)).2 and return (G(m' ‖ h)).1, or return J(z ‖ c) on rejection.

theorem Cslib.Crypto.Protocols.MLKEMTransform.decapsWith_eq {PK SK M R CT Hk Z K : Type} [DecidableEq CT] (pke : ExplicitCoinPKE PK SK M R CT) (G : M × Hk → K × R) (J : Z × CT → K) (dk : DecapsKey PK SK Hk Z) (c : CT) {m' : M} (hdec : pke.dec dk.sk c = some m') :
decapsWith pke G J dk c = if pke.encDet dk.pk m' (G (m', dk.pkHash)).2 = c then (G (m', dk.pkHash)).1 else J (dk.seed, c)

FIPS 203 form of decapsulation (NIST, Section 6, Algorithm 18): after m' = Dec(sk, c), return K' if re-encrypting m' with r' gives c, and J(z ‖ c) otherwise, where (K', r') = G(m' ‖ h).

theorem Cslib.Crypto.Protocols.MLKEMTransform.decapsWith_encT {PK SK M R CT Hk Z K : Type} [DecidableEq CT] (pke : ExplicitCoinPKE PK SK M R CT) (G : M × Hk → K × R) (J : Z × CT → K) (dk : DecapsKey PK SK Hk Z) (m : M) (hdec : pke.dec dk.sk (pke.encDet dk.pk m (G (m, dk.pkHash)).2) = some m) :
decapsWith pke G J dk (pke.encDet dk.pk m (G (m, dk.pkHash)).2) = (G (m, dk.pkHash)).1

Correctness: if the PKE decrypts the honest ciphertext Enc(pk, m; (G(m ‖ h)).2), then decapsulation returns the encapsulated key (G(m ‖ h)).1.

theorem Cslib.Crypto.Protocols.MLKEMTransform.decapsWith_of_reencrypt_ne {PK SK M R CT Hk Z K : Type} [DecidableEq CT] (pke : ExplicitCoinPKE PK SK M R CT) (G : M × Hk → K × R) (J : Z × CT → K) (dk : DecapsKey PK SK Hk Z) (c : CT) (hbad : ∀ (m' : M), pke.dec dk.sk c = some m' → pke.encDet dk.pk m' (G (m', dk.pkHash)).2 ≠ c) :
decapsWith pke G J dk c = J (dk.seed, c)

Implicit rejection: a ciphertext that fails the re-encryption check decapsulates to the rejection key J(z ‖ c).

theorem Cslib.Crypto.Protocols.MLKEMTransform.mem_support_keyGenWith {PK SK M R CT Hk Z : Type} (pke : ExplicitCoinPKE PK SK M R CT) (sampleSeed : ProbComp Z) (H : PK → Hk) {pk : PK} {dk : DecapsKey PK SK Hk Z} (h : (pk, dk) ∈ (keyGenWith pke sampleSeed H).eval.support) :
dk.pk = pk ∧ dk.pkHash = H pk ∧ (pk, dk.sk) ∈ pke.keyGen.eval.support

Every key pair produced by keyGenWith stores the public key and its hash.

@[reducible, inline]

ML-KEM decapsulation keys over K-PKE, with 256-bit public-key hashes and seeds.

noncomputable def Cslib.Crypto.MLKEM.kemKeyGen (P : Params) [NeZero P.q] (H : PublicKey P → Fin 256 → Bool) :

ML-KEM.KeyGen (NIST, Section 7, Algorithm 19) with a uniform seed z.

noncomputable def Cslib.Crypto.MLKEM.kemEncaps (P : Params) [NeZero P.q] (G : (Fin P.n → Bool) × (Fin 256 → Bool) → (Fin 256 → Bool) × Coins P) (H : PublicKey P → Fin 256 → Bool) (pk : PublicKey P) :
ProbComp (Ciphertext P × (Fin 256 → Bool))

ML-KEM.Encaps (NIST, Section 7, Algorithm 20) with a uniform message m ∈ {0,1}^n.

noncomputable def Cslib.Crypto.MLKEM.kemDecaps (P : Params) [NeZero P.q] (G : (Fin P.n → Bool) × (Fin 256 → Bool) → (Fin 256 → Bool) × Coins P) (J : (Fin 256 → Bool) × Ciphertext P → Fin 256 → Bool) (dk : DecapsKey P) (c : Ciphertext P) :
Fin 256 → Bool

ML-KEM.Decaps (NIST, Section 7, Algorithm 21).

theorem Cslib.Crypto.MLKEM.kemDecaps_encrypt_of_noise_le (P : Params) [NeZero P.q] {B : ℕ} (hB : 4 * B + 2 < P.q) (G : (Fin P.n → Bool) × (Fin 256 → Bool) → (Fin 256 → Bool) × Coins P) (H : PublicKey P → Fin 256 → Bool) (J : (Fin 256 → Bool) × Ciphertext P → Fin 256 → Bool) (A : Matrix (Fin P.k) (Fin P.k) (Fin P.n → ZMod P.q)) (s e : Fin P.k → Fin P.n → ZMod P.q) (z : Fin 256 → Bool) (m : Fin P.n → Bool) (r e₁ : Fin P.k → Fin P.n → ZMod P.q) (e₂ : Fin P.n → ZMod P.q) (hG : (G (m, H (moduleLWEKeyGen A s e))).2 = (r, e₁, e₂)) (hnoise : ∀ (i : Fin P.n), (decryptionNoise P A s e r e₁ e₂ m i).valMinAbs.natAbs ≤ B) :
have pk := moduleLWEKeyGen A s e; have dk := { sk := s, pk := pk, pkHash := H pk, seed := z }; kemDecaps P G J dk (encrypt P pk m (G (m, H pk)).2) = (G (m, H pk)).1

Correctness of ML-KEM: for an honest key pk = (A, A s + e) and a message m whose derived coins (G(m ‖ H(pk))).2 = (r, e₁, e₂) keep every coefficient of the K-PKE decryption noise within B, where 4 * B + 2 < q, decapsulating the honest ciphertext Enc(pk, m; (G(m ‖ H(pk))).2) produced by kemEncaps on message m returns its key.