Skip to main content

poulpy_core/api/
automorphism.rs

1#![allow(clippy::too_many_arguments)]
2
3use poulpy_hal::layouts::{Backend, ScratchArena};
4
5use crate::layouts::{
6    GGLWEInfos, GGLWEToBackendMut, GGLWEToBackendRef, GGSWInfos, GGSWToBackendMut, GGSWToBackendRef, GLWEInfos, GLWEToBackendMut,
7    GLWEToBackendRef, GetGaloisElement, SetGaloisElement,
8    prepared::{GGLWEPreparedToBackendRef, GGLWEToGGSWKeyPreparedToBackendRef},
9};
10
11pub trait GLWEAutomorphism<BE: Backend> {
12    fn glwe_automorphism_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
13    where
14        R: GLWEInfos,
15        A: GLWEInfos,
16        K: GGLWEInfos;
17
18    fn glwe_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
19    where
20        R: GLWEToBackendMut<BE> + GLWEInfos,
21        A: GLWEToBackendRef<BE> + GLWEInfos,
22        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
23
24    fn glwe_automorphism_assign<R, K>(&self, res: &mut R, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
25    where
26        R: GLWEToBackendMut<BE> + GLWEInfos,
27        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
28
29    fn glwe_automorphism_add<R, A, K>(&self, res: &mut R, a: &A, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
30    where
31        R: GLWEToBackendMut<BE> + GLWEInfos,
32        A: GLWEToBackendRef<BE> + GLWEInfos,
33        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
34
35    fn glwe_automorphism_add_assign<R, K>(&self, res: &mut R, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
36    where
37        R: GLWEToBackendMut<BE> + GLWEInfos,
38        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
39
40    fn glwe_automorphism_sub<R, A, K>(&self, res: &mut R, a: &A, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
41    where
42        R: GLWEToBackendMut<BE> + GLWEInfos,
43        A: GLWEToBackendRef<BE> + GLWEInfos,
44        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
45
46    fn glwe_automorphism_sub_negate<R, A, K>(
47        &self,
48        res: &mut R,
49        a: &A,
50        key: &K,
51        key_size: usize,
52        scratch: &mut ScratchArena<'_, BE>,
53    ) where
54        R: GLWEToBackendMut<BE> + GLWEInfos,
55        A: GLWEToBackendRef<BE> + GLWEInfos,
56        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
57
58    fn glwe_automorphism_sub_assign<R, K>(&self, res: &mut R, key: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
59    where
60        R: GLWEToBackendMut<BE> + GLWEInfos,
61        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
62
63    fn glwe_automorphism_sub_negate_assign<R, K>(
64        &self,
65        res: &mut R,
66        key: &K,
67        key_size: usize,
68        scratch: &mut ScratchArena<'_, BE>,
69    ) where
70        R: GLWEToBackendMut<BE> + GLWEInfos,
71        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
72}
73
74pub trait GGSWAutomorphism<BE: Backend> {
75    fn ggsw_automorphism_tmp_bytes<R, A, K, T>(&self, res_infos: &R, a_infos: &A, key_infos: &K, tsk_infos: &T) -> usize
76    where
77        R: GGSWInfos,
78        A: GGSWInfos,
79        K: GGLWEInfos,
80        T: GGLWEInfos;
81
82    fn ggsw_automorphism<R, A, K, T>(
83        &self,
84        res: &mut R,
85        a: &A,
86        key: &K,
87        key_size: usize,
88        tsk: &T,
89        tsk_size: usize,
90        scratch: &mut ScratchArena<'_, BE>,
91    ) where
92        R: GGSWToBackendMut<BE> + GGSWInfos,
93        A: GGSWToBackendRef<BE> + GGSWInfos,
94        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
95        T: GGLWEToGGSWKeyPreparedToBackendRef<BE> + GGLWEInfos;
96
97    fn ggsw_automorphism_assign<R, K, T>(
98        &self,
99        res: &mut R,
100        key: &K,
101        key_size: usize,
102        tsk: &T,
103        tsk_size: usize,
104        scratch: &mut ScratchArena<'_, BE>,
105    ) where
106        R: GGSWToBackendMut<BE> + GGSWInfos,
107        K: GetGaloisElement + GGLWEPreparedToBackendRef<BE> + GGLWEInfos,
108        T: GGLWEToGGSWKeyPreparedToBackendRef<BE> + GGLWEInfos;
109}
110
111pub trait GLWEAutomorphismKeyAutomorphism<BE: Backend> {
112    fn glwe_automorphism_key_automorphism_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
113    where
114        R: GGLWEInfos,
115        A: GGLWEInfos,
116        K: GGLWEInfos;
117
118    fn glwe_automorphism_key_automorphism<R, A, K>(
119        &self,
120        res: &mut R,
121        a: &A,
122        key: &K,
123        key_size: usize,
124        scratch: &mut ScratchArena<'_, BE>,
125    ) where
126        R: GGLWEToBackendMut<BE> + SetGaloisElement + GGLWEInfos,
127        A: GGLWEToBackendRef<BE> + GetGaloisElement + GGLWEInfos,
128        K: GGLWEPreparedToBackendRef<BE> + GetGaloisElement + GGLWEInfos;
129
130    fn glwe_automorphism_key_automorphism_assign<R, K>(
131        &self,
132        res: &mut R,
133        key: &K,
134        key_size: usize,
135        scratch: &mut ScratchArena<'_, BE>,
136    ) where
137        R: GGLWEToBackendMut<BE> + SetGaloisElement + GetGaloisElement + GGLWEInfos,
138        K: GGLWEPreparedToBackendRef<BE> + GetGaloisElement + GGLWEInfos;
139}