Documentation

CslibFrontier.Crypto.Computational.DictionarySearch

Dictionary searches against a hash oracle #

Offline dictionary attacks (18.1)–(18.3) of [BS23], Section 18.3.1.2–18.3.1.3 (pp. 721–723), together with the salted and secret-salt forms of Section 18.4.1–18.4.2 (pp. 724–726), modeled as programs with oracle access to H : X → Y.

dictionarySearch input accept D queries the oracle at input w for each w in D in list order and stops at the first candidate whose reply satisfies accept. dictionaryPreimageSearch specializes accept to equality with vk ((18.1)). dictionaryTable builds the preprocessing table of (H (input w), w) pairs ((18.2)), and dictionaryBatchSearch runs one table lookup per entry of F ((18.3)). dictionaryInverter turns dictionaryPreimageSearch into a PMF inverter for inversionExperiment.

This formalization differs from the book's presentation as follows:

  1. List order. D is a List P searched in list order rather than an unordered set; a Finset dictionary is handled via Finset.toList.
  2. Exact oracle-query counts. H is an oracle and cost is OracleComp.IsQueryBounded, giving exact bounds D.length and F.length * D.length instead of O(|D|) and O(|D| × |F|).
  3. Failure output. Searches return Option P (none when no candidate passes), where (18.1) prints no output and (18.2) prints "fail".
  4. Parameterized input and test. dictionarySearch takes input : P → X and accept : Y → Bool; (18.1) is input := id and accept := fun y => decide (y = vk), while input := (·, salt) gives the salted search.
  5. Hash-keyed table. dictionaryTable stores (H (input w), w) rather than (w, H(w)) and is read by List.lookup. Lookups, comparisons, and accept are uncounted; no constant-time lookup is claimed.
  6. Batch bound. (18.3)'s "attack time O(|F|)" appears only as D.length oracle calls regardless of F; O(|D| + |F|) vs O(|D| × |F|) appears as two upper bounds, without claiming the second bound is attained for every input.
  7. Weak-secret distribution. le_inversionExperiment_dictionaryInverter formalizes choosing a weak secret from an arbitrary distribution μ over a small dictionary; the resulting probability lower bound μ.toOuterMeasure {pw | pw ∈ D} ≤ ... is this library's (the book states no probability, only the pointwise claim on p. 722 that if pw ∈ D the adversary obtains pw or some pw' with H(pw) = H(pw') in time O(|D|)).
  8. Total PMF inverter. dictionaryInverter returns default when the search fails; [Inhabited P] is needed only there.
  9. Recovering pw itself. Returning pw (rather than some w ∈ D with H (input w) = vk) is proved only under Set.InjOn of w ↦ H (input w) on D; "in all likelihood" is not claimed.
  10. Salts and peppers. Salt and pepper spaces are parameters of the test instances; the book's factor 4096 is peppers.length.
  11. Universe Type. All types live in Type (0), as OracleComp requires.

No machine-time bound is certified here: comparisons, accept, and List.lookup are free, and no polynomial-time certificate is stated (D is a parameter, and efficiency means "D.length oracle evaluations").

Main definitions #

Main results #

References #

def Cslib.Crypto.dictionarySearch {P X Y : Type} (input : P → X) (accept : Y → Bool) (D : List P) :
OracleComp (fun (x : X) => Y) (Option P)

The search (18.1) with any derived input and any test of the reply: for each candidate w of D in order, ask the oracle at input w and stop at the first w whose reply passes accept.

theorem Cslib.Crypto.evalPure_dictionarySearch {P X Y : Type} (H : X → Y) (input : P → X) (accept : Y → Bool) (D : List P) :
OracleComp.evalPure H (dictionarySearch input accept D) = List.find? (fun (w : P) => accept (H (input w))) D

Against H, the search returns the first candidate that passes.

theorem Cslib.Crypto.isQueryBounded_dictionarySearch {P X Y : Type} (input : P → X) (accept : Y → Bool) (D : List P) :

Cost of (18.1). At most one oracle call per candidate, on every path.

theorem Cslib.Crypto.queriesSatisfy_dictionarySearch {P X Y : Type} (input : P → X) (accept : Y → Bool) (D : List P) :
OracleComp.QueriesSatisfy (fun (x : X) => ∃ w ∈ D, input w = x) (dictionarySearch input accept D)

The search asks the oracle only at inputs of candidates.

theorem Cslib.Crypto.dictionarySearch_sound {P X Y : Type} {H : X → Y} {input : P → X} {accept : Y → Bool} {D : List P} {w : P} (h : OracleComp.evalPure H (dictionarySearch input accept D) = some w) :
w ∈ D ∧ accept (H (input w)) = true

An output is a candidate of the dictionary that passes the test.

theorem Cslib.Crypto.evalPure_dictionarySearch_eq_none_iff {P X Y : Type} {H : X → Y} {input : P → X} {accept : Y → Bool} {D : List P} :
OracleComp.evalPure H (dictionarySearch input accept D) = none ↔ ∀ w ∈ D, accept (H (input w)) = false

The search fails exactly when no candidate passes.

theorem Cslib.Crypto.exists_evalPure_dictionarySearch_of_mem {P X Y : Type} {H : X → Y} {input : P → X} {accept : Y → Bool} {D : List P} {pw : P} (hmem : pw ∈ D) (hpw : accept (H (input pw)) = true) :
∃ w ∈ D, OracleComp.evalPure H (dictionarySearch input accept D) = some w ∧ accept (H (input w)) = true

Success of (18.1). If the secret is in the dictionary and passes the test, the search returns a candidate that passes: the secret, or another candidate the test cannot tell from it.

theorem Cslib.Crypto.evalPure_dictionarySearch_of_unique {P X Y : Type} {H : X → Y} {input : P → X} {accept : Y → Bool} {D : List P} {pw : P} (hmem : pw ∈ D) (hpw : accept (H (input pw)) = true) (huniq : ∀ w ∈ D, accept (H (input w)) = true → w = pw) :

When only the secret passes, the search returns the secret.

theorem Cslib.Crypto.dictionarySearch_cons {P X Y : Type} (input : P → X) (accept : Y → Bool) (w : P) (ws : List P) :
dictionarySearch input accept (w :: ws) = do let y ← OracleComp.query (input w) if accept y = true then pure (some w) else dictionarySearch input accept ws

One step of the search.

theorem Cslib.Crypto.not_isQueryBounded_dictionarySearch {P X Y : Type} {input : P → X} {accept : Y → Bool} {D : List P} {y₀ : Y} (hy : accept y₀ = false) {n : ℕ} (hn : n < D.length) :

The count is sharp. If accept rejects some reply, no budget below D.length bounds the search.

def Cslib.Crypto.dictionaryTable {P X Y : Type} (input : P → X) (D : List P) :
OracleComp (fun (x : X) => Y) (List (Y × P))

Preprocessing phase of (18.2). The list of pairs (H (input w), w) for w in D, in the order of D and keyed by the hash, so that the attack phase is List.lookup.

theorem Cslib.Crypto.evalPure_dictionaryTable {P X Y : Type} (H : X → Y) (input : P → X) (D : List P) :
OracleComp.evalPure H (dictionaryTable input D) = List.map (fun (w : P) => (H (input w), w)) D

Against H, the table lists each candidate with its hash.

theorem Cslib.Crypto.isQueryBounded_dictionaryTable {P X Y : Type} (input : P → X) (D : List P) :

Cost of the preprocessing phase. One oracle call per candidate.

@[reducible, inline]
abbrev Cslib.Crypto.dictionaryPreimageSearch {P X Y : Type} [DecidableEq Y] (input : P → X) (vk : Y) (D : List P) :
OracleComp (fun (x : X) => Y) (Option P)

The search (18.1): the first w in D with H (input w) = vk. With input := id this is the book's procedure; input := (·, salt) is its salted form.

theorem Cslib.Crypto.exists_evalPure_dictionaryPreimageSearch_of_mem {P X Y : Type} [DecidableEq Y] (H : X → Y) (input : P → X) (D : List P) {pw : P} (hmem : pw ∈ D) :
∃ w ∈ D, OracleComp.evalPure H (dictionaryPreimageSearch input (H (input pw)) D) = some w ∧ H (input w) = H (input pw)

The book's claim after (18.1): if pw ∈ D, the search on vk = H(pw) returns pw or some pw' with H(pw') = H(pw).

theorem Cslib.Crypto.evalPure_dictionaryPreimageSearch_of_injOn {P X Y : Type} [DecidableEq Y] (H : X → Y) (input : P → X) (D : List P) {pw : P} (hmem : pw ∈ D) (hinj : Set.InjOn (fun (w : P) => H (input w)) {w : P | w ∈ D}) :
OracleComp.evalPure H (dictionaryPreimageSearch input (H (input pw)) D) = some pw

Without collisions on the dictionary the search returns pw.

theorem Cslib.Crypto.lookup_evalPure_dictionaryTable {P X Y : Type} [DecidableEq Y] (H : X → Y) (input : P → X) (D : List P) (vk : Y) :

Attack phase of (18.2). Looking vk up in the table of D returns what the search (18.1) returns. The lookup is core's List.lookup, a function of the table and vk alone: it has no access to the oracle.

def Cslib.Crypto.dictionaryBatchSearch {P X Y : Type} [DecidableEq Y] (input : P → X) (D : List P) (F : List Y) :
OracleComp (fun (x : X) => Y) (List (Option P))

The batch search (18.3). One table, then one lookup for each entry of F.

theorem Cslib.Crypto.evalPure_dictionaryBatchSearch {P X Y : Type} [DecidableEq Y] (H : X → Y) (input : P → X) (D : List P) (F : List Y) :

The batch search answers each entry as a separate search (18.1) would.

theorem Cslib.Crypto.isQueryBounded_dictionaryBatchSearch {P X Y : Type} [DecidableEq Y] (input : P → X) (D : List P) (F : List Y) :

Cost of (18.3). D.length oracle calls, whatever the number of entries.

theorem Cslib.Crypto.isQueryBounded_mapM_dictionaryPreimageSearch {P X Y : Type} [DecidableEq Y] (D : List P) {E : Type} (inputOf : E → P → X) (vkOf : E → Y) (F : List E) :
(List.mapM (fun (e : E) => dictionaryPreimageSearch (inputOf e) (vkOf e) D) F).IsQueryBounded (F.length * D.length)

Cost of separate searches. Running (18.1) once per entry, each entry e with its own derived input (for example its own salt), costs at most F.length * D.length calls.

noncomputable def Cslib.Crypto.dictionaryInverter {P X Y : Type} [DecidableEq Y] [Inhabited P] (H : X → Y) (input : P → X) (D : List P) (vk : Y) :
PMF P

The search as an inverter for pw ↦ H (input pw): it returns default when the search fails.

theorem Cslib.Crypto.dictionaryInverter_apply {P X Y : Type} [DecidableEq Y] [Inhabited P] (H : X → Y) (input : P → X) (D : List P) (vk : Y) :

The inverter is the search (18.1) evaluated against H: the program that isQueryBounded_dictionarySearch bounds.

theorem Cslib.Crypto.le_inversionExperiment_dictionaryInverter {P X Y : Type} [DecidableEq Y] [Inhabited P] (μ : PMF P) (H : X → Y) (input : P → X) (D : List P) :
μ.toOuterMeasure {pw : P | pw ∈ D} ≤ (inversionExperiment μ (fun (pw : P) => H (input pw)) (dictionaryInverter H input D)) true

Weak secrets. For any distribution μ of the secret, the search wins the inversion experiment for pw ↦ H (input pw) at least as often as the secret lies in the dictionary.

theorem Cslib.Crypto.dictionarySearch_inverts {P X Y : Type} [DecidableEq Y] [Inhabited P] (μ : PMF P) (H : X → Y) (input : P → X) (D : List P) :
(∀ (vk : Y), (dictionaryPreimageSearch input vk D).IsQueryBounded D.length) ∧ μ.toOuterMeasure {pw : P | pw ∈ D} ≤ (inversionExperiment μ (fun (pw : P) => H (input pw)) (dictionaryInverter H input D)) true

The dictionary search against a weak secret. [BS23], Section 18.3.1.2 (p. 722) states that if pw ∈ D, the adversary obtains pw or some pw' with H(pw) = H(pw') in time O(|D|). Here, for every H, every derived input, and a secret drawn from an arbitrary distribution μ on P, the search (18.1) over D makes at most D.length evaluations of H on every challenge and wins inversionExperiment for pw ↦ H (input pw) with probability at least μ.toOuterMeasure {pw | pw ∈ D} (this probability form is original to this library, not in the book).