arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/core/src/elem.rs
core/src/elem.rsRaw
 1use backend::{Backend, Module, ZnxInfos};
 2
 3use crate::GLWECiphertextFourier;
 4
 5pub trait Infos {
 6    type Inner: ZnxInfos;
 7
 8    fn inner(&self) -> &Self::Inner;
 9
10    /// Returns the ring degree of the polynomials.
11    fn n(&self) -> usize {
12        self.inner().n()
13    }
14
15    /// Returns the base two logarithm of the ring dimension of the polynomials.
16    fn log_n(&self) -> usize {
17        self.inner().log_n()
18    }
19
20    /// Returns the number of rows.
21    fn rows(&self) -> usize {
22        self.inner().rows()
23    }
24
25    /// Returns the number of polynomials in each row.
26    fn cols(&self) -> usize {
27        self.inner().cols()
28    }
29
30    fn rank(&self) -> usize {
31        self.cols() - 1
32    }
33
34    /// Returns the number of size per polynomial.
35    fn size(&self) -> usize {
36        let size: usize = self.inner().size();
37        debug_assert_eq!(size, self.k().div_ceil(self.basek()));
38        size
39    }
40
41    /// Returns the total number of small polynomials.
42    fn poly_count(&self) -> usize {
43        self.rows() * self.cols() * self.size()
44    }
45
46    /// Returns the base 2 logarithm of the ciphertext base.
47    fn basek(&self) -> usize;
48
49    /// Returns the bit precision of the ciphertext.
50    fn k(&self) -> usize;
51}
52
53pub trait SetMetaData {
54    fn set_basek(&mut self, basek: usize);
55    fn set_k(&mut self, k: usize);
56}
57
58pub trait GetRow<B: Backend> {
59    fn get_row<R>(&self, module: &Module<B>, row_i: usize, col_j: usize, res: &mut GLWECiphertextFourier<R, B>)
60    where
61        R: AsMut<[u8]> + AsRef<[u8]>;
62}
63
64pub trait SetRow<B: Backend> {
65    fn set_row<R>(&mut self, module: &Module<B>, row_i: usize, col_j: usize, a: &GLWECiphertextFourier<R, B>)
66    where
67        R: AsRef<[u8]>;
68}