aboutsummaryrefslogtreecommitdiff
path: root/docs/journal/pages/field-extension.md
blob: 6995570a5db4809ddf963d2177eff4260bac2b0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
> [Index](../README.md)

# Polynomial Extension Rings

The other kind of field that is important for elliptic curve pairings are polynomial extension fields. These are just polynomial quotient rings over the curve's field modulo some irreducible monic polynomial (chosen as a parameter of the extension field). This concept is a _little_ complicated, and the Wikipedia article linked in the resources section does a decent job at explainng it (at least better than I can, as I lack a lot of the jargon required).

To try and explain it better, lets take the polynomial extension field of degree 2 used in BLS12-381 pairings. This is defined as the polynomial quotient ring `Fp[x] / (1 + x^2)`, or `Fp2` for brevity, where `Fp[x]` are polynomials over the field `Fp`. With a slightly more concrete example, imagine the polynomials `a + bx` and `c + dx` belonging to `Fp2` where `a`, `b`, `c`, `d` are elements of `Fp` and `x` is some indeterminate also belonging to `Fp`. In code we can represent the elements of `Fp2` as a tuple of two `Fp` elements `Fp.t * Fp.t` where `(a, b)` represents `a + bx`. For this field, addition and multiplication are just definied to be the addition and multiplication modulo `1 + x^2` respectively of the polynomials.

- Addition: `(a + bx) + (c + dx) = (a + c) + (b + d)x`. Since we don't create any `x^2` terms, this is already non-divisible by `1 + x^2`. Addition in these polynomial extension fields are, therefore, very straight forward: `(a, b) + (c, d) = (a + b, c + d)`.
- Multiplication: `(a + bx) * (c + dx) = ac + adx + bcx + bdx^2`. This must be taken modulo `1 + x^2`, so `ac + adx + bcx + bdx^2 =~ ac + adx + bcx + bdx^2 - bd(1 + x^2) =~ (ac - bd) + (ad + bc)x`. Multiplication over `Fp2` is therefore `(a, b) * (c, d) = (ac - bd, ad + bc)`. Look familiar? It is the same as complex number multiplication - which isn't a coincidence as the complex numbers are an extension field of degree 2 over the real numbers.

This same concept can be extended to polynomial extension fields of any degree, and in particular a polynomial extension field of degree 12 is also used for elliptic curve pairings (but with a different irreducible monic polynomial):

- Addition: this can be trivially extended to component-wise adding the coefficients of the polynomials together.
- Multiplication: this is a little more complicated, but the general idea is:
  1. You first multiply out the polynomials and get a result of degree `2d - 1` where `d` is the degree of the polynomial extension field.
  2. Starting from the highest degree term, you subtract multiples of the irreducible polynomial until you have a polynomial of degree `d - 1` or less. Since the irreducible polynomial monic, in each iteration you subtract the component-wise multiplication of the `i`th degree term from the polynomial computed in step 1.

Computing additive and multiplicative inverses are done by:

- Additive inverse: this is just the component-wise additive inverse of the polynomial coeficients: `-(a + bx) = -a + (-b)x`.
- Multiplicative inverse: this is a little more complicated, but can be done using the extended euclidean algorithm and Bézout's identity.

# Resources

- [Polynomial Ring](https://en.wikipedia.org/wiki/Polynomial_ring)
- [Extended Euclidean Algorithm](https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Simple_algebraic_field_extensions)
- [Euclidean Division](https://en.wikipedia.org/wiki/Polynomial_greatest_common_divisor#Euclidean_division)

> [Index](../README.md)