Path: blob/main/foundations/03-galois-fields-aes/sage/03b-extension-fields-gf2n.ipynb
483 views
Extension Fields: GF()
Module 03b | Galois Fields and AES
Building larger fields from GF(2) using irreducible polynomials.
Question: GF(2) has only two elements, not enough to represent a byte (256 values). We need a field with exactly 256 elements. But there's no prime equal to 256. So how do you build a field whose size is a power of a prime?
The answer: take the polynomial ring GF(2) from notebook 03a, pick an irreducible polynomial of degree , and quotient. The result is GF(), a field with elements. This is the same construction you saw in Module 02 for quotient rings, but now applied to binary polynomials.
Objectives
By the end of this notebook you will be able to:
Explain why GF(2) is not a field and what we need to fix
Identify irreducible polynomials over GF(2) and explain their role
Construct GF() as a quotient ring GF(2)
Perform addition and multiplication in GF()
Find multiplicative inverses in GF()
Bridge from 03a
In 03a you saw that GF(2) polynomials correspond to bit-strings: addition is XOR, and multiplication produces higher-degree polynomials. But GF(2) is a ring, not a field, polynomials of degree have no multiplicative inverse.
In Module 02 (notebook 02f) you learned the fix: quotient by an irreducible polynomial. This is exactly how we build GF().
where is irreducible of degree . Elements are polynomials of degree , and multiplication is done modulo .
Why GF(2) Is Not a Field
Let's see the problem concretely:
Irreducible Polynomials over GF(2)
A polynomial is irreducible if it cannot be factored into lower-degree polynomials over GF(2). This is the polynomial analogue of a prime number.
Checkpoint: Is irreducible over GF(2)? Before running the next cell, try to factor it. Hint: in GF(2), , so
Key observations:
over GF(2), reducible (because in characteristic 2)
is the only irreducible quadratic over GF(2)
The number of irreducible polynomials grows with degree, there are always enough to build extension fields
Building GF(): A Tiny Example
Let's build the smallest non-trivial binary extension field: GF(4) = GF().
GF(4) has exactly 4 elements: , where satisfies , i.e., .
Addition in GF()
Addition is polynomial addition with GF(2) coefficients, which is just XOR of coefficients. No reduction needed because adding polynomials of degree gives a polynomial of degree .
Multiplication in GF()
Multiplication is polynomial multiplication reduced modulo the irreducible polynomial. This is where the quotient ring structure matters, without reduction, the degree would grow beyond .
Checkpoint: In GF(4), compute by hand. You get , but means . Verify with SageMath:
Every nonzero element has an inverse, this is what makes GF(4) a field, not just a ring. The irreducible polynomial is what guarantees this.
What Happens with a Reducible Polynomial?
Common mistake: "Any degree- polynomial works for building GF()." No! If you quotient by a reducible polynomial, you get a ring with zero divisors, not a field. The polynomial MUST be irreducible.
Scaling Up: GF()
GF(4) is tiny. Let's build GF() = GF(16) to see the pattern at a more interesting size.
Checkpoint: In GF(), is a generator of the multiplicative group (order 15). Is every nonzero element a power of ? Count the distinct values in the power table above. You should see all 15 nonzero elements.
The Choice of Irreducible Polynomial
Different irreducible polynomials of the same degree give isomorphic fields, same structure, different representation. But the choice matters for implementation efficiency.
The Construction, Summarized
Here is the recipe for GF():
Start with the polynomial ring GF(2)
Choose an irreducible polynomial of degree
Form the quotient: GF() = GF(2)
Elements are polynomials of degree (equivalently, -bit strings)
Addition = polynomial addition = XOR of bit-strings
Multiplication = polynomial multiplication mod
Every nonzero element has a multiplicative inverse (because is irreducible)
Exercises
Exercise 1 (Worked)
In GF() with modulus , compute by hand, then verify with SageMath.
Exercise 2 (Guided)
Find all irreducible polynomials of degree 3 over GF(2). For each one, build GF() and verify that the generator has multiplicative order 7 (= ).
Exercise 3 (Independent)
In GF() with SageMath's default modulus:
Find the multiplicative inverse of every nonzero element. Verify each satisfies .
Compute the discrete logarithm: for each nonzero element , find such that (where is the generator). Build a log table.
Using your log table, verify that multiplication can be done as: . This is how hardware implements GF multiplication efficiently!
Summary
| Concept | Key idea |
|---|---|
| GF(2) is not a field | Polynomials of degree have no multiplicative inverse in the polynomial ring |
| Irreducible polynomials | The polynomial analogue of primes. Quotienting by one of degree produces GF(), a field with elements |
| Reducible polynomials fail | Using a reducible polynomial creates zero divisors, not a field |
| Addition = XOR | Adding polynomials in GF() is just XOR of coefficient bit-strings, no reduction needed |
| Multiplication needs reduction | Multiply the polynomials, then reduce mod to keep the degree below |
| Isomorphic fields | Different irreducible polynomials of the same degree give isomorphic fields. The choice affects implementation, not algebra |
Crypto foreshadowing: AES uses GF() = GF(2). In notebook 03c, we build this exact field and do byte-level arithmetic inside it. The S-box, MixColumns, and key schedule all live here.
Next: GF(256) Arithmetic, the specific field that powers AES.