1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-27 09:51:30 +00:00
pqcrypto/crypto_sign/rainbowVc-classic/clean/parallel_matrix_op.h

283 lines
13 KiB
C
Raw Normal View History

2019-06-22 17:17:07 +01:00
#ifndef _P_MATRIX_OP_H_
#define _P_MATRIX_OP_H_
/// @file parallel_matrix_op.h
/// @brief Librarys for operations of batched matrixes.
///
///
//////////////// Section: triangle matrix <-> rectangle matrix ///////////////////////////////////
///
/// @brief Calculate the corresponding index in an array for an upper-triangle(UT) matrix.
///
/// @param[in] i_row - the i-th row in an upper-triangle matrix.
/// @param[in] j_col - the j-th column in an upper-triangle matrix.
/// @param[in] dim - the dimension of the upper-triangle matrix, i.e., an dim x dim matrix.
/// @return the corresponding index in an array storage.
///
unsigned PQCLEAN_RAINBOWVCCLASSIC_CLEAN_idx_of_trimat( unsigned i_row, unsigned j_col, unsigned dim );
///
/// @brief Upper trianglize a rectangle matrix to the corresponding upper-trangle matrix.
///
/// @param[out] btriC - the batched upper-trianglized matrix C.
/// @param[in] bA - a batched retangle matrix A.
/// @param[in] bwidth - the width of the batched matrix A, i.e., A is a Awidth x Awidth matrix.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_UpperTrianglize( unsigned char *btriC, const unsigned char *bA, unsigned Awidth, unsigned size_batch );
//////////////////// Section: matrix multiplications ///////////////////////////////
///
/// @brief bC += btriA * B , in GF(16)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] btriA - a batched UT matrix A.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_trimat_madd_gf16( unsigned char *bC, const unsigned char *btriA,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += btriA * B , in GF(256)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] btriA - a batched UT matrix A.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_trimat_madd_gf256( unsigned char *bC, const unsigned char *btriA,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += btriA^Tr * B , in GF(16)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] btriA - a batched UT matrix A. A will be transposed while multiplying.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_trimatTr_madd_gf16( unsigned char *bC, const unsigned char *btriA,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += btriA^Tr * B , in GF(256)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] btriA - a batched UT matrix A, which will be transposed while multiplying.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_trimatTr_madd_gf256( unsigned char *bC, const unsigned char *btriA,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += (btriA + btriA^Tr) *B , in GF(16)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] btriA - a batched UT matrix A. The operand for multiplication is (btriA + btriA^Tr).
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_2trimat_madd_gf16( unsigned char *bC, const unsigned char *btriA,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += (btriA + btriA^Tr) *B , in GF(256)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] btriA - a batched UT matrix A. The operand for multiplication is (btriA + btriA^Tr).
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_2trimat_madd_gf256( unsigned char *bC, const unsigned char *btriA,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += A^Tr * bB , in GF(16)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] A_to_tr - a column-major matrix A. The operand for multiplication is A^Tr.
/// @param[in] Aheight - the height of A.
/// @param[in] size_Acolvec - the size of a column vector in A.
/// @param[in] Awidth - the width of A.
/// @param[in] bB - a batched matrix B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_matTr_madd_gf16( unsigned char *bC,
const unsigned char *A_to_tr, unsigned Aheight, unsigned size_Acolvec, unsigned Awidth,
const unsigned char *bB, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += A^Tr * bB , in GF(256)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] A_to_tr - a column-major matrix A. The operand for multiplication is A^Tr.
/// @param[in] Aheight - the height of A.
/// @param[in] size_Acolvec - the size of a column vector in A.
/// @param[in] Awidth - the width of A.
/// @param[in] bB - a batched matrix B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_matTr_madd_gf256( unsigned char *bC,
const unsigned char *A_to_tr, unsigned Aheight, unsigned size_Acolvec, unsigned Awidth,
const unsigned char *bB, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += bA^Tr * B , in GF(16)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] bA_to_tr - a batched matrix A. The operand for multiplication is (bA^Tr).
/// @param[in] Awidth_befor_tr - the width of A.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_bmatTr_madd_gf16( unsigned char *bC, const unsigned char *bA_to_tr, unsigned Awidth_before_tr,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += bA^Tr * B , in GF(256)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] bA_to_tr - a batched matrix A. The operand for multiplication is (bA^Tr).
/// @param[in] Awidth_befor_tr - the width of A.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_bmatTr_madd_gf256( unsigned char *bC, const unsigned char *bA_to_tr, unsigned Awidth_before_tr,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += bA * B , in GF(16)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] bA - a batched matrix A.
/// @param[in] Aheigh - the height of A.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_mat_madd_gf16( unsigned char *bC, const unsigned char *bA, unsigned Aheight,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
///
/// @brief bC += bA * B , in GF(256)
///
/// @param[out] bC - the batched matrix C.
/// @param[in] bA - a batched matrix A.
/// @param[in] Aheigh - the height of A.
/// @param[in] B - a column-major matrix B.
/// @param[in] Bheight - the height of B.
/// @param[in] size_Bcolvec - the size of the column vector in B.
/// @param[in] Bwidth - the width of B.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_mat_madd_gf256( unsigned char *bC, const unsigned char *bA, unsigned Aheight,
const unsigned char *B, unsigned Bheight, unsigned size_Bcolvec, unsigned Bwidth, unsigned size_batch );
//////////////////// Section: "quadratric" matrix evaluation ///////////////////////////////
///
/// @brief y = x^Tr * trimat * x , in GF(16)
///
/// @param[out] y - the returned batched element y.
/// @param[in] trimat - a batched matrix.
/// @param[in] x - an input vector x.
/// @param[in] dim - the dimension of matrix trimat (and x).
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_quad_trimat_eval_gf16( unsigned char *y, const unsigned char *trimat, const unsigned char *x, unsigned dim, unsigned size_batch );
///
/// @brief y = x^Tr * trimat * x , in GF(256)
///
/// @param[out] y - the returned batched element y.
/// @param[in] trimat - a batched matrix.
/// @param[in] x - an input vector x.
/// @param[in] dim - the dimension of matrix trimat (and x).
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_quad_trimat_eval_gf256( unsigned char *y, const unsigned char *trimat, const unsigned char *x, unsigned dim, unsigned size_batch );
///
/// @brief z = y^Tr * mat * x , in GF(16)
///
/// @param[out] z - the returned batched element z.
/// @param[in] y - an input vector y.
/// @param[in] dim_y - the length of y.
/// @param[in] mat - a batched matrix.
/// @param[in] x - an input vector x.
/// @param[in] dim_x - the length of x.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_quad_recmat_eval_gf16( unsigned char *z, const unsigned char *y, unsigned dim_y,
const unsigned char *mat, const unsigned char *x, unsigned dim_x, unsigned size_batch );
///
/// @brief z = y^Tr * mat * x , in GF(256)
///
/// @param[out] z - the returned batched element z.
/// @param[in] y - an input vector y.
/// @param[in] dim_y - the length of y.
/// @param[in] mat - a batched matrix.
/// @param[in] x - an input vector x.
/// @param[in] dim_x - the length of x.
/// @param[in] size_batch - number of the batched elements in the corresponding position of the matrix.
///
void PQCLEAN_RAINBOWVCCLASSIC_CLEAN_batch_quad_recmat_eval_gf256( unsigned char *z, const unsigned char *y, unsigned dim_y,
const unsigned char *mat, const unsigned char *x, unsigned dim_x, unsigned size_batch );
#endif // _P_MATRIX_OP_H_