Skip to main content

poulpy_ckks/delegates/
tmp_bytes.rs

1use crate::{
2    CKKSCtBounds, CKKSInfos,
3    leveled::api::{
4        CKKSAddOps, CKKSAllOpsTmpBytes, CKKSConjugateOps, CKKSDecrypt, CKKSEncrypt, CKKSImagOps, CKKSMulOps, CKKSNegOps,
5        CKKSPow2Ops, CKKSRescaleOps, CKKSRotateOps, CKKSSubOps,
6    },
7};
8use poulpy_core::{
9    GLWEAutomorphism, GLWEAutomorphismKeyEncryptSk, GLWEMulConst, GLWEMulPlain, GLWERotate, GLWEShift, GLWETensorKeyEncryptSk,
10    GLWETensoring,
11    layouts::{GGLWEInfos, GLWEAutomorphismKeyPreparedFactory, GLWETensorKeyPreparedFactory},
12};
13use poulpy_hal::{
14    api::{
15        ModuleN, VecZnxLshBackend, VecZnxLshTmpBytes, VecZnxRshAddIntoBackend, VecZnxRshBackend, VecZnxRshSubBackend,
16        VecZnxRshTmpBytes,
17    },
18    layouts::{Backend, Module},
19};
20
21impl<BE: Backend> CKKSAllOpsTmpBytes<BE> for Module<BE>
22where
23    Self: CKKSEncrypt<BE>
24        + CKKSDecrypt<BE>
25        + CKKSAddOps<BE>
26        + CKKSConjugateOps<BE>
27        + CKKSSubOps<BE>
28        + CKKSNegOps<BE>
29        + CKKSPow2Ops<BE>
30        + CKKSImagOps<BE>
31        + CKKSRescaleOps<BE>
32        + CKKSRotateOps<BE>
33        + CKKSMulOps<BE>
34        + GLWEAutomorphism<BE>
35        + GLWEAutomorphismKeyEncryptSk<BE>
36        + GLWEAutomorphismKeyPreparedFactory<BE>
37        + ModuleN
38        + GLWEShift<BE>
39        + GLWEMulPlain<BE>
40        + GLWEMulConst<BE>
41        + GLWERotate<BE>
42        + GLWETensoring<BE>
43        + GLWETensorKeyEncryptSk<BE>
44        + GLWETensorKeyPreparedFactory<BE>
45        + VecZnxLshBackend<BE>
46        + VecZnxLshTmpBytes
47        + VecZnxRshBackend<BE>
48        + VecZnxRshAddIntoBackend<BE>
49        + VecZnxRshSubBackend<BE>
50        + VecZnxRshTmpBytes,
51{
52    fn ckks_all_ops_tmp_bytes<C, T, P>(&self, ct_infos: &C, tsk_infos: &T, pt_prec: &P) -> usize
53    where
54        C: CKKSCtBounds,
55        T: GGLWEInfos,
56        P: CKKSInfos,
57    {
58        self.ckks_encrypt_sk_tmp_bytes(ct_infos)
59            .max(self.ckks_decrypt_tmp_bytes(ct_infos))
60            .max(self.ckks_add_tmp_bytes())
61            .max(self.ckks_add_pt_vec_tmp_bytes())
62            .max(self.ckks_add_pt_const_tmp_bytes())
63            .max(self.ckks_sub_tmp_bytes())
64            .max(self.ckks_sub_pt_vec_tmp_bytes())
65            .max(self.ckks_sub_pt_const_tmp_bytes())
66            .max(self.ckks_neg_tmp_bytes())
67            .max(self.ckks_mul_pow2_tmp_bytes())
68            .max(self.ckks_div_pow2_tmp_bytes())
69            .max(self.ckks_mul_i_tmp_bytes())
70            .max(self.ckks_div_i_tmp_bytes())
71            .max(self.ckks_rescale_tmp_bytes())
72            .max(self.ckks_align_tmp_bytes())
73            .max(self.ckks_mul_tmp_bytes(ct_infos, tsk_infos))
74            .max(self.ckks_square_tmp_bytes(ct_infos, tsk_infos))
75            .max(self.ckks_mul_pt_vec_tmp_bytes(ct_infos, ct_infos, pt_prec))
76            .max(self.ckks_mul_pt_const_tmp_bytes(ct_infos, ct_infos, pt_prec))
77            .max(self.prepare_tensor_key_tmp_bytes(tsk_infos))
78            .max(self.glwe_tensor_key_encrypt_sk_tmp_bytes(tsk_infos))
79    }
80
81    fn ckks_all_ops_with_atk_tmp_bytes<C, T, A, P>(&self, ct_infos: &C, tsk_infos: &T, atk_infos: &A, pt_prec: &P) -> usize
82    where
83        C: CKKSCtBounds,
84        T: GGLWEInfos,
85        A: GGLWEInfos,
86        P: CKKSInfos,
87    {
88        self.ckks_all_ops_tmp_bytes(ct_infos, tsk_infos, pt_prec)
89            .max(self.ckks_rotate_tmp_bytes(ct_infos, atk_infos))
90            .max(self.ckks_conjugate_tmp_bytes(ct_infos, atk_infos))
91            .max(self.glwe_automorphism_key_encrypt_sk_tmp_bytes(atk_infos))
92            .max(self.glwe_automorphism_key_prepare_tmp_bytes(atk_infos))
93    }
94}