Rainbow and Hellman tables for two-phase hash inversion #
Two-phase table precomputation and online inversion of a hash function h : P → Y from
[BS23], Section 18.7 (pp. 742–746; Fig. 18.13 on p. 744), modeled as oracle programs over
h and an endpoint lookup oracle.
Given column reduction functions g : ℕ → Y → P defining f_j(pw) := g j (h pw) on 0-indexed
columns j = 0, ..., τ - 1 (corresponding to the book's g_1, ..., g_τ):
rainbowChainPureandrainbowChainevaluatelenconsecutive columns starting atstart, specializing wheng = fun _ => g₀to Hellman's single-reduction iterate(g₀ ∘ h)^[len](p. 743; Fig. 18.13a, p. 744).rainbowPreprocess(AlgorithmA₀, pp. 743, 745) maps starting pointsstarts : List Pto endpoint-keyed pairs(z_i, pw_i)using at moststarts.length * τhash queries, so thatList.lookuprecovers every starting pointpw₀ ∈ startswhoseτ-step endpoint is shared by no earlier entry ofstarts(in particular whenever endpoints are distinct, matchingA₀'s duplicate-endpoint discarding on p. 745).rainbowAttack(rainbow AlgorithmA₁, p. 746; Fig. 18.13b, p. 744) runs overTableAttackSpec P Y—hash queries on the left (TableAttackSpec.hashCost) and table lookups on the right (TableAttackSpec.lookupCost)—searching stepsk = 0, ..., τ - 1(columnsτ - 1down to0, corresponding tofor i = τ downto 1) withList.findSomeM?, reconstructing a candidate preimage on each table hit and verifyingh(pw) = ybefore returningsome pw.hellmanAttack(Hellman's AlgorithmA₁and Fig. 18.13a, p. 744) initializesz ← g₀(y)and advancesz ← g₀(h(z))step-by-step acrossτiterations, reconstructing(g₀ ∘ h)^[τ - i](pw₀)and verifyingh(pw) = yon each hit.
Deterministic per-run request-trace counts (OracleComp.queriesWith) for both rainbowAttack and
hellmanAttack are proved in CslibFrontier.Crypto.Computational.RainbowTable.RunCost.
This formalization differs from the book's presentation as follows:
- 0-indexed columns. Reduction functions are indexed
0, ..., τ - 1rather than1, ..., τ; loop stepk ∈ {0, ..., τ - 1}tests columncol = τ - 1 - k(i = τ - kinfor i = τ downto 1). - Explicit starting list. Sampling
ℓrandom starting pointspw_1, ..., pw_ℓ ∈ Pis factored out into the parameterstarts : List P. - Endpoint-keyed table and abstract lookup oracle.
rainbowPreprocessstores(z_i, pw_i)rather than(pw_i, z_i)so thatList.lookupimplements table lookup directly, as inCslib.Crypto.dictionaryTable. Online inversion accesses the table through the right-hand oracleP → Option PofTableAttackSpec P Y, separating hash evaluations (TableAttackSpec.hashCost) from table lookups (TableAttackSpec.lookupCost) without claiming constant machine time forList.lookup. - Failure output. Inversion returns
Option P(nonefor "fail"). - Limitations. Soundness and two-phase inversion on covered chains are proved pointwise for
arbitrary
handg. Hellman's multiple-table remedy (msmall independent tables with distinct reduction functions searched separately byA₁, p. 745), the book's heuristic success-probability approximations modelinghandg_jas random functions (pp. 743–746), and machine-level running-time bounds are not formalized here (#5752).
Main definitions #
Cslib.Crypto.rainbowChainPure: pure evaluation oflencolumns starting atstart.Cslib.Crypto.rainbowChain: oracle program evaluatinglencolumns againsth : P → Y.Cslib.Crypto.rainbowPreprocess: preprocessing algorithmA₀producing(z_i, pw_i)pairs.Cslib.Crypto.TableAttackSpec: summed oracle interface of hash queries and table lookups.Cslib.Crypto.TableAttackSpec.hashCost,Cslib.Crypto.TableAttackSpec.lookupCost: per-call weights counting hash evaluations and table lookups.Cslib.Crypto.rainbowAttackStep,Cslib.Crypto.rainbowAttack: online rainbow-table inversion algorithmA₁(p. 746).Cslib.Crypto.hellmanLoop,Cslib.Crypto.hellmanAttack: Hellman's stateful online inversion algorithmA₁(p. 744).
Main results #
Cslib.Crypto.rainbowChainPure_add,Cslib.Crypto.rainbowChainPure_const: chain splitting and specialization of constant reduction functionsfun _ => g₀to(fun x => g₀ (h x))^[len].Cslib.Crypto.evalPure_rainbowChain,Cslib.Crypto.isQueryBounded_rainbowChain,Cslib.Crypto.length_queriesWith_rainbowChain: deterministic semantics andlenquery count ofrainbowChain.Cslib.Crypto.evalPure_rainbowPreprocess,Cslib.Crypto.isQueryBounded_rainbowPreprocess,Cslib.Crypto.lookup_evalPure_rainbowPreprocess,Cslib.Crypto.lookup_evalPure_rainbowPreprocess_eq_some_iff,Cslib.Crypto.lookup_evalPure_rainbowPreprocess_of_nodup: output list,starts.length * τquery bound, andList.lookupcharacterization ofrainbowPreprocess.Cslib.Crypto.rainbowAttack_sound,Cslib.Crypto.hellmanAttack_sound: every returned password satisfiesh pw = y(false alarms are rejected).Cslib.Crypto.exists_evalPure_rainbowAttack_of_lookup_eq_some,Cslib.Crypto.evalPure_rainbowAttack_of_injective,Cslib.Crypto.exists_evalPure_rainbowAttack_rainbowPreprocess,Cslib.Crypto.evalPure_rainbowAttack_rainbowPreprocess_of_injective: completeness ofrainbowAttackagainst an abstract lookup oracle and againstrainbowPreprocess, with exact preimage recovery whenhis injective.Cslib.Crypto.exists_evalPure_hellmanAttack_of_lookup_eq_some,Cslib.Crypto.evalPure_hellmanAttack_of_injective,Cslib.Crypto.exists_evalPure_hellmanAttack_rainbowPreprocess,Cslib.Crypto.evalPure_hellmanAttack_rainbowPreprocess_of_injective: completeness ofhellmanAttackagainst an abstract lookup oracle and againstrainbowPreprocess, with exact preimage recovery whenhis injective.Cslib.Crypto.isCostBounded_lookupCost_rainbowAttack,Cslib.Crypto.isCostBounded_hashCost_rainbowAttack: pathwise budgets ofτlookups andτ * τhash evaluations forrainbowAttack.Cslib.Crypto.isCostBounded_lookupCost_hellmanAttack,Cslib.Crypto.isCostBounded_hashCost_hellmanAttack: pathwise budgets ofτlookups andτ * (τ + 3) / 2hash evaluations forhellmanAttack.
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Section 18.7, pp. 742–746.
Rainbow chains #
Pure evaluation of len columns of a rainbow chain starting at column start from pw
([BS23], Section 18.7, Fig. 18.13b, p. 744; p. 745): column j applies
f_j(x) = g j (h x). Columns are 0-indexed (0, ..., τ - 1 for the book's g_1, ..., g_τ).
Zero columns leave the password unchanged.
Applying len + 1 columns from start applies column start then len columns from
start + 1.
Splitting a rainbow chain of length m + n into m columns from start followed by n
columns from start + m.
With a single column-independent reduction g₀, rainbowChainPure is (g₀ ∘ h)^[len]
(Hellman's chain, [BS23], Section 18.7, p. 743; Fig. 18.13a, p. 744).
Oracle evaluation of len columns of a rainbow chain starting at column start from pw,
querying h : P → Y once per column ([BS23], Section 18.7, pp. 745–746).
Against h, rainbowChain computes rainbowChainPure h.
Evaluating len columns makes at most len hash queries on every path.
Along any deterministic run against h, rainbowChain makes len hash queries.
Preprocessing phase A₀ #
Preprocessing algorithm A₀ for a rainbow table of chain length τ from starting points
starts ([BS23], Section 18.7, pp. 743, 745; Fig. 18.13, p. 744): computes the endpoint
z_i = f_{τ-1}(⋯ f_0(pw_i) ⋯) of each pw_i in starts and stores (z_i, pw_i) keyed by
endpoint for List.lookup.
Against h, rainbowPreprocess pairs each starting point's τ-step endpoint with that
starting point.
Looking an endpoint z up in the preprocessed table finds the first starting point in starts
whose τ-step chain ends at z.
Endpoint lookup in A₀'s table. List.lookup z on the preprocessed table returns
some pw₀ if and only if pw₀'s τ-step chain ends at z and no earlier element of starts
has endpoint z.
When the τ-step endpoints of starts are distinct—as guaranteed when A₀ discards chains
with duplicate endpoints ([BS23], Section 18.7, p. 745)—every pw₀ ∈ starts is
recovered from its endpoint by List.lookup.
Online inversion interface #
Per-call cost charging 1 per hash query (left) and 0 per table lookup (right).
Per-call cost charging 0 per hash query (left) and 1 per table lookup (right).
A left (hash) query has lookupCost 0.
A right (table lookup) query has lookupCost 1.
Online rainbow-table inversion A₁ (p. 746) #
Step k (0 ≤ k < τ, testing column col = τ - 1 - k, i.e., loop index i = τ - k in
for i = τ downto 1) of online rainbow-table inversion A₁ ([BS23], Section 18.7,
p. 746): computes the candidate endpoint z from g (τ - 1 - k) y across k columns, looks z
up in the table, and on some pw₀ reconstructs pw across τ - 1 - k columns and checks
h(pw) = y.
Online rainbow-table inversion algorithm A₁ ([BS23], Section 18.7, p. 746):
searches steps k = 0, ..., τ - 1 (i = τ down to 1) in order and stops at the first verified
preimage of y.
Deterministic evaluation of one step of rainbowAttack.
Deterministic evaluation of rainbowAttack against h and lookup.
Soundness of rainbow-table inversion ([BS23], Section 18.7, line 5 of Algorithm
A₁, p. 746): every password output by rainbowAttack satisfies h pw = y; false alarms from
chain merges or reduction collisions are rejected.
Completeness of rainbow-table inversion on covered points ([BS23], Section 18.7,
pp. 745–746): if y is the hash of the column-col value (col < τ) of a chain starting at pw₀
whose τ-step endpoint maps to some pw₀ under lookup, then rainbowAttack outputs a valid
preimage of y.
When h is injective, rainbowAttack recovers pw itself on any covered chain point.
Two-phase completeness of (rainbowPreprocess, rainbowAttack) ([BS23],
Section 18.7, pp. 745–746): against the endpoint table built by rainbowPreprocess g τ starts when
the τ-step endpoints of starts are distinct, rainbowAttack inverts y = h(pw) for every
point pw = rainbowChainPure h g 0 col pw₀ (pw₀ ∈ starts, col < τ).
When h is injective and starts has distinct τ-step endpoints, two-phase rainbow inversion
(rainbowPreprocess, rainbowAttack) recovers pw itself on every covered chain point.
Pathwise lookup budget of rainbow A₁. rainbowAttack makes at most τ table lookups on
every path ([BS23], Section 18.7, p. 746).
Pathwise hash budget of rainbow A₁. Across arbitrary answers (even if every lookup hits
and fails verification), rainbowAttack makes at most τ * τ hash queries on every path.
Hellman's stateful online attack A₁ (Fig. 18.13a, p. 744) #
Remaining rem iterations of Hellman's online search A₁ ([BS23], Section 18.7,
p. 744) from current chain element z: at rem = m + 1 (corresponding to τ - i = m), looks z
up in the table, reconstructs (g₀ ∘ h)^[m](pw₀) and checks h(pw) = y on a hit, and otherwise
advances z ← g₀(h(z)).
Hellman's online inversion algorithm A₁ ([BS23], Section 18.7, Fig. 18.13a,
p. 744): initializes z ← g₀(y) and iterates τ times, looking z up in L, reconstructing
pw ← (g₀ ∘ h)^[τ - i](pw₀) and checking h(pw) = y on a hit, and advancing z ← g₀(h(z))
step-by-step between iterations.
Soundness of Hellman's inversion ([BS23], Section 18.7, line 5 of Algorithm A₁,
p. 744): every password output by hellmanAttack satisfies h pw = y.
Completeness of Hellman's inversion on covered points ([BS23], Section 18.7,
pp. 743–744): if y = h(pw) for a point pw = (g₀ ∘ h)^[col](pw₀) at column col < τ whose
τ-step endpoint maps to some pw₀ under lookup, then hellmanAttack outputs a valid preimage
of y.
When h is injective, hellmanAttack recovers pw itself on any covered chain point.
Two-phase completeness of (rainbowPreprocess (fun _ => g₀), hellmanAttack)
([BS23], Section 18.7, pp. 743–744): against the endpoint table built by
rainbowPreprocess (fun _ => g₀) τ starts when the τ-step endpoints of starts are distinct,
hellmanAttack inverts y = h(pw) for every point pw = (g₀ ∘ h)^[col](pw₀) (pw₀ ∈ starts,
col < τ).
When h is injective and starts has distinct τ-step endpoints, two-phase Hellman inversion
(rainbowPreprocess (fun _ => g₀), hellmanAttack) recovers pw itself on every covered chain
point.
Pathwise lookup budget of Hellman's A₁. hellmanAttack makes at most τ table lookups
on every path ([BS23], Section 18.7, p. 744).
Pathwise hash budget of Hellman's A₁. Across arbitrary answers (even if every lookup hits
and fails verification, spending m + 2 hash queries at remaining depth m + 1), hellmanAttack
makes at most ∑_{m < τ} (m + 2) = τ * (τ + 3) / 2 hash queries on every path.