poulpy_ckks/delegates/
rotate.rs1use anyhow::Result;
2use poulpy_core::{
3 GLWEAutomorphism, GLWEShift,
4 layouts::{
5 GGLWEInfos, GGLWEPreparedToBackendRef, GLWEAutomorphismKeyHelper, GLWEToBackendMut, GLWEToBackendRef, GetGaloisElement,
6 prepared::GLWEAutomorphismKeyPreparedToBackendRef,
7 },
8};
9use poulpy_hal::layouts::{Backend, Module, ScratchArena};
10
11use crate::{CKKSCompositionError, CKKSCtBounds, SetCKKSInfos, oep::CKKSRotateImpl};
12
13use crate::api::CKKSRotateOps;
14
15impl<BE: Backend + CKKSRotateImpl<BE>> CKKSRotateOps<BE> for Module<BE>
16where
17 Module<BE>: GLWEAutomorphism<BE> + GLWEShift<BE>,
18{
19 fn ckks_rotate_tmp_bytes<C, K>(&self, ct_infos: &C, key_infos: &K) -> usize
20 where
21 C: CKKSCtBounds,
22 K: GGLWEInfos,
23 {
24 BE::ckks_rotate_tmp_bytes(self, ct_infos, key_infos)
25 }
26
27 fn ckks_rotate_into<Dst, Src, H, K>(
28 &self,
29 dst: &mut Dst,
30 src: &Src,
31 k: i64,
32 keys: &H,
33 scratch: &mut ScratchArena<'_, BE>,
34 ) -> Result<()>
35 where
36 K: GLWEAutomorphismKeyPreparedToBackendRef<BE> + GGLWEPreparedToBackendRef<BE> + GetGaloisElement + GGLWEInfos,
37 H: GLWEAutomorphismKeyHelper<K, BE>,
38 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
39 Src: GLWEToBackendRef<BE> + CKKSCtBounds,
40 {
41 let key = keys
42 .get_automorphism_key(k)
43 .ok_or(CKKSCompositionError::MissingAutomorphismKey {
44 op: "rotate",
45 rotation: k,
46 })?;
47 BE::ckks_rotate_into(self, dst, src, key, scratch)
48 }
49
50 fn ckks_rotate_assign<Dst, H, K>(&self, dst: &mut Dst, k: i64, keys: &H, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
51 where
52 K: GLWEAutomorphismKeyPreparedToBackendRef<BE> + GGLWEPreparedToBackendRef<BE> + GetGaloisElement + GGLWEInfos,
53 H: GLWEAutomorphismKeyHelper<K, BE>,
54 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
55 {
56 let key = keys
57 .get_automorphism_key(k)
58 .ok_or(CKKSCompositionError::MissingAutomorphismKey {
59 op: "rotate_assign",
60 rotation: k,
61 })?;
62 BE::ckks_rotate_assign(self, dst, key, scratch)
63 }
64}