1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-27 01:41:40 +00:00
pqcrypto/crypto_kem/firesaber/clean/poly.c

58 lines
1.8 KiB
C
Raw Normal View History

#include "api.h"
2019-06-18 15:37:25 +01:00
#include "cbd.h"
#include "fips202.h"
#include "pack_unpack.h"
2019-06-18 15:37:25 +01:00
#include "poly.h"
#include <stddef.h>
2019-06-18 15:37:25 +01:00
2020-10-28 16:02:04 +00:00
void PQCLEAN_FIRESABER_CLEAN_MatrixVectorMul(poly c[SABER_L], const poly A[SABER_L][SABER_L], const poly s[SABER_L], int16_t transpose) {
size_t i, j;
2020-10-28 16:02:04 +00:00
if (transpose) {
for (i = 0; i < SABER_L; i++) {
PQCLEAN_FIRESABER_CLEAN_poly_mul(&c[i], &A[0][i], &s[0], 0);
for (j = 1; j < SABER_L; j++) {
PQCLEAN_FIRESABER_CLEAN_poly_mul(&c[i], &A[j][i], &s[j], 1);
}
}
} else {
for (i = 0; i < SABER_L; i++) {
PQCLEAN_FIRESABER_CLEAN_poly_mul(&c[i], &A[i][0], &s[0], 0);
for (j = 1; j < SABER_L; j++) {
PQCLEAN_FIRESABER_CLEAN_poly_mul(&c[i], &A[i][j], &s[j], 1);
}
}
}
}
2020-10-28 16:02:04 +00:00
void PQCLEAN_FIRESABER_CLEAN_InnerProd(poly *c, const poly b[SABER_L], const poly s[SABER_L]) {
size_t i;
PQCLEAN_FIRESABER_CLEAN_poly_mul(c, &b[0], &s[0], 0);
for (i = 1; i < SABER_L; i++) {
PQCLEAN_FIRESABER_CLEAN_poly_mul(c, &b[i], &s[i], 1);
}
}
2020-10-28 16:02:04 +00:00
void PQCLEAN_FIRESABER_CLEAN_GenMatrix(poly A[SABER_L][SABER_L], const uint8_t seed[SABER_SEEDBYTES]) {
size_t i;
2020-10-28 16:02:04 +00:00
uint8_t buf[SABER_L * SABER_POLYVECBYTES];
shake128(buf, sizeof(buf), seed, SABER_SEEDBYTES);
for (i = 0; i < SABER_L; i++) {
PQCLEAN_FIRESABER_CLEAN_BS2POLVECq(A[i], buf + i * SABER_POLYVECBYTES);
}
}
2020-10-28 16:02:04 +00:00
void PQCLEAN_FIRESABER_CLEAN_GenSecret(poly s[SABER_L], const uint8_t seed[SABER_NOISESEEDBYTES]) {
size_t i;
2020-10-28 16:02:04 +00:00
uint8_t buf[SABER_L * SABER_POLYCOINBYTES];
2019-06-18 15:37:25 +01:00
2020-10-28 16:02:04 +00:00
shake128(buf, sizeof(buf), seed, SABER_NOISESEEDBYTES);
2019-06-18 15:37:25 +01:00
for (i = 0; i < SABER_L; i++) {
2020-10-28 16:02:04 +00:00
PQCLEAN_FIRESABER_CLEAN_cbd(s[i].coeffs, buf + i * SABER_POLYCOINBYTES);
2019-06-18 15:37:25 +01:00
}
}