poulpy/core/src/external_product/gglwe_atk.rs
core/src/external_product/gglwe_atk.rsRaw
1use backend::hal::{
2 api::{ScratchAvailable, TakeVecZnxDft},
3 layouts::{Backend, DataMut, DataRef, Module, Scratch},
4};
5
6use crate::{
7 layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, prepared::GGSWCiphertextPrepared},
8 trait_families::GLWEExternalProductFamily,
9};
10
11impl GGLWEAutomorphismKey<Vec<u8>> {
12 pub fn external_product_scratch_space<B: Backend>(
13 module: &Module<B>,
14 n: usize,
15 basek: usize,
16 k_out: usize,
17 k_in: usize,
18 ggsw_k: usize,
19 digits: usize,
20 rank: usize,
21 ) -> usize
22 where
23 Module<B>: GLWEExternalProductFamily<B>,
24 {
25 GGLWESwitchingKey::external_product_scratch_space(module, n, basek, k_out, k_in, ggsw_k, digits, rank)
26 }
27
28 pub fn external_product_inplace_scratch_space<B: Backend>(
29 module: &Module<B>,
30 n: usize,
31 basek: usize,
32 k_out: usize,
33 ggsw_k: usize,
34 digits: usize,
35 rank: usize,
36 ) -> usize
37 where
38 Module<B>: GLWEExternalProductFamily<B>,
39 {
40 GGLWESwitchingKey::external_product_inplace_scratch_space(module, n, basek, k_out, ggsw_k, digits, rank)
41 }
42}
43
44impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
45 pub fn external_product<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
46 &mut self,
47 module: &Module<B>,
48 lhs: &GGLWEAutomorphismKey<DataLhs>,
49 rhs: &GGSWCiphertextPrepared<DataRhs, B>,
50 scratch: &mut Scratch<B>,
51 ) where
52 Module<B>: GLWEExternalProductFamily<B>,
53 Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
54 {
55 self.key.external_product(module, &lhs.key, rhs, scratch);
56 }
57
58 pub fn external_product_inplace<DataRhs: DataRef, B: Backend>(
59 &mut self,
60 module: &Module<B>,
61 rhs: &GGSWCiphertextPrepared<DataRhs, B>,
62 scratch: &mut Scratch<B>,
63 ) where
64 Module<B>: GLWEExternalProductFamily<B>,
65 Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
66 {
67 self.key.external_product_inplace(module, rhs, scratch);
68 }
69}