arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key.rs
poulpy-schemes/src/bin_fhe/blind_rotation/encryption/key.rsRaw
 1use poulpy_hal::{
 2    layouts::{Backend, DataMut, Scratch},
 3    source::Source,
 4};
 5
 6use poulpy_core::{
 7    GetDistribution, ScratchTakeCore,
 8    layouts::{GGSWInfos, GLWEInfos, GLWESecretPreparedToRef, LWEInfos, LWESecretToRef},
 9};
10
11use crate::bin_fhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey};
12
13pub trait BlindRotationKeyEncryptSk<BRA: BlindRotationAlgo, B: Backend> {
14    fn blind_rotation_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
15    where
16        A: GGSWInfos;
17
18    #[allow(clippy::too_many_arguments)]
19    fn blind_rotation_key_encrypt_sk<D, S0, S1>(
20        &self,
21        res: &mut BlindRotationKey<D, BRA>,
22        sk_glwe: &S0,
23        sk_lwe: &S1,
24        source_xa: &mut Source,
25        source_xe: &mut Source,
26        scratch: &mut Scratch<B>,
27    ) where
28        D: DataMut,
29        S0: GLWESecretPreparedToRef<B> + GLWEInfos,
30        S1: LWESecretToRef + LWEInfos + GetDistribution;
31}
32
33impl<D: DataMut, BRA: BlindRotationAlgo> BlindRotationKey<D, BRA> {
34    pub fn encrypt_sk<M, S0, S1, BE: Backend>(
35        &mut self,
36        module: &M,
37        sk_glwe: &S0,
38        sk_lwe: &S1,
39        source_xa: &mut Source,
40        source_xe: &mut Source,
41        scratch: &mut Scratch<BE>,
42    ) where
43        S0: GLWESecretPreparedToRef<BE> + GLWEInfos,
44        S1: LWESecretToRef + LWEInfos + GetDistribution,
45        Scratch<BE>: ScratchTakeCore<BE>,
46        M: BlindRotationKeyEncryptSk<BRA, BE>,
47    {
48        module.blind_rotation_key_encrypt_sk(self, sk_glwe, sk_lwe, source_xa, source_xe, scratch);
49    }
50}
51
52impl<BRA: BlindRotationAlgo> BlindRotationKey<Vec<u8>, BRA> {
53    pub fn encrypt_sk_tmp_bytes<A, M, BE: Backend>(module: &M, infos: &A) -> usize
54    where
55        A: GGSWInfos,
56        M: BlindRotationKeyEncryptSk<BRA, BE>,
57    {
58        module.blind_rotation_key_encrypt_sk_tmp_bytes(infos)
59    }
60}