Linear congruential generator distinguisher and seed search #
The linear congruential generator G_lcg(s) = (⌊s / w⌋, a * s + b mod q) with state space
S_q = {0, …, q - 1} and output space R = {0, …, ⌊(q - 1) / w⌋}
([BS23], Section 3.7.1, pp. 70–71).
Given (r, s'), LinearCongruential.test recovers s from s' using BinaryGcd.modInv and
checks ⌊s / w⌋ = r. On LinearCongruential.generator : Generator (Fin q) (Fin |R| × Fin q),
when a is coprime to q, generator is injective (generator_injective) and test computes
cslib's range test Generator.rangeTest (rangeTest_generator), so
advantage_generator_test gives exact distinguishing advantage 1 - 1 / |R|. Note the boundary:
Boneh–Shoup call G_lcg "clearly insecure" for every positive w ≤ q. That holds when 0 < w < q
(advantage at least 1 / 2) and fails at w = q: then |R| = 1 and the advantage is 0, as it
is for the values w = 0 and w > q that the book excludes. The advantage theorem targets the
finite typed game (which has no adversary cost model); computableInPolyTime_test separately
certifies test on encoded natural numbers in binary.
For the multi-iteration generator outputting consecutive ⌊s_i / w⌋ values,
LinearCongruential.seedSearch checks all w candidates r₁ * w + e with e < w below q whose
second and third outputs match r₂ and r₃, returning the greatest passing candidate or r₁ * w
if none passes (Boneh–Shoup do not specify a tie-breaking or fallback value). seedSearch_eq proves
that the search returns the seed s < q when 0 < w and the condition hshort holds: no nonzero
d with |d| < w has a * d within less than w of a multiple of q. Under 0 < w and
hshort two outputs already determine the state (eq_of_div_eq_of_next_div_eq). hshort is not
in the book, which describes the search for the Java 8 parameters only. It is sufficient and not
necessary, and some condition is needed: with a = b = 1, q = 16, w = 4, which meet the book's
conditions on the parameters, the seeds 0 and 1 have the same three outputs.
computableInPolyTime_seedSearch certifies seedSearch in time polynomial in w (given in unary
via encUnary, so exponential in the bit length of w) and the binary lengths of the other
inputs. java8 records Boneh–Shoup's parameters for Java 8 Math.random, and seedSearch_java8
discharges hshort for every seed s < 2 ^ 48.
Differences from [BS23]: LinearCongruential omits a, b < q and 0 < w ≤ q, taking
only the hypothesis each result uses; G_lcg^(n) as a generator and Lemma 3.7 are omitted.
Main definitions #
Cslib.Crypto.PRG.LinearCongruential: parameters(q, a, b, w)and binary encodingencLinearCongruential.Cslib.Crypto.PRG.LinearCongruential.next,Cslib.Crypto.PRG.LinearCongruential.prev: modular state update and inverse viaBinaryGcd.modInv.Cslib.Crypto.PRG.LinearCongruential.test: the distinguishing test(r, s') ↦ (prev s' / w == r).Cslib.Crypto.PRG.LinearCongruential.generator: the single-stepGeneratorG_lcg.Cslib.Crypto.PRG.LinearCongruential.seedSearch: exhaustive search overe < wmatching three outputs.Cslib.Crypto.PRG.LinearCongruential.java8: Boneh–Shoup's parameters forMath.random.
Main results #
Cslib.Crypto.PRG.LinearCongruential.prev_next:previnvertsnextwhena.Coprime q.Cslib.Crypto.PRG.LinearCongruential.computableInPolyTime_test:testis computable in polynomial time in binary.Cslib.Crypto.PRG.LinearCongruential.generator_injective:generatoris injective whena.Coprime q.Cslib.Crypto.PRG.LinearCongruential.rangeTest_generator:generator.rangeTestagrees withtest.Cslib.Crypto.PRG.LinearCongruential.advantage_generator_test:generator.advantageagainsttestis1 - 1 / (⌊(q - 1) / w⌋ + 1).Cslib.Crypto.PRG.LinearCongruential.eq_of_div_eq_of_next_div_eq: state uniqueness from two outputs underhshort.Cslib.Crypto.PRG.LinearCongruential.seedSearch_eq:seedSearchrecoverss < qunder0 < wandhshort.Cslib.Crypto.PRG.LinearCongruential.computableInPolyTime_seedSearch:seedSearchruns in polynomial time inw(unary) and the binary lengths ofP, r₁, r₂, r₃.Cslib.Crypto.PRG.LinearCongruential.seedSearch_java8:seedSearchrecovers every seeds < 2 ^ 48ofjava8.
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Version 0.6, Section 3.7.1, pp. 70–71.
The public system parameters of a linear congruential generator ([BS23], Section 3.7.1, p. 70).
The encoding of the parameters of a linear congruential generator: q, a, b and w in
binary, each framed except the last (encLinearCongruential_apply).
The test runs in time polynomial in the length of the parameters and the challenge, all in binary.
The seed-recovery test has advantage exactly 1 - 1 / |R| against G_lcg
([BS23], Section 3.7.1, p. 70): the test that recovers the state s from
a * s + b mod q and compares ⌊s / w⌋, run on a challenge in R × S_q, has advantage exactly
1 - 1 / |R|, where |R| = ⌊(q - 1) / w⌋ + 1. The advantage is at least 1 / 2 when
0 < w < q; otherwise R has one element and the advantage is 0. Boneh–Shoup call G_lcg
clearly insecure for every positive w ≤ q; that fails at w = q, where G_lcg(s) is exactly
uniform.
Under hshort, a state is determined by its output and the output of its successor.
The search recovers the seed from its first three outputs under hshort: no nonzero d with
|d| < w has a * d within w of a multiple of q. Then no two states have the same first two
outputs. The condition is sufficient and not necessary.
The search runs in time polynomial in w and in the length of the other inputs in binary: the
caller supplies w in unary (so time is exponential in the bit length of w).
Seed recovery in Boneh–Shoup's Java 8 LCG model ([BS23], p. 71): with the
parameters that the book gives for Java 8 Math.random, the search over the 2 ^ 22 candidates
returns the seed from the model's integer outputs ⌊s_i / w⌋, for every seed. Java's
Math.random returns a double; no correspondence with that interface is formalized here. The
proof uses the first two outputs only.