Rijndael Finite Field
A first time reader might skip this section and go directly to the description of the round transformations, then come back later (it is mostly useful to understand the construction of the operation MC and SB).
Each byte in AES is viewed as an element of a binary finite field of 256 elements, where it can always be represented as a polynomial of degree at most 7 with coefficients inF2. The construction of the finite field is made as the quotient ringF2[x]/f(x), wherefis an irreducible polynomial of degree 8 inF2[x]so the ring becomes a field.
In AES, the choice forfis
We can check with SageMath that it is irreducible:
F2 = GF(2)
K.<x> = F2[]
f = x^8 + x^4 + x^3 + x + 1
f.is_irreducible()
# TrueMatching Bytes as Finite Field Elements
A byte b is composed of 8 bits (b7,…,b0)2 and is matched to a polynomial as
For instance, take the byte 3a whose binary decomposition is (0,0,1,1,1,0,1,0)2 and becomes the polynomial
Polynomial Reduction
Polynomials of degree 8 or more can always be reduced, using the fact that in the finite field, we have f(x)=0 , so we have the relation
Why not x8=−x4−x3−x−1? In fact, that's also true, but the coefficient are in F2 so the additive inverse−1 of 1 is itself.
In SageMath, this reduction can be produced in one of the following methods.
Method 1: Remainder of an Euclidean division by f
Method 2: Image in the quotient ring F2[x]/f(x)
Method 3: Using the Finite Field class of SageMath directly.
On this page we use this last method. Also, this helper converts an element of the finite field to the hexadecimal representation of a byte, and could be useful in the examples:
Addition
The addition of two polynomials is done by adding the coefficients corresponding of each monomial:
And as the addition of the coefficients is inF2, it corresponds to the bitwise xor operation on the byte.
Multiplication
Multiplication of two polynomials is more complex (one example would be the Karatsuba algorithm, more efficient than the naive algorithm). For an implementation of AES, it is possible to only use the multiplication by x, whose byte representation is 02.
Letb7x7+⋯+b1x+b0an element and we consider the multiplication byx:
All coefficients are shifted to a monomial one degree higher. Then, there are two cases:
Ifb7is0, then we have a polynomial of degree at most 7 and we are done;
Ifb7is1, we can replacex8byx4+x3+x+1during the reduction phase:
This can be used to implement a very efficient multiplication byxwith the byte representation:
A bitwise shiftleft operation:
(b << 1) & 0xff;Followed by a conditional addition with
1bif the top bit of b is 1.
Here an example in SageMath (we use the finite field construction of method 3):
Last updated
Was this helpful?