Linear Feedback Shift Registers

Work in progress. This note is still being written and incomplete.

A linear feedback shift register (LFSR) builds a keystream from a register of nn bits s0,s1,…,sn−1s_0, s_1, \ldots, s_{n-1}, where each new bit is the XOR of a fixed subset of the current bits.

si=c1si−1⊕c2si−2⊕⋯⊕cnsi−n,i≥ns_i = c_1 s_{i-1} \oplus c_2 s_{i-2} \oplus \cdots \oplus c_n s_{i-n}, \quad i \ge n
  • c1,…,cn∈{0,1}c_1, \ldots, c_n \in \{0, 1\}: the feedback taps, fixed for a given LFSR.
  • s0,…,sn−1s_0, \ldots, s_{n-1}: the initial state, acting as the secret key or seed.

Each step outputs 1 bit, usually si−ns_{i-n}, then shifts the register and inserts the new feedback bit.

shift 1 2 3 4 output c₁ c₄ new bit

Connection Polynomial

The taps are written as a connection polynomial over GF(2)\mathrm{GF}(2), also called the feedback polynomial.

p(x)=1+c1x+c2x2+⋯+cnxnp(x) = 1 + c_1 x + c_2 x^2 + \cdots + c_n x^n

Each term ckxkc_k x^k marks whether the tap kk steps back feeds into the recurrence, so p(x)p(x) is a complete description of the LFSR’s wiring, independent of the initial state.

The output sequence has period 2n−12^n - 1, the maximum possible for an nn-bit register, iff p(x)p(x) is a primitive polynomial over GF(2)\mathrm{GF}(2).

Characteristic Polynomial

The recurrence itself corresponds to a characteristic polynomial, related to the connection polynomial by xnx^n reversal.

p∗(x)=xnp(1/x)=xn+c1xn−1+c2xn−2+⋯+cnp^*(x) = x^n p(1/x) = x^n + c_1 x^{n-1} + c_2 x^{n-2} + \cdots + c_n

p∗(x)p^*(x) is primitive over GF(2)\mathrm{GF}(2) iff p(x)p(x) is, so either polynomial can be used to check for maximal period. The characteristic polynomial is the one whose roots in the extension field GF(2n)\mathrm{GF}(2^n) 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 ff.

ki=f(si(1),si(2),…,si(m))k_i = f\left(s_i^{(1)}, s_i^{(2)}, \ldots, s_i^{(m)}\right)
  • si(j)s_i^{(j)}: the output bit of the jj-th LFSR at step ii.
  • ff: a fixed nonlinear function of the mm component outputs.

For example, the Geffe generator combines 3 LFSRs through f(x1,x2,x3)=x1x2⊕(1⊕x1)x3f(x_1, x_2, x_3) = x_1 x_2 \oplus (1 \oplus x_1) x_3, using x1x_1 to select between x2x_2 and x3x_3.

Security

A combining function ff must satisfy several properties for the resulting keystream to resist analysis.

  • Balance
    ff outputs 0 and 1 equally often across all input combinations, so the keystream carries no statistical bias.
  • High nonlinear order
    ff 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
    kik_i is statistically independent of each individual si(j)s_i^{(j)}, 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 x2x_2 on 75%75\% of inputs and with x3x_3 on 75%75\% of inputs, since x1x_1 only selects which of the two it copies.

Attacking

Berlekamp-Massey Algorithm

Targets a single LFSR directly, exploiting the linearity of its recurrence.

  • 2n2n consecutive output bits give nn linear equations in the nn unknown taps c1,…,cnc_1, \ldots, c_n.
  • Solving this system (the Berlekamp-Massey algorithm does so in O(n2)O(n^2)) 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 ff 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 2n−12^n - 1 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 50%50\% of the time is accepted as the recovered state.

This reduces recovering an mm-LFSR generator’s full state from 1 search of size 2∑nj−12^{\sum n_j} - 1 to mm separate searches of size 2nj−12^{n_j} - 1 each, so correlation immunity directly defends against it.

Example

Take n=4n = 4 with connection polynomial p(x)=1+x+x4p(x) = 1 + x + x^4, so c1=1,c2=0,c3=0,c4=1c_1 = 1, c_2 = 0, c_3 = 0, c_4 = 1, and initial state s0s1s2s3=1000s_0 s_1 s_2 s_3 = 1000.

si=si−1⊕si−4s_i = s_{i-1} \oplus s_{i-4}
iisi−4si−3si−2si−1s_{i-4} s_{i-3} s_{i-2} s_{i-1}sis_iOutput
410001s0=1s_0=1
500011s1=0s_1=0
600110s2=0s_2=0
701101s3=0s_3=0
811011s4=1s_4=1
910110s5=1s_5=1

Continuing the recurrence for 15 steps cycles through every nonzero state of the register once before repeating, giving the maximal period 24−1=152^4 - 1 = 15, confirming p(x)=1+x+x4p(x) = 1 + x + x^4 is primitive over GF(2)\mathrm{GF}(2).

Written by September 29, 2026 4 min read
Was this helpful?