Documentation

CslibFrontier.Crypto.Computational.Encryption.Nested

Nested encryption #

Given a symmetric cipher E : Cipher K M M whose ciphertexts lie in its plaintext space M, E.nested n ([BS23], §2.4, p. 37) composes n encryption layers with independent keys k 0, ..., k (n - 1), applying k 0 innermost and k (n - 1) outermost. Decryption peels the keys in reverse order. Cipher.nested_correct proves that n-way nesting preserves correctness.

Cipher.nestedExperiment states the n-way nested security game of [BS23], §2.4, p. 37: the adversary chooses a message pair and the index withheld : Fin n of one hidden key, and receives the nested ciphertext together with the remaining n - 1 keys (revealKeys).

Relative to [BS23], §2.4, this module has the following differences:

nestedToSingleAdversary gives the reduction for Theorem 2.12: it samples a Fin n → K key vector via OracleComp.replicateFin (never reading the withheld coordinate), encrypts both messages through the prefix layers 0, ..., withheld - 1, delegates the withheld layer to oneTimeExperiment, and applies the suffix layers withheld + 1, ..., n - 1 before calling A.guess when st.admissible holds. eval_oneTimeExperiment_nestedToSingleAdversary and advantage_nestedExperiment_eq prove exact distribution and advantage equality, isPPT_nestedToSingleAdversary proves uniform strict polynomial-time efficiency of the reduction, and indistinguishable_nestedExperiment_of_oneTimeExperiment derives Game.Indistinguishable for n-way nesting from single-key semantic security.

Main definitions #

Main results #

References #

def Cslib.Crypto.Cipher.nestedEncrypt {K M : Type} (E : Cipher K M M) (n : ℕ) :
(Fin n → K) → M → ProbComp M

n-way nested encryption applying keys k 0, ..., k (n - 1) from innermost to outermost.

@[simp]
theorem Cslib.Crypto.Cipher.nestedEncrypt_zero {K M : Type} (E : Cipher K M M) (k : Fin 0 → K) (m : M) :
E.nestedEncrypt 0 k m = pure m
@[simp]
theorem Cslib.Crypto.Cipher.nestedEncrypt_succ {K M : Type} (E : Cipher K M M) (n : ℕ) (k : Fin (n + 1) → K) (m : M) :
E.nestedEncrypt (n + 1) k m = E.encrypt (k 0) m >>= E.nestedEncrypt n (Fin.tail k)
def Cslib.Crypto.Cipher.nestedDecrypt {K M : Type} (E : Cipher K M M) (n : ℕ) :
(Fin n → K) → M → Option M

n-way nested decryption peeling keys k (n - 1), ..., k 0 from outermost to innermost.

@[simp]
theorem Cslib.Crypto.Cipher.nestedDecrypt_zero {K M : Type} (E : Cipher K M M) (k : Fin 0 → K) (c : M) :
E.nestedDecrypt 0 k c = some c
@[simp]
theorem Cslib.Crypto.Cipher.nestedDecrypt_succ {K M : Type} (E : Cipher K M M) (n : ℕ) (k : Fin (n + 1) → K) (c : M) :
E.nestedDecrypt (n + 1) k c = (E.nestedDecrypt n (Fin.tail k) c).bind (E.decrypt (k 0))
def Cslib.Crypto.Cipher.nested {K M : Type} (E : Cipher K M M) (n : ℕ) :
Cipher (Fin n → K) M M

The n-way nested cipher E_n ([BS23], §2.4, p. 37). Unlike the book's 1-based indexing, keys are indexed by Fin n with k 0 applied innermost; n = 0 is the identity.

theorem Cslib.Crypto.Cipher.nested_correct {K M : Type} {E : Cipher K M M} (hE : E.Correct) (n : ℕ) :

n-way nested encryption of a correct cipher is correct.

def Cslib.Crypto.Cipher.PreservesValid {K M : Type} (E : Cipher K M M) (sampleKey : ProbComp K) (valid : M → M → Bool) :

Admissibility preservation under encryption: encrypting an admissible pair (m₀, m₁) under any supported key produces an admissible ciphertext pair (c₀, c₁). [BS23] Theorem 2.12 does not state this condition, and the theorem fails without it (tagCipher_no_wrapper in the tests); the corrected form here assumes it so prefix-encrypted pairs stay admissible for the outer game.

