Documentation

CslibFrontier.Crypto.Computational.PseudorandomPermutation

Uniform computational block ciphers and pseudorandom permutations #

A BlockCipher ([BS23], Section 4.1, interpreted asymptotically as in Sections 2.3 and 4.1.5) has polynomial-time key- and block-length schedules keyLen, blockLen : ℕ → ℕ and deterministic polynomial-time algorithms encrypt n key block and decrypt n key block that receive the unary security parameter n. On every keyLen n-bit key they preserve blockLen n-bit blocks and invert one another, so each valid key induces a permutation BlockCipher.permEquiv of BitString (blockLen n).

There are two adaptive security notions against uniform IsOraclePPT encBool distinguishers:

  1. Pseudorandom permutation (BlockCipher.PRP, chosen-plaintext): an OracleDistinguisher queries encryption on blockLen n-bit words (other words are answered with []) and cannot tell a uniformly keyed cipher (BlockCipher.prpRealGame) from a uniformly random permutation of BitString (blockLen n) (prpIdealGame); this is [BS23], Attack Game 4.1 and Definition 4.1.
  2. Strong pseudorandom permutation (BlockCipher.StrongPRP, chosen-ciphertext): a StrongPRPDistinguisher asks (false, x) for encryption and (true, y) for decryption and cannot tell BlockCipher.strongPRPRealGame from strongPRPIdealGame; this is the strongly secure block cipher sketched in [BS23], Section 4.1.3, and left as Exercise 4.9(a).

The ideal-experiment PRP/PRF switching lemma for word-oracle adversaries (advantage_prpIdealGame_prfIdealGame_le) is the finite switching lemma PRP.advantage_idealExperiment_prfIdealExperiment_le on blockLen n-bit blocks, applied to the adversary that reads valid words as blocks (OracleCodec.bitString). Consequently, when ((2 : ℝ≥0) ^ E.blockLen n)⁻¹ is negligible, every block cipher E, with any key length, is a PRP iff it is a secure PRF: E.prpRealGame is indistinguishable from prfIdealGame E.blockLen E.blockLen (BlockCipher.prp_iff_indistinguishable_prpRealGame_prfIdealGame). When moreover E.keyLen = id, the PRF side is the library notion PseudorandomFunctionOver E.blockLen E.blockLen (BlockCipher.prp_iff_pseudorandomFunctionOver_of_keyLen_eq_id). Every StrongPRP is also a PRP (BlockCipher.StrongPRP.prp).

Main definitions #

Main results #

References #

@[reducible, inline]

An adaptive test with a unary parameter, an auxiliary word and a bidirectional word channel: (false, x) asks for encryption of x and (true, y) asks for decryption of y.

A uniform deterministic block cipher ([BS23], Section 4.1, interpreted asymptotically as in Section 4.1.5). Both algorithms receive the unary security parameter n. Lengths and inversion are required only for keys of length keyLen n and blocks of length blockLen n.

Read a permutation of m-bit blocks as a table, answering other words with [].

Read a permutation of m-bit blocks in both directions (false for π, true for π.symm), answering other words with [].

noncomputable def Cslib.Crypto.prpIdealGame (blockLen : ℕ → ℕ) (adversary : OracleDistinguisher) (n : ℕ) :

The ideal chosen-plaintext experiment: a uniform permutation of blockLen n-bit blocks, sampled independently of the adversary's private coins ([BS23], Attack Game 4.1, Experiment 1).

noncomputable def Cslib.Crypto.strongPRPIdealGame (blockLen : ℕ → ℕ) (adversary : StrongPRPDistinguisher) (n : ℕ) :

The ideal chosen-ciphertext experiment: one uniform permutation answers both forward and inverse queries ([BS23], Section 4.1.3).

The key length of an efficiently computed parameter is efficiently computable.

The block length of an efficiently computed parameter is efficiently computable.

Encryption of efficiently computed arguments is efficiently computable.

Decryption of efficiently computed arguments is efficiently computable.

The permutation of blockLen n-bit blocks induced by a valid key.

The encryption oracle, answering words of the wrong length with [].

The encryption/decryption oracle (false for encryption, true for decryption), answering words of the wrong length with [].

theorem Cslib.Crypto.BlockCipher.prpOracle_eq_randomPermOracle (E : BlockCipher) {n : ℕ} {key : List Bool} (hkey : key.length = E.keyLen n) (query : List Bool) :
E.prpOracle n key query = randomPermOracle (E.blockLen n) (E.permEquiv n key hkey) query

A valid key answers encryption queries as its induced permutation.

theorem Cslib.Crypto.BlockCipher.strongPRPOracle_eq_strongRandomPermOracle (E : BlockCipher) {n : ℕ} {key : List Bool} (hkey : key.length = E.keyLen n) (request : Bool × List Bool) :
E.strongPRPOracle n key request = strongRandomPermOracle (E.blockLen n) (E.permEquiv n key hkey) request

A valid key answers encryption and decryption queries as its induced permutation.

The real chosen-plaintext experiment: one uniform keyLen n-bit key answers every encryption query ([BS23], Attack Game 4.1, Experiment 0).

