1 #ifndef POLYVEC_H
2 #define POLYVEC_H
3 
4 #include <stdint.h>
5 #include "params.h"
6 #include "poly.h"
7 
8 /* Vectors of polynomials of length L */
9 typedef struct {
10   poly vec[L];
11 } polyvecl;
12 
13 #define polyvecl_uniform_eta DILITHIUM_NAMESPACE(polyvecl_uniform_eta)
14 void polyvecl_uniform_eta(polyvecl *v, const uint8_t seed[CRHBYTES], uint16_t nonce);
15 
16 #define polyvecl_uniform_gamma1 DILITHIUM_NAMESPACE(polyvecl_uniform_gamma1)
17 void polyvecl_uniform_gamma1(polyvecl *v, const uint8_t seed[CRHBYTES], uint16_t nonce);
18 
19 #define polyvecl_reduce DILITHIUM_NAMESPACE(polyvecl_reduce)
20 void polyvecl_reduce(polyvecl *v);
21 
22 #define polyvecl_add DILITHIUM_NAMESPACE(polyvecl_add)
23 void polyvecl_add(polyvecl *w, const polyvecl *u, const polyvecl *v);
24 
25 #define polyvecl_ntt DILITHIUM_NAMESPACE(polyvecl_ntt)
26 void polyvecl_ntt(polyvecl *v);
27 #define polyvecl_invntt_tomont DILITHIUM_NAMESPACE(polyvecl_invntt_tomont)
28 void polyvecl_invntt_tomont(polyvecl *v);
29 #define polyvecl_pointwise_poly_montgomery DILITHIUM_NAMESPACE(polyvecl_pointwise_poly_montgomery)
30 void polyvecl_pointwise_poly_montgomery(polyvecl *r, const poly *a, const polyvecl *v);
31 #define polyvecl_pointwise_acc_montgomery \
32         DILITHIUM_NAMESPACE(polyvecl_pointwise_acc_montgomery)
33 void polyvecl_pointwise_acc_montgomery(poly *w,
34                                        const polyvecl *u,
35                                        const polyvecl *v);
36 
37 #define polyvecl_chknorm DILITHIUM_NAMESPACE(polyvecl_chknorm)
38 int polyvecl_chknorm(const polyvecl *v, int32_t B);
39 
40 /* Vectors of polynomials of length K */
41 typedef struct {
42   poly vec[K];
43 } polyveck;
44 
45 #define polyveck_uniform_eta DILITHIUM_NAMESPACE(polyveck_uniform_eta)
46 void polyveck_uniform_eta(polyveck *v, const uint8_t seed[CRHBYTES], uint16_t nonce);
47 
48 #define polyveck_reduce DILITHIUM_NAMESPACE(polyveck_reduce)
49 void polyveck_reduce(polyveck *v);
50 #define polyveck_caddq DILITHIUM_NAMESPACE(polyveck_caddq)
51 void polyveck_caddq(polyveck *v);
52 
53 #define polyveck_add DILITHIUM_NAMESPACE(polyveck_add)
54 void polyveck_add(polyveck *w, const polyveck *u, const polyveck *v);
55 #define polyveck_sub DILITHIUM_NAMESPACE(polyveck_sub)
56 void polyveck_sub(polyveck *w, const polyveck *u, const polyveck *v);
57 #define polyveck_shiftl DILITHIUM_NAMESPACE(polyveck_shiftl)
58 void polyveck_shiftl(polyveck *v);
59 
60 #define polyveck_ntt DILITHIUM_NAMESPACE(polyveck_ntt)
61 void polyveck_ntt(polyveck *v);
62 #define polyveck_invntt_tomont DILITHIUM_NAMESPACE(polyveck_invntt_tomont)
63 void polyveck_invntt_tomont(polyveck *v);
64 #define polyveck_pointwise_poly_montgomery DILITHIUM_NAMESPACE(polyveck_pointwise_poly_montgomery)
65 void polyveck_pointwise_poly_montgomery(polyveck *r, const poly *a, const polyveck *v);
66 
67 #define polyveck_chknorm DILITHIUM_NAMESPACE(polyveck_chknorm)
68 int polyveck_chknorm(const polyveck *v, int32_t B);
69 
70 #define polyveck_power2round DILITHIUM_NAMESPACE(polyveck_power2round)
71 void polyveck_power2round(polyveck *v1, polyveck *v0, const polyveck *v);
72 #define polyveck_decompose DILITHIUM_NAMESPACE(polyveck_decompose)
73 void polyveck_decompose(polyveck *v1, polyveck *v0, const polyveck *v);
74 #define polyveck_make_hint DILITHIUM_NAMESPACE(polyveck_make_hint)
75 unsigned int polyveck_make_hint(uint8_t *hint, const polyveck *v0, const polyveck *v1);
76 #define polyveck_use_hint DILITHIUM_NAMESPACE(polyveck_use_hint)
77 void polyveck_use_hint(polyveck *w, const polyveck *v, const polyveck *h);
78 
79 #define polyveck_pack_w1 DILITHIUM_NAMESPACE(polyveck_pack_w1)
80 void polyveck_pack_w1(uint8_t r[K*POLYW1_PACKEDBYTES], const polyveck *w1);
81 
82 #define polyvec_matrix_expand DILITHIUM_NAMESPACE(polyvec_matrix_expand)
83 void polyvec_matrix_expand(polyvecl mat[K], const uint8_t rho[SEEDBYTES]);
84 
85 #ifndef DILITHIUM_USE_AES
86 #define polyvec_matrix_expand_row0 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row0)
87 void polyvec_matrix_expand_row0(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
88 #define polyvec_matrix_expand_row1 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row1)
89 void polyvec_matrix_expand_row1(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
90 #define polyvec_matrix_expand_row2 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row2)
91 void polyvec_matrix_expand_row2(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
92 #define polyvec_matrix_expand_row3 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row3)
93 void polyvec_matrix_expand_row3(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
94 #define polyvec_matrix_expand_row4 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row4)
95 void polyvec_matrix_expand_row4(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
96 #define polyvec_matrix_expand_row5 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row5)
97 void polyvec_matrix_expand_row5(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
98 #define polyvec_matrix_expand_row6 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row6)
99 void polyvec_matrix_expand_row6(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
100 #define polyvec_matrix_expand_row7 DILITHIUM_NAMESPACE(polyvec_matrix_expand_row7)
101 void polyvec_matrix_expand_row7(polyvecl *rowa, polyvecl *rowb, const uint8_t rho[SEEDBYTES]);
102 #endif
103 
104 #define polyvec_matrix_pointwise_montgomery DILITHIUM_NAMESPACE(polyvec_matrix_pointwise_montgomery)
105 void polyvec_matrix_pointwise_montgomery(polyveck *t, const polyvecl mat[K], const polyvecl *v);
106 
107 #endif
108