Clippy check & update CI (#73) * updated CI workflow with clippy & fmt
jump to
@@ -18,6 +18,8 @@ submodules: recursive
- name: Install Rust nightly uses: dtolnay/rust-toolchain@nightly + with: + components: clippy, rustfmt - name: Cache cargo dependencies uses: actions/cache@v4@@ -32,6 +34,12 @@ ${{ runner.os }}-cargo-
- name: Build run: cargo build --all-targets + + - name: Clippy (deny warnings) + run: cargo clippy --workspace --all-targets --all-features -- -D warnings + + - name: rustfmt (check only) + run: cargo fmt --all --check - name: Run tests run: cargo test --all
@@ -1,6 +1,6 @@
-use crate::hal::layouts::{Backend, Module}; +use crate::hal::layouts::Backend; /// Instantiate a new [crate::hal::layouts::Module]. pub trait ModuleNew<B: Backend> { - fn new(n: u64) -> Module<B>; + fn new(n: u64) -> Self; }
@@ -164,7 +164,7 @@ /// # Panics
/// /// This method requires that all [crate::hal::layouts::VecZnx] of b have the same ring degree /// and that b.n() * b.len() <= a.n() - fn vec_znx_split<R, A>(&self, res: &mut Vec<R>, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>) + fn vec_znx_split<R, A>(&self, res: &mut [R], res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>) where R: VecZnxToMut, A: VecZnxToRef;@@ -177,7 +177,7 @@ /// # Panics
/// /// This method requires that all [crate::hal::layouts::VecZnx] of a have the same ring degree /// and that a.n() * a.len() <= b.n() - fn vec_znx_merge<R, A>(&self, res: &mut R, res_col: usize, a: Vec<A>, a_col: usize) + fn vec_znx_merge<R, A>(&self, res: &mut R, res_col: usize, a: &[A], a_col: usize) where R: VecZnxToMut, A: VecZnxToRef;@@ -204,6 +204,7 @@ where
R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] pub trait VecZnxFillDistF64 { fn vec_znx_fill_dist_f64<R, D: Distribution<f64>>( &self,@@ -218,6 +219,7 @@ ) where
R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] pub trait VecZnxAddDistF64 { /// Adds vector sampled according to the provided distribution, scaled by 2^{-k} and bounded to \[-bound, bound\]. fn vec_znx_add_dist_f64<R, D: Distribution<f64>>(@@ -233,6 +235,7 @@ ) where
R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] pub trait VecZnxFillNormal { fn vec_znx_fill_normal<R>( &self,@@ -247,6 +250,7 @@ ) where
R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] pub trait VecZnxAddNormal { /// Adds a discrete normal vector scaled by 2^{-k} with the provided standard deviation and bounded to \[-bound, bound\]. fn vec_znx_add_normal<R>(
@@ -19,6 +19,7 @@ pub trait VecZnxBigFromBytes<B: Backend> {
fn vec_znx_big_from_bytes(&self, n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxBigOwned<B>; } +#[allow(clippy::too_many_arguments)] /// Add a discrete normal distribution on res. /// /// # Arguments@@ -42,6 +43,7 @@ bound: f64,
); } +#[allow(clippy::too_many_arguments)] pub trait VecZnxBigFillNormal<B: Backend> { fn vec_znx_big_fill_normal<R: VecZnxBigToMut<B>>( &self,@@ -55,6 +57,7 @@ bound: f64,
); } +#[allow(clippy::too_many_arguments)] pub trait VecZnxBigFillDistF64<B: Backend> { fn vec_znx_big_fill_dist_f64<R: VecZnxBigToMut<B>, D: Distribution<f64>>( &self,@@ -68,6 +71,7 @@ bound: f64,
); } +#[allow(clippy::too_many_arguments)] pub trait VecZnxBigAddDistF64<B: Backend> { fn vec_znx_big_add_dist_f64<R: VecZnxBigToMut<B>, D: Distribution<f64>>( &self,
@@ -33,6 +33,7 @@ R: VmpPMatToMut<B>,
A: MatZnxToRef; } +#[allow(clippy::too_many_arguments)] pub trait VmpApplyTmpBytes { fn vmp_apply_tmp_bytes( &self,@@ -78,6 +79,7 @@ A: VecZnxDftToRef<B>,
C: VmpPMatToRef<B>; } +#[allow(clippy::too_many_arguments)] pub trait VmpApplyAddTmpBytes { fn vmp_apply_add_tmp_bytes( &self,
@@ -274,7 +274,7 @@ impl<B> VecZnxSplit<B> for Module<B>
where B: Backend + VecZnxSplitImpl<B>, { - fn vec_znx_split<R, A>(&self, res: &mut Vec<R>, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>) + fn vec_znx_split<R, A>(&self, res: &mut [R], res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>) where R: VecZnxToMut, A: VecZnxToRef,@@ -287,7 +287,7 @@ impl<B> VecZnxMerge for Module<B>
where B: Backend + VecZnxMergeImpl<B>, { - fn vec_znx_merge<R, A>(&self, res: &mut R, res_col: usize, a: Vec<A>, a_col: usize) + fn vec_znx_merge<R, A>(&self, res: &mut R, res_col: usize, a: &[A], a_col: usize) where R: VecZnxToMut, A: VecZnxToRef,
@@ -15,7 +15,7 @@ {
let a: VecZnx<&mut [u8]> = self.to_mut(); assert!( size <= a.size(), - "invalid argument k: k.div_ceil(basek)={} > a.size()={}", + "invalid argument k.div_ceil(basek)={} > a.size()={}", size, a.size() );@@ -69,7 +69,7 @@ let a: VecZnx<&mut [u8]> = self.to_mut();
assert!(idx < a.n()); assert!( size <= a.size(), - "invalid argument k: k.div_ceil(basek)={} > a.size()={}", + "invalid argument k.div_ceil(basek)={} > a.size()={}", size, a.size() );
@@ -2,7 +2,7 @@ use crate::{
alloc_aligned, hal::{ api::{DataView, DataViewMut, FillUniform, Reset, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, ZnxZero}, - layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, WriterTo}, + layouts::{Data, DataMut, DataRef, ReaderFrom, ToOwnedDeep, VecZnx, WriterTo}, }, }; use std::fmt;@@ -19,6 +19,20 @@ size: usize,
rows: usize, cols_in: usize, cols_out: usize, +} + +impl<D: DataRef> ToOwnedDeep for MatZnx<D> { + type Owned = MatZnx<Vec<u8>>; + fn to_owned_deep(&self) -> Self::Owned { + MatZnx { + data: self.data.as_ref().to_vec(), + n: self.n, + size: self.size, + rows: self.rows, + cols_in: self.cols_in, + cols_out: self.cols_out, + } + } } impl<D: DataRef> fmt::Debug for MatZnx<D> {@@ -86,7 +100,7 @@
pub fn alloc(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> Self { let data: Vec<u8> = alloc_aligned(Self::alloc_bytes(n, rows, cols_in, cols_out, size)); Self { - data: data.into(), + data, n, size, rows,@@ -99,7 +113,7 @@ pub fn from_bytes(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into(); assert!(data.len() == Self::alloc_bytes(n, rows, cols_in, cols_out, size)); Self { - data: data.into(), + data, n, size, rows,
@@ -25,3 +25,8 @@
pub trait Data = PartialEq + Eq + Sized; pub trait DataRef = Data + AsRef<[u8]>; pub trait DataMut = DataRef + AsMut<[u8]>; + +pub trait ToOwnedDeep { + type Owned; + fn to_owned_deep(&self) -> Self::Owned; +}
@@ -2,6 +2,7 @@ use std::{marker::PhantomData, ptr::NonNull};
use crate::GALOISGENERATOR; +#[allow(clippy::missing_safety_doc)] pub trait Backend: Sized { type Handle: 'static; unsafe fn destroy(handle: NonNull<Self::Handle>);@@ -17,6 +18,7 @@ impl<B: Backend> Module<B> {
/// Construct from a raw pointer managed elsewhere. /// SAFETY: `ptr` must be non-null and remain valid for the lifetime of this Module. #[inline] + #[allow(clippy::missing_safety_doc)] pub unsafe fn from_raw_parts(ptr: *mut B::Handle, n: u64) -> Self { Self { ptr: NonNull::new(ptr).expect("null module ptr"),@@ -25,6 +27,7 @@ _marker: PhantomData,
} } + #[allow(clippy::missing_safety_doc)] #[inline] pub unsafe fn ptr(&self) -> *mut <B as Backend>::Handle { self.ptr.as_ptr()@@ -55,7 +58,8 @@ pub fn galois_element(&self, generator: i64) -> i64 {
if generator == 0 { return 1; } - ((mod_exp_u64(GALOISGENERATOR, generator.abs() as usize) & (self.cyclotomic_order() - 1)) as i64) * generator.signum() + ((mod_exp_u64(GALOISGENERATOR, generator.unsigned_abs() as usize) & (self.cyclotomic_order() - 1)) as i64) + * generator.signum() } // Returns gen^-1@@ -64,7 +68,10 @@ pub fn galois_element_inv(&self, gal_el: i64) -> i64 {
if gal_el == 0 { panic!("cannot invert 0") } - ((mod_exp_u64(gal_el.abs() as u64, (self.cyclotomic_order() - 1) as usize) & (self.cyclotomic_order() - 1)) as i64) + ((mod_exp_u64( + gal_el.unsigned_abs(), + (self.cyclotomic_order() - 1) as usize, + ) & (self.cyclotomic_order() - 1)) as i64) * gal_el.signum() } }
@@ -7,7 +7,7 @@ use crate::{
alloc_aligned, hal::{ api::{DataView, DataViewMut, FillUniform, Reset, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, ZnxZero}, - layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, WriterTo}, + layouts::{Data, DataMut, DataRef, ReaderFrom, ToOwnedDeep, VecZnx, WriterTo}, }, };@@ -16,6 +16,17 @@ pub struct ScalarZnx<D: Data> {
pub(crate) data: D, pub(crate) n: usize, pub(crate) cols: usize, +} + +impl<D: DataRef> ToOwnedDeep for ScalarZnx<D> { + type Owned = ScalarZnx<Vec<u8>>; + fn to_owned_deep(&self) -> Self::Owned { + ScalarZnx { + data: self.data.as_ref().to_vec(), + n: self.n, + cols: self.cols, + } + } } impl<D: Data> ZnxInfos for ScalarZnx<D> {@@ -63,7 +74,7 @@ impl<D: DataMut> ScalarZnx<D> {
pub fn fill_ternary_prob(&mut self, col: usize, prob: f64, source: &mut Source) { let choices: [i64; 3] = [-1, 0, 1]; let weights: [f64; 3] = [prob / 2.0, 1.0 - prob, prob / 2.0]; - let dist: WeightedIndex<f64> = WeightedIndex::new(&weights).unwrap(); + let dist: WeightedIndex<f64> = WeightedIndex::new(weights).unwrap(); self.at_mut(col, 0) .iter_mut() .for_each(|x: &mut i64| *x = choices[dist.sample(source)]);@@ -80,7 +91,7 @@
pub fn fill_binary_prob(&mut self, col: usize, prob: f64, source: &mut Source) { let choices: [i64; 2] = [0, 1]; let weights: [f64; 2] = [1.0 - prob, prob]; - let dist: WeightedIndex<f64> = WeightedIndex::new(&weights).unwrap(); + let dist: WeightedIndex<f64> = WeightedIndex::new(weights).unwrap(); self.at_mut(col, 0) .iter_mut() .for_each(|x: &mut i64| *x = choices[dist.sample(source)]);@@ -95,7 +106,7 @@ self.at_mut(col, 0).shuffle(source);
} pub fn fill_binary_block(&mut self, col: usize, block_size: usize, source: &mut Source) { - assert!(self.n() % block_size == 0); + assert!(self.n().is_multiple_of(block_size)); let max_idx: u64 = (block_size + 1) as u64; let mask_idx: u64 = (1 << ((u64::BITS - max_idx.leading_zeros()) as u64)) - 1; for block in self.at_mut(col, 0).chunks_mut(block_size) {@@ -114,21 +125,13 @@ }
pub fn alloc(n: usize, cols: usize) -> Self { let data: Vec<u8> = alloc_aligned::<u8>(Self::alloc_bytes(n, cols)); - Self { - data: data.into(), - n, - cols, - } + Self { data, n, cols } } pub fn from_bytes(n: usize, cols: usize, bytes: impl Into<Vec<u8>>) -> Self { let data: Vec<u8> = bytes.into(); assert!(data.len() == Self::alloc_bytes(n, cols)); - Self { - data: data.into(), - n, - cols, - } + Self { data, n, cols } } }
@@ -4,17 +4,30 @@ use crate::{
alloc_aligned, hal::{ api::{DataView, DataViewMut, FillUniform, Reset, ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, ZnxZero}, - layouts::{Data, DataMut, DataRef, ReaderFrom, WriterTo}, + layouts::{Data, DataMut, DataRef, ReaderFrom, ToOwnedDeep, WriterTo}, }, }; -#[derive(PartialEq, Eq, Clone)] +#[derive(PartialEq, Eq, Clone, Copy)] pub struct VecZnx<D: Data> { pub(crate) data: D, pub(crate) n: usize, pub(crate) cols: usize, pub(crate) size: usize, pub(crate) max_size: usize, +} + +impl<D: DataRef> ToOwnedDeep for VecZnx<D> { + type Owned = VecZnx<Vec<u8>>; + fn to_owned_deep(&self) -> Self::Owned { + VecZnx { + data: self.data.as_ref().to_vec(), + n: self.n, + cols: self.cols, + size: self.size, + max_size: self.max_size, + } + } } impl<D: DataRef> fmt::Debug for VecZnx<D> {@@ -87,7 +100,7 @@
pub fn alloc(n: usize, cols: usize, size: usize) -> Self { let data: Vec<u8> = alloc_aligned::<u8>(Self::alloc_bytes(n, cols, size)); Self { - data: data.into(), + data, n, cols, size,@@ -99,7 +112,7 @@ pub fn from_bytes<Scalar: Sized>(n: usize, cols: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into(); assert!(data.len() == Self::alloc_bytes(n, cols, size)); Self { - data: data.into(), + data, n, cols, size,@@ -203,19 +216,6 @@ n: self.n,
cols: self.cols, size: self.size, max_size: self.max_size, - } - } -} - -impl<D: DataRef> VecZnx<D> { - pub fn clone(&self) -> VecZnx<Vec<u8>> { - let self_ref: VecZnx<&[u8]> = self.to_ref(); - VecZnx { - data: self_ref.data.to_vec(), - n: self_ref.n, - cols: self_ref.cols, - size: self_ref.size, - max_size: self_ref.max_size, } } }
@@ -94,7 +94,7 @@ pub(crate) fn alloc(n: usize, cols: usize, size: usize) -> Self {
let data: Vec<u8> = alloc_aligned::<u8>(Self::bytes_of(n, cols, size)); Self { data: data.into(), - n: n, + n, cols, size, max_size: size,@@ -107,7 +107,7 @@ let data: Vec<u8> = bytes.into();
assert!(data.len() == Self::bytes_of(n, cols, size)); Self { data: data.into(), - n: n, + n, cols, size, max_size: size,
@@ -1,5 +1,9 @@
use crate::hal::layouts::{Backend, Module}; +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait ModuleNewImpl<B: Backend> { fn new_impl(n: u64) -> Module<B>; }
@@ -3,38 +3,74 @@ api::ZnxInfos,
layouts::{Backend, DataRef, MatZnx, ScalarZnx, Scratch, ScratchOwned, SvpPPol, VecZnx, VecZnxBig, VecZnxDft, VmpPMat}, }; +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait ScratchOwnedAllocImpl<B: Backend> { fn scratch_owned_alloc_impl(size: usize) -> ScratchOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait ScratchOwnedBorrowImpl<B: Backend> { fn scratch_owned_borrow_impl(scratch: &mut ScratchOwned<B>) -> &mut Scratch<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait ScratchFromBytesImpl<B: Backend> { fn scratch_from_bytes_impl(data: &mut [u8]) -> &mut Scratch<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait ScratchAvailableImpl<B: Backend> { fn scratch_available_impl(scratch: &Scratch<B>) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeSliceImpl<B: Backend> { fn take_slice_impl<T>(scratch: &mut Scratch<B>, len: usize) -> (&mut [T], &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeScalarZnxImpl<B: Backend> { fn take_scalar_znx_impl(scratch: &mut Scratch<B>, n: usize, cols: usize) -> (ScalarZnx<&mut [u8]>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeSvpPPolImpl<B: Backend> { fn take_svp_ppol_impl(scratch: &mut Scratch<B>, n: usize, cols: usize) -> (SvpPPol<&mut [u8], B>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeVecZnxImpl<B: Backend> { fn take_vec_znx_impl(scratch: &mut Scratch<B>, n: usize, cols: usize, size: usize) -> (VecZnx<&mut [u8]>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeVecZnxSliceImpl<B: Backend> { fn take_vec_znx_slice_impl( scratch: &mut Scratch<B>,@@ -45,6 +81,10 @@ size: usize,
) -> (Vec<VecZnx<&mut [u8]>>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeVecZnxBigImpl<B: Backend> { fn take_vec_znx_big_impl( scratch: &mut Scratch<B>,@@ -54,6 +94,10 @@ size: usize,
) -> (VecZnxBig<&mut [u8], B>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeVecZnxDftImpl<B: Backend> { fn take_vec_znx_dft_impl( scratch: &mut Scratch<B>,@@ -63,6 +107,10 @@ size: usize,
) -> (VecZnxDft<&mut [u8], B>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeVecZnxDftSliceImpl<B: Backend> { fn take_vec_znx_dft_slice_impl( scratch: &mut Scratch<B>,@@ -73,6 +121,10 @@ size: usize,
) -> (Vec<VecZnxDft<&mut [u8], B>>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeVmpPMatImpl<B: Backend> { fn take_vmp_pmat_impl( scratch: &mut Scratch<B>,@@ -84,6 +136,10 @@ size: usize,
) -> (VmpPMat<&mut [u8], B>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait TakeMatZnxImpl<B: Backend> { fn take_mat_znx_impl( scratch: &mut Scratch<B>,@@ -95,6 +151,10 @@ size: usize,
) -> (MatZnx<&mut [u8]>, &mut Scratch<B>); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub trait TakeLikeImpl<'a, B: Backend, T> { type Output; fn take_like_impl(scratch: &'a mut Scratch<B>, template: &T) -> (Self::Output, &'a mut Scratch<B>);
@@ -2,18 +2,34 @@ use crate::hal::layouts::{
Backend, Module, ScalarZnxToRef, SvpPPolOwned, SvpPPolToMut, SvpPPolToRef, VecZnxDftToMut, VecZnxDftToRef, }; +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait SvpPPolFromBytesImpl<B: Backend> { fn svp_ppol_from_bytes_impl(n: usize, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait SvpPPolAllocImpl<B: Backend> { fn svp_ppol_alloc_impl(n: usize, cols: usize) -> SvpPPolOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait SvpPPolAllocBytesImpl<B: Backend> { fn svp_ppol_alloc_bytes_impl(n: usize, cols: usize) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait SvpPrepareImpl<B: Backend> { fn svp_prepare_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -21,6 +37,10 @@ R: SvpPPolToMut<B>,
A: ScalarZnxToRef; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait SvpApplyImpl<B: Backend> { fn svp_apply_impl<R, A, C>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where@@ -29,6 +49,10 @@ A: SvpPPolToRef<B>,
C: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait SvpApplyInplaceImpl: Backend { fn svp_apply_inplace_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize) where
@@ -6,7 +6,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_normalize_base2k_tmp_bytes_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L245C17-L245C55) for reference code. /// * See [crate::hal::api::VecZnxNormalizeTmpBytes] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxNormalizeTmpBytesImpl<B: Backend> { fn vec_znx_normalize_tmp_bytes_impl(module: &Module<B>, n: usize) -> usize; }@@ -14,7 +14,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_normalize_base2k_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L212) for reference code. /// * See [crate::hal::api::VecZnxNormalize] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxNormalizeImpl<B: Backend> { fn vec_znx_normalize_impl<R, A>( module: &Module<B>,@@ -32,7 +32,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_normalize_base2k_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L212) for reference code. /// * See [crate::hal::api::VecZnxNormalizeInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxNormalizeInplaceImpl<B: Backend> { fn vec_znx_normalize_inplace_impl<A>(module: &Module<B>, basek: usize, a: &mut A, a_col: usize, scratch: &mut Scratch<B>) where@@ -42,7 +42,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_add_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L86) for reference code. /// * See [crate::hal::api::VecZnxAdd] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxAddImpl<B: Backend> { fn vec_znx_add_impl<R, A, C>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where@@ -54,7 +54,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_add_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L86) for reference code. /// * See [crate::hal::api::VecZnxAddInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxAddInplaceImpl<B: Backend> { fn vec_znx_add_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -65,7 +65,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_add_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L86) for reference code. /// * See [crate::hal::api::VecZnxAddScalarInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxAddScalarInplaceImpl<B: Backend> { fn vec_znx_add_scalar_inplace_impl<R, A>( module: &Module<B>,@@ -82,7 +82,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_sub_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L125) for reference code. /// * See [crate::hal::api::VecZnxSub] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxSubImpl<B: Backend> { fn vec_znx_sub_impl<R, A, C>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where@@ -94,7 +94,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_sub_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L125) for reference code. /// * See [crate::hal::api::VecZnxSubABInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxSubABInplaceImpl<B: Backend> { fn vec_znx_sub_ab_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -105,7 +105,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_sub_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L125) for reference code. /// * See [crate::hal::api::VecZnxSubBAInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxSubBAInplaceImpl<B: Backend> { fn vec_znx_sub_ba_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -116,7 +116,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_sub_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L125) for reference code. /// * See [crate::hal::api::VecZnxSubScalarInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxSubScalarInplaceImpl<B: Backend> { fn vec_znx_sub_scalar_inplace_impl<R, A>( module: &Module<B>,@@ -133,7 +133,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_negate_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L322C13-L322C31) for reference code. /// * See [crate::hal::api::VecZnxNegate] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxNegateImpl<B: Backend> { fn vec_znx_negate_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -144,7 +144,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_negate_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L322C13-L322C31) for reference code. /// * See [crate::hal::api::VecZnxNegateInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxNegateInplaceImpl<B: Backend> { fn vec_znx_negate_inplace_impl<A>(module: &Module<B>, a: &mut A, a_col: usize) where@@ -154,7 +154,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::implementation::cpu_spqlios::vec_znx::vec_znx_rsh_inplace_ref] for reference code. /// * See [crate::hal::api::VecZnxRshInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxRshInplaceImpl<B: Backend> { fn vec_znx_rsh_inplace_impl<A>(module: &Module<B>, basek: usize, k: usize, a: &mut A) where@@ -164,7 +164,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::implementation::cpu_spqlios::vec_znx::vec_znx_lsh_inplace_ref] for reference code. /// * See [crate::hal::api::VecZnxLshInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxLshInplaceImpl<B: Backend> { fn vec_znx_lsh_inplace_impl<A>(module: &Module<B>, basek: usize, k: usize, a: &mut A) where@@ -174,7 +174,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_rotate_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L164) for reference code. /// * See [crate::hal::api::VecZnxRotate] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxRotateImpl<B: Backend> { fn vec_znx_rotate_impl<R, A>(module: &Module<B>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -185,7 +185,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_rotate_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L164) for reference code. /// * See [crate::hal::api::VecZnxRotateInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxRotateInplaceImpl<B: Backend> { fn vec_znx_rotate_inplace_impl<A>(module: &Module<B>, k: i64, a: &mut A, a_col: usize) where@@ -195,7 +195,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_automorphism_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L188) for reference code. /// * See [crate::hal::api::VecZnxAutomorphism] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxAutomorphismImpl<B: Backend> { fn vec_znx_automorphism_impl<R, A>(module: &Module<B>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -206,7 +206,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_automorphism_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/32a3f5fcce9863b58e949f2dfd5abc1bfbaa09b4/spqlios/arithmetic/vec_znx.c#L188) for reference code. /// * See [crate::hal::api::VecZnxAutomorphismInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxAutomorphismInplaceImpl<B: Backend> { fn vec_znx_automorphism_inplace_impl<A>(module: &Module<B>, k: i64, a: &mut A, a_col: usize) where@@ -216,7 +216,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_mul_xp_minus_one_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/7160f588da49712a042931ea247b4259b95cefcc/spqlios/arithmetic/vec_znx.c#L200C13-L200C41) for reference code. /// * See [crate::hal::api::VecZnxMulXpMinusOne] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxMulXpMinusOneImpl<B: Backend> { fn vec_znx_mul_xp_minus_one_impl<R, A>(module: &Module<B>, p: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -227,7 +227,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [vec_znx_mul_xp_minus_one_ref](https://github.com/phantomzone-org/spqlios-arithmetic/blob/7160f588da49712a042931ea247b4259b95cefcc/spqlios/arithmetic/vec_znx.c#L200C13-L200C41) for reference code. /// * See [crate::hal::api::VecZnxMulXpMinusOneInplace] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxMulXpMinusOneInplaceImpl<B: Backend> { fn vec_znx_mul_xp_minus_one_inplace_impl<R>(module: &Module<B>, p: i64, res: &mut R, res_col: usize) where@@ -237,16 +237,10 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::implementation::cpu_spqlios::vec_znx::vec_znx_split_ref] for reference code. /// * See [crate::hal::api::VecZnxSplit] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxSplitImpl<B: Backend> { - fn vec_znx_split_impl<R, A>( - module: &Module<B>, - res: &mut Vec<R>, - res_col: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch<B>, - ) where + fn vec_znx_split_impl<R, A>(module: &Module<B>, res: &mut [R], res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>) + where R: VecZnxToMut, A: VecZnxToRef; }@@ -254,9 +248,9 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::implementation::cpu_spqlios::vec_znx::vec_znx_merge_ref] for reference code. /// * See [crate::hal::api::VecZnxMerge] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxMergeImpl<B: Backend> { - fn vec_znx_merge_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: Vec<A>, a_col: usize) + fn vec_znx_merge_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &[A], a_col: usize) where R: VecZnxToMut, A: VecZnxToRef;@@ -265,7 +259,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::implementation::cpu_spqlios::vec_znx::vec_znx_switch_degree_ref] for reference code. /// * See [crate::hal::api::VecZnxSwithcDegree] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxSwithcDegreeImpl<B: Backend> { fn vec_znx_switch_degree_impl<R: VecZnxToMut, A: VecZnxToRef>( module: &Module<B>,@@ -279,7 +273,7 @@
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::implementation::cpu_spqlios::vec_znx::vec_znx_copy_ref] for reference code. /// * See [crate::hal::api::VecZnxCopy] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxCopyImpl<B: Backend> { fn vec_znx_copy_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -289,16 +283,17 @@ }
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::hal::api::VecZnxFillUniform] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxFillUniformImpl<B: Backend> { fn vec_znx_fill_uniform_impl<R>(module: &Module<B>, basek: usize, res: &mut R, res_col: usize, k: usize, source: &mut Source) where R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] /// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::hal::api::VecZnxFillDistF64] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxFillDistF64Impl<B: Backend> { fn vec_znx_fill_dist_f64_impl<R, D: Distribution<f64>>( module: &Module<B>,@@ -313,9 +308,10 @@ ) where
R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] /// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::hal::api::VecZnxAddDistF64] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxAddDistF64Impl<B: Backend> { fn vec_znx_add_dist_f64_impl<R, D: Distribution<f64>>( module: &Module<B>,@@ -330,9 +326,10 @@ ) where
R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] /// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::hal::api::VecZnxFillNormal] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxFillNormalImpl<B: Backend> { fn vec_znx_fill_normal_impl<R>( module: &Module<B>,@@ -347,9 +344,10 @@ ) where
R: VecZnxToMut; } +#[allow(clippy::too_many_arguments)] /// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) /// * See [crate::hal::api::VecZnxAddNormal] for corresponding public API. -/// * See [crate::doc::backend_safety] for safety contract. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxAddNormalImpl<B: Backend> { fn vec_znx_add_normal_impl<R>( module: &Module<B>,
@@ -3,18 +3,35 @@ use sampling::source::Source;
use crate::hal::layouts::{Backend, Module, Scratch, VecZnxBigOwned, VecZnxBigToMut, VecZnxBigToRef, VecZnxToMut, VecZnxToRef}; +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAllocImpl<B: Backend> { fn vec_znx_big_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxBigOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigFromBytesImpl<B: Backend> { fn vec_znx_big_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxBigOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAllocBytesImpl<B: Backend> { fn vec_znx_big_alloc_bytes_impl(n: usize, cols: usize, size: usize) -> usize; } +#[allow(clippy::too_many_arguments)] +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAddNormalImpl<B: Backend> { fn add_normal_impl<R: VecZnxBigToMut<B>>( module: &Module<B>,@@ -28,6 +45,11 @@ bound: f64,
); } +#[allow(clippy::too_many_arguments)] +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigFillNormalImpl<B: Backend> { fn fill_normal_impl<R: VecZnxBigToMut<B>>( module: &Module<B>,@@ -41,6 +63,11 @@ bound: f64,
); } +#[allow(clippy::too_many_arguments)] +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigFillDistF64Impl<B: Backend> { fn fill_dist_f64_impl<R: VecZnxBigToMut<B>, D: Distribution<f64>>( module: &Module<B>,@@ -54,6 +81,11 @@ bound: f64,
); } +#[allow(clippy::too_many_arguments)] +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAddDistF64Impl<B: Backend> { fn add_dist_f64_impl<R: VecZnxBigToMut<B>, D: Distribution<f64>>( module: &Module<B>,@@ -67,6 +99,10 @@ bound: f64,
); } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAddImpl<B: Backend> { fn vec_znx_big_add_impl<R, A, C>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where@@ -75,6 +111,10 @@ A: VecZnxBigToRef<B>,
C: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAddInplaceImpl<B: Backend> { fn vec_znx_big_add_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -82,6 +122,10 @@ R: VecZnxBigToMut<B>,
A: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAddSmallImpl<B: Backend> { fn vec_znx_big_add_small_impl<R, A, C>( module: &Module<B>,@@ -97,6 +141,10 @@ A: VecZnxBigToRef<B>,
C: VecZnxToRef; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAddSmallInplaceImpl<B: Backend> { fn vec_znx_big_add_small_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -104,6 +152,10 @@ R: VecZnxBigToMut<B>,
A: VecZnxToRef; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigSubImpl<B: Backend> { fn vec_znx_big_sub_impl<R, A, C>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where@@ -112,6 +164,10 @@ A: VecZnxBigToRef<B>,
C: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigSubABInplaceImpl<B: Backend> { fn vec_znx_big_sub_ab_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -119,6 +175,10 @@ R: VecZnxBigToMut<B>,
A: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigSubBAInplaceImpl<B: Backend> { fn vec_znx_big_sub_ba_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -126,6 +186,10 @@ R: VecZnxBigToMut<B>,
A: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigSubSmallAImpl<B: Backend> { fn vec_znx_big_sub_small_a_impl<R, A, C>( module: &Module<B>,@@ -141,6 +205,10 @@ A: VecZnxToRef,
C: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigSubSmallAInplaceImpl<B: Backend> { fn vec_znx_big_sub_small_a_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -148,6 +216,10 @@ R: VecZnxBigToMut<B>,
A: VecZnxToRef; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigSubSmallBImpl<B: Backend> { fn vec_znx_big_sub_small_b_impl<R, A, C>( module: &Module<B>,@@ -163,6 +235,10 @@ A: VecZnxBigToRef<B>,
C: VecZnxToRef; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigSubSmallBInplaceImpl<B: Backend> { fn vec_znx_big_sub_small_b_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -170,16 +246,28 @@ R: VecZnxBigToMut<B>,
A: VecZnxToRef; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigNegateInplaceImpl<B: Backend> { fn vec_znx_big_negate_inplace_impl<A>(module: &Module<B>, a: &mut A, a_col: usize) where A: VecZnxBigToMut<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigNormalizeTmpBytesImpl<B: Backend> { fn vec_znx_big_normalize_tmp_bytes_impl(module: &Module<B>, n: usize) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigNormalizeImpl<B: Backend> { fn vec_znx_big_normalize_impl<R, A>( module: &Module<B>,@@ -194,6 +282,10 @@ R: VecZnxToMut,
A: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAutomorphismImpl<B: Backend> { fn vec_znx_big_automorphism_impl<R, A>(module: &Module<B>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -201,6 +293,10 @@ R: VecZnxBigToMut<B>,
A: VecZnxBigToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxBigAutomorphismInplaceImpl<B: Backend> { fn vec_znx_big_automorphism_inplace_impl<A>(module: &Module<B>, k: i64, a: &mut A, a_col: usize) where
@@ -3,22 +3,42 @@ Backend, Data, Module, Scratch, VecZnxBig, VecZnxBigToMut, VecZnxDft, VecZnxDftOwned, VecZnxDftToMut, VecZnxDftToRef,
VecZnxToRef, }; +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftAllocImpl<B: Backend> { fn vec_znx_dft_alloc_impl(n: usize, cols: usize, size: usize) -> VecZnxDftOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftFromBytesImpl<B: Backend> { fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxDftOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftAllocBytesImpl<B: Backend> { fn vec_znx_dft_alloc_bytes_impl(n: usize, cols: usize, size: usize) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftToVecZnxBigTmpBytesImpl<B: Backend> { fn vec_znx_dft_to_vec_znx_big_tmp_bytes_impl(module: &Module<B>, n: usize) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftToVecZnxBigImpl<B: Backend> { fn vec_znx_dft_to_vec_znx_big_impl<R, A>( module: &Module<B>,@@ -32,6 +52,10 @@ R: VecZnxBigToMut<B>,
A: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftToVecZnxBigTmpAImpl<B: Backend> { fn vec_znx_dft_to_vec_znx_big_tmp_a_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &mut A, a_col: usize) where@@ -39,12 +63,20 @@ R: VecZnxBigToMut<B>,
A: VecZnxDftToMut<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftToVecZnxBigConsumeImpl<B: Backend> { fn vec_znx_dft_to_vec_znx_big_consume_impl<D: Data>(module: &Module<B>, a: VecZnxDft<D, B>) -> VecZnxBig<D, B> where VecZnxDft<D, B>: VecZnxDftToMut<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftAddImpl<B: Backend> { fn vec_znx_dft_add_impl<R, A, D>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize) where@@ -53,6 +85,10 @@ A: VecZnxDftToRef<B>,
D: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftAddInplaceImpl<B: Backend> { fn vec_znx_dft_add_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -60,6 +96,10 @@ R: VecZnxDftToMut<B>,
A: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftSubImpl<B: Backend> { fn vec_znx_dft_sub_impl<R, A, D>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize) where@@ -68,6 +108,10 @@ A: VecZnxDftToRef<B>,
D: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftSubABInplaceImpl<B: Backend> { fn vec_znx_dft_sub_ab_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -75,6 +119,10 @@ R: VecZnxDftToMut<B>,
A: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftSubBAInplaceImpl<B: Backend> { fn vec_znx_dft_sub_ba_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where@@ -82,6 +130,10 @@ R: VecZnxDftToMut<B>,
A: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftCopyImpl<B: Backend> { fn vec_znx_dft_copy_impl<R, A>( module: &Module<B>,@@ -96,6 +148,10 @@ R: VecZnxDftToMut<B>,
A: VecZnxDftToRef<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftFromVecZnxImpl<B: Backend> { fn vec_znx_dft_from_vec_znx_impl<R, A>( module: &Module<B>,@@ -110,6 +166,10 @@ R: VecZnxDftToMut<B>,
A: VecZnxToRef; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VecZnxDftZeroImpl<B: Backend> { fn vec_znx_dft_zero_impl<R>(module: &Module<B>, res: &mut R) where
@@ -2,14 +2,26 @@ use crate::hal::layouts::{
Backend, MatZnxToRef, Module, Scratch, VecZnxDftToMut, VecZnxDftToRef, VmpPMatOwned, VmpPMatToMut, VmpPMatToRef, }; +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpPMatAllocImpl<B: Backend> { fn vmp_pmat_alloc_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> VmpPMatOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpPMatAllocBytesImpl<B: Backend> { fn vmp_pmat_alloc_bytes_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpPMatFromBytesImpl<B: Backend> { fn vmp_pmat_from_bytes_impl( n: usize,@@ -21,6 +33,10 @@ bytes: Vec<u8>,
) -> VmpPMatOwned<B>; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpPrepareTmpBytesImpl<B: Backend> { fn vmp_prepare_tmp_bytes_impl( module: &Module<B>,@@ -32,6 +48,10 @@ size: usize,
) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpPMatPrepareImpl<B: Backend> { fn vmp_prepare_impl<R, A>(module: &Module<B>, res: &mut R, a: &A, scratch: &mut Scratch<B>) where@@ -39,6 +59,11 @@ R: VmpPMatToMut<B>,
A: MatZnxToRef; } +#[allow(clippy::too_many_arguments)] +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpApplyTmpBytesImpl<B: Backend> { fn vmp_apply_tmp_bytes_impl( module: &Module<B>,@@ -52,6 +77,10 @@ b_size: usize,
) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpApplyImpl<B: Backend> { fn vmp_apply_impl<R, A, C>(module: &Module<B>, res: &mut R, a: &A, b: &C, scratch: &mut Scratch<B>) where@@ -60,6 +89,11 @@ A: VecZnxDftToRef<B>,
C: VmpPMatToRef<B>; } +#[allow(clippy::too_many_arguments)] +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpApplyAddTmpBytesImpl<B: Backend> { fn vmp_apply_add_tmp_bytes_impl( module: &Module<B>,@@ -73,6 +107,10 @@ b_size: usize,
) -> usize; } +/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe) +/// * See TODO for reference code. +/// * See TODO for corresponding public API. +/// # Safety [crate::doc::backend_safety] for safety contract. pub unsafe trait VmpApplyAddImpl<B: Backend> { // Same as [MatZnxDftOps::vmp_apply] except result is added on R instead of overwritting R. fn vmp_apply_add_impl<R, A, C>(module: &Module<B>, res: &mut R, a: &A, b: &C, scale: usize, scratch: &mut Scratch<B>)
@@ -5,6 +5,7 @@
pub type module_type_t = ::std::os::raw::c_uint; pub use self::module_type_t as MODULE_TYPE; +#[allow(clippy::upper_case_acronyms)] pub type MODULE = module_info_t; unsafe extern "C" {
@@ -260,7 +260,7 @@ let rem_slice: &mut [u8] = &mut *std::ptr::slice_from_raw_parts_mut(rem_ptr, rem_len);
let take_slice: &mut [u8] = &mut *std::ptr::slice_from_raw_parts_mut(ptr.add(aligned_offset), take_len); - return (take_slice, rem_slice); + (take_slice, rem_slice) } } else { panic!(
@@ -34,10 +34,7 @@ unsafe { vec_znx::vec_znx_normalize_base2k_tmp_bytes(module.ptr() as *const module_info_t, n as u64) as usize }
} } -unsafe impl<B: Backend> VecZnxNormalizeImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxNormalizeImpl<B> for B { fn vec_znx_normalize_impl<R, A>( module: &Module<B>, basek: usize,@@ -77,10 +74,7 @@ }
} } -unsafe impl<B: Backend> VecZnxNormalizeInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxNormalizeInplaceImpl<B> for B { fn vec_znx_normalize_inplace_impl<A>(module: &Module<B>, basek: usize, a: &mut A, a_col: usize, scratch: &mut Scratch<B>) where A: VecZnxToMut,@@ -106,10 +100,7 @@ }
} } -unsafe impl<B: Backend> VecZnxAddImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxAddImpl<B> for B { fn vec_znx_add_impl<R, A, C>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where R: VecZnxToMut,@@ -143,10 +134,7 @@ }
} } -unsafe impl<B: Backend> VecZnxAddInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxAddInplaceImpl<B> for B { fn vec_znx_add_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -176,10 +164,7 @@ }
} } -unsafe impl<B: Backend> VecZnxAddScalarInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxAddScalarInplaceImpl<B> for B { fn vec_znx_add_scalar_inplace_impl<R, A>( module: &Module<B>, res: &mut R,@@ -203,23 +188,20 @@ unsafe {
vec_znx::vec_znx_add( module.ptr() as *const module_info_t, res.at_mut_ptr(res_col, res_limb), - 1 as u64, + 1_u64, res.sl() as u64, a.at_ptr(a_col, 0), a.size() as u64, a.sl() as u64, res.at_ptr(res_col, res_limb), - 1 as u64, + 1_u64, res.sl() as u64, ) } } } -unsafe impl<B: Backend> VecZnxSubImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxSubImpl<B> for B { fn vec_znx_sub_impl<R, A, C>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where R: VecZnxToMut,@@ -253,10 +235,7 @@ }
} } -unsafe impl<B: Backend> VecZnxSubABInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxSubABInplaceImpl<B> for B { fn vec_znx_sub_ab_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -285,10 +264,7 @@ }
} } -unsafe impl<B: Backend> VecZnxSubBAInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxSubBAInplaceImpl<B> for B { fn vec_znx_sub_ba_inplace_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -317,10 +293,7 @@ }
} } -unsafe impl<B: Backend> VecZnxSubScalarInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxSubScalarInplaceImpl<B> for B { fn vec_znx_sub_scalar_inplace_impl<R, A>( module: &Module<B>, res: &mut R,@@ -344,23 +317,20 @@ unsafe {
vec_znx::vec_znx_sub( module.ptr() as *const module_info_t, res.at_mut_ptr(res_col, res_limb), - 1 as u64, + 1_u64, res.sl() as u64, a.at_ptr(a_col, 0), a.size() as u64, a.sl() as u64, res.at_ptr(res_col, res_limb), - 1 as u64, + 1_u64, res.sl() as u64, ) } } } -unsafe impl<B: Backend> VecZnxNegateImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxNegateImpl<B> for B { fn vec_znx_negate_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -386,10 +356,7 @@ }
} } -unsafe impl<B: Backend> VecZnxNegateInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxNegateInplaceImpl<B> for B { fn vec_znx_negate_inplace_impl<A>(module: &Module<B>, a: &mut A, a_col: usize) where A: VecZnxToMut,@@ -409,10 +376,7 @@ }
} } -unsafe impl<B: Backend> VecZnxLshInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxLshInplaceImpl<B> for B { fn vec_znx_lsh_inplace_impl<A>(_module: &Module<B>, basek: usize, k: usize, a: &mut A) where A: VecZnxToMut,@@ -453,10 +417,7 @@ });
} } -unsafe impl<B: Backend> VecZnxRshInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxRshInplaceImpl<B> for B { fn vec_znx_rsh_inplace_impl<A>(_module: &Module<B>, basek: usize, k: usize, a: &mut A) where A: VecZnxToMut,@@ -500,10 +461,7 @@ })
} } -unsafe impl<B: Backend> VecZnxRotateImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxRotateImpl<B> for B { fn vec_znx_rotate_impl<R, A>(_module: &Module<B>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -528,10 +486,7 @@ }
} } -unsafe impl<B: Backend> VecZnxRotateInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxRotateInplaceImpl<B> for B { fn vec_znx_rotate_inplace_impl<A>(_module: &Module<B>, k: i64, a: &mut A, a_col: usize) where A: VecZnxToMut,@@ -545,10 +500,7 @@ }
} } -unsafe impl<B: Backend> VecZnxAutomorphismImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxAutomorphismImpl<B> for B { fn vec_znx_automorphism_impl<R, A>(module: &Module<B>, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -575,10 +527,7 @@ }
} } -unsafe impl<B: Backend> VecZnxAutomorphismInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxAutomorphismInplaceImpl<B> for B { fn vec_znx_automorphism_inplace_impl<A>(module: &Module<B>, k: i64, a: &mut A, a_col: usize) where A: VecZnxToMut,@@ -607,10 +556,7 @@ }
} } -unsafe impl<B: Backend> VecZnxMulXpMinusOneImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxMulXpMinusOneImpl<B> for B { fn vec_znx_mul_xp_minus_one_impl<R, A>(module: &Module<B>, p: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -638,10 +584,7 @@ }
} } -unsafe impl<B: Backend> VecZnxMulXpMinusOneInplaceImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxMulXpMinusOneInplaceImpl<B> for B { fn vec_znx_mul_xp_minus_one_inplace_impl<R>(module: &Module<B>, p: i64, res: &mut R, res_col: usize) where R: VecZnxToMut,@@ -666,18 +609,9 @@ }
} } -unsafe impl<B: Backend> VecZnxSplitImpl<B> for B -where - B: CPUAVX, -{ - fn vec_znx_split_impl<R, A>( - module: &Module<B>, - res: &mut Vec<R>, - res_col: usize, - a: &A, - a_col: usize, - scratch: &mut Scratch<B>, - ) where +unsafe impl<B: Backend + CPUAVX> VecZnxSplitImpl<B> for B { + fn vec_znx_split_impl<R, A>(module: &Module<B>, res: &mut [R], res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>) + where R: VecZnxToMut, A: VecZnxToRef, {@@ -685,15 +619,15 @@ vec_znx_split_ref(module, res, res_col, a, a_col, scratch)
} } -pub fn vec_znx_split_ref<R, A, B: Backend>( +pub fn vec_znx_split_ref<R, A, B>( module: &Module<B>, - res: &mut Vec<R>, + res: &mut [R], res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>, ) where - B: CPUAVX, + B: Backend + CPUAVX, R: VecZnxToMut, A: VecZnxToRef, {@@ -720,17 +654,14 @@ if i == 0 {
module.vec_znx_switch_degree(bi, res_col, &a, a_col); module.vec_znx_rotate(-1, &mut buf, 0, &a, a_col); } else { - module.vec_znx_switch_degree(bi, res_col, &mut buf, a_col); + module.vec_znx_switch_degree(bi, res_col, &buf, a_col); module.vec_znx_rotate_inplace(-1, &mut buf, a_col); } }) } -unsafe impl<B: Backend> VecZnxMergeImpl<B> for B -where - B: CPUAVX, -{ - fn vec_znx_merge_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: Vec<A>, a_col: usize) +unsafe impl<B: Backend + CPUAVX> VecZnxMergeImpl<B> for B { + fn vec_znx_merge_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &[A], a_col: usize) where R: VecZnxToMut, A: VecZnxToRef,@@ -739,9 +670,9 @@ vec_znx_merge_ref(module, res, res_col, a, a_col)
} } -pub fn vec_znx_merge_ref<R, A, B: Backend>(module: &Module<B>, res: &mut R, res_col: usize, a: Vec<A>, a_col: usize) +pub fn vec_znx_merge_ref<R, A, B>(module: &Module<B>, res: &mut R, res_col: usize, a: &[A], a_col: usize) where - B: CPUAVX, + B: Backend + CPUAVX, R: VecZnxToMut, A: VecZnxToRef, {@@ -761,7 +692,7 @@ "invalid input a: all VecZnx must have the same degree"
) }); - a.iter().enumerate().for_each(|(_, ai)| { + a.iter().for_each(|ai| { module.vec_znx_switch_degree(&mut res, res_col, ai, a_col); module.vec_znx_rotate_inplace(-1, &mut res, res_col); });@@ -769,10 +700,7 @@
module.vec_znx_rotate_inplace(a.len() as i64, &mut res, res_col); } -unsafe impl<B: Backend> VecZnxSwithcDegreeImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxSwithcDegreeImpl<B> for B { fn vec_znx_switch_degree_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -782,9 +710,9 @@ vec_znx_switch_degree_ref(module, res, res_col, a, a_col)
} } -pub fn vec_znx_switch_degree_ref<R, A, B: Backend>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) +pub fn vec_znx_switch_degree_ref<R, A, B>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where - B: CPUAVX, + B: Backend + CPUAVX, R: VecZnxToMut, A: VecZnxToRef, {@@ -817,10 +745,7 @@ .for_each(|(x_in, x_out)| *x_out = *x_in);
}); } -unsafe impl<B: Backend> VecZnxCopyImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxCopyImpl<B> for B { fn vec_znx_copy_impl<R, A>(_module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxToMut,@@ -850,10 +775,7 @@ res_mut.zero_at(res_col, j);
}) } -unsafe impl<B: Backend> VecZnxFillUniformImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxFillUniformImpl<B> for B { fn vec_znx_fill_uniform_impl<R>(_module: &Module<B>, basek: usize, res: &mut R, res_col: usize, k: usize, source: &mut Source) where R: VecZnxToMut,@@ -870,10 +792,7 @@ })
} } -unsafe impl<B: Backend> VecZnxFillDistF64Impl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxFillDistF64Impl<B> for B { fn vec_znx_fill_dist_f64_impl<R, D: rand::prelude::Distribution<f64>>( _module: &Module<B>, basek: usize,@@ -916,10 +835,7 @@ }
} } -unsafe impl<B: Backend> VecZnxAddDistF64Impl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxAddDistF64Impl<B> for B { fn vec_znx_add_dist_f64_impl<R, D: rand::prelude::Distribution<f64>>( _module: &Module<B>, basek: usize,@@ -962,10 +878,7 @@ }
} } -unsafe impl<B: Backend> VecZnxFillNormalImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxFillNormalImpl<B> for B { fn vec_znx_fill_normal_impl<R>( module: &Module<B>, basek: usize,@@ -990,10 +903,7 @@ );
} } -unsafe impl<B: Backend> VecZnxAddNormalImpl<B> for B -where - B: CPUAVX, -{ +unsafe impl<B: Backend + CPUAVX> VecZnxAddNormalImpl<B> for B { fn vec_znx_add_normal_impl<R>( module: &Module<B>, basek: usize,
@@ -91,9 +91,9 @@ (0..min_size).for_each(|j| {
vec_znx_dft::vec_znx_idft( module.ptr(), res.at_mut_ptr(res_col, j) as *mut vec_znx_big::vec_znx_big_t, - 1 as u64, + 1_u64, a.at_ptr(a_col, j) as *const vec_znx_dft::vec_znx_dft_t, - 1 as u64, + 1_u64, tmp_bytes.as_mut_ptr(), ) });@@ -120,9 +120,9 @@ (0..min_size).for_each(|j| {
vec_znx_dft::vec_znx_idft_tmp_a( module.ptr(), res_mut.at_mut_ptr(res_col, j) as *mut vec_znx_big::vec_znx_big_t, - 1 as u64, + 1_u64, a_mut.at_mut_ptr(a_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1 as u64, + 1_u64, ) }); (min_size..res_mut.size()).for_each(|j| {@@ -146,9 +146,9 @@ (0..a_mut.cols()).for_each(|i| {
vec_znx_dft::vec_znx_idft_tmp_a( module.ptr(), a_mut.at_mut_ptr(i, j) as *mut vec_znx_big::vec_znx_big_t, - 1 as u64, + 1_u64, a_mut.at_mut_ptr(i, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1 as u64, + 1_u64, ) }); });@@ -182,9 +182,9 @@ if limb < a_ref.size() {
vec_znx_dft::vec_znx_dft( module.ptr(), res_mut.at_mut_ptr(res_col, j) as *mut vec_znx_dft::vec_znx_dft_t, - 1 as u64, + 1_u64, a_ref.at_ptr(a_col, limb), - 1 as u64, + 1_u64, a_ref.sl() as u64, ) }
@@ -17,7 +17,7 @@ pub const GALOISGENERATOR: u64 = 5;
pub const DEFAULTALIGN: usize = 64; fn is_aligned_custom<T>(ptr: *const T, align: usize) -> bool { - (ptr as usize) % align == 0 + (ptr as usize).is_multiple_of(align) } pub fn is_aligned<T>(ptr: *const T) -> bool {@@ -37,6 +37,7 @@ let len: usize = data.len() / size_of::<V>();
unsafe { std::slice::from_raw_parts(ptr, len) } } +#[allow(clippy::mut_from_ref)] pub fn cast_mut<T, V>(data: &[T]) -> &mut [V] { let ptr: *mut V = data.as_ptr() as *mut V; let len: usize = data.len() / size_of::<V>();
@@ -90,7 +90,8 @@
let ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, FFT64> = ct_ggsw.prepare_alloc(&module, scratch.borrow()); move || { - black_box(ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow())); + ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow()); + black_box(()); } }@@ -185,7 +186,8 @@ let ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, FFT64> = ct_ggsw.prepare_alloc(&module, scratch.borrow());
move || { let scratch_borrow = scratch.borrow(); - black_box(ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow)); + ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow); + black_box(()); } }
@@ -96,7 +96,8 @@
let ksk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, _> = ksk.prepare_alloc(&module, scratch.borrow()); move || { - black_box(ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow())); + ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow()); + black_box(()); } }@@ -105,11 +106,11 @@ let basek: usize = 19;
let params_set: Vec<Params> = vec![Params { log_n: 15, - basek: basek, + basek, k_ct_in: 874 - digits * basek, k_ct_out: 874 - digits * basek, k_ksk: 874, - digits: digits, + digits, rank_in: 1, rank_out: 1, }];@@ -191,7 +192,8 @@
let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, FFT64> = ksk.prepare_alloc(&module, scratch.borrow()); move || { - black_box(ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow())); + ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow()); + black_box(()); } }
@@ -10,6 +10,7 @@
use crate::layouts::{GGLWEAutomorphismKey, GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared}; impl GGLWEAutomorphismKey<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn automorphism_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -43,7 +44,7 @@ }
} impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> { - pub fn automorphism<'a, DataLhs: DataRef, DataRhs: DataRef, B: Backend>( + pub fn automorphism<DataLhs: DataRef, DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, lhs: &GGLWEAutomorphismKey<DataLhs>,@@ -149,7 +150,7 @@ Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
{ unsafe { let self_ptr: *mut GGLWEAutomorphismKey<DataSelf> = self as *mut GGLWEAutomorphismKey<DataSelf>; - self.automorphism(&module, &*self_ptr, rhs, scratch); + self.automorphism(module, &*self_ptr, rhs, scratch); } } }
@@ -14,6 +14,7 @@ prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared},
}; impl GGSWCiphertext<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn automorphism_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -38,6 +39,7 @@ let expand: usize = GGSWCiphertext::expand_row_scratch_space(module, n, basek, k_out, k_tsk, digits_tsk, rank);
ci_dft + (ks_internal | expand) } + #[allow(clippy::too_many_arguments)] pub fn automorphism_inplace_scratch_space<B: Backend>( module: &Module<B>, n: usize,
@@ -10,6 +10,7 @@
use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared}; impl GLWECiphertext<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn automorphism_scratch_space<B: Backend>( module: &Module<B>, n: usize,
@@ -64,7 +64,7 @@ // c0_big = (a * s) + (-a * s + m + e) = BIG(m + e)
module.vec_znx_big_add_small_inplace(&mut c0_big, 0, &self.data, 0); // pt = norm(BIG(m + e)) - module.vec_znx_big_normalize(self.basek(), &mut pt.data, 0, &mut c0_big, 0, scratch_1); + module.vec_znx_big_normalize(self.basek(), &mut pt.data, 0, &c0_big, 0, scratch_1); pt.basek = self.basek(); pt.k = pt.k().min(self.k());
@@ -10,12 +10,12 @@ impl<DataSelf> LWECiphertext<DataSelf>
where DataSelf: DataRef, { - pub fn decrypt<DataPt, DataSk, B: Backend>(&self, module: &Module<B>, pt: &mut LWEPlaintext<DataPt>, sk: &LWESecret<DataSk>) + pub fn decrypt<DataPt, DataSk, B>(&self, module: &Module<B>, pt: &mut LWEPlaintext<DataPt>, sk: &LWESecret<DataSk>) where DataPt: DataMut, DataSk: DataRef, Module<B>: VecZnxNormalizeInplace<B>, - B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { #[cfg(debug_assertions)] {
@@ -27,6 +27,7 @@ }
} impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,@@ -96,7 +97,7 @@ });
} self.key - .encrypt_sk(module, &sk, &sk_out, seed_xa, source_xe, sigma, scratch_1); + .encrypt_sk(module, sk, &sk_out, seed_xa, source_xe, sigma, scratch_1); self.p = p; }
@@ -24,6 +24,7 @@ }
} impl<D: DataMut> GGLWECiphertextCompressed<D> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,
@@ -33,6 +33,7 @@ }
} impl<DataSelf: DataMut> GGLWESwitchingKeyCompressed<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>( &mut self, module: &Module<B>,
@@ -73,7 +73,7 @@ let n: usize = sk.n();
let rank: usize = self.rank(); let (mut sk_dft_prep, scratch1) = scratch.take_glwe_secret_prepared(n, rank); - sk_dft_prep.prepare(module, &sk, scratch1); + sk_dft_prep.prepare(module, sk, scratch1); let (mut sk_dft, scratch2) = scratch1.take_vec_znx_dft(n, rank, 1);
@@ -24,6 +24,7 @@ }
} impl<DataSelf: DataMut> GGSWCiphertextCompressed<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,
@@ -23,6 +23,7 @@ }
} impl<D: DataMut> GLWECiphertextCompressed<D> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,@@ -59,6 +60,7 @@ scratch,
); } + #[allow(clippy::too_many_arguments)] pub(crate) fn encrypt_sk_internal<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,
@@ -28,6 +28,7 @@ }
} impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,@@ -91,7 +92,7 @@ });
} self.key - .encrypt_sk(module, &sk, &sk_out, source_xa, source_xe, sigma, scratch_1); + .encrypt_sk(module, sk, &sk_out, source_xa, source_xe, sigma, scratch_1); self.p = p; }
@@ -28,6 +28,7 @@ }
} impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,
@@ -44,6 +44,7 @@ }
} impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>( &mut self, module: &Module<B>,
@@ -75,7 +75,7 @@
let rank: usize = self.rank(); let (mut sk_dft_prep, scratch1) = scratch.take_glwe_secret_prepared(n, rank); - sk_dft_prep.prepare(module, &sk, scratch1); + sk_dft_prep.prepare(module, sk, scratch1); let (mut sk_dft, scratch2) = scratch1.take_vec_znx_dft(n, rank, 1);
@@ -27,6 +27,7 @@ }
} impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,
@@ -38,6 +38,7 @@ }
} impl<DataSelf: DataMut> GLWECiphertext<DataSelf> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,@@ -133,6 +134,7 @@ scratch,
); } + #[allow(clippy::too_many_arguments)] pub(crate) fn encrypt_sk_internal<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,@@ -175,6 +177,7 @@ scratch,
); } + #[allow(clippy::too_many_arguments)] pub fn encrypt_pk<DataPt: DataRef, DataPk: DataRef, B: Backend>( &mut self, module: &Module<B>,@@ -232,6 +235,7 @@ scratch,
); } + #[allow(clippy::too_many_arguments)] pub(crate) fn encrypt_pk_internal<DataPt: DataRef, DataPk: DataRef, B: Backend>( &mut self, module: &Module<B>,@@ -307,10 +311,10 @@ sigma * SIX_SIGMA,
); // ci_big = u * pk[i] + e + m (if col = i) - if let Some((pt, col)) = pt { - if col == i { - module.vec_znx_big_add_small_inplace(&mut ci_big, 0, &pt.data, 0); - } + if let Some((pt, col)) = pt + && col == i + { + module.vec_znx_big_add_small_inplace(&mut ci_big, 0, &pt.data, 0); } // ct[i] = norm(ci_big)@@ -319,6 +323,7 @@ });
} } +#[allow(clippy::too_many_arguments)] pub(crate) fn glwe_encrypt_sk_internal<DataCt: DataMut, DataPt: DataRef, DataSk: DataRef, B: Backend>( module: &Module<B>, basek: usize,@@ -373,12 +378,7 @@
// ct[i] = uniform // ct[0] -= c[i] * s[i], (1..cols).for_each(|i| { - let col_ct: usize; - if compressed { - col_ct = 0; - } else { - col_ct = i; - } + let col_ct: usize = if compressed { 0 } else { i }; // ct[i] = uniform (+ pt) module.vec_znx_fill_uniform(basek, ct, col_ct, k, source_xa);@@ -415,10 +415,10 @@ // c[0] += e
module.vec_znx_add_normal(basek, &mut c0, 0, k, source_xe, sigma, sigma * SIX_SIGMA); // c[0] += m if col = 0 - if let Some((pt, col)) = pt { - if col == 0 { - module.vec_znx_add_inplace(&mut c0, 0, &pt.data, 0); - } + if let Some((pt, col)) = pt + && col == 0 + { + module.vec_znx_add_inplace(&mut c0, 0, &pt.data, 0); } // c[0] = norm(c[0])
@@ -12,7 +12,7 @@
use crate::layouts::{GLWECiphertext, GLWEPublicKey, Infos, prepared::GLWESecretPrepared}; impl<D: DataMut> GLWEPublicKey<D> { - pub fn generate_from_sk<S: DataRef, B: Backend>( + pub fn generate_from_sk<S: DataRef, B>( &mut self, module: &Module<B>, sk: &GLWESecretPrepared<S, B>,@@ -34,7 +34,8 @@ + VecZnxNormalizeInplace<B>
+ VecZnxAddNormal + VecZnxNormalize<B> + VecZnxSub, - B: ScratchOwnedAllocImpl<B> + B: Backend + + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B> + TakeVecZnxDftImpl<B> + ScratchAvailableImpl<B>@@ -46,9 +47,8 @@ use crate::Distribution;
assert_eq!(self.n(), sk.n()); - match sk.dist { - Distribution::NONE => panic!("invalid sk: SecretDistribution::NONE"), - _ => {} + if sk.dist == Distribution::NONE { + panic!("invalid sk: SecretDistribution::NONE") } }
@@ -26,6 +26,7 @@ }
} impl<D: DataMut> GLWEToLWESwitchingKey<D> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DLwe, DGlwe, B: Backend>( &mut self, module: &Module<B>,
@@ -13,7 +13,7 @@ layouts::{Infos, LWECiphertext, LWEPlaintext, LWESecret},
}; impl<DataSelf: DataMut> LWECiphertext<DataSelf> { - pub fn encrypt_sk<DataPt, DataSk, B: Backend>( + pub fn encrypt_sk<DataPt, DataSk, B>( &mut self, module: &Module<B>, pt: &LWEPlaintext<DataPt>,@@ -25,7 +25,7 @@ ) where
DataPt: DataRef, DataSk: DataRef, Module<B>: VecZnxFillUniform + VecZnxAddNormal + VecZnxNormalizeInplace<B>, - B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { #[cfg(debug_assertions)] {
@@ -26,6 +26,7 @@ }
} impl<D: DataMut> LWESwitchingKey<D> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DIn, DOut, B: Backend>( &mut self, module: &Module<B>,
@@ -24,6 +24,7 @@ }
} impl<D: DataMut> LWEToGLWESwitchingKey<D> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DLwe, DGlwe, B: Backend>( &mut self, module: &Module<B>,@@ -69,7 +70,7 @@
self.0.encrypt_sk( module, &sk_lwe_as_glwe, - &sk_glwe, + sk_glwe, source_xa, source_xe, sigma,
@@ -9,6 +9,7 @@
use crate::layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, prepared::GGSWCiphertextPrepared}; impl GGLWEAutomorphismKey<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn external_product_scratch_space<B: Backend>( module: &Module<B>, n: usize,
@@ -9,6 +9,7 @@
use crate::layouts::{GGLWESwitchingKey, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}; impl GGLWESwitchingKey<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn external_product_scratch_space<B: Backend>( module: &Module<B>, n: usize,
@@ -9,6 +9,7 @@
use crate::layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}; impl GGSWCiphertext<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn external_product_scratch_space<B: Backend>( module: &Module<B>, n: usize,
@@ -9,6 +9,7 @@
use crate::layouts::{GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}; impl GLWECiphertext<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn external_product_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -160,7 +161,7 @@ Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
{ unsafe { let self_ptr: *mut GLWECiphertext<DataSelf> = self as *mut GLWECiphertext<DataSelf>; - self.external_product(&module, &*self_ptr, rhs, scratch); + self.external_product(module, &*self_ptr, rhs, scratch); } } }
@@ -55,14 +55,14 @@
impl GLWEPacker { /// Instantiates a new [GLWEPacker]. /// - /// #Arguments + /// # Arguments /// /// * `module`: static backend FFT tables. /// * `log_batch`: packs coefficients which are multiples of X^{N/2^log_batch}. - /// i.e. with `log_batch=0` only the constant coefficient is packed - /// and N GLWE ciphertext can be packed. With `log_batch=2` all coefficients - /// which are multiples of X^{N/4} are packed. Meaning that N/4 ciphertexts - /// can be packed. + /// i.e. with `log_batch=0` only the constant coefficient is packed + /// and N GLWE ciphertext can be packed. With `log_batch=2` all coefficients + /// which are multiples of X^{N/4} are packed. Meaning that N/4 ciphertexts + /// can be packed. /// * `basek`: base 2 logarithm of the GLWE ciphertext in memory digit representation. /// * `k`: base 2 precision of the GLWE ciphertext precision over the Torus. /// * `rank`: rank of the GLWE ciphertext.@@ -71,7 +71,7 @@ let mut accumulators: Vec<Accumulator> = Vec::<Accumulator>::new();
let log_n: usize = (usize::BITS - (n - 1).leading_zeros()) as _; (0..log_n - log_batch).for_each(|_| accumulators.push(Accumulator::alloc(n, basek, k, rank))); Self { - accumulators: accumulators, + accumulators, log_batch, counter: 0, }@@ -111,7 +111,7 @@ /// #Arguments
/// /// * `module`: static backend FFT tables. /// * `res`: space to append fully packed ciphertext. Only when the number - /// of packed ciphertexts reaches N/2^log_batch is a result written. + /// of packed ciphertexts reaches N/2^log_batch is a result written. /// * `a`: ciphertext to pack. Can optionally give None to pack a 0 ciphertext. /// * `auto_keys`: a [HashMap] containing the [AutomorphismKeyExec]s. /// * `scratch`: scratch space of size at least [Self::scratch_space].@@ -329,13 +329,11 @@ let basek: usize = a.basek();
let k: usize = a.k(); let rank: usize = a.rank(); - let gal_el: i64; - - if i == 0 { - gal_el = -1; + let gal_el: i64 = if i == 0 { + -1 } else { - gal_el = module.galois_element(1 << (i - 1)) - } + module.galois_element(1 << (i - 1)) + }; let t: i64 = 1 << (log_n - i - 1);@@ -390,20 +388,18 @@ } else {
panic!("auto_key[{}] not found", gal_el); } } - } else { - if let Some(b) = b { - let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(n, basek, k, rank); - tmp_b.rotate(module, 1 << (log_n - i - 1), b); - tmp_b.rsh(module, 1); - - // a = (b* X^t - phi(b* X^t)) - if let Some(key) = auto_keys.get(&gal_el) { - a.automorphism_sub_ba(module, &tmp_b, key, scratch_1); - } else { - panic!("auto_key[{}] not found", gal_el); - } + } else if let Some(b) = b { + let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(n, basek, k, rank); + tmp_b.rotate(module, 1 << (log_n - i - 1), b); + tmp_b.rsh(module, 1); - acc.value = true; + // a = (b* X^t - phi(b* X^t)) + if let Some(key) = auto_keys.get(&gal_el) { + a.automorphism_sub_ba(module, &tmp_b, key, scratch_1); + } else { + panic!("auto_key[{}] not found", gal_el); } + + acc.value = true; } }
@@ -27,6 +27,7 @@ });
gal_els } + #[allow(clippy::too_many_arguments)] pub fn trace_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -111,12 +112,11 @@ {
(start..end).for_each(|i| { self.rsh(module, 1); - let p: i64; - if i == 0 { - p = -1; + let p: i64 = if i == 0 { + -1 } else { - p = module.galois_element(1 << (i - 1)); - } + module.galois_element(1 << (i - 1)) + }; if let Some(key) = auto_keys.get(&p) { self.automorphism_add_inplace(module, key, scratch);
@@ -12,6 +12,7 @@ prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared},
}; impl GGLWEAutomorphismKey<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn keyswitch_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -88,6 +89,7 @@ }
} impl GGLWESwitchingKey<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn keyswitch_scratch_space<B: Backend>( module: &Module<B>, n: usize,
@@ -49,6 +49,7 @@ let norm: usize = module.vec_znx_normalize_tmp_bytes(n);
tmp_dft_i + ((tmp_a + vmp) | (tmp_idft + norm)) } + #[allow(clippy::too_many_arguments)] pub fn keyswitch_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -74,6 +75,7 @@ let res_dft: usize = module.vec_znx_dft_alloc_bytes(n, rank + 1, out_size);
res_znx + ci_dft + (ks | expand_rows | res_dft) } + #[allow(clippy::too_many_arguments)] pub fn keyswitch_inplace_scratch_space<B: Backend>( module: &Module<B>, n: usize,
@@ -9,6 +9,7 @@
use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWESwitchingKeyPrepared}; impl GLWECiphertext<Vec<u8>> { + #[allow(clippy::too_many_arguments)] pub fn keyswitch_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -38,7 +39,7 @@ rank_out + 1,
ksk_size, ) + module.vec_znx_dft_alloc_bytes(n, rank_in, in_size); let normalize: usize = module.vec_znx_big_normalize_tmp_bytes(n); - return res_dft + ((ai_dft + vmp) | normalize); + res_dft + ((ai_dft + vmp) | normalize) } pub fn keyswitch_inplace_scratch_space<B: Backend>(@@ -180,7 +181,7 @@ Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
{ unsafe { let self_ptr: *mut GLWECiphertext<DataSelf> = self as *mut GLWECiphertext<DataSelf>; - self.keyswitch(&module, &*self_ptr, rhs, scratch); + self.keyswitch(module, &*self_ptr, rhs, scratch); } } }
@@ -61,7 +61,7 @@ impl<D: Data> Infos for GGLWEAutomorphismKeyCompressed<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.key.inner() + self.key.inner() } fn basek(&self) -> usize {
@@ -76,7 +76,7 @@ );
Self { data: MatZnx::alloc(n, rows, rank_in, 1, size), - basek: basek, + basek, k, rank_out, digits,
@@ -54,7 +54,7 @@ impl<D: Data> Infos for GGLWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.key.inner() + self.key.inner() } fn basek(&self) -> usize {
@@ -59,7 +59,7 @@ keys.push(GGLWESwitchingKeyCompressed::alloc(
n, basek, k, rows, digits, 1, rank, )); }); - Self { keys: keys } + Self { keys } } pub fn bytes_of(n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank: usize) -> usize {@@ -72,7 +72,7 @@ impl<D: Data> Infos for GGLWETensorKeyCompressed<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.keys[0].inner() + self.keys[0].inner() } fn basek(&self) -> usize {
@@ -76,7 +76,7 @@
Self { data: MatZnx::alloc(n, rows, rank + 1, 1, k.div_ceil(basek)), basek, - k: k, + k, digits, rank, seed: Vec::new(),@@ -123,7 +123,7 @@ GLWECiphertextCompressed {
data: self.data.at_mut(row, col), basek: self.basek, k: self.k, - rank: rank, + rank, seed: self.seed[row * (rank + 1) + col], } }
@@ -96,7 +96,7 @@ fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
self.k = reader.read_u64::<LittleEndian>()? as usize; self.basek = reader.read_u64::<LittleEndian>()? as usize; self.rank = reader.read_u64::<LittleEndian>()? as usize; - reader.read(&mut self.seed)?; + reader.read_exact(&mut self.seed)?; self.data.read_from(reader) } }
@@ -43,7 +43,7 @@ impl<D: Data> Infos for GLWEToLWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -57,8 +57,8 @@ impl LWECiphertextCompressed<Vec<u8>> {
pub fn alloc(basek: usize, k: usize) -> Self { Self { data: VecZnx::alloc(1, 1, k.div_ceil(basek)), - k: k, - basek: basek, + k, + basek, seed: [0u8; 32], } }@@ -103,7 +103,7 @@ impl<D: DataMut> ReaderFrom for LWECiphertextCompressed<D> {
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.k = reader.read_u64::<LittleEndian>()? as usize; self.basek = reader.read_u64::<LittleEndian>()? as usize; - reader.read(&mut self.seed)?; + reader.read_exact(&mut self.seed)?; self.data.read_from(reader) } }
@@ -44,7 +44,7 @@ impl<D: Data> Infos for LWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -45,7 +45,7 @@ impl<D: Data> Infos for LWEToGLWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -59,7 +59,7 @@ impl<D: Data> Infos for GGLWEAutomorphismKey<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.key.inner() + self.key.inner() } fn basek(&self) -> usize {
@@ -87,7 +87,7 @@ );
Self { data: MatZnx::alloc(n, rows, rank_in, rank_out + 1, size), - basek: basek, + basek, k, digits, }
@@ -55,7 +55,7 @@ let pairs: usize = (((rank + 1) * rank) >> 1).max(1);
(0..pairs).for_each(|_| { keys.push(GGLWESwitchingKey::alloc(n, basek, k, rows, digits, 1, rank)); }); - Self { keys: keys } + Self { keys } } pub fn bytes_of(n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank: usize) -> usize {@@ -68,7 +68,7 @@ impl<D: Data> Infos for GGLWETensorKey<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.keys[0].inner() + self.keys[0].inner() } fn basek(&self) -> usize {
@@ -88,7 +88,7 @@
Self { data: MatZnx::alloc(n, rows, rank + 1, rank + 1, k.div_ceil(basek)), basek, - k: k, + k, digits, } }
@@ -1,6 +1,6 @@
use backend::hal::{ api::{FillUniform, Reset}, - layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, VecZnxToMut, VecZnxToRef, WriterTo}, + layouts::{Data, DataMut, DataRef, ReaderFrom, ToOwnedDeep, VecZnx, VecZnxToMut, VecZnxToRef, WriterTo}, }; use sampling::source::Source;@@ -13,6 +13,17 @@ pub struct GLWECiphertext<D: Data> {
pub data: VecZnx<D>, pub basek: usize, pub k: usize, +} + +impl<D: DataRef> ToOwnedDeep for GLWECiphertext<D> { + type Owned = GLWECiphertext<Vec<u8>>; + fn to_owned_deep(&self) -> Self::Owned { + GLWECiphertext { + data: self.data.to_owned_deep(), + basek: self.basek, + k: self.k, + } + } } impl<D: DataRef> fmt::Debug for GLWECiphertext<D> {@@ -83,16 +94,6 @@
impl<D: Data> GLWECiphertext<D> { pub fn rank(&self) -> usize { self.cols() - 1 - } -} - -impl<D: DataRef> GLWECiphertext<D> { - pub fn clone(&self) -> GLWECiphertext<Vec<u8>> { - GLWECiphertext { - data: self.data.clone(), - basek: self.basek(), - k: self.k(), - } } }
@@ -15,8 +15,8 @@ impl GLWEPublicKey<Vec<u8>> {
pub fn alloc(n: usize, basek: usize, k: usize, rank: usize) -> Self { Self { data: VecZnx::alloc(n, rank + 1, k.div_ceil(basek)), - basek: basek, - k: k, + basek, + k, dist: Distribution::NONE, } }
@@ -52,7 +52,7 @@ impl GLWEPlaintext<Vec<u8>> {
pub fn alloc(n: usize, basek: usize, k: usize) -> Self { Self { data: VecZnx::alloc(n, 1, k.div_ceil(basek)), - basek: basek, + basek, k, } }
@@ -39,7 +39,7 @@ impl<D: Data> Infos for GLWEToLWESwitchingKey<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -64,8 +64,8 @@ impl LWECiphertext<Vec<u8>> {
pub fn alloc(n: usize, basek: usize, k: usize) -> Self { Self { data: VecZnx::alloc(n + 1, 1, k.div_ceil(basek)), - k: k, - basek: basek, + k, + basek, } } }
@@ -44,7 +44,7 @@ impl<D: Data> Infos for LWESwitchingKey<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -14,8 +14,8 @@ impl LWEPlaintext<Vec<u8>> {
pub fn alloc(basek: usize, k: usize) -> Self { Self { data: VecZnx::alloc(1, 1, k.div_ceil(basek)), - k: k, - basek: basek, + k, + basek, } } }
@@ -38,7 +38,7 @@ impl<D: Data> Infos for LWEToGLWESwitchingKey<D> {
type Inner = MatZnx<D>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -37,7 +37,7 @@ impl<D: Data, B: Backend> Infos for GGLWEAutomorphismKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>; fn inner(&self) -> &Self::Inner { - &self.key.inner() + self.key.inner() } fn basek(&self) -> usize {
@@ -17,6 +17,7 @@ pub(crate) digits: usize,
} impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> { + #[allow(clippy::too_many_arguments)] pub fn alloc( module: &Module<B>, n: usize,@@ -48,12 +49,13 @@ );
Self { data: module.vmp_pmat_alloc(n, rows, rank_in, rank_out + 1, size), - basek: basek, + basek, k, digits, } } + #[allow(clippy::too_many_arguments)] pub fn bytes_of( module: &Module<B>, n: usize,
@@ -16,6 +16,7 @@ pub(crate) sk_out_n: usize, // Degree of sk_out
} impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> { + #[allow(clippy::too_many_arguments)] pub fn alloc( module: &Module<B>, n: usize,@@ -36,6 +37,7 @@ sk_out_n: 0,
} } + #[allow(clippy::too_many_arguments)] pub fn bytes_of( module: &Module<B>, n: usize,
@@ -41,7 +41,7 @@ impl<D: Data, B: Backend> Infos for GGLWETensorKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>; fn inner(&self) -> &Self::Inner { - &self.keys[0].inner() + self.keys[0].inner() } fn basek(&self) -> usize {
@@ -42,7 +42,7 @@
Self { data: module.vmp_pmat_alloc(n, rows, rank + 1, rank + 1, k.div_ceil(basek)), basek, - k: k, + k, digits, } }
@@ -0,0 +1,177 @@
+use backend::hal::{ + api::{FillUniform, Reset, VecZnxCopy, VecZnxFillUniform}, + layouts::{Backend, Data, DataMut, DataRef, Module, ReaderFrom, VecZnx, WriterTo}, +}; +use sampling::source::Source; + +use crate::layouts::{GLWECiphertext, Infos, compressed::Decompress}; +use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; +use std::fmt; + +#[derive(PartialEq, Eq, Clone)] +pub struct GLWECiphertextCompressed<D: Data> { + pub(crate) data: VecZnx<D>, + pub(crate) basek: usize, + pub(crate) k: usize, + pub(crate) rank: usize, + pub(crate) seed: [u8; 32], +} + +impl<D: DataRef> fmt::Debug for GLWECiphertextCompressed<D> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self) + } +} + +impl<D: DataRef> fmt::Display for GLWECiphertextCompressed<D> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "GLWECiphertextCompressed: basek={} k={} rank={} seed={:?}: {}", + self.basek(), + self.k(), + self.rank, + self.seed, + self.data + ) + } +} + +impl<D: DataMut> Reset for GLWECiphertextCompressed<D> { + fn reset(&mut self) { + self.data.reset(); + self.basek = 0; + self.k = 0; + self.rank = 0; + self.seed = [0u8; 32]; + } +} + +impl<D: DataMut> FillUniform for GLWECiphertextCompressed<D> { + fn fill_uniform(&mut self, source: &mut Source) { + self.data.fill_uniform(source); + } +} + +impl<D: Data> Infos for GLWECiphertextCompressed<D> { + type Inner = VecZnx<D>; + + fn inner(&self) -> &Self::Inner { + &self.data + } + + fn basek(&self) -> usize { + self.basek + } + + fn k(&self) -> usize { + self.k + } +} + +impl<D: Data> GLWECiphertextCompressed<D> { + pub fn rank(&self) -> usize { + self.rank + } +} + +impl GLWECiphertextCompressed<Vec<u8>> { + pub fn alloc(n: usize, basek: usize, k: usize, rank: usize) -> Self { + Self { + data: VecZnx::alloc(n, 1, k.div_ceil(basek)), + basek, + k, + rank, + seed: [0u8; 32], + } + } + + pub fn bytes_of(n: usize, basek: usize, k: usize) -> usize { + GLWECiphertext::bytes_of(n, basek, k, 1) + } +} + +impl<D: DataMut> ReaderFrom for GLWECiphertextCompressed<D> { + fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { + self.k = reader.read_u64::<LittleEndian>()? as usize; + self.basek = reader.read_u64::<LittleEndian>()? as usize; + self.rank = reader.read_u64::<LittleEndian>()? as usize; + reader.read_exact(&mut self.seed)?; + self.data.read_from(reader) + } +} + +impl<D: DataRef> WriterTo for GLWECiphertextCompressed<D> { + fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { + writer.write_u64::<LittleEndian>(self.k as u64)?; + writer.write_u64::<LittleEndian>(self.basek as u64)?; + writer.write_u64::<LittleEndian>(self.rank as u64)?; + writer.write_all(&self.seed)?; + self.data.write_to(writer) + } +} + +impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D> { + fn decompress(&mut self, module: &Module<B>, other: &GLWECiphertextCompressed<DR>) + where + Module<B>: VecZnxCopy + VecZnxFillUniform, + { + #[cfg(debug_assertions)] + { + use backend::hal::api::ZnxInfos; + + assert_eq!( + self.n(), + other.data.n(), + "invalid receiver: self.n()={} != other.n()={}", + self.n(), + other.data.n() + ); + assert_eq!( + self.size(), + other.size(), + "invalid receiver: self.size()={} != other.size()={}", + self.size(), + other.size() + ); + assert_eq!( + self.rank(), + other.rank(), + "invalid receiver: self.rank()={} != other.rank()={}", + self.rank(), + other.rank() + ); + } + + let mut source: Source = Source::new(other.seed); + self.decompress_internal(module, other, &mut source); + } +} + +impl<D: DataMut> GLWECiphertext<D> { + pub(crate) fn decompress_internal<DataOther, B: Backend>( + &mut self, + module: &Module<B>, + other: &GLWECiphertextCompressed<DataOther>, + source: &mut Source, + ) where + DataOther: DataRef, + Module<B>: VecZnxCopy + VecZnxFillUniform, + { + #[cfg(debug_assertions)] + { + assert_eq!(self.rank(), other.rank()) + } + + let k: usize = other.k; + let basek: usize = other.basek; + let cols: usize = other.rank() + 1; + module.vec_znx_copy(&mut self.data, 0, &other.data, 0); + (1..cols).for_each(|i| { + module.vec_znx_fill_uniform(basek, &mut self.data, i, k, source); + }); + + self.basek = basek; + self.k = k; + } +}
@@ -48,8 +48,8 @@ Module<B>: VecZnxDftAlloc<B>,
{ Self { data: module.vec_znx_dft_alloc(n, rank + 1, k.div_ceil(basek)), - basek: basek, - k: k, + basek, + k, dist: Distribution::NONE, } }
@@ -15,7 +15,7 @@ impl<D: Data, B: Backend> Infos for GLWEToLWESwitchingKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -15,7 +15,7 @@ impl<D: Data, B: Backend> Infos for LWESwitchingKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -16,7 +16,7 @@ impl<D: Data, B: Backend> Infos for LWEToGLWESwitchingKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>; fn inner(&self) -> &Self::Inner { - &self.0.inner() + self.0.inner() } fn basek(&self) -> usize {
@@ -11,7 +11,7 @@
use crate::layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}; impl<D: DataRef> GGLWECiphertext<D> { - pub fn assert_noise<B: Backend, DataSk, DataWant>( + pub fn assert_noise<B, DataSk, DataWant>( self, module: &Module<B>, sk: &GLWESecretPrepared<DataSk, B>,@@ -30,7 +30,7 @@ + VecZnxBigAddSmallInplace<B>
+ VecZnxBigNormalize<B> + VecZnxNormalizeTmpBytes + VecZnxSubScalarInplace, - B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { let digits: usize = self.digits(); let basek: usize = self.basek();@@ -47,7 +47,7 @@
(0..self.rank_in()).for_each(|col_i| { (0..self.rows()).for_each(|row_i| { self.at(row_i, col_i) - .decrypt(&module, &mut pt, &sk, scratch.borrow()); + .decrypt(module, &mut pt, sk, scratch.borrow()); module.vec_znx_sub_scalar_inplace( &mut pt.data,
@@ -12,7 +12,7 @@
use crate::layouts::{GGSWCiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}; impl<D: DataRef> GGSWCiphertext<D> { - pub fn assert_noise<B: Backend, DataSk, DataScalar, F>( + pub fn assert_noise<B, DataSk, DataScalar, F>( &self, module: &Module<B>, sk_prepared: &GLWESecretPrepared<DataSk, B>,@@ -36,7 +36,7 @@ + VecZnxBigNormalizeTmpBytes
+ VecZnxDftToVecZnxBigTmpA<B> + VecZnxAddScalarInplace + VecZnxSubABInplace, - B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, F: Fn(usize) -> f64, { let basek: usize = self.basek();@@ -65,7 +65,7 @@ module.vec_znx_big_normalize(basek, &mut pt.data, 0, &pt_big, 0, scratch.borrow());
} self.at(row_i, col_j) - .decrypt(module, &mut pt_have, &sk_prepared, scratch.borrow()); + .decrypt(module, &mut pt_have, sk_prepared, scratch.borrow()); module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt.data, 0);@@ -81,7 +81,7 @@ }
} impl<D: DataRef> GGSWCiphertext<D> { - pub fn print_noise<B: Backend, DataSk, DataScalar>( + pub fn print_noise<B, DataSk, DataScalar>( &self, module: &Module<B>, sk_prepared: &GLWESecretPrepared<DataSk, B>,@@ -104,7 +104,7 @@ + VecZnxBigNormalizeTmpBytes
+ VecZnxDftToVecZnxBigTmpA<B> + VecZnxAddScalarInplace + VecZnxSubABInplace, - B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { let basek: usize = self.basek(); let k: usize = self.k();@@ -132,7 +132,7 @@ module.vec_znx_big_normalize(basek, &mut pt.data, 0, &pt_big, 0, scratch.borrow());
} self.at(row_i, col_j) - .decrypt(module, &mut pt_have, &sk_prepared, scratch.borrow()); + .decrypt(module, &mut pt_have, sk_prepared, scratch.borrow()); module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt.data, 0);
@@ -15,7 +15,7 @@ layouts::{GLWECiphertext, Infos},
}; impl<D: DataRef> GLWECiphertext<D> { - pub fn assert_noise<B: Backend, DataSk, DataPt>( + pub fn assert_noise<B, DataSk, DataPt>( &self, module: &Module<B>, sk_prepared: &GLWESecretPrepared<DataSk, B>,@@ -35,7 +35,7 @@ + VecZnxBigNormalize<B>
+ VecZnxNormalizeTmpBytes + VecZnxSubABInplace + VecZnxNormalizeInplace<B>, - B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), self.basek(), self.k());@@ -46,7 +46,7 @@ self.basek(),
self.k(), )); - self.decrypt(module, &mut pt_have, &sk_prepared, scratch.borrow()); + self.decrypt(module, &mut pt_have, sk_prepared, scratch.borrow()); module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt_want.data, 0); module.vec_znx_normalize_inplace(self.basek(), &mut pt_have.data, 0, scratch.borrow());
@@ -2,6 +2,7 @@ mod gglwe_ct;
mod ggsw_ct; mod glwe_ct; +#[allow(clippy::too_many_arguments)] #[allow(dead_code)] pub(crate) fn var_noise_gglwe_product( n: f64,@@ -33,6 +34,7 @@ noise /= b_scale * b_scale;
noise } +#[allow(clippy::too_many_arguments)] #[allow(dead_code)] pub(crate) fn log2_std_noise_gglwe_product( n: f64,@@ -62,6 +64,7 @@ noise = noise.sqrt();
noise.log2().min(-1.0).max(-(a_logq as f64)) // max noise is [-2^{-1}, 2^{-1}] } +#[allow(clippy::too_many_arguments)] #[allow(dead_code)] pub(crate) fn noise_ggsw_product( n: f64,@@ -95,6 +98,7 @@ noise /= b_scale;
noise.log2().min(-1.0) // max noise is [-2^{-1}, 2^{-1}] } +#[allow(clippy::too_many_arguments)] #[allow(dead_code)] pub(crate) fn noise_ggsw_keyswitch( n: f64,
@@ -41,6 +41,7 @@ fn take_glwe_pt(&mut self, n: usize, basek: usize, k: usize) -> (GLWEPlaintext<&mut [u8]>, &mut Self);
} pub trait TakeGGLWE { + #[allow(clippy::too_many_arguments)] fn take_gglwe( &mut self, n: usize,@@ -54,6 +55,7 @@ ) -> (GGLWECiphertext<&mut [u8]>, &mut Self);
} pub trait TakeGGLWEPrepared<B: Backend> { + #[allow(clippy::too_many_arguments)] fn take_gglwe_prepared( &mut self, n: usize,@@ -113,6 +115,7 @@ ) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self);
} pub trait TakeGLWESwitchingKey { + #[allow(clippy::too_many_arguments)] fn take_glwe_switching_key( &mut self, n: usize,@@ -126,6 +129,7 @@ ) -> (GGLWESwitchingKey<&mut [u8]>, &mut Self);
} pub trait TakeGLWESwitchingKeyPrepared<B: Backend> { + #[allow(clippy::too_many_arguments)] fn take_glwe_switching_key_prepared( &mut self, n: usize,@@ -292,8 +296,8 @@ k.div_ceil(basek),
); ( GGLWECiphertext { - data: data, - basek: basek, + data, + basek, k, digits, },@@ -353,8 +357,8 @@ k.div_ceil(basek),
); ( GGLWECiphertextPrepared { - data: data, - basek: basek, + data, + basek, k, digits, },
@@ -23,7 +23,8 @@ },
noise::log2_std_noise_gglwe_product, }; -pub fn test_gglwe_automorphism_key_automorphism<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_gglwe_automorphism_key_automorphism<B>( module: &Module<B>, p0: i64, p1: i64,@@ -65,7 +66,8 @@ + VecZnxSwithcDegree
+ SvpPPolAlloc<B> + VecZnxBigAddInplace<B> + VecZnxSubScalarInplace, - B: ScratchOwnedAllocImpl<B> + B: Backend + + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B> + ScratchAvailableImpl<B> + TakeScalarZnxImpl<B>@@ -186,7 +188,8 @@ });
}); } -pub fn test_gglwe_automorphism_key_automorphism_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_gglwe_automorphism_key_automorphism_inplace<B>( module: &Module<B>, p0: i64, p1: i64,@@ -241,7 +244,8 @@ + VecZnxSubScalarInplace
+ VecZnxCopy + VmpPMatAlloc<B> + VmpPrepare<B>, - B: ScratchOwnedAllocImpl<B> + B: Backend + + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B> + ScratchAvailableImpl<B> + TakeScalarZnxImpl<B>
@@ -24,7 +24,8 @@ },
noise::noise_ggsw_keyswitch, }; -pub fn test_ggsw_automorphism<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_ggsw_automorphism<B>( p: i64, module: &Module<B>, basek: usize,@@ -72,7 +73,8 @@ + SvpApply<B>
+ VecZnxSwithcDegree + VecZnxAutomorphismInplace + VecZnxAutomorphism, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -178,10 +180,11 @@ k_tsk,
) + 0.5 }; - ct_out.assert_noise(module, &sk_prepared, &pt_scalar, &max_noise); + ct_out.assert_noise(module, &sk_prepared, &pt_scalar, max_noise); } -pub fn test_ggsw_automorphism_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_ggsw_automorphism_inplace<B>( p: i64, module: &Module<B>, basek: usize,@@ -229,7 +232,8 @@ + SvpApply<B>
+ VecZnxSwithcDegree + VecZnxAutomorphismInplace + VecZnxAutomorphism, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -325,5 +329,5 @@ k_tsk,
) + 0.5 }; - ct.assert_noise(module, &sk_prepared, &pt_scalar, &max_noise); + ct.assert_noise(module, &sk_prepared, &pt_scalar, max_noise); }
@@ -23,7 +23,8 @@ },
noise::log2_std_noise_gglwe_product, }; -pub fn test_glwe_automorphism<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_glwe_automorphism<B>( module: &Module<B>, basek: usize, p: i64,@@ -63,7 +64,8 @@ + VecZnxAddScalarInplace
+ VecZnxAutomorphismInplace + VmpPMatAlloc<B> + VmpPrepare<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -150,7 +152,8 @@
ct_out.assert_noise(module, &sk_prepared, &pt_want, max_noise + 1.0); } -pub fn test_glwe_automorphism_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_glwe_automorphism_inplace<B>( module: &Module<B>, basek: usize, p: i64,@@ -189,7 +192,8 @@ + VecZnxAddScalarInplace
+ VecZnxAutomorphismInplace + VmpPMatAlloc<B> + VmpPrepare<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -21,7 +21,7 @@ LWEToGLWESwitchingKey,
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc}, }; -pub fn test_lwe_to_glwe<B: Backend>(module: &Module<B>) +pub fn test_lwe_to_glwe<B>(module: &Module<B>) where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B>@@ -51,7 +51,8 @@ + VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxAutomorphismInplace, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -131,7 +132,7 @@
assert_eq!(glwe_pt.data.at(0, 0)[0], lwe_pt.data.at(0, 0)[0]); } -pub fn test_glwe_to_lwe<B: Backend>(module: &Module<B>) +pub fn test_glwe_to_lwe<B>(module: &Module<B>) where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B>@@ -161,7 +162,8 @@ + VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxAutomorphismInplace, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -21,7 +21,7 @@ compressed::{Decompress, GGLWEAutomorphismKeyCompressed},
prepared::{GLWESecretPrepared, PrepareAlloc}, }; -pub fn test_gglwe_automorphisk_key_encrypt_sk<B: Backend>( +pub fn test_gglwe_automorphisk_key_encrypt_sk<B>( module: &Module<B>, basek: usize, k_ksk: usize,@@ -60,7 +60,8 @@ + VecZnxSubScalarInplace
+ VecZnxCopy + VmpPMatAlloc<B> + VmpPrepare<B>, - B: ScratchOwnedAllocImpl<B> + B: Backend + + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B> + ScratchAvailableImpl<B> + TakeScalarZnxImpl<B>@@ -114,7 +115,7 @@ .key
.assert_noise(module, &sk_out_prepared, &sk.data, sigma); } -pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B: Backend>( +pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>( module: &Module<B>, basek: usize, k_ksk: usize,@@ -153,7 +154,8 @@ + VecZnxSubScalarInplace
+ VecZnxCopy + VmpPMatAlloc<B> + VmpPrepare<B>, - B: ScratchOwnedAllocImpl<B> + B: Backend + + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B> + ScratchAvailableImpl<B> + TakeScalarZnxImpl<B>
@@ -20,7 +20,7 @@ compressed::{Decompress, GGLWESwitchingKeyCompressed},
prepared::{GLWESecretPrepared, PrepareAlloc}, }; -pub fn test_gglwe_switching_key_encrypt_sk<B: Backend>( +pub fn test_gglwe_switching_key_encrypt_sk<B>( module: &Module<B>, basek: usize, k_ksk: usize,@@ -54,7 +54,8 @@ + VecZnxSubScalarInplace
+ VecZnxCopy + VmpPMatAlloc<B> + VmpPrepare<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -99,7 +100,7 @@ ksk.key
.assert_noise(module, &sk_out_prepared, &sk_in.data, sigma); } -pub fn test_gglwe_switching_key_compressed_encrypt_sk<B: Backend>( +pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>( module: &Module<B>, basek: usize, k_ksk: usize,@@ -133,7 +134,8 @@ + VecZnxSubScalarInplace
+ VecZnxCopy + VmpPMatAlloc<B> + VmpPrepare<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>
@@ -20,7 +20,7 @@ compressed::{Decompress, GGSWCiphertextCompressed},
prepared::{GLWESecretPrepared, PrepareAlloc}, }; -pub fn test_ggsw_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64) +pub fn test_ggsw_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64) where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B>@@ -49,7 +49,8 @@ + VecZnxBigAlloc<B>
+ VecZnxDftAlloc<B> + VecZnxBigNormalizeTmpBytes + VecZnxDftToVecZnxBigTmpA<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -94,17 +95,11 @@ );
let noise_f = |_col_i: usize| -(k as f64) + sigma.log2() + 0.5; - ct.assert_noise(module, &sk_prepared, &pt_scalar, &noise_f); + ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f); } -pub fn test_ggsw_compressed_encrypt_sk<B: Backend>( - module: &Module<B>, - basek: usize, - k: usize, - digits: usize, - rank: usize, - sigma: f64, -) where +pub fn test_ggsw_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64) +where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B> + VecZnxDftFromVecZnx<B>@@ -132,7 +127,8 @@ + VecZnxBigAlloc<B>
+ VecZnxDftAlloc<B> + VecZnxBigNormalizeTmpBytes + VecZnxDftToVecZnxBigTmpA<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -180,5 +176,5 @@
let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(n, basek, k, rows, digits, rank); ct.decompress(module, &ct_compressed); - ct.assert_noise(module, &sk_prepared, &pt_scalar, &noise_f); + ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f); }
@@ -23,7 +23,7 @@ },
operations::GLWEOperations, }; -pub fn test_glwe_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize) +pub fn test_glwe_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize) where Module<B>: VecZnxDftAllocBytes + VecZnxBigAllocBytes@@ -60,7 +60,8 @@ + VecZnxNormalizeInplace<B>
+ VecZnxAddNormal + VecZnxNormalize<B> + VecZnxSub, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -109,14 +110,8 @@
assert!(noise_have <= noise_want + 0.2); } -pub fn test_glwe_compressed_encrypt_sk<B: Backend>( - module: &Module<B>, - basek: usize, - k_ct: usize, - k_pt: usize, - sigma: f64, - rank: usize, -) where +pub fn test_glwe_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize) +where Module<B>: VecZnxDftAllocBytes + VecZnxBigAllocBytes + VecZnxDftFromVecZnx<B>@@ -153,7 +148,8 @@ + VecZnxAddNormal
+ VecZnxNormalize<B> + VecZnxSub + VecZnxCopy, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -213,7 +209,7 @@ noise_want + 0.2
); } -pub fn test_glwe_encrypt_zero_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, sigma: f64, rank: usize) +pub fn test_glwe_encrypt_zero_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, sigma: f64, rank: usize) where Module<B>: VecZnxDftAllocBytes + VecZnxBigAllocBytes@@ -250,7 +246,8 @@ + VecZnxNormalizeInplace<B>
+ VecZnxAddNormal + VecZnxNormalize<B> + VecZnxSub, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -290,7 +287,7 @@
assert!((sigma - pt.data.std(basek, 0) * (k_ct as f64).exp2()) <= 0.2); } -pub fn test_glwe_encrypt_pk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize) +pub fn test_glwe_encrypt_pk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize) where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B>@@ -315,7 +312,8 @@ + VecZnxCopy
+ VecZnxDftAlloc<B> + SvpApply<B> + VecZnxBigAddNormal<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -20,7 +20,7 @@ compressed::{Decompress, GGLWETensorKeyCompressed},
prepared::{GLWESecretPrepared, PrepareAlloc}, }; -pub fn test_glwe_tensor_key_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize) +pub fn test_glwe_tensor_key_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize) where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B>@@ -49,7 +49,8 @@ + VecZnxDftToVecZnxBigTmpA<B>
+ VecZnxAddScalarInplace + VecZnxSwithcDegree + VecZnxSubScalarInplace, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -130,7 +131,7 @@ })
}) } -pub fn test_glwe_tensor_key_compressed_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize) +pub fn test_glwe_tensor_key_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize) where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B>@@ -159,7 +160,8 @@ + VecZnxDftToVecZnxBigTmpA<B>
+ VecZnxAddScalarInplace + VecZnxSwithcDegree + VecZnxSubScalarInplace, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>
@@ -23,7 +23,8 @@ },
noise::noise_ggsw_product, }; -pub fn test_gglwe_switching_key_external_product<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_gglwe_switching_key_external_product<B>( module: &Module<B>, basek: usize, k_out: usize,@@ -63,7 +64,8 @@ + VmpApplyTmpBytes
+ VmpApply<B> + VmpApplyAdd<B> + VmpPrepare<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -165,7 +167,8 @@ .key
.assert_noise(module, &sk_out_prepared, &sk_in.data, max_noise + 0.5); } -pub fn test_gglwe_switching_key_external_product_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_gglwe_switching_key_external_product_inplace<B>( module: &Module<B>, basek: usize, k_ct: usize,@@ -204,7 +207,8 @@ + VmpApplyTmpBytes
+ VmpApply<B> + VmpApplyAdd<B> + VmpPrepare<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>
@@ -23,7 +23,8 @@ },
noise::noise_ggsw_product, }; -pub fn test_ggsw_external_product<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_ggsw_external_product<B>( module: &Module<B>, basek: usize, k_in: usize,@@ -64,7 +65,8 @@ + VecZnxBigAlloc<B>
+ VecZnxDftAlloc<B> + VecZnxBigNormalizeTmpBytes + VecZnxDftToVecZnxBigTmpA<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -154,10 +156,11 @@ k_ggsw,
) + 0.5 }; - ct_ggsw_lhs_out.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, &max_noise); + ct_ggsw_lhs_out.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, max_noise); } -pub fn test_ggsw_external_product_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_ggsw_external_product_inplace<B>( module: &Module<B>, basek: usize, k_ct: usize,@@ -197,7 +200,8 @@ + VecZnxBigAlloc<B>
+ VecZnxDftAlloc<B> + VecZnxBigNormalizeTmpBytes + VecZnxDftToVecZnxBigTmpA<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -287,5 +291,5 @@ k_ggsw,
) + 0.5 }; - ct_ggsw_lhs.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, &max_noise); + ct_ggsw_lhs.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, max_noise); }
@@ -22,7 +22,8 @@ },
noise::noise_ggsw_product, }; -pub fn test_glwe_external_product<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_glwe_external_product<B>( module: &Module<B>, basek: usize, k_out: usize,@@ -58,7 +59,8 @@ + VmpPrepare<B>
+ VmpApplyTmpBytes + VmpApply<B> + VmpApplyAdd<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -158,7 +160,8 @@
ct_glwe_out.assert_noise(module, &sk_prepared, &pt_want, max_noise + 0.5); } -pub fn test_glwe_external_product_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_glwe_external_product_inplace<B>( module: &Module<B>, basek: usize, k_ct: usize,@@ -193,7 +196,8 @@ + VmpPrepare<B>
+ VmpApplyTmpBytes + VmpApply<B> + VmpApplyAdd<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -22,7 +22,8 @@ },
noise::log2_std_noise_gglwe_product, }; -pub fn test_gglwe_switching_key_keyswitch<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_gglwe_switching_key_keyswitch<B>( module: &Module<B>, basek: usize, k_out: usize,@@ -62,7 +63,8 @@ + VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxSubScalarInplace, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -174,7 +176,8 @@ .key
.assert_noise(module, &sk2_prepared, &sk0.data, max_noise + 0.5); } -pub fn test_gglwe_switching_key_keyswitch_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_gglwe_switching_key_keyswitch_inplace<B>( module: &Module<B>, basek: usize, k_ct: usize,@@ -212,7 +215,8 @@ + VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxSubScalarInplace, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -23,7 +23,8 @@ },
noise::noise_ggsw_keyswitch, }; -pub fn test_ggsw_keyswitch<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_ggsw_keyswitch<B>( module: &Module<B>, basek: usize, k_out: usize,@@ -67,7 +68,8 @@ + VecZnxDftCopy<B>
+ VecZnxDftAddInplace<B> + VecZnxBigAlloc<B> + VecZnxDftAlloc<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -167,10 +169,11 @@ k_tsk,
) + 0.5 }; - ct_out.assert_noise(module, &sk_out_prepared, &pt_scalar, &max_noise); + ct_out.assert_noise(module, &sk_out_prepared, &pt_scalar, max_noise); } -pub fn test_ggsw_keyswitch_inplace<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_ggsw_keyswitch_inplace<B>( module: &Module<B>, basek: usize, k_ct: usize,@@ -213,7 +216,8 @@ + VecZnxDftCopy<B>
+ VecZnxDftAddInplace<B> + VecZnxBigAlloc<B> + VecZnxDftAlloc<B>, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -304,5 +308,5 @@ k_tsk,
) + 0.5 }; - ct.assert_noise(module, &sk_out_prepared, &pt_scalar, &max_noise); + ct.assert_noise(module, &sk_out_prepared, &pt_scalar, max_noise); }
@@ -22,7 +22,8 @@ },
noise::log2_std_noise_gglwe_product, }; -pub fn test_glwe_keyswitch<B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn test_glwe_keyswitch<B>( module: &Module<B>, basek: usize, k_out: usize,@@ -60,7 +61,8 @@ + VmpApply<B>
+ VmpApplyAdd<B> + VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -147,7 +149,7 @@
ct_out.assert_noise(module, &sk_out_prepared, &pt_want, max_noise + 0.5); } -pub fn test_glwe_keyswitch_inplace<B: Backend>( +pub fn test_glwe_keyswitch_inplace<B>( module: &Module<B>, basek: usize, k_ct: usize,@@ -183,7 +185,8 @@ + VmpApply<B>
+ VmpApplyAdd<B> + VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -20,7 +20,7 @@ Infos, LWECiphertext, LWEPlaintext, LWESecret, LWESwitchingKey,
prepared::{LWESwitchingKeyPrepared, PrepareAlloc}, }; -pub fn test_lwe_keyswitch<B: Backend>(module: &Module<B>) +pub fn test_lwe_keyswitch<B>(module: &Module<B>) where Module<B>: VecZnxDftAllocBytes + VecZnxBigNormalize<B>@@ -50,7 +50,8 @@ + VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxAutomorphismInplace, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -26,7 +26,7 @@ prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
}, }; -pub fn test_glwe_packing<B: Backend>(module: &Module<B>) +pub fn test_glwe_packing<B>(module: &Module<B>) where Module<B>: VecZnxDftAllocBytes + VecZnxAutomorphism@@ -64,7 +64,8 @@ + VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree + VecZnxAutomorphismInplace + VecZnxCopy, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>@@ -155,7 +156,7 @@ );
pt.rotate_inplace(module, -(1 << log_batch)); // X^-batch * pt - if reverse_bits_msb(i, log_n as u32) % 5 == 0 { + if reverse_bits_msb(i, log_n as u32).is_multiple_of(5) { packer.add(module, Some(&ct), &auto_keys, scratch.borrow()); } else { packer.add(@@ -173,7 +174,7 @@
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_ct); let mut data: Vec<i64> = vec![0i64; n]; data.iter_mut().enumerate().for_each(|(i, x)| { - if i % 5 == 0 { + if i.is_multiple_of(5) { *x = reverse_bits_msb(i, log_n as u32) as i64; } });
@@ -26,7 +26,7 @@ },
noise::var_noise_gglwe_product, }; -pub fn test_glwe_trace_inplace<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize) +pub fn test_glwe_trace_inplace<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize) where Module<B>: VecZnxDftAllocBytes + VecZnxAutomorphism@@ -61,7 +61,8 @@ + VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxCopy, - B: TakeVecZnxDftImpl<B> + B: Backend + + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + TakeSvpPPolImpl<B> + ScratchOwnedAllocImpl<B>
@@ -2,6 +2,12 @@ [package]
name = "poulpy" version = "0.1.0" edition = "2024" +description = "An efficient & modular FHE library using bivariate polynomial representation" +licence = "Apache 2.0" +readme = "README.md" +repository = "https://github.com/phantomzone-org/poulpy" +homepage = "https://github.com/phantomzone-org/poulpy" +documentation = "https://docs.rs/poulpy" [dependencies] backend = {path="../backend"}
@@ -20,6 +20,7 @@ use crate::tfhe::blind_rotation::{
BlincRotationExecute, BlindRotationKeyPrepared, CGGI, LookUpTable, LookUpTableRotationDirection, }; +#[allow(clippy::too_many_arguments)] pub fn cggi_blind_rotate_scratch_space<B: Backend>( module: &Module<B>, n: usize,@@ -49,20 +50,17 @@ let vmp_res: usize = module.vec_znx_dft_alloc_bytes(n, cols, brk_size) * extension_factor;
let vmp_xai: usize = module.vec_znx_dft_alloc_bytes(n, 1, brk_size); let acc_dft_add: usize = vmp_res; let vmp: usize = module.vmp_apply_tmp_bytes(n, brk_size, rows, rows, 2, 2, brk_size); // GGSW product: (1 x 2) x (2 x 2) - - let acc: usize; - if extension_factor > 1 { - acc = VecZnx::alloc_bytes(n, cols, k_res.div_ceil(basek)) * extension_factor; + let acc: usize = if extension_factor > 1 { + VecZnx::alloc_bytes(n, cols, k_res.div_ceil(basek)) * extension_factor } else { - acc = 0; - } + 0 + }; - return acc - + acc_dft + acc + acc_dft + acc_dft_add + vmp_res + vmp_xai - + (vmp | (acc_big + (module.vec_znx_big_normalize_tmp_bytes(n) | module.vec_znx_dft_to_vec_znx_big_tmp_bytes(n)))); + + (vmp | (acc_big + (module.vec_znx_big_normalize_tmp_bytes(n) | module.vec_znx_dft_to_vec_znx_big_tmp_bytes(n)))) } else { GLWECiphertext::bytes_of(n, basek, k_res, rank) + GLWECiphertext::external_product_scratch_space(module, n, basek, k_res, k_res, k_brk, 1, rank)@@ -520,7 +518,7 @@ let basek: usize = lwe.basek();
let log2n: usize = usize::BITS as usize - (n - 1).leading_zeros() as usize + 1; - res.copy_from_slice(&lwe.data().at(0, 0)); + res.copy_from_slice(lwe.data().at(0, 0)); match rot_dir { LookUpTableRotationDirection::Left => {
@@ -149,6 +149,7 @@ }
} impl<D: DataMut> BlindRotationKeyCompressed<D, CGGI> { + #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSkGLWE, DataSkLWE, B: Backend>( &mut self, module: &Module<B>,
@@ -20,6 +20,7 @@ fn alloc(n_gglwe: usize, n_lwe: usize, basek: usize, k: usize, rows: usize, rank: usize) -> Self;
} pub trait BlindRotationKeyEncryptSk<B: Backend> { + #[allow(clippy::too_many_arguments)] fn encrypt_sk<DataSkGLWE, DataSkLWE>( &mut self, module: &Module<B>,
@@ -108,18 +108,15 @@ });
self.dist = other.dist; - match other.dist { - Distribution::BinaryBlock(_) => { - let mut x_pow_a: Vec<SvpPPol<Vec<u8>, B>> = Vec::with_capacity(n << 1); - let mut buf: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); - (0..n << 1).for_each(|i| { - let mut res: SvpPPol<Vec<u8>, B> = module.svp_ppol_alloc(n, 1); - set_xai_plus_y(module, i, 0, &mut res, &mut buf); - x_pow_a.push(res); - }); - self.x_pow_a = Some(x_pow_a); - } - _ => {} + if let Distribution::BinaryBlock(_) = other.dist { + let mut x_pow_a: Vec<SvpPPol<Vec<u8>, B>> = Vec::with_capacity(n << 1); + let mut buf: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); + (0..n << 1).for_each(|i| { + let mut res: SvpPPol<Vec<u8>, B> = module.svp_ppol_alloc(n, 1); + set_xai_plus_y(module, i, 0, &mut res, &mut buf); + x_pow_a.push(res); + }); + self.x_pow_a = Some(x_pow_a); } } }
@@ -69,10 +69,10 @@ pub fn set_rotation_direction(&mut self, rot_dir: LookUpTableRotationDirection) {
self.rot_dir = rot_dir } - pub fn set<B: Backend>(&mut self, module: &Module<B>, f: &Vec<i64>, k: usize) + pub fn set<B>(&mut self, module: &Module<B>, f: &[i64], k: usize) where Module<B>: VecZnxRotateInplace + VecZnxNormalizeInplace<B> + VecZnxNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxCopy, - B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { assert!(f.len() <= module.n());@@ -93,7 +93,7 @@ }
// Scaling factor let mut scale = 1; - if k % basek != 0 { + if !k.is_multiple_of(basek) { scale <<= basek - (k % basek); }@@ -168,7 +168,7 @@ (extension_factor - k_lo..extension_factor).for_each(|i| {
module.vec_znx_rotate_inplace(k_hi as i64 + 1, &mut self.data[i], 0); }); - self.data.rotate_right(k_lo as usize); + self.data.rotate_right(k_lo); } }
@@ -26,7 +26,7 @@ GLWECiphertext, GLWEPlaintext, GLWESecret, Infos, LWECiphertext, LWECiphertextToRef, LWEPlaintext, LWESecret,
prepared::{GLWESecretPrepared, PrepareAlloc}, }; -pub fn test_blind_rotation<B: Backend>(module: &Module<B>, n_lwe: usize, block_size: usize, extension_factor: usize) +pub fn test_blind_rotation<B>(module: &Module<B>, n_lwe: usize, block_size: usize, extension_factor: usize) where Module<B>: VecZnxBigAllocBytes + VecZnxDftAllocBytes@@ -66,7 +66,8 @@ + VmpPMatAlloc<B>
+ VmpPrepare<B> + VmpApply<B> + VmpApplyAdd<B>, - B: VecZnxDftAllocBytesImpl<B> + B: Backend + + VecZnxDftAllocBytesImpl<B> + VecZnxBigAllocBytesImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>@@ -82,7 +83,7 @@ let basek: usize = 19;
let k_lwe: usize = 24; let k_brk: usize = 3 * basek; let rows_brk: usize = 2; // Ensures first limb is noise-free. - let k_lut: usize = 1 * basek; + let k_lut: usize = basek; let k_res: usize = 2 * basek; let rank: usize = 1;
@@ -8,10 +8,10 @@ };
use crate::tfhe::blind_rotation::{DivRound, LookUpTable}; -pub fn test_lut_standard<B: Backend>(module: &Module<B>) +pub fn test_lut_standard<B>(module: &Module<B>) where Module<B>: VecZnxRotateInplace + VecZnxNormalizeInplace<B> + VecZnxNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxCopy, - B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { let n: usize = module.n(); let basek: usize = 20;@@ -44,10 +44,10 @@ });
}); } -pub fn test_lut_extended<B: Backend>(module: &Module<B>) +pub fn test_lut_extended<B>(module: &Module<B>) where Module<B>: VecZnxRotateInplace + VecZnxNormalizeInplace<B> + VecZnxNormalizeTmpBytes + VecZnxSwithcDegree + VecZnxCopy, - B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, { let n: usize = module.n(); let basek: usize = 20;@@ -63,10 +63,10 @@ .enumerate()
.for_each(|(i, x)| *x = (i as i64) - 8); let mut lut: LookUpTable = LookUpTable::alloc(n, basek, k_lut, extension_factor); - lut.set(&module, &f, log_scale); + lut.set(module, &f, log_scale); let half_step: i64 = lut.domain_size().div_round(message_modulus << 1) as i64; - lut.rotate(&module, half_step); + lut.rotate(module, half_step); let step: usize = module.n().div_round(message_modulus);
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, usize}; +use std::collections::HashMap; use backend::hal::{ api::{@@ -9,7 +9,7 @@ VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA,
VecZnxNegateInplace, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, }, - layouts::{Backend, DataMut, DataRef, Module, Scratch}, + layouts::{Backend, DataMut, DataRef, Module, Scratch, ToOwnedDeep}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl}, };@@ -24,7 +24,7 @@ },
circuit_bootstrapping::{CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute}, }; -impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CirtuitBootstrappingExecute<B> for CircuitBootstrappingKeyPrepared<D, BRA, B> +impl<D: DataRef, BRA: BlindRotationAlgo, B> CirtuitBootstrappingExecute<B> for CircuitBootstrappingKeyPrepared<D, BRA, B> where Module<B>: VecZnxRotateInplace + VecZnxNormalizeInplace<B>@@ -53,7 +53,7 @@ + VecZnxBigSubSmallBInplace<B>
+ VecZnxBigAllocBytes + VecZnxDftAddInplace<B> + VecZnxRotate, - B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, Scratch<B>: TakeVecZnx + TakeVecZnxDftSlice<B> + TakeVecZnxBig<B>@@ -109,7 +109,8 @@ );
} } -pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B: Backend>( +#[allow(clippy::too_many_arguments)] +pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>( to_exponent: bool, module: &Module<B>, log_gap_out: usize,@@ -150,7 +151,7 @@ + VecZnxBigSubSmallBInplace<B>
+ VecZnxBigAllocBytes + VecZnxDftAddInplace<B> + VecZnxRotate, - B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, + B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>, Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxBig<B> + TakeVecZnxDft<B>@@ -201,7 +202,7 @@ // TODO: separate GGSW k from output of blind rotation k
let (mut res_glwe, scratch1) = scratch.take_glwe_ct(n, basek, k, rank); let (mut tmp_gglwe, scratch2) = scratch1.take_gglwe(n, basek, k, rows, 1, rank.max(1), rank); - key.brk.execute(module, &mut res_glwe, &lwe, &lut, scratch2); + key.brk.execute(module, &mut res_glwe, lwe, &lut, scratch2); let gap: usize = 2 * lut.drift / lut.extension_factor();@@ -235,6 +236,7 @@ // Expands GGLWE to GGSW using GGLWE(s^2)
res.from_gglwe(module, &tmp_gglwe, &key.tsk, scratch2); } +#[allow(clippy::too_many_arguments)] fn post_process<DataRes, DataA, B: Backend>( module: &Module<B>, res: &mut GLWECiphertext<DataRes>,@@ -282,9 +284,9 @@ // First partial trace, vanishes all coefficients which are not multiples of gap_in
// [1, 1, 1, 1, 0, 0, 0, ..., 0, 0, -1, -1, -1, -1] -> [1, 0, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0, 0] res.trace( module, - module.log_n() - log_gap_in as usize + 1, + module.log_n() - log_gap_in + 1, log_n, - &a, + a, auto_keys, scratch, );@@ -297,7 +299,7 @@ (0..steps).for_each(|i| {
if i != 0 { res.rotate_inplace(module, -(1 << log_gap_in)); } - cts.insert(i as usize * (1 << log_gap_out), res.clone()); + cts.insert(i as usize * (1 << log_gap_out), res.to_owned_deep()); }); pack(module, &mut cts, log_gap_out, auto_keys, scratch); let packed: GLWECiphertext<Vec<u8>> = cts.remove(&0).unwrap();@@ -353,14 +355,13 @@ let k: usize = cts.get(&0).unwrap().k();
let rank: usize = cts.get(&0).unwrap().rank(); (0..log_n - log_gap_out).for_each(|i| { - let t = 16.min(1 << (log_n - 1 - i)); + let t: usize = 16.min(1 << (log_n - 1 - i)); - let auto_key: &GGLWEAutomorphismKeyPrepared<Vec<u8>, B>; - if i == 0 { - auto_key = auto_keys.get(&-1).unwrap() + let auto_key: &GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = if i == 0 { + auto_keys.get(&-1).unwrap() } else { - auto_key = auto_keys.get(&module.galois_element(1 << (i - 1))).unwrap(); - } + auto_keys.get(&module.galois_element(1 << (i - 1))).unwrap() + }; (0..t).for_each(|j| { let mut a: Option<GLWECiphertext<D>> = cts.remove(&j);@@ -387,6 +388,7 @@ });
}); } +#[allow(clippy::too_many_arguments)] fn combine<A: DataMut, D: DataMut, DataAK: DataRef, B: Backend>( module: &Module<B>, basek: usize,@@ -472,18 +474,16 @@ a.rsh(module, 1);
// a = a + phi(a) a.automorphism_add_inplace(module, auto_key, scratch); } - } else { - if let Some(b) = b { - let n: usize = b.n(); - let log_n: usize = (u64::BITS - (n - 1).leading_zeros()) as _; - let t: i64 = 1 << (log_n - i - 1); + } else if let Some(b) = b { + let n: usize = b.n(); + let log_n: usize = (u64::BITS - (n - 1).leading_zeros()) as _; + let t: i64 = 1 << (log_n - i - 1); - let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(n, basek, k, rank); - tmp_b.rotate(module, t, b); - tmp_b.rsh(module, 1); + let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(n, basek, k, rank); + tmp_b.rotate(module, t, b); + tmp_b.rsh(module, 1); - // a = (b* X^t - phi(b* X^t)) - b.automorphism_sub_ba(module, &tmp_b, auto_key, scratch_1); - } + // a = (b* X^t - phi(b* X^t)) + b.automorphism_sub_ba(module, &tmp_b, auto_key, scratch_1); } }
@@ -2,7 +2,7 @@ use core::layouts::{
GGLWEAutomorphismKey, GGLWETensorKey, GLWECiphertext, GLWESecret, LWESecret, prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }; -use std::{collections::HashMap, usize}; +use std::collections::HashMap; use backend::hal::{ api::{@@ -21,6 +21,7 @@ BlindRotationAlgo, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared,
}; pub trait CircuitBootstrappingKeyEncryptSk<B: Backend> { + #[allow(clippy::too_many_arguments)] fn encrypt_sk<DLwe, DGlwe>( module: &Module<B>, basek: usize,@@ -96,12 +97,12 @@ DGlwe: DataRef,
Module<B>:, { let mut auto_keys: HashMap<i64, GGLWEAutomorphismKey<Vec<u8>>> = HashMap::new(); - let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(&module); + let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(module); gal_els.iter().for_each(|gal_el| { let mut key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(sk_glwe.n(), basek, k_trace, rows_trace, 1, sk_glwe.rank()); key.encrypt_sk( - &module, *gal_el, &sk_glwe, source_xa, source_xe, sigma, scratch, + module, *gal_el, sk_glwe, source_xa, source_xe, sigma, scratch, ); auto_keys.insert(*gal_el, key); });@@ -128,7 +129,7 @@ scratch,
); let mut tsk: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(sk_glwe.n(), basek, k_tsk, rows_tsk, 1, sk_glwe.rank()); - tsk.encrypt_sk(module, &sk_glwe, source_xa, source_xe, sigma, scratch); + tsk.encrypt_sk(module, sk_glwe, source_xa, source_xe, sigma, scratch); Self { brk,
@@ -1,8 +1,8 @@
-mod circuit_bootstrapping; +mod circuit; mod key; pub mod tests; -pub use circuit_bootstrapping::*; +pub use circuit::*; pub use key::*; use core::layouts::{GGSWCiphertext, LWECiphertext};@@ -20,6 +20,7 @@ extension_factor: usize,
scratch: &mut Scratch<B>, ); + #[allow(clippy::too_many_arguments)] fn execute_to_exponent<DM: DataMut, DR: DataRef>( &self, module: &Module<B>,
@@ -36,7 +36,7 @@ GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret,
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared}, }; -pub fn test_circuit_bootstrapping_to_exponent<B: Backend, BRA: BlindRotationAlgo>(module: &Module<B>) +pub fn test_circuit_bootstrapping_to_exponent<B, BRA: BlindRotationAlgo>(module: &Module<B>) where Module<B>: VecZnxFillUniform + VecZnxAddNormal@@ -81,7 +81,8 @@ + VecZnxBigSubSmallBInplace<B>
+ VecZnxBigAllocBytes + VecZnxDftAddInplace<B> + VecZnxRotate, - B: ScratchOwnedAllocImpl<B> + B: Backend + + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B> + TakeVecZnxDftImpl<B> + ScratchAvailableImpl<B>@@ -223,7 +224,7 @@ pt_want[data as usize * (1 << log_gap_out)] = pt_glwe.data.at(0, 0)[0];
assert_eq!(pt_res.data.at(0, 0), pt_want); } -pub fn test_circuit_bootstrapping_to_constant<B: Backend, BRA: BlindRotationAlgo>(module: &Module<B>) +pub fn test_circuit_bootstrapping_to_constant<B, BRA: BlindRotationAlgo>(module: &Module<B>) where Module<B>: VecZnxFillUniform + VecZnxAddNormal@@ -268,7 +269,8 @@ + VecZnxBigSubSmallBInplace<B>
+ VecZnxBigAllocBytes + VecZnxDftAddInplace<B> + VecZnxRotate, - B: ScratchOwnedAllocImpl<B> + B: Backend + + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B> + TakeVecZnxDftImpl<B> + ScratchAvailableImpl<B>