A Crash Course in Binary Finite Fields
Prime numbers are important in cryptography mainly because of the special structure they impart to modular arithmetic. For any number , we can define sensible addition, subtraction, and multiplication operations over the elements of . But only when is prime can we also define “division” (section 3.4). In the study of abstract algebra, a set of items/objects that support addition, subtraction, multiplication, and division in the usual ways is called a field. Thus, is a field when is prime.
Computers (and computer scientists) love powers of two, so in this chapter we will see how to construct a field with elements. The elements of this field are strings from , and we will interpret each string as the encoding of a polynomial with 0/1 coefficients, and degree less than .
represents the polynomial .
Arithmetic Modulo a Polynomial: Reducing a number modulo another number means: Divide by and take the remainder. We can similarly reduce polynomials modulo another polynomial, by dividing and taking the remainder. But no one likes polynomial long division, so here's another way to think about modular reductions.
Arithmetic mod means following the logical consequences of deciding that . For example, when working mod 11, we boldly decide that 11 = 0. Hence, you can reduce 42 mod 11 as:
We can think the same way about reduction modulo a polynomial. If we are working mod , then we can boldly decide that and see what happens. But it is more convenient to rearrange this equation as:
Now you can reduce mod via:
Try the same calculation with polynomial long division and see whether you get the same answer.
Irreducible polynomials: A polynomial is irreducible if it cannot be factored as the product of lower-degree polynomials. Just as a prime modulus is special for integer arithmetic, an irreducible polynomial is special for polynomial arithmetic.
Let be an irreducible polynomial of degree . Then the binary finite field consists of the elements of . We interpret each element as the coefficients of polynomials of degree less than , and equip the elements with the following operations:
-
addition: add the polynomials, reducing coefficients mod 2.
-
multiplication: multiply the polynomials, reducing coefficients mod 2 and reducing the entire polynomial mod .
-
multiplicative inverse: (discussed below)
The definition says “the” binary finite field because the choice of doesn't really matter. That's because, for each , there is only one finite field with elements. More precisely, if we use different choices of in the definition above, then as long as they are both irreducible we will obtain fields that are isomorphic. There is only one mathematical field structure over elements, although there are many ways to encode the elements of that structure into strings.
To compute , add the corresponding polynomials and reduce mod 2:
The result is .
Addition in a binary finite field is just xor!
Let , which is irreducible. This example considers using this as the polynomial modulus.
To compute in the field, we do the following:
-
Multiply the polynomials:
-
Reduce mod :
-
Reduce coefficients mod 2:
The result is .
In the field , the element represents the all-zeros polynomial and is the neutral element with respect to addition. We sometimes write it as “0.”
The element represents the constant polynomial , and is the neutral element with respect to multiplication. We sometimes write it as “1.”
Multiplicative inverses:
The most important property in a field is that every nonzero element has a multiplicative inverse:
For every nonzero , there is an element satisfying .
We do not prove this fact here.
It is possible to efficiently compute inverses similarly to how they are computed for integers (section 3.4). Given , we can use a variant of the Euclidean GCD algorithm to compute the Bezout coefficients:
where all the variables in this case are field elements (polynomials with 0/1 coefficients), and is the polynomial modulus. Since is an irreducible polynomial, and the degree of is less than that of , the GCD is indeed 1. Reducing both sides mod shows that must be the multiplicative inverse of .
Galois fields: There is nothing terribly special about reducing coefficients mod 2; it's merely the most convenient value for computers. It is also possible to construct a finite field with elements for any prime and any , by considering polynomials with coefficients in , modulo an irreducible degree- polynomial. These are called Galois fields, after their discoverer. This is the reason for the notation .
Sage: You can manipulate finite fields in sage:
The following example establishes F as and sets X to be the formal variable of the field's polynomials. That way, you can use X to directly construct group elements. We can also see that sage has chosen the irreducible polynomial as the modulus.
Applications to cryptography: Shamir secret sharing (construction 3.5.1) and poly-UHF (construction 11.4.1) were introduced using arithmetic modulo a prime. But the math behind these constructions works in any field, including the binary finite fields discussed here. Be careful not to get confused by the polynomials appearing at two levels of the abstraction:
-
We can use polynomials to define a finite field: The elements of the field are polynomials with coefficients mod (mod 2 in the examples above); the field operations are essentially polynomial addition and multiplication mod .
-
Equipped with a finite field, we should forget that the field elements are polynomials and simply think of the field as a collection of abstract objects that support addition, subtraction, multiplication, and division. Shamir secret sharing and poly-UHF then define polynomials over the field—that is, the coefficients are field elements and addition/multiplication that appear in the polynomial are the field operations.