1#![allow(clippy::too_many_arguments)]
2
3use poulpy_hal::{
4 layouts::{Backend, NoiseInfos, ScalarZnxToBackendRef, ScratchArena, ZnxInfos},
5 source::Source,
6};
7
8use crate::{
9 GetDistribution, GetDistributionMut,
10 layouts::{
11 GGLWEInfos, GGLWEToBackendMut, GGLWEToGGSWKeyCompressedToBackendMut, GGLWEToGGSWKeyToBackendMut, GGSWAtViewMut,
12 GGSWCompressedSeedMut, GGSWCompressedToBackendMut, GGSWInfos, GGSWToBackendMut, GLWECompressedSeedMut,
13 GLWECompressedToBackendMut, GLWEInfos, GLWESecretToBackendRef, GLWESwitchingKeyDegreesMut, GLWEToBackendMut,
14 GLWEToBackendRef, LWEInfos, LWEPlaintextToBackendRef, LWESecretToBackendRef, LWEToBackendMut, SetGaloisElement,
15 TorusPrecision,
16 compressed::{GGLWECompressedSeedMut, GGLWECompressedToBackendMut},
17 prepared::{GLWEPreparedToBackendRef, GLWESecretPreparedToBackendRef},
18 },
19};
20
21pub trait DeclaredK: LWEInfos {
22 fn k(&self) -> TorusPrecision;
23}
24
25pub trait EncryptionInfos {
26 fn noise_infos(&self) -> NoiseInfos;
27}
28
29pub trait LWEEncryptSk<BE: Backend> {
30 fn lwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
31 where
32 A: LWEInfos;
33
34 fn lwe_encrypt_sk<R, P, S, E>(
35 &self,
36 res: &mut R,
37 pt: &P,
38 sk: &S,
39 enc_infos: &E,
40 source_xe: &mut Source,
41 source_xa: &mut Source,
42 scratch: &mut ScratchArena<'_, BE>,
43 ) where
44 R: LWEToBackendMut<BE> + LWEInfos,
45 P: LWEPlaintextToBackendRef<BE>,
46 S: LWESecretToBackendRef<BE>,
47 E: EncryptionInfos;
48}
49
50pub trait GLWEEncryptSk<BE: Backend> {
51 fn glwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
52 where
53 A: GLWEInfos;
54
55 fn glwe_encrypt_sk<R, P, S, E>(
56 &self,
57 res: &mut R,
58 pt: &P,
59 sk: &S,
60 enc_infos: &E,
61 source_xe: &mut Source,
62 source_xa: &mut Source,
63 scratch: &mut ScratchArena<'_, BE>,
64 ) where
65 R: GLWEToBackendMut<BE>,
66 P: GLWEToBackendRef<BE>,
67 E: EncryptionInfos,
68 S: GLWESecretPreparedToBackendRef<BE>;
69
70 fn glwe_encrypt_zero_sk<R, E, S>(
71 &self,
72 res: &mut R,
73 sk: &S,
74 enc_infos: &E,
75 source_xe: &mut Source,
76 source_xa: &mut Source,
77 scratch: &mut ScratchArena<'_, BE>,
78 ) where
79 R: GLWEToBackendMut<BE>,
80 E: EncryptionInfos,
81 S: GLWESecretPreparedToBackendRef<BE>;
82}
83
84pub trait GLWEEncryptPk<BE: Backend> {
85 fn glwe_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
86 where
87 A: GLWEInfos;
88
89 fn glwe_encrypt_pk<R, P, K, E>(
90 &self,
91 res: &mut R,
92 pt: &P,
93 pk: &K,
94 enc_infos: &E,
95 source_xu: &mut Source,
96 source_xe: &mut Source,
97 scratch: &mut ScratchArena<'_, BE>,
98 ) where
99 R: GLWEToBackendMut<BE> + GLWEInfos,
100 P: GLWEToBackendRef<BE> + GLWEInfos,
101 E: EncryptionInfos,
102 K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos;
103
104 fn glwe_encrypt_zero_pk<R, K, E>(
105 &self,
106 res: &mut R,
107 pk: &K,
108 enc_infos: &E,
109 source_xu: &mut Source,
110 source_xe: &mut Source,
111 scratch: &mut ScratchArena<'_, BE>,
112 ) where
113 R: GLWEToBackendMut<BE> + GLWEInfos,
114 E: EncryptionInfos,
115 K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos;
116}
117
118pub trait GLWEPublicKeyGenerate<BE: Backend> {
119 fn glwe_public_key_generate<R, S, E>(
120 &self,
121 res: &mut R,
122 sk: &S,
123 enc_infos: &E,
124 source_xe: &mut Source,
125 source_xa: &mut Source,
126 ) where
127 R: GLWEToBackendMut<BE> + GetDistributionMut + GLWEInfos,
128 E: EncryptionInfos,
129 S: GLWESecretPreparedToBackendRef<BE> + GetDistribution;
130}
131
132pub trait GGLWEEncryptSk<BE: Backend> {
133 fn gglwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
134 where
135 A: GGLWEInfos;
136
137 fn gglwe_encrypt_sk<R, P, S, E>(
138 &self,
139 res: &mut R,
140 pt: &P,
141 sk: &S,
142 enc_infos: &E,
143 source_xe: &mut Source,
144 source_xa: &mut Source,
145 scratch: &mut ScratchArena<'_, BE>,
146 ) where
147 R: GGLWEToBackendMut<BE>,
148 P: ScalarZnxToBackendRef<BE>,
149 E: EncryptionInfos,
150 S: GLWESecretPreparedToBackendRef<BE>;
151}
152
153pub trait GGSWEncryptSk<BE: Backend> {
154 fn ggsw_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
155 where
156 A: GGSWInfos;
157
158 fn ggsw_encrypt_sk<R, P, S, E>(
159 &self,
160 res: &mut R,
161 pt: &P,
162 sk: &S,
163 enc_infos: &E,
164 source_xe: &mut Source,
165 source_xa: &mut Source,
166 scratch: &mut ScratchArena<'_, BE>,
167 ) where
168 R: GGSWToBackendMut<BE> + GGSWInfos + GGSWAtViewMut<BE>,
169 P: ScalarZnxToBackendRef<BE> + ZnxInfos,
170 E: EncryptionInfos,
171 S: GLWESecretPreparedToBackendRef<BE> + LWEInfos + GLWEInfos;
172}
173
174pub trait GGLWEToGGSWKeyEncryptSk<BE: Backend> {
175 fn gglwe_to_ggsw_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
176 where
177 A: GGLWEInfos;
178
179 fn gglwe_to_ggsw_key_encrypt_sk<R, S, E>(
180 &self,
181 res: &mut R,
182 sk: &S,
183 enc_infos: &E,
184 source_xe: &mut Source,
185 source_xa: &mut Source,
186 scratch: &mut ScratchArena<'_, BE>,
187 ) where
188 R: GGLWEToGGSWKeyToBackendMut<BE>,
189 E: EncryptionInfos,
190 S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
191}
192
193pub trait GLWESwitchingKeyEncryptSk<BE: Backend> {
194 fn glwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
195 where
196 A: GGLWEInfos;
197
198 fn glwe_switching_key_encrypt_sk<R, S1, S2, E>(
199 &self,
200 res: &mut R,
201 sk_in: &S1,
202 sk_out: &S2,
203 enc_infos: &E,
204 source_xe: &mut Source,
205 source_xa: &mut Source,
206 scratch: &mut ScratchArena<'_, BE>,
207 ) where
208 R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
209 E: EncryptionInfos,
210 S1: GLWESecretToBackendRef<BE> + GLWEInfos,
211 S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
212}
213
214pub trait GLWESwitchingKeyEncryptPk<BE: Backend> {
215 fn glwe_switching_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
216 where
217 A: GGLWEInfos;
218}
219
220pub trait GLWETensorKeyEncryptSk<BE: Backend> {
221 fn glwe_tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
222 where
223 A: GGLWEInfos;
224
225 fn glwe_tensor_key_encrypt_sk<R, S, E>(
226 &self,
227 res: &mut R,
228 sk: &S,
229 enc_infos: &E,
230 source_xe: &mut Source,
231 source_xa: &mut Source,
232 scratch: &mut ScratchArena<'_, BE>,
233 ) where
234 R: GGLWEToBackendMut<BE> + GGLWEInfos,
235 E: EncryptionInfos,
236 S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
237}
238
239pub trait GLWEToLWESwitchingKeyEncryptSk<BE: Backend> {
240 fn glwe_to_lwe_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
241 where
242 A: GGLWEInfos;
243
244 fn glwe_to_lwe_key_encrypt_sk<R, S1, S2, E>(
245 &self,
246 res: &mut R,
247 sk_lwe: &S1,
248 sk_glwe: &S2,
249 enc_infos: &E,
250 source_xe: &mut Source,
251 source_xa: &mut Source,
252 scratch: &mut ScratchArena<'_, BE>,
253 ) where
254 S1: LWESecretToBackendRef<BE>,
255 S2: GLWESecretToBackendRef<BE>,
256 E: EncryptionInfos,
257 R: GGLWEToBackendMut<BE> + GGLWEInfos;
258}
259
260pub trait LWESwitchingKeyEncrypt<BE: Backend> {
261 fn lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
262 where
263 A: GGLWEInfos;
264
265 fn lwe_switching_key_encrypt_sk<R, S1, S2, E>(
266 &self,
267 res: &mut R,
268 sk_lwe_in: &S1,
269 sk_lwe_out: &S2,
270 enc_infos: &E,
271 source_xe: &mut Source,
272 source_xa: &mut Source,
273 scratch: &mut ScratchArena<'_, BE>,
274 ) where
275 R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
276 E: EncryptionInfos,
277 S1: LWESecretToBackendRef<BE>,
278 S2: LWESecretToBackendRef<BE>;
279}
280
281pub trait LWEToGLWESwitchingKeyEncryptSk<BE: Backend> {
282 fn lwe_to_glwe_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
283 where
284 A: GGLWEInfos;
285
286 fn lwe_to_glwe_key_encrypt_sk<R, S1, S2, E>(
287 &self,
288 res: &mut R,
289 sk_lwe: &S1,
290 sk_glwe: &S2,
291 enc_infos: &E,
292 source_xe: &mut Source,
293 source_xa: &mut Source,
294 scratch: &mut ScratchArena<'_, BE>,
295 ) where
296 S1: LWESecretToBackendRef<BE>,
297 S2: GLWESecretPreparedToBackendRef<BE>,
298 E: EncryptionInfos,
299 R: GGLWEToBackendMut<BE> + GGLWEInfos;
300}
301
302pub trait GLWEAutomorphismKeyEncryptSk<BE: Backend> {
303 fn glwe_automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
304 where
305 A: GGLWEInfos;
306
307 fn glwe_automorphism_key_encrypt_sk<R, S, E>(
308 &self,
309 res: &mut R,
310 p: i64,
311 sk: &S,
312 enc_infos: &E,
313 source_xe: &mut Source,
314 source_xa: &mut Source,
315 scratch: &mut ScratchArena<'_, BE>,
316 ) where
317 R: GGLWEToBackendMut<BE> + SetGaloisElement + GGLWEInfos,
318 E: EncryptionInfos,
319 S: GLWESecretToBackendRef<BE> + GLWEInfos;
320}
321
322pub trait GLWEAutomorphismKeyEncryptPk<BE: Backend> {
323 fn glwe_automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
324 where
325 A: GGLWEInfos;
326}
327
328pub trait GLWECompressedEncryptSk<BE: Backend> {
329 fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
330 where
331 A: GLWEInfos;
332
333 fn glwe_compressed_encrypt_sk<R, P, S, E>(
334 &self,
335 res: &mut R,
336 pt: &P,
337 sk: &S,
338 seed_xa: [u8; 32],
339 enc_infos: &E,
340 source_xe: &mut Source,
341 scratch: &mut ScratchArena<'_, BE>,
342 ) where
343 R: GLWECompressedToBackendMut<BE> + GLWECompressedSeedMut,
344 P: GLWEToBackendRef<BE>,
345 E: EncryptionInfos,
346 S: GLWESecretPreparedToBackendRef<BE>;
347}
348
349pub trait GGLWECompressedEncryptSk<BE: Backend> {
350 fn gglwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
351 where
352 A: GGLWEInfos;
353
354 fn gglwe_compressed_encrypt_sk<R, P, S, E>(
355 &self,
356 res: &mut R,
357 pt: &P,
358 sk: &S,
359 seed: [u8; 32],
360 enc_infos: &E,
361 source_xe: &mut Source,
362 scratch: &mut ScratchArena<'_, BE>,
363 ) where
364 R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut,
365 P: ScalarZnxToBackendRef<BE>,
366 E: EncryptionInfos,
367 S: GLWESecretPreparedToBackendRef<BE>;
368}
369
370pub trait GGSWCompressedEncryptSk<BE: Backend> {
371 fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
372 where
373 A: GGSWInfos;
374
375 fn ggsw_compressed_encrypt_sk<R, P, S, E>(
376 &self,
377 res: &mut R,
378 pt: &P,
379 sk: &S,
380 seed_xa: [u8; 32],
381 enc_infos: &E,
382 source_xe: &mut Source,
383 scratch: &mut ScratchArena<'_, BE>,
384 ) where
385 R: GGSWCompressedToBackendMut<BE> + GGSWCompressedSeedMut + GGSWInfos,
386 P: ScalarZnxToBackendRef<BE>,
387 E: EncryptionInfos,
388 S: GLWESecretPreparedToBackendRef<BE>;
389}
390
391pub trait GLWESwitchingKeyCompressedEncryptSk<BE: Backend> {
392 fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
393 where
394 A: GGLWEInfos;
395
396 fn glwe_switching_key_compressed_encrypt_sk<R, S1, S2, E>(
397 &self,
398 res: &mut R,
399 sk_in: &S1,
400 sk_out: &S2,
401 seed_xa: [u8; 32],
402 enc_infos: &E,
403 source_xe: &mut Source,
404 scratch: &mut ScratchArena<'_, BE>,
405 ) where
406 R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + GLWESwitchingKeyDegreesMut + GGLWEInfos,
407 E: EncryptionInfos,
408 S1: GLWESecretToBackendRef<BE> + GLWEInfos,
409 S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
410}
411
412pub trait GLWEAutomorphismKeyCompressedEncryptSk<BE: Backend> {
413 fn glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
414 where
415 A: GGLWEInfos;
416
417 fn glwe_automorphism_key_compressed_encrypt_sk<R, S, E>(
418 &self,
419 res: &mut R,
420 p: i64,
421 sk: &S,
422 seed_xa: [u8; 32],
423 enc_infos: &E,
424 source_xe: &mut Source,
425 scratch: &mut ScratchArena<'_, BE>,
426 ) where
427 R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos,
428 E: EncryptionInfos,
429 S: GLWESecretToBackendRef<BE> + GLWEInfos;
430}
431
432pub trait GLWETensorKeyCompressedEncryptSk<BE: Backend> {
433 fn glwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
434 where
435 A: GGLWEInfos;
436
437 fn glwe_tensor_key_compressed_encrypt_sk<R, S, E>(
438 &self,
439 res: &mut R,
440 sk: &S,
441 seed_xa: [u8; 32],
442 enc_infos: &E,
443 source_xe: &mut Source,
444 scratch: &mut ScratchArena<'_, BE>,
445 ) where
446 R: GGLWECompressedToBackendMut<BE> + GGLWEInfos + GGLWECompressedSeedMut,
447 E: EncryptionInfos,
448 S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
449}
450
451pub trait GGLWEToGGSWKeyCompressedEncryptSk<BE: Backend> {
452 fn gglwe_to_ggsw_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
453 where
454 A: GGLWEInfos;
455
456 fn gglwe_to_ggsw_key_compressed_encrypt_sk<R, S, E>(
457 &self,
458 res: &mut R,
459 sk: &S,
460 seed_xa: [u8; 32],
461 enc_infos: &E,
462 source_xe: &mut Source,
463 scratch: &mut ScratchArena<'_, BE>,
464 ) where
465 R: GGLWEToGGSWKeyCompressedToBackendMut<BE> + GGLWEInfos,
466 E: EncryptionInfos,
467 S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
468}