pqc/crypto_kem/firesaber/clean/poly.c

50 lines
1.6 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 "poly_mul.h"
#include <stdio.h>
2019-06-18 15:37:25 +01:00
void PQCLEAN_FIRESABER_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) {
int i, j;
for (i = 0; i < SABER_L; i++) {
for (j = 0; j < SABER_L; j++) {
if (transpose == 1) {
PQCLEAN_FIRESABER_CLEAN_poly_mul_acc(A[j][i], s[j], res[i]);
} else {
PQCLEAN_FIRESABER_CLEAN_poly_mul_acc(A[i][j], s[j], res[i]);
}
}
}
}
void PQCLEAN_FIRESABER_CLEAN_InnerProd(uint16_t res[SABER_N], const uint16_t b[SABER_L][SABER_N], const uint16_t s[SABER_L][SABER_N]) {
int j;
for (j = 0; j < SABER_L; j++) {
PQCLEAN_FIRESABER_CLEAN_poly_mul_acc(b[j], s[j], res);
}
}
void PQCLEAN_FIRESABER_CLEAN_GenMatrix(uint16_t A[SABER_L][SABER_L][SABER_N], const uint8_t seed[SABER_SEEDBYTES]) {
uint8_t buf[SABER_L * SABER_POLYVECBYTES];
int i;
shake128(buf, sizeof(buf), seed, SABER_SEEDBYTES);
for (i = 0; i < SABER_L; i++) {
PQCLEAN_FIRESABER_CLEAN_BS2POLVECq(A[i], buf + i * SABER_POLYVECBYTES);
}
}
void PQCLEAN_FIRESABER_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 15:37:25 +01:00
shake128(buf, sizeof(buf), seed, SABER_NOISE_SEEDBYTES);
2019-06-18 15:37:25 +01:00
for (i = 0; i < SABER_L; i++) {
PQCLEAN_FIRESABER_CLEAN_cbd(s[i], buf + i * SABER_POLYCOINBYTES);
2019-06-18 15:37:25 +01:00
}
}