You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 line
3.0 KiB

  1. #include "bf_decoding.h"
  2. #include "dfr_test.h"
  3. #include "gf2x_arith_mod_xPplusOne.h"
  4. #include "qc_ldpc_parameters.h"
  5. #include "sort.h"
  6. #include <string.h>
  7. int PQCLEAN_LEDAKEMLT12_LEAKTIME_DFR_test(POSITION_T LSparse[N0][DV * M], uint8_t *secondIterThreshold) {
  8. POSITION_T LSparse_loc[N0][DV * M]; /* vector of N_0 sparse blocks */
  9. uint8_t gamma[N0][N0][P] = {{{0}}};
  10. uint32_t gammaHist[N0][DV * M + 1] = {{0}};
  11. size_t maxMut[N0], maxMutMinusOne[N0];
  12. size_t allBlockMaxSumst, allBlockMaxSumstMinusOne;
  13. size_t histIdx, toAdd;
  14. for (size_t i = 0; i < N0; i++) {
  15. for (size_t j = 0; j < DV * M; j++) {
  16. if (LSparse[i][j] != 0) {
  17. LSparse_loc[i][j] = (P - LSparse[i][j]);
  18. }
  19. }
  20. PQCLEAN_LEDAKEMLT12_LEAKTIME_uint32_sort(LSparse_loc[i], DV * M);
  21. }
  22. for (size_t i = 0; i < N0; i++ ) {
  23. for (size_t j = 0; j < N0; j++) {
  24. for (size_t k = 0; k < (DV * M); k++) {
  25. for (size_t l = 0; l < (DV * M); l++) {
  26. gamma[i][j][(P + LSparse_loc[i][k] - LSparse_loc[j][l]) % P]++;
  27. }
  28. }
  29. }
  30. }
  31. for (size_t i = 0; i < N0; i++ ) {
  32. for (size_t j = 0; j < N0; j++ ) {
  33. gamma[i][j][0] = 0;
  34. }
  35. }
  36. /* build histogram of values in gamma */
  37. for (size_t i = 0; i < N0; i++ ) {
  38. for (size_t j = 0; j < N0; j++ ) {
  39. for (size_t k = 0; k < P; k++) {
  40. gammaHist[i][gamma[i][j][k]]++;
  41. }
  42. }
  43. }
  44. for (size_t gammaBlockRowIdx = 0; gammaBlockRowIdx < N0; gammaBlockRowIdx++) {
  45. maxMutMinusOne[gammaBlockRowIdx] = 0;
  46. histIdx = DV * M;
  47. toAdd = T_BAR - 1;
  48. while ( (histIdx > 0) && (toAdd > 0)) {
  49. if (gammaHist[gammaBlockRowIdx][histIdx] > toAdd ) {
  50. maxMutMinusOne[gammaBlockRowIdx] += histIdx * toAdd;
  51. toAdd = 0;
  52. } else {
  53. maxMutMinusOne[gammaBlockRowIdx] += histIdx * gammaHist[gammaBlockRowIdx][histIdx];
  54. toAdd -= gammaHist[gammaBlockRowIdx][histIdx];
  55. histIdx--;
  56. }
  57. }
  58. maxMut[gammaBlockRowIdx] = histIdx + maxMutMinusOne[gammaBlockRowIdx];
  59. }
  60. /*seek max values across all gamma blocks */
  61. allBlockMaxSumst = maxMut[0];
  62. allBlockMaxSumstMinusOne = maxMutMinusOne[0];
  63. for (size_t gammaBlockRowIdx = 0; gammaBlockRowIdx < N0; gammaBlockRowIdx++) {
  64. allBlockMaxSumst = allBlockMaxSumst < maxMut[gammaBlockRowIdx] ?
  65. maxMut[gammaBlockRowIdx] :
  66. allBlockMaxSumst;
  67. allBlockMaxSumstMinusOne = allBlockMaxSumstMinusOne < maxMutMinusOne[gammaBlockRowIdx] ?
  68. maxMutMinusOne[gammaBlockRowIdx] :
  69. allBlockMaxSumstMinusOne;
  70. }
  71. if (DV * M > (allBlockMaxSumstMinusOne + allBlockMaxSumst)) {
  72. *secondIterThreshold = (uint8_t) (allBlockMaxSumst + 1);
  73. return 1;
  74. }
  75. return 0;
  76. }