ffrs.GF256¶
- class ffrs.GF256¶
Finite-field operations optimized for \(GF(2^8)\)
Methods
Instantiate type for operations over \(GF(p^n)/P\)
Addition: \(\text{lhs} + \text{rhs}\)
Division: \(\frac{\text{num}}{\text{den}}\)
Exponential function: \(a^{\text{value}}\)
Reciprocal: \(\frac{1}{\text{value}}\)
Logarithm: \(\log_a (\text{value})\)
Multiplication: \(\text{lhs} \times \text{rhs}\)
Multiply 8 values in a single operation
Add polynomials
Polynomial quotient and remainder
Evaluate polynomial at
xEvaluate polynomial at 8 points on a single operation
Polynomial remainder
Shifted polynomial remainder
Multiply polynomials
Subtract polynomials
Power: \(\text{base}^\text{exponent}\)
Subtraction: \(\text{lhs} - \text{rhs}\)
Attributes
GF256.field_elementsAlways 256
GF256.poly1Masked irreducible polynomial, excluding MSb
GF256.powerAlways 8
GF256.primeAlways 2
GF256.primitivePrimitive value used to generate the field
- __init__(self: libffrs.GF256, primitive: SupportsInt | SupportsIndex = 2, poly1: SupportsInt | SupportsIndex = 285) None¶
Instantiate type for operations over \(GF(p^n)/P\)
- Parameters:
primitive – \(a\) – primitive value used to generate the field
polynomial – \(P\) – irreducible polynomial used to generate the field
- add(self: libffrs.GF256, lhs: SupportsInt | SupportsIndex, rhs: SupportsInt | SupportsIndex) int¶
Addition: \(\text{lhs} + \text{rhs}\)
- div(self: libffrs.GF256, num: SupportsInt | SupportsIndex, den: SupportsInt | SupportsIndex) int¶
Division: \(\frac{\text{num}}{\text{den}}\)
- exp(self: libffrs.GF256, value: SupportsInt | SupportsIndex) int¶
Exponential function: \(a^{\text{value}}\)
- inv(self: libffrs.GF256, value: SupportsInt | SupportsIndex) int¶
Reciprocal: \(\frac{1}{\text{value}}\)
- log(self: libffrs.GF256, value: SupportsInt | SupportsIndex) int¶
Logarithm: \(\log_a (\text{value})\)
- mul(self: libffrs.GF256, lhs: SupportsInt | SupportsIndex, rhs: SupportsInt | SupportsIndex) int¶
Multiplication: \(\text{lhs} \times \text{rhs}\)
- mul8(self: libffrs.GF256, a: collections.abc.Buffer, b: collections.abc.Buffer) bytearray¶
Multiply 8 values in a single operation
- poly_add(self: libffrs.GF256, p1: collections.abc.Buffer, p2: collections.abc.Buffer) bytearray¶
Add polynomials
- poly_divmod(self: libffrs.GF256, p1: collections.abc.Buffer, p2: collections.abc.Buffer) tuple¶
Polynomial quotient and remainder
- Returns:
(quotient, remainder)
- poly_eval(self: libffrs.GF256, poly: collections.abc.Buffer, x: SupportsInt | SupportsIndex) int¶
Evaluate polynomial at
x
- poly_eval8(self: libffrs.GF256, poly: collections.abc.Buffer, xs: collections.abc.Buffer) bytearray¶
Evaluate polynomial at 8 points on a single operation
- poly_mod(self: libffrs.GF256, p1: collections.abc.Buffer, p2: collections.abc.Buffer) bytearray¶
Polynomial remainder
- poly_mod_x_n(self: libffrs.GF256, p1: collections.abc.Buffer, p2: collections.abc.Buffer) bytearray¶
Shifted polynomial remainder
\(P \times X^n \mod (X^n + p_2)\) where
n = len(p2)
- poly_mul(self: libffrs.GF256, p1: collections.abc.Buffer, p2: collections.abc.Buffer) bytearray¶
Multiply polynomials
- poly_sub(self: libffrs.GF256, p1: collections.abc.Buffer, p2: collections.abc.Buffer) bytearray¶
Subtract polynomials
- pow(self: libffrs.GF256, base: SupportsInt | SupportsIndex, exponent: SupportsInt | SupportsIndex) int¶
Power: \(\text{base}^\text{exponent}\)
- sub(self: libffrs.GF256, lhs: SupportsInt | SupportsIndex, rhs: SupportsInt | SupportsIndex) int¶
Subtraction: \(\text{lhs} - \text{rhs}\)