Documentation

CslibFrontier.Crypto.Computational.ShoupComposition

Shoup XOR-masking composition ([Shoup2000], [HHRVW2020] Lemma 5.7) #

This module formalizes Shoup's XOR-masking composition theorem ([Shoup2000]; restated as [HHRVW2020], Section 5.1.4, Lemma 5.7, pp. 29–30), stretching a target collision-resistant shrinking compression function $H_K : \{0, 1\}^{b + s} \to \{0, 1\}^b$ ($s \ge 1$) to $t$ sequential steps with a single shared subkey $K$ and $\lfloor \log_2 t \rfloor + 1$ public $b$-bit XOR masks (O(|K| + b log t) total key bits):

  1. XOR-masked sequential cascade (shoupState, shoupCascade, exists_shoupCascade_step_collision): iterates i = 1, ..., t with mask BitString.listRow b (padicValNat 2 i) masks and s-bit chunk shoupChunk b s i x, extracting an in-range step collision (1 ≤ i ≤ t) from any fixed-length message collision when b ≤ L ≤ b + t * s.
  2. Mask-reconstruction bijection (shoupPackMasks, shoupStepInput_shoupPackMasks, uniformList_map_shoupPackMasks, computableInPolyTime_shoupPackMasks): reconstructs the XOR masks via one downward scan using binary trailing-zero (padicValNat 2) last-occurrence breakpoints, proving both that step iStar receives listRow b (padicValNat 2 iStar) T ++ shoupChunk b s iStar x and that T ↦ shoupPackMasks ... T preserves BitString.uniformList (shoupMasksLen b t) via an explicit left-inverse.
  3. Target collision-resistant composition (shoupComposeKeyLen, shoupComposeEval, shoupComposeChoose, shoupComposeFindWith, shoupComposeAdversary, targetCollisionResistantOn_shoupCompose): packages [Shoup2000] / [HHRVW2020] Lemma 5.7 with O(|y| log t) key length (shoupComposeKeyLen_le) and explicit multiplicative loss dyadicSize (t n), exposing the pre-key and post-key reduction stages so downstream candidate concatenations can reuse them directly.

Main definitions #

Main results #

References #

2-adic valuation combinatorics ([Shoup2000]; [HHRVW2020], Lemma 5.7, pp. 29–30) #

Mask-count schedule and XOR-masked cascade ([Shoup2000]; [HHRVW2020] Lemma 5.7) #

Number ⌊log₂ t⌋ + 1 of b-bit XOR masks needed for a t-step Shoup cascade.

Total mask bit length (⌊log₂ t⌋ + 1) * b for t steps and chaining width b.

s-bit message chunk for step i (1 ≤ i ≤ t) after removing the initial b-bit block.

@[simp]
theorem Cslib.Crypto.length_shoupChunk (b s i : ℕ) (x : List Bool) :
(shoupChunk b s i x).length = s
def Cslib.Crypto.shoupStepInput (b s : ℕ) (masks x : List Bool) (i : ℕ) (state : List Bool) :

Input to step at step i (1 ≤ i ≤ t): (state ⊕ M_{ν₂(i)}) ++ chunk_i(x).

@[simp]
theorem Cslib.Crypto.length_shoupStepInput (b s : ℕ) (masks x : List Bool) (i : ℕ) (state : List Bool) :
(shoupStepInput b s masks x i state).length = b + s
def Cslib.Crypto.shoupState (b s : ℕ) (step : List Bool → List Bool) (masks x : List Bool) :

Chaining value h_k after k steps of Shoup's cascade under step and masks.

def Cslib.Crypto.shoupCascade (b s t : ℕ) (step : List Bool → List Bool) (masks x : List Bool) :

Output of the t-step Shoup cascade.

