CSS411 Cryptography

Finite Fields (Galois Field)

Finite field rules, GF(p) arithmetic, polynomials over GF(2), irreducible and primitive polynomials, the construction of GF(2^m), conjugates and minimal polynomials.

32 min read

Finite field basicsSearch on YouTube

DefinitionSearch on YouTube

A finite field is also called a Galois field. The course notes name the mathematician "Pierre Galois". His real name is Évariste Galois. A Galois field with qq elements has the name GF(q)GF(q).

A finite field has these formal properties:

  • It has two defined operations: addition and multiplication.
  • The sum or product of two field elements is always a field element (closure).
  • It has a zero element: a+0=aa + 0 = a.
  • It has a unity element: a⋅1=aa \cdot 1 = a.
  • Each element aa has an additive inverse −a-a, with a+(−a)=0a + (-a) = 0. Subtraction is addition of the inverse.
  • Each non-zero element bb has a multiplicative inverse b−1b^{-1}, with b⋅b−1=1b \cdot b^{-1} = 1. Division is multiplication by the inverse.
  • The associative, commutative and distributive laws apply.
a+(b+c)=(a+b)+c,a⋅(b⋅c)=(a⋅b)⋅c,a⋅(b+c)=a⋅b+a⋅ca+(b+c)=(a+b)+c, \quad a\cdot(b\cdot c)=(a\cdot b)\cdot c, \quad a\cdot(b+c)=a\cdot b+a\cdot c

Field sizesSearch on YouTube

Not all field sizes can satisfy these properties. They are satisfied when the field size is a prime number or an integer power of a prime.

AES uses GF(28)GF(2^8). The size 28=2562^8 = 256 is a power of the prime 2, so a field of this size exists.

Prime size field GF(p)Search on YouTube

Arithmetic modulo pSearch on YouTube

For a field with a prime number pp of elements, do the arithmetic modulo pp. Take two elements in the range 00 to p−1p-1. Add or multiply them. Then take the result modulo pp.

  • GF(2): modulo-2 addition and multiplication. The elements are 0 and 1.
  • GF(3): the elements are 0, 1 and 2.

In GF(3), the additive inverse of 0 is 0. The additive inverse of 1 is 2, and the additive inverse of 2 is 1. To find a multiplicative inverse, find the pair of elements with product 1 in the table. In GF(3), 1−1=11^{-1} = 1 and 2−1=22^{-1} = 2, because 2⋅2=4≡1(mod3)2 \cdot 2 = 4 \equiv 1 \pmod 3.

Primitive elementSearch on YouTube

In each prime size field, at least one element has powers that give all the non-zero elements. This element is primitive. In GF(7)GF(7), the number 3 is primitive:

31=3, 32=2, 33=6, 34=4, 35=5, 36=1(mod7)3^1=3,\ 3^2=2,\ 3^3=6,\ 3^4=4,\ 3^5=5,\ 3^6=1 \pmod 7

Higher powers of 3 repeat the pattern, because 36=13^6 = 1. You can multiply two elements if you add their powers of 3:

6×2=33×32=35=56 \times 2 = 3^3 \times 3^2 = 3^5 = 5

The multiplicative inverse of 3i3^i is 3−i=36−i3^{-i} = 3^{6-i}. In GF(7):

  • The inverse of 66 (333^3) is 66 (333^3).
  • The inverse of 44 (343^4) is 22 (323^2).
  • The inverse of 55 (353^5) is 33 (313^1).

GF(7) subtraction and divisionSearch on YouTube

Example 3 builds the addition and multiplication tables of GF(7) with the elements 0 to 6. Use the addition table also for subtraction. Use the multiplication table for division.

  • Subtract 6 from 3. The additive inverse of 6 is 1. Thus 3−6=3+1=43 - 6 = 3 + 1 = 4.
  • Divide 3 by 2. The multiplicative inverse of 2 is 4. Thus 3÷2=3⋅4=12≡53 \div 2 = 3 \cdot 4 = 12 \equiv 5.

