Top Description Constructors Methods
org.bouncycastle.pqc.crypto.rainbow

pack-priv Class ComputeInField

extends Object
Class Inheritance

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

AccessConstructor and Description
public
ComputeInField()

Constructor with no parameters

Method Summary

Modifier and TypeMethod and Description
public short[][]

Returns:

addition of matrix1 and matrix2
addMatrix
(short[][]
first summand
matrix1
,
short[][]
second summand
matrix2
)

Adds the matrices matrix1 and matrix2

public short[][]

Returns:

addition of matrix and matrix_transpose
addMatrixTranspose
(short[][]
first summand
matrix
)

Adds the transpose of a n x n matrix to itself

public short[]

Returns:

addition of vector1 and vector2
addVect
(short[]
first summand, always of dim n
vector1
,
short[]
second summand, always of dim n
vector2
)

Addition of two vectors

private void
gaussElim(short[][] A)

public short[][]

Returns:

inverse matrix of the input matrix. If the matrix is singular, null is returned.
inverse
(short[][]
the matrix which inverse matrix is needed
coef
)

This function computes the inverse of a given matrix using the Gauss- Elimination method.

public short[][]

Returns:

A = M1*M2
multiplyMatrix
(short[][]
-the 1st matrix
M1
,
short[][]
-the 2nd matrix
M2
)

This function multiplies two given matrices.

public short[]

Returns:

M1*m
multiplyMatrix
(short[][]
the matrix to be multiplied
M1
,
short[]
the one-dimensional array to be multiplied
m
)

This function multiplies a given matrix with a one-dimensional array.

public short

Returns:

m_transpose*M1*m
multiplyMatrix_quad
(short[][]
the matrix to be multiplied
M1
,
short[]
the one-dimensional array to be multiplied
m
)

This function multiplies a given matrix with a one-dimensional array as m_transpose * M1 * m.

public short[][]

Returns:

matrix multiplied with scalar
multMatrix
(short
galois element to multiply matrix with
scalar
,
short[][]
2-dim n x n matrix to be multiplied
matrix
)

Multiplies matrix with scalar

public short[]

Returns:

vector multiplied with scalar
multVect
(short
galois element to multiply vector with
scalar
,
short[]
vector to be multiplied
vector
)

Multiplies vector with scalar

public short[][]

Returns:

resulting n x n matrix of multiplication
multVects
(short[]
column vector, always n x 1
vector1
,
short[]
row vector, always 1 x n
vector2
)

Multiplication of column vector with row vector

public short[][][]

Returns:

batch matrix a * b + c
obfuscate_l1_polys
(short[][]
matrix
a
,
short[][][]
batched matrix
b
,
short[][][]
batched matrix
c
)

Computes a * b + c for batched matrices b and c

public short[]

Returns:

x the solution of the equation if it is solvable null otherwise
solveEquation
(short[][]
this matrix is the left part of the equation (B in the equation above)
B
,
short[]
the right part of the equation (b in the equation above)
b
)

This function finds a solution of the equation Bx = b.

public short[][]

Returns:

UT of matrix
to_UT
(short[][]
matrix to turn into UT
matrix
)

Compute upper triangular matrix for given n x n matrix

public short[][]

Returns:

transpose of matrix
transpose
(short[][]
matrix to transpose
matrix
)

Returns the transpose of matrix

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ComputeInFieldback to summary
public ComputeInField()

Constructor with no parameters

Method Detail

addMatrixback to summary
public short[][] addMatrix(short[][] matrix1, short[][] matrix2)

Adds the matrices matrix1 and matrix2

Parameters
matrix1:short[][]

first summand

matrix2:short[][]

second summand

Returns:short[][]

addition of matrix1 and matrix2

Exceptions
RuntimeException:
in case the addition is not possible because of different dimensions of the matrices
addMatrixTransposeback to summary
public short[][] addMatrixTranspose(short[][] matrix)

Adds the transpose of a n x n matrix to itself

Parameters
matrix:short[][]

first summand

Returns:short[][]

addition of matrix and matrix_transpose

