1use poulpy_hal::layouts::{Backend, Module, ScratchArena};
2
3use crate::{
4 api::{GGLWEExternalProduct, GGSWExternalProduct, GLWEExternalProduct},
5 layouts::{
6 GGLWEInfos, GGLWEToBackendMut, GGLWEToBackendRef, GGSWAtViewMut, GGSWAtViewRef, GGSWInfos, GGSWToBackendMut,
7 GGSWToBackendRef, GLWEInfos, GLWEToBackendMut, GLWEToBackendRef, prepared::GGSWPreparedToBackendRef,
8 },
9 oep::{GGLWEExternalProductImpl, GGSWExternalProductImpl, GLWEExternalProductImpl},
10};
11
12macro_rules! impl_external_product_delegate {
13 ($trait:ty, [$($bounds:tt)+], $($body:item)+) => {
14 impl<BE> $trait for Module<BE>
15 where
16 $($bounds)+
17 {
18 $($body)+
19 }
20 };
21}
22
23impl_external_product_delegate!(
24 GLWEExternalProduct<BE>,
25 [BE: Backend + GLWEExternalProductImpl<BE>],
26 fn glwe_external_product_tmp_bytes<R, A, B>(&self, res_infos: &R, a_infos: &A, b_infos: &B) -> usize
27 where
28 R: GLWEInfos,
29 A: GLWEInfos,
30 B: GGSWInfos,
31 {
32 BE::glwe_external_product_tmp_bytes(self, res_infos, a_infos, b_infos)
33 }
34
35 fn glwe_external_product_assign<R, D>(
36 &self,
37 res: &mut R,
38 rhs: &D,
39 key_size: usize,
40 scratch: &mut ScratchArena<'_, BE>,
41 )
42 where
43 R: GLWEToBackendMut<BE> + GLWEInfos,
44 D: GGSWPreparedToBackendRef<BE> + GGSWInfos,
45 {
46 BE::glwe_external_product_assign(self, res, rhs, key_size, scratch)
47 }
48
49 fn glwe_external_product<R, A, D>(
50 &self,
51 res: &mut R,
52 lhs: &A,
53 rhs: &D,
54 key_size: usize,
55 scratch: &mut ScratchArena<'_, BE>,
56 )
57 where
58 R: GLWEToBackendMut<BE> + GLWEInfos,
59 A: GLWEToBackendRef<BE> + GLWEInfos,
60 D: GGSWPreparedToBackendRef<BE> + GGSWInfos,
61 {
62 BE::glwe_external_product(self, res, lhs, rhs, key_size, scratch)
63 }
64);
65
66impl_external_product_delegate!(
67 GGLWEExternalProduct<BE>,
68 [BE: Backend + GGLWEExternalProductImpl<BE>, Module<BE>: GLWEExternalProduct<BE>],
69 fn gglwe_external_product_tmp_bytes<R, A, B>(&self, res_infos: &R, a_infos: &A, b_infos: &B) -> usize
70 where
71 R: GGLWEInfos,
72 A: GGLWEInfos,
73 B: GGSWInfos,
74 {
75 BE::gglwe_external_product_tmp_bytes(self, res_infos, a_infos, b_infos)
76 }
77
78 fn gglwe_external_product<R, A, B>(
79 &self,
80 res: &mut R,
81 a: &A,
82 b: &B,
83 key_size: usize,
84 scratch: &mut ScratchArena<'_, BE>,
85 )
86 where
87 R: GGLWEToBackendMut<BE> + GGLWEInfos,
88 A: GGLWEToBackendRef<BE> + GGLWEInfos,
89 B: GGSWPreparedToBackendRef<BE> + GGSWInfos,
90 {
91 BE::gglwe_external_product(self, res, a, b, key_size, scratch)
92 }
93
94 fn gglwe_external_product_assign<R, A>(
95 &self,
96 res: &mut R,
97 a: &A,
98 key_size: usize,
99 scratch: &mut ScratchArena<'_, BE>,
100 )
101 where
102 R: GGLWEToBackendMut<BE> + GGLWEInfos,
103 A: GGSWPreparedToBackendRef<BE> + GGSWInfos,
104 {
105 BE::gglwe_external_product_assign(self, res, a, key_size, scratch)
106 }
107);
108
109impl_external_product_delegate!(
110 GGSWExternalProduct<BE>,
111 [BE: Backend + GGSWExternalProductImpl<BE>, Module<BE>: GLWEExternalProduct<BE>],
112 fn ggsw_external_product_tmp_bytes<R, A, B>(&self, res_infos: &R, a_infos: &A, b_infos: &B) -> usize
113 where
114 R: GGSWInfos,
115 A: GGSWInfos,
116 B: GGSWInfos,
117 {
118 BE::ggsw_external_product_tmp_bytes(self, res_infos, a_infos, b_infos)
119 }
120
121 fn ggsw_external_product<R, A, B>(
122 &self,
123 res: &mut R,
124 a: &A,
125 b: &B,
126 key_size: usize,
127 scratch: &mut ScratchArena<'_, BE>,
128 )
129 where
130 R: GGSWToBackendMut<BE> + GGSWAtViewMut<BE> + GGSWInfos,
131 A: GGSWToBackendRef<BE> + GGSWAtViewRef<BE> + GGSWInfos,
132 B: GGSWPreparedToBackendRef<BE> + GGSWInfos,
133 {
134 BE::ggsw_external_product(self, res, a, b, key_size, scratch)
135 }
136
137 fn ggsw_external_product_assign<R, A>(
138 &self,
139 res: &mut R,
140 a: &A,
141 key_size: usize,
142 scratch: &mut ScratchArena<'_, BE>,
143 )
144 where
145 R: GGSWToBackendMut<BE> + GGSWAtViewMut<BE> + GGSWInfos,
146 A: GGSWPreparedToBackendRef<BE> + GGSWInfos,
147 {
148 BE::ggsw_external_product_assign(self, res, a, key_size, scratch)
149 }
150);