In a finite field, "minus" means "add the additive inverse". "Divide" means "multiply by the multiplicative inverse". Do not use ordinary integer subtraction or division.

Polynomials over GF(2)Search on YouTube

Degree and countSearch on YouTube

A polynomial over GF(2) has coefficients from GF(2):

f(X)=f0+f1X+f2X2+⋯+fnXn,fi=0 or 1f(X) = f_0 + f_1 X + f_2 X^2 + \cdots + f_n X^n, \qquad f_i = 0 \text{ or } 1

The degree is the largest power of XX with a non-zero coefficient. If fn=1f_n = 1, f(X)f(X) has degree nn. The degree of f(X)=f0f(X) = f_0 is zero.

  • Degree 1 has two polynomials: XX and 1+X1 + X.
  • Degree 2 has four polynomials: X2X^2, 1+X21 + X^2, X+X2X + X^2 and 1+X+X21 + X + X^2.
  • In general, degree nn has 2n2^n polynomials.

AdditionSearch on YouTube

To add f(X)f(X) and g(X)g(X), add the coefficients of the same power of XX modulo 2. Subtraction gives the same result, because 1+1=01 + 1 = 0.

Example 6. Add a(X)=1+X+X3+X5a(X) = 1 + X + X^3 + X^5 and b(X)=1+X2+X3+X4+X7b(X) = 1 + X^2 + X^3 + X^4 + X^7:

a(X)+b(X)=(1+1)+X+X2+(1+1)X3+X4+X5+X7=X+X2+X4+X5+X7a(X) + b(X) = (1+1) + X + X^2 + (1+1)X^3 + X^4 + X^5 + X^7 = X + X^2 + X^4 + X^5 + X^7

DivisionSearch on YouTube

When you divide f(X)f(X) by g(X)g(X), you get one pair of polynomials: the quotient q(X)q(X) and the remainder r(X)r(X):

f(X)=q(X) g(X)+r(X),deg⁡r(X)<deg⁡g(X)f(X) = q(X)\,g(X) + r(X), \qquad \deg r(X) < \deg g(X)

Example 7. Divide f(X)=1+X+X4+X5+X6f(X) = 1 + X + X^4 + X^5 + X^6 by g(X)=1+X+X3g(X) = 1 + X + X^3.

  1. X6÷X3=X3X^6 \div X^3 = X^3. Subtract X3g(X)=X6+X4+X3X^3 g(X) = X^6 + X^4 + X^3. The result is X5+X3+X+1X^5 + X^3 + X + 1.
  2. X5÷X3=X2X^5 \div X^3 = X^2. Subtract X2g(X)=X5+X3+X2X^2 g(X) = X^5 + X^3 + X^2. The result is X2+X+1X^2 + X + 1.
  3. The degree is now less than 3, so the division stops.
q(X)=X3+X2,r(X)=X2+X+1q(X) = X^3 + X^2, \qquad r(X) = X^2 + X + 1

Check: X6+X5+X4+X+1=(X3+X2)(X3+X+1)+X2+X+1X^6 + X^5 + X^4 + X + 1 = (X^3 + X^2)(X^3 + X + 1) + X^2 + X + 1.

If r(X)=0r(X) = 0, then f(X)f(X) is divisible by g(X)g(X), and g(X)g(X) is a factor of f(X)f(X).

Roots and the X + 1 factorSearch on YouTube

For real numbers, if aa is a root of f(X)f(X), then f(X)f(X) is divisible by X−aX - a. The same rule applies over GF(2).

Example 8. Let f(X)=1+X2+X3+X4f(X) = 1 + X^2 + X^3 + X^4. Put X=1X = 1:

f(1)=1+1+1+1=0f(1) = 1 + 1 + 1 + 1 = 0

Thus 1 is a root, and f(X)f(X) is divisible by X+1X + 1. The long division gives:

X4+X3+X2+1=(X+1)(X3+X+1)X^4 + X^3 + X^2 + 1 = (X + 1)(X^3 + X + 1)

