Documentation

CslibFrontier.Crypto.Computational.ElGamal.ProbComp

Strict-PPT ElGamal Key Generation, KEM Encapsulation, and Encryption.INDCPAOn Bridges #

This module defines uniform strict-PPT (IsPPTOn) key generation, encapsulation, decapsulation, and encryption for multiplicative ElGamal and Hashed ElGamal ([BS23], Section 11.5, pp. 445–446, Remark 11.1, Section 11.5.2, Theorem 11.5, pp. 449–451, Exercise 11.5(a), p. 459, and Exercise 11.9, pp. 460–461) using ProbComp.sampleModNat, and connects the PMF-level ElGamal games in CslibFrontier/Crypto/Computational/ElGamal.lean directly to Encryption.KEMINDCPA, Encryption.INDCPAOf, Encryption.INDCPAOn, and Encryption.INDCPA.

Main definitions #

Main results #

References #

Probabilistic polynomial-time ElGamal key generation for a group description family d : ℕ → F.Desc ([BS23], Section 11.5, p. 445, and Exercise 11.5, p. 459): sample a ← sampleExp n (d n) and output (encPair F.encDesc encBits (d n, encode (a • g)), encNat a).

Probabilistic polynomial-time Hashed ElGamal KEM encapsulation for a group description family d : ℕ → F.Desc ([BS23], Section 11.5, p. 445, Remark 11.1, p. 446, and Exercise 11.9, pp. 460–461): sample b ← sampleExp n (d n), unpack u = dropFrame pk, and output (H (d n, encode (b • u)), encode (b • g)).

Deterministic polynomial-time Hashed ElGamal KEM decapsulation ([BS23], Section 11.5, p. 445, Remark 11.1, p. 446): given secret key sk = encNat a and KEM ciphertext ctKem = encode (b • g), recover H (d n, encode (a • v)).

theorem Cslib.Crypto.PrimeOrderGroupFamily.hashedElGamalDecaps_hashedElGamalEncapsProb (F : PrimeOrderGroupFamily) (H : F.Desc × List Bool → List Bool) (d : ℕ → F.Desc) (n : ℕ) {keys : List Bool × List Bool} (hkeys : keys ∈ (F.elGamalKeyGenProb d n).eval.support) {encapsulated : List Bool × List Bool} (hencaps : encapsulated ∈ (F.hashedElGamalEncapsProb H d n keys.1).eval.support) :
F.hashedElGamalDecaps H d n keys.2 encapsulated.2 = encapsulated.1

Hashed ElGamal KEM decapsulation correctness: for any n : ℕ, any (pk, sk) in the support of elGamalKeyGenProb d n, and any (k, ctKem) in the support of hashedElGamalEncapsProb H d n pk, hashedElGamalDecaps H d n sk ctKem = k.

KDF distinguisher constructed from a KEMAdversary (Distinguisher) for (elGamalKeyGenProb d, hashedElGamalEncapsProb H d): given (d, u, v, key), pass the public key (d, encode u) and the encapsulation (key, encode v) to the KEM distinguisher.

@[reducible, inline]

DDH distinguisher constructed from a KEMAdversary (Distinguisher) for (elGamalKeyGenProb d, hashedElGamalEncapsProb H d): kemToKDFDistinguisher run with the key H (d, encode w) derived from the candidate shared element w.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_kemGame_hashedElGamalEncapsProb_le (F : PrimeOrderGroupFamily) (keyLen : ℕ → ℕ) (H : F.Desc × List Bool → List Bool) (d : ℕ → F.Desc) (distinguisher : Distinguisher) (n : ℕ) :
Game.advantage (Encryption.kemRealGame (F.elGamalKeyGenProb d) (F.hashedElGamalEncapsProb H d) distinguisher n).eval (Encryption.kemIdealGame keyLen (F.elGamalKeyGenProb d) (F.hashedElGamalEncapsProb H d) distinguisher n).eval ≤ (F.ddhRealGame (fun (m : ℕ) => PMF.pure (d m)) (F.kemToDDHDistinguisher H distinguisher) n).advantage (F.ddhRandomGame (fun (m : ℕ) => PMF.pure (d m)) (F.kemToDDHDistinguisher H distinguisher) n) + (F.kdfRealGame (fun (m : ℕ) => PMF.pure (d m)) H (F.kemToKDFDistinguisher distinguisher) n).advantage (F.kdfIdealGame (fun (m : ℕ) => PMF.pure (d m)) keyLen (F.kemToKDFDistinguisher distinguisher) n) + 4 / 2 ^ n

