Documentation

CslibFrontier.Crypto.Computational.CramerShoup.Reductions

Certified PPT Reductions and Probabilistic Operations for Cramer–Shoup #

This module constructs the uniform strict-PPT (IsPPTOn) operations and security reductions for the Multiplicative Cramer–Shoup public-key encryption scheme ($\mathcal{E}_{\mathrm{MCS}}$, Boneh and Shoup, Exercise 12.27, printed pp. 521–522, with associated data $\mathcal{D}$ as in Section 12.7, Definition 12.7, printed pp. 501–502) over a PrimeOrderGroupFamily, following the Games 0–4 reduction structure of Boneh and Shoup, Section 12.5.3, Theorem 12.9, printed pp. 488–493:

  1. Approximate exponent sampling via sampleModNat: sampleExp, sampleCramerShoupPair, sampleCramerShoupTripleExponents, and sampleCramerShoupSK, together with their IsPPTOn certificates and Game.advantage bounds (1 / 2 ^ n per exponent draw) relative to exact uniform sampling on ZMod (F.order d).
  2. Phase 1/2 and collision-tracking decryption oracle handlers: cramerShoupPhase1Oracle, cramerShoupPhase2Reply, cramerShoupPhase2Oracle, and cramerShoupCollisionPhase2Oracle.
  3. Certified strict-PPT DDH distinguishers (Game 1 → Game 2, eq. (12.22), printed p. 492): cramerShoupMsgToDDHDistinguisher, cramerShoupADToDDHDistinguisher, and cramerShoupToDDHDistinguisher, with DDHDistinguisher.IsPPT certificates isPPT_cramerShoupMsgToDDHDistinguisher, isPPT_cramerShoupADToDDHDistinguisher, and isPPT_cramerShoupToDDHDistinguisher.
  4. Certified strict-PPT CRHF collision finders (Game 3 → Game 4, eqs. (12.24)–(12.25), printed p. 492): cramerShoupMsgToCollisionFinder, cramerShoupADToCollisionFinder, and cramerShoupToCollisionFinder, with IsPPTOn certificates isPPTOn_cramerShoupMsgToCollisionFinder, isPPTOn_cramerShoupADToCollisionFinder, and isPPTOn_cramerShoupToCollisionFinder.
  5. Certified strict-PPT Encryption.cca2ADGameOn and Encryption.cca2GameOn operations with a keyed hash: cramerShoupValid, cramerShoupKeyGenProb, cramerShoupADEncryptProb, cramerShoupEncryptProb, cramerShoupADDecryptOpt, and cramerShoupDecryptOpt, together with their ComputableInPolyTime and IsPPTOn certificates. Key generation draws a uniform keyLen n-bit hash key hk and publishes it in the public key ([CS03], Section 6.1, Figure 1); the algorithms run the word-level scheme over the parameters (d n, hk) of F.withKey, and the hash H reads both the group and the key. isElemWithKey and cramerShoupPkHashKey read the group and the key back.

Approximate exponent sampling via sampleModNat #

Sample a pair of approximate exponents modulo F.order d.

Sample a 3-tuple of approximate exponents ⟨a, b, c⟩ modulo F.order d.

