2020-10-16 01:00:04 +01:00
|
|
|
#include "api.h"
|
2019-06-18 10:00:33 +01:00
|
|
|
#include "cbd.h"
|
|
|
|
#include "fips202.h"
|
2020-10-16 01:00:04 +01:00
|
|
|
#include "pack_unpack.h"
|
2019-06-18 10:00:33 +01:00
|
|
|
#include "poly.h"
|
2020-10-16 01:00:04 +01:00
|
|
|
#include "poly_mul.h"
|
2020-10-19 17:23:48 +01:00
|
|
|
#include <stddef.h>
|
2019-06-18 10:00:33 +01:00
|
|
|
|
2020-10-16 01:00:04 +01:00
|
|
|
void PQCLEAN_SABER_CLEAN_MatrixVectorMul(uint16_t res[SABER_L][SABER_N], const uint16_t A[SABER_L][SABER_L][SABER_N], const uint16_t s[SABER_L][SABER_N], int16_t transpose) {
|
2020-10-19 17:23:48 +01:00
|
|
|
size_t i, j;
|
2020-10-16 01:00:04 +01:00
|
|
|
for (i = 0; i < SABER_L; i++) {
|
|
|
|
for (j = 0; j < SABER_L; j++) {
|
|
|
|
if (transpose == 1) {
|
2020-10-19 17:23:48 +01:00
|
|
|
PQCLEAN_SABER_CLEAN_poly_mul_acc(res[i], A[j][i], s[j]);
|
2020-10-16 01:00:04 +01:00
|
|
|
} else {
|
2020-10-19 17:23:48 +01:00
|
|
|
PQCLEAN_SABER_CLEAN_poly_mul_acc(res[i], A[i][j], s[j]);
|
2020-10-16 01:00:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PQCLEAN_SABER_CLEAN_InnerProd(uint16_t res[SABER_N], const uint16_t b[SABER_L][SABER_N], const uint16_t s[SABER_L][SABER_N]) {
|
2020-10-19 17:23:48 +01:00
|
|
|
size_t j;
|
2020-10-16 01:00:04 +01:00
|
|
|
for (j = 0; j < SABER_L; j++) {
|
2020-10-19 17:23:48 +01:00
|
|
|
PQCLEAN_SABER_CLEAN_poly_mul_acc(res, b[j], s[j]);
|
2020-10-16 01:00:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PQCLEAN_SABER_CLEAN_GenMatrix(uint16_t A[SABER_L][SABER_L][SABER_N], const uint8_t seed[SABER_SEEDBYTES]) {
|
|
|
|
uint8_t buf[SABER_L * SABER_POLYVECBYTES];
|
2020-10-19 17:23:48 +01:00
|
|
|
size_t i;
|
2020-10-16 01:00:04 +01:00
|
|
|
|
|
|
|
shake128(buf, sizeof(buf), seed, SABER_SEEDBYTES);
|
|
|
|
|
|
|
|
for (i = 0; i < SABER_L; i++) {
|
|
|
|
PQCLEAN_SABER_CLEAN_BS2POLVECq(A[i], buf + i * SABER_POLYVECBYTES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PQCLEAN_SABER_CLEAN_GenSecret(uint16_t s[SABER_L][SABER_N], const uint8_t seed[SABER_NOISE_SEEDBYTES]) {
|
|
|
|
uint8_t buf[SABER_L * SABER_POLYCOINBYTES];
|
|
|
|
size_t i;
|
2019-06-18 10:00:33 +01:00
|
|
|
|
2020-10-16 01:00:04 +01:00
|
|
|
shake128(buf, sizeof(buf), seed, SABER_NOISE_SEEDBYTES);
|
2019-06-18 10:00:33 +01:00
|
|
|
|
2020-10-16 01:00:04 +01:00
|
|
|
for (i = 0; i < SABER_L; i++) {
|
|
|
|
PQCLEAN_SABER_CLEAN_cbd(s[i], buf + i * SABER_POLYCOINBYTES);
|
2019-06-18 10:00:33 +01:00
|
|
|
}
|
|
|
|
}
|