Quantitative KEM IND-CPA bound for Hashed ElGamal: the KEM distinguishing advantage of distinguisher against (elGamalKeyGenProb d, hashedElGamalEncapsProb H d) is bounded by the DDH advantage of kemToDDHDistinguisher H distinguisher plus the KDF advantage of kemToKDFDistinguisher distinguisher plus 4 / 2 ^ n. The middle hybrid is the random DDH game, which is the real KDF game (ddhRandomGame_kdfToDDHDistinguisher).

Key-encapsulation step of Theorem 11.5 for the $\mathcal{E}'_{\mathrm{EG}}$ variant of Remark 11.1 ([BS23], Remark 11.1, p. 446, and Section 11.5.2, Theorem 11.5, pp. 449–451, with the KEM notion Encryption.KEMINDCPA, which strengthens that of Exercise 11.9, pp. 460–461, by giving the distinguisher the public key): the KEM (elGamalKeyGenProb d, hashedElGamalEncapsProb H d), which derives its key from the Diffie–Hellman element w = b • u alone (H (d n, encode w), not Theorem 11.5's H (v, w)), over a deterministic group schedule d : ℕ → F.Desc, satisfies Encryption.KEMINDCPA keyLen when F.DDH (fun n => PMF.pure (d n)) and F.SecureKDF (fun n => PMF.pure (d n)) H keyLen hold and H is computable in polynomial time. This is Games 0–2 of the proof of Theorem 11.5, which Remark 11.1 carries over to $\mathcal{E}'_{\mathrm{EG}}$; Theorem 11.5 itself, semantic security of the encryption scheme, is DDH.wordINDCPA_hybrid_hashedElGamal. At parameter n the group description is d n: the system parameterization $P(\lambda)$ of Section 10.5.2 (p. 413) taken deterministic.

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.indcpaOf_hybrid_hashedElGamal {F : PrimeOrderGroupFamily} {keyLen : ℕ → ℕ} {Msg : Type} {encMsg : Msg ↪ List Bool} {H : F.Desc × List Bool → List Bool} {d : ℕ → F.Desc} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hDDH : F.DDH fun (n : ℕ) => PMF.pure (d n)) (hKDF : F.SecureKDF (fun (n : ℕ) => PMF.pure (d n)) H keyLen) (hdem : Encryption.DEMOneTimeKeyINDCPAOf encMsg keyLen encryptSym) (hH : Turing.MultiTapeTM.ComputableInPolyTime H (Turing.MultiTapeTM.encPair F.encDesc Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hd : Turing.MultiTapeTM.ComputableInPolyTime d Turing.MultiTapeTM.encUnary F.encDesc) (hencryptSym : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, m) => encryptSym n k m) :

