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.
- 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 forlabel (α + m * γ) = label βwithβ ∈ {1, …, m}andγ < n, and outputsβ - m * γ. The steplabel mis the last baby label. - Baby labels of
1, …, minstead of0, …, m - 1, since the program is given the labels of1andαonly. - Two table sizes.
mandnare separate, as in the book's time/space trade-off; the book's algorithm ism = n = ⌈q^(1/2)⌉, and brute-force search is close to(m, n) = (q, 1). - 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 #
Cslib.Crypto.GenericGroup.babyStepGiantStep: baby-step/giant-step withmbaby labels andngiant labels.Cslib.Crypto.GenericGroup.subgroupDlog: baby-step/giant-step in a subgroup of orderw, withm = n = Nat.sqrt (w - 1) + 1.
Main results #
Cslib.Crypto.GenericGroup.evalPure_babyStepGiantStep: forq ≠ 0, an injective labeling andq ≤ m * n, the program outputs the discrete logarithm.Cslib.Crypto.GenericGroup.queriesSatisfy_babyStepGiantStep,Cslib.Crypto.GenericGroup.isQueryBounded_babyStepGiantStep: every call is a product, and there are at most(m - 1) + (n - 1)of them.Cslib.Crypto.GenericGroup.babyStepGiantStep_sqrt: the book's parameterm = n = Nat.sqrt (q - 1) + 1, which is⌈q^(1/2)⌉: forq ≠ 0the program is correct with at most2 * Nat.sqrt (q - 1)products.Cslib.Crypto.GenericGroup.evalPure_groupAnswer_babyStepGiantStep: in aZMod q-module withq ≠ 0, forgof orderq, the program run on the group's own oracle outputs the discrete logarithm.Cslib.Crypto.GenericGroup.evalPure_subgroupDlog,Cslib.Crypto.GenericGroup.queriesSatisfy_subgroupDlog,Cslib.Crypto.GenericGroup.isQueryBounded_subgroupDlog: correctness and product count2 * Nat.sqrt (w - 1)forsubgroupDlog.
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Section 16.1.1, pp. 682–683, and Section 16.3, p. 693.
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 #
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.
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.
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.
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.