Galois Fields for Cryptography
What “GF” means and why cryptographers care.
a ^ b. Multiplication by \(X\) is (a << 1) ^ (0x1B if a & 0x80 else 0). No big-integer libraries needed.The building blocks of GF(\(2^m\)).
100110x53 \(=\) 01010011 represents \(X^6 + X^4 + X + 1\)0x00 represents the zero polynomial0x01 represents the constant polynomial 1| Polynomial | Binary | Hex |
|---|---|---|
| \(0\) | 00000000 |
0x00 |
| \(1\) | 00000001 |
0x01 |
| \(X\) | 00000010 |
0x02 |
| \(X + 1\) | 00000011 |
0x03 |
| \(X^2 + X + 1\) | 00000111 |
0x07 |
| \(X^6 + X^4 + X + 1\) | 01010011 |
0x53 |
| \(X^4 + X^3 + X + 1\) (AES reduction constant) | 00011011 |
0x1B |
| \(X^7 + X^6 + \ldots + X + 1\) | 11111111 |
0xFF |
10011 \(\oplus\) 11001 \(=\) 010100x07 \(\times\) 0x05 in GF(\(2^8\)), i.e. \((X^2 + X + 1) \times (X^2 + 1)\):The analogue of “mod a prime” for polynomials.
When a product has degree \(\geq m\), we reduce it modulo \(p(X)\)
The key trick: since \(p(X) \equiv 0\) in our field, \(X^m \equiv\) (lower-degree terms of \(p(X)\))
Example in GF(\(2^4\)) with \(p(X) = X^4 + X + 1\):
\[ \begin{aligned} X^5 + X^3 + X + 1 &= X \cdot X^4 + X^3 + X + 1 \\ &\equiv X \cdot (X + 1) + X^3 + X + 1 \\ &= X^2 + X + X^3 + X + 1 \\ &= X^3 + X^2 + 1 \end{aligned} \]
101011 \(\to\) 001101 = 0xD in GF(\(2^4\))0 through F)0x7 \(\times\) 0x5 in GF(\(2^4\)):
0x80x6\(^{-1}\) = 0x7, because 0x6 \(\times\) 0x7 = 0x1)
| \(\times\) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 2 | 2 | 4 | 6 | 8 | A | C | E |
| 3 | 3 | 6 | 5 | C | F | A | 9 |
| 4 | 4 | 8 | C | 3 | 7 | B | F |
| 5 | 5 | A | F | 7 | 2 | D | 8 |
| 6 | 6 | C | A | B | D | 7 | 1 |
| 7 | 7 | E | 9 | F | 8 | 1 | 6 |
What AES is actually doing byte-by-byte.
0x11B (the 9-bit pattern 100011011)0x63)\[ \begin{pmatrix} b_0 \\ b_1 \\ b_2 \\ b_3 \end{pmatrix} = \begin{pmatrix} 2 & 3 & 1 & 1 \\ 1 & 2 & 3 & 1 \\ 1 & 1 & 2 & 3 \\ 3 & 1 & 1 & 2 \end{pmatrix} \begin{pmatrix} a_0 \\ a_1 \\ a_2 \\ a_3 \end{pmatrix} \]
xtime operation (next slide), \(3\) = xtime \(\oplus\) originalxtime\((a)\) multiplies \(a\) by \(X\) in GF(\(2^8\)), i.e. “multiply by 2”
This is the fundamental building block: multiply by any constant via repeated xtime + XOR
What GHASH is actually doing block-by-block.
0x1B0x87PCLMULQDQ instruction performs 64-bit carryless (polynomial) multiplication
PCLMULQDQ operations produce the 256-bit unreduced productPMULL / PMULL2 (polynomial multiply long)The same pattern, different fields.
PCLMULQDQ / PMULL hardware| Notation | Meaning | Used in |
|---|---|---|
| GF(\(2\)) | \(\{0, 1\}\) with XOR and AND | Everywhere (bits) |
| GF(\(2^8\)) | Bytes with polynomial arithmetic mod \(X^8 + X^4 + X^3 + X + 1\) | Block Ciphers (AES) |
| GF(\(2^{128}\)) | 128-bit blocks with polynomial arithmetic mod \(X^{128} + X^7 + X^2 + X + 1\) | AEAD (GCM/GHASH) |
| Irreducible polynomial | Analogue of a prime number for polynomial rings | AES, GCM |
xtime |
Multiply by \(X\) in GF(\(2^8\)): left shift + conditional XOR 0x1B |
AES (MixColumns) |
PCLMULQDQ |
Hardware carryless (polynomial) multiplication | GCM performance |
| \(\mathbb{Z}_{2^{130}-5}\) | Prime field for Poly1305 (ordinary modular arithmetic) | ChaCha20-Poly1305 |