structure Cslib.Crypto.NestedRequest (M : Type) (n : ℕ) :

Challenge request of an n-way nested encryption adversary: a message pair and the 0-indexed withheld key position withheld : Fin n (empty when n = 0).

  • pair : MessagePair M

    Pair of challenge plaintexts chosen by the adversary.

  • withheld : Fin n

    0-based index of the single key withheld from the adversary (Fin 0 is empty).

structure Cslib.Crypto.NestedChallenge (K M : Type) (n : ℕ) :

Second-stage challenge received by an n-way nested encryption adversary: the nested ciphertext and every key except the withheld index.

  • ciphertext : M

    Challenge ciphertext returned by the n-way nested cipher.

  • revealedKeys : Fin n → Option K

    Partial key vector revealing some (k i) for i ≠ withheld and none at withheld.

def Cslib.Crypto.revealKeys {K : Type} {n : ℕ} (d : Fin n) (k : Fin n → K) :
Fin n → Option K

Reveal every key in k except at 0-based index d.

@[simp]
theorem Cslib.Crypto.revealKeys_self {K : Type} {n : ℕ} (d : Fin n) (k : Fin n → K) :
@[simp]
theorem Cslib.Crypto.revealKeys_of_ne {K : Type} {n : ℕ} {d i : Fin n} (h : i ≠ d) (k : Fin n → K) :
revealKeys d k i = some (k i)
theorem Cslib.Crypto.revealKeys_apply {K : Type} {n : ℕ} (d i : Fin n) (k : Fin n → K) :
revealKeys d k i = if i = d then none else some (k i)
def Cslib.Crypto.Cipher.nestedExperiment {K M σ : Type} (E : Cipher K M M) (sampleKey : ProbComp K) (valid : M → M → Bool) (n : ℕ) (A : TwoStage Unit (NestedRequest M n) (NestedChallenge K M n) Bool σ) (b : Bool) :

The n-way nested encryption security experiment ([BS23], §2.4, p. 37). Differs from the book by indexing keys from 0 via Fin n and permitting the vacuous n = 0 case.

def Cslib.Crypto.Cipher.nestedPrefix {K M : Type} (E : Cipher K M M) {n : ℕ} :
Fin n → (Fin n → K) → M → ProbComp M

Piece of the reduction: encrypt under prefix layers 0, ..., d - 1 (reads only k i for i < d).

def Cslib.Crypto.Cipher.nestedSuffix {K M : Type} (E : Cipher K M M) {n : ℕ} :
Fin n → (Fin n → K) → M → ProbComp M

Piece of the reduction: encrypt under suffix layers d + 1, ..., n - 1 (reads only k i for d < i).

Internal state of the reduction from n-way nested encryption to single-key encryption.

  • innerState : σ

    Saved state of the underlying n-way nested adversary A.

  • withheld : Fin n

    Withheld key index chosen by A.

  • keys : Fin n → K

    Keys drawn by the reduction; coordinate withheld is never read.

  • admissible : Bool

    Whether A's original message pair satisfies valid.

def Cslib.Crypto.nestedToSingleAdversary {K M σ : Type} (E : Cipher K M M) (sampleKey : ProbComp K) (valid : M → M → Bool) (n : ℕ) (A : TwoStage Unit (NestedRequest M n) (NestedChallenge K M n) Bool σ) :

Single-key reduction adversary for Theorem 2.12: draws n keys (ignoring coordinate withheld), encrypts msg₀ and msg₁ under the prefix 0, ..., withheld - 1, delegates the withheld layer to oneTimeExperiment, and finishes with the suffix withheld + 1, ..., n - 1 when st.admissible holds.

theorem Cslib.Crypto.eval_oneTimeExperiment_nestedToSingleAdversary {K M σ : Type} (E : Cipher K M M) (sampleKey : ProbComp K) (valid : M → M → Bool) (hpres : E.PreservesValid sampleKey valid) (n : ℕ) (A : TwoStage Unit (NestedRequest M n) (NestedChallenge K M n) Bool σ) (b : Bool) :
ProbComp.eval (E.oneTimeExperiment sampleKey valid (nestedToSingleAdversary E sampleKey valid n A) b) = ProbComp.eval (E.nestedExperiment sampleKey valid n A b)

