2019-05-19 18:14:46 +01:00
|
|
|
#include "H_Q_matrices_generation.h"
|
|
|
|
#include "gf2x_arith_mod_xPplusOne.h"
|
|
|
|
|
2019-08-24 14:48:38 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_generateHPosOnes(POSITION_T HPosOnes[N0][DV], AES_XOF_struct *keys_expander) {
|
|
|
|
for (size_t i = 0; i < N0; i++) {
|
2019-05-19 18:14:46 +01:00
|
|
|
/* Generate a random block of Htr */
|
2019-08-24 14:48:38 +01:00
|
|
|
PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_sparse_block(&HPosOnes[i][0], DV, keys_expander);
|
2019-05-19 18:14:46 +01:00
|
|
|
}
|
2019-05-24 17:38:54 +01:00
|
|
|
}
|
2019-05-19 18:14:46 +01:00
|
|
|
|
2019-08-24 14:48:38 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_generateQPosOnes(POSITION_T QPosOnes[N0][M], AES_XOF_struct *keys_expander) {
|
|
|
|
size_t placed_ones;
|
2019-08-21 13:28:31 +01:00
|
|
|
|
2019-08-24 14:48:38 +01:00
|
|
|
for (size_t i = 0; i < N0; i++) {
|
|
|
|
placed_ones = 0;
|
|
|
|
for (size_t j = 0; j < N0; j++) {
|
2019-08-21 13:28:31 +01:00
|
|
|
PQCLEAN_LEDAKEMLT12_LEAKTIME_rand_circulant_sparse_block(&QPosOnes[i][placed_ones],
|
2019-05-24 17:38:54 +01:00
|
|
|
qBlockWeights[i][j],
|
|
|
|
keys_expander);
|
2019-05-19 18:14:46 +01:00
|
|
|
placed_ones += qBlockWeights[i][j];
|
2019-06-07 14:07:22 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-24 17:38:54 +01:00
|
|
|
}
|
2019-08-21 13:28:31 +01:00
|
|
|
|
2019-08-24 14:48:38 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_transposeHPosOnes(POSITION_T HtrPosOnes[N0][DV], POSITION_T HPosOnes[N0][DV]) {
|
|
|
|
for (size_t i = 0; i < N0; i++) {
|
2019-08-21 13:28:31 +01:00
|
|
|
/* Obtain directly the sparse representation of the block of H */
|
2019-08-24 14:48:38 +01:00
|
|
|
for (size_t k = 0; k < DV; k++) {
|
2019-08-21 13:28:31 +01:00
|
|
|
HtrPosOnes[i][k] = (P - HPosOnes[i][k]) % P; /* transposes indexes */
|
2019-08-24 14:48:38 +01:00
|
|
|
}
|
2019-08-21 13:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 14:48:38 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_transposeQPosOnes(POSITION_T QtrPosOnes[N0][M], POSITION_T QPosOnes[N0][M]) {
|
|
|
|
POSITION_T transposed_ones_idx[N0] = {0x00};
|
|
|
|
size_t currQoneIdx, endQblockIdx;
|
2019-08-21 13:28:31 +01:00
|
|
|
|
2019-08-24 14:48:38 +01:00
|
|
|
for (size_t source_row_idx = 0; source_row_idx < N0 ; source_row_idx++) {
|
|
|
|
currQoneIdx = 0; // position in the column of QtrPosOnes[][...]
|
|
|
|
endQblockIdx = 0;
|
2019-08-21 13:28:31 +01:00
|
|
|
for (int blockIdx = 0; blockIdx < N0; blockIdx++) {
|
|
|
|
endQblockIdx += qBlockWeights[source_row_idx][blockIdx];
|
|
|
|
for (; currQoneIdx < endQblockIdx; currQoneIdx++) {
|
2019-08-24 14:48:38 +01:00
|
|
|
QtrPosOnes[blockIdx][transposed_ones_idx[blockIdx]] =
|
|
|
|
(P - QPosOnes[source_row_idx][currQoneIdx]) % P;
|
2019-08-21 13:28:31 +01:00
|
|
|
transposed_ones_idx[blockIdx]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|