Documentation

CslibFrontier.Crypto.Computational.DiffieHellman.GapCDH.WordKEM

Word-level random-oracle DH-KEM and certified Gap-CDH reduction #

Over a DecodablePrimeOrderGroupFamily, this module states the fair-coin word-level random-oracle Diffie–Hellman key-encapsulation mechanism ([KL20], Construction 12.19, p. 431) and its word-level ROM IND-CCA security notion ([KL20], Definition 12.13, p. 425), together with the explicit word-level Gap-CDH reduction dhKEMToGapCDHWord of Theorem 12.22 (p. 435) and its uniform strict oracle-PPT certificate isOraclePPTOn_dhKEMToGapCDHWord.

Honest key generation dhKEMKeyGenWordProb and encapsulation dhKEMEncapsWordProb sample their exponents in uniform strict (oracle) PPT over fair coins via PrimeOrderGroupFamily.sampleExp (within statistical distance 1 / 2 ^ n of uniform on ZMod (F.order d)), and dhKEMDecapsWordOracle validates canonical group membership via F.isElem before evaluating the random oracle, rejecting words outside Set.range (F.encode d) with none following the ciphertext-validation remark of [KL20], Construction 12.23 (pp. 435–436). In dhKEMCCAWordGame, the random oracle H : F.Carrier d → BitString (keyLen n) is drawn uniformly, key generation, challenge encapsulation, and non-challenge decapsulation queries execute dhKEMKeyGenWordProb, dhKEMEncapsWordProb, and dhKEMDecapsWordOracle against dhKEMROAnswer, hash queries outside Set.range (F.encode d) return [], and decapsulation refuses c = cStar with [].

dhKEMToGapCDHWord mirrors PrimeOrderGroupFamily.dhKEMToGapCDH on words: when the public key word equals F.encode d 0 it outputs F.encode d 0; otherwise it samples a uniform keyLen n-bit challenge key, answers the KEM adversary's hash and decaps queries from a list of DHKEMSimEntry records using F.isElem and queryDDHWord, and extracts the first hash entry z satisfying queryDDHWord cStar z. Its oracle-PPT certificate uses only IsOraclePPT encBool A and ComputableInPolyTime keyLen encUnary encUnary.

Main definitions #

Main results #

References #

Oracle operations of a word-level ROM IND-CCA adversary against Construction 12.19: random- oracle hash queries (hash) and decapsulation queries (decaps).

  • hash : DHKEMOp

    Evaluate the random oracle H at a candidate group-element word.

  • decaps : DHKEMOp

    Decapsulate a candidate ciphertext word.