Exact output-distribution equality between the outer single-key experiment running nestedToSingleAdversary and the n-way nested experiment running A, under E.PreservesValid sampleKey valid.

theorem Cslib.Crypto.advantage_nestedExperiment_eq {K M σ : Type} (E : Cipher K M M) (sampleKey : ProbComp K) (valid : M → M → Bool) (hpres : E.PreservesValid sampleKey valid) (n : ℕ) (A : TwoStage Unit (NestedRequest M n) (NestedChallenge K M n) Bool σ) :
(E.nestedExperiment sampleKey valid n A false).advantage (E.nestedExperiment sampleKey valid n A true) = (E.oneTimeExperiment sampleKey valid (nestedToSingleAdversary E sampleKey valid n A) false).advantage (E.oneTimeExperiment sampleKey valid (nestedToSingleAdversary E sampleKey valid n A) true)

Exact advantage equality for the corrected form of Theorem 2.12 ([BS23], §2.4, p. 37): under E.PreservesValid sampleKey valid, a hypothesis the book does not state and without which the equality fails (tagCipher_no_wrapper), the n-way nested advantage of A equals the one-time advantage of nestedToSingleAdversary.

theorem Cslib.Crypto.encNestedRequest_mk_deg {M : Type} (encM : M ↪ List Bool) (n : ℕ) :
Turing.MultiTapeTM.ComputableInDegree (fun (p : MessagePair M × Fin n) => { pair := p.1, withheld := p.2 }) (encNestedRequestFields encM n) (encNestedRequest encM n) 1 1
theorem Cslib.Crypto.encNestedRequest_pair_polyTime {M : Type} (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedRequest M n} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encNestedRequest encM n) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).pair) encIn✝ (encMessagePair encM)
theorem Cslib.Crypto.encNestedRequest_mk_budget {M : Type} (encM : M ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → MessagePair M} {x1 : γ → Fin n} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn (encMessagePair encM) budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn (Turing.MultiTapeTM.encFinEnum (Fin n)) budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { pair := x0 x, withheld := x1 x }) encIn (encNestedRequest encM n) budget
theorem Cslib.Crypto.encNestedRequest_withheld_polyTime {M : Type} (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedRequest M n} :
@[reducible, inline]

The tuple of the fields of encNestedRequest.

theorem Cslib.Crypto.encNestedRequest_mk_inO {M : Type} (encM : M ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → MessagePair M} {T0 S0 : γ → ℕ} {x1 : γ → Fin n} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn (encMessagePair encM) T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encFinEnum (Fin n)) T1 S1) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { pair := x0 x, withheld := x1 x }) encIn (encNestedRequest encM n) (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
theorem Cslib.Crypto.encNestedRequest_mk_polyTime {M : Type} (encM : M ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → MessagePair M} {x1 : γ → Fin n} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn (encMessagePair encM)) (h1 : Turing.MultiTapeTM.ComputableInPolyTime x1 encIn (Turing.MultiTapeTM.encFinEnum (Fin n))) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { pair := x0 x, withheld := x1 x }) encIn (encNestedRequest encM n)
theorem Cslib.Crypto.encNestedRequest_pair_budget {M : Type} (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedRequest M n} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encNestedRequest encM n) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).pair) encIn✝ (encMessagePair encM) S✝
theorem Cslib.Crypto.encNestedRequest_withheld_budget {M : Type} (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedRequest M n} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encNestedRequest encM n) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).withheld) encIn✝ (Turing.MultiTapeTM.encFinEnum (Fin n)) S✝

Computable encoding of a NestedRequest M n as (pair, withheld).

