2019-06-18 10:00:33 +01:00
|
|
|
#include "poly_mul.h"
|
2019-06-18 10:41:54 +01:00
|
|
|
#include "SABER_params.h"
|
2019-06-18 10:00:33 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2019-06-18 13:20:59 +01:00
|
|
|
void PQCLEAN_SABER_CLEAN_pol_mul(const uint16_t *a, const uint16_t *b, uint16_t *res, uint16_t p, uint32_t n) {
|
2019-06-18 10:00:33 +01:00
|
|
|
// Polynomial multiplication using the schoolbook method, c[x] = a[x]*b[x]
|
|
|
|
|
2019-06-18 13:20:59 +01:00
|
|
|
// normal multiplication
|
|
|
|
uint16_t c[2 * SABER_N] = {0};
|
|
|
|
for (size_t i = 0; i < SABER_N; i++) {
|
|
|
|
for (size_t j = 0; j < SABER_N; j++) {
|
|
|
|
c[i + j] += a[i] * b[j];
|
|
|
|
}
|
2019-06-18 10:00:33 +01:00
|
|
|
}
|
|
|
|
|
2019-06-18 13:20:59 +01:00
|
|
|
// reduction
|
|
|
|
for (size_t i = n; i < 2 * n; i++) {
|
2019-06-18 10:00:33 +01:00
|
|
|
res[i - n] = (c[i - n] - c[i]) & (p - 1);
|
|
|
|
}
|
|
|
|
}
|