Class ComputeInField
java.lang.Object
org.bouncycastle.pqc.legacy.crypto.rainbow.util.ComputeInField
This class offers different operations on matrices in field GF2^8.
Implemented are functions: - finding inverse of a matrix - solving linear equation systems using the Gauss-Elimination method - basic operations like matrix multiplication, addition and so on.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionshort[][]
addSquareMatrix
(short[][] matrix1, short[][] matrix2) Adds the n x n matrices matrix1 and matrix2short[]
addVect
(short[] vector1, short[] vector2) Addition of two vectorsshort[][]
inverse
(short[][] coef) This function computes the inverse of a given matrix using the Gauss- Elimination method.short[]
multiplyMatrix
(short[][] M1, short[] m) This function multiplies a given matrix with a one-dimensional array.short[][]
multiplyMatrix
(short[][] M1, short[][] M2) This function multiplies two given matrices.short[][]
multMatrix
(short scalar, short[][] matrix) Multiplies matrix with scalarshort[]
multVect
(short scalar, short[] vector) Multiplies vector with scalarshort[][]
multVects
(short[] vector1, short[] vector2) Multiplication of column vector with row vectorshort[]
solveEquation
(short[][] B, short[] b) This function finds a solution of the equation Bx = b.
-
Constructor Details
-
ComputeInField
public ComputeInField()Constructor with no parameters
-
-
Method Details
-
solveEquation
public short[] solveEquation(short[][] B, short[] b) This function finds a solution of the equation Bx = b. Exception is thrown if the linear equation system has no solution- Parameters:
B
- this matrix is the left part of the equation (B in the equation above)b
- the right part of the equation (b in the equation above)- Returns:
- x the solution of the equation if it is solvable null otherwise
- Throws:
RuntimeException
- if LES is not solvable
-
inverse
public short[][] inverse(short[][] coef) This function computes the inverse of a given matrix using the Gauss- Elimination method.An exception is thrown if the matrix has no inverse
- Parameters:
coef
- the matrix which inverse matrix is needed- Returns:
- inverse matrix of the input matrix. If the matrix is singular, null is returned.
- Throws:
RuntimeException
- if the given matrix is not invertible
-
multiplyMatrix
This function multiplies two given matrices. If the given matrices cannot be multiplied due to different sizes, an exception is thrown.- Parameters:
M1
- -the 1st matrixM2
- -the 2nd matrix- Returns:
- A = M1*M2
- Throws:
RuntimeException
- in case the given matrices cannot be multiplied due to different dimensions.
-
multiplyMatrix
This function multiplies a given matrix with a one-dimensional array.An exception is thrown, if the number of columns in the matrix and the number of rows in the one-dim. array differ.
- Parameters:
M1
- the matrix to be multipliedm
- the one-dimensional array to be multiplied- Returns:
- M1*m
- Throws:
RuntimeException
- in case of dimension inconsistency
-
addVect
public short[] addVect(short[] vector1, short[] vector2) Addition of two vectors- Parameters:
vector1
- first summand, always of dim nvector2
- second summand, always of dim n- Returns:
- addition of vector1 and vector2
- Throws:
RuntimeException
- in case the addition is impossible due to inconsistency in the dimensions
-
multVects
public short[][] multVects(short[] vector1, short[] vector2) Multiplication of column vector with row vector- Parameters:
vector1
- column vector, always n x 1vector2
- row vector, always 1 x n- Returns:
- resulting n x n matrix of multiplication
- Throws:
RuntimeException
- in case the multiplication is impossible due to inconsistency in the dimensions
-
multVect
public short[] multVect(short scalar, short[] vector) Multiplies vector with scalar- Parameters:
scalar
- galois element to multiply vector withvector
- vector to be multiplied- Returns:
- vector multiplied with scalar
-
multMatrix
public short[][] multMatrix(short scalar, short[][] matrix) Multiplies matrix with scalar- Parameters:
scalar
- galois element to multiply matrix withmatrix
- 2-dim n x n matrix to be multiplied- Returns:
- matrix multiplied with scalar
-
addSquareMatrix
public short[][] addSquareMatrix(short[][] matrix1, short[][] matrix2) Adds the n x n matrices matrix1 and matrix2- Parameters:
matrix1
- first summandmatrix2
- second summand- Returns:
- addition of matrix1 and matrix2; both having the dimensions n x n
- Throws:
RuntimeException
- in case the addition is not possible because of different dimensions of the matrices
-