@[simp]
theorem Cslib.Crypto.encNestedChallenge_mk_polyTime {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → M} {x1 : γ → Fin n → Option K} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn encM) (h1 : Turing.MultiTapeTM.ComputableInPolyTime x1 encIn (Turing.MultiTapeTM.encFinFn n (Turing.MultiTapeTM.encOption encK))) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { ciphertext := x0 x, revealedKeys := x1 x }) encIn (encNestedChallenge encK encM n)
theorem Cslib.Crypto.encNestedChallenge_mk_budget {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → M} {x1 : γ → Fin n → Option K} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encM budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn (Turing.MultiTapeTM.encFinFn n (Turing.MultiTapeTM.encOption encK)) budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { ciphertext := x0 x, revealedKeys := x1 x }) encIn (encNestedChallenge encK encM n) budget
theorem Cslib.Crypto.encNestedChallenge_ciphertext_length_le {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) (a : NestedChallenge K M n) :
(encM a.ciphertext).length ≤ ((encNestedChallenge encK encM n) a).length
theorem Cslib.Crypto.encNestedChallenge_mk_deg {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) :
Turing.MultiTapeTM.ComputableInDegree (fun (p : M × (Fin n → Option K)) => { ciphertext := p.1, revealedKeys := p.2 }) (encNestedChallengeFields encK encM n) (encNestedChallenge encK encM n) 1 1
theorem Cslib.Crypto.encNestedChallenge_revealedKeys_polyTime {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedChallenge K M n} :
theorem Cslib.Crypto.encNestedChallenge_revealedKeys_budget {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedChallenge K M n} :
def Cslib.Crypto.encNestedChallenge {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) :

Computable encoding of a NestedChallenge K M n as (ciphertext, revealedKeys).

@[simp]
theorem Cslib.Crypto.encNestedChallenge_apply {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) (a : NestedChallenge K M n) :
theorem Cslib.Crypto.encNestedChallenge_ciphertext_budget {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedChallenge K M n} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encNestedChallenge encK encM n) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).ciphertext) encIn✝ encM S✝
theorem Cslib.Crypto.encNestedChallenge_ciphertext_polyTime {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedChallenge K M n} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encNestedChallenge encK encM n) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).ciphertext) encIn✝ encM
theorem Cslib.Crypto.encNestedChallenge_mk_inO {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → M} {T0 S0 : γ → ℕ} {x1 : γ → Fin n → Option K} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encM T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encFinFn n (Turing.MultiTapeTM.encOption encK)) T1 S1) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { ciphertext := x0 x, revealedKeys := x1 x }) encIn (encNestedChallenge encK encM n) (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
@[reducible, inline]
abbrev Cslib.Crypto.encNestedChallengeFields {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) :
M × (Fin n → Option K) ↪ List Bool

The tuple of the fields of encNestedChallenge.

theorem Cslib.Crypto.encNestedChallenge_ciphertext_inO {K M : Type} (encK : K ↪ List Bool) (encM : M ↪ List Bool) (n : ℕ) :
Turing.MultiTapeTM.ComputableInO NestedChallenge.ciphertext (encNestedChallenge encK encM n) encM (fun (a : NestedChallenge K M n) => ((encNestedChallenge encK encM n) a).length) fun (a : NestedChallenge K M n) => ((encNestedChallenge encK encM n) a).length
theorem Cslib.Crypto.encNestedReductionState_withheld_polyTime {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedReductionState K σ n} :
theorem Cslib.Crypto.encNestedReductionState_mk_inO {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → σ} {T0 S0 : γ → ℕ} {x1 : γ → Fin n} {T1 S1 : γ → ℕ} {x2 : γ → Fin n → K} {T2 S2 : γ → ℕ} {x3 : γ → Bool} {T3 S3 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encσ T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encFinEnum (Fin n)) T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn (Turing.MultiTapeTM.encFinFn n encK) T2 S2) (h3 : Turing.MultiTapeTM.ComputableInO x3 encIn Turing.MultiTapeTM.encBool T3 S3) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { innerState := x0 x, withheld := x1 x, keys := x2 x, admissible := x3 x }) encIn (encNestedReductionState encK encσ n) (fun (x : γ) => T0 x + (T1 x + (T2 x + T3 x))) fun (x : γ) => S0 x + (S1 x + (S2 x + S3 x))
theorem Cslib.Crypto.encNestedReductionState_keys_budget {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedReductionState K σ n} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encNestedReductionState encK encσ n) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).keys) encIn✝ (Turing.MultiTapeTM.encFinFn n encK) S✝
theorem Cslib.Crypto.encNestedReductionState_admissible_budget {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedReductionState K σ n} :
theorem Cslib.Crypto.encNestedReductionState_innerState_budget {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedReductionState K σ n} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encNestedReductionState encK encσ n) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).innerState) encIn✝ encσ S✝
theorem Cslib.Crypto.encNestedReductionState_innerState_polyTime {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedReductionState K σ n} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encNestedReductionState encK encσ n) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).innerState) encIn✝ encσ
theorem Cslib.Crypto.encNestedReductionState_mk_polyTime {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → σ} {x1 : γ → Fin n} {x2 : γ → Fin n → K} {x3 : γ → Bool} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn encσ) (h1 : Turing.MultiTapeTM.ComputableInPolyTime x1 encIn (Turing.MultiTapeTM.encFinEnum (Fin n))) (h2 : Turing.MultiTapeTM.ComputableInPolyTime x2 encIn (Turing.MultiTapeTM.encFinFn n encK)) (h3 : Turing.MultiTapeTM.ComputableInPolyTime x3 encIn Turing.MultiTapeTM.encBool) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { innerState := x0 x, withheld := x1 x, keys := x2 x, admissible := x3 x }) encIn (encNestedReductionState encK encσ n)
theorem Cslib.Crypto.encNestedReductionState_withheld_budget {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NestedReductionState K σ n} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encNestedReductionState encK encσ n) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).withheld) encIn✝ (Turing.MultiTapeTM.encFinEnum (Fin n)) S✝
theorem Cslib.Crypto.encNestedReductionState_admissible_polyTime {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedReductionState K σ n} :

