mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Added LWESecret
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use backend::{Backend, FFT64, Module, ScalarZnx, ScalarZnxAlloc, ScalarZnxToRef, Scratch, ZnxView, ZnxViewMut};
|
||||
use sampling::source::Source;
|
||||
|
||||
use crate::{AutomorphismKey, GGSWCiphertext, GLWESecret, SecretDistribution};
|
||||
use crate::{AutomorphismKey, GGSWCiphertext, GLWESecret, LWESecret, SecretDistribution};
|
||||
|
||||
pub struct BlindRotationKeyCGGI<B: Backend> {
|
||||
pub(crate) data: Vec<GGSWCiphertext<Vec<u8>, B>>,
|
||||
@@ -27,7 +27,7 @@ impl BlindRotationKeyCGGI<FFT64> {
|
||||
&mut self,
|
||||
module: &Module<FFT64>,
|
||||
sk_glwe: &GLWESecret<DataSkGLWE, FFT64>,
|
||||
sk_lwe: &GLWESecret<DataSkLWE, FFT64>,
|
||||
sk_lwe: &LWESecret<DataSkLWE>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
|
||||
@@ -17,6 +17,66 @@ pub(crate) enum SecretDistribution {
|
||||
NONE, // Unitialized
|
||||
}
|
||||
|
||||
pub struct LWESecret<T> {
|
||||
pub(crate) data: ScalarZnx<T>,
|
||||
pub(crate) dist: SecretDistribution,
|
||||
}
|
||||
|
||||
impl LWESecret<Vec<u8>> {
|
||||
pub fn alloc(n: usize) -> Self {
|
||||
Self {
|
||||
data: ScalarZnx::new(n, 1),
|
||||
dist: SecretDistribution::NONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf> LWESecret<DataSelf> {
|
||||
pub fn n(&self) -> usize {
|
||||
self.data.n()
|
||||
}
|
||||
|
||||
pub fn log_n(&self) -> usize {
|
||||
self.data.log_n()
|
||||
}
|
||||
|
||||
pub fn rank(&self) -> usize {
|
||||
self.data.cols()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: AsRef<[u8]> + AsMut<[u8]>> LWESecret<D> {
|
||||
pub fn fill_ternary_prob(&mut self, prob: f64, source: &mut Source) {
|
||||
self.data.fill_ternary_prob(0, prob, source);
|
||||
self.dist = SecretDistribution::TernaryProb(prob);
|
||||
}
|
||||
|
||||
pub fn fill_ternary_hw(&mut self, hw: usize, source: &mut Source) {
|
||||
self.data.fill_ternary_hw(0, hw, source);
|
||||
self.dist = SecretDistribution::TernaryFixed(hw);
|
||||
}
|
||||
|
||||
pub fn fill_binary_prob(&mut self, prob: f64, source: &mut Source) {
|
||||
self.data.fill_binary_prob(0, prob, source);
|
||||
self.dist = SecretDistribution::BinaryProb(prob);
|
||||
}
|
||||
|
||||
pub fn fill_binary_hw(&mut self, hw: usize, source: &mut Source) {
|
||||
self.data.fill_binary_hw(0, hw, source);
|
||||
self.dist = SecretDistribution::BinaryFixed(hw);
|
||||
}
|
||||
|
||||
pub fn fill_binary_block(&mut self, block_size: usize, source: &mut Source) {
|
||||
self.data.fill_binary_block(0, block_size, source);
|
||||
self.dist = SecretDistribution::BinaryBlock(block_size);
|
||||
}
|
||||
|
||||
pub fn fill_zero(&mut self) {
|
||||
self.data.zero();
|
||||
self.dist = SecretDistribution::ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GLWESecret<T, B: Backend> {
|
||||
pub(crate) data: ScalarZnx<T>,
|
||||
pub(crate) data_fourier: ScalarZnxDft<T, B>,
|
||||
@@ -5,10 +5,10 @@ pub mod gglwe_ciphertext;
|
||||
pub mod ggsw_ciphertext;
|
||||
pub mod glwe_ciphertext;
|
||||
pub mod glwe_ciphertext_fourier;
|
||||
pub mod glwe_keys;
|
||||
pub mod glwe_ops;
|
||||
pub mod glwe_packing;
|
||||
pub mod glwe_plaintext;
|
||||
pub mod keys;
|
||||
pub mod keyswitch_key;
|
||||
pub mod tensor_key;
|
||||
#[cfg(test)]
|
||||
@@ -24,10 +24,10 @@ pub use gglwe_ciphertext::*;
|
||||
pub use ggsw_ciphertext::*;
|
||||
pub use glwe_ciphertext::*;
|
||||
pub use glwe_ciphertext_fourier::*;
|
||||
pub use glwe_keys::*;
|
||||
pub use glwe_ops::*;
|
||||
pub use glwe_packing::*;
|
||||
pub use glwe_plaintext::*;
|
||||
pub use keys::*;
|
||||
pub use keyswitch_key::*;
|
||||
pub use tensor_key::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user