-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit.h
202 lines (173 loc) · 5.24 KB
/
commit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* @defgroup commit Lattice-based commitment.
*/
/**
* @file
*
* Interface of the lattice-based commitment scheme.
*
* @ingroup commit
*/
#include <flint/flint.h>
#include <flint/nmod_poly.h>
/*============================================================================*/
/* Constant definitions */
/*============================================================================*/
/* Parameter v in the commitment scheme (laximum l1-norm of challs). */
#define NONZERO 36
/* The \infty-norm bound of certain elements. */
#define BETA 1
/* Width k of the comming matrix. */
#define WIDTH 3
/* Height of the commitment matrix. */
#define HEIGHT 1
/*============================================================================*/
/* Type definitions */
/*============================================================================*/
/* Type that represents a polynomial in CRT representation. */
typedef nmod_poly_t pcrt_poly_t[2];
/* Type that represents a commitment key pair. */
typedef struct _key_t {
pcrt_poly_t B1[HEIGHT][WIDTH];
pcrt_poly_t b2[WIDTH];
} commitkey_t;
/* Type that represents a commitment in CRT representation. */
typedef struct _com_t {
pcrt_poly_t c1, c2;
} commit_t;
/*============================================================================*/
/* Function prototypes */
/*============================================================================*/
/**
* Initialize the commitment module.
*/
void commit_setup();
/**
* Finalize the commitment module.
*/
void commit_finish();
/**
* Return the polynomial (x^N + 1) defining the cyclotomic ring Rp.
*
* @return the polynomial defining the cyclotomic ring Rp.
*/
nmod_poly_t *commit_poly();
/**
* Return the i-th polynomial defining the CRT representation.
* The returned polynomial is such that it factors the polynomial defining Rp.
*
* @return the i-th irreducible polynomial defining the CRT representation.
*/
nmod_poly_t *commit_irred(int i);
/* Recover polynomial from CRT representation.
*
* @param[in] c - the resulting polynomial.
* @param[in] a - the polynomial in CRT representation.
*/
void pcrt_poly_rec(nmod_poly_t c, pcrt_poly_t a);
/* Convert polynomial to CRT representation.
*
* @param[in] a - the resulting polynomial in CRT representation.
* @param[in] c - the polynomial to convert.
*/
void pcrt_poly_convert(pcrt_poly_t a, nmod_poly_t c);
/* Compute the squared l2-norm of a polynomial.
*
* @param[in] r - the polynomial to compute the norm.
* @return The squared l2-norm.
*/
uint64_t commit_norm2_sqr(nmod_poly_t r);
/* Compute the l\infty-norm of a polynomial.
*
* @param[in] r - the polynomial to compute the norm.
* @return The l\infty-norm.
*/
uint64_t commit_norm_inf(nmod_poly_t r);
/**
* Generate a key pair for the commitment scheme using a PRNG.
*
* @param[out] key - the generated key pair.
* @param[in] rand - the random number generator.
*/
void commit_keygen(commitkey_t *key, flint_rand_t rand);
/**
* Free a key pair for the commitment scheme.
*
* @param[out] key - the generated key pair.
* @param[in] rand - the random number generator.
*/
void commit_keyfree(commitkey_t *key);
/**
* Sample a short polynomial.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_short(nmod_poly_t r);
/**
* Sample a short polynomial in CRT representation.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_short_crt(pcrt_poly_t r);
/**
* Sample a random polynomial.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_rand(nmod_poly_t r, flint_rand_t rand, int degree);
/**
* Sample a random polynomial in CRT representation.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_rand_crt(pcrt_poly_t r, flint_rand_t rand);
/**
* Sample a random challenge.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_chall(nmod_poly_t f);
/**
* Sample a random challenge in CRT representation.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_chall_crt(pcrt_poly_t f);
/**
* Sample a random polynomial following a Gaussian distribution.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_gauss(nmod_poly_t r);
/**
* Sample a random polynomial following a Gaussian distribution in CRT
* representation.
*
* @param[out] r - the polynomial to sample.
*/
void commit_sample_gauss_crt(pcrt_poly_t r);
/**
* Commit to a message and randomness using a key pair.
*
* @param[out] com - the resulting commitment.
* @param[in] m - the message to commit.
* @param[in] r - the commitment randomness.
*/
void commit_doit(commit_t *com, nmod_poly_t m, commitkey_t *key,
pcrt_poly_t r[WIDTH]);
/**
* Open a commitment on a certain message.
*
* @param[in] com - the commitment to open.
* @param[in] m - the associated message.
* @param[in] r - the opening randomness.
* @param[in] f - the opening challenge.
*/
int commit_open(commit_t *com, nmod_poly_t m, commitkey_t *key,
pcrt_poly_t r[WIDTH], pcrt_poly_t f);
/**
* Free a commitment.
*
* @param[out] com - the commitment to free.
*/
void commit_free(commit_t *com);