theorem Cslib.Crypto.length_shoupState (b s : ℕ) (step : List Bool → List Bool) (hstep : ∀ (w : List Bool), w.length = b + s → (step w).length = b) (masks x : List Bool) (k : ℕ) :
(shoupState b s step masks x k).length = b
theorem Cslib.Crypto.length_shoupCascade (b s t : ℕ) (step : List Bool → List Bool) (hstep : ∀ (w : List Bool), w.length = b + s → (step w).length = b) (masks x : List Bool) :
(shoupCascade b s t step masks x).length = b
theorem Cslib.Crypto.exists_shoupCascade_step_collision {b s t L : ℕ} (hs_pos : 1 ≤ s) (hb_le : b ≤ L) (hL_le : L ≤ b + t * s) (step : List Bool → List Bool) (hstep : ∀ (w : List Bool), w.length = b + s → (step w).length = b) (masks x₀ x₁ : List Bool) (hx₀ : x₀.length = L) (hx₁ : x₁.length = L) (hne : x₀ ≠ x₁) (hcoll : shoupCascade b s t step masks x₀ = shoupCascade b s t step masks x₁) :
∃ (i : ℕ), 1 ≤ i ∧ i ≤ t ∧ shoupStepInput b s masks x₀ i (shoupState b s step masks x₀ (i - 1)) ≠ shoupStepInput b s masks x₁ i (shoupState b s step masks x₁ (i - 1)) ∧ step (shoupStepInput b s masks x₀ i (shoupState b s step masks x₀ (i - 1))) = step (shoupStepInput b s masks x₁ i (shoupState b s step masks x₁ (i - 1)))

Deterministic step-collision extraction from any equal-length collision on shoupCascade.

Shoup XOR-mask reconstruction ([Shoup2000]; [HHRVW2020] Lemma 5.7, p. 30) #

def Cslib.Crypto.shoupPackMasks (b s t iStar : ℕ) (step : List Bool → List Bool) (x T : List Bool) :

Shoup's XOR-mask reconstruction algorithm ([Shoup2000]; [HHRVW2020] Lemma 5.7, p. 30): given base step step, target message x, planted collision step iStar (1 ≤ iStar ≤ t), and uniform random block vector T of length shoupMasksLen b t, builds the shoupMasksLen b t-bit mask list M satisfying both planted-input equality at iStar and exact uniformity.

theorem Cslib.Crypto.length_shoupPackMasks (b s t iStar : ℕ) (step : List Bool → List Bool) (x T : List Bool) :
(shoupPackMasks b s t iStar step x T).length = shoupMasksLen b t
theorem Cslib.Crypto.shoupStepInput_shoupPackMasks {b s t iStar : ℕ} (step : List Bool → List Bool) (hstep : ∀ (w : List Bool), w.length = b + s → (step w).length = b) (hi_pos : 1 ≤ iStar) (hit : iStar ≤ t) (x T : List Bool) :
have masks := shoupPackMasks b s t iStar step x T; shoupStepInput b s masks x iStar (shoupState b s step masks x (iStar - 1)) = BitString.listRow b (padicValNat 2 iStar) T ++ shoupChunk b s iStar x
theorem Cslib.Crypto.uniformList_map_shoupPackMasks (b s t iStar : ℕ) (step : List Bool → List Bool) (hstep : ∀ (w : List Bool), w.length = b + s → (step w).length = b) (hi_pos : 1 ≤ iStar) (hit : iStar ≤ t) (x : List Bool) :

Shoup's mask-reconstruction map preserves BitString.uniformList (shoupMasksLen b t) whenever 1 ≤ iStar ≤ t.

Standalone Shoup composition ([Shoup2000], [HHRVW2020] Lemma 5.7) #

def Cslib.Crypto.shoupComposeKeyLen (baseKeyLen outLen t : ℕ → ℕ) (n : ℕ) :

Total key bit-length baseKeyLen n + (Nat.log 2 (t n) + 1) * outLen n for t n-step Shoup XOR-masking composition ([Shoup2000]; [HHRVW2020], Section 5.1.4, Lemma 5.7, p. 30).

theorem Cslib.Crypto.shoupComposeKeyLen_le {baseKeyLen outLen t : ℕ → ℕ} {n : ℕ} (hout_le : outLen n ≤ baseKeyLen n) :
shoupComposeKeyLen baseKeyLen outLen t n ≤ (Nat.log 2 (t n) + 2) * baseKeyLen n

O(|y| log t) key-length bound: whenever outLen n ≤ baseKeyLen n, the composed key has length at most (Nat.log 2 (t n) + 2) * baseKeyLen n.

def Cslib.Crypto.shoupComposeEval (baseKeyLen outLen s t : ℕ → ℕ) (h : ℕ → List Bool → List Bool → List Bool) (n : ℕ) (K x : List Bool) :

