Skip to main content

poulpy_core/api/
conversion.rs

1use poulpy_hal::layouts::{Backend, ScratchArena};
2
3use crate::layouts::{
4    GGLWEInfos, GGLWEToBackendRef, GGSWInfos, GGSWToBackendMut, GLWEInfos, GLWEToBackendMut, GLWEToBackendRef, LWEInfos,
5    LWEToBackendMut, LWEToBackendRef,
6    prepared::{GGLWEPreparedToBackendRef, GGLWEToGGSWKeyPreparedToBackendRef},
7};
8
9pub trait LWESampleExtract<BE: Backend> {
10    fn lwe_sample_extract<R, A>(&self, res: &mut R, a: &A)
11    where
12        R: LWEToBackendMut<BE> + LWEInfos,
13        A: GLWEToBackendRef<BE> + GLWEInfos;
14}
15
16pub trait GLWEFromLWE<BE: Backend> {
17    fn glwe_from_lwe_tmp_bytes<R, A, K>(&self, glwe_infos: &R, lwe_infos: &A, key_infos: &K) -> usize
18    where
19        R: GLWEInfos,
20        A: LWEInfos,
21        K: GGLWEInfos;
22
23    fn glwe_from_lwe<R, A, K>(&self, res: &mut R, lwe: &A, ksk: &K, key_size: usize, scratch: &mut ScratchArena<'_, BE>)
24    where
25        R: GLWEToBackendMut<BE> + GLWEInfos,
26        A: LWEToBackendRef<BE> + LWEInfos,
27        K: GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
28}
29
30pub trait LWEFromGLWE<BE: Backend> {
31    fn lwe_from_glwe_tmp_bytes<R, A, K>(&self, lwe_infos: &R, glwe_infos: &A, key_infos: &K) -> usize
32    where
33        R: LWEInfos,
34        A: GLWEInfos,
35        K: GGLWEInfos;
36
37    fn lwe_from_glwe<R, A, K>(
38        &self,
39        res: &mut R,
40        a: &A,
41        a_idx: usize,
42        key: &K,
43        key_size: usize,
44        scratch: &mut ScratchArena<'_, BE>,
45    ) where
46        R: LWEToBackendMut<BE> + LWEInfos,
47        A: GLWEToBackendRef<BE> + GLWEInfos,
48        K: GGLWEPreparedToBackendRef<BE> + GGLWEInfos;
49}
50
51pub trait GGSWFromGGLWE<BE: Backend> {
52    fn ggsw_from_gglwe_tmp_bytes<R, A>(&self, res_infos: &R, tsk_infos: &A) -> usize
53    where
54        R: GGSWInfos,
55        A: GGLWEInfos;
56
57    fn ggsw_from_gglwe<R, A, T>(&self, res: &mut R, a: &A, tsk: &T, tsk_size: usize, scratch: &mut ScratchArena<'_, BE>)
58    where
59        R: GGSWToBackendMut<BE> + GGSWInfos,
60        A: GGLWEToBackendRef<BE> + GGLWEInfos,
61        T: GGLWEToGGSWKeyPreparedToBackendRef<BE> + GGLWEInfos;
62}
63
64pub trait GLWEExpandLWE<BE: Backend> {
65    fn glwe_expand_lwe_tmp_bytes<R, A>(&self, lwe_infos: &R, a_infos: &A) -> usize
66    where
67        R: LWEInfos,
68        A: GLWEInfos;
69
70    fn glwe_expand_lwe<R, A>(&self, res: &mut [R], a: &A, scratch: &mut ScratchArena<'_, BE>)
71    where
72        R: LWEToBackendMut<BE> + LWEInfos,
73        A: GLWEToBackendRef<BE> + GLWEInfos;
74}
75
76pub trait GGSWExpandRows<BE: Backend> {
77    fn ggsw_expand_rows_tmp_bytes<R, A>(&self, res_infos: &R, tsk_infos: &A) -> usize
78    where
79        R: GGSWInfos,
80        A: GGLWEInfos;
81
82    fn ggsw_expand_row<R, T>(&self, res: &mut R, tsk: &T, tsk_size: usize, scratch: &mut ScratchArena<'_, BE>)
83    where
84        R: GGSWToBackendMut<BE> + GGSWInfos,
85        T: GGLWEToGGSWKeyPreparedToBackendRef<BE> + GGLWEInfos;
86}