ffrs.GF256#

class ffrs.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: ffrs.GF256, primitive: int = 2, poly1: int = 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: ffrs.GF256, lhs: int, rhs: int) int#

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

div(self: ffrs.GF256, num: int, den: int) int#

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

exp(self: ffrs.GF256, value: int) int#

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

inv(self: ffrs.GF256, value: int) int#

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

log(self: ffrs.GF256, value: int) int#

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

mul(self: ffrs.GF256, lhs: int, rhs: int) int#

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

mul8(self: ffrs.GF256, a: Buffer, b: Buffer) bytearray#

Multiply 8 values in a single operation

poly_add(self: ffrs.GF256, p1: Buffer, p2: Buffer) bytearray#

Add polynomials

poly_divmod(self: ffrs.GF256, p1: Buffer, p2: Buffer) tuple#

Polynomial quotient and remainder

Returns:

(quotient, remainder)

poly_eval(self: ffrs.GF256, poly: Buffer, x: int) int#

Evaluate polynomial at x

poly_eval8(self: ffrs.GF256, poly: Buffer, xs: Buffer) bytearray#

Evaluate polynomial at 8 points on a single operation

poly_mod(self: ffrs.GF256, p1: Buffer, p2: Buffer) bytearray#

Polynomial remainder

poly_mod_x_n(self: ffrs.GF256, p1: Buffer, p2: Buffer) bytearray#

Shifted polynomial remainder

\(P \times X^n \mod (X^n + p_2)\) where n = len(p2)

poly_mul(self: ffrs.GF256, p1: Buffer, p2: Buffer) bytearray#

Multiply polynomials

poly_sub(self: ffrs.GF256, p1: Buffer, p2: Buffer) bytearray#

Subtract polynomials

pow(self: ffrs.GF256, base: int, exponent: int) int#

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

sub(self: ffrs.GF256, lhs: int, rhs: int) int#

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