Even-terms rule: a polynomial over GF(2) with an even number of terms is divisible by X+1X + 1.

Irreducible polynomialsSearch on YouTube

DefinitionSearch on YouTube

A polynomial p(X)p(X) over GF(2) of degree mm is irreducible if it has no factor of lower degree. The factor degree must be greater than zero and less than mm.

Example 9. Check the four polynomials of degree 2:

  • X2X^2 and X2+XX^2 + X are divisible by XX.
  • X2+1X^2 + 1 is divisible by X+1X + 1.
  • X2+X+1X^2 + X + 1 has no root at 0 or 1. Thus no degree-1 polynomial divides it. It is irreducible.

Homework from the notes: check if X3+X+1X^3 + X + 1 is irreducible over GF(2). Put X=0X = 0: the result is 1. Put X=1X = 1: the result is 1+1+1=11 + 1 + 1 = 1. It has no degree-1 factor. A degree-3 polynomial that has a factor must have a degree-1 factor. Thus X3+X+1X^3 + X + 1 is irreducible.

Divisor of X^(2^m - 1) + 1Search on YouTube

For each m≥1m \geq 1, an irreducible polynomial of degree mm exists that divides X2m−1+1X^{2^m - 1} + 1.

Example 10. X3+X+1X^3 + X + 1 divides X23−1+1=X7+1X^{2^3 - 1} + 1 = X^7 + 1. The long division gives:

X7+1=(X3+X+1)(X4+X2+X+1)X^7 + 1 = (X^3 + X + 1)(X^4 + X^2 + X + 1)

Primitive polynomialsSearch on YouTube

DefinitionSearch on YouTube

An irreducible polynomial p(X)p(X) of degree mm is primitive if the smallest positive nn for which p(X)p(X) divides Xn+1X^n + 1 is n=2m−1n = 2^m - 1.

  • X4+X+1X^4 + X + 1 divides X15+1X^{15} + 1. It does not divide Xn+1X^n + 1 for 1≤n<151 \leq n < 15. Thus it is primitive.
  • X4+X3+X2+X+1X^4 + X^3 + X^2 + X + 1 is irreducible. It divides X5+1X^5 + 1, so it is not primitive.

Primitive test: degree mm, first divisor of X2m−1+1X^{2^m - 1} + 1. For m=4m = 4, the first nn must be 15. If a smaller nn works, the polynomial is not primitive.

Primitive polynomial tableSearch on YouTube

It is not easy to find a primitive polynomial. Tables of irreducible polynomials show which ones are primitive. One degree mm can have more than one primitive polynomial. Some entries from the table in the notes:

mmPrimitive polynomialmmPrimitive polynomial
31+X+X31 + X + X^381+X2+X3+X4+X81 + X^2 + X^3 + X^4 + X^8
41+X+X41 + X + X^491+X4+X91 + X^4 + X^9
51+X2+X51 + X^2 + X^5101+X3+X101 + X^3 + X^{10}
61+X+X61 + X + X^6111+X2+X111 + X^2 + X^{11}
71+X3+X71 + X^3 + X^7121+X+X4+X6+X121 + X + X^4 + X^6 + X^{12}

Construction of GF(2^m)Search on YouTube

Powers of alphaSearch on YouTube

Start with the elements 0 and 1 from GF(2) and a new symbol α\alpha. Define a multiplication "⋅\cdot" with these rules:

0⋅αj=0,1⋅αj=αj,αi⋅αj=αi+j0 \cdot \alpha^j = 0, \qquad 1 \cdot \alpha^j = \alpha^j, \qquad \alpha^i \cdot \alpha^j = \alpha^{i+j}

Here αj=α⋅α⋯α\alpha^j = \alpha \cdot \alpha \cdots \alpha (jj times). This gives the set:

F={0,1,α,α2,…,αj,…}F = \{0, 1, \alpha, \alpha^2, \ldots, \alpha^j, \ldots\}