Sample a 6-exponent secret key ⟨s, t, s₁, t₁, s₂, t₂⟩ of approximate exponents modulo F.order d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_bind_sampleCramerShoupPair_le (F : PrimeOrderGroupFamily) (n : ℕ) (d : F.Desc) (k : ZMod (F.order d) → ZMod (F.order d) → Game) :
Game.advantage ((F.sampleCramerShoupPair n d).eval.bind fun (p : ℕ × ℕ) => k ↑p.1 ↑p.2) ((Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (σ : ZMod (F.order d)) => (Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (τ : ZMod (F.order d)) => k σ τ) ≤ 2 / 2 ^ n

Replacing sampleCramerShoupPair n d by two independent uniform draws on ZMod (F.order d) changes Game.advantage by at most 2 / 2 ^ n.

Replacing sampleCramerShoupTripleExponents n d by three independent uniform draws on ZMod (F.order d) changes Game.advantage by at most 3 / 2 ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_bind_sampleCramerShoupSK_le (F : PrimeOrderGroupFamily) (n : ℕ) (d : F.Desc) (k : CramerShoupSK ℕ → Game) (kZMod : ZMod (F.order d) → ZMod (F.order d) → ZMod (F.order d) → ZMod (F.order d) → ZMod (F.order d) → ZMod (F.order d) → Game) (hcast : ∀ (s t s₁ t₁ s₂ t₂ : ℕ), k { s := s, t := t, s₁ := s₁, t₁ := t₁, s₂ := s₂, t₂ := t₂ } = kZMod ↑s ↑t ↑s₁ ↑t₁ ↑s₂ ↑t₂) :
Game.advantage ((F.sampleCramerShoupSK n d).eval.bind k) ((Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (σ : ZMod (F.order d)) => (Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (τ : ZMod (F.order d)) => (Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (σ₁ : ZMod (F.order d)) => (Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (τ₁ : ZMod (F.order d)) => (Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (σ₂ : ZMod (F.order d)) => (Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (τ₂ : ZMod (F.order d)) => kZMod σ τ σ₁ τ₁ σ₂ τ₂) ≤ 6 / 2 ^ n

Replacing sampleCramerShoupSK n d by six independent uniform draws on ZMod (F.order d) changes Game.advantage by at most 6 / 2 ^ n.

Phase 1 decryption oracle handler for Cramer–Shoup (hasAD = true for cca2ADPhase1Oracle, hasAD = false for cca2Phase1Oracle).

Stateless Phase 2 decryption reply for Cramer–Shoup, rejecting the challenge (ct, ad) with [].

Phase 2 decryption oracle handler for Cramer–Shoup, rejecting the challenge (ct, ad).

Phase 2 collision-tracking oracle handler for cramerShoupMsgToCollisionFinder: replies with cramerShoupCollisionPhase2Reply and records the hashed tuple some (extractCramerShoupTuple q.1 q.2) of a query q = splitCramerShoupQuery hasAD req whenever that tuple collides with the challenge's (isCramerShoupCollision H d q.1 q.2 ct ad) and is a well-formed hash input (isCramerShoupHashInput hasAD isElem d). Queries whose tuple is not well-formed are rejected by decryption anyway, so recording only well-formed collisions loses nothing ([BS23], Section 12.5.3, Fig. 12.3, printed p. 491, takes decryption queries in $\mathbb{G}^3 \times \mathcal{C}$).

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.cramerShoupMsgToDDHDistinguisher (F : PrimeOrderGroupFamily) (hasAD : Bool) {Msg AD : Type} (encodeMsg : F.Desc × Msg → List Bool) (encodeAD : F.Desc × AD → List Bool) (H : F.Desc × List Bool → List Bool) (isElem : F.Desc × List Bool → Bool) (adversary : Encryption.ADCCA2AdversaryOf Msg AD) (bit : Bool) :

The DDH distinguisher constructed from an ADCCA2AdversaryOf Msg AD with message-to-group-word encoding encodeMsg : F.Desc × Msg → List Bool and associated-data encoding encodeAD : F.Desc × AD → List Bool ([BS23], proof of Theorem 12.9, Game 1 $\to$ Game 2, equation (12.22), printed pp. 490, 492, adapted to $\mathcal{E}_{\mathrm{MCS}}$ with associated data). It encodes the DDH elements (u, v, w) of group d and runs the word-level game on them.

@[reducible, inline]

The DDH distinguisher constructed from a group-message 1CCA adversary with associated data (Msg = List Bool, encodeMsg = Prod.snd, encodeAD = fun p => encAD p.2).

@[reducible, inline]

The DDH distinguisher constructed from an associated-data-free group-message 1CCA adversary (Msg = List Bool, encodeMsg = Prod.snd, ad = []).

cramerShoupMsgToDDHDistinguisher is uniform strict PPT whenever encodeMsg, encodeAD, H, and isElem are computable in polynomial time and adversary is a strict oracle PPT 1CCA adversary with associated data.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.cramerShoupMsgToCollisionFinder (F : PrimeOrderGroupFamily) (hasAD : Bool) {Msg AD : Type} (encodeMsg : F.Desc × Msg → List Bool) (encodeAD : F.Desc × AD → List Bool) (H : F.Desc × List Bool → List Bool) (isElem : F.Desc × List Bool → Bool) (adversary : Encryption.ADCCA2AdversaryOf Msg AD) (bit : Bool) :

The setup-parameterized collision finder constructed from an ADCCA2AdversaryOf Msg AD with message-to-group-word encoding encodeMsg : F.Desc × Msg → List Bool and associated-data encoding encodeAD : F.Desc × AD → List Bool ([BS23], proof of Theorem 12.9, Game 4, equations (12.24)–(12.25), printed p. 492, adapted to $\mathcal{E}_{\mathrm{MCS}}$ with associated data). It plays Game 3 and outputs the challenge's hashed tuple together with the last Phase 2 query tuple that cramerShoupCollisionPhase2Oracle recorded, a well-formed hash input that collides with it, or the challenge's tuple twice if there is none.

@[reducible, inline]

The setup-parameterized collision finder constructed from a group-message 1CCA adversary with associated data (Msg = List Bool, encodeMsg = Prod.snd, encodeAD = fun p => encAD p.2).

@[reducible, inline]

The setup-parameterized collision finder constructed from an associated-data-free group-message 1CCA adversary (Msg = List Bool, encodeMsg = Prod.snd, ad = []).

cramerShoupMsgToCollisionFinder is uniform strict PPT whenever encodeMsg, encodeAD, H, and isElem are computable in polynomial time and adversary is a strict oracle PPT 1CCA adversary with associated data.

encodeCramerShoupPublicKey depends on sk only through its residues modulo F.order d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.encodeCramerShoupChallenge_eq_skNatOfZMod (F : PrimeOrderGroupFamily) (H : F.Desc × List Bool → List Bool) (d : F.Desc) (sk : CramerShoupSK ℕ) (v w : F.Carrier d) (m ad : List Bool) :
F.encodeCramerShoupChallenge H d sk (F.encode d v) (F.encode d w) m ad = F.encodeCramerShoupChallenge H d (F.skNatOfZMod d ↑sk.s ↑sk.t ↑sk.s₁ ↑sk.t₁ ↑sk.s₂ ↑sk.t₂) (F.encode d v) (F.encode d w) m ad

encodeCramerShoupChallenge depends on sk only through its residues modulo F.order d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.decodeCramerShoup_eq_skNatOfZMod (F : PrimeOrderGroupFamily) (H : F.Desc × List Bool → List Bool) (isElem : F.Desc × List Bool → Bool) (hmem : ∀ (d : F.Desc) (x : List Bool), isElem (d, x) = true ↔ x ∈ Set.range (F.encode d)) (d : F.Desc) (sk : CramerShoupSK ℕ) (ct ad : List Bool) :
F.decodeCramerShoup H isElem d sk ct ad = F.decodeCramerShoup H isElem d (F.skNatOfZMod d ↑sk.s ↑sk.t ↑sk.s₁ ↑sk.t₁ ↑sk.s₂ ↑sk.t₂) ct ad

decodeCramerShoup depends on sk only through its residues modulo F.order d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.cramerShoupPhase1Oracle_eq_skNatOfZMod (F : PrimeOrderGroupFamily) (hasAD : Bool) (H : F.Desc × List Bool → List Bool) (isElem : F.Desc × List Bool → Bool) (hmem : ∀ (d : F.Desc) (x : List Bool), isElem (d, x) = true ↔ x ∈ Set.range (F.encode d)) (d : F.Desc) (sk : CramerShoupSK ℕ) :
F.cramerShoupPhase1Oracle hasAD H isElem d sk = F.cramerShoupPhase1Oracle hasAD H isElem d (F.skNatOfZMod d ↑sk.s ↑sk.t ↑sk.s₁ ↑sk.t₁ ↑sk.s₂ ↑sk.t₂)

cramerShoupPhase1Oracle depends on sk only through its residues modulo F.order d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.cramerShoupPhase2Oracle_eq_skNatOfZMod (F : PrimeOrderGroupFamily) (hasAD : Bool) (H : F.Desc × List Bool → List Bool) (isElem : F.Desc × List Bool → Bool) (hmem : ∀ (d : F.Desc) (x : List Bool), isElem (d, x) = true ↔ x ∈ Set.range (F.encode d)) (d : F.Desc) (sk : CramerShoupSK ℕ) (ct ad : List Bool) :
F.cramerShoupPhase2Oracle hasAD H isElem d sk ct ad = F.cramerShoupPhase2Oracle hasAD H isElem d (F.skNatOfZMod d ↑sk.s ↑sk.t ↑sk.s₁ ↑sk.t₁ ↑sk.s₂ ↑sk.t₂) ct ad

cramerShoupPhase2Oracle depends on sk only through its residues modulo F.order d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.cramerShoupCollisionPhase2Oracle_eq_skNatOfZMod (F : PrimeOrderGroupFamily) (hasAD : Bool) (H : F.Desc × List Bool → List Bool) (isElem : F.Desc × List Bool → Bool) (hmem : ∀ (d : F.Desc) (x : List Bool), isElem (d, x) = true ↔ x ∈ Set.range (F.encode d)) (d : F.Desc) (sk : CramerShoupSK ℕ) (ct ad : List Bool) :
F.cramerShoupCollisionPhase2Oracle hasAD H isElem d sk ct ad = F.cramerShoupCollisionPhase2Oracle hasAD H isElem d (F.skNatOfZMod d ↑sk.s ↑sk.t ↑sk.s₁ ↑sk.t₁ ↑sk.s₂ ↑sk.t₂) ct ad

cramerShoupCollisionPhase2Oracle depends on sk only through its residues modulo F.order d.

@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.encodeCramerShoupEncrypt_publicKey_eq_challenge (F : PrimeOrderGroupFamily) (H : F.Desc × List Bool → List Bool) (d : F.Desc) (α β σ τ σ₁ τ₁ σ₂ τ₂ : ZMod (F.order d)) (m ad : List Bool) :
have pkVal := F.cramerShoupPublicKey d α σ τ σ₁ τ₁ σ₂ τ₂; F.encodeCramerShoupEncrypt H d (CramerShoupPublicKey.map (F.encode d) pkVal) m ad β.val = F.encodeCramerShoupChallenge H d (F.skNatOfZMod d σ τ σ₁ τ₁ σ₂ τ₂) (F.encode d (β • F.generator d)) (F.encode d ((α * β) • F.generator d)) m ad

Word-level public-key encryption under cramerShoupPublicKey d α σ τ σ₁ τ₁ σ₂ τ₂ coincides with encodeCramerShoupChallenge on (v, w) = (β • g, (α * β) • g) ([BS23], Section 12.5.3, Game 0 $\to$ Game 1, equation (12.21), printed p. 490).

Encryption.cca2ADGameOn and Encryption.cca2GameOn instantiation #

Unpack a canonically framed 6-exponent secret key CramerShoupSK ℕ.

Native keyed scheme #

[CS03] (Section 6.1, Figure 1) draws the key hk of the hash function at key generation and puts it in the public key; [CS98] (Section 3) likewise chooses the hash function from a family when it generates keys. The native scheme below does the same over the group family F.withKey, whose parameters (d, hk) attach a key to the group d. The group at parameter n is the fixed description d n, the key hk is a uniform keyLen n-bit word, the public key word starts with the encoded parameters (d n, hk), and the secret key word starts with hk. The hash H reads both.

Group membership for the parameters (d, hk) of F.withKey: membership in the group of d, ignoring the key.

theorem Cslib.Crypto.PrimeOrderGroupFamily.isElemWithKey_iff (F : PrimeOrderGroupFamily) {isElem : F.Desc × List Bool → Bool} (hmem : ∀ (d : F.Desc) (x : List Bool), isElem (d, x) = true ↔ x ∈ Set.range (F.encode d)) (p : F.withKey.Desc) (x : List Bool) :

isElemWithKey isElem recognizes the group words of F.withKey whenever isElem recognizes those of F.

The hash key in a public key word of cramerShoupKeyGenProb: the key attached to the group parameters at the front of the word.

def Cslib.Crypto.PrimeOrderGroupFamily.cramerShoupValid (F : PrimeOrderGroupFamily) (isElem : F.Desc × List Bool → Bool) (d : ℕ → F.Desc) (n : ℕ) (_pk m₀ m₁ : List Bool) :

Challenge-pair group-membership admissibility predicate for Encryption.cca2ADGameOn and Encryption.cca2GameOn ([BS23], Section 12.5.3 & Exercise 12.27): both challenge words m₀ and m₁ must belong to the group F.Carrier (d n).

Probabilistic polynomial-time Cramer–Shoup key generation with a hash key, for a group family d : ℕ → F.Desc and key length keyLen ([CS03], Section 6.1, Figure 1): draw a uniform keyLen n-bit hash key hk, then generate a key pair over the parameters (d n, hk) of F.withKey, sampling approximate uniform exponents via sampleModNat. The public key word encodes (d n, hk) and the four group elements; the secret key word is hk framed, followed by the six secret exponents.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.cramerShoupADEncryptProb (F : PrimeOrderGroupFamily) {AD : Type} (encAD : AD ↪ List Bool) (H : F.withKey.Desc × List Bool → List Bool) (d : ℕ → F.Desc) (n : ℕ) (pk m : List Bool) (ad : AD) :

Probabilistic polynomial-time Cramer–Shoup encryption with associated data, for a group family d : ℕ → F.Desc and a keyed hash H ([CS03], Section 6.1, Figure 1): read the hash key from the public key and encrypt over the parameters (d n, hk), sampling the encryption exponent via sampleModNat.

Probabilistic polynomial-time Cramer–Shoup encryption with a keyed hash (associated-data-free specialization ad = []).

Deterministic polynomial-time Cramer–Shoup decryption with associated data and a keyed hash, for Encryption.cca2ADGameOn: read the hash key from the secret key and decrypt over the parameters (d n, hk).

Deterministic polynomial-time Cramer–Shoup decryption with a keyed hash, for Encryption.cca2GameOn (associated-data-free specialization ad = []).

@[simp]

Extracting the 4-component public-key word record from encodeCramerShoupPublicKey.

theorem Cslib.Crypto.PrimeOrderGroupFamily.encodeCramerShoupEncrypt_skNatOfZMod (F : PrimeOrderGroupFamily) (H : F.Desc × List Bool → List Bool) (d : F.Desc) (α σ τ σ₁ τ₁ σ₂ τ₂ : ZMod (F.order d)) (m ad : List Bool) (b : ℕ) :
have u := F.encode d (α • F.generator d); have sk := F.skNatOfZMod d σ τ σ₁ τ₁ σ₂ τ₂; have pkVal := F.cramerShoupPublicKey d α σ τ σ₁ τ₁ σ₂ τ₂; F.encodeCramerShoupEncrypt H d { u := u, h := F.encodeProjHashAux d sk.s sk.t u, h₁ := F.encodeProjHashAux d sk.s₁ sk.t₁ u, h₂ := F.encodeProjHashAux d sk.s₂ sk.t₂ u } m ad b = F.encodeCramerShoupEncrypt H d (CramerShoupPublicKey.map (F.encode d) pkVal) m ad (↑b).val

encodeCramerShoupEncrypt on the public-key words generated by skNatOfZMod agrees with cramerShoupPublicKey.