Documentation

CslibFrontier.Crypto.Primitives.PRF.RandomOracleModel

Pseudorandom functions in the random-oracle model #

Attack Game 8.4 of [BS23], Section 8.10.2 (printed p. 329), for finite types. The adversary is one adaptive program with private coins and two interfaces (ROSpec): the query Sum.inl x asks for the keyed function F at x : X and returns a value in Y, and the query Sum.inr m asks for the random oracle at m : M and returns a value in T. Both experiments first sample the whole oracle table O : M → T uniformly and answer every oracle query m with O m. Experiment 0 (roRealExperiment F A) then samples one uniform key and answers every F-query x with F O key x; Experiment 1 (roIdealExperiment A) samples one uniform function f : X → Y and answers with f x. The advantage roAdvantage F A is their distinguishing advantage. A keyed function F : (M → T) → Key → X → Y of the oracle table is the book's F^O. When F ignores the table and the adversary never queries the oracle, this is Attack Game 4.2 (roAdvantage_const_simulate).

Theorem 8.9 is about the key-prepending function F_pre(k, x) = H (k ‖ x), here prependKey encode O key x = O (encode key x) for a pairing encode : Key → X → M. If encode is injective in the pair of its arguments, an adversary that makes at most Q random-oracle queries on every path has advantage at most Q / |Key| (roAdvantage_prependKey_le). Nothing is assumed about its F-queries, its private coins or its running time, as in the book's remark that the theorem is unconditional. keyAppend κ L is the book's k ‖ x for a κ-bit key and a word of length at most L, with bound Q / 2 ^ κ (roAdvantage_prependKey_keyAppend_le). Over a security parameter, if 1 / |Key n| is negligible (for bit strings: keys of at least n bits), every family of adversaries with polynomially many random-oracle queries has negligible advantage (negligible_roAdvantage_prependKey, negligible_roAdvantage_prependKey_keyAppend).

The proof is not the book's, which uses lazily sampled "faithful" and "forgetful gnome" games (p. 330) and assumes that the adversary never repeats an F-query. For a fixed key the oracle O has the law of Function.extend (encode key) f O for an independent uniform table f : X → T (Cslib.Probability.PMF.uniformOfFintype_bind_bind_extend), and this oracle composed with encode key is f. Experiment 0 therefore has the law of a game that answers F-queries with f and oracle queries with Function.extend (encode key) f O, while Experiment 1 answers oracle queries with O. For fixed f and O the two challengers differ only at an oracle query encode key x, so they are identical until the set of keys that the oracle queries name contains the key (ProbOracleComp.IdenticalUntilBad). In Experiment 1 that set does not depend on the key and has at most Q members on every path, so a uniform key lies in it with probability at most Q / |Key|.

Differences from the book:

ROSpec, ROAdversary, roRealExperiment, roIdealExperiment, roAdvantage, prependKey and keyAppend are this library's names. Cslib.Crypto.Protocols.FujisakiOkamoto has its own ROSpec and ROAdversary.

Main definitions #

Main results #

References #

Attack Game 8.4 #

@[reducible, inline]
abbrev Cslib.Crypto.PRF.ROSpec (X Y M T : Type) :

The calls of a PRF adversary in the random-oracle model: an F-query names a point of X and returns a value in Y; an O-query names a point of M and returns a value in T.

@[reducible, inline]

An adaptive test with private coins and oracle access to a function X → Y and to the random oracle M → T.

@[reducible, inline]

The adversary makes at most Q random-oracle queries on every path, whatever its private samples and the replies. Its F-queries and its private samples are free.

noncomputable def Cslib.Crypto.PRF.roRealExperiment {Key X Y M T : Type} [Fintype M] [DecidableEq M] [Fintype T] [Nonempty T] [Fintype Key] [Nonempty Key] (F : (M → T) → Key → X → Y) (A : ROAdversary X Y M T) :

Experiment 0 of Attack Game 8.4: sample the random oracle O and one uniform key, answer every F-query x with F O key x and every O-query m with O m.

noncomputable def Cslib.Crypto.PRF.roIdealExperiment {X Y M T : Type} [Fintype M] [DecidableEq M] [Fintype T] [Nonempty T] [Fintype X] [DecidableEq X] [Fintype Y] [Nonempty Y] (A : ROAdversary X Y M T) :

