Documentation

CslibFrontier.Crypto.Computational.GenericGroup.BabyStepGiantStep

Baby-step/giant-step in the generic group model #

The baby-step/giant-step algorithm of [BS23], Section 16.1.1 (pp. 682–683), computes discrete logarithms in a cyclic group of order q generated by g, with q prime or not. Write the unknown logarithm α as γ * m + β with β, γ < m. The baby steps tabulate g^β for β < m; the giant steps compute u · (g^(-m))^γ for γ = 0, 1, … until one is in the table. With m = ⌈q^(1/2)⌉ the book counts "about 2 q^(1/2) group operations in the worse case". On p. 693 the book names the algorithm as an example of a discrete logarithm algorithm in a generic group: it gets the labels of 1 and α, calls the group operation oracle and outputs α.

babyStepGiantStep m n g u is that algorithm as a program over the group oracle of CslibFrontier.Crypto.Computational.GenericGroup.Basic, with m baby labels and n giant labels. It differs from the book's procedure as follows.

  1. No inversion. The book's step g^(-m) is not a product of two labels the program holds. Here the giant steps go up instead: the program looks for label (α + m * γ) = label β with β ∈ {1, …, m} and γ < n, and outputs β - m * γ. The step label m is the last baby label.
  2. Baby labels of 1, …, m instead of 0, …, m - 1, since the program is given the labels of 1 and α only.
  3. Two table sizes. m and n are separate, as in the book's time/space trade-off; the book's algorithm is m = n = ⌈q^(1/2)⌉, and brute-force search is close to (m, n) = (q, 1).
  4. No early exit. The program computes all giant labels and then searches them. This does not change the worst case, which is all that is counted here.

The count is of oracle calls of the program itself: every call is a product of two labelled elements (queriesSatisfy_babyStepGiantStep), and every run makes at most (m - 1) + (n - 1) calls (isQueryBounded_babyStepGiantStep). This is the efficiency certificate of the algorithm in the generic group model. Table lookups and the search are not counted, as in the book, which counts group operations and keeps the table in an associative array; nothing here is a statement about running time in a machine model.

Main definitions #

Main results #

References #

Baby-step/giant-step ([BS23], Section 16.1.1) with m baby labels and n giant labels, on input g, the label of 1, and u, the label of α. The baby steps compute the labels of 1, 2, …, m with m - 1 products. The giant steps compute the labels of α, α + m, …, α + m * (n - 1) with n - 1 products, the step being the label of m. The output is β - m * γ for the first giant index γ whose label is the label of a baby β, and 0 if there is none. The module documentation lists how this differs from the book's procedure.

Correctness #

theorem Cslib.Crypto.GenericGroup.evalPure_babyStepGiantStep {q : ℕ} {S : Type} [NeZero q] [DecidableEq S] {L : ZMod q → S} (hL : Function.Injective L) {m n : ℕ} (hmn : q ≤ m * n) (α : ZMod q) :
OracleComp.evalPure (answer L) (babyStepGiantStep m n (L 1) (L α)) = α

Correctness. For q ≠ 0, an injective labeling L and table sizes with q ≤ m * n, baby-step/giant-step on the labels of 1 and α outputs α ([BS23], Section 16.1.1, run in the generic group of Section 16.3). There is no primality hypothesis: the book says that q may or may not be prime.

theorem Cslib.Crypto.GenericGroup.evalPure_groupAnswer_babyStepGiantStep {q : ℕ} [NeZero q] {G : Type} [AddCommGroup G] [Module (ZMod q) G] [DecidableEq G] {g : G} (hg : Function.Injective fun (β : ZMod q) => β • g) {m n : ℕ} (hmn : q ≤ m * n) (α : ZMod q) :

Correctness in a group. For q ≠ 0, in a ZMod q-module G with g of order q (the map β ↦ β • g is injective) and table sizes with q ≤ m * n, baby-step/giant-step run on the group's own oracle with inputs g and α • g (the book's g^α) outputs α. This is [BS23], Section 16.1.1, where G is cyclic of order q and generated by g; here g need not generate G.

Counting products #

Every call of baby-step/giant-step is a product of two labelled elements.

Product count. Baby-step/giant-step with m baby and n giant labels makes at most (m - 1) + (n - 1) oracle calls on every run, whatever the oracle answers. With queriesSatisfy_babyStepGiantStep, these are at most (m - 1) + (n - 1) multiplications in the group. The book counts m multiplications for its baby steps ([BS23], Section 16.1.1, p. 683), one of which computes an unused element.

theorem Cslib.Crypto.GenericGroup.babyStepGiantStep_sqrt {q : ℕ} {S : Type} [NeZero q] [DecidableEq S] {L : ZMod q → S} (hL : Function.Injective L) (α : ZMod q) :
OracleComp.evalPure (answer L) (babyStepGiantStep ((q - 1).sqrt + 1) ((q - 1).sqrt + 1) (L 1) (L α)) = α ∧ (babyStepGiantStep ((q - 1).sqrt + 1) ((q - 1).sqrt + 1) (L 1) (L α)).IsQueryBounded (2 * (q - 1).sqrt)

The book's parameter. With r = Nat.sqrt (q - 1), the table sizes m = n = r + 1 are the book's m = ⌈q^(1/2)⌉ ([BS23], Section 16.1.1, p. 683). For q ≠ 0 and an injective labeling, baby-step/giant-step outputs the discrete logarithm and makes at most 2 * r calls; every call is a product by queriesSatisfy_babyStepGiantStep. Since (2 * r)^2 ≤ 4 * (q - 1) < 4 * q, this is fewer than 2 * q^(1/2) products, the book's "about 2 q^(1/2) group operations in the worse case".

Baby-step/giant-step in a subgroup of order w, with m = n = Nat.sqrt (w - 1) + 1 and the residue modulo w as output.

theorem Cslib.Crypto.GenericGroup.evalPure_subgroupDlog {q : ℕ} {S : Type} [NeZero q] [DecidableEq S] {L : ZMod q → S} (hL : Function.Injective L) {O : (query : GroupQuery q S) → GroupOracleSpec q S query} (hO : ∀ (β₁ β₂ : ZMod q), O (GroupQuery.op (L β₁) (L β₂) 1 1) = some (L (β₁ + β₂))) {w : ℕ} {t : ZMod q} (ht : addOrderOf t = w) {a : ℕ} (ha : a < w) :
OracleComp.evalPure O (subgroupDlog w (L t) (L (↑a * t))) = a

Subgroup correctness. For q ≠ 0, an injective labeling L, any oracle O that multiplies labels of L, and a base t with addOrderOf t = w, subgroupDlog w (L t) (L (a * t)) outputs a for every a < w.

Every query made by subgroupDlog is a product (GroupQuery.IsProduct).

subgroupDlog makes at most 2 * Nat.sqrt (w - 1) product queries on every path, whatever the oracle returns; exponent and modulus arithmetic and table search are not costed, and no machine-model bound is claimed.