Documentation

Complexity.Crypto.Computational.ElGamal.KDF

Unconditionally Secure Key Derivation for Hashed ElGamal via the Leftover Hash Lemma #

In [BS23], Section 8.10.4 (Theorem 8.11, p. 334) and Section 11.5.2 (p. 449), a universal hash function whose key is placed in the public system parameter yields an unconditionally secure key derivation function (SecureKDF, Attack Game 11.3, pp. 448–449, and Definition 11.5, p. 449) via the Leftover Hash Lemma, without any computational assumptions on the hash family.

To formalize this over an arbitrary PrimeOrderGroupFamily:

  1. PrimeOrderGroupFamily.withSeed augments the public group description d : F.Desc with a public bit-string seed s : List Bool, giving F.withSeed.Desc = F.Desc × List Bool. Under PrimeOrderGroupFamily.seededSetup, given the sampled group description d ← setup n, s is sampled uniformly from {0, 1}^{seedLen n d} conditional on d (and independently of the group exponents). When seedLen is polynomial-time computable in unary, DDH.withSeed transfers the DDH assumption from (F, setup) to (F.withSeed, F.seededSetup setup seedLen).
  2. PrimeOrderGroupFamily.linearHashKDF pads the encoded group element w : List Bool to the fixed self-delimiting width 2 * bound d + 1 via Cslib.BitString.padWord (bound d) w and hashes it with the public Boolean matrix seed s via Cslib.BitString.LinearHash.wordHash (keyLen d) s. Because padWord is injective on words of length at most bound d (Cslib.BitString.word_eq_of_paddedBits_eq) and F.encode d is injective on F.Carrier d, a uniform group element γ • g maps injectively into BitString (2 * bound d + 1) with collision probability (F.order d)⁻¹.
  3. Applying the Leftover Hash Lemma for two-universal binary matrix hashing (Cslib.BitString.LinearHash.isTwoUniversal_flat and IsTwoUniversal.leftover_hash), advantage_kdfGame_linearHashKDF_le bounds the distinguishing advantage between kdfRealGame and kdfIdealGame for every (even computationally unbounded) distinguisher by NNReal.sqrt ((2 : ℝ≥0) ^ (msgLen n) / (qMin : ℝ≥0)) / 2. Consequently, secureKDF_linearHashKDF, secureKDF_linearHashKDF_const, exists_secureKDF_withSeed, and DDH.negligible_hashedElGamalCPAGame_linearHashKDF yield non-degenerate SecureKDF and Hashed ElGamal instantiations for arbitrary positive key lengths msgLen n > 0 whenever 2 ^ (msgLen n) / q is negligible.

Main definitions #

Main results #

References #

Prime-order group family with a public seed in the description #

@[reducible, inline]

Augment a PrimeOrderGroupFamily with a public bit-string seed in the group description (Desc := F.Desc × List Bool), as in [BS23], Section 8.10.4 (p. 334), where the universal-hash key is part of the public system parameter. All group operations act on the underlying group description d.1 : F.Desc.

