Skip to main content

poulpy_core/oep/
encryption.rs

1#![allow(clippy::too_many_arguments)]
2
3use poulpy_hal::{
4    layouts::{Backend, Module, ScalarZnxToBackendRef, ScratchArena, ZnxInfos},
5    source::Source,
6};
7
8use crate::{
9    EncryptionInfos, GetDistribution, GetDistributionMut,
10    encryption::{
11        GGLWECompressedEncryptSkDefault, GGLWEEncryptSkDefault, GGLWEToGGSWKeyCompressedEncryptSkDefault,
12        GGLWEToGGSWKeyEncryptSkDefault, GGSWCompressedEncryptSkDefault, GGSWEncryptSkDefault,
13        GLWEAutomorphismKeyCompressedEncryptSkDefault, GLWEAutomorphismKeyEncryptPkDefault, GLWEAutomorphismKeyEncryptSkDefault,
14        GLWECompressedEncryptSkDefault, GLWEEncryptPkDefault, GLWEEncryptSkDefault, GLWEPublicKeyGenerateDefault,
15        GLWESwitchingKeyCompressedEncryptSkDefault, GLWESwitchingKeyEncryptPkDefault, GLWESwitchingKeyEncryptSkDefault,
16        GLWETensorKeyCompressedEncryptSkDefault, GLWETensorKeyEncryptSkDefault, GLWEToLWESwitchingKeyEncryptSkDefault,
17        LWEEncryptSkDefault, LWESwitchingKeyEncryptDefault, LWEToGLWESwitchingKeyEncryptSkDefault,
18    },
19    layouts::{
20        GGLWECompressedSeedMut, GGLWECompressedToBackendMut, GGLWEInfos, GGLWEToBackendMut, GGLWEToGGSWKeyCompressedToBackendMut,
21        GGLWEToGGSWKeyToBackendMut, GGSWAtViewMut, GGSWCompressedSeedMut, GGSWCompressedToBackendMut, GGSWInfos,
22        GGSWToBackendMut, GLWECompressedSeedMut, GLWECompressedToBackendMut, GLWEInfos, GLWESecretToBackendRef,
23        GLWESwitchingKeyDegreesMut, GLWEToBackendMut, GLWEToBackendRef, LWEInfos, LWEPlaintextToBackendRef,
24        LWESecretToBackendRef, LWEToBackendMut, SetGaloisElement,
25        prepared::{GLWEPreparedToBackendRef, GLWESecretPreparedToBackendRef},
26    },
27};
28
29/// # Safety
30///
31/// Implementations must satisfy the contracts of all trait methods, including
32/// any HAL-level invariants (alignment, layout, scratch sizing) implied by the
33/// associated method signatures.
34pub unsafe trait EncryptionImpl<BE: Backend>: Backend {
35    fn lwe_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
36    where
37        A: LWEInfos;
38
39    fn lwe_encrypt_sk_default<R, P, S, E>(
40        module: &Module<BE>,
41        res: &mut R,
42        pt: &P,
43        sk: &S,
44        enc_infos: &E,
45        source_xe: &mut Source,
46        source_xa: &mut Source,
47        scratch: &mut ScratchArena<'_, BE>,
48    ) where
49        R: LWEToBackendMut<BE> + LWEInfos,
50        P: LWEPlaintextToBackendRef<BE>,
51        S: LWESecretToBackendRef<BE>,
52        E: EncryptionInfos;
53
54    fn glwe_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
55    where
56        A: GLWEInfos;
57
58    fn glwe_encrypt_sk_default<R, P, S, E>(
59        module: &Module<BE>,
60        res: &mut R,
61        pt: &P,
62        sk: &S,
63        enc_infos: &E,
64        source_xe: &mut Source,
65        source_xa: &mut Source,
66        scratch: &mut ScratchArena<'_, BE>,
67    ) where
68        R: GLWEToBackendMut<BE>,
69        P: GLWEToBackendRef<BE>,
70        E: EncryptionInfos,
71        S: GLWESecretPreparedToBackendRef<BE>;
72
73    fn glwe_encrypt_zero_sk_default<R, E, S>(
74        module: &Module<BE>,
75        res: &mut R,
76        sk: &S,
77        enc_infos: &E,
78        source_xe: &mut Source,
79        source_xa: &mut Source,
80        scratch: &mut ScratchArena<'_, BE>,
81    ) where
82        R: GLWEToBackendMut<BE>,
83        E: EncryptionInfos,
84        S: GLWESecretPreparedToBackendRef<BE>;
85
86    fn glwe_encrypt_pk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
87    where
88        A: GLWEInfos;
89
90    fn glwe_encrypt_pk_default<R, P, K, E>(
91        module: &Module<BE>,
92        res: &mut R,
93        pt: &P,
94        pk: &K,
95        enc_infos: &E,
96        source_xu: &mut Source,
97        source_xe: &mut Source,
98        scratch: &mut ScratchArena<'_, BE>,
99    ) where
100        R: GLWEToBackendMut<BE> + GLWEInfos,
101        P: GLWEToBackendRef<BE> + GLWEInfos,
102        E: EncryptionInfos,
103        K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos;
104
105    fn glwe_encrypt_zero_pk_default<R, K, E>(
106        module: &Module<BE>,
107        res: &mut R,
108        pk: &K,
109        enc_infos: &E,
110        source_xu: &mut Source,
111        source_xe: &mut Source,
112        scratch: &mut ScratchArena<'_, BE>,
113    ) where
114        R: GLWEToBackendMut<BE> + GLWEInfos,
115        E: EncryptionInfos,
116        K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos;
117
118    fn glwe_public_key_generate_default<R, S, E>(
119        module: &Module<BE>,
120        res: &mut R,
121        sk: &S,
122        enc_infos: &E,
123        source_xe: &mut Source,
124        source_xa: &mut Source,
125    ) where
126        R: GLWEToBackendMut<BE> + GetDistributionMut + GLWEInfos,
127        E: EncryptionInfos,
128        S: GLWESecretPreparedToBackendRef<BE> + GetDistribution;
129
130    fn gglwe_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
131    where
132        A: GGLWEInfos;
133
134    fn gglwe_encrypt_sk_default<R, P, S, E>(
135        module: &Module<BE>,
136        res: &mut R,
137        pt: &P,
138        sk: &S,
139        enc_infos: &E,
140        source_xe: &mut Source,
141        source_xa: &mut Source,
142        scratch: &mut ScratchArena<'_, BE>,
143    ) where
144        R: GGLWEToBackendMut<BE>,
145        P: ScalarZnxToBackendRef<BE>,
146        E: EncryptionInfos,
147        S: GLWESecretPreparedToBackendRef<BE>;
148
149    fn ggsw_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
150    where
151        A: GGSWInfos;
152
153    fn ggsw_encrypt_sk_default<R, P, S, E>(
154        module: &Module<BE>,
155        res: &mut R,
156        pt: &P,
157        sk: &S,
158        enc_infos: &E,
159        source_xe: &mut Source,
160        source_xa: &mut Source,
161        scratch: &mut ScratchArena<'_, BE>,
162    ) where
163        R: GGSWToBackendMut<BE> + GGSWInfos + GGSWAtViewMut<BE>,
164        P: ScalarZnxToBackendRef<BE> + ZnxInfos,
165        E: EncryptionInfos,
166        S: GLWESecretPreparedToBackendRef<BE> + LWEInfos + GLWEInfos;
167
168    fn gglwe_to_ggsw_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
169    where
170        A: GGLWEInfos;
171
172    fn gglwe_to_ggsw_key_encrypt_sk_default<R, S, E>(
173        module: &Module<BE>,
174        res: &mut R,
175        sk: &S,
176        enc_infos: &E,
177        source_xe: &mut Source,
178        source_xa: &mut Source,
179        scratch: &mut ScratchArena<'_, BE>,
180    ) where
181        R: GGLWEToGGSWKeyToBackendMut<BE>,
182        E: EncryptionInfos,
183        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
184
185    fn glwe_switching_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
186    where
187        A: GGLWEInfos;
188
189    fn glwe_switching_key_encrypt_sk_default<R, S1, S2, E>(
190        module: &Module<BE>,
191        res: &mut R,
192        sk_in: &S1,
193        sk_out: &S2,
194        enc_infos: &E,
195        source_xe: &mut Source,
196        source_xa: &mut Source,
197        scratch: &mut ScratchArena<'_, BE>,
198    ) where
199        R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
200        E: EncryptionInfos,
201        S1: GLWESecretToBackendRef<BE> + GLWEInfos,
202        S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
203
204    fn glwe_switching_key_encrypt_pk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
205    where
206        A: GGLWEInfos;
207
208    fn glwe_tensor_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
209    where
210        A: GGLWEInfos;
211
212    fn glwe_tensor_key_encrypt_sk_default<R, S, E>(
213        module: &Module<BE>,
214        res: &mut R,
215        sk: &S,
216        enc_infos: &E,
217        source_xe: &mut Source,
218        source_xa: &mut Source,
219        scratch: &mut ScratchArena<'_, BE>,
220    ) where
221        R: GGLWEToBackendMut<BE> + GGLWEInfos,
222        E: EncryptionInfos,
223        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
224
225    fn glwe_to_lwe_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
226    where
227        A: GGLWEInfos;
228
229    fn glwe_to_lwe_key_encrypt_sk_default<R, S1, S2, E>(
230        module: &Module<BE>,
231        res: &mut R,
232        sk_lwe: &S1,
233        sk_glwe: &S2,
234        enc_infos: &E,
235        source_xe: &mut Source,
236        source_xa: &mut Source,
237        scratch: &mut ScratchArena<'_, BE>,
238    ) where
239        S1: LWESecretToBackendRef<BE>,
240        S2: GLWESecretToBackendRef<BE>,
241        E: EncryptionInfos,
242        R: GGLWEToBackendMut<BE> + GGLWEInfos;
243
244    fn lwe_switching_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
245    where
246        A: GGLWEInfos;
247
248    fn lwe_switching_key_encrypt_sk_default<R, S1, S2, E>(
249        module: &Module<BE>,
250        res: &mut R,
251        sk_lwe_in: &S1,
252        sk_lwe_out: &S2,
253        enc_infos: &E,
254        source_xe: &mut Source,
255        source_xa: &mut Source,
256        scratch: &mut ScratchArena<'_, BE>,
257    ) where
258        R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
259        E: EncryptionInfos,
260        S1: LWESecretToBackendRef<BE>,
261        S2: LWESecretToBackendRef<BE>;
262
263    fn lwe_to_glwe_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
264    where
265        A: GGLWEInfos;
266
267    fn lwe_to_glwe_key_encrypt_sk_default<R, S1, S2, E>(
268        module: &Module<BE>,
269        res: &mut R,
270        sk_lwe: &S1,
271        sk_glwe: &S2,
272        enc_infos: &E,
273        source_xe: &mut Source,
274        source_xa: &mut Source,
275        scratch: &mut ScratchArena<'_, BE>,
276    ) where
277        S1: LWESecretToBackendRef<BE>,
278        S2: GLWESecretPreparedToBackendRef<BE>,
279        E: EncryptionInfos,
280        R: GGLWEToBackendMut<BE> + GGLWEInfos;
281
282    fn glwe_automorphism_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
283    where
284        A: GGLWEInfos;
285
286    fn glwe_automorphism_key_encrypt_sk_default<R, S, E>(
287        module: &Module<BE>,
288        res: &mut R,
289        p: i64,
290        sk: &S,
291        enc_infos: &E,
292        source_xe: &mut Source,
293        source_xa: &mut Source,
294        scratch: &mut ScratchArena<'_, BE>,
295    ) where
296        R: GGLWEToBackendMut<BE> + SetGaloisElement + GGLWEInfos,
297        E: EncryptionInfos,
298        S: GLWESecretToBackendRef<BE> + GLWEInfos;
299
300    fn glwe_automorphism_key_encrypt_pk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
301    where
302        A: GGLWEInfos;
303
304    fn glwe_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
305    where
306        A: GLWEInfos;
307
308    fn glwe_compressed_encrypt_sk_default<R, P, S, E>(
309        module: &Module<BE>,
310        res: &mut R,
311        pt: &P,
312        sk: &S,
313        seed_xa: [u8; 32],
314        enc_infos: &E,
315        source_xe: &mut Source,
316        scratch: &mut ScratchArena<'_, BE>,
317    ) where
318        R: GLWECompressedToBackendMut<BE> + GLWECompressedSeedMut,
319        P: GLWEToBackendRef<BE>,
320        E: EncryptionInfos,
321        S: GLWESecretPreparedToBackendRef<BE>;
322
323    fn gglwe_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
324    where
325        A: GGLWEInfos;
326
327    fn gglwe_compressed_encrypt_sk_default<R, P, S, E>(
328        module: &Module<BE>,
329        res: &mut R,
330        pt: &P,
331        sk: &S,
332        seed: [u8; 32],
333        enc_infos: &E,
334        source_xe: &mut Source,
335        scratch: &mut ScratchArena<'_, BE>,
336    ) where
337        R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut,
338        P: ScalarZnxToBackendRef<BE>,
339        E: EncryptionInfos,
340        S: GLWESecretPreparedToBackendRef<BE>;
341
342    fn ggsw_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
343    where
344        A: GGSWInfos;
345
346    fn ggsw_compressed_encrypt_sk_default<R, P, S, E>(
347        module: &Module<BE>,
348        res: &mut R,
349        pt: &P,
350        sk: &S,
351        seed_xa: [u8; 32],
352        enc_infos: &E,
353        source_xe: &mut Source,
354        scratch: &mut ScratchArena<'_, BE>,
355    ) where
356        R: GGSWCompressedToBackendMut<BE> + GGSWCompressedSeedMut + GGSWInfos,
357        P: ScalarZnxToBackendRef<BE>,
358        E: EncryptionInfos,
359        S: GLWESecretPreparedToBackendRef<BE>;
360
361    fn gglwe_to_ggsw_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
362    where
363        A: GGLWEInfos;
364
365    fn gglwe_to_ggsw_key_compressed_encrypt_sk_default<R, S, E>(
366        module: &Module<BE>,
367        res: &mut R,
368        sk: &S,
369        seed_xa: [u8; 32],
370        enc_infos: &E,
371        source_xe: &mut Source,
372        scratch: &mut ScratchArena<'_, BE>,
373    ) where
374        R: GGLWEToGGSWKeyCompressedToBackendMut<BE> + GGLWEInfos,
375        E: EncryptionInfos,
376        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
377
378    fn glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
379    where
380        A: GGLWEInfos;
381
382    fn glwe_automorphism_key_compressed_encrypt_sk_default<R, S, E>(
383        module: &Module<BE>,
384        res: &mut R,
385        p: i64,
386        sk: &S,
387        seed_xa: [u8; 32],
388        enc_infos: &E,
389        source_xe: &mut Source,
390        scratch: &mut ScratchArena<'_, BE>,
391    ) where
392        R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos,
393        E: EncryptionInfos,
394        S: GLWESecretToBackendRef<BE> + GLWEInfos;
395
396    fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
397    where
398        A: GGLWEInfos;
399
400    fn glwe_switching_key_compressed_encrypt_sk_default<R, S1, S2, E>(
401        module: &Module<BE>,
402        res: &mut R,
403        sk_in: &S1,
404        sk_out: &S2,
405        seed_xa: [u8; 32],
406        enc_infos: &E,
407        source_xe: &mut Source,
408        scratch: &mut ScratchArena<'_, BE>,
409    ) where
410        R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + GLWESwitchingKeyDegreesMut + GGLWEInfos,
411        E: EncryptionInfos,
412        S1: GLWESecretToBackendRef<BE> + GLWEInfos,
413        S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
414
415    fn glwe_tensor_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
416    where
417        A: GGLWEInfos;
418
419    fn glwe_tensor_key_compressed_encrypt_sk_default<R, S, E>(
420        module: &Module<BE>,
421        res: &mut R,
422        sk: &S,
423        seed_xa: [u8; 32],
424        enc_infos: &E,
425        source_xe: &mut Source,
426        scratch: &mut ScratchArena<'_, BE>,
427    ) where
428        R: GGLWECompressedToBackendMut<BE> + GGLWEInfos + GGLWECompressedSeedMut,
429        E: EncryptionInfos,
430        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
431}
432
433#[doc(hidden)]
434#[allow(private_bounds)]
435pub trait EncryptionDefault<BE: Backend>:
436    LWEEncryptSkDefault<BE>
437    + GLWEEncryptSkDefault<BE>
438    + GLWEEncryptPkDefault<BE>
439    + GLWEPublicKeyGenerateDefault<BE>
440    + GGLWEEncryptSkDefault<BE>
441    + GGSWEncryptSkDefault<BE>
442    + GGLWEToGGSWKeyEncryptSkDefault<BE>
443    + GLWESwitchingKeyEncryptSkDefault<BE>
444    + GLWESwitchingKeyEncryptPkDefault<BE>
445    + GLWETensorKeyEncryptSkDefault<BE>
446    + GLWEToLWESwitchingKeyEncryptSkDefault<BE>
447    + LWESwitchingKeyEncryptDefault<BE>
448    + LWEToGLWESwitchingKeyEncryptSkDefault<BE>
449    + GLWEAutomorphismKeyEncryptSkDefault<BE>
450    + GLWEAutomorphismKeyEncryptPkDefault<BE>
451    + GLWECompressedEncryptSkDefault<BE>
452    + GGLWECompressedEncryptSkDefault<BE>
453    + GGSWCompressedEncryptSkDefault<BE>
454    + GGLWEToGGSWKeyCompressedEncryptSkDefault<BE>
455    + GLWEAutomorphismKeyCompressedEncryptSkDefault<BE>
456    + GLWESwitchingKeyCompressedEncryptSkDefault<BE>
457    + GLWETensorKeyCompressedEncryptSkDefault<BE>
458{
459}
460
461unsafe impl<BE: Backend> EncryptionImpl<BE> for BE
462where
463    Module<BE>: EncryptionDefault<BE>,
464{
465    fn lwe_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
466    where
467        A: LWEInfos,
468    {
469        module.lwe_encrypt_sk_tmp_bytes_default(infos)
470    }
471
472    fn lwe_encrypt_sk_default<R, P, S, E>(
473        module: &Module<BE>,
474        res: &mut R,
475        pt: &P,
476        sk: &S,
477        enc_infos: &E,
478        source_xe: &mut Source,
479        source_xa: &mut Source,
480        scratch: &mut ScratchArena<'_, BE>,
481    ) where
482        R: LWEToBackendMut<BE> + LWEInfos,
483        P: LWEPlaintextToBackendRef<BE>,
484        S: LWESecretToBackendRef<BE>,
485        E: EncryptionInfos,
486    {
487        module.lwe_encrypt_sk_default(res, pt, sk, enc_infos, source_xe, source_xa, scratch)
488    }
489
490    fn glwe_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
491    where
492        A: GLWEInfos,
493    {
494        module.glwe_encrypt_sk_tmp_bytes_default(infos)
495    }
496
497    fn glwe_encrypt_sk_default<R, P, S, E>(
498        module: &Module<BE>,
499        res: &mut R,
500        pt: &P,
501        sk: &S,
502        enc_infos: &E,
503        source_xe: &mut Source,
504        source_xa: &mut Source,
505        scratch: &mut ScratchArena<'_, BE>,
506    ) where
507        R: GLWEToBackendMut<BE>,
508        P: GLWEToBackendRef<BE>,
509        E: EncryptionInfos,
510        S: GLWESecretPreparedToBackendRef<BE>,
511    {
512        module.glwe_encrypt_sk_default(res, pt, sk, enc_infos, source_xe, source_xa, scratch)
513    }
514
515    fn glwe_encrypt_zero_sk_default<R, E, S>(
516        module: &Module<BE>,
517        res: &mut R,
518        sk: &S,
519        enc_infos: &E,
520        source_xe: &mut Source,
521        source_xa: &mut Source,
522        scratch: &mut ScratchArena<'_, BE>,
523    ) where
524        R: GLWEToBackendMut<BE>,
525        E: EncryptionInfos,
526        S: GLWESecretPreparedToBackendRef<BE>,
527    {
528        module.glwe_encrypt_zero_sk_default(res, sk, enc_infos, source_xe, source_xa, scratch)
529    }
530
531    fn glwe_encrypt_pk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
532    where
533        A: GLWEInfos,
534    {
535        module.glwe_encrypt_pk_tmp_bytes_default(infos)
536    }
537
538    fn glwe_encrypt_pk_default<R, P, K, E>(
539        module: &Module<BE>,
540        res: &mut R,
541        pt: &P,
542        pk: &K,
543        enc_infos: &E,
544        source_xu: &mut Source,
545        source_xe: &mut Source,
546        scratch: &mut ScratchArena<'_, BE>,
547    ) where
548        R: GLWEToBackendMut<BE> + GLWEInfos,
549        P: GLWEToBackendRef<BE> + GLWEInfos,
550        E: EncryptionInfos,
551        K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos,
552    {
553        module.glwe_encrypt_pk_default(res, pt, pk, enc_infos, source_xu, source_xe, scratch)
554    }
555
556    fn glwe_encrypt_zero_pk_default<R, K, E>(
557        module: &Module<BE>,
558        res: &mut R,
559        pk: &K,
560        enc_infos: &E,
561        source_xu: &mut Source,
562        source_xe: &mut Source,
563        scratch: &mut ScratchArena<'_, BE>,
564    ) where
565        R: GLWEToBackendMut<BE> + GLWEInfos,
566        E: EncryptionInfos,
567        K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos,
568    {
569        module.glwe_encrypt_zero_pk_default(res, pk, enc_infos, source_xu, source_xe, scratch)
570    }
571
572    fn glwe_public_key_generate_default<R, S, E>(
573        module: &Module<BE>,
574        res: &mut R,
575        sk: &S,
576        enc_infos: &E,
577        source_xe: &mut Source,
578        source_xa: &mut Source,
579    ) where
580        R: GLWEToBackendMut<BE> + GetDistributionMut + GLWEInfos,
581        E: EncryptionInfos,
582        S: GLWESecretPreparedToBackendRef<BE> + GetDistribution,
583    {
584        module.glwe_public_key_generate_default(res, sk, enc_infos, source_xe, source_xa)
585    }
586
587    fn gglwe_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
588    where
589        A: GGLWEInfos,
590    {
591        module.gglwe_encrypt_sk_tmp_bytes_default(infos)
592    }
593
594    fn gglwe_encrypt_sk_default<R, P, S, E>(
595        module: &Module<BE>,
596        res: &mut R,
597        pt: &P,
598        sk: &S,
599        enc_infos: &E,
600        source_xe: &mut Source,
601        source_xa: &mut Source,
602        scratch: &mut ScratchArena<'_, BE>,
603    ) where
604        R: GGLWEToBackendMut<BE>,
605        P: ScalarZnxToBackendRef<BE>,
606        E: EncryptionInfos,
607        S: GLWESecretPreparedToBackendRef<BE>,
608    {
609        module.gglwe_encrypt_sk_default(res, pt, sk, enc_infos, source_xe, source_xa, scratch)
610    }
611
612    fn ggsw_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
613    where
614        A: GGSWInfos,
615    {
616        module.ggsw_encrypt_sk_tmp_bytes_default(infos)
617    }
618
619    fn ggsw_encrypt_sk_default<R, P, S, E>(
620        module: &Module<BE>,
621        res: &mut R,
622        pt: &P,
623        sk: &S,
624        enc_infos: &E,
625        source_xe: &mut Source,
626        source_xa: &mut Source,
627        scratch: &mut ScratchArena<'_, BE>,
628    ) where
629        R: GGSWToBackendMut<BE> + GGSWInfos + GGSWAtViewMut<BE>,
630        P: ScalarZnxToBackendRef<BE> + ZnxInfos,
631        E: EncryptionInfos,
632        S: GLWESecretPreparedToBackendRef<BE> + LWEInfos + GLWEInfos,
633    {
634        module.ggsw_encrypt_sk_default(res, pt, sk, enc_infos, source_xe, source_xa, scratch)
635    }
636
637    fn gglwe_to_ggsw_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
638    where
639        A: GGLWEInfos,
640    {
641        module.gglwe_to_ggsw_key_encrypt_sk_tmp_bytes_default(infos)
642    }
643
644    fn gglwe_to_ggsw_key_encrypt_sk_default<R, S, E>(
645        module: &Module<BE>,
646        res: &mut R,
647        sk: &S,
648        enc_infos: &E,
649        source_xe: &mut Source,
650        source_xa: &mut Source,
651        scratch: &mut ScratchArena<'_, BE>,
652    ) where
653        R: GGLWEToGGSWKeyToBackendMut<BE>,
654        E: EncryptionInfos,
655        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos,
656    {
657        module.gglwe_to_ggsw_key_encrypt_sk_default(res, sk, enc_infos, source_xe, source_xa, scratch)
658    }
659
660    fn glwe_switching_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
661    where
662        A: GGLWEInfos,
663    {
664        module.glwe_switching_key_encrypt_sk_tmp_bytes_default(infos)
665    }
666
667    fn glwe_switching_key_encrypt_sk_default<R, S1, S2, E>(
668        module: &Module<BE>,
669        res: &mut R,
670        sk_in: &S1,
671        sk_out: &S2,
672        enc_infos: &E,
673        source_xe: &mut Source,
674        source_xa: &mut Source,
675        scratch: &mut ScratchArena<'_, BE>,
676    ) where
677        R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
678        E: EncryptionInfos,
679        S1: GLWESecretToBackendRef<BE> + GLWEInfos,
680        S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos,
681    {
682        module.glwe_switching_key_encrypt_sk_default(res, sk_in, sk_out, enc_infos, source_xe, source_xa, scratch)
683    }
684
685    fn glwe_switching_key_encrypt_pk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
686    where
687        A: GGLWEInfos,
688    {
689        module.glwe_switching_key_encrypt_pk_tmp_bytes_default(infos)
690    }
691
692    fn glwe_tensor_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
693    where
694        A: GGLWEInfos,
695    {
696        module.glwe_tensor_key_encrypt_sk_tmp_bytes_default(infos)
697    }
698
699    fn glwe_tensor_key_encrypt_sk_default<R, S, E>(
700        module: &Module<BE>,
701        res: &mut R,
702        sk: &S,
703        enc_infos: &E,
704        source_xe: &mut Source,
705        source_xa: &mut Source,
706        scratch: &mut ScratchArena<'_, BE>,
707    ) where
708        R: GGLWEToBackendMut<BE> + GGLWEInfos,
709        E: EncryptionInfos,
710        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos,
711    {
712        module.glwe_tensor_key_encrypt_sk_default(res, sk, enc_infos, source_xe, source_xa, scratch)
713    }
714
715    fn glwe_to_lwe_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
716    where
717        A: GGLWEInfos,
718    {
719        module.glwe_to_lwe_key_encrypt_sk_tmp_bytes_default(infos)
720    }
721
722    fn glwe_to_lwe_key_encrypt_sk_default<R, S1, S2, E>(
723        module: &Module<BE>,
724        res: &mut R,
725        sk_lwe: &S1,
726        sk_glwe: &S2,
727        enc_infos: &E,
728        source_xe: &mut Source,
729        source_xa: &mut Source,
730        scratch: &mut ScratchArena<'_, BE>,
731    ) where
732        S1: LWESecretToBackendRef<BE>,
733        S2: GLWESecretToBackendRef<BE>,
734        E: EncryptionInfos,
735        R: GGLWEToBackendMut<BE> + GGLWEInfos,
736    {
737        module.glwe_to_lwe_key_encrypt_sk_default(res, sk_lwe, sk_glwe, enc_infos, source_xe, source_xa, scratch)
738    }
739
740    fn lwe_switching_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
741    where
742        A: GGLWEInfos,
743    {
744        module.lwe_switching_key_encrypt_sk_tmp_bytes_default(infos)
745    }
746
747    fn lwe_switching_key_encrypt_sk_default<R, S1, S2, E>(
748        module: &Module<BE>,
749        res: &mut R,
750        sk_lwe_in: &S1,
751        sk_lwe_out: &S2,
752        enc_infos: &E,
753        source_xe: &mut Source,
754        source_xa: &mut Source,
755        scratch: &mut ScratchArena<'_, BE>,
756    ) where
757        R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
758        E: EncryptionInfos,
759        S1: LWESecretToBackendRef<BE>,
760        S2: LWESecretToBackendRef<BE>,
761    {
762        module.lwe_switching_key_encrypt_sk_default(res, sk_lwe_in, sk_lwe_out, enc_infos, source_xe, source_xa, scratch)
763    }
764
765    fn lwe_to_glwe_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
766    where
767        A: GGLWEInfos,
768    {
769        module.lwe_to_glwe_key_encrypt_sk_tmp_bytes_default(infos)
770    }
771
772    fn lwe_to_glwe_key_encrypt_sk_default<R, S1, S2, E>(
773        module: &Module<BE>,
774        res: &mut R,
775        sk_lwe: &S1,
776        sk_glwe: &S2,
777        enc_infos: &E,
778        source_xe: &mut Source,
779        source_xa: &mut Source,
780        scratch: &mut ScratchArena<'_, BE>,
781    ) where
782        S1: LWESecretToBackendRef<BE>,
783        S2: GLWESecretPreparedToBackendRef<BE>,
784        E: EncryptionInfos,
785        R: GGLWEToBackendMut<BE> + GGLWEInfos,
786    {
787        module.lwe_to_glwe_key_encrypt_sk_default(res, sk_lwe, sk_glwe, enc_infos, source_xe, source_xa, scratch)
788    }
789
790    fn glwe_automorphism_key_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
791    where
792        A: GGLWEInfos,
793    {
794        module.glwe_automorphism_key_encrypt_sk_tmp_bytes_default(infos)
795    }
796
797    fn glwe_automorphism_key_encrypt_sk_default<R, S, E>(
798        module: &Module<BE>,
799        res: &mut R,
800        p: i64,
801        sk: &S,
802        enc_infos: &E,
803        source_xe: &mut Source,
804        source_xa: &mut Source,
805        scratch: &mut ScratchArena<'_, BE>,
806    ) where
807        R: GGLWEToBackendMut<BE> + SetGaloisElement + GGLWEInfos,
808        E: EncryptionInfos,
809        S: GLWESecretToBackendRef<BE> + GLWEInfos,
810    {
811        module.glwe_automorphism_key_encrypt_sk_default(res, p, sk, enc_infos, source_xe, source_xa, scratch)
812    }
813
814    fn glwe_automorphism_key_encrypt_pk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
815    where
816        A: GGLWEInfos,
817    {
818        module.glwe_automorphism_key_encrypt_pk_tmp_bytes_default(infos)
819    }
820
821    fn glwe_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
822    where
823        A: GLWEInfos,
824    {
825        module.glwe_compressed_encrypt_sk_tmp_bytes_default(infos)
826    }
827
828    fn glwe_compressed_encrypt_sk_default<R, P, S, E>(
829        module: &Module<BE>,
830        res: &mut R,
831        pt: &P,
832        sk: &S,
833        seed_xa: [u8; 32],
834        enc_infos: &E,
835        source_xe: &mut Source,
836        scratch: &mut ScratchArena<'_, BE>,
837    ) where
838        R: GLWECompressedToBackendMut<BE> + GLWECompressedSeedMut,
839        P: GLWEToBackendRef<BE>,
840        E: EncryptionInfos,
841        S: GLWESecretPreparedToBackendRef<BE>,
842    {
843        module.glwe_compressed_encrypt_sk_default(res, pt, sk, seed_xa, enc_infos, source_xe, scratch)
844    }
845
846    fn gglwe_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
847    where
848        A: GGLWEInfos,
849    {
850        module.gglwe_compressed_encrypt_sk_tmp_bytes_default(infos)
851    }
852
853    fn gglwe_compressed_encrypt_sk_default<R, P, S, E>(
854        module: &Module<BE>,
855        res: &mut R,
856        pt: &P,
857        sk: &S,
858        seed: [u8; 32],
859        enc_infos: &E,
860        source_xe: &mut Source,
861        scratch: &mut ScratchArena<'_, BE>,
862    ) where
863        R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut,
864        P: ScalarZnxToBackendRef<BE>,
865        E: EncryptionInfos,
866        S: GLWESecretPreparedToBackendRef<BE>,
867    {
868        module.gglwe_compressed_encrypt_sk_default(res, pt, sk, seed, enc_infos, source_xe, scratch)
869    }
870
871    fn ggsw_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
872    where
873        A: GGSWInfos,
874    {
875        module.ggsw_compressed_encrypt_sk_tmp_bytes_default(infos)
876    }
877
878    fn ggsw_compressed_encrypt_sk_default<R, P, S, E>(
879        module: &Module<BE>,
880        res: &mut R,
881        pt: &P,
882        sk: &S,
883        seed_xa: [u8; 32],
884        enc_infos: &E,
885        source_xe: &mut Source,
886        scratch: &mut ScratchArena<'_, BE>,
887    ) where
888        R: GGSWCompressedToBackendMut<BE> + GGSWCompressedSeedMut + GGSWInfos,
889        P: ScalarZnxToBackendRef<BE>,
890        E: EncryptionInfos,
891        S: GLWESecretPreparedToBackendRef<BE>,
892    {
893        module.ggsw_compressed_encrypt_sk_default(res, pt, sk, seed_xa, enc_infos, source_xe, scratch)
894    }
895
896    fn gglwe_to_ggsw_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
897    where
898        A: GGLWEInfos,
899    {
900        module.gglwe_to_ggsw_key_compressed_encrypt_sk_tmp_bytes_default(infos)
901    }
902
903    fn gglwe_to_ggsw_key_compressed_encrypt_sk_default<R, S, E>(
904        module: &Module<BE>,
905        res: &mut R,
906        sk: &S,
907        seed_xa: [u8; 32],
908        enc_infos: &E,
909        source_xe: &mut Source,
910        scratch: &mut ScratchArena<'_, BE>,
911    ) where
912        R: GGLWEToGGSWKeyCompressedToBackendMut<BE> + GGLWEInfos,
913        E: EncryptionInfos,
914        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos,
915    {
916        module.gglwe_to_ggsw_key_compressed_encrypt_sk_default(res, sk, seed_xa, enc_infos, source_xe, scratch)
917    }
918
919    fn glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
920    where
921        A: GGLWEInfos,
922    {
923        module.glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes_default(infos)
924    }
925
926    fn glwe_automorphism_key_compressed_encrypt_sk_default<R, S, E>(
927        module: &Module<BE>,
928        res: &mut R,
929        p: i64,
930        sk: &S,
931        seed_xa: [u8; 32],
932        enc_infos: &E,
933        source_xe: &mut Source,
934        scratch: &mut ScratchArena<'_, BE>,
935    ) where
936        R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos,
937        E: EncryptionInfos,
938        S: GLWESecretToBackendRef<BE> + GLWEInfos,
939    {
940        module.glwe_automorphism_key_compressed_encrypt_sk_default(res, p, sk, seed_xa, enc_infos, source_xe, scratch)
941    }
942
943    fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
944    where
945        A: GGLWEInfos,
946    {
947        module.glwe_switching_key_compressed_encrypt_sk_tmp_bytes_default(infos)
948    }
949
950    fn glwe_switching_key_compressed_encrypt_sk_default<R, S1, S2, E>(
951        module: &Module<BE>,
952        res: &mut R,
953        sk_in: &S1,
954        sk_out: &S2,
955        seed_xa: [u8; 32],
956        enc_infos: &E,
957        source_xe: &mut Source,
958        scratch: &mut ScratchArena<'_, BE>,
959    ) where
960        R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + GLWESwitchingKeyDegreesMut + GGLWEInfos,
961        E: EncryptionInfos,
962        S1: GLWESecretToBackendRef<BE> + GLWEInfos,
963        S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos,
964    {
965        module.glwe_switching_key_compressed_encrypt_sk_default(res, sk_in, sk_out, seed_xa, enc_infos, source_xe, scratch)
966    }
967
968    fn glwe_tensor_key_compressed_encrypt_sk_tmp_bytes_default<A>(module: &Module<BE>, infos: &A) -> usize
969    where
970        A: GGLWEInfos,
971    {
972        module.glwe_tensor_key_compressed_encrypt_sk_tmp_bytes_default(infos)
973    }
974
975    fn glwe_tensor_key_compressed_encrypt_sk_default<R, S, E>(
976        module: &Module<BE>,
977        res: &mut R,
978        sk: &S,
979        seed_xa: [u8; 32],
980        enc_infos: &E,
981        source_xe: &mut Source,
982        scratch: &mut ScratchArena<'_, BE>,
983    ) where
984        R: GGLWECompressedToBackendMut<BE> + GGLWEInfos + GGLWECompressedSeedMut,
985        E: EncryptionInfos,
986        S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos,
987    {
988        module.glwe_tensor_key_compressed_encrypt_sk_default(res, sk, seed_xa, enc_infos, source_xe, scratch)
989    }
990}
991
992/// Marker opt-in for [`EncryptionDefault`] on `Module<$be>`.
993///
994/// Equivalent to writing `impl EncryptionDefault<$be> for Module<$be> {}`. The aggregator's
995/// supertrait chain auto-derives all 22 encryption sub-defaults from their HAL bounds.
996#[macro_export]
997macro_rules! impl_encryption_defaults_full {
998    ($be:ty) => {
999        impl $crate::oep::EncryptionDefault<$be> for ::poulpy_hal::layouts::Module<$be> {}
1000    };
1001}