Closing the setSearch on YouTube

Let p(X)p(X) be a primitive polynomial of degree mm, and set p(α)=0p(\alpha) = 0. Because p(X)p(X) divides X2m−1+1X^{2^m - 1} + 1:

X2m−1+1=q(X) p(X)X^{2^m - 1} + 1 = q(X)\,p(X)

Put X=αX = \alpha. Because p(α)=0p(\alpha) = 0, the right side is 0. Thus:

α2m−1+1=0⇒α2m−1=1\alpha^{2^m - 1} + 1 = 0 \quad \Rightarrow \quad \alpha^{2^m - 1} = 1

The powers repeat after 2m−12^m - 1 steps. The set becomes finite:

F∗={0,1,α,α2,…,α2m−2}F^* = \{0, 1, \alpha, \alpha^2, \ldots, \alpha^{2^m - 2}\}

F∗F^* is a Galois field of 2m2^m elements, GF(2m)GF(2^m). GF(2) is a subfield of GF(2m)GF(2^m).

GF(2^4) exampleSearch on YouTube

Example 11. Let m=4m = 4 and p(X)=1+X+X4p(X) = 1 + X + X^4, a primitive polynomial. Set p(α)=0p(\alpha) = 0. Then:

α4=1+α\alpha^4 = 1 + \alpha

Use this identity again and again to write each power as a polynomial of degree 3 or less:

PowerPolynomialPowerPolynomial
0000α7\alpha^71+α+α31 + \alpha + \alpha^3
1111α8\alpha^81+α21 + \alpha^2
α\alphaα\alphaα9\alpha^9α+α3\alpha + \alpha^3
α2\alpha^2α2\alpha^2α10\alpha^{10}1+α+α21 + \alpha + \alpha^2
α3\alpha^3α3\alpha^3α11\alpha^{11}α+α2+α3\alpha + \alpha^2 + \alpha^3
α4\alpha^41+α1 + \alphaα12\alpha^{12}1+α+α2+α31 + \alpha + \alpha^2 + \alpha^3
α5\alpha^5α+α2\alpha + \alpha^2α13\alpha^{13}1+α2+α31 + \alpha^2 + \alpha^3
α6\alpha^6α2+α3\alpha^2 + \alpha^3α14\alpha^{14}1+α31 + \alpha^3

The next power is α15=1\alpha^{15} = 1. The field has 15 non-zero elements and 0, so it has 16 elements.

In GF(24)GF(2^4): αi⋅αj=α(i+j) mod 15\alpha^i \cdot \alpha^j = \alpha^{(i+j) \bmod 15}, and the inverse of αi\alpha^i is α15−i\alpha^{15-i}. To add two elements, add their polynomial forms modulo 2.

Roots in GF(2^m)Search on YouTube

Roots in an extension fieldSearch on YouTube

A polynomial with real coefficients can have roots that are not real. An example is X2+6X+25X^2 + 6X + 25, with the complex roots −3+4j-3 + 4j and −3−4j-3 - 4j. Similarly, a polynomial over GF(2) can have no roots in GF(2), but have roots in an extension field of GF(2).

Example 12. X4+X3+1X^4 + X^3 + 1 is irreducible over GF(2), so it has no roots in GF(2). It has four roots in GF(24)GF(2^4): α7\alpha^7, α11\alpha^{11}, α13\alpha^{13} and α14\alpha^{14}. To verify, multiply out the product with the GF(16) table:

(X+α7)(X+α11)(X+α13)(X+α14)=X4+X3+1(X + \alpha^7)(X + \alpha^{11})(X + \alpha^{13})(X + \alpha^{14}) = X^4 + X^3 + 1

ConjugatesSearch on YouTube

Let f(X)f(X) be a polynomial over GF(2), and let β\beta be an element in an extension field of GF(2). If β\beta is a root of f(X)f(X), then β2l\beta^{2^l} is also a root for each l≥0l \geq 0. The element β2l\beta^{2^l} is a conjugate of β\beta.

