Documentation

CslibFrontier.Crypto.Primitives.PRG.LFSR

Linear feedback shift registers are predictable #

An n-bit linear feedback shift register (LFSR) with a set of tap positions in {0, …, n - 1} holds a state (b_{n-1}, …, b_0). Each clock cycle outputs b_0, computes the feedback bit, the exclusive or of the bits at the tap positions, and shifts the register to (b, b_{n-1}, …, b_1) Boneh and Shoup, Section 3.8, p. 75.

Here the register is a list of bits starting with b_0, and the tap set is a tap mask: a list taps in which position v is a tap when taps[v] = true. Mask bits beyond the register length are ignored. The feedback bit is the inner product Cslib.BitString.listDot taps state.

Any n consecutive output bits are the state of the register at the time the first of them was output, so they determine all later output bits. In particular output bit i ≥ n is the feedback bit of the n bits before it, and the predictor that computes it wins Attack Game 3.2 at every position i ≥ n with probability 1. The statements hold for every seed, including the all-zero seed that [BS23] excludes.

Main definitions #

Main results #

References #

One clock cycle of a linear feedback shift register Boneh and Shoup, Section 3.8, p. 75. The register is listed from the bit b_0 that is output next, and position v is a tap when taps[v] = true. The feedback bit listDot taps state enters at the high end and b_0 leaves.

The first ℓ output bits of the register started in state: each clock cycle outputs b_0 and then applies step. An empty register outputs false.

@[simp]
theorem Cslib.Crypto.PRG.LFSR.output_zero (taps state : List Bool) :
output taps 0 state = []
theorem Cslib.Crypto.PRG.LFSR.output_succ (taps : List Bool) (ℓ : ℕ) (state : List Bool) :
output taps (ℓ + 1) state = state.headD false :: output taps ℓ (step taps state)
@[simp]
theorem Cslib.Crypto.PRG.LFSR.length_step (taps state : List Bool) :
(step taps state).length = state.length

A clock cycle preserves the register length.

@[simp]
theorem Cslib.Crypto.PRG.LFSR.length_iterate_step (taps : List Bool) (t : ℕ) (state : List Bool) :
((step taps)^[t] state).length = state.length

Clock cycles preserve the register length.

@[simp]
theorem Cslib.Crypto.PRG.LFSR.length_output (taps : List Bool) (ℓ : ℕ) (state : List Bool) :
(output taps ℓ state).length = ℓ

The register outputs exactly ℓ bits.

theorem Cslib.Crypto.PRG.LFSR.take_output (taps : List Bool) {k ℓ : ℕ} {state : List Bool} (hk : k ≤ state.length) (hℓ : k ≤ ℓ) :
List.take k (output taps ℓ state) = List.take k state

The first output bits are the low bits of the seed.

theorem Cslib.Crypto.PRG.LFSR.take_length_output (taps : List Bool) {ℓ : ℕ} {state : List Bool} (hℓ : state.length ≤ ℓ) :
List.take state.length (output taps ℓ state) = state

The first n output bits of an n-bit register are its seed.

theorem Cslib.Crypto.PRG.LFSR.output_length (taps state : List Bool) :
output taps state.length state = state

An n-bit register clocked n times outputs its seed.

theorem Cslib.Crypto.PRG.LFSR.drop_output (taps : List Bool) (t ℓ : ℕ) (state : List Bool) :
List.drop t (output taps ℓ state) = output taps (ℓ - t) ((step taps)^[t] state)

The output after the first t bits is the output of the register after t clock cycles.

theorem Cslib.Crypto.PRG.LFSR.take_drop_output (taps : List Bool) {t ℓ : ℕ} {state : List Bool} (h : t + state.length ≤ ℓ) :
List.take state.length (List.drop t (output taps ℓ state)) = (step taps)^[t] state

Any n consecutive output bits of an n-bit register are its state at the time the first of them was output.

theorem Cslib.Crypto.PRG.LFSR.drop_output_eq_output_take_drop (taps : List Bool) (t ℓ : ℕ) (state : List Bool) :
List.drop t (output taps ℓ state) = output taps (ℓ - t) (List.take state.length (List.drop t (output taps ℓ state)))

A single LFSR is predictable Boneh and Shoup, Section 3.8, p. 75: any n consecutive output bits of an n-bit register determine all later output bits, which are the output of the register started on those n bits. When fewer than n bits remain after position t, the statement says only that a register clocked as often as it is long outputs its state.

theorem Cslib.Crypto.PRG.LFSR.getD_output_length (taps : List Bool) {ℓ : ℕ} {state : List Bool} (h : state.length < ℓ) :
(output taps ℓ state).getD state.length false = BitString.listDot taps state

The output bit that follows the seed is the feedback bit of the seed.

theorem Cslib.Crypto.PRG.LFSR.getD_output_add (taps : List Bool) {t ℓ : ℕ} {state : List Bool} (h : t + state.length < ℓ) :
(output taps ℓ state).getD (t + state.length) false = BitString.listDot taps (List.take state.length (List.drop t (output taps ℓ state)))

The linear recurrence of an n-bit register: output bit t + n is the feedback bit of output bits t, …, t + n - 1.

The generator and Attack Game 3.2 #

The LFSR with tap mask taps, an n-bit register and ℓ output bits, as a generator on bit strings. Seed bit j is the register bit b_j.

theorem Cslib.Crypto.PRG.LFSR.ofFn_generator (taps : List Bool) (n ℓ : ℕ) (seed : BitString n) :
List.ofFn ((generator taps n ℓ) seed) = output taps ℓ (List.ofFn seed)

The bits of the generated string are the output of the register.

noncomputable def Cslib.Crypto.PRG.LFSR.predictor (taps : List Bool) (n i : ℕ) :

The predictor for output bit i of an n-bit register: the feedback bit of the last n of the i bits it is given. It is deterministic.

theorem Cslib.Crypto.PRG.LFSR.listDot_drop_take_generator (taps : List Bool) {n ℓ : ℕ} (i : Fin ℓ) (hi : n ≤ ↑i) (seed : BitString n) :
BitString.listDot taps (List.drop (↑i - n) (List.ofFn (Fin.take ↑i ⋯ ((generator taps n ℓ) seed)))) = (generator taps n ℓ) seed i

For every seed, the feedback bit of the n output bits before position i ≥ n is output bit i.

theorem Cslib.Crypto.PRG.LFSR.predictionExperiment_predictor (taps : List Bool) {n ℓ : ℕ} (i : Fin ℓ) (hi : n ≤ ↑i) :
(generator taps n ℓ).predictionExperiment i (predictor taps n ↑i) = PMF.pure true

A single LFSR is predictable Boneh and Shoup, Section 3.8, p. 75, in Attack Game 3.2: for every position i ≥ n, the predictor guesses output bit i of an n-bit register with probability 1.

theorem Cslib.Crypto.PRG.LFSR.predictionAdvantage_predictor (taps : List Bool) {n ℓ : ℕ} (i : Fin ℓ) (hi : n ≤ ↑i) :
(generator taps n ℓ).predictionAdvantage i (predictor taps n ↑i) = 1 / 2

The predictor has the largest possible advantage 1 / 2 in Attack Game 3.2.

theorem Cslib.Crypto.PRG.LFSR.advantage_predictionTest_predictor (taps : List Bool) {n ℓ : ℕ} (i : Fin ℓ) (hi : n ≤ ↑i) :
(generator taps n ℓ).advantage (predictionTest i (predictor taps n ↑i)) = 1 / 2

The test built from the predictor distinguishes the LFSR output from a uniform string with advantage 1 / 2 in Attack Game 3.1.