-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshuffle.h
201 lines (144 loc) · 5.55 KB
/
shuffle.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
#include <relic/relic.h>
#define NR_ELGAMAL_COMPONENTS 2
// Sizes in bits
#define SHUFFLE_LENGTH_E 160
#define SHUFFLE_LENGTH_S 80
struct shuffle_com_pk {
g1_t *bases;
g1_t rand_base;
size_t nr_bases;
bn_t q;
};
struct shuffle_com {
g1_t com;
size_t n;
};
struct shuffle_elgamal_sk {
bn_t sk;
};
struct shuffle_elgamal_pk {
g1_t gen;
g1_t pk;
bn_t q;
};
struct shuffle_elgamal_randomizer {
size_t n;
bn_t rand[NR_ELGAMAL_COMPONENTS];
};
/*
* Elgamal ciphertext encoding n messages
*/
struct shuffle_elgamal_ctxt {
size_t n;
g1_t c1[NR_ELGAMAL_COMPONENTS];
g1_t c2[NR_ELGAMAL_COMPONENTS];
};
struct shuffle_known_proof {
size_t n;
bn_t x;
bn_t e;
struct shuffle_com cd, cdelta, ca;
bn_t *f;
bn_t z;
bn_t *fdelta;
bn_t zdelta;
};
struct shuffle_proof {
size_t n;
struct shuffle_com c, cd;
struct shuffle_elgamal_ctxt Ed;
uint8_t tseed[MD_LEN_SH256];
bn_t *f;
struct shuffle_elgamal_randomizer Z;
uint8_t lambdabase[MD_LEN_SH256];
struct shuffle_known_proof known_proof;
};
void unsafe_random_permutation(unsigned int *perm, size_t n);
// ****************************
// Pederson's commitment scheme
// ****************************
void shuffle_commit_keygen(struct shuffle_com_pk *pk, size_t n);
void shuffle_commit_new(struct shuffle_com *com, size_t n);
void shuffle_commit_to(struct shuffle_com *com, bn_t *vals, size_t n, bn_t r,
struct shuffle_com_pk *pk);
void shuffle_commit_exp(struct shuffle_com *res, struct shuffle_com *com,
bn_t exp);
void shuffle_commit_mul(struct shuffle_com *res, struct shuffle_com *com,
struct shuffle_com *mul);
void shuffle_commit_print(struct shuffle_com *com);
int shuffle_commit_equal(struct shuffle_com *left, struct shuffle_com *right);
// ******************
// ElGamal encryption
// ******************
void shuffle_elgamal_keygen(struct shuffle_elgamal_pk *pk,
struct shuffle_elgamal_sk *sk);
void shuffle_elgamal_init(struct shuffle_elgamal_ctxt *ctxt, size_t n);
void shuffle_elgamal_randomizer(struct shuffle_elgamal_randomizer *rand,
struct shuffle_elgamal_ctxt *ctxt, struct shuffle_elgamal_pk *pk);
void shuffle_elgamal_randomizer_init(struct shuffle_elgamal_randomizer *rand,
struct shuffle_elgamal_ctxt *ctxt);
void shuffle_elgamal_randomizer_add(
struct shuffle_elgamal_randomizer *res,
struct shuffle_elgamal_randomizer *a,
struct shuffle_elgamal_randomizer *b,
struct shuffle_elgamal_pk *pk);
void
shuffle_elgamal_randomizer_multiply(
struct shuffle_elgamal_randomizer *res,
struct shuffle_elgamal_randomizer *a,
bn_t t, struct shuffle_elgamal_pk *pk);
size_t
shuffle_elgamal_randomizer_size( struct shuffle_elgamal_randomizer *rand);
void shuffle_elgamal_empty_ctxt(struct shuffle_elgamal_ctxt *ctxt,
const struct shuffle_elgamal_randomizer *rand,
const struct shuffle_elgamal_pk *pk);
void shuffle_elgamal_exp(struct shuffle_elgamal_ctxt *res,
const struct shuffle_elgamal_ctxt *a,
const bn_t exp);
void shuffle_elgamal_copy(struct shuffle_elgamal_ctxt *ctxt,
struct shuffle_elgamal_ctxt *orig);
void shuffle_elgamal_multiply(struct shuffle_elgamal_ctxt *res,
const struct shuffle_elgamal_ctxt *a,
const struct shuffle_elgamal_ctxt *b);
void shuffle_elgamal_encrypt(struct shuffle_elgamal_ctxt *ctxt,
g1_t *msgs, size_t n, struct shuffle_elgamal_pk *pk);
void shuffle_elgamal_encrypt_with_randomizer(
struct shuffle_elgamal_ctxt *ctxt, g1_t *msgs,
size_t n, struct shuffle_elgamal_randomizer *rand,
struct shuffle_elgamal_pk *pk);
void shuffle_elgamal_decrypt(g1_t *msgs, struct shuffle_elgamal_ctxt *ctxt,
struct shuffle_elgamal_sk *sk);
size_t shuffle_elgamal_size(struct shuffle_elgamal_ctxt *ctxt);
size_t shuffle_elgamal_pk_size(struct shuffle_elgamal_pk *pk);
void shuffle_elgamal_write_bin(uint8_t *ptr, struct shuffle_elgamal_ctxt *ctxt);
void shuffle_elgamal_derandomize( struct shuffle_elgamal_ctxt *res,
struct shuffle_elgamal_ctxt *a, bn_t rand);
// ***********************
// Proof of known contents
// ***********************
void shuffle_prove_known_content(struct shuffle_known_proof *proof,
struct shuffle_com *c, bn_t r, bn_t *vals, size_t n,
unsigned int *perm, struct shuffle_com_pk *pk, uint8_t *context,
size_t lcontext);
int shuffle_verify_known_content_proof(struct shuffle_known_proof *proof,
struct shuffle_com *c, bn_t *vals, size_t n,
struct shuffle_com_pk *pk, uint8_t *context, size_t lcontext);
size_t shuffle_known_proof_size(struct shuffle_known_proof *p);
void shuffle_and_randomize( struct shuffle_elgamal_ctxt *e,
struct shuffle_elgamal_ctxt **E_res,
struct shuffle_elgamal_randomizer **rand_res,
unsigned int **perm_res,
size_t n, struct shuffle_elgamal_pk *pk);
void
shuffle_prove(struct shuffle_proof *proof,
struct shuffle_elgamal_ctxt *e, struct shuffle_elgamal_ctxt *E,
size_t n, struct shuffle_elgamal_pk *pk, struct shuffle_com_pk *ck,
unsigned int *perm, struct shuffle_elgamal_randomizer *R,
uint8_t *context, size_t lcontext);
int
shuffle_proof_verify(struct shuffle_proof *proof,
struct shuffle_elgamal_ctxt *e, struct shuffle_elgamal_ctxt *E,
size_t n, struct shuffle_elgamal_pk *pk, struct shuffle_com_pk *ck,
uint8_t *context, size_t lcontext);
size_t shuffle_proof_size(struct shuffle_proof *p);
void shuffle_elgamal_print(struct shuffle_elgamal_ctxt *ctxt);