poulpy/core/src/lwe/secret.rs
core/src/lwe/secret.rsRaw
1use backend::{ScalarZnx, ZnxInfos, ZnxZero};
2use sampling::source::Source;
3
4use crate::Distribution;
5
6pub struct LWESecret<T> {
7 pub(crate) data: ScalarZnx<T>,
8 pub(crate) dist: Distribution,
9}
10
11impl LWESecret<Vec<u8>> {
12 pub fn alloc(n: usize) -> Self {
13 Self {
14 data: ScalarZnx::new(n, 1),
15 dist: Distribution::NONE,
16 }
17 }
18}
19
20impl<DataSelf> LWESecret<DataSelf> {
21 pub fn n(&self) -> usize {
22 self.data.n()
23 }
24
25 pub fn log_n(&self) -> usize {
26 self.data.log_n()
27 }
28
29 pub fn rank(&self) -> usize {
30 self.data.cols()
31 }
32}
33
34impl<D: AsRef<[u8]> + AsMut<[u8]>> LWESecret<D> {
35 pub fn fill_ternary_prob(&mut self, prob: f64, source: &mut Source) {
36 self.data.fill_ternary_prob(0, prob, source);
37 self.dist = Distribution::TernaryProb(prob);
38 }
39
40 pub fn fill_ternary_hw(&mut self, hw: usize, source: &mut Source) {
41 self.data.fill_ternary_hw(0, hw, source);
42 self.dist = Distribution::TernaryFixed(hw);
43 }
44
45 pub fn fill_binary_prob(&mut self, prob: f64, source: &mut Source) {
46 self.data.fill_binary_prob(0, prob, source);
47 self.dist = Distribution::BinaryProb(prob);
48 }
49
50 pub fn fill_binary_hw(&mut self, hw: usize, source: &mut Source) {
51 self.data.fill_binary_hw(0, hw, source);
52 self.dist = Distribution::BinaryFixed(hw);
53 }
54
55 pub fn fill_binary_block(&mut self, block_size: usize, source: &mut Source) {
56 self.data.fill_binary_block(0, block_size, source);
57 self.dist = Distribution::BinaryBlock(block_size);
58 }
59
60 pub fn fill_zero(&mut self) {
61 self.data.zero();
62 self.dist = Distribution::ZERO;
63 }
64}