java.lang.Object
org.bouncycastle.pqc.legacy.math.linearalgebra.Matrix
org.bouncycastle.pqc.legacy.math.linearalgebra.GF2Matrix

public class GF2Matrix extends Matrix
This class describes some operations with matrices over finite field GF(2) and is used in ecc and MQ-PKC (also has some specific methods and implementation)
  • Constructor Details

    • GF2Matrix

      public GF2Matrix(byte[] enc)
      Create the matrix from encoded form.
      Parameters:
      enc - the encoded matrix
    • GF2Matrix

      public GF2Matrix(int numColumns, int[][] matrix)
      Create the matrix with the contents of the given array. The matrix is not copied. Unused coefficients are masked out.
      Parameters:
      numColumns - the number of columns
      matrix - the element array
    • GF2Matrix

      public GF2Matrix(int n, char typeOfMatrix)
      Create an nxn matrix of the given type.
      Parameters:
      n - the number of rows (and columns)
      typeOfMatrix - the martix type (see Matrix for predefined constants)
    • GF2Matrix

      public GF2Matrix(int n, char typeOfMatrix, SecureRandom sr)
      Create an nxn matrix of the given type.
      Parameters:
      n - the matrix size
      typeOfMatrix - the matrix type
      sr - the source of randomness
    • GF2Matrix

      public GF2Matrix(GF2Matrix a)
      Copy constructor.
      Parameters:
      a - another GF2Matrix
  • Method Details

    • createRandomRegularMatrixAndItsInverse

      public static GF2Matrix[] createRandomRegularMatrixAndItsInverse(int n, SecureRandom sr)
      Create a nxn random regular matrix and its inverse.
      Parameters:
      n - number of rows (and columns)
      sr - source of randomness
      Returns:
      the created random regular matrix and its inverse
    • getIntArray

      public int[][] getIntArray()
      Returns:
      the array keeping the matrix elements
    • getLength

      public int getLength()
      Returns:
      the length of each array representing a row of this matrix
    • getRow

      public int[] getRow(int index)
      Return the row of this matrix with the given index.
      Parameters:
      index - the index
      Returns:
      the row of this matrix with the given index
    • getEncoded

      public byte[] getEncoded()
      Returns encoded matrix, i.e., this matrix in byte array form
      Specified by:
      getEncoded in class Matrix
      Returns:
      the encoded matrix
    • getHammingWeight

      public double getHammingWeight()
      Returns the percentage of the number of "ones" in this matrix.
      Returns:
      the Hamming weight of this matrix (as a ratio).
    • isZero

      public boolean isZero()
      Check if this is the zero matrix (i.e., all entries are zero).
      Specified by:
      isZero in class Matrix
      Returns:
      true if this is the zero matrix
    • getLeftSubMatrix

      public GF2Matrix getLeftSubMatrix()
      Get the quadratic submatrix of this matrix consisting of the leftmost numRows columns.
      Returns:
      the (numRows x numRows) submatrix
    • extendLeftCompactForm

      public GF2Matrix extendLeftCompactForm()
      Compute the full form matrix (this | Id) from this matrix in left compact form, where Id is the k x k identity matrix and k is the number of rows of this matrix.
      Returns:
      (this | Id)
    • getRightSubMatrix

      public GF2Matrix getRightSubMatrix()
      Get the submatrix of this matrix consisting of the rightmost numColumns-numRows columns.
      Returns:
      the (numRows x (numColumns-numRows)) submatrix
    • extendRightCompactForm

      public GF2Matrix extendRightCompactForm()
      Compute the full form matrix (Id | this) from this matrix in right compact form, where Id is the k x k identity matrix and k is the number of rows of this matrix.
      Returns:
      (Id | this)
    • computeTranspose

      public Matrix computeTranspose()
      Compute the transpose of this matrix.
      Returns:
      (this)T
    • computeInverse

      public Matrix computeInverse()
      Compute the inverse of this matrix.
      Specified by:
      computeInverse in class Matrix
      Returns:
      the inverse of this matrix (newly created).
      Throws:
      ArithmeticException - if this matrix is not invertible.
    • leftMultiply

      public Matrix leftMultiply(Permutation p)
      Compute the product of a permutation matrix (which is generated from an n-permutation) and this matrix.
      Parameters:
      p - the permutation
      Returns:
      GF2Matrix P*this
    • leftMultiply

      public Vector leftMultiply(Vector vec)
      compute product a row vector and this matrix
      Specified by:
      leftMultiply in class Matrix
      Parameters:
      vec - a vector over GF(2)
      Returns:
      Vector product a*matrix
    • leftMultiplyLeftCompactForm

      public Vector leftMultiplyLeftCompactForm(Vector vec)
      Compute the product of the matrix (this | Id) and a column vector, where Id is a (numRows x numRows) unit matrix.
      Parameters:
      vec - the vector over GF(2)
      Returns:
      (this | Id)*vector
    • rightMultiply

      public Matrix rightMultiply(Matrix mat)
      Compute the product of this matrix and a matrix A over GF(2).
      Specified by:
      rightMultiply in class Matrix
      Parameters:
      mat - a matrix A over GF(2)
      Returns:
      matrix product this*matrixA
    • rightMultiply

      public Matrix rightMultiply(Permutation p)
      Compute the product of this matrix and a permutation matrix which is generated from an n-permutation.
      Specified by:
      rightMultiply in class Matrix
      Parameters:
      p - the permutation
      Returns:
      GF2Matrix this*P
    • rightMultiply

      public Vector rightMultiply(Vector vec)
      Compute the product of this matrix and the given column vector.
      Specified by:
      rightMultiply in class Matrix
      Parameters:
      vec - the vector over GF(2)
      Returns:
      this*vector
    • rightMultiplyRightCompactForm

      public Vector rightMultiplyRightCompactForm(Vector vec)
      Compute the product of the matrix (Id | this) and a column vector, where Id is a (numRows x numRows) unit matrix.
      Parameters:
      vec - the vector over GF(2)
      Returns:
      (Id | this)*vector
    • equals

      public boolean equals(Object other)
      Compare this matrix with another object.
      Overrides:
      equals in class Object
      Parameters:
      other - another object
      Returns:
      the result of the comparison
    • hashCode

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

      public String toString()
      Specified by:
      toString in class Matrix
      Returns:
      a human readable form of the matrix