Skip to main content

Module poly_basis

Module poly_basis 

Source
Expand description

GF(2^128) in the polynomial basis of x^128 + x^7 + x^2 + x + 1.

BinaryField128 stores its elements in the tower basis, and a product there is a change of basis on each operand, a carryless multiply, and a change of basis back — three table-driven conversions of sixteen dependent lookups each, which dominate the multiply. Code that performs many products on the same data can pay the conversion once at each end instead, and multiply through mul in between.

Addition is XOR in either basis, so a sum needs no conversion at all: only products and squares do, which is what this module supplies. An element is carried as the u128 of its coordinates, deliberately not as a field type — the two bases are indistinguishable once wrapped, and a value that reaches ordinary BinaryField128 arithmetic in the wrong one is silently wrong rather than ill-typed.

Constants§

HAS_HARDWARE_CLMUL
Whether mul and square compile down to a hardware carryless multiply.

Functions§

from_tower
The polynomial-basis coordinates of a tower element.
mul
The product of two elements, both given and returned in the polynomial basis.
square
The square of an element, given and returned in the polynomial basis.
to_tower
The tower element with the given polynomial-basis coordinates.