arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-schemes/src/tfhe/blind_rotation/utils.rs
poulpy-schemes/src/tfhe/blind_rotation/utils.rsRaw
 1use poulpy_backend::hal::{
 2    api::{SvpPrepare, ZnxInfos, ZnxViewMut},
 3    layouts::{Backend, DataMut, Module, ScalarZnx, SvpPPol},
 4};
 5
 6pub(crate) fn set_xai_plus_y<A, C, B: Backend>(
 7    module: &Module<B>,
 8    ai: usize,
 9    y: i64,
10    res: &mut SvpPPol<A, B>,
11    buf: &mut ScalarZnx<C>,
12) where
13    A: DataMut,
14    C: DataMut,
15    Module<B>: SvpPrepare<B>,
16{
17    let n: usize = res.n();
18
19    {
20        let raw: &mut [i64] = buf.at_mut(0, 0);
21        if ai < n {
22            raw[ai] = 1;
23        } else {
24            raw[(ai - n) & (n - 1)] = -1;
25        }
26        raw[0] += y;
27    }
28
29    module.svp_prepare(res, 0, buf, 0);
30
31    {
32        let raw: &mut [i64] = buf.at_mut(0, 0);
33
34        if ai < n {
35            raw[ai] = 0;
36        } else {
37            raw[(ai - n) & (n - 1)] = 0;
38        }
39        raw[0] = 0;
40    }
41}