Skip to main content

poulpy_core/api/
decryption.rs

1use poulpy_hal::layouts::{Backend, Data, ScratchArena};
2
3use crate::layouts::{
4    GLWEInfos, GLWEPlaintext, GLWESecretPrepared, GLWESecretTensorPrepared, GLWETensor, GLWEToBackendMut, GLWEToBackendRef,
5    LWEInfos, LWEPlaintextToBackendMut, LWESecretToBackendRef, LWEToBackendRef, SetLWEInfos,
6    prepared::{GLWESecretPreparedToBackendRef, GLWESecretTensorPreparedToBackendRef},
7};
8
9pub trait GLWEDecrypt<BE: Backend> {
10    fn glwe_decrypt_tmp_bytes<A>(&self, infos: &A) -> usize
11    where
12        A: GLWEInfos;
13
14    fn glwe_decrypt<R, P, S>(&self, res: &R, pt: &mut P, sk: &S, scratch: &mut ScratchArena<'_, BE>)
15    where
16        R: GLWEToBackendRef<BE> + GLWEInfos,
17        P: GLWEToBackendMut<BE> + GLWEInfos + SetLWEInfos,
18        S: GLWESecretPreparedToBackendRef<BE> + GLWEInfos;
19}
20
21pub trait LWEDecrypt<BE: Backend> {
22    fn lwe_decrypt<R, P, S>(&self, res: &R, pt: &mut P, sk: &S, scratch: &mut ScratchArena<'_, BE>)
23    where
24        R: LWEToBackendRef<BE> + LWEInfos,
25        P: LWEPlaintextToBackendMut<BE> + SetLWEInfos + LWEInfos,
26        S: LWESecretToBackendRef<BE> + LWEInfos;
27
28    fn lwe_decrypt_tmp_bytes<A>(&self, infos: &A) -> usize
29    where
30        A: LWEInfos;
31}
32
33pub trait GLWETensorDecrypt<BE: Backend> {
34    fn glwe_tensor_decrypt_tmp_bytes<A>(&self, infos: &A) -> usize
35    where
36        A: GLWEInfos;
37
38    fn glwe_tensor_decrypt<R: Data, P: Data, S0: Data, S1: Data>(
39        &self,
40        res: &GLWETensor<R>,
41        pt: &mut GLWEPlaintext<P>,
42        sk: &GLWESecretPrepared<S0, BE>,
43        sk_tensor: &GLWESecretTensorPrepared<S1, BE>,
44        scratch: &mut ScratchArena<'_, BE>,
45    ) where
46        GLWETensor<R>: GLWEToBackendRef<BE> + GLWEInfos,
47        GLWEPlaintext<P>: GLWEToBackendMut<BE> + GLWEInfos + SetLWEInfos,
48        GLWESecretPrepared<S0, BE>: GLWESecretPreparedToBackendRef<BE> + GLWEInfos,
49        GLWESecretTensorPrepared<S1, BE>: GLWESecretTensorPreparedToBackendRef<BE> + GLWEInfos;
50}