選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

91 行
3.7 KiB

  1. #ifndef _BLAS_COMM_H_
  2. #define _BLAS_COMM_H_
  3. /// @file blas_comm.h
  4. /// @brief Common functions for linear algebra.
  5. ///
  6. #include "rainbow_config.h"
  7. #include <stdint.h>
  8. /// @brief set a vector to 0.
  9. ///
  10. /// @param[in,out] b - the vector b.
  11. /// @param[in] _num_byte - number of bytes for the vector b.
  12. ///
  13. void PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256v_set_zero(uint8_t *b, unsigned int _num_byte);
  14. /// @brief get an element from GF(256) vector .
  15. ///
  16. /// @param[in] a - the input vector a.
  17. /// @param[in] i - the index in the vector a.
  18. /// @return the value of the element.
  19. ///
  20. uint8_t PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256v_get_ele(const uint8_t *a, unsigned int i);
  21. /// @brief check if a vector is 0.
  22. ///
  23. /// @param[in] a - the vector a.
  24. /// @param[in] _num_byte - number of bytes for the vector a.
  25. /// @return 1(true) if a is 0. 0(false) else.
  26. ///
  27. unsigned int PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256v_is_zero(const uint8_t *a, unsigned int _num_byte);
  28. /// @brief polynomial multiplication: c = a*b
  29. ///
  30. /// @param[out] c - the output polynomial c
  31. /// @param[in] a - the vector a.
  32. /// @param[in] b - the vector b.
  33. /// @param[in] _num - number of elements for the polynomials a and b.
  34. ///
  35. void PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256v_polymul(uint8_t *c, const uint8_t *a, const uint8_t *b, unsigned int _num);
  36. /// @brief matrix-vector multiplication: c = matA * b , in GF(256)
  37. ///
  38. /// @param[out] c - the output vector c
  39. /// @param[in] matA - a column-major matrix A.
  40. /// @param[in] n_A_vec_byte - the size of column vectors in bytes.
  41. /// @param[in] n_A_width - the width of matrix A.
  42. /// @param[in] b - the vector b.
  43. ///
  44. void PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256mat_prod(uint8_t *c, const uint8_t *matA, unsigned int n_A_vec_byte, unsigned int n_A_width, const uint8_t *b);
  45. /// @brief matrix-matrix multiplication: c = a * b , in GF(256)
  46. ///
  47. /// @param[out] c - the output matrix c
  48. /// @param[in] c - a matrix a.
  49. /// @param[in] b - a matrix b.
  50. /// @param[in] len_vec - the length of column vectors.
  51. ///
  52. void PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256mat_mul(uint8_t *c, const uint8_t *a, const uint8_t *b, unsigned int len_vec);
  53. /// @brief Gauss elimination for a matrix, in GF(256)
  54. ///
  55. /// @param[in,out] mat - the matrix.
  56. /// @param[in] h - the height of the matrix.
  57. /// @param[in] w - the width of the matrix.
  58. /// @return 1(true) if success. 0(false) if the matrix is singular.
  59. ///
  60. unsigned int PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256mat_gauss_elim(uint8_t *mat, unsigned int h, unsigned int w);
  61. /// @brief Solving linear equations, in GF(256)
  62. ///
  63. /// @param[out] sol - the solutions.
  64. /// @param[in] inp_mat - the matrix parts of input equations.
  65. /// @param[in] c_terms - the constant terms of the input equations.
  66. /// @param[in] n - the number of equations.
  67. /// @return 1(true) if success. 0(false) if the matrix is singular.
  68. ///
  69. unsigned int PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256mat_solve_linear_eq(uint8_t *sol, const uint8_t *inp_mat, const uint8_t *c_terms, unsigned int n);
  70. /// @brief Computing the inverse matrix, in GF(256)
  71. ///
  72. /// @param[out] inv_a - the output of matrix a.
  73. /// @param[in] a - a matrix a.
  74. /// @param[in] H - height of matrix a, i.e., matrix a is an HxH matrix.
  75. /// @param[in] buffer - The buffer for computations. it has to be as large as 2 input matrixes.
  76. /// @return 1(true) if success. 0(false) if the matrix is singular.
  77. ///
  78. unsigned int PQCLEAN_RAINBOWIIICCLASSIC_CLEAN_gf256mat_inv(uint8_t *inv_a, const uint8_t *a, unsigned int H, uint8_t *buffer);
  79. #endif // _BLAS_COMM_H_