1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-23 16:08:59 +00:00
pqcrypto/crypto_kem/saber/clean/poly.c

58 lines
1.7 KiB
C
Raw Normal View History

#include "api.h"
2019-06-18 10:00:33 +01:00
#include "cbd.h"
#include "fips202.h"
#include "pack_unpack.h"
2019-06-18 10:00:33 +01:00
#include "poly.h"
#include <stddef.h>
2019-06-18 10:00:33 +01:00
2020-10-28 16:02:04 +00:00
void PQCLEAN_SABER_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_SABER_CLEAN_poly_mul(&c[i], &A[0][i], &s[0], 0);
for (j = 1; j < SABER_L; j++) {
PQCLEAN_SABER_CLEAN_poly_mul(&c[i], &A[j][i], &s[j], 1);
}
}
} else {
for (i = 0; i < SABER_L; i++) {
PQCLEAN_SABER_CLEAN_poly_mul(&c[i], &A[i][0], &s[0], 0);
for (j = 1; j < SABER_L; j++) {
PQCLEAN_SABER_CLEAN_poly_mul(&c[i], &A[i][j], &s[j], 1);
}
}
}
}
2020-10-28 16:02:04 +00:00
void PQCLEAN_SABER_CLEAN_InnerProd(poly *c, const poly b[SABER_L], const poly s[SABER_L]) {
size_t i;
PQCLEAN_SABER_CLEAN_poly_mul(c, &b[0], &s[0], 0);
for (i = 1; i < SABER_L; i++) {
PQCLEAN_SABER_CLEAN_poly_mul(c, &b[i], &s[i], 1);
}
}
2020-10-28 16:02:04 +00:00
void PQCLEAN_SABER_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_SABER_CLEAN_BS2POLVECq(A[i], buf + i * SABER_POLYVECBYTES);
}
}
2020-10-28 16:02:04 +00:00
void PQCLEAN_SABER_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 10:00:33 +01:00
2020-10-28 16:02:04 +00:00
shake128(buf, sizeof(buf), seed, SABER_NOISESEEDBYTES);
2019-06-18 10:00:33 +01:00
for (i = 0; i < SABER_L; i++) {
2020-10-28 16:02:04 +00:00
PQCLEAN_SABER_CLEAN_cbd(s[i].coeffs, buf + i * SABER_POLYCOINBYTES);
2019-06-18 10:00:33 +01:00
}
}