Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_crypto/src/c/poly.c

1.3 KiB, 1 run

created by r1870400018:212, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1#include <stdio.h>
2#include "api.h"
3#include "poly.h"
4#include "poly_mul.h"
5#include "pack_unpack.h"
6#include "cbd.h"
7#include "fips202.h"
8
9void MatrixVectorMul(const uint16_t A[SABER_L][SABER_L][SABER_N], const uint16_t s[SABER_L][SABER_N], uint16_t res[SABER_L][SABER_N], int16_t transpose)
10{
11 int i, j;
12 for (i = 0; i < SABER_L; i++)
13 {
14 for (j = 0; j < SABER_L; j++)
15 {
16 if (transpose == 1)
17 {
18 poly_mul_acc(A[j][i], s[j], res[i]);
19 }
20 else
21 {
22 poly_mul_acc(A[i][j], s[j], res[i]);
23 }
24 }
25 }
26}
27
28void InnerProd(const uint16_t b[SABER_L][SABER_N], const uint16_t s[SABER_L][SABER_N], uint16_t res[SABER_N])
29{
30 int j;
31 for (j = 0; j < SABER_L; j++)
32 {
33 poly_mul_acc(b[j], s[j], res);
34 }
35}
36
37void GenMatrix(uint16_t A[SABER_L][SABER_L][SABER_N], const uint8_t seed[SABER_SEEDBYTES])
38{
39 uint8_t buf[SABER_L * SABER_POLYVECBYTES];
40 int i;
41
42 saber_shake128(buf, sizeof(buf), seed, SABER_SEEDBYTES);
43
44 for (i = 0; i < SABER_L; i++)
45 {
46 BS2POLVECq(buf + i * SABER_POLYVECBYTES, A[i]);
47 }
48}
49
50void GenSecret(uint16_t s[SABER_L][SABER_N], const uint8_t seed[SABER_NOISE_SEEDBYTES])
51{
52 uint8_t buf[SABER_L * SABER_POLYCOINBYTES];
53 size_t i;
54
55 saber_shake128(buf, sizeof(buf), seed, SABER_NOISE_SEEDBYTES);
56
57 for (i = 0; i < SABER_L; i++)
58 {
59 cbd(s[i], buf + i * SABER_POLYCOINBYTES);
60 }
61}