Computable encoding of NestedReductionState K σ n.

theorem Cslib.Crypto.encNestedReductionState_mk_deg {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) :
Turing.MultiTapeTM.ComputableInDegree (fun (p : σ × Fin n × (Fin n → K) × Bool) => { innerState := p.1, withheld := p.2.1, keys := p.2.2.1, admissible := p.2.2.2 }) (encNestedReductionStateFields encK encσ n) (encNestedReductionState encK encσ n) 1 1
theorem Cslib.Crypto.encNestedReductionState_keys_polyTime {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NestedReductionState K σ n} :
@[reducible, inline]
abbrev Cslib.Crypto.encNestedReductionStateFields {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) :
σ × Fin n × (Fin n → K) × Bool ↪ List Bool

The tuple of the fields of encNestedReductionState.

theorem Cslib.Crypto.encNestedReductionState_mk_budget {K σ : Type} (encK : K ↪ List Bool) (encσ : σ ↪ List Bool) (n : ℕ) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → σ} {x1 : γ → Fin n} {x2 : γ → Fin n → K} {x3 : γ → Bool} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encσ budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn (Turing.MultiTapeTM.encFinEnum (Fin n)) budget) (h2 : Turing.MultiTapeTM.ComputableInSpace x2 encIn (Turing.MultiTapeTM.encFinFn n encK) budget) (h3 : Turing.MultiTapeTM.ComputableInSpace x3 encIn Turing.MultiTapeTM.encBool budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { innerState := x0 x, withheld := x1 x, keys := x2 x, admissible := x3 x }) encIn (encNestedReductionState encK encσ n) budget
theorem Cslib.Crypto.isPPT_nestedToSingleAdversary {K M σ : Type} {encK : K ↪ List Bool} {encM : M ↪ List Bool} {encσ : σ ↪ List Bool} {E : ℕ → Cipher K M M} {sampleKey : ℕ → ProbComp K} {valid : ℕ → M → M → Bool} (hsampleKey : Probability.IsPPTOn Turing.MultiTapeTM.encUnary encK sampleKey) (hencrypt : Probability.IsPPTOn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary (Turing.MultiTapeTM.encPair encK encM)) encM fun (x : ℕ × K × M) => match x with | (sec, k, m) => (E sec).encrypt k m) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × M × M) => match x with | (sec, m₀, m₁) => valid sec m₀ m₁) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary (Turing.MultiTapeTM.encPair encM encM)) Turing.MultiTapeTM.encBool) (n : ℕ) {A : ℕ → TwoStage Unit (NestedRequest M n) (NestedChallenge K M n) Bool σ} (hA : TwoStage.IsPPT Turing.MultiTapeTM.encUnit (encNestedRequest encM n) (encNestedChallenge encK encM n) Turing.MultiTapeTM.encBool encσ A) :
TwoStage.IsPPT Turing.MultiTapeTM.encUnit (encMessagePair encM) encM Turing.MultiTapeTM.encBool (encNestedReductionState encK encσ n) fun (sec : ℕ) => nestedToSingleAdversary (E sec) (sampleKey sec) (valid sec) n (A sec)