Theorem 11.5 for the $\mathcal{E}'_{\mathrm{EG}}$ variant of Remark 11.1, via Encryption.INDCPAOf ([BS23], Remark 11.1, p. 446, and Section 11.5.2, Theorem 11.5, pp. 449–451): Hashed ElGamal with the key derived from the Diffie–Hellman element w = b • u alone (hashedElGamalEncapsProb H d, not Theorem 11.5's H (v, w)), over a deterministic polynomial-time group schedule d : ℕ → F.Desc, coupled with any uniform strict-PPT one-time semantically secure symmetric cipher encryptSym (DEMOneTimeKeyINDCPAOf encMsg keyLen encryptSym), satisfies Encryption.INDCPAOf under F.DDH (fun n => PMF.pure (d n)) and F.SecureKDF (fun n => PMF.pure (d n)) H keyLen. Remark 11.1 states that the chapter's security results hold for $\mathcal{E}'_{\mathrm{EG}}$ as well as for $\mathcal{E}_{\mathrm{EG}}$. At parameter n the group description is d n: the system parameterization $P(\lambda)$ of Section 10.5.2 (p. 413) taken deterministic. Every challenge pair is admissible, for the cipher as for the scheme; this is the source's notion when all messages of Msg have one length, and DDH.wordINDCPA_hybrid_hashedElGamal is the equal-length form for words. The proof combines DDH.kemINDCPA_hashedElGamalEncapsProb with KEMINDCPA.hybrid_indcpa.

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.indcpaOn_hybrid_hashedElGamal {F : PrimeOrderGroupFamily} {keyLen : ℕ → ℕ} {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {H : F.Desc × List Bool → List Bool} {d : ℕ → F.Desc} {encryptSym : ℕ → List Bool → Msg → ProbComp (List Bool)} (hDDH : F.DDH fun (n : ℕ) => PMF.pure (d n)) (hKDF : F.SecureKDF (fun (n : ℕ) => PMF.pure (d n)) H keyLen) (hdem : Encryption.DEMOneTimeKeyINDCPAOn valid encMsg keyLen encryptSym) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × Msg × Msg) => match x with | (n, pk, m₀, m₁) => valid n pk m₀ m₁) (Encryption.encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) (hpk : ∀ (n : ℕ) (pk : List Bool) (m₀ m₁ : Msg), valid n pk m₀ m₁ = valid n [] m₀ m₁) (hH : Turing.MultiTapeTM.ComputableInPolyTime H (Turing.MultiTapeTM.encPair F.encDesc Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hd : Turing.MultiTapeTM.ComputableInPolyTime d Turing.MultiTapeTM.encUnary F.encDesc) (hencryptSym : Probability.IsPPTOn (encKeyedInput encMsg) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × Msg) => match x with | (n, k, m) => encryptSym n k m) :

Theorem 11.5 for the $\mathcal{E}'_{\mathrm{EG}}$ variant of Remark 11.1, via Encryption.INDCPAOn ([BS23], Remark 11.1, p. 446, and Section 11.5.2, Theorem 11.5, pp. 449–451): for any polynomial-time admissibility predicate valid that ignores the public key, Hashed ElGamal with the key derived from the Diffie–Hellman element w = b • u alone (hashedElGamalEncapsProb H d, not Theorem 11.5's H (v, w)), over a deterministic polynomial-time group schedule d : ℕ → F.Desc, coupled with any uniform strict-PPT one-time semantically secure symmetric cipher encryptSym (DEMOneTimeKeyINDCPAOn valid encMsg keyLen encryptSym), satisfies Encryption.INDCPAOn valid under F.DDH (fun n => PMF.pure (d n)) and F.SecureKDF (fun n => PMF.pure (d n)) H keyLen. Remark 11.1 states that the chapter's security results hold for $\mathcal{E}'_{\mathrm{EG}}$ as well as for $\mathcal{E}_{\mathrm{EG}}$. At parameter n the group description is d n: the system parameterization $P(\lambda)$ of Section 10.5.2 (p. 413) taken deterministic. Attack Game 11.1's equal-length rule fun _ _ m₀ m₁ => m₀.length == m₁.length gives the source's notion (DDH.wordINDCPA_hybrid_hashedElGamal). The proof combines DDH.kemINDCPA_hashedElGamalEncapsProb with KEMINDCPA.hybrid_indcpaOn.

