Added LWE-GLWE conversion & LWE Keyswitch, improved LUT generation

This commit is contained in:
Jean-Philippe Bossuat
2025-07-07 11:09:04 +02:00
parent c4a517e9c3
commit 5234c3fc63
28 changed files with 979 additions and 782 deletions

View File

@@ -231,6 +231,23 @@ impl Scratch {
)
}
pub fn tmp_slice_vec_znx_dft<B: Backend>(
&mut self,
slice_size: usize,
module: &Module<B>,
cols: usize,
size: usize,
) -> (Vec<VecZnxDft<&mut [u8], B>>, &mut Self) {
let mut scratch: &mut Scratch = self;
let mut slice: Vec<VecZnxDft<&mut [u8], B>> = Vec::with_capacity(slice_size);
for _ in 0..slice_size{
let (znx, new_scratch) = scratch.tmp_vec_znx_dft(module, cols, size);
scratch = new_scratch;
slice.push(znx);
};
(slice, scratch)
}
pub fn tmp_vec_znx_big<B: Backend>(
&mut self,
module: &Module<B>,
@@ -253,6 +270,23 @@ impl Scratch {
)
}
pub fn tmp_slice_vec_znx<B: Backend>(
&mut self,
slice_size: usize,
module: &Module<B>,
cols: usize,
size: usize,
) -> (Vec<VecZnx<&mut [u8]>>, &mut Self) {
let mut scratch: &mut Scratch = self;
let mut slice: Vec<VecZnx<&mut [u8]>> = Vec::with_capacity(slice_size);
for _ in 0..slice_size{
let (znx, new_scratch) = scratch.tmp_vec_znx(module, cols, size);
scratch = new_scratch;
slice.push(znx);
};
(slice, scratch)
}
pub fn tmp_mat_znx_dft<B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -57,8 +57,8 @@ pub trait ZnxView: ZnxInfos + DataView<D: AsRef<[u8]>> {
fn at_ptr(&self, i: usize, j: usize) -> *const Self::Scalar {
#[cfg(debug_assertions)]
{
assert!(i < self.cols());
assert!(j < self.size());
assert!(i < self.cols(), "{} >= {}", i, self.cols());
assert!(j < self.size(), "{} >= {}", j, self.size());
}
let offset: usize = self.n() * (j * self.cols() + i);
unsafe { self.as_ptr().add(offset) }
@@ -85,8 +85,8 @@ pub trait ZnxViewMut: ZnxView + DataViewMut<D: AsMut<[u8]>> {
fn at_mut_ptr(&mut self, i: usize, j: usize) -> *mut Self::Scalar {
#[cfg(debug_assertions)]
{
assert!(i < self.cols());
assert!(j < self.size());
assert!(i < self.cols(), "{} >= {}", i, self.cols());
assert!(j < self.size(), "{} >= {}", j, self.size());
}
let offset: usize = self.n() * (j * self.cols() + i);
unsafe { self.as_mut_ptr().add(offset) }