Exceptions
RuntimeException:
in case the addition is not possible because of different dimensions of the matrices
addVectback to summary
public short[] addVect(short[] vector1, short[] vector2)

Addition of two vectors

Parameters
vector1:short[]

first summand, always of dim n

vector2:short[]

second summand, always of dim n

Returns:short[]

addition of vector1 and vector2

Exceptions
RuntimeException:
in case the addition is impossible due to inconsistency in the dimensions
gaussElimback to summary
private void gaussElim(short[][] A)
inverseback to summary
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:short[][]

the matrix which inverse matrix is needed

Returns:short[][]

inverse matrix of the input matrix. If the matrix is singular, null is returned.

Exceptions
RuntimeException:
if the given matrix is not invertible
multiplyMatrixback to summary
public short[][] multiplyMatrix(short[][] M1, short[][] M2) throws RuntimeException

This function multiplies two given matrices. If the given matrices cannot be multiplied due to different sizes, an exception is thrown.

Parameters
M1:short[][]

-the 1st matrix

M2:short[][]

-the 2nd matrix

Returns:short[][]

A = M1*M2

Exceptions
RuntimeException:
in case the given matrices cannot be multiplied due to different dimensions.
multiplyMatrixback to summary
public short[] multiplyMatrix(short[][] M1, short[] m) throws RuntimeException

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:short[][]

the matrix to be multiplied

m:short[]

the one-dimensional array to be multiplied

Returns:short[]

M1*m

Exceptions
RuntimeException:
in case of dimension inconsistency
multiplyMatrix_quadback to summary
public short multiplyMatrix_quad(short[][] M1, short[] m) throws RuntimeException

This function multiplies a given matrix with a one-dimensional array as m_transpose * M1 * m.

An exception is thrown, if matrix is ot quadratic and the number of columns in the matrix and the number of rows in the one-dim. array differ.

Parameters
M1:short[][]

the matrix to be multiplied

m:short[]

the one-dimensional array to be multiplied

Returns:short

m_transpose*M1*m

Exceptions
RuntimeException:
in case of dimension inconsistency
multMatrixback to summary
public short[][] multMatrix(short scalar, short[][] matrix)

Multiplies matrix with scalar

Parameters
scalar:short

galois element to multiply matrix with

matrix:short[][]

2-dim n x n matrix to be multiplied

Returns:short[][]

matrix multiplied with scalar

multVectback to summary
public short[] multVect(short scalar, short[] vector)

Multiplies vector with scalar

Parameters
scalar:short

galois element to multiply vector with

vector:short[]

vector to be multiplied

Returns:short[]

vector multiplied with scalar

multVectsback to summary
public short[][] multVects(short[] vector1, short[] vector2)

Multiplication of column vector with row vector

Parameters
vector1:short[]

column vector, always n x 1

vector2:short[]

row vector, always 1 x n

Returns:short[][]

resulting n x n matrix of multiplication

Exceptions
RuntimeException:
in case the multiplication is impossible due to inconsistency in the dimensions
obfuscate_l1_polysback to summary
public short[][][] obfuscate_l1_polys(short[][] a, short[][][] b, short[][][] c)

Computes a * b + c for batched matrices b and c

Parameters
a:short[][]

matrix

b:short[][][]

batched matrix

c:short[][][]

batched matrix

Returns:short[][][]

batch matrix a * b + c

Exceptions
RuntimeException:
in case the matrices dimensions don't permit these operations
solveEquationback to summary
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:short[][]

this matrix is the left part of the equation (B in the equation above)

b:short[]

the right part of the equation (b in the equation above)

Returns:short[]

x the solution of the equation if it is solvable null otherwise

Exceptions
RuntimeException:
if LES is not solvable
to_UTback to summary
public short[][] to_UT(short[][] matrix)

Compute upper triangular matrix for given n x n matrix

Parameters
matrix:short[][]

matrix to turn into UT

Returns:short[][]

UT of matrix

Exceptions
RuntimeException:
in case the matrix is not square
transposeback to summary
public short[][] transpose(short[][] matrix)

Returns the transpose of matrix

Parameters
matrix:short[][]

matrix to transpose

Returns:short[][]

transpose of matrix