Composed evaluator applying t n steps of shoupCascade to base evaluator h n key where key := BitString.listRow (baseKeyLen n) 0 K and masks := K.drop (baseKeyLen n).

@[simp]
theorem Cslib.Crypto.length_shoupComposeEval {baseKeyLen outLen s t : ℕ → ℕ} {h : ℕ → List Bool → List Bool → List Bool} {n : ℕ} {K x : List Bool} (h_len : ∀ (k w : List Bool), k.length = baseKeyLen n → w.length = outLen n + s n → (h n k w).length = outLen n) :
(shoupComposeEval baseKeyLen outLen s t h n K x).length = outLen n
noncomputable def Cslib.Crypto.shoupComposeChoose (outLen s t : ℕ → ℕ) (adversary : TargetCollisionFinder) (n : ℕ) :

Pre-key target-selection stage of Shoup's Lemma 5.7 reduction ([Shoup2000]; [HHRVW2020], Section 5.1.4, Lemma 5.7, p. 30): samples a dyadic cascade step guess rawSlot, runs adversary.choose n, draws a uniform mask-seed vector T, and outputs the (outLen n + s n)-bit planted step target w₀ together with the encoded state passed to shoupComposeFindWith.

theorem Cslib.Crypto.length_fst_of_mem_support_shoupComposeChoose {outLen s t : ℕ → ℕ} {adversary : TargetCollisionFinder} {n : ℕ} {p : List Bool × List Bool} (hp : p ∈ (shoupComposeChoose outLen s t adversary n).eval.support) :
p.1.length = outLen n + s n
noncomputable def Cslib.Crypto.shoupComposeFindWith (baseKeyLen outLen s t : ℕ) (stepOfKey : List Bool → List Bool → List Bool) (adversary : TargetCollisionFinder) (n : ℕ) (savedState k : List Bool) :

Post-key collision-extraction stage of Shoup's Lemma 5.7 reduction ([Shoup2000]; [HHRVW2020], Section 5.1.4, Lemma 5.7, p. 30): decodes savedState, normalizes k to baseKeyLen bits, reconstructs the masks via shoupPackMasks for stepOfKey key, runs adversary.find n st.advState (key ++ masks), and returns the step-iStar input.

theorem Cslib.Crypto.length_of_mem_support_shoupComposeFindWith {baseKeyLen outLen s t : ℕ} {stepOfKey : List Bool → List Bool → List Bool} {adversary : TargetCollisionFinder} {n : ℕ} {savedState k w₁ : List Bool} (hw₁ : w₁ ∈ (shoupComposeFindWith baseKeyLen outLen s t stepOfKey adversary n savedState k).eval.support) :
w₁.length = outLen + s
theorem Cslib.Crypto.isPPTOn_shoupComposeFindWith {γ : Type} {encIn : γ ↪ List Bool} {baseKeyLen outLen s t n : γ → ℕ} {stepOfKey : γ → List Bool → List Bool → List Bool} {savedState k : γ → List Bool} {adversary : TargetCollisionFinder} (hbase : Turing.MultiTapeTM.ComputableInPolyTime baseKeyLen encIn Turing.MultiTapeTM.encUnary) (hout : Turing.MultiTapeTM.ComputableInPolyTime outLen encIn Turing.MultiTapeTM.encUnary) (hs : Turing.MultiTapeTM.ComputableInPolyTime s encIn Turing.MultiTapeTM.encUnary) (ht : Turing.MultiTapeTM.ComputableInPolyTime t encIn Turing.MultiTapeTM.encUnary) (hn : Turing.MultiTapeTM.ComputableInPolyTime n encIn Turing.MultiTapeTM.encUnary) (hstep_key : Turing.MultiTapeTM.ComputableInPolyTime (fun (q : γ × List Bool × List Bool) => stepOfKey q.1 q.2.1 q.2.2) (Turing.MultiTapeTM.encPair encIn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits)) Turing.MultiTapeTM.encBits) (h_len : ∀ (a : γ) (key w : List Bool), key.length = baseKeyLen a → w.length = outLen a + s a → (stepOfKey a key w).length = outLen a) (hsaved : Turing.MultiTapeTM.ComputableInPolyTime savedState encIn Turing.MultiTapeTM.encBits) (hk : Turing.MultiTapeTM.ComputableInPolyTime k encIn Turing.MultiTapeTM.encBits) (hfind : Probability.IsPPTOn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits)) Turing.MultiTapeTM.encBits fun (x : ℕ × List Bool × List Bool) => match x with | (m, st, key) => adversary.find m st key) :
Probability.IsPPTOn encIn Turing.MultiTapeTM.encBits fun (a : γ) => shoupComposeFindWith (baseKeyLen a) (outLen a) (s a) (t a) (stepOfKey a) adversary (n a) (savedState a) (k a)
noncomputable def Cslib.Crypto.shoupComposeAdversary (baseKeyLen outLen s t : ℕ → ℕ) (h : ℕ → List Bool → List Bool → List Bool) (adversary : TargetCollisionFinder) :