Uniform strict polynomial-time efficiency of nestedToSingleAdversary: for a fixed n, when sampleKey and encrypt are strict PPT and valid is computable in polynomial time (each uniformly in the security parameter), the reductions of any uniform strict PPT family A (with revealed keys encoded as an encFinFn table) form a uniform strict PPT family.

theorem Cslib.Crypto.indistinguishable_nestedExperiment_of_oneTimeExperiment {K M : Type} {encK : K ↪ List Bool} {encM : M ↪ List Bool} (E : ℕ → Cipher K M M) (sampleKey : ℕ → ProbComp K) (valid : ℕ → M → M → Bool) (hsampleKey : Probability.IsPPTOn Turing.MultiTapeTM.encUnary encK sampleKey) (hencrypt : Probability.IsPPTOn (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary (Turing.MultiTapeTM.encPair encK encM)) encM fun (x : ℕ × K × M) => match x with | (sec, k, m) => (E sec).encrypt k m) (hvalid : Turing.MultiTapeTM.ComputableInPolyTime (fun (x : ℕ × M × M) => match x with | (sec, m₀, m₁) => valid sec m₀ m₁) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary (Turing.MultiTapeTM.encPair encM encM)) Turing.MultiTapeTM.encBool) (hpres : ∀ (sec : ℕ), (E sec).PreservesValid (sampleKey sec) (valid sec)) (n : ℕ) (hsec : ∀ {σ' : Type} (encσ' : σ' ↪ List Bool), Game.Indistinguishable (fun (B : ℕ → TwoStage Unit (MessagePair M) M Bool σ') (sec : ℕ) => ProbComp.eval ((E sec).oneTimeExperiment (sampleKey sec) (valid sec) (B sec) false)) (fun (B : ℕ → TwoStage Unit (MessagePair M) M Bool σ') (sec : ℕ) => ProbComp.eval ((E sec).oneTimeExperiment (sampleKey sec) (valid sec) (B sec) true)) (TwoStage.IsPPT Turing.MultiTapeTM.encUnit (encMessagePair encM) encM Turing.MultiTapeTM.encBool encσ')) {σ : Type} (encσ : σ ↪ List Bool) :
Game.Indistinguishable (fun (A : ℕ → TwoStage Unit (NestedRequest M n) (NestedChallenge K M n) Bool σ) (sec : ℕ) => ProbComp.eval ((E sec).nestedExperiment (sampleKey sec) (valid sec) n (A sec) false)) (fun (A : ℕ → TwoStage Unit (NestedRequest M n) (NestedChallenge K M n) Bool σ) (sec : ℕ) => ProbComp.eval ((E sec).nestedExperiment (sampleKey sec) (valid sec) n (A sec) true)) (TwoStage.IsPPT Turing.MultiTapeTM.encUnit (encNestedRequest encM n) (encNestedChallenge encK encM n) Turing.MultiTapeTM.encBool encσ)

Corrected form of Theorem 2.12 ([BS23], §2.4, p. 37), with the admissibility hypothesis PreservesValid that the book does not state and without which the theorem fails (tagCipher_no_wrapper in the tests): for every constant n : ℕ, if sampleKey and encrypt are strict PPT, valid is computable in polynomial time (each uniformly in the security parameter), E preserves admissibility (PreservesValid) at every security parameter, and E is one-time semantically secure (Game.Indistinguishable against uniform strict PPT TwoStage adversaries for every state type and encoding), then E is semantically secure for n-way nesting with all keys but one revealed.