1use poulpy_hal::layouts::{Backend, Module, ScratchArena};
2
3use crate::{
4 api::{GGSWAutomorphism, GLWEAutomorphism, GLWEAutomorphismKeyAutomorphism},
5 layouts::{
6 GGLWEInfos, GGLWEToBackendMut, GGLWEToBackendRef, GGSWInfos, GGSWToBackendMut, GGSWToBackendRef, GLWEInfos,
7 GLWEToBackendMut, GLWEToBackendRef, GetGaloisElement, SetGaloisElement,
8 prepared::{GGLWEPreparedToBackendRef, GGLWEToGGSWKeyPreparedToBackendRef},
9 },
10 oep::AutomorphismImpl,
11};
12
13macro_rules! impl_automorphism_delegate {
14 ($trait:ty, [$($bounds:tt)+], $($body:item)+) => {
15 impl<BE> $trait for Module<BE>
16 where
17 $($bounds)+
18 {
19 $($body)+
20 }
21 };
22}
23
24impl_automorphism_delegate!(
25 GLWEAutomorphism<BE>,
26 [BE: Backend + AutomorphismImpl<BE>],
27 fn glwe_automorphism_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
28 where
29 R: GLWEInfos,
30 A: GLWEInfos,
31 K: GGLWEInfos,
32 {
33 BE::glwe_automorphism_tmp_bytes(self, res_infos, a_infos, key_infos)
34 }
35
36 fn glwe_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
37 where
38 R: GLWEToBackendMut<BE> + GLWEInfos,
39 A: GLWEToBackendRef<BE> + GLWEInfos,
40 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
41 {
42 BE::glwe_automorphism(self, res, a, key, key_size, scratch)
43 }
44
45 fn glwe_automorphism_assign<R, K>(&self, res: &mut R, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
46 where
47 R: GLWEToBackendMut<BE> + GLWEInfos,
48 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
49 {
50 BE::glwe_automorphism_assign(self, res, key, key_size, scratch)
51 }
52
53 fn glwe_automorphism_add<R, A, K>(&self, res: &mut R, a: &A, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
54 where
55 R: GLWEToBackendMut<BE> + GLWEInfos,
56 A: GLWEToBackendRef<BE> + GLWEInfos,
57 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
58 {
59 BE::glwe_automorphism_add(self, res, a, key, key_size, scratch)
60 }
61
62 fn glwe_automorphism_add_assign<R, K>(&self, res: &mut R, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
63 where
64 R: GLWEToBackendMut<BE> + GLWEInfos,
65 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
66 {
67 BE::glwe_automorphism_add_assign(self, res, key, key_size, scratch)
68 }
69
70 fn glwe_automorphism_sub<R, A, K>(&self, res: &mut R, a: &A, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
71 where
72 R: GLWEToBackendMut<BE> + GLWEInfos,
73 A: GLWEToBackendRef<BE> + GLWEInfos,
74 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
75 {
76 BE::glwe_automorphism_sub(self, res, a, key, key_size, scratch)
77 }
78
79 fn glwe_automorphism_sub_negate<R, A, K>(&self, res: &mut R, a: &A, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
80 where
81 R: GLWEToBackendMut<BE> + GLWEInfos,
82 A: GLWEToBackendRef<BE> + GLWEInfos,
83 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
84 {
85 BE::glwe_automorphism_sub_negate(self, res, a, key, key_size, scratch)
86 }
87
88 fn glwe_automorphism_sub_assign<R, K>(&self, res: &mut R, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
89 where
90 R: GLWEToBackendMut<BE> + GLWEInfos,
91 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
92 {
93 BE::glwe_automorphism_sub_assign(self, res, key, key_size, scratch)
94 }
95
96 fn glwe_automorphism_sub_negate_assign<R, K>(&self, res: &mut R, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
97 where
98 R: GLWEToBackendMut<BE> + GLWEInfos,
99 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
100 {
101 BE::glwe_automorphism_sub_negate_assign(self, res, key, key_size, scratch)
102 }
103);
104
105impl_automorphism_delegate!(
106 GGSWAutomorphism<BE>,
107 [BE: Backend + AutomorphismImpl<BE> + crate::oep::ConversionImpl<BE>, Module<BE>: crate::oep::ConversionDefault<BE>],
108 fn ggsw_automorphism_tmp_bytes<R, A, K, T>(&self, res_infos: &R, a_infos: &A, key_infos: &K, tsk_infos: &T) -> usize
109 where
110 R: GGSWInfos,
111 A: GGSWInfos,
112 K: GGLWEInfos,
113 T: GGLWEInfos,
114 {
115 BE::ggsw_automorphism_tmp_bytes(self, res_infos, a_infos, key_infos, tsk_infos)
116 }
117
118 fn ggsw_automorphism<R, A, K, T>(&self, res: &mut R, a: &A, key: &K, key_size: usize, tsk: &T, tsk_size: usize, scratch: &mut ScratchArena<'_, BE>)
119 where
120 R: GGSWToBackendMut<BE> + GGSWInfos,
121 A: GGSWToBackendRef<BE> + GGSWInfos,
122 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
123 T: GGLWEToGGSWKeyPreparedToBackendRef<BE> + GGLWEInfos,
124 {
125 BE::ggsw_automorphism(self, res, a, key, key_size, tsk, tsk_size, scratch)
126 }
127
128 fn ggsw_automorphism_assign<R, K, T>(&self, res: &mut R, key: &K, key_size: usize, tsk: &T, tsk_size: usize, scratch: &mut ScratchArena<'_, BE>)
129 where
130 R: GGSWToBackendMut<BE> + GGSWInfos,
131 K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
132 T: GGLWEToGGSWKeyPreparedToBackendRef<BE> + GGLWEInfos,
133 {
134 BE::ggsw_automorphism_assign(self, res, key, key_size, tsk, tsk_size, scratch)
135 }
136);
137
138impl_automorphism_delegate!(
139 GLWEAutomorphismKeyAutomorphism<BE>,
140 [BE: Backend + AutomorphismImpl<BE>],
141 fn glwe_automorphism_key_automorphism_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
142 where
143 R: GGLWEInfos,
144 A: GGLWEInfos,
145 K: GGLWEInfos,
146 {
147 BE::glwe_automorphism_key_automorphism_tmp_bytes(self, res_infos, a_infos, key_infos)
148 }
149
150 fn glwe_automorphism_key_automorphism<R, A, K>(
151 &self,
152 res: &mut R,
153 a: &A,
154 key: &K,
155 key_size: usize,
156 scratch: &mut ScratchArena<'_, BE>,
157 )
158 where
159 R: GGLWEToBackendMut<BE> + SetGaloisElement + GGLWEInfos,
160 A: GGLWEToBackendRef<BE> + GetGaloisElement + GGLWEInfos,
161 K: GGLWEPreparedToBackendRef<BE> + GetGaloisElement + GGLWEInfos,
162 {
163 BE::glwe_automorphism_key_automorphism(self, res, a, key, key_size, scratch)
164 }
165
166 fn glwe_automorphism_key_automorphism_assign<R, K>(
167 &self,
168 res: &mut R,
169 key: &K,
170 key_size: usize,
171 scratch: &mut ScratchArena<'_, BE>,
172 )
173 where
174 R: GGLWEToBackendMut<BE> + SetGaloisElement + GetGaloisElement + GGLWEInfos,
175 K: GGLWEPreparedToBackendRef<BE> + GetGaloisElement + GGLWEInfos,
176 {
177 BE::glwe_automorphism_key_automorphism_assign(self, res, key, key_size, scratch)
178 }
179);