Experiment 1 of Attack Game 8.4: sample the random oracle O and one uniform function f : X → Y, answer every F-query x with f x and every O-query m with O m.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.PRF.roAdvantage {Key X Y M T : Type} [Fintype M] [DecidableEq M] [Fintype T] [Nonempty T] [Fintype Key] [Nonempty Key] [Fintype X] [DecidableEq X] [Fintype Y] [Nonempty Y] (F : (M → T) → Key → X → Y) (A : ROAdversary X Y M T) :

The PRF distinguishing advantage of A against F in the random-oracle model ([BS23], Attack Game 8.4).

A budget on all queries is a budget on the random-oracle queries.

def Cslib.Crypto.PRF.prependKey {Key X M T : Type} (encode : Key → X → M) (H : M → T) (key : Key) (x : X) :
T

The key-prepending function F_pre(k, x) = H (k ‖ x) of a hash function H ([BS23], Section 8.10.2), for a pairing encode of keys and inputs into hash inputs.

@[simp]
theorem Cslib.Crypto.PRF.prependKey_apply {Key X M T : Type} (encode : Key → X → M) (H : M → T) (key : Key) (x : X) :
prependKey encode H key x = H (encode key x)

prependKey encode H evaluates H at the pairing of the key and the input.

The challengers of the proof #

Theorem 8.9 #

theorem Cslib.Crypto.PRF.eval_roRealExperiment {Key X Y M T : Type} [Fintype M] [DecidableEq M] [Fintype T] [Nonempty T] [Fintype Key] [Nonempty Key] (F : (M → T) → Key → X → Y) (A : ROAdversary X Y M T) :
(roRealExperiment F A).eval = (Probability.PMF.uniformOfFintype (M → T)).bind fun (O : M → T) => (Probability.PMF.uniformOfFintype Key).bind fun (key : Key) => OracleComp.interpret (OracleComp.sumHandler ProbComp.unifOracle (OracleComp.sumHandler (fun (x : X) => PMF.pure (F O key x)) fun (m : M) => PMF.pure (O m))) A

The law of roRealExperiment: a uniform oracle table and a uniform key, then the adversary interpreted at the PMF level.

theorem Cslib.Crypto.PRF.eval_roIdealExperiment {X Y M T : Type} [Fintype M] [DecidableEq M] [Fintype T] [Nonempty T] [Fintype X] [DecidableEq X] [Fintype Y] [Nonempty Y] (A : ROAdversary X Y M T) :
(roIdealExperiment A).eval = (Probability.PMF.uniformOfFintype (M → T)).bind fun (O : M → T) => (Probability.PMF.uniformOfFintype (X → Y)).bind fun (f : X → Y) => OracleComp.interpret (OracleComp.sumHandler ProbComp.unifOracle (OracleComp.sumHandler (fun (x : X) => PMF.pure (f x)) fun (m : M) => PMF.pure (O m))) A

The law of roIdealExperiment: a uniform oracle table and a uniform function, then the adversary interpreted at the PMF level.

theorem Cslib.Crypto.PRF.roAdvantage_const_simulate {Key X Y M T : Type} [Fintype M] [DecidableEq M] [Fintype T] [Nonempty T] [Fintype Key] [Nonempty Key] [Fintype X] [DecidableEq X] [Fintype Y] [Nonempty Y] (F : Key → X → Y) (A : Adversary X Y) :
roAdvantage (fun (x : M → T) => F) (ProbOracleComp.simulate (fun (x : X) => ProbOracleComp.query (Sum.inl x)) A) = advantage F A

A keyed function that ignores the oracle, against an adversary that does not query it: Attack Game 8.4 is then Attack Game 4.2 ([BS23]).

theorem Cslib.Crypto.PRF.roAdvantage_prependKey_le {Key X M T : Type} [Fintype M] [DecidableEq M] [Fintype T] [Nonempty T] [Fintype Key] [Nonempty Key] [Fintype X] [DecidableEq X] {encode : Key → X → M} (hencode : Function.Injective2 encode) {A : ROAdversary X T M T} {Q : ℕ} (hQ : A.IsOracleQueryBounded Q) :
↑(roAdvantage (prependKey encode) A) ≤ ↑Q / ↑(Fintype.card Key)

