Documentation

CslibFrontier.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)⁻¹, which for this uniform element equals its maximum point probability, Theorem 8.11's γ.
  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 and exists_secureKDF_withSeed yield non-degenerate SecureKDF instantiations for arbitrary positive key lengths msgLen n > 0 whenever 2 ^ (msgLen n) / q is negligible, and DDH.negligible_hashedElGamalCPAGame_ideal_linearHashKDF applies them to the ideal-sampling Hashed ElGamal game.

Main definitions #

Main results #

Ideal-sampling step #

References #

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

@[reducible, inline]

Seeded group descriptor (d, s) pairing a group descriptor d : F.Desc with a hash seed s : List Bool.

@[reducible, inline]

Underlying group descriptor d of a seeded descriptor (d, s).

@[reducible, inline]

Hash seed s of a seeded descriptor (d, s).

@[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.

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).

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 running distinguisher on the seeded group parameters (d, s).

@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRealGame_seededDDHDistinguisher (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (seedLen : ℕ → F.Desc → ℕ) (distinguisher : F.withSeed.DDHDistinguisher) (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.ddhRandomGame_seededDDHDistinguisher (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (seedLen : ℕ → F.Desc → ℕ) (distinguisher : F.withSeed.DDHDistinguisher) (n : ℕ) :
F.ddhRandomGame setup (F.seededDDHDistinguisher seedLen distinguisher) n = F.withSeed.ddhRandomGame (F.seededSetup setup seedLen) distinguisher n

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

seededDDHDistinguisher is uniform strict PPT whenever seedLen is polynomial-time computable in unary and distinguisher is uniform strict PPT.

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.

@[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 (SeededDesc.desc input.1)

linearHashKDF always has the key length of its underlying group description.

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.

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

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.KDFDistinguisher) (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.

structure Cslib.Crypto.PrimeOrderGroupFamily.LinearHashKDFConditions (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (keyLen bound : F.Desc → ℕ) (msgLen qMin : ℕ → ℕ) :

Statistical conditions under which linearHashKDF keyLen bound is a SecureKDF with output length msgLen over setup ([BS23], Section 8.10.4, Theorem 8.11, p. 334): on every supported description d of setup n, the derived key has length msgLen n, bound d bounds the encoded group elements, and the group order is at least qMin n > 0, while the Leftover Hash Lemma loss 2 ^ (msgLen n) / qMin n is negligible.

  • qMin_pos (n : ℕ) : 0 < qMin n

    The group-order lower bound is positive.

  • keyLen_eq (n : ℕ) (d : F.Desc) : d ∈ (setup n).support → keyLen d = msgLen n

    Supported descriptions derive keys of length msgLen n.

  • length_encode_le (n : ℕ) (d : F.Desc) : d ∈ (setup n).support → ∀ (x : F.Carrier d), (F.encode d x).length ≤ bound d

    bound d bounds the encoded length of every group element of a supported description.

  • qMin_le_order (n : ℕ) (d : F.Desc) : d ∈ (setup n).support → qMin n ≤ F.order d

    Supported descriptions have group order at least qMin n.

  • negligible : Negligible fun (n : ℕ) => 2 ^ msgLen n / ↑(qMin n)

    The Leftover Hash Lemma loss 2 ^ (msgLen n) / qMin n is negligible.

theorem Cslib.Crypto.PrimeOrderGroupFamily.secureKDF_linearHashKDF (F : PrimeOrderGroupFamily) {setup : ℕ → PMF F.Desc} {keyLen bound : F.Desc → ℕ} {msgLen qMin : ℕ → ℕ} (h : F.LinearHashKDFConditions setup keyLen bound msgLen qMin) :
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): under LinearHashKDFConditions, 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_ideal_linearHashKDF {F : PrimeOrderGroupFamily} {setup : ℕ → PMF F.Desc} {keyLen bound : F.Desc → ℕ} {msgLen qMin : ℕ → ℕ} (hDDH : F.DDH setup) (hKDF : F.LinearHashKDFConditions setup keyLen bound msgLen qMin) (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) {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)

Ideal-sampling step, not the cited result: under F.DDH setup alone, every uniform strict PPT Encryption.WordAdversary has negligible advantage in the one-time-pad Hashed ElGamal game hashedElGamalCPAGame with linearHashKDF, whose exponents are drawn exactly uniformly at the PMF level (after [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_ideal, no computational hypothesis on the key-derivation hash is needed under LinearHashKDFConditions.

@[reducible, inline]

Augment a DecodablePrimeOrderGroupFamily with a public bit-string seed in its description (Desc := F.Desc × List Bool), mirroring PrimeOrderGroupFamily.withSeed. Decoding and membership testing delegate to the underlying family description d.1 : F.Desc.