This crate implements elliptic curve arithmetic and bilinear pairings for Barreto-Naehrig (BN) curves.
It was created to commemorate the 20th anniversary of the discovery of those curves in 2005.
A BN curve is specified by an integer parameter <i>u</i> ∈ ℤ such that the value
<i>p</i> ≔ 36<i>u⁴</i> + 36<i>u³</i> + 24<i>u²</i> + 6<i>u</i> + 1 is prime,
defining a finite field <b>F</b><sub><i>p</i></sub>.
The additional constraint <i>p</i> ≡ 3 (mod 4) is typical, since it enables specifying
the quadratic extension <b>F</b><sub><i>p²</i></sub> = <b>F</b><sub><i>p</i></sub>[<i>i</i>]/<<i>i²</i> + 1>
and the tower-friendly extension fields
<b>F</b><sub><i>p⁴</i></sub> ≃ <b>F</b><sub><i>p²</i></sub>[<i>σ</i>]/<<i>σ² - ξ</i>>,
<b>F</b><sub><i>p⁶</i></sub> ≃ <b>F</b><sub><i>p²</i></sub>[<i>τ</i>]/<<i>τ³ - ξ</i>>,
and <b>F</b><sub><i>p¹²</i></sub> ≃ <b>F</b><sub><i>p²</i></sub>[<i>z</i>]/<<i>z⁶ - ξ</i>>,
where <i>ξ</i> = 1 + <i>i</i>.
The BN curve equation is <i>E</i>/<b>F</b><sub><i>p</i></sub> : <i>Y²Z</i> = <i>X³ + bZ³</i>,
whose number of points is
<i>n</i> ≔ <i>#E</i>(<b>F</b><sub><i>p</i></sub>) = <i>36u⁴</i> + 36<i>u³</i> + 18<i>u²</i> + 6<i>u</i> + 1,
which is usually required (with a careful choice of the curve parameter <i>u</i>) to be prime.
The underlying finite field and the number of points are thus related as
<i>n</i> = <i>p</i> + 1 - <i>t</i> where <i>t</i> ≔ 6<i>u²</i> + 1 is the trace of the Frobenius endomorphism
on the curve.
Incidentally, the curve order satisfies <i>n</i> ≡ 5 (mod 8).
The default quadratic twist of the curve is <i>E'</i>/<b>F</b><sub><i>p²</i></sub> : <i>Y'²Z'</i> = <i>X'³ + b'Z'³</i>
with <i>b'</i> ≔ <i>b</i>/<i>ξ</i>, whose number of points is <i>n'</i> ≔
<i>#E'</i>(<b>F</b><sub><i>p²</i></sub>) = <i>h'</i><i>n</i>
where <i>h'</i> ≔ <i>p</i> - 1 + <i>t</i> is called the cofactor of the curve twist.
All supported curves were selected so that the BN curve parameter is a negative number
(so that field inversion can be replaced by conjugation at the final exponentiation of a pairing)
with absolute value of small Hamming weight (typically 5 or less),
ceil(lg(<i>p</i>)) = 64×<i>LIMBS</i> - 2 for 64-bit limbs,
and the curve equation coefficients are always <i>b</i> = 2 and <i>b'</i> = 1 - <i>i</i>.
With this choice, a suitable generator of <i>n</i>-torsion on <i>E</i>/<b>F</b><sub><i>p</i></sub>
is the point <i>G</i> ≔ [-1 : 1 : 1],
and a suitable generator of <i>n</i>-torsion on <i>E'</i>/<b>F</b><sub><i>p²</i></sub>
is the point <i>G'</i> ≔ [<i>h'</i>]<i>G₀'</i>
where <i>G₀'</i> ≔ [-<i>i</i> : 1 : 1].
The maximum supported size is <i>LIMBS</i> = 12.
All feasible care has been taken to make sure the arithmetic algorithms adopted in this crate
are isochronous ("constant-time") and efficient.
Yet, the no-warranty clause of the MIT license is in full force for this whole crate.
References:
* Paulo S. L. M. Barreto, Michael Naehrig:
"Pairing-Friendly Elliptic Curves of Prime Order."
In: Preneel, B., Tavares, S. (eds). <i>Selected Areas in Cryptography -- SAC 2005</i>.
Lecture Notes in Computer Science, vol. 3897, pp. 319--331.
Springer, Berlin, Heidelberg. 2005. https://doi.org/10.1007/11693383_22
* Geovandro C. C. F. Pereira, Marcos A. Simplicio Jr., Michael Naehrig, Paulo S. L. M. Barreto:
"A Family of Implementation-Friendly BN Elliptic Curves."
<i>Journal of Systems and Software</i>, vol. 84, no. 8, pp. 1319--1326.
Elsevier, 2011. https://doi.org/10.1016/j.jss.2011.03.083