Path: blob/main/foundations/03-galois-fields-aes/sage/03c-gf256-arithmetic.ipynb
483 views
GF(256) Arithmetic
Module 03c | Galois Fields and AES
The field inside every AES byte.
Question: A single AES byte, say
0x53, is simultaneously an integer (83), a bit-string (01010011), and a polynomial (). You can XOR two bytes (addition), but can you multiply them? Divide them? Invert them?Yes, because bytes live in GF(256), a field. In this notebook, you'll do arithmetic with bytes the way AES does.
Objectives
By the end of this notebook you will be able to:
Construct GF(256) using the AES irreducible polynomial
Convert between bytes, bit-strings, and GF(256) polynomials
Perform addition (XOR), multiplication, and inversion in GF(256)
Build
xtime, the fundamental multiplication-by- operationUnderstand why GF(256) is the right choice for a byte-oriented cipher
Bridge from 03b
In 03b you built GF() for small (2, 3, 4). Now we go to : GF() = GF(256). The construction is identical, quotient GF(2) by an irreducible polynomial of degree 8, but the specific polynomial is chosen by the AES standard:
This polynomial is irreducible over GF(2) and has the hex representation 0x11B.
The AES Field: GF(256)
Byte ↔ Polynomial Conversion
Every byte (0x00 to 0xFF) corresponds to a unique element of GF(256). The bit representation is read as polynomial coefficients:
Addition: XOR
Addition in GF(256) is polynomial addition with GF(2) coefficients. Since each coefficient is a bit, this is bitwise XOR, exactly as in 03a, but now with 8-bit vectors.
Multiplication: Polynomial Product mod
Multiplication is where GF(256) gets interesting. You multiply the polynomials, then reduce modulo the AES polynomial .
Checkpoint: Multiply 0x53 × 0xCA in GF(256). This is NOT integer multiplication (83 × 202 = 16766). It's polynomial multiplication reduced mod . Predict: will the result be larger or smaller than the inputs?
The xtime Operation
Multiplication by (= 0x02) is the fundamental building block. AES calls it xtime. Every GF(256) multiplication can be built from repeated xtime and XOR.
The 0x1B comes from the AES polynomial: .
General Multiplication via xtime
To multiply by an arbitrary byte, use the "Russian peasant" method: decompose one factor into powers of 2 and accumulate with xtime.
Multiplicative Inverse
Every nonzero byte has a unique multiplicative inverse in GF(256). This is the core of the AES S-box (notebook 03d).
Checkpoint: What is the inverse of 0x53 in GF(256)? It's the byte such that 0x53 × = 0x01. You can find it via the extended Euclidean algorithm (Module 04) or by Fermat's little theorem: since .
The Full Inverse Table
Let's build the complete 256-byte inverse table, this is the first step of the AES S-box construction.
Common mistake: "GF(256) multiplication is just regular multiplication mod 256." Absolutely not. Regular multiplication mod 256 produces zero divisors (e.g., ). GF(256) multiplication uses polynomial arithmetic mod an irreducible polynomial, no zero divisors, every nonzero element is invertible. That's what makes it a field, and that's why AES uses it.
The Generator and Multiplicative Group
Exercises
Exercise 1 (Worked)
Multiply 0x57 × 0x83 in GF(256) using xtime, showing each step. Verify with SageMath.
Exercise 2 (Guided)
Build the complete 256-entry exp and log tables using generator 0x03. Then implement multiplication using only table lookups (no polynomial arithmetic).
Exercise 3 (Independent)
Verify that 0x03 is a generator of GF(256)* by showing its order is 255.
Is 0x02 a generator? What is its order? Find all elements whose order divides 51 but not 17.
AES's MixColumns uses multiplication by 0x01, 0x02, and 0x03. Why are these sufficient? (Hint: in GF(256), 0x03 = 0x02 + 0x01, so multiplication by 0x03 is
xtime(b) XOR b.)
Summary
| Concept | Key idea |
|---|---|
| GF(256) | The AES field, constructed as GF(2). Elements are bytes (8-bit polynomials) |
| Addition = XOR | Adding two GF(256) elements is bitwise XOR, no reduction needed |
| Multiplication | Polynomial multiplication reduced mod . The xtime operation (multiply by ) is the fundamental building block |
| Multiplicative inverse | Every nonzero byte has a unique inverse. This is the key property that makes GF(256) a field, not just a ring |
xtime | Multiply by 0x02: shift left, and if the high bit was set, XOR with 0x1B. All GF(256) multiplications decompose into xtime and XOR |
| Exp/log tables | Using generator 0x03, multiplication becomes table lookup: |
Crypto foreshadowing: The AES S-box (notebook 03d) applies two operations to each byte: (1) take the multiplicative inverse in GF(256), then (2) apply an affine transformation over GF(2). The field inverse provides nonlinearity, the single most important property for resisting linear and differential cryptanalysis.
Next: AES S-box Construction, building the S-box from field inverses and affine maps.