Example. f(X)=1+X3+X4+X5+X6f(X) = 1 + X^3 + X^4 + X^5 + X^6 has α4\alpha^4 as a root. With α15=1\alpha^{15} = 1:

f(α4)=1+α12+α+α5+α9=1+(1+α+α2+α3)+α+(α+α2)+(α+α3)=0f(\alpha^4) = 1 + \alpha^{12} + \alpha + \alpha^5 + \alpha^9 = 1 + (1 + \alpha + \alpha^2 + \alpha^3) + \alpha + (\alpha + \alpha^2) + (\alpha + \alpha^3) = 0

The conjugates of α4\alpha^4 are α8\alpha^8, α16=α\alpha^{16} = \alpha and α32=α2\alpha^{32} = \alpha^2. Thus α8\alpha^8, α\alpha and α2\alpha^2 are also roots of f(X)f(X). The element α5\alpha^5 and its conjugate α10\alpha^{10} are also roots.

Roots of X^(2^m - 1) + 1Search on YouTube

Let β\beta be a non-zero element of GF(2m)GF(2^m). Then β2m−1=1\beta^{2^m - 1} = 1, so β2m−1+1=0\beta^{2^m - 1} + 1 = 0. Thus each non-zero element of GF(2m)GF(2^m) is a root of X2m−1+1X^{2^m - 1} + 1. This polynomial has degree 2m−12^m - 1. Thus the 2m−12^m - 1 non-zero elements are all its roots.

Minimal polynomialsSearch on YouTube

Definition and rulesSearch on YouTube

The minimal polynomial ϕ(X)\phi(X) of a field element β\beta is the polynomial of smallest degree over GF(2) with β\beta as a root.

  • The minimal polynomial of a field element is irreducible.
  • Let β\beta be a root of a polynomial f(X)f(X) over GF(2). Then f(X)f(X) is divisible by ϕ(X)\phi(X).
  • An element and its conjugates have the same minimal polynomial.

Minimal polynomial of alpha^3Search on YouTube

Example 13. In GF(24)GF(2^4), let β=α3\beta = \alpha^3. The conjugates are β2=α6\beta^2 = \alpha^6, β4=α12\beta^{4} = \alpha^{12} and β8=α24=α9\beta^{8} = \alpha^{24} = \alpha^9. Thus:

ϕ(X)=(X+α3)(X+α6)(X+α12)(X+α9)\phi(X) = (X + \alpha^3)(X + \alpha^6)(X + \alpha^{12})(X + \alpha^9)

Multiply out the product with the GF(16) table:

ϕ(X)=(X2+α2X+α9)(X2+α8X+α6)=X4+X3+X2+X+1\phi(X) = (X^2 + \alpha^2 X + \alpha^9)(X^2 + \alpha^8 X + \alpha^6) = X^4 + X^3 + X^2 + X + 1

Minimal polynomials of GF(2^4)Search on YouTube

The minimal polynomials of all elements in GF(24)GF(2^4), made by p(X)=X4+X+1p(X) = X^4 + X + 1:

Conjugate rootsMinimal polynomial
00XX
11X+1X + 1
α,α2,α4,α8\alpha, \alpha^2, \alpha^4, \alpha^8X4+X+1X^4 + X + 1
α3,α6,α9,α12\alpha^3, \alpha^6, \alpha^9, \alpha^{12}X4+X3+X2+X+1X^4 + X^3 + X^2 + X + 1
α5,α10\alpha^5, \alpha^{10}X2+X+1X^2 + X + 1
α7,α11,α13,α14\alpha^7, \alpha^{11}, \alpha^{13}, \alpha^{14}X4+X3+1X^4 + X^3 + 1

The elements of GF(2m)GF(2^m) are polynomials over GF(2) modulo p(X)p(X). They are not integers modulo 2m2^m. For example, α4\alpha^4 and 1+α1 + \alpha are the same element.

