-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfhe.cdecl
323 lines (265 loc) · 7.53 KB
/
tfhe.cdecl
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
;;;; TFHE bindings for MIT Scheme
(typedef int32_t int)
(typedef uint32_t uint)
;;; Parameters
(typedef TFheGateBootstrappingParameterSet
(struct TFheGateBootstrappingParameterSet
(ks_t (const int))
(ks_basebit (const int))
(in_out_params (const (* (const LweParams))))
(tgsw_params (const (* (const TGswParams))))))
(extern (* TFheGateBootstrappingParameterSet)
new_default_gate_bootstrapping_parameters
(minimum_lambda int))
(extern void
delete_gate_bootstrapping_parameters
(keyset (* TFheGateBootstrappingParameterSet)))
;;; Secret keyset
(typedef TFheGateBootstrappingSecretKeySet
(struct TFheGateBootstrappingSecretKeySet
(params (* (const TFheGateBootstrappingParameterSet)))
(lwe_key (* (const LweKey)))
(tgsw_key (* (const TGswKey)))
(cloud (const TFheGateBootstrappingCloudKeySet))))
(extern (* TFheGateBootstrappingSecretKeySet)
new_random_gate_bootstrapping_secret_keyset
(params (* (const TFheGateBootstrappingParameterSet))))
(extern void
delete_gate_bootstrapping_secret_keyset
(keyset (* TFheGateBootstrappingSecretKeySet)))
;;; Cloud keyset
(typedef LweBootstrappingKey
(struct LweBootstrappingKey
(in_out_params (* (const LweParams)))
(bk_params (* (const TGswParams)))
(accum_params (* (const TLweParams)))
(extract_params (* (const LweParams)))
(bk (* TGswSample))
(ks (* LweKeySwitchKey))))
(typedef LweParams
(struct LweParams
(n (const int))
(alpha_min (const double))
(alpha_max (const double))))
(typedef TLweParams
(struct TLweParams
(N (const int))
(k (const int))
(alpha_min (const double))
(alpha_max (const double))
(extracted_lweparams (const LweParams))))
(typedef TorusPolynomial
(struct TorusPolynomial
(N (const int))
(coefsT (* Torus32))))
(typedef TLweSample
(struct TLweSample
(a (* TorusPolynomial))
(b (* TorusPolynomial))
(current_variance double)
(k (const int))))
(typedef LagrangeHalfCPolynomial
(struct LagrangeHalfCPolynomial
(data (* void))
(precomp (* void))))
(typedef TLweSampleFFT
(struct TLweSampleFFT
(a (* LagrangeHalfCPolynomial))
(b (* LagrangeHalfCPolynomial))
(current_variance double)
(k (const int))))
(typedef TGswParams
(struct TGswParams
(l (const int))
(Bgbit (const int))
(Bg (const int))
(halfBg (const int32_t))
(maskMod (const uint32_t))
(tlwe_params (* (const TLweParams)))
(kpl (const int))
(h (* Torus32))
(offset uint32_t)))
(typedef TGswSample
(struct TGswSample
(all_sample (* TLweSample))
(bloc_sample (* (* TLweSample)))
(k (const int))
(l (const int))))
(typedef TGswSampleFFT
(struct TGswSampleFFT
(all_samples (* TLweSampleFFT))
(sample (* (* TLweSampleFFT)))
(k (const int))
(l (const int))))
(typedef IntPolynomial
(struct IntPolynomial
(N (const int))
(coefs (* int))))
(typedef TLweKey
(struct TLweKey
(params (* (const TLweParams)))
(key (* IntPolynomial))))
(typedef TGswKey
(struct TGswKey
(params (* (const TGswParams)))
(tlwe_params (* (const TLweParams)))
(key (* IntPolynomial))
(tlwe_key TLweKey)))
(typedef LweKeySwitchKey
(struct LweKeySwitchKey
(n int)
(t int)
(basebit int)
(base int)
(out_params (* (const LweParams)))
(ks0_raw (* LweSample))
(ks1_raw (* (* LweSample)))
(ks (* (* (* LweSample))))))
(typedef LweBootstrappingKeyFFT
(struct LweBootstrappingKeyFFT
(in_out_params (* (const LweParams)))
(bk_params (* (const TGswParams)))
(accum_params (* (const TLweParams)))
(extract_params (* (const LweParams)))
(bkFFT (* (const TGswSampleFFT)))
(ks (* (const LweKeySwitchKey)))))
(typedef TFheGateBootstrappingCloudKeySet
(struct TFheGateBootstrappingCloudKeySet
(params (const (* (const TFheGateBootstrappingParameterSet))))
(bk (const (* (const LweBootstrappingKey))))
(bkFFT (const (* (const LweBootstrappingKeyFFT))))))
(extern void
delete_gate_bootstrapping_cloud_keyset
(keyset (* TFheGateBootstrappingCloudKeySet)))
;;; Ciphertexts
(typedef Torus32 int32_t)
(typedef LweSample
(struct LweSample
(a (* Torus32))
(b Torus32)
(current_variance double)))
;; generate a new unititialized ciphertext (or an array of ciphertexts)
(extern (* LweSample)
new_gate_bootstrapping_ciphertext
(params (* (const TFheGateBootstrappingParameterSet))))
(extern (* LweSample)
new_gate_bootstrapping_ciphertext_array
(nbelems int)
(params (* (const TFheGateBootstrappingParameterSet))))
;; deletes a ciphertext (or an array of ciphertexts)
(extern void
delete_gate_bootstrapping_ciphertext
(sample (* LweSample)))
(extern void
delete_gate_bootstrapping_ciphertext_array
(nbelems int)
(samples (* LweSample)))
;;; Encrypt decrypt
;; encrypts a boolean
(extern void
bootsSymEncrypt
(result (* LweSample))
(message int)
(params (* (const TFheGateBootstrappingSecretKeySet))))
;; decrypts a boolean
(extern int
bootsSymDecrypt
(sample (* (const LweSample)))
(params (* (const TFheGateBootstrappingSecretKeySet))))
;;; Homomorphic operations
;; bootstrapped Constant (true or false) trivial Gate
(extern void
bootsCONSTANT
(result (* LweSample))
(value int)
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Not Gate: result = not(a)
(extern void
bootsNOT
(result (* LweSample))
(ca (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Copy Gate: result = a
(extern void
bootsCOPY
(result (* LweSample))
(ca (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Nand Gate
(extern void
bootsNAND
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Or Gate
(extern void
bootsOR
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped And Gate: result = a and b
(extern void
bootsAND
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Xor Gate: result = a xor b
(extern void
bootsXOR
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Xnor Gate: result = (a==b)
(extern void
bootsXNOR
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Nor Gate: result = not(a or b)
(extern void
bootsNOR
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped AndNY Gate: not(a) and b
(extern void
bootsANDNY
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped AndYN Gate: a and not(b)
(extern void
bootsANDYN
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped OrNY Gate: not(a) or b
(extern void
bootsORNY
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped OrYN Gate: a or not(b)
(extern void
bootsORYN
(result (* LweSample))
(ca (* (const LweSample)))
(cb (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))
;; bootstrapped Mux(a,b,c) = a?b:c
(extern void
bootsMUX
(result (* LweSample))
(a (* (const LweSample)))
(b (* (const LweSample)))
(c (* (const LweSample)))
(bk (* (const TFheGateBootstrappingCloudKeySet))))