Instances For

    Challenge input (d, h, c⋆, k̂) of a word-level ROM IND-CCA adversary against Construction 12.19 ([KL20], Definition 12.13, p. 425, and Construction 12.19, p. 431).

    • groupParameters : F.Desc

      Public parameters selecting the group, its prime order, and its generator.

    • publicPoint : List Bool

      Encoded public key element (F.encode d (x • g) in the experiment).

    • ciphertext : List Bool

      Encoded challenge ciphertext (F.encode d (y • g) in the experiment).

    • key : List Bool

      Challenge symmetric key word (kReal or uniform kRand of length keyLen n).

    theorem Cslib.Crypto.encDHKEMChallenge_key_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → DHKEMChallenge F} :
    theorem Cslib.Crypto.encDHKEMChallenge_mk_budget (F : PrimeOrderGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → F.Desc} {x1 x2 x3 : γ → List Bool} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn F.encDesc budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encBits budget) (h2 : Turing.MultiTapeTM.ComputableInSpace x2 encIn Turing.MultiTapeTM.encBits budget) (h3 : Turing.MultiTapeTM.ComputableInSpace x3 encIn Turing.MultiTapeTM.encBits budget) :
    Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { groupParameters := x0 x, publicPoint := x1 x, ciphertext := x2 x, key := x3 x }) encIn (encDHKEMChallenge F) budget
    theorem Cslib.Crypto.encDHKEMChallenge_ciphertext_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → DHKEMChallenge F} :
    theorem Cslib.Crypto.encDHKEMChallenge_groupParameters_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → DHKEMChallenge F} :
    Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encDHKEMChallenge F) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).groupParameters) encIn✝ F.encDesc S✝

    Encoding of DHKEMChallenge F as the framed tuple of its four fields.

    theorem Cslib.Crypto.encDHKEMChallenge_publicPoint_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → DHKEMChallenge F} :
    theorem Cslib.Crypto.encDHKEMChallenge_mk_deg (F : PrimeOrderGroupFamily) :
    Turing.MultiTapeTM.ComputableInDegree (fun (p : F.Desc × List Bool × List Bool × List Bool) => { groupParameters := p.1, publicPoint := p.2.1, ciphertext := p.2.2.1, key := p.2.2.2 }) (encDHKEMChallengeFields F) (encDHKEMChallenge F) 1 1
    theorem Cslib.Crypto.encDHKEMChallenge_mk_inO (F : PrimeOrderGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → F.Desc} {T0 S0 : γ → ℕ} {x1 : γ → List Bool} {T1 S1 : γ → ℕ} {x2 : γ → List Bool} {T2 S2 : γ → ℕ} {x3 : γ → List Bool} {T3 S3 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn F.encDesc T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encBits T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn Turing.MultiTapeTM.encBits T2 S2) (h3 : Turing.MultiTapeTM.ComputableInO x3 encIn Turing.MultiTapeTM.encBits T3 S3) :
    Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { groupParameters := x0 x, publicPoint := x1 x, ciphertext := x2 x, key := x3 x }) encIn (encDHKEMChallenge F) (fun (x : γ) => T0 x + (T1 x + (T2 x + T3 x))) fun (x : γ) => S0 x + (S1 x + (S2 x + S3 x))

    One entry in the word-level reduction's query table: isDecaps = false records a random-oracle query elem = z, and isDecaps = true records a decapsulation query elem = c, paired with the sampled key returned for it.

    • isDecaps : Bool

      false for a hash entry (.inl z), true for a decapsulation entry (.inr c).

    • elem : List Bool

      Encoded group element (z or c).

    • key : List Bool

      Key word returned for this entry.

    theorem Cslib.Crypto.encDHKEMSimEntry_elem_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → DHKEMSimEntry} :

    Encoding of DHKEMSimEntry as the framed triple (isDecaps, elem, key).

    theorem Cslib.Crypto.encDHKEMSimEntry_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → Bool} {x1 x2 : γ → List Bool} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encBool budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encBits budget) (h2 : Turing.MultiTapeTM.ComputableInSpace x2 encIn Turing.MultiTapeTM.encBits budget) :
    Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { isDecaps := x0 x, elem := x1 x, key := x2 x }) encIn encDHKEMSimEntry budget
    theorem Cslib.Crypto.encDHKEMSimEntry_isDecaps_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → DHKEMSimEntry} :
    @[reducible, inline]

    The tuple of the fields of encDHKEMSimEntry.

    theorem Cslib.Crypto.encDHKEMSimEntry_key_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → DHKEMSimEntry} :
    theorem Cslib.Crypto.encDHKEMSimEntry_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → Bool} {T0 S0 : γ → ℕ} {x1 : γ → List Bool} {T1 S1 : γ → ℕ} {x2 : γ → List Bool} {T2 S2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encBool T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encBits T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn Turing.MultiTapeTM.encBits T2 S2) :
    Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { isDecaps := x0 x, elem := x1 x, key := x2 x }) encIn encDHKEMSimEntry (fun (x : γ) => T0 x + (T1 x + T2 x)) fun (x : γ) => S0 x + (S1 x + S2 x)

    Match a table entry against a hash query z: hash entries compare e.elem == z, while decapsulation entries ask the external DDH oracle whether z = x • e.elem.

    Match a table entry against a decapsulation query c: decapsulation entries compare e.elem == c, while hash entries ask the external DDH oracle whether e.elem = x • c.

    Return the key of the first matching entry in table, or sample a fresh uniform m-bit key and prepend ⟨isDecaps, elem, key⟩.

    Test whether a table entry is a hash entry z satisfying z = x • cStar.

    Output of fair-coin word-level DH-KEM key generation: encoded public key element paired with the sampled secret exponent residue secretKey < F.order d.

    • publicKey : List Bool

      Encoded public key F.encode d ((secretKey : ZMod (F.order d)) • F.generator d).

    • secretKey : ℕ

      Secret exponent residue sampled by PrimeOrderGroupFamily.sampleExp.

    theorem Cslib.Crypto.DecodablePrimeOrderGroupFamily.encDHKEMKeyPair_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List Bool} {T0 S0 x1 T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encBits T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) :
    Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { publicKey := x0 x, secretKey := x1 x }) encIn encDHKEMKeyPair (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x

    Encoding of DHKEMKeyPair as the framed pair (publicKey, secretKey) with binary secretKey.

    theorem Cslib.Crypto.DecodablePrimeOrderGroupFamily.encDHKEMKeyPair_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → List Bool} {x1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encBits budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) :
    Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { publicKey := x0 x, secretKey := x1 x }) encIn encDHKEMKeyPair budget

    Output of word-level DH-KEM encapsulation: encoded group-element ciphertext and key word.

    • ciphertext : List Bool

      Encoded ciphertext F.encode d (y • g).

    • key : List Bool

      Encapsulated symmetric key word List.ofFn (H (y • h)).

    theorem Cslib.Crypto.DecodablePrimeOrderGroupFamily.encDHKEMEncapsOutput_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List Bool} {T0 S0 : γ → ℕ} {x1 : γ → List Bool} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encBits T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encBits T1 S1) :
    Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { ciphertext := x0 x, key := x1 x }) encIn encDHKEMEncapsOutput (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
    @[instance_reducible]

    Canonical Fintype instance on F.Carrier d induced by the bijection α ↦ α • F.generator d from ZMod (F.order d).

    Word-level encapsulation of [KL20], Construction 12.19 (p. 431), for random oracle H, public key element h, and ephemeral exponent y: outputs the encoded ciphertext F.encode d (y • g) and the key word List.ofFn (H (y • h)).

    Word-level decapsulation of [KL20], Construction 12.19 (p. 431), with explicit group membership validation ([KL20], Construction 12.23, pp. 435–436): decodes ciphertext via F.decode d and returns some (List.ofFn (H (x • c))) on valid group encodings, or none when ¬ F.isElem (d, ciphertext).

    @[simp]

    Decapsulating an honestly generated encapsulation under the matching secret key recovers its symmetric key word.

    theorem Cslib.Crypto.DecodablePrimeOrderGroupFamily.dhKEMDecapsWord_of_not_isElem (F : DecodablePrimeOrderGroupFamily) (d : F.Desc) {m : ℕ} (H : F.Carrier d → BitString m) (x : ZMod (F.order d)) {ciphertext : List Bool} (hc : F.isElem (d, ciphertext) = false) :
    F.dhKEMDecapsWord d H x ciphertext = none

    Decapsulation rejects any candidate ciphertext word outside Set.range (F.encode d).

    Fair-coin word-level key generation of [KL20], Construction 12.19 (p. 431), at security parameter n and group d: samples x ← F.toPrimeOrderGroupFamily.sampleExp n d (within statistical distance 1 / 2 ^ n of uniform on ZMod (F.order d)) and outputs the encoded public key F.smul (d, x, F.encode d (F.generator d)) paired with x.

    Fair-coin word-level random-oracle encapsulation of [KL20], Construction 12.19 (p. 431), at security parameter n, group d, and symmetric key length keyLen: samples y ← F.toPrimeOrderGroupFamily.sampleExp n d, computes the ciphertext word F.smul (d, y, F.encode d (F.generator d)) and shared Diffie–Hellman word F.smul (d, y, publicKey), and reads keyLen n bits from the random-oracle reply at that shared word.

    Word-level random-oracle decapsulation of [KL20], Construction 12.19 (p. 431), with explicit subgroup validation ([KL20], Construction 12.23, pp. 435–436): rejects words failing F.isElem (d, ciphertext) with none, and otherwise computes F.smul (d, secretKey, ciphertext) and reads keyLen n bits from the random-oracle reply.

    Word-level random-oracle reply for H : F.Carrier d → BitString m: evaluates H on canonical group encodings (F.decode d w = some z) and returns [] outside Set.range (F.encode d).

    theorem Cslib.Crypto.DecodablePrimeOrderGroupFamily.run_dhKEMEncapsWordProb (F : DecodablePrimeOrderGroupFamily) (keyLen : ℕ → ℕ) (n : ℕ) (d : F.Desc) (H : F.Carrier d → BitString (keyLen n)) (h : F.Carrier d) :
    (ProbOracleComp.run (F.dhKEMEncapsWordProb keyLen n d (F.encode d h)) fun (req : Unit × List Bool) => pure (F.dhKEMROAnswer d H req.2)) = (fun (y : ℕ) => F.dhKEMEncapsWord d H h ↑y) <$> F.sampleExp n d

    Running dhKEMEncapsWordProb on an encoded group element F.encode d h against dhKEMROAnswer d H evaluates dhKEMEncapsWord d H h at the sampled exponent y ← F.toPrimeOrderGroupFamily.sampleExp n d.

    @[simp]
    theorem Cslib.Crypto.DecodablePrimeOrderGroupFamily.run_dhKEMDecapsWordOracle (F : DecodablePrimeOrderGroupFamily) (keyLen : ℕ → ℕ) (n : ℕ) (d : F.Desc) (H : F.Carrier d → BitString (keyLen n)) (secretKey : ℕ) (ciphertext : List Bool) :
    (ProbOracleComp.run (F.dhKEMDecapsWordOracle keyLen n d secretKey ciphertext) fun (req : Unit × List Bool) => pure (F.dhKEMROAnswer d H req.2)) = pure (F.dhKEMDecapsWord d H (↑secretKey) ciphertext)

    Running dhKEMDecapsWordOracle against dhKEMROAnswer d H computes F.dhKEMDecapsWord d H (secretKey : ZMod (F.order d)) ciphertext on every candidate word, including malformed ciphertexts outside Set.range (F.encode d).

    theorem Cslib.Crypto.DecodablePrimeOrderGroupFamily.run_dhKEMDecapsWordOracle_of_mem_support (F : DecodablePrimeOrderGroupFamily) (keyLen : ℕ → ℕ) (n : ℕ) (d : F.Desc) (H : F.Carrier d → BitString (keyLen n)) {keys : DHKEMKeyPair} (hkeys : keys ∈ (F.dhKEMKeyGenWordProb n d).eval.support) {out : DHKEMEncapsOutput} (hout : out ∈ (ProbOracleComp.run (F.dhKEMEncapsWordProb keyLen n d keys.publicKey) fun (req : Unit × List Bool) => pure (F.dhKEMROAnswer d H req.2)).eval.support) :
    (ProbOracleComp.run (F.dhKEMDecapsWordOracle keyLen n d keys.secretKey out.ciphertext) fun (req : Unit × List Bool) => pure (F.dhKEMROAnswer d H req.2)) = pure (some out.key)

    Decapsulation correctness for the fair-coin word-level DH-KEM: for every key pair keys generated by dhKEMKeyGenWordProb n d and every encapsulation out produced by dhKEMEncapsWordProb keyLen n d keys.publicKey against dhKEMROAnswer d H, running dhKEMDecapsWordOracle keyLen n d keys.secretKey out.ciphertext against the same random oracle returns pure (some out.key).

    Word-level ROM IND-CCA oracle answer for Construction 12.19: .hash w replies via F.dhKEMROAnswer d H w; .decaps c refuses c = cStar with [] (encOption encBits none) and otherwise encodes F.dhKEMDecapsWord d H x c via encOption encBits.

    Fixed-group fair-coin word-level ROM IND-CCA game for Construction 12.19 at security parameter n and group d: draws the random oracle H : F.Carrier d → BitString (keyLen n) uniformly, runs the fair-coin key generator dhKEMKeyGenWordProb n d and challenge encapsulator dhKEMEncapsWordProb keyLen n d against dhKEMROAnswer d H, supplies the real encapsulated key when bit = true (b = 0 in [KL20], Definition 12.13, p. 425) and an independent uniform keyLen n-bit key when bit = false (b = 1), and answers random-oracle and non-challenge decapsulation queries via dhKEMROAnswer and dhKEMDecapsWordOracle.

    Fair-coin word-level ROM IND-CCA game for Construction 12.19 ([KL20], Definition 12.13, p. 425, and Construction 12.19, p. 431) over setup and symmetric key length keyLen.

    Random-oracle IND-CCA security of the fair-coin word-level DH-KEM (Construction 12.19, with subgroup-validating decapsulation as in Construction 12.23) with key length keyLen: every uniform strict oracle-PPT adversary has negligible distinguishing advantage between the real-key (bit = true) and random-key (bit = false) worlds of dhKEMCCAWordGame.

    Encapsulation, decapsulation and the adversary share one random function in this game. The generic Cslib.Crypto.KEM.cpaExperiment runs closed honest algorithms and gives the distinguisher a single challenge.

    Stateful query simulator of dhKEMToGapCDHWord at parameter n, group d, and challenge ciphertext word cStar: answers valid .hash z and non-challenge valid .decaps c queries consistently from its DHKEMSimEntry table via queryDDHWord, and answers out-of-group or challenge-decapsulation queries with [] without modifying the table.

    Extract the first hash entry z in table satisfying queryDDHWord cStar z, falling back to F.encode d 0 when none matches.

    Word-level Gap-CDH reduction of [KL20], Theorem 12.22 (p. 435), mirroring PrimeOrderGroupFamily.dhKEMToGapCDH: on input = ⟨n, d, cStar, h⟩, outputs F.encode d 0 when h == F.encode d 0; otherwise samples a uniform keyLen n-bit challenge key, runs adversary n against simWordHandler, and extracts the first hash query matching x • cStar via extractDHWord.

    Uniform strict oracle-PPT certificate for dhKEMToGapCDHWord #

    Uniform strict-(oracle-)PPT certificates for honest Construction 12.19 algorithms #

    dhKEMKeyGenWordProb is uniform strict PPT whenever n and d are computable in polynomial time.

    dhKEMEncapsWordProb is uniform strict oracle-PPT whenever keyLen, n, d, and publicKey are computable in polynomial time.