Reduction adversary turning a target collision finder on shoupComposeEval into a target collision finder on the underlying shrinking compression function h, guessing the colliding step 1 ≤ iStar ≤ t n and reconstructing the log t-mask vector via shoupPackMasks ([Shoup2000]; [HHRVW2020], Section 5.1.4, Lemma 5.7, p. 30).

shoupComposeAdversary is uniformly strict PPT whenever adversary is strict PPT and all parameters and h are polynomial time.

theorem Cslib.Crypto.succProbability_targetCollisionGame_shoupCompose_le {baseKeyLen outLen s t L : ℕ → ℕ} {h : ℕ → List Bool → List Bool → List Bool} (adversary : TargetCollisionFinder) (n : ℕ) (hs_pos : 1 ≤ s n) (hb_le : outLen n ≤ L n) (hL_le : L n ≤ outLen n + t n * s n) (h_len : ∀ (k w : List Bool), k.length = baseKeyLen n → w.length = outLen n + s n → (h n k w).length = outLen n) :
Game.succProbability (targetCollisionGame (shoupComposeKeyLen baseKeyLen outLen t) (shoupComposeEval baseKeyLen outLen s t h) (fun (m : ℕ) (x : List Bool) => x.length == L m) adversary n).eval ≤ ↑(Probability.dyadicSize (t n)) * Game.succProbability (targetCollisionGame baseKeyLen h (fun (m : ℕ) (w : List Bool) => w.length == outLen m + s m) (shoupComposeAdversary baseKeyLen outLen s t h adversary) n).eval

Concrete [Shoup2000] / [HHRVW2020] Lemma 5.7 reduction: the target-collision advantage of adversary against shoupComposeEval on L n-bit inputs (outLen n ≤ L n ≤ outLen n + t n * s n) is at most dyadicSize (t n) times the target-collision advantage of shoupComposeAdversary against h on (outLen n + s n)-bit inputs.

theorem Cslib.Crypto.targetCollisionResistantOn_shoupCompose {baseKeyLen outLen s t L : ℕ → ℕ} {h : ℕ → List Bool → List Bool → List Bool} (hbase : Turing.MultiTapeTM.ComputableInPolyTime baseKeyLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (hout : Turing.MultiTapeTM.ComputableInPolyTime outLen Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (hs : Turing.MultiTapeTM.ComputableInPolyTime s Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (ht : Turing.MultiTapeTM.ComputableInPolyTime t Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (hh : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool × List Bool) => h p.1 p.2.1 p.2.2) (encKeyedInput Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hs_pos : ∀ (n : ℕ), 1 ≤ s n) (hb_le : ∀ (n : ℕ), outLen n ≤ L n) (hL_le : ∀ (n : ℕ), L n ≤ outLen n + t n * s n) (h_len : ∀ (n : ℕ) (k w : List Bool), k.length = baseKeyLen n → w.length = outLen n + s n → (h n k w).length = outLen n) (hTCR : TargetCollisionResistantOn baseKeyLen h fun (m : ℕ) (w : List Bool) => w.length == outLen m + s m) :
TargetCollisionResistantOn (shoupComposeKeyLen baseKeyLen outLen t) (shoupComposeEval baseKeyLen outLen s t h) fun (m : ℕ) (x : List Bool) => x.length == L m

Asymptotic [Shoup2000] / [HHRVW2020] Lemma 5.7: if h is target collision resistant on (outLen n + s n)-bit inputs with 1 ≤ s n and outLen n ≤ L n ≤ outLen n + t n * s n, then shoupComposeEval is target collision resistant on L n-bit inputs with compact key length baseKeyLen n + (Nat.log 2 (t n) + 1) * outLen n.