Theorem 11.5 for the $\mathcal{E}'_{\mathrm{EG}}$ variant of Remark 11.1, via Encryption.WordINDCPA ([BS23], Remark 11.1, p. 446, and Section 11.5.2, Theorem 11.5, pp. 449–451): Hashed ElGamal with the key derived from the Diffie–Hellman element w = b • u alone (hashedElGamalEncapsProb H d, not Theorem 11.5's H (v, w)), over a deterministic polynomial-time group schedule d : ℕ → F.Desc, coupled with any uniform strict-PPT one-time semantically secure word cipher encryptSym (DEMOneTimeKeyWordINDCPA keyLen encryptSym), satisfies Encryption.WordINDCPA under F.DDH (fun n => PMF.pure (d n)) and F.SecureKDF (fun n => PMF.pure (d n)) H keyLen. Remark 11.1 states that the chapter's security results hold for $\mathcal{E}'_{\mathrm{EG}}$ as well as for $\mathcal{E}_{\mathrm{EG}}$; here SecureKDF is Attack Game 11.3 for the hash of w alone. At parameter n the group description is d n: the system parameterization $P(\lambda)$ of Section 10.5.2 (p. 413) taken deterministic. The scheme and the cipher are held to the equal-length rules of Attack Games 11.1 and 2.1; the proof applies DDH.indcpaOn_hybrid_hashedElGamal with fun _ _ m₀ m₁ => m₀.length == m₁.length.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.elGamalEncryptProb (F : PrimeOrderGroupFamily) {Msg : Type} (encodeMsg : F.Desc → Msg → List Bool) (d : ℕ → F.Desc) (n : ℕ) (pk : List Bool) (m : Msg) :

Probabilistic polynomial-time multiplicative ElGamal encryption for a group description family d : ℕ → F.Desc and message encoder encodeMsg : F.Desc → Msg → List Bool ([BS23], Exercise 11.5, p. 459): sample b ← sampleExp n (d n), unpack u = dropFrame pk, and output encPair encBits encBits (encodeElGamalEncrypt (d n, u, encodeMsg (d n) m, b)).

elGamalEncryptProb is uniformly strict PPT whenever encodeMsg and d are computable in polynomial time.

Deterministic polynomial-time multiplicative ElGamal decryption on words: given secret key sk = encNat a and ciphertext ct = encPair encBits encBits (v, e), compute decodeElGamal (d n, ofBits sk, unframe ct, dropFrame ct).

theorem Cslib.Crypto.PrimeOrderGroupFamily.elGamalDecryptDet_elGamalEncryptProb (F : PrimeOrderGroupFamily) (d : ℕ → F.Desc) (n : ℕ) {keys : List Bool × List Bool} (hkeys : keys ∈ (F.elGamalKeyGenProb d n).eval.support) (m : F.Carrier (d n)) {ct : List Bool} (hct : ct ∈ (F.elGamalEncryptProb (fun (x : F.Desc) (x_1 : List Bool) => x_1) d n keys.1 (F.encode (d n) m)).eval.support) :
F.elGamalDecryptDet d n keys.2 ct = F.encode (d n) m

Multiplicative ElGamal decryption correctness on ProbComp outputs: for any (pk, sk) in the support of elGamalKeyGenProb d n, any m : F.Carrier (d n), and any ct in the support of elGamalEncryptProb (fun d x => x) d n pk (F.encode (d n) m), elGamalDecryptDet d n sk ct = F.encode (d n) m.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_gameOn_elGamalMsgCPAGameOn_le (F : PrimeOrderGroupFamily) {Msg : Type} (valid : ℕ → List Bool → Msg → Msg → Bool) (encodeMsg : F.Desc → Msg → List Bool) (d : ℕ → F.Desc) (adversary : Encryption.AdversaryOf Msg) (bit : Bool) (n : ℕ) :
Game.advantage (Encryption.gameOn valid (F.elGamalKeyGenProb d) (F.elGamalEncryptProb encodeMsg d) adversary bit n).eval (F.elGamalMsgCPAGameOn valid encodeMsg (fun (m : ℕ) => PMF.pure (d m)) adversary bit n) ≤ 2 / 2 ^ n

