Linear Feedback Shift Registers

Also known as 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.

In an LFSR, the register is a row of nn 1-bit memory cells. Its contents are the current nn-bit state. Each clock tick outputs 1 designated bit, shifts every cell’s bit to the next cell, then inserts the feedback bit into the vacant cell.

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
Here:
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.

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

Connection Polynomial

Also known as feedback polynomial. A connection polynomial encodes an LFSR’s feedback recurrence as coefficients of a polynomial. It is not a separate part of the LFSR.

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

The coefficient ckc_k is 11 iff si−ks_{i-k} feeds into the new bit sis_i. A coefficient of 00 omits that tap. The polynomial therefore describes the LFSR’s wiring independently of its initial state.

The constant 11 is fixed by convention. It represents the new bit sis_i after the recurrence is moved to 1 side.

si+c1si−1+c2si−2+⋯+cnsi−n=0s_i + c_1s_{i-1} + c_2s_{i-2} + \cdots + c_ns_{i-n} = 0

It is not a tap. Over GF(2)\mathrm{GF}(2), subtraction and addition are identical. Some texts use the reversed characteristic polynomial instead. Its fixed coefficient is the leading xnx^n term.

Primitive Polynomial

A degree-nn polynomial p(x)p(x) over GF(2)\mathrm{GF}(2) is primitive iff it is irreducible and any root has multiplicative order 2n−12^n - 1 in GF(2n)\mathrm{GF}(2^n). Its successive powers therefore generate every nonzero field element.

To test whether a degree-nn polynomial p(x)p(x) is primitive, first check that it is irreducible over GF(2)\mathrm{GF}(2). Let M=2n−1M = 2^n - 1. For every prime factor qq of MM, compute xM/q mod p(x)x^{M/q} \bmod p(x). The polynomial is primitive iff none of these remainders equals 1.

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).

A non-primitive connection polynomial still produces a periodic sequence, just with a period shorter than 2n−12^n - 1, and possibly a period that depends on the initial state.

Key Space

With a fixed public connection polynomial, the initial nn-bit state is the key. The all-zero state is excluded because it remains zero forever. The key space therefore has 2n−12^n - 1 members.

Characteristic Polynomial

A characteristic polynomial is algebraic notation for the feedback rule. The LFSR does not evaluate this polynomial while it shifts. It lets finite-field algebra determine properties of the recurrence, especially its period.

Replace the new bit sis_i with xnx^n. Replace each delayed bit si−ks_{i-k} with xn−kx^{n-k}. The feedback rule then becomes the characteristic polynomial.

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

For si=si−1⊕si−4s_i = s_{i-1} \oplus s_{i-4}, the characteristic polynomial is x4+x3+1x^4 + x^3 + 1. It records exactly the same recurrence. It is not a different LFSR.

The connection polynomial p(x)p(x) records the same coefficients in reverse order. Some texts use p∗(x)p^*(x) as their connection-polynomial convention.

p∗(x)p^*(x) is primitive over GF(2)\mathrm{GF}(2) iff p(x)p(x) is. Either polynomial can be used to test whether the LFSR has maximal period.

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)
Here:
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.

Clock Control

Component LFSRs need not advance together. A clock-control function can select which registers advance at each step from their current output bits. Irregular clocking disrupts the fixed alignment between component sequences and the output keystream.

Clock control must not leave a component’s output statistically detectable in the resulting keystream.

Security

A combining or clock-control function 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.

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.

  • 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.

If clock control repeatedly holds 1 component’s output while another advances, the output can retain detectable structure from the held component. Statistical tests can then reveal its period or state.

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.

Solution Reveal Hide
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
4 1000 1 s0=1s_0=1
5 0001 1 s1=0s_1=0
6 0011 1 s2=0s_2=0
7 0111 1 s3=0s_3=0
8 1111 0 s4=1s_4=1
9 1110 1 s5=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 November 3, 2026 6 min read
Was this helpful?