A linear feedback shift register (LFSR) builds a keystream from a register of bits , where each new bit is the XOR of a fixed subset of the current bits.
- : the feedback taps, fixed for a given LFSR.
- : the initial state, acting as the secret key or seed.
Each step outputs 1 bit, usually , then shifts the register and inserts the new feedback bit.
Connection Polynomial
The taps are written as a connection polynomial over , also called the feedback polynomial.
Each term marks whether the tap steps back feeds into the recurrence, so is a complete description of the LFSR’s wiring, independent of the initial state.
The output sequence has period , the maximum possible for an -bit register, iff is a primitive polynomial over .
Characteristic Polynomial
The recurrence itself corresponds to a characteristic polynomial, related to the connection polynomial by reversal.
is primitive over iff is, so either polynomial can be used to check for maximal period. The characteristic polynomial is the one whose roots in the extension field generate the output sequence, each output bit expressible as a trace function of a root raised to successive powers.
Combining LFSRs
An LFSR alone fails the unpredictability requirement of a secure keystream generator, since its recurrence is linear. Practical generators instead combine several LFSRs of different lengths and connection polynomials through a nonlinear Boolean function .
- : the output bit of the -th LFSR at step .
- : a fixed nonlinear function of the component outputs.
For example, the Geffe generator combines 3 LFSRs through , using to select between and .
Security
A combining function must satisfy several properties for the resulting keystream to resist analysis.
- Balance
outputs 0 and 1 equally often across all input combinations, so the keystream carries no statistical bias. - High nonlinear order
cannot be approximated by a linear or affine function of its inputs, since a close linear approximation reduces the combiner to a single large LFSR. - Correlation immunity
is statistically independent of each individual , so no component LFSR’s output correlates with the combiner’s output.
A higher correlation immunity order generally forces a lower achievable nonlinear order, so the 2 properties trade off against each other rather than maximising independently. The Geffe generator above illustrates the failure mode: despite being nonlinear and balanced, its output agrees with on of inputs and with on of inputs, since only selects which of the two it copies.
Attacking
Berlekamp-Massey Algorithm
Targets a single LFSR directly, exploiting the linearity of its recurrence.
- consecutive output bits give linear equations in the unknown taps .
- Solving this system (the Berlekamp-Massey algorithm does so in ) recovers every tap and the state at that point.
- The attacker then computes every following output bit from the recurrence.
Correlation Attack
Targets a combined generator whose combining function correlates with 1 of its component LFSRs, as in the Geffe example above.
- The attacker guesses the connection polynomial of the correlated LFSR (public in most designs) and searches over its possible initial states.
- Each candidate state produces a candidate output sequence, compared against the keystream bit by bit.
- The candidate whose sequence agrees with the keystream noticeably more than of the time is accepted as the recovered state.
This reduces recovering an -LFSR generator’s full state from 1 search of size to separate searches of size each, so correlation immunity directly defends against it.
Example
Take with connection polynomial , so , and initial state .
| Output | |||
|---|---|---|---|
| 4 | 1000 | 1 | |
| 5 | 0001 | 1 | |
| 6 | 0011 | 0 | |
| 7 | 0110 | 1 | |
| 8 | 1101 | 1 | |
| 9 | 1011 | 0 |
Continuing the recurrence for 15 steps cycles through every nonzero state of the register once before repeating, giving the maximal period , confirming is primitive over .