2019-06-10 17:57:26 +01:00
|
|
|
#include "gf2x_arith.h"
|
|
|
|
|
|
|
|
#include <string.h> // memset(...)
|
|
|
|
|
2019-06-16 16:01:29 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_add(DIGIT Res[], const DIGIT A[], const DIGIT B[], int nr) {
|
2019-06-11 21:50:33 +01:00
|
|
|
for (int i = 0; i < nr; i++) {
|
|
|
|
Res[i] = A[i] ^ B[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-10 17:57:26 +01:00
|
|
|
/* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */
|
2019-06-16 16:01:29 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_right_bit_shift_n(int length, DIGIT in[], unsigned int amount) {
|
2019-06-10 17:57:26 +01:00
|
|
|
if ( amount == 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unsigned int j;
|
|
|
|
DIGIT mask;
|
|
|
|
mask = ((DIGIT)0x01 << amount) - 1;
|
|
|
|
for (j = length - 1; j > 0 ; j--) {
|
|
|
|
in[j] >>= amount;
|
|
|
|
in[j] |= (in[j - 1] & mask) << (DIGIT_SIZE_b - amount);
|
|
|
|
}
|
|
|
|
in[j] >>= amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PRE: MAX ALLOWED ROTATION AMOUNT : DIGIT_SIZE_b */
|
2019-06-16 16:01:29 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_left_bit_shift_n(int length, DIGIT in[], unsigned int amount) {
|
2019-06-10 17:57:26 +01:00
|
|
|
if ( amount == 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
2019-06-11 15:20:31 +01:00
|
|
|
int j;
|
2019-06-10 17:57:26 +01:00
|
|
|
DIGIT mask;
|
|
|
|
mask = ~(((DIGIT)0x01 << (DIGIT_SIZE_b - amount)) - 1);
|
|
|
|
for (j = 0 ; j < length - 1 ; j++) {
|
|
|
|
in[j] <<= amount;
|
|
|
|
in[j] |= (in[j + 1] & mask) >> (DIGIT_SIZE_b - amount);
|
|
|
|
}
|
|
|
|
in[j] <<= amount;
|
|
|
|
}
|
|
|
|
|
2019-06-16 16:01:29 +01:00
|
|
|
void PQCLEAN_LEDAKEMLT12_LEAKTIME_gf2x_mul_comb(int nr, DIGIT Res[],
|
2019-06-10 17:57:26 +01:00
|
|
|
int na, const DIGIT A[],
|
|
|
|
int nb, const DIGIT B[]) {
|
|
|
|
int i, j, k;
|
|
|
|
DIGIT u, h;
|
|
|
|
|
|
|
|
memset(Res, 0x00, nr * sizeof(DIGIT));
|
|
|
|
|
|
|
|
for (k = DIGIT_SIZE_b - 1; k > 0; k--) {
|
|
|
|
for (i = na - 1; i >= 0; i--) {
|
|
|
|
if ( A[i] & (((DIGIT)0x1) << k) ) {
|
|
|
|
for (j = nb - 1; j >= 0; j--) {
|
|
|
|
Res[i + j + 1] ^= B[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u = Res[na + nb - 1];
|
|
|
|
Res[na + nb - 1] = u << 0x1;
|
|
|
|
for (j = 1; j < na + nb; ++j) {
|
|
|
|
h = u >> (DIGIT_SIZE_b - 1);
|
|
|
|
u = Res[na + nb - 1 - j];
|
|
|
|
Res[na + nb - 1 - j] = h ^ (u << 0x1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = na - 1; i >= 0; i--) {
|
|
|
|
if ( A[i] & ((DIGIT)0x1) ) {
|
|
|
|
for (j = nb - 1; j >= 0; j--) {
|
|
|
|
Res[i + j + 1] ^= B[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|