Path: blob/main/foundations/03-galois-fields-aes/break/weak-sbox-reducible-poly.ipynb
483 views
Break: Weak S-box from Reducible Polynomial
Module 03 | Breaking Weak Parameters
The AES S-box derives its strength from GF(2^8) inversion. Use the wrong polynomial and the field falls apart.
Why This Matters
The AES S-box maps each byte to its multiplicative inverse in GF(), then applies an affine transformation. This relies on a critical assumption: every nonzero byte has a unique inverse.
That property only holds if the modulus polynomial is irreducible over GF(2). The AES standard uses , which is irreducible, so is a genuine field with 255 invertible elements.
But what if someone accidentally (or maliciously) uses a reducible polynomial? Then the quotient ring is not a field --- it has zero divisors, elements with no inverse. The S-box construction breaks down, and the result is cryptographically weak.
The Scenario
A careless implementer builds "AES" using the polynomial instead of the correct .
The polynomial factors over GF(2), so the quotient ring is not a field.
Your job: show that this breaks the S-box and produces exploitable weaknesses.
Step 1: Identify Zero Divisors
In a field, implies or . In a ring with zero divisors, you can have with both and .
If is a zero divisor, then has no multiplicative inverse (proof: if existed, then , contradicting ).
Let's find all zero divisors in .
Step 2: Build the Broken S-box
The AES S-box construction:
Compute in GF() (with )
Apply the affine transformation
With our broken polynomial, step 1 fails for every zero divisor --- there is no inverse. The implementer is forced to patch these entries, typically mapping them to 0 (like the real S-box does for input 0). This creates a large number of collisions and fixed points.
Step 3: Measure the Damage --- Fixed Points and Collisions
A good S-box should be a bijection (permutation): every input maps to a unique output. The real AES S-box has:
256 distinct outputs (bijection)
0 fixed points ( for all )
The broken S-box will fail both tests because all non-invertible inputs get patched to the same value .
Step 4: Measure Non-linearity
The non-linearity of an S-box measures how far it is from any affine function. Higher is better. We compute it using the Walsh-Hadamard transform: for each pair of input mask and output mask , count the bias of the linear approximation .
For an 8-bit S-box, the theoretical maximum is 120. The real AES S-box achieves 112.
The Fix
AES uses the irreducible polynomial .
This guarantees that is a field with 255 invertible nonzero elements. No zero divisors, no patching, no collisions.
The choice of irreducible polynomial was not arbitrary --- the AES designers verified irreducibility and chose a polynomial that also gives efficient hardware implementation (the specific terms correspond to a low-weight reduction step).
Exercises
Exercise 1
Try the reducible polynomial . How many non-invertible elements does the quotient ring have? Build the S-box and compare its nonlinearity to the real one.
Exercise 2
Try over GF(2). This polynomial has a single repeated root. How many zero divisors appear? Is the damage worse than our example above?
Exercise 3
Pick a different irreducible degree-8 polynomial (not the AES one) and build the S-box using it. Is the nonlinearity the same as the AES S-box? (Hint: the nonlinearity comes from the inversion map, which has the same Walsh spectrum regardless of which irreducible polynomial you use. The affine step preserves nonlinearity.)
Summary
| Property | Real AES S-box | Broken S-box (reducible poly) |
|---|---|---|
| Modulus polynomial | (irreducible) | (reducible) |
| Quotient ring | Field (GF(256)) | Ring with zero divisors |
| Invertible nonzero elements | 255 / 255 | Much fewer |
| S-box is bijection? | Yes | No (many collisions) |
| Fixed points | 0 | Multiple |
| Nonlinearity | 112 / 120 | Significantly lower |
Key takeaways:
The AES S-box construction requires an irreducible modulus polynomial.
A reducible polynomial creates zero divisors --- elements with no inverse.
Patching those entries creates collisions, fixed points, and reduced nonlinearity.
These weaknesses are directly exploitable by linear and differential cryptanalysis.
The mathematical lesson: a quotient ring is only a field when the modulus is irreducible.
Back to Module 03: Galois Fields and AES