Instances For
    noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.seededSetup (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (seedLen : ℕ → F.Desc → ℕ) (n : ℕ) :

    Setup distribution for F.withSeed: draw d ← setup n, then sample a uniform seed s ← Cslib.BitString.uniformList (seedLen n d) conditional on d, and return (d, s).

    Instances For

      Given a DDH distinguisher for F.withSeed, construct a DDH distinguisher for F by sampling a fresh uniform seed s ← Cslib.BitString.sampleList (seedLen n d) and passing ((d, s), u, v, w) to distinguisher.

      Instances For
        @[simp]
        theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRealGame_seededDDHDistinguisher (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (seedLen : ℕ → F.Desc → ℕ) (distinguisher : ℕ → F.withSeed.Desc × List Bool × List Bool × List Bool → ProbComp Bool) (n : ℕ) :
        F.ddhRealGame setup (F.seededDDHDistinguisher seedLen distinguisher) n = F.withSeed.ddhRealGame (F.seededSetup setup seedLen) distinguisher n

        In ddhRealGame, seededDDHDistinguisher simulates F.withSeed.ddhRealGame under seededSetup.

        @[simp]
        theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhIdealGame_seededDDHDistinguisher (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (seedLen : ℕ → F.Desc → ℕ) (distinguisher : ℕ → F.withSeed.Desc × List Bool × List Bool × List Bool → ProbComp Bool) (n : ℕ) :
        F.ddhIdealGame setup (F.seededDDHDistinguisher seedLen distinguisher) n = F.withSeed.ddhIdealGame (F.seededSetup setup seedLen) distinguisher n

        In ddhIdealGame, seededDDHDistinguisher simulates F.withSeed.ddhIdealGame under seededSetup.

        Preservation of DDH under public-seed augmentation: if F.DDH setup holds and seedLen is polynomial-time computable in unary, then F.withSeed.DDH (F.seededSetup setup seedLen) holds.

        Binary Linear-Hash Key Derivation and Leftover Hash Lemma #

        Binary linear-hash key derivation function ([BS23], Section 8.10.4, Theorem 8.11, p. 334, and Section 11.5.2, p. 449): given a seeded group description (d, s) : F.withSeed.Desc and an encoded group element w : List Bool, pad w to the self-delimiting width 2 * bound d + 1 via Cslib.BitString.padWord (bound d) w and hash with the public seed s via Cslib.BitString.LinearHash.wordHash (keyLen d) s.

        Instances For
          @[simp]
          theorem Cslib.Crypto.PrimeOrderGroupFamily.length_linearHashKDF (F : PrimeOrderGroupFamily) (keyLen bound : F.Desc → ℕ) (input : F.withSeed.Desc × List Bool) :
          (F.linearHashKDF keyLen bound input).length = keyLen input.1.1

          linearHashKDF always outputs a word of length keyLen input.1.1.

          def Cslib.Crypto.PrimeOrderGroupFamily.linearHashSeedLen (F : PrimeOrderGroupFamily) (msgLen : ℕ → ℕ) (bound : F.Desc → ℕ) (n : ℕ) (d : F.Desc) :

          The matrix seed length required by linearHashKDF for output length msgLen n and encoding length bound bound d: msgLen n * (2 * bound d + 1) bits.

          Instances For

            Self-delimiting padded bit-string encoding of γ • g in BitString (2 * bound d + 1).

            Instances For
              theorem Cslib.Crypto.PrimeOrderGroupFamily.ofFn_paddedGeneratorMultiple (F : PrimeOrderGroupFamily) {bound : F.Desc → ℕ} {d : F.Desc} (hbound : ∀ (x : F.Carrier d), (F.encode d x).length ≤ bound d) (γ : ZMod (F.order d)) :
              List.ofFn (F.paddedGeneratorMultiple bound d γ) = BitString.padWord (bound d) (F.encode d (γ • F.generator d))

              When every encoded group element in F.Carrier d has bit-length at most bound d, List.ofFn (F.paddedGeneratorMultiple bound d γ) recovers the padded word Cslib.BitString.padWord (bound d) (F.encode d (γ • F.generator d)).

              When every encoded group element in F.Carrier d has bit-length at most bound d, paddedGeneratorMultiple bound d is injective on ZMod (F.order d).

              theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_kdfGame_linearHashKDF_le (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (keyLen bound : F.Desc → ℕ) (msgLen : ℕ → ℕ) (distinguisher : ℕ → F.withSeed.Desc × List Bool × List Bool × List Bool → ProbComp Bool) (n qMin : ℕ) (hq0 : 0 < qMin) (hkey : ∀ d ∈ (setup n).support, keyLen d = msgLen n) (hbound : ∀ d ∈ (setup n).support, ∀ (x : F.Carrier d), (F.encode d x).length ≤ bound d) (hq : ∀ d ∈ (setup n).support, qMin ≤ F.order d) :
              (F.withSeed.kdfRealGame (F.seededSetup setup (F.linearHashSeedLen msgLen bound)) (F.linearHashKDF keyLen bound) distinguisher n).advantage (F.withSeed.kdfIdealGame (F.seededSetup setup (F.linearHashSeedLen msgLen bound)) msgLen distinguisher n) ≤ NNReal.sqrt (2 ^ msgLen n / ↑qMin) / 2

              Unconditional Leftover Hash Lemma bound for linearHashKDF ([BS23], Section 8.10.4, Theorem 8.11, p. 334, and Section 11.5.2, p. 449): for every (even computationally unbounded) distinguisher, when every d ∈ (setup n).support satisfies keyLen d = msgLen n, ∀ x, (F.encode d x).length ≤ bound d, and qMin ≤ F.order d with 0 < qMin, the distinguishing advantage between kdfRealGame and kdfIdealGame under F.seededSetup and F.linearHashKDF is at most NNReal.sqrt ((2 : ℝ≥0) ^ (msgLen n) / (qMin : ℝ≥0)) / 2.

              theorem Cslib.Crypto.PrimeOrderGroupFamily.secureKDF_linearHashKDF (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (keyLen bound : F.Desc → ℕ) (msgLen : ℕ → ℕ) {qMin : ℕ → ℕ} (hq0 : ∀ (n : ℕ), 0 < qMin n) (hkey : ∀ (n : ℕ), ∀ d ∈ (setup n).support, keyLen d = msgLen n) (hbound : ∀ (n : ℕ), ∀ d ∈ (setup n).support, ∀ (x : F.Carrier d), (F.encode d x).length ≤ bound d) (hq : ∀ (n : ℕ), ∀ d ∈ (setup n).support, qMin n ≤ F.order d) (hneg : Negligible fun (n : ℕ) => 2 ^ msgLen n / ↑(qMin n)) :
              F.withSeed.SecureKDF (F.seededSetup setup (F.linearHashSeedLen msgLen bound)) (F.linearHashKDF keyLen bound) msgLen

              Unconditional SecureKDF instantiation via linearHashKDF ([BS23], Section 8.10.4, Theorem 8.11, p. 334, and Section 11.5.2, Definition 11.5, p. 449): when keyLen matches msgLen n on (setup n).support, bound bounds the encoded group element length, and 2 ^ (msgLen n) / qMin n is negligible, linearHashKDF keyLen bound satisfies SecureKDF over F.withSeed and F.seededSetup setup (F.linearHashSeedLen msgLen bound).

              theorem Cslib.Crypto.PrimeOrderGroupFamily.secureKDF_linearHashKDF_const (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (bound : F.Desc → ℕ) (k : ℕ) {qMin : ℕ → ℕ} (hq0 : ∀ (n : ℕ), 0 < qMin n) (hbound : ∀ (n : ℕ), ∀ d ∈ (setup n).support, ∀ (x : F.Carrier d), (F.encode d x).length ≤ bound d) (hq : ∀ (n : ℕ), ∀ d ∈ (setup n).support, qMin n ≤ F.order d) (hneg : Negligible fun (n : ℕ) => 1 / ↑(qMin n)) :
              F.withSeed.SecureKDF (F.seededSetup setup (F.linearHashSeedLen (fun (x : ℕ) => k) bound)) (F.linearHashKDF (fun (x : F.Desc) => k) bound) fun (x : ℕ) => k

              Unconditional SecureKDF instantiation for any constant key length k : ℕ (including all non-degenerate k > 0, e.g., k = 128 as in [BS23], Section 8.10.4, p. 334): when 1 / qMin n is negligible, linearHashKDF (fun _ => k) bound is a SecureKDF with output length fun _ => k.

              theorem Cslib.Crypto.PrimeOrderGroupFamily.exists_secureKDF_withSeed (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (k : ℕ) {qMin : ℕ → ℕ} (hq0 : ∀ (n : ℕ), 0 < qMin n) (hq : ∀ (n : ℕ), ∀ d ∈ (setup n).support, qMin n ≤ F.order d) (hneg : Negligible fun (n : ℕ) => 1 / ↑(qMin n)) :

              Existence of a polynomial-time non-degenerate SecureKDF for any PrimeOrderGroupFamily with super-polynomial group order: using the canonical polynomial encoding-length bound from F.exists_length_encode_le, for every key length k : ℕ (in particular any k > 0) there exist a unary polynomial-time seed-length function seedLen and a polynomial-time hash function H : F.withSeed.Desc × List Bool → List Bool such that F.withSeed.SecureKDF (F.seededSetup setup seedLen) H (fun _ => k) holds whenever 1 / qMin n is negligible.

              theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.negligible_hashedElGamalCPAGame_linearHashKDF {F : PrimeOrderGroupFamily} {setup : ℕ → PMF F.Desc} {keyLen bound : F.Desc → ℕ} {msgLen qMin : ℕ → ℕ} (hDDH : F.DDH setup) (hkey_poly : Turing.MultiTapeTM.ComputableInPolyTime keyLen F.encDesc Turing.MultiTapeTM.encUnary) (hbound_poly : Turing.MultiTapeTM.ComputableInPolyTime bound F.encDesc Turing.MultiTapeTM.encUnary) (hmsg_poly : Turing.MultiTapeTM.ComputableInPolyTime msgLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (hq0 : ∀ (n : ℕ), 0 < qMin n) (hkey : ∀ (n : ℕ), ∀ d ∈ (setup n).support, keyLen d = msgLen n) (hbound : ∀ (n : ℕ), ∀ d ∈ (setup n).support, ∀ (x : F.Carrier d), (F.encode d x).length ≤ bound d) (hq : ∀ (n : ℕ), ∀ d ∈ (setup n).support, qMin n ≤ F.order d) (hneg : Negligible fun (n : ℕ) => 2 ^ msgLen n / ↑(qMin n)) {adversary : Encryption.WordAdversary} (hA : adversary.IsPPT) :
              Negligible fun (n : ℕ) => (F.withSeed.hashedElGamalCPAGame (F.seededSetup setup (F.linearHashSeedLen msgLen bound)) (F.linearHashKDF keyLen bound) adversary false n).advantage (F.withSeed.hashedElGamalCPAGame (F.seededSetup setup (F.linearHashSeedLen msgLen bound)) (F.linearHashKDF keyLen bound) adversary true n)

              Hashed ElGamal with linearHashKDF is IND-CPA secure under F.DDH setup alone ([BS23], Section 8.10.4, Theorem 8.11, p. 334, and Section 11.5.2, Theorem 11.5, pp. 449–451): combining DDH.withSeed, secureKDF_linearHashKDF, and DDH.negligible_hashedElGamalCPAGame, no computational hypothesis on the key-derivation hash is needed when 2 ^ (msgLen n) / qMin n is negligible.