The real chosen-ciphertext experiment: one uniform keyLen n-bit key answers forward queries with encryption and inverse queries with decryption ([BS23], Section 4.1.3).

Pseudorandom-permutation security against uniform oracle-PPT distinguishers ([BS23], Definition 4.1, interpreted asymptotically as in Section 4.1.5).

Strong pseudorandom-permutation security against uniform oracle-PPT distinguishers ([BS23], Section 4.1.3 and Exercise 4.9(a)).

Efficiency of the real experiments #

The real chosen-plaintext experiment is uniformly strict PPT for every oracle-PPT adversary.

The real chosen-ciphertext experiment is uniformly strict PPT for every oracle-PPT adversary.

Strong pseudorandom permutations are pseudorandom permutations #

Run a forward distinguisher against a bidirectional oracle, sending every query to the encryption channel false. Replies are cut at blockLen n bits, which changes nothing against the real or ideal permutation oracles and keeps the substitution polynomial on arbitrary replies.

Lifting an oracle-PPT forward distinguisher with a polynomial-time block length gives an oracle-PPT bidirectional distinguisher.

Against the real bidirectional experiment, the lifted distinguisher has the law of the forward distinguisher in the real chosen-plaintext experiment.

theorem Cslib.Crypto.eval_strongPRPIdealGame_liftForwardDistinguisher (blockLen : ℕ → ℕ) (adversary : OracleDistinguisher) (n : ℕ) :
(strongPRPIdealGame blockLen (liftForwardDistinguisher blockLen adversary) n).eval = (prpIdealGame blockLen adversary n).eval

Against the ideal bidirectional experiment, the lifted distinguisher has the law of the forward distinguisher in the ideal chosen-plaintext experiment.

Strong PRP security implies PRP security ([BS23], Section 4.1.3).

The PRP/PRF switching lemma #

theorem Cslib.Crypto.advantage_prpIdealGame_prfIdealGame_le (blockLen : ℕ → ℕ) (adversary : OracleDistinguisher) (n Q : ℕ) (hQ : ProbOracleComp.IsQueryBounded (adversary n []) Q) :
↑(Game.advantage (prpIdealGame blockLen adversary n).eval (prfIdealGame blockLen blockLen adversary n).eval) ≤ ↑(Q.choose 2) * (2 ^ blockLen n)⁻¹

Ideal-experiment PRP/PRF switching lemma ([BS23], Attack Game 4.3 and Theorem 4.6): a randomized word-oracle adversary making at most Q queries distinguishes a uniform permutation of blockLen n-bit blocks from a uniform random function on them with advantage at most Q.choose 2 / 2 ^ blockLen n. This is PRP.advantage_idealExperiment_prfIdealExperiment_le for the adversary reading valid words as blocks through OracleCodec.bitString (blockLen n).

theorem Cslib.Crypto.indistinguishable_prpIdealGame_prfIdealGame {blockLen : ℕ → ℕ} (hneg : Negligible fun (n : ℕ) => (2 ^ blockLen n)⁻¹) :
Game.Indistinguishable (fun (adversary : OracleDistinguisher) (n : ℕ) => (prpIdealGame blockLen adversary n).eval) (fun (adversary : OracleDistinguisher) (n : ℕ) => (prfIdealGame blockLen blockLen adversary n).eval) (Probability.IsOraclePPT Turing.MultiTapeTM.encBool)

Asymptotic PRP/PRF switching: when (2 ^ blockLen n)⁻¹ is negligible, no oracle-PPT distinguisher tells a uniform permutation from a uniform random function on blockLen n-bit blocks.

theorem Cslib.Crypto.eval_prpRealGame_eq_eval_prfRealGame {E : BlockCipher} (hkey : E.keyLen = id) (adversary : OracleDistinguisher) (n : ℕ) :
(E.prpRealGame adversary n).eval = (prfRealGame E.blockLen (fun (key query : List Bool) => E.encrypt key.length key query) adversary n).eval

When E.keyLen = id, E.prpRealGame agrees in distribution with the PRF real game of E.

A block cipher is a PRP iff it is a PRF ([BS23], Corollary 4.5): for every block cipher E, with any key length, if the block space is super-polynomial (Negligible fun n => ((2 : ℝ≥0) ^ E.blockLen n)⁻¹), then E.PRP holds iff no oracle-PPT distinguisher tells E under a uniform E.keyLen n-bit key from a uniform function on E.blockLen n-bit blocks. The right side is the security of E viewed as a PRF over (K, X, X) ([BS23], Attack Game 4.2 and Definition 4.2): E.prpRealGame is that PRF's real experiment, and prfIdealGame E.blockLen E.blockLen its random-function experiment. As in the source, both directions follow from the switching lemma (indistinguishable_prpIdealGame_prfIdealGame) by the triangle inequality.

The E.keyLen = id case of BlockCipher.prp_iff_indistinguishable_prpRealGame_prfIdealGame, with the PRF side stated in the library's PRF notion: E.PRP holds iff E.encrypt, with the security parameter read from the key length, is a PseudorandomFunctionOver E.blockLen E.blockLen. The restriction E.keyLen = id comes from PseudorandomFunctionOver, which draws n-bit keys; [BS23], Corollary 4.5, allows any key space.