2020-10-16 01:00:04 +01:00
|
|
|
#include "api.h"
|
2019-06-18 15:27:03 +01:00
|
|
|
#include "cbd.h"
|
|
|
|
#include "fips202.h"
|
2020-10-16 01:00:04 +01:00
|
|
|
#include "pack_unpack.h"
|
2019-06-18 15:27:03 +01:00
|
|
|
#include "poly.h"
|
2020-10-19 17:23:48 +01:00
|
|
|
#include <stddef.h>
|
2019-06-18 15:27:03 +01:00
|
|
|
|
2020-10-28 16:02:04 +00:00
|
|
|
void PQCLEAN_LIGHTSABER_CLEAN_MatrixVectorMul(poly c[SABER_L], const poly A[SABER_L][SABER_L], const poly s[SABER_L], int16_t transpose) {
|
2020-10-19 17:23:48 +01:00
|
|
|
size_t i, j;
|
2020-10-28 16:02:04 +00:00
|
|
|
|
|
|
|
if (transpose) {
|
|
|
|
for (i = 0; i < SABER_L; i++) {
|
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_poly_mul(&c[i], &A[0][i], &s[0], 0);
|
|
|
|
for (j = 1; j < SABER_L; j++) {
|
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_poly_mul(&c[i], &A[j][i], &s[j], 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < SABER_L; i++) {
|
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_poly_mul(&c[i], &A[i][0], &s[0], 0);
|
|
|
|
for (j = 1; j < SABER_L; j++) {
|
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_poly_mul(&c[i], &A[i][j], &s[j], 1);
|
2020-10-16 01:00:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 16:02:04 +00:00
|
|
|
void PQCLEAN_LIGHTSABER_CLEAN_InnerProd(poly *c, const poly b[SABER_L], const poly s[SABER_L]) {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_poly_mul(c, &b[0], &s[0], 0);
|
|
|
|
for (i = 1; i < SABER_L; i++) {
|
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_poly_mul(c, &b[i], &s[i], 1);
|
2020-10-16 01:00:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 16:02:04 +00:00
|
|
|
void PQCLEAN_LIGHTSABER_CLEAN_GenMatrix(poly A[SABER_L][SABER_L], const uint8_t seed[SABER_SEEDBYTES]) {
|
2020-10-19 17:23:48 +01:00
|
|
|
size_t i;
|
2020-10-28 16:02:04 +00:00
|
|
|
uint8_t buf[SABER_L * SABER_POLYVECBYTES];
|
2020-10-16 01:00:04 +01:00
|
|
|
|
|
|
|
shake128(buf, sizeof(buf), seed, SABER_SEEDBYTES);
|
|
|
|
|
|
|
|
for (i = 0; i < SABER_L; i++) {
|
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_BS2POLVECq(A[i], buf + i * SABER_POLYVECBYTES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 16:02:04 +00:00
|
|
|
void PQCLEAN_LIGHTSABER_CLEAN_GenSecret(poly s[SABER_L], const uint8_t seed[SABER_NOISESEEDBYTES]) {
|
2020-10-16 01:00:04 +01:00
|
|
|
size_t i;
|
2020-10-28 16:02:04 +00:00
|
|
|
uint8_t buf[SABER_L * SABER_POLYCOINBYTES];
|
2019-06-18 15:27:03 +01:00
|
|
|
|
2020-10-28 16:02:04 +00:00
|
|
|
shake128(buf, sizeof(buf), seed, SABER_NOISESEEDBYTES);
|
2019-06-18 15:27:03 +01:00
|
|
|
|
2020-10-16 01:00:04 +01:00
|
|
|
for (i = 0; i < SABER_L; i++) {
|
2020-10-28 16:02:04 +00:00
|
|
|
PQCLEAN_LIGHTSABER_CLEAN_cbd(s[i].coeffs, buf + i * SABER_POLYCOINBYTES);
|
2019-06-18 15:27:03 +01:00
|
|
|
}
|
|
|
|
}
|