AES uses GF(28)GF(2^8), which is made in the same way. It uses the irreducible polynomial:

m(x)=x8+x4+x3+x+1={11B}m(x) = x^8 + x^4 + x^3 + x + 1 = \{11B\}

The AES S-box and MixColumns do their calculations in this field. The AES lecture shows the five roles of field arithmetic in the cipher.

Quick self-testSearch on YouTube

Which field sizes give a finite field?

A prime number or an integer power of a prime. AES uses 282^8, a power of the prime 2.

Calculate 3 − 6 and 3 ÷ 2 in GF(7).

The additive inverse of 6 is 1, so 3−6=3+1=43 - 6 = 3 + 1 = 4. The multiplicative inverse of 2 is 4, so 3÷2=3⋅4=12≡53 \div 2 = 3 \cdot 4 = 12 \equiv 5.

Why is 3 primitive in GF(7)?

The powers 313^1 to 363^6 give 3, 2, 6, 4, 5, 1. These are all six non-zero elements.

Divide 1+X+X4+X5+X61 + X + X^4 + X^5 + X^6 by 1+X+X31 + X + X^3 over GF(2).

The quotient is X3+X2X^3 + X^2. The remainder is X2+X+1X^2 + X + 1.

Is 1+X2+X3+X41 + X^2 + X^3 + X^4 divisible by X+1X + 1?

Yes. It has an even number of terms, so f(1)=0f(1) = 0. The quotient is X3+X+1X^3 + X + 1.

Which degree-2 polynomial over GF(2) is irreducible?

Only X2+X+1X^2 + X + 1. It has no root at 0 or 1. X2X^2 and X2+XX^2 + X are divisible by XX. X2+1X^2 + 1 is divisible by X+1X + 1.

Why is X4+X+1X^4 + X + 1 primitive, but X4+X3+X2+X+1X^4 + X^3 + X^2 + X + 1 is not?

X4+X+1X^4 + X + 1 first divides Xn+1X^n + 1 at n=15=24−1n = 15 = 2^4 - 1. The other polynomial already divides X5+1X^5 + 1.

How do you build GF(16) from p(X)=1+X+X4p(X) = 1 + X + X^4?

Set p(α)=0p(\alpha) = 0, so α4=1+α\alpha^4 = 1 + \alpha. Use this identity to write α0\alpha^0 to α14\alpha^{14} as polynomials of degree 3 or less. Then α15=1\alpha^{15} = 1, and the field has 16 elements with 0.

What are the conjugates of α3\alpha^3 in GF(16), and what is its minimal polynomial?

The conjugates are α6\alpha^6, α12\alpha^{12} and α9\alpha^9. The minimal polynomial is X4+X3+X2+X+1X^4 + X^3 + X^2 + X + 1.

Give the roots of X4+X3+1X^4 + X^3 + 1 in GF(16).

α7\alpha^7, α11\alpha^{11}, α13\alpha^{13} and α14\alpha^{14}. They are conjugates of each other.

  • A finite field (Galois field) exists for a prime size or a prime power size. Subtraction and division use the inverses.
  • GF(p)GF(p) uses arithmetic modulo pp. In GF(7), 3 is primitive, so products become sums of powers.
  • Polynomials over GF(2) add with coefficients modulo 2. Division gives a quotient and a remainder.
  • An even number of terms means the polynomial is divisible by X+1X + 1.
  • An irreducible polynomial has no factor of lower degree. A primitive polynomial of degree mm first divides X2m−1+1X^{2^m-1}+1.
  • Set p(α)=0p(\alpha) = 0 for a primitive p(X)p(X) to build GF(2m)GF(2^m). For GF(24)GF(2^4), α4=1+α\alpha^4 = 1 + \alpha and α15=1\alpha^{15} = 1.
  • If β\beta is a root, its conjugates β2l\beta^{2^l} are also roots. Conjugates share one irreducible minimal polynomial.
  • AES works in GF(28)GF(2^8) modulo {11B}\{11B\}.