arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/core/src/glwe_plaintext.rs
core/src/glwe_plaintext.rsRaw
 1use base2k::{Backend, Module, VecZnx, VecZnxAlloc, VecZnxToMut, VecZnxToRef};
 2
 3use crate::{elem::Infos, utils::derive_size};
 4
 5pub struct GLWEPlaintext<C> {
 6    pub data: VecZnx<C>,
 7    pub basek: usize,
 8    pub k: usize,
 9}
10
11impl<T> Infos for GLWEPlaintext<T> {
12    type Inner = VecZnx<T>;
13
14    fn inner(&self) -> &Self::Inner {
15        &self.data
16    }
17
18    fn basek(&self) -> usize {
19        self.basek
20    }
21
22    fn k(&self) -> usize {
23        self.k
24    }
25}
26
27impl<C> VecZnxToMut for GLWEPlaintext<C>
28where
29    VecZnx<C>: VecZnxToMut,
30{
31    fn to_mut(&mut self) -> VecZnx<&mut [u8]> {
32        self.data.to_mut()
33    }
34}
35
36impl<C> VecZnxToRef for GLWEPlaintext<C>
37where
38    VecZnx<C>: VecZnxToRef,
39{
40    fn to_ref(&self) -> VecZnx<&[u8]> {
41        self.data.to_ref()
42    }
43}
44
45impl GLWEPlaintext<Vec<u8>> {
46    pub fn new<B: Backend>(module: &Module<B>, base2k: usize, k: usize) -> Self {
47        Self {
48            data: module.new_vec_znx(1, derive_size(base2k, k)),
49            basek: base2k,
50            k,
51        }
52    }
53}