Documentation

CslibFrontier.Crypto.Computational.SIS.MLKEM.KPKE

K-PKE, the public-key encryption scheme inside ML-KEM #

K-PKE (NIST, Section 5, Algorithms 13–15) is Module-LWE encryption over R_q = ℤ_q[X] / (X^n + 1) with centered-binomial secrets and errors and lossy ciphertext compression:

The uncompressed ciphertext is the existing moduleLWEEncrypt ciphertext of the all-zero message shifted by the FIPS 203 message polynomial (encryptRaw_eq_moduleLWEEncrypt_add); the two encodings differ because FIPS 203 rounds q / 2 up. Public keys reuse ModuleLWEPublicKey, and the scheme is packaged through the shared ExplicitCoinPKE interface (toExplicitCoinPKE) for later use by the Fujisaki–Okamoto layer.

Correctness is deterministic: decryption recovers m whenever every coefficient of the decryption noise decryptionNoise, which collects the Module-LWE error terms and both compression errors, has centered magnitude at most B with 4 * B + 2 < q (decrypt_encrypt_eq_of_noise_le). The compression errors are bounded by natAbs_valMinAbs_decompress_compress_sub_le.

Model differences #

Main definitions #

Main results #

References #

Parameters #

ML-KEM parameters: ring degree n, modulus q, module rank k, centered-binomial widths η₁ (secrets and encryption randomness) and η₂ (encryption errors), and compression widths d_u, d_v. The degree and modulus default to the FIPS 203 values 256 and 3329.

  • n : ℕ

    Ring degree n.

  • q : ℕ

    Modulus q.

  • k : ℕ

    Module rank k.

  • η₁ : ℕ

    Centered-binomial width η₁ of the secret, key error and encryption randomness.

  • η₂ : ℕ

    Centered-binomial width η₂ of the encryption errors.

  • du : ℕ

    Compression width d_u of the vector part of a ciphertext.

  • dv : ℕ

    Compression width d_v of the scalar part of a ciphertext.

ML-KEM-512 (NIST, Section 8, Table 2): k = 2, η₁ = 3, η₂ = 2, d_u = 10, d_v = 4.

ML-KEM-768 (NIST, Section 8, Table 2): k = 3, η₁ = 2, η₂ = 2, d_u = 10, d_v = 4.

ML-KEM-1024 (NIST, Section 8, Table 2): k = 4, η₁ = 2, η₂ = 2, d_u = 11, d_v = 5.

The parameter sets approved by FIPS 203.

Instances For
    theorem Cslib.Crypto.MLKEM.Params.IsStandard.bounds {P : Params} (h : P.IsStandard) :
    P.n = 256 ∧ P.q = 3329 ∧ 2 ^ P.du < P.q ∧ 2 ^ P.dv < P.q

    Every approved parameter set has n = 256, q = 3329 and compression widths below log₂ q, so compress_decompress applies to both ciphertext parts.

    Keys, ciphertexts and deterministic algorithms #

    @[reducible, inline]

    K-PKE public keys (A, b) are Module-LWE public keys.

    @[reducible, inline]

    K-PKE secret keys s ∈ R_q^k.

    @[reducible, inline]

    Encryption coins (r, e₁, e₂) ∈ R_q^k × R_q^k × R_q.

    @[reducible, inline]

    Compressed ciphertexts (c₁, c₂) with d_u-bit coefficients in c₁ ∈ (ℤ_{2^{d_u}}^n)^k and d_v-bit coefficients in c₂ ∈ ℤ_{2^{d_v}}^n.

    def Cslib.Crypto.MLKEM.messagePoly (P : Params) (m : Fin P.n → Bool) :
    Fin P.n → ZMod P.q

    The message polynomial Decompress_1(m): bit 1 becomes ⌈q / 2⌋ and bit 0 becomes 0.

    def Cslib.Crypto.MLKEM.encryptRaw (P : Params) (pk : PublicKey P) (r e₁ : Fin P.k → Fin P.n → ZMod P.q) (e₂ : Fin P.n → ZMod P.q) (m : Fin P.n → Bool) :

    Uncompressed K-PKE encryption (Aᵀ r + e₁, bᵀ r + e₂ + Decompress_1(m)).

    Compress both parts of an uncompressed ciphertext.

    Decompress both parts of a ciphertext.

    def Cslib.Crypto.MLKEM.encrypt (P : Params) (pk : PublicKey P) (m : Fin P.n → Bool) (coins : Coins P) :

    Deterministic K-PKE encryption K-PKE.Encrypt(pk, m; (r, e₁, e₂)) (NIST, Section 5, Algorithm 14), with explicit coins.

    def Cslib.Crypto.MLKEM.decrypt (P : Params) (s : SecretKey P) (ct : Ciphertext P) :
    Fin P.n → Bool

    K-PKE decryption K-PKE.Decrypt(s, c) = Compress_1(v' - sᵀ u') (NIST, Section 5, Algorithm 15), reading coefficient 1 as the bit true.

    @[simp]
    theorem Cslib.Crypto.MLKEM.encodePolyMsg_false {n : ℕ} (q : ℕ) :
    (encodePolyMsg q fun (x : Fin n) => false) = 0

    The existing Module-LWE encoding of the all-zero message is zero.

    theorem Cslib.Crypto.MLKEM.encryptRaw_eq_moduleLWEEncrypt_add (P : Params) (pk : PublicKey P) (r e₁ : Fin P.k → Fin P.n → ZMod P.q) (e₂ : Fin P.n → ZMod P.q) (m : Fin P.n → Bool) :
    encryptRaw P pk r e₁ e₂ m = (moduleLWEEncrypt pk r e₁ e₂ fun (x : Fin P.n) => false) + (0, messagePoly P m)

    Relation to moduleLWEEncrypt: uncompressed K-PKE encryption is Module-LWE encryption of the all-zero message, shifted by the FIPS 203 message polynomial.

    Bounded-noise correctness #

    def Cslib.Crypto.MLKEM.decryptionNoise (P : Params) (A : Matrix (Fin P.k) (Fin P.k) (Fin P.n → ZMod P.q)) (s e r e₁ : Fin P.k → Fin P.n → ZMod P.q) (e₂ : Fin P.n → ZMod P.q) (m : Fin P.n → Bool) :
    Fin P.n → ZMod P.q

    The decryption noise of an honest encryption: the Module-LWE error eᵀ r - sᵀ e₁ + e₂, plus the scalar compression error c_v, minus sᵀ c_u for the vector compression error c_u.

    theorem Cslib.Crypto.MLKEM.decrypt_encrypt_phase (P : Params) (A : Matrix (Fin P.k) (Fin P.k) (Fin P.n → ZMod P.q)) (s e r e₁ : Fin P.k → Fin P.n → ZMod P.q) (e₂ : Fin P.n → ZMod P.q) (m : Fin P.n → Bool) :
    have ct := decompressCiphertext P (encrypt P (moduleLWEKeyGen A s e) m (r, e₁, e₂)); ct.2 - innerPoly ct.1 s = messagePoly P m + decryptionNoise P A s e r e₁ e₂ m

    Decryption phase: for an honest key and encryption, v' - sᵀ u' equals the message polynomial plus decryptionNoise.

    theorem Cslib.Crypto.MLKEM.decrypt_encrypt_eq_of_noise_le (P : Params) {B : ℕ} (hB : 4 * B + 2 < P.q) (A : Matrix (Fin P.k) (Fin P.k) (Fin P.n → ZMod P.q)) (s e r e₁ : Fin P.k → Fin P.n → ZMod P.q) (e₂ : Fin P.n → ZMod P.q) (m : Fin P.n → Bool) (hnoise : ∀ (i : Fin P.n), (decryptionNoise P A s e r e₁ e₂ m i).valMinAbs.natAbs ≤ B) :
    decrypt P s (encrypt P (moduleLWEKeyGen A s e) m (r, e₁, e₂)) = m

    Bounded-noise correctness of K-PKE: if every coefficient of decryptionNoise has centered magnitude at most B and 4 * B + 2 < q, decryption of an honest encryption recovers the message.

    Centered-binomial sampling programs #

    noncomputable def Cslib.Crypto.MLKEM.samplePolyCBD (n q η : ℕ) :
    ProbComp (Fin n → ZMod q)

    SamplePolyCBD_η (NIST, Section 4.2.2, Algorithm 8) as a program: n independent centered-binomial coefficients of width η, reduced modulo q.

    noncomputable def Cslib.Crypto.MLKEM.sampleVecCBD (k n q η : ℕ) :
    ProbComp (Fin k → Fin n → ZMod q)

    A vector of k independent SamplePolyCBD_η polynomials.

    K-PKE key generation (NIST, Section 5, Algorithm 13) with a uniform matrix: A uniform, s, e ← CBD_{η₁}^k, output ((A, A s + e), s).

    K-PKE encryption coins (NIST, Section 5, Algorithm 14): r ← CBD_{η₁}^k, e₁ ← CBD_{η₂}^k, e₂ ← CBD_{η₂}.

    K-PKE as an explicit-coin public-key encryption scheme. Decryption never fails.