Class GF2nPolynomial

java.lang.Object
org.bouncycastle.pqc.legacy.math.linearalgebra.GF2nPolynomial

public class GF2nPolynomial extends Object
This class implements polynomials over GF2nElements.
See Also:
  • Constructor Details

    • GF2nPolynomial

      public GF2nPolynomial(int deg, GF2nElement elem)
      Creates a new PolynomialGF2n of size deg and elem as coefficients.
      Parameters:
      deg - - the maximum degree + 1
      elem - - a GF2nElement
    • GF2nPolynomial

      public GF2nPolynomial(GF2nPolynomial a)
      Creates a new PolynomialGF2n by cloning the given PolynomialGF2n a.
      Parameters:
      a - the PolynomialGF2n to clone
    • GF2nPolynomial

      public GF2nPolynomial(GF2Polynomial polynomial, GF2nField B1)
      Creates a new PolynomialGF2n from the given Bitstring polynomial over the GF2nField B1.
      Parameters:
      polynomial - the Bitstring to use
      B1 - the field
  • Method Details

    • assignZeroToElements

      public final void assignZeroToElements()
    • size

      public final int size()
      Returns the size (=maximum degree + 1) of this PolynomialGF2n. This is not the degree, use getDegree instead.
      Returns:
      the size (=maximum degree + 1) of this PolynomialGF2n.
    • getDegree

      public final int getDegree()
      Returns the degree of this PolynomialGF2n.
      Returns:
      the degree of this PolynomialGF2n.
    • enlarge

      public final void enlarge(int k)
      Enlarges the size of this PolynomialGF2n to k + 1.
      Parameters:
      k - the new maximum degree
    • shrink

      public final void shrink()
    • set

      public final void set(int index, GF2nElement elem)
      Sets the coefficient at index to elem.
      Parameters:
      index - the index
      elem - the GF2nElement to store as coefficient index
    • at

      public final GF2nElement at(int index)
      Returns the coefficient at index.
      Parameters:
      index - the index
      Returns:
      the GF2nElement stored as coefficient index
    • isZero

      public final boolean isZero()
      Returns true if all coefficients equal zero.
      Returns:
      true if all coefficients equal zero.
    • equals

      public final boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this polynomial
    • add

      public final GF2nPolynomial add(GF2nPolynomial b)
      Adds the PolynomialGF2n b to this and returns the result in a new PolynomialGF2n.
      Parameters:
      b - - the PolynomialGF2n to add
      Returns:
      this + b
    • scalarMultiply

      public final GF2nPolynomial scalarMultiply(GF2nElement s)
      Multiplies the scalar s to each coefficient of this PolynomialGF2n and returns the result in a new PolynomialGF2n.
      Parameters:
      s - the scalar to multiply
      Returns:
      this x s
    • multiply

      public final GF2nPolynomial multiply(GF2nPolynomial b)
      Multiplies this by b and returns the result in a new PolynomialGF2n.
      Parameters:
      b - the PolynomialGF2n to multiply
      Returns:
      this * b
    • multiplyAndReduce

      public final GF2nPolynomial multiplyAndReduce(GF2nPolynomial b, GF2nPolynomial g)
      Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.
      Parameters:
      b - the PolynomialGF2n to multiply
      g - the modul
      Returns:
      this * b mod g
    • reduce

      Reduces this by g and returns the result in a new PolynomialGF2n.
      Parameters:
      g - - the modulus
      Returns:
      this % g
      Throws:
      RuntimeException
      ArithmeticException
    • shiftThisLeft

      public final void shiftThisLeft(int amount)
      Shifts left this by amount and stores the result in this PolynomialGF2n.
      Parameters:
      amount - the amount to shift the coefficients
    • shiftLeft

      public final GF2nPolynomial shiftLeft(int amount)
    • divide

      public final GF2nPolynomial[] divide(GF2nPolynomial b)
      Divides this by b and stores the result in a new PolynomialGF2n[2], quotient in result[0] and remainder in result[1].
      Parameters:
      b - the divisor
      Returns:
      the quotient and remainder of this / b
    • remainder

      Divides this by b and stores the remainder in a new PolynomialGF2n.
      Parameters:
      b - the divisor
      Returns:
      the remainder this % b
      Throws:
      RuntimeException
      ArithmeticException
    • quotient

      Divides this by b and stores the quotient in a new PolynomialGF2n.
      Parameters:
      b - the divisor
      Returns:
      the quotient this / b
      Throws:
      RuntimeException
      ArithmeticException
    • gcd

      public final GF2nPolynomial gcd(GF2nPolynomial g)
      Computes the greatest common divisor of this and g and returns the result in a new PolynomialGF2n.
      Parameters:
      g - - a GF2nPolynomial
      Returns:
      gcd(this, g)