libffrs.GF256

class libffrs.GF256

Finite-field operations optimized for \(GF(2^8)\)

Methods

GF256.__init__

Instantiate type for operations over \(GF(p^n)/P\)

GF256.add

Addition: \(\text{lhs} + \text{rhs}\)

GF256.div

Division: \(\frac{\text{num}}{\text{den}}\)

GF256.exp

Exponential function: \(a^{\text{value}}\)

GF256.inv

Reciprocal: \(\frac{1}{\text{value}}\)

GF256.log

Logarithm: \(\log_a (\text{value})\)

GF256.mul

Multiplication: \(\text{lhs} \times \text{rhs}\)

GF256.mul8

Multiply 8 values in a single operation

GF256.poly_add

Add polynomials

GF256.poly_divmod

Polynomial quotient and remainder

GF256.poly_eval

Evaluate polynomial at x

GF256.poly_eval8

Evaluate polynomial at 8 points on a single operation

GF256.poly_mod

Polynomial remainder

GF256.poly_mod_x_n

Shifted polynomial remainder

GF256.poly_mul

Multiply polynomials

GF256.poly_sub

Subtract polynomials

GF256.pow

Power: \(\text{base}^\text{exponent}\)

GF256.sub

Subtraction: \(\text{lhs} - \text{rhs}\)

Attributes

GF256.field_elements

Always 256

GF256.poly1

Masked irreducible polynomial, excluding MSb

GF256.power

Always 8

GF256.prime

Always 2

GF256.primitive

Primitive 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}\)