Documentation

CslibFrontier.Crypto.Computational.PseudorandomFunction

Uniform computational pseudorandom functions #

A keyed family has n-bit keys, and its valid queries and answers have inLen n and outLen n bits. An adversary receives the unary security parameter, independent private randomness and adaptive access to one word channel. The real game samples one key; the ideal game samples one whole function and reuses it across calls. Both games invoke the adversary with empty auxiliary input and reject malformed queries with the empty word. The table is a semantic specification; prfIdealGame_eq_lazy samples it lazily, and RandomOracle certifies a lazy realization of the length-preserving game for oracle-PPT adversaries.

The keyed evaluator has a uniform deterministic TM certificate on the encoded key/query pair. Admissible adversaries satisfy IsOraclePPT, charging ordinary computation and request writing, with one machine and polynomial for all parameters and auxiliary inputs.

PseudorandomFunction is the length-preserving case inLen = outLen = id, in which keys, valid queries and answers all have n bits.

Main definitions #

Main results #

References #

Adapted from Crypto/Computational/PseudorandomFunction.lean on the cslib crypto branch at 5ff69ca93402e7c947208dc56396d6d86203ccd8, using the shared typed interpreter and word channel.

@[reducible, inline]

An adaptive test with a unary parameter, an auxiliary word and one external word channel.

def Cslib.Crypto.prfOracle (family : List Bool → List Bool → List Bool) (n : ℕ) (key query : List Bool) :

A keyed oracle rejects queries outside the declared domain.

Evaluating prfOracle family (n a) (key a) (query a) is computable in plain polynomial time whenever family, the unary domain width n, key, and query are computable in plain polynomial time.

def Cslib.Crypto.randomFunctionOracle (n : ℕ) {w : ℕ} (table : BitString n → BitString w) (query : List Bool) :

Read a fixed random table on n-bit inputs, rejecting malformed words before interpreting their bits.

theorem Cslib.Crypto.randomFunctionOracle_keyed {family : List Bool → List Bool → List Bool} {keyWidth width outWidth : ℕ} (hlength : ∀ (key query : List Bool), key.length = keyWidth → query.length = width → (family key query).length = outWidth) (key : BitString keyWidth) (query : List Bool) :
randomFunctionOracle width (fun (block : BitString width) => BitString.ofList outWidth (family (List.ofFn key) (List.ofFn block))) query = prfOracle family width (List.ofFn key) query

The finite table of a keyed family presents the keyed word oracle when the family has the declared reply width on valid inputs. Both presentations reject malformed queries.

Adapt a valid word to the finite domain. Malformed words make no external call; this is (OracleCodec.bitStrings n w).wordOracle ProbOracleComp.query on (), query.

theorem Cslib.Crypto.wordOracle_bitStrings {m : Type → Type u_1} [Monad m] [LawfulMonad m] (n w : ℕ) (table : BitString n → BitString w) :
((OracleCodec.bitStrings n w).wordOracle fun (bits : BitString n) => pure (table bits)) = fun (request : Unit × List Bool) => pure (randomFunctionOracle n table request.2)

OracleCodec.bitStrings n w presents randomFunctionOracle n table on the unit word channel: an n-bit request is answered by the bits of table and any other request by [].

noncomputable def Cslib.Crypto.lazyRandomFunctionOracle (n w : ℕ) (query : List Bool) :

A semantic random-function cache from n-bit to w-bit strings, retaining only the finite-domain answers already used.

OracleCodec.bitStrings n w lifts RandomOracle.answer to lazyRandomFunctionOracle n w on the unit word channel.

noncomputable def Cslib.Crypto.prfRealGame (inLen : ℕ → ℕ) (family : List Bool → List Bool → List Bool) (adversary : OracleDistinguisher) (n : ℕ) :

The real experiment of a keyed family with inLen n-bit inputs: sample one n-bit key and answer every query of inLen n bits with the family under that key, and any other query with the empty word.

noncomputable def Cslib.Crypto.prfIdealGame (inLen outLen : ℕ → ℕ) (adversary : OracleDistinguisher) (n : ℕ) :

The ideal experiment with inLen n-bit inputs and outLen n-bit outputs: sample one uniform function between them, independently of the adversary's private samples, and answer every query of inLen n bits with its value, and any other query with the empty word.

theorem Cslib.Crypto.prfIdealGame_eq_lazy (inLen outLen : ℕ → ℕ) (adversary : OracleDistinguisher) (n : ℕ) :
(prfIdealGame inLen outLen adversary n).eval = PMF.map Prod.fst ((OracleComp.interpret (OracleComp.sumHandler (fun (k : ℕ) => StateT.lift (ProbComp.unifOracle k)) fun (request : Unit × List Bool) => lazyRandomFunctionOracle (inLen n) (outLen n) request.2) (adversary n [])).run fun (x : BitString (inLen n)) => none)

The ideal game admits consistent lazy answers to adaptive queries, with private randomness independent of the table and the same rejection convention for malformed inputs.

structure Cslib.Crypto.PseudorandomFunctionOver (inLen outLen : ℕ → ℕ) (family : List Bool → List Bool → List Bool) :

A keyed family with n-bit keys, inLen n-bit inputs and outLen n-bit outputs, evaluated in plain polynomial time and secure against every uniform adaptive oracle test: [BS23], Attack Game 4.2 and Definition 4.2, pp. 132–133, for a PRF defined over (K, X, Y), read asymptotically with K, X and Y the words of n, inLen n and outLen n bits. A query of another length is answered by the empty word in both games, and deterministic polynomial-time evaluation is part of the notion. PseudorandomFunction is the case inLen = outLen = id.

The lengths are meant to be polynomially bounded in n, as in the book's asymptotic definition (Definition 4.4, Section 4.4.5, pp. 139–141), whose X and Y are families of spaces with strings of polynomially bounded length (Definition 2.9, Section 2.3.2, p. 30). The structure does not require this, and without it the notion degenerates:

  • if inLen n grows faster than every polynomial (for example 2 ^ n), each admitted test eventually writes only queries shorter than inLen n (IsOraclePPT.query_bounds), so both games answer all of them with the empty word and secure holds for every family: every family meeting polyTime and length_eq qualifies;
  • if outLen n is not bounded by a polynomial in n + inLen n, polyTime and length_eq cannot both hold, because a polynomial-time machine writes polynomially many bits (ComputableInPolyTime.polyBounded_length), and no family qualifies.

The theorems that use the notion take the bound from their own hypotheses: a BlockCipher's blockLen is computable in polynomial time from unary n (BlockCipher.blockLen_polyTime); indistinguishable_prgFromPRF and PseudorandomFunctionOver.toPRG assume the query points computable in polynomial time from unary n, and the former also outLen; and MLKEM.indCPA_kpkePRF_of_decisionModuleLWEWith assumes parameters computable in polynomial time, with n, k, η₁ and η₂ encoded in unary.

Evaluate the family at the all-zero key and a valid all-zero query to compute the output width in unary.

@[reducible, inline]

A length-preserving pseudorandom function: PseudorandomFunctionOver id id, whose keys, valid queries and answers all have n bits ([BS23], Attack Game 4.2 and Definition 4.2, pp. 132–133, with K, X and Y all the words of n bits). Its fields are those of PseudorandomFunctionOver.