Theorem 8.9, concrete bound ([BS23], Section 8.10.2, p. 329). If encode is injective in the pair of its arguments, an adversary that makes at most Q random-oracle queries distinguishes F_pre(k, x) = O (encode k x) from a random function with advantage at most Q / |Key|. Nothing is assumed about its F-queries, its private coins or its running time.

theorem Cslib.Crypto.PRF.negligible_roAdvantage_prependKey {Key X M T : ℕ → Type} [(n : ℕ) → Fintype (M n)] [(n : ℕ) → DecidableEq (M n)] [(n : ℕ) → Fintype (T n)] [∀ (n : ℕ), Nonempty (T n)] [(n : ℕ) → Fintype (Key n)] [∀ (n : ℕ), Nonempty (Key n)] [(n : ℕ) → Fintype (X n)] [(n : ℕ) → DecidableEq (X n)] {encode : (n : ℕ) → Key n → X n → M n} (hencode : ∀ (n : ℕ), Function.Injective2 (encode n)) (hKey : Negligible fun (n : ℕ) => 1 / ↑(Fintype.card (Key n))) {A : (n : ℕ) → ROAdversary (X n) (T n) (M n) (T n)} {Q : ℕ → ℕ} (hQ : PolynomiallyBounded Q) (hA : ∀ (n : ℕ), (A n).IsOracleQueryBounded (Q n)) :
Negligible fun (n : ℕ) => roAdvantage (prependKey (encode n)) (A n)

Theorem 8.9 ([BS23], Section 8.10.2, p. 329). If 1 / |Key n| is negligible, the key-prepending function is a secure PRF in the random-oracle model in the following sense: every family of adversaries whose number of random-oracle queries is polynomially bounded has negligible advantage. The family need not be efficient; Definition 8.5 asks this only of efficient adversaries.

The book's bit strings #

def Cslib.Crypto.PRF.keyAppend (κ L : ℕ) (k : BitString κ) (x : ↥(BitString.shortWords L)) :

The book's k ‖ x ([BS23], Section 8.10.2): a κ-bit key followed by a word of length at most L.

@[simp]
theorem Cslib.Crypto.PRF.coe_keyAppend (κ L : ℕ) (k : BitString κ) (x : ↥(BitString.shortWords L)) :
↑(keyAppend κ L k x) = List.ofFn k ++ ↑x

The word keyAppend κ L k x is the bits of k followed by the word x.

A key of fixed length followed by a word determines both.

theorem Cslib.Crypto.PRF.roAdvantage_prependKey_keyAppend_le {T : Type} (κ L : ℕ) [Fintype T] [Nonempty T] {A : ROAdversary (↥(BitString.shortWords L)) T (↥(BitString.shortWords (κ + L))) T} {Q : ℕ} (hQ : A.IsOracleQueryBounded Q) :
↑(roAdvantage (prependKey (keyAppend κ L)) A) ≤ ↑Q / 2 ^ κ

Theorem 8.9 ([BS23], Section 8.10.2, p. 329) for K = {0,1}^κ, X = {0,1}^{≤L} and M = {0,1}^{≤κ+L}: an adversary that makes at most Q random-oracle queries has advantage at most Q / 2 ^ κ.

theorem Cslib.Crypto.PRF.negligible_roAdvantage_prependKey_keyAppend {κ : ℕ → ℕ} (hκ : ∀ (n : ℕ), n ≤ κ n) (L : ℕ → ℕ) {T : ℕ → Type} [(n : ℕ) → Fintype (T n)] [∀ (n : ℕ), Nonempty (T n)] {A : (n : ℕ) → ROAdversary (↥(BitString.shortWords (L n))) (T n) (↥(BitString.shortWords (κ n + L n))) (T n)} {Q : ℕ → ℕ} (hQ : PolynomiallyBounded Q) (hA : ∀ (n : ℕ), (A n).IsOracleQueryBounded (Q n)) :
Negligible fun (n : ℕ) => roAdvantage (prependKey (keyAppend (κ n) (L n))) (A n)

Theorem 8.9 ([BS23], Section 8.10.2, p. 329) for bit strings over a security parameter: with keys of at least n bits at security parameter n, every family of adversaries whose number of random-oracle queries is polynomially bounded has negligible advantage.