The native Encryption.gameOn experiment for (elGamalKeyGenProb d, elGamalEncryptProb encodeMsg d) is within statistical distance 2 / 2 ^ n of the ideal exact-uniform PMF game elGamalMsgCPAGameOn valid encodeMsg (fun n => PMF.pure (d n)).

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.indcpaOn_elGamalEncryptProb_on {F : PrimeOrderGroupFamily} {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {encodeMsg : F.Desc → Msg → List Bool} {d : ℕ → F.Desc} (hDDH : F.DDH fun (n : ℕ) => PMF.pure (d n)) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × Msg × Msg) => match x with | (n, pk, m₀, m₁) => valid n pk m₀ m₁) (Encryption.encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) (hsound : F.AdmitsGroupElementsOn (fun (n : ℕ) => PMF.pure (d n)) encodeMsg valid) (hencMsg : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : F.Desc × Msg) => encodeMsg p.1 p.2) (Turing.MultiTapeTM.encPair F.encDesc encMsg) Turing.MultiTapeTM.encBits) :
Encryption.INDCPAOn valid encMsg (F.elGamalKeyGenProb d) (F.elGamalEncryptProb encodeMsg d)

Multiplicative ElGamal satisfies Encryption.INDCPAOn under DDH when valid admits only group elements under encodeMsg at d n (AdmitsGroupElementsOn (fun n => PMF.pure (d n))).

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.indcpaOn_elGamalEncryptProb {F : PrimeOrderGroupFamily} {Msg : Type} {encMsg : Msg ↪ List Bool} {valid : ℕ → List Bool → Msg → Msg → Bool} {encodeMsg : F.Desc → Msg → List Bool} {d : ℕ → F.Desc} (hDDH : F.DDH fun (n : ℕ) => PMF.pure (d n)) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × List Bool × Msg × Msg) => match x with | (n, pk, m₀, m₁) => valid n pk m₀ m₁) (Encryption.encChallengePairInput encMsg) Turing.MultiTapeTM.encBool) (hsound : F.AdmitsGroupElements encodeMsg valid) (hencMsg : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : F.Desc × Msg) => encodeMsg p.1 p.2) (Turing.MultiTapeTM.encPair F.encDesc encMsg) Turing.MultiTapeTM.encBits) :
Encryption.INDCPAOn valid encMsg (F.elGamalKeyGenProb d) (F.elGamalEncryptProb encodeMsg d)

Multiplicative ElGamal satisfies Encryption.INDCPAOn under DDH ([BS23], Exercise 11.5(a), p. 459): for any polynomial-time group description family d : ℕ → F.Desc, polynomial-time message encoder encodeMsg, and polynomial-time admissibility predicate valid admitting only group elements (AdmitsGroupElements encodeMsg valid), (elGamalKeyGenProb d, elGamalEncryptProb encodeMsg d) satisfies Encryption.INDCPAOn valid encMsg whenever F.DDH (fun n => PMF.pure (d n)) holds.

Bit ElGamal satisfies Encryption.INDCPA under DDH ([BS23], Exercise 11.5(a), p. 459): specialization of DDH.indcpaOn_elGamalEncryptProb to encodeBit.

@[reducible, inline]

Fair-coin multiplicative ElGamal ([BS23], Section 12.6.2, pp. 499–500) at security parameter n and group description d: elGamalExplicitCoinPKEWith drawing both the secret key and the encryption coins from (Nat.cast : ℕ → ZMod (F.order d)) <$> F.sampleExp n d. Correctness holds by elGamalExplicitCoinPKEWith_correct, and elGamalKeyGenProb, elGamalEncryptProb, and elGamalDecryptDet realize it on encoded group elements (eval_fst_elGamalKeyGenProb, eval_elGamalEncryptProb_encode).

The public-key output distribution of elGamalKeyGenProb d n equals the (d n, encode ·) image of the public key drawn by (elGamalProbExplicitCoinPKE n (d n)).keyGen.

On an encoded public key (d n, encode u) and encoded group element encode x, elGamalEncryptProb (fun _ w => w) has the same output distribution as encoding both components of (elGamalProbExplicitCoinPKE n (d n)).encrypt u x.