mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
Some traits updates + added missing tests for products on RGSWCt
This commit is contained in:
150
core/src/elem.rs
150
core/src/elem.rs
@@ -66,92 +66,88 @@ pub trait SetRow<B: Backend> {
|
|||||||
VecZnxDft<A, B>: VecZnxDftToRef<B>;
|
VecZnxDft<A, B>: VecZnxDftToRef<B>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ProdByScratchSpace {
|
pub trait ProdInplaceScratchSpace {
|
||||||
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize;
|
fn prod_by_grlwe_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize;
|
||||||
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize;
|
fn prod_by_rgsw_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ProdBy<D> {
|
pub trait ProdInplace<MUT, REF>
|
||||||
fn prod_by_grlwe<R>(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<R, FFT64>, scratch: &mut Scratch)
|
|
||||||
where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>;
|
|
||||||
|
|
||||||
fn prod_by_rgsw<R>(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<R, FFT64>, scratch: &mut Scratch)
|
|
||||||
where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FromProdByScratchSpace {
|
|
||||||
fn from_prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize;
|
|
||||||
fn from_prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FromProdBy<D, L> {
|
|
||||||
fn from_prod_by_grlwe<R>(&mut self, module: &Module<FFT64>, lhs: &L, rhs: &GRLWECt<R, FFT64>, scratch: &mut Scratch)
|
|
||||||
where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>;
|
|
||||||
|
|
||||||
fn from_prod_by_rgsw<R>(&mut self, module: &Module<FFT64>, lhs: &L, rhs: &RGSWCt<R, FFT64>, scratch: &mut Scratch)
|
|
||||||
where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) trait MatZnxDftProducts<D, C>: Infos
|
|
||||||
where
|
where
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64> + ZnxInfos,
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn mul_rlwe<R, A>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, a: &RLWECt<A>, scratch: &mut Scratch)
|
fn prod_by_grlwe_inplace(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch);
|
||||||
where
|
fn prod_by_rgsw_inplace(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch);
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64>,
|
}
|
||||||
VecZnx<R>: VecZnxToMut,
|
|
||||||
VecZnx<A>: VecZnxToRef;
|
|
||||||
|
|
||||||
fn mul_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, grlwe_size: usize) -> usize;
|
pub trait ProdScratchSpace {
|
||||||
|
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize;
|
||||||
|
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
fn mul_rlwe_inplace_scratch_space(module: &Module<FFT64>, res_size: usize, mat_size: usize) -> usize {
|
pub trait Product<MUT, REF>
|
||||||
Self::mul_rlwe_scratch_space(module, res_size, res_size, mat_size)
|
where
|
||||||
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
|
{
|
||||||
|
type Lhs;
|
||||||
|
|
||||||
|
fn prod_by_grlwe(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch);
|
||||||
|
fn prod_by_rgsw(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) trait MatRLWEProductScratchSpace {
|
||||||
|
fn prod_with_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, grlwe_size: usize) -> usize;
|
||||||
|
|
||||||
|
fn prod_with_rlwe_inplace_scratch_space(module: &Module<FFT64>, res_size: usize, mat_size: usize) -> usize {
|
||||||
|
Self::prod_with_rlwe_scratch_space(module, res_size, res_size, mat_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_rlwe_dft_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, mat_size: usize) -> usize {
|
fn prod_with_rlwe_dft_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, mat_size: usize) -> usize {
|
||||||
(Self::mul_rlwe_scratch_space(module, res_size, a_size, mat_size) | module.vec_znx_idft_tmp_bytes())
|
(Self::prod_with_rlwe_scratch_space(module, res_size, a_size, mat_size) | module.vec_znx_idft_tmp_bytes())
|
||||||
+ module.bytes_of_vec_znx(2, a_size)
|
+ module.bytes_of_vec_znx(2, a_size)
|
||||||
+ module.bytes_of_vec_znx(2, res_size)
|
+ module.bytes_of_vec_znx(2, res_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_rlwe_dft_inplace_scratch_space(module: &Module<FFT64>, res_size: usize, mat_size: usize) -> usize {
|
fn prod_with_rlwe_dft_inplace_scratch_space(module: &Module<FFT64>, res_size: usize, mat_size: usize) -> usize {
|
||||||
(Self::mul_rlwe_inplace_scratch_space(module, res_size, mat_size) | module.vec_znx_idft_tmp_bytes())
|
(Self::prod_with_rlwe_inplace_scratch_space(module, res_size, mat_size) | module.vec_znx_idft_tmp_bytes())
|
||||||
+ module.bytes_of_vec_znx(2, res_size)
|
+ module.bytes_of_vec_znx(2, res_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_mat_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, mat_size: usize) -> usize {
|
fn prod_with_mat_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, mat_size: usize) -> usize {
|
||||||
Self::mul_rlwe_dft_inplace_scratch_space(module, res_size, mat_size) + module.bytes_of_vec_znx_dft(2, a_size)
|
Self::prod_with_rlwe_dft_scratch_space(module, res_size, a_size, mat_size)
|
||||||
|
+ module.bytes_of_vec_znx_dft(2, a_size)
|
||||||
|
+ module.bytes_of_vec_znx_dft(2, res_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_mat_rlwe_inplace_scratch_space(module: &Module<FFT64>, res_size: usize, mat_size: usize) -> usize {
|
fn prod_with_mat_rlwe_inplace_scratch_space(module: &Module<FFT64>, res_size: usize, mat_size: usize) -> usize {
|
||||||
Self::mul_rlwe_dft_inplace_scratch_space(module, res_size, mat_size) + module.bytes_of_vec_znx_dft(2, res_size)
|
Self::prod_with_rlwe_dft_inplace_scratch_space(module, res_size, mat_size) + module.bytes_of_vec_znx_dft(2, res_size)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn mul_rlwe_inplace<R>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, scratch: &mut Scratch)
|
pub(crate) trait MatRLWEProduct: Infos {
|
||||||
|
fn prod_with_rlwe<MUT, REF>(&self, module: &Module<FFT64>, res: &mut RLWECt<MUT>, a: &RLWECt<REF>, scratch: &mut Scratch)
|
||||||
where
|
where
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64> + ZnxInfos,
|
VecZnx<MUT>: VecZnxToMut,
|
||||||
VecZnx<R>: VecZnxToMut + VecZnxToRef,
|
VecZnx<REF>: VecZnxToRef;
|
||||||
|
|
||||||
|
fn prod_with_rlwe_inplace<MUT>(&self, module: &Module<FFT64>, res: &mut RLWECt<MUT>, scratch: &mut Scratch)
|
||||||
|
where
|
||||||
|
VecZnx<MUT>: VecZnxToMut + VecZnxToRef,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let res_ptr: *mut RLWECt<R> = res as *mut RLWECt<R>; // This is ok because [Self::mul_rlwe] only updates res at the end.
|
let res_ptr: *mut RLWECt<MUT> = res as *mut RLWECt<MUT>; // This is ok because [Self::mul_rlwe] only updates res at the end.
|
||||||
self.mul_rlwe(&module, &mut *res_ptr, &*res_ptr, scratch);
|
self.prod_with_rlwe(&module, &mut *res_ptr, &*res_ptr, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_rlwe_dft<R, A>(
|
fn prod_with_rlwe_dft<MUT, REF>(
|
||||||
&self,
|
&self,
|
||||||
module: &Module<FFT64>,
|
module: &Module<FFT64>,
|
||||||
res: &mut RLWECtDft<R, FFT64>,
|
res: &mut RLWECtDft<MUT, FFT64>,
|
||||||
a: &RLWECtDft<A, FFT64>,
|
a: &RLWECtDft<REF, FFT64>,
|
||||||
scratch: &mut Scratch,
|
scratch: &mut Scratch,
|
||||||
) where
|
) where
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64> + ZnxInfos,
|
VecZnxDft<MUT, FFT64>: VecZnxDftToMut<FFT64> + VecZnxDftToRef<FFT64> + ZnxInfos,
|
||||||
VecZnxDft<R, FFT64>: VecZnxDftToMut<FFT64> + VecZnxDftToRef<FFT64> + ZnxInfos,
|
VecZnxDft<REF, FFT64>: VecZnxDftToRef<FFT64> + ZnxInfos,
|
||||||
VecZnxDft<A, FFT64>: VecZnxDftToRef<FFT64> + ZnxInfos,
|
|
||||||
{
|
{
|
||||||
let log_base2k: usize = self.log_base2k();
|
let log_base2k: usize = self.log_base2k();
|
||||||
|
|
||||||
@@ -180,15 +176,15 @@ where
|
|||||||
log_k: res.log_k(),
|
log_k: res.log_k(),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.mul_rlwe(module, &mut res_idft, &a_idft, scratch_2);
|
self.prod_with_rlwe(module, &mut res_idft, &a_idft, scratch_2);
|
||||||
|
|
||||||
module.vec_znx_dft(res, 0, &res_idft, 0);
|
module.vec_znx_dft(res, 0, &res_idft, 0);
|
||||||
module.vec_znx_dft(res, 1, &res_idft, 1);
|
module.vec_znx_dft(res, 1, &res_idft, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_rlwe_dft_inplace<R>(&self, module: &Module<FFT64>, res: &mut RLWECtDft<R, FFT64>, scratch: &mut Scratch)
|
fn prod_with_rlwe_dft_inplace<MUT>(&self, module: &Module<FFT64>, res: &mut RLWECtDft<MUT, FFT64>, scratch: &mut Scratch)
|
||||||
where
|
where
|
||||||
VecZnxDft<R, FFT64>: VecZnxDftToRef<FFT64> + VecZnxDftToMut<FFT64>,
|
VecZnxDft<MUT, FFT64>: VecZnxDftToRef<FFT64> + VecZnxDftToMut<FFT64>,
|
||||||
{
|
{
|
||||||
let log_base2k: usize = self.log_base2k();
|
let log_base2k: usize = self.log_base2k();
|
||||||
|
|
||||||
@@ -209,47 +205,55 @@ where
|
|||||||
|
|
||||||
res.idft(module, &mut res_idft, scratch_1);
|
res.idft(module, &mut res_idft, scratch_1);
|
||||||
|
|
||||||
self.mul_rlwe_inplace(module, &mut res_idft, scratch_1);
|
self.prod_with_rlwe_inplace(module, &mut res_idft, scratch_1);
|
||||||
|
|
||||||
module.vec_znx_dft(res, 0, &res_idft, 0);
|
module.vec_znx_dft(res, 0, &res_idft, 0);
|
||||||
module.vec_znx_dft(res, 1, &res_idft, 1);
|
module.vec_znx_dft(res, 1, &res_idft, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_mat_rlwe<R, A>(&self, module: &Module<FFT64>, res: &mut R, a: &A, scratch: &mut Scratch)
|
fn prod_with_mat_rlwe<RES, LHS>(&self, module: &Module<FFT64>, res: &mut RES, a: &LHS, scratch: &mut Scratch)
|
||||||
where
|
where
|
||||||
A: GetRow<FFT64> + Infos,
|
LHS: GetRow<FFT64> + Infos,
|
||||||
R: SetRow<FFT64> + Infos,
|
RES: SetRow<FFT64> + Infos,
|
||||||
{
|
{
|
||||||
let (tmp_row_data, scratch1) = scratch.tmp_vec_znx_dft(module, 2, a.size());
|
let (tmp_row_data, scratch1) = scratch.tmp_vec_znx_dft(module, 2, a.size());
|
||||||
|
|
||||||
let mut tmp_row: RLWECtDft<&mut [u8], FFT64> = RLWECtDft::<&mut [u8], FFT64> {
|
let mut tmp_a_row: RLWECtDft<&mut [u8], FFT64> = RLWECtDft::<&mut [u8], FFT64> {
|
||||||
data: tmp_row_data,
|
data: tmp_row_data,
|
||||||
log_base2k: a.log_base2k(),
|
log_base2k: a.log_base2k(),
|
||||||
log_k: a.log_k(),
|
log_k: a.log_k(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (tmp_res_data, scratch2) = scratch1.tmp_vec_znx_dft(module, 2, res.size());
|
||||||
|
|
||||||
|
let mut tmp_res_row: RLWECtDft<&mut [u8], FFT64> = RLWECtDft::<&mut [u8], FFT64> {
|
||||||
|
data: tmp_res_data,
|
||||||
|
log_base2k: res.log_base2k(),
|
||||||
|
log_k: res.log_k(),
|
||||||
|
};
|
||||||
|
|
||||||
let min_rows: usize = res.rows().min(a.rows());
|
let min_rows: usize = res.rows().min(a.rows());
|
||||||
|
|
||||||
(0..res.rows()).for_each(|row_i| {
|
(0..res.rows()).for_each(|row_i| {
|
||||||
(0..res.cols()).for_each(|col_j| {
|
(0..res.cols()).for_each(|col_j| {
|
||||||
a.get_row(module, row_i, col_j, &mut tmp_row);
|
a.get_row(module, row_i, col_j, &mut tmp_a_row);
|
||||||
self.mul_rlwe_dft_inplace(module, &mut tmp_row, scratch1);
|
self.prod_with_rlwe_dft(module, &mut tmp_res_row, &tmp_a_row, scratch2);
|
||||||
res.set_row(module, row_i, col_j, &tmp_row);
|
res.set_row(module, row_i, col_j, &tmp_res_row);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tmp_row.data.zero();
|
tmp_res_row.data.zero();
|
||||||
|
|
||||||
(min_rows..res.rows()).for_each(|row_i| {
|
(min_rows..res.rows()).for_each(|row_i| {
|
||||||
(0..self.cols()).for_each(|col_j| {
|
(0..self.cols()).for_each(|col_j| {
|
||||||
res.set_row(module, row_i, col_j, &tmp_row);
|
res.set_row(module, row_i, col_j, &tmp_res_row);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mul_mat_rlwe_inplace<R>(&self, module: &Module<FFT64>, res: &mut R, scratch: &mut Scratch)
|
fn prod_with_mat_rlwe_inplace<RES>(&self, module: &Module<FFT64>, res: &mut RES, scratch: &mut Scratch)
|
||||||
where
|
where
|
||||||
R: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
RES: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
||||||
{
|
{
|
||||||
let (tmp_row_data, scratch1) = scratch.tmp_vec_znx_dft(module, 2, res.size());
|
let (tmp_row_data, scratch1) = scratch.tmp_vec_znx_dft(module, 2, res.size());
|
||||||
|
|
||||||
@@ -262,7 +266,7 @@ where
|
|||||||
(0..res.rows()).for_each(|row_i| {
|
(0..res.rows()).for_each(|row_i| {
|
||||||
(0..res.cols()).for_each(|col_j| {
|
(0..res.cols()).for_each(|col_j| {
|
||||||
res.get_row(module, row_i, col_j, &mut tmp_row);
|
res.get_row(module, row_i, col_j, &mut tmp_row);
|
||||||
self.mul_rlwe_dft_inplace(module, &mut tmp_row, scratch1);
|
self.prod_with_rlwe_dft_inplace(module, &mut tmp_row, scratch1);
|
||||||
res.set_row(module, row_i, col_j, &tmp_row);
|
res.set_row(module, row_i, col_j, &tmp_row);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ use base2k::{
|
|||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
elem::{FromProdBy, FromProdByScratchSpace, GetRow, Infos, MatZnxDftProducts, ProdBy, ProdByScratchSpace, SetRow},
|
elem::{
|
||||||
|
GetRow, Infos, MatRLWEProduct, MatRLWEProductScratchSpace, ProdInplace, ProdInplaceScratchSpace, ProdScratchSpace,
|
||||||
|
Product, SetRow,
|
||||||
|
},
|
||||||
keys::SecretKeyDft,
|
keys::SecretKeyDft,
|
||||||
rgsw::RGSWCt,
|
rgsw::RGSWCt,
|
||||||
rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
||||||
@@ -30,18 +33,6 @@ impl<B: Backend> GRLWECt<Vec<u8>, B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> GRLWECt<C, FFT64>
|
|
||||||
where
|
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
pub fn get_row<R>(&self, module: &Module<FFT64>, row_i: usize, res: &mut RLWECtDft<R, FFT64>)
|
|
||||||
where
|
|
||||||
VecZnxDft<R, FFT64>: VecZnxDftToMut<FFT64>,
|
|
||||||
{
|
|
||||||
module.vmp_extract_row(res, self, row_i, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, B: Backend> Infos for GRLWECt<T, B> {
|
impl<T, B: Backend> Infos for GRLWECt<T, B> {
|
||||||
type Inner = MatZnxDft<T, B>;
|
type Inner = MatZnxDft<T, B>;
|
||||||
|
|
||||||
@@ -202,18 +193,20 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> MatZnxDftProducts<GRLWECt<C, FFT64>, C> for GRLWECt<C, FFT64>
|
impl MatRLWEProductScratchSpace for GRLWECt<Vec<u8>, FFT64> {
|
||||||
where
|
fn prod_with_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, grlwe_size: usize) -> usize {
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64> + ZnxInfos,
|
|
||||||
{
|
|
||||||
fn mul_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, grlwe_size: usize) -> usize {
|
|
||||||
module.bytes_of_vec_znx_dft(2, grlwe_size)
|
module.bytes_of_vec_znx_dft(2, grlwe_size)
|
||||||
+ (module.vec_znx_big_normalize_tmp_bytes()
|
+ (module.vec_znx_big_normalize_tmp_bytes()
|
||||||
| (module.vmp_apply_tmp_bytes(res_size, a_size, a_size, 1, 2, grlwe_size)
|
| (module.vmp_apply_tmp_bytes(res_size, a_size, a_size, 1, 2, grlwe_size)
|
||||||
+ module.bytes_of_vec_znx_dft(1, a_size)))
|
+ module.bytes_of_vec_znx_dft(1, a_size)))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn mul_rlwe<R, A>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, a: &RLWECt<A>, scratch: &mut Scratch)
|
impl<C> MatRLWEProduct for GRLWECt<C, FFT64>
|
||||||
|
where
|
||||||
|
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64> + ZnxInfos,
|
||||||
|
{
|
||||||
|
fn prod_with_rlwe<R, A>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, a: &RLWECt<A>, scratch: &mut Scratch)
|
||||||
where
|
where
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64>,
|
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
VecZnx<R>: VecZnxToMut,
|
VecZnx<R>: VecZnxToMut,
|
||||||
@@ -247,79 +240,52 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProdByScratchSpace for GRLWECt<Vec<u8>, FFT64> {
|
impl ProdInplaceScratchSpace for GRLWECt<Vec<u8>, FFT64> {
|
||||||
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_inplace_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_inplace_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromProdByScratchSpace for GRLWECt<Vec<u8>, FFT64> {
|
impl ProdScratchSpace for GRLWECt<Vec<u8>, FFT64> {
|
||||||
fn from_prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT> ProdBy<GRLWECt<MUT, FFT64>> for GRLWECt<MUT, FFT64>
|
impl<MUT, REF> ProdInplace<MUT, REF> for GRLWECt<MUT, FFT64>
|
||||||
where
|
where
|
||||||
GRLWECt<MUT, FFT64>: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
GRLWECt<MUT, FFT64>: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
||||||
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn prod_by_grlwe<R>(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_grlwe_inplace(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_mat_rlwe_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw<R>(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_rgsw_inplace(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_mat_rlwe_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT, REF> FromProdBy<GRLWECt<MUT, FFT64>, GRLWECt<REF, FFT64>> for GRLWECt<MUT, FFT64>
|
impl<MUT, REF> Product<MUT, REF> for GRLWECt<MUT, FFT64>
|
||||||
where
|
where
|
||||||
GRLWECt<MUT, FFT64>: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
MatZnxDft<MUT, FFT64>: MatZnxDftToRef<FFT64> + MatZnxDftToMut<FFT64>,
|
||||||
GRLWECt<REF, FFT64>: GetRow<FFT64> + Infos,
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn from_prod_by_grlwe<R>(
|
type Lhs = GRLWECt<REF, FFT64>;
|
||||||
&mut self,
|
|
||||||
module: &Module<FFT64>,
|
fn prod_by_grlwe(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
lhs: &GRLWECt<REF, FFT64>,
|
rhs.prod_with_mat_rlwe(module, self, lhs, scratch);
|
||||||
rhs: &GRLWECt<R, FFT64>,
|
|
||||||
scratch: &mut Scratch,
|
|
||||||
) where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw<R>(
|
fn prod_by_rgsw(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
&mut self,
|
rhs.prod_with_mat_rlwe(module, self, lhs, scratch);
|
||||||
module: &Module<FFT64>,
|
|
||||||
lhs: &GRLWECt<REF, FFT64>,
|
|
||||||
rhs: &RGSWCt<R, FFT64>,
|
|
||||||
scratch: &mut Scratch,
|
|
||||||
) where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ pub mod grlwe;
|
|||||||
pub mod keys;
|
pub mod keys;
|
||||||
pub mod rgsw;
|
pub mod rgsw;
|
||||||
pub mod rlwe;
|
pub mod rlwe;
|
||||||
|
#[cfg(test)]
|
||||||
mod test_fft64;
|
mod test_fft64;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ use base2k::{
|
|||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
elem::{FromProdBy, FromProdByScratchSpace, GetRow, Infos, MatZnxDftProducts, ProdBy, ProdByScratchSpace, SetRow},
|
elem::{
|
||||||
|
GetRow, Infos, MatRLWEProduct, MatRLWEProductScratchSpace, ProdInplace, ProdInplaceScratchSpace, ProdScratchSpace,
|
||||||
|
Product, SetRow,
|
||||||
|
},
|
||||||
grlwe::GRLWECt,
|
grlwe::GRLWECt,
|
||||||
keys::SecretKeyDft,
|
keys::SecretKeyDft,
|
||||||
rlwe::{RLWECt, RLWECtDft, RLWEPt, encrypt_rlwe_sk},
|
rlwe::{RLWECt, RLWECtDft, RLWEPt, encrypt_rlwe_sk},
|
||||||
@@ -184,17 +187,19 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> MatZnxDftProducts<RGSWCt<C, FFT64>, C> for RGSWCt<C, FFT64>
|
impl MatRLWEProductScratchSpace for RGSWCt<Vec<u8>, FFT64> {
|
||||||
where
|
fn prod_with_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, rgsw_size: usize) -> usize {
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64> + ZnxInfos,
|
|
||||||
{
|
|
||||||
fn mul_rlwe_scratch_space(module: &Module<FFT64>, res_size: usize, a_size: usize, rgsw_size: usize) -> usize {
|
|
||||||
module.bytes_of_vec_znx_dft(2, rgsw_size)
|
module.bytes_of_vec_znx_dft(2, rgsw_size)
|
||||||
+ ((module.bytes_of_vec_znx_dft(2, a_size) + module.vmp_apply_tmp_bytes(res_size, a_size, a_size, 2, 2, rgsw_size))
|
+ ((module.bytes_of_vec_znx_dft(2, a_size) + module.vmp_apply_tmp_bytes(res_size, a_size, a_size, 2, 2, rgsw_size))
|
||||||
| module.vec_znx_big_normalize_tmp_bytes())
|
| module.vec_znx_big_normalize_tmp_bytes())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn mul_rlwe<R, A>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, a: &RLWECt<A>, scratch: &mut Scratch)
|
impl<C> MatRLWEProduct for RGSWCt<C, FFT64>
|
||||||
|
where
|
||||||
|
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64> + ZnxInfos,
|
||||||
|
{
|
||||||
|
fn prod_with_rlwe<R, A>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, a: &RLWECt<A>, scratch: &mut Scratch)
|
||||||
where
|
where
|
||||||
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64>,
|
MatZnxDft<C, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
VecZnx<R>: VecZnxToMut,
|
VecZnx<R>: VecZnxToMut,
|
||||||
@@ -227,79 +232,52 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProdByScratchSpace for RGSWCt<Vec<u8>, FFT64> {
|
impl ProdInplaceScratchSpace for RGSWCt<Vec<u8>, FFT64> {
|
||||||
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_inplace_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_inplace_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromProdByScratchSpace for RGSWCt<Vec<u8>, FFT64> {
|
impl ProdScratchSpace for RGSWCt<Vec<u8>, FFT64> {
|
||||||
fn from_prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_mat_rlwe_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_mat_rlwe_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT> ProdBy<RGSWCt<MUT, FFT64>> for RGSWCt<MUT, FFT64>
|
impl<MUT, REF> ProdInplace<MUT, REF> for RGSWCt<MUT, FFT64>
|
||||||
where
|
where
|
||||||
RGSWCt<MUT, FFT64>: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
RGSWCt<MUT, FFT64>: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
||||||
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn prod_by_grlwe<R>(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_grlwe_inplace(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_mat_rlwe_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw<R>(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_rgsw_inplace(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_mat_rlwe_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT, REF> FromProdBy<RGSWCt<MUT, FFT64>, RGSWCt<REF, FFT64>> for RGSWCt<MUT, FFT64>
|
impl<MUT, REF> Product<MUT, REF> for RGSWCt<MUT, FFT64>
|
||||||
where
|
where
|
||||||
RGSWCt<MUT, FFT64>: GetRow<FFT64> + SetRow<FFT64> + Infos,
|
MatZnxDft<MUT, FFT64>: MatZnxDftToRef<FFT64> + MatZnxDftToMut<FFT64>,
|
||||||
RGSWCt<REF, FFT64>: GetRow<FFT64> + Infos,
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn from_prod_by_grlwe<R>(
|
type Lhs = RGSWCt<REF, FFT64>;
|
||||||
&mut self,
|
|
||||||
module: &Module<FFT64>,
|
fn prod_by_grlwe(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
lhs: &RGSWCt<REF, FFT64>,
|
rhs.prod_with_mat_rlwe(module, self, lhs, scratch);
|
||||||
rhs: &GRLWECt<R, FFT64>,
|
|
||||||
scratch: &mut Scratch,
|
|
||||||
) where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw<R>(
|
fn prod_by_rgsw(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
&mut self,
|
rhs.prod_with_mat_rlwe(module, self, lhs, scratch);
|
||||||
module: &Module<FFT64>,
|
|
||||||
lhs: &RGSWCt<REF, FFT64>,
|
|
||||||
rhs: &RGSWCt<R, FFT64>,
|
|
||||||
scratch: &mut Scratch,
|
|
||||||
) where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_mat_rlwe(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
148
core/src/rlwe.rs
148
core/src/rlwe.rs
@@ -6,7 +6,7 @@ use base2k::{
|
|||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
elem::{FromProdBy, FromProdByScratchSpace, Infos, MatZnxDftProducts, ProdBy, ProdByScratchSpace},
|
elem::{Infos, MatRLWEProduct, MatRLWEProductScratchSpace, ProdInplace, ProdInplaceScratchSpace, ProdScratchSpace, Product},
|
||||||
grlwe::GRLWECt,
|
grlwe::GRLWECt,
|
||||||
keys::{PublicKey, SecretDistribution, SecretKeyDft},
|
keys::{PublicKey, SecretDistribution, SecretKeyDft},
|
||||||
rgsw::RGSWCt,
|
rgsw::RGSWCt,
|
||||||
@@ -84,70 +84,54 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProdByScratchSpace for RLWECt<Vec<u8>> {
|
impl ProdInplaceScratchSpace for RLWECt<Vec<u8>> {
|
||||||
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_inplace_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_inplace_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromProdByScratchSpace for RLWECt<Vec<u8>> {
|
impl ProdScratchSpace for RLWECt<Vec<u8>> {
|
||||||
fn from_prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT> ProdBy<RLWECt<MUT>> for RLWECt<MUT>
|
impl<MUT, REF> ProdInplace<MUT, REF> for RLWECt<MUT>
|
||||||
where
|
where
|
||||||
VecZnx<MUT>: VecZnxToMut + VecZnxToRef,
|
VecZnx<MUT>: VecZnxToMut + VecZnxToRef,
|
||||||
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn prod_by_grlwe<R>(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_grlwe_inplace(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_rlwe_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_rlwe_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw<R>(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_rgsw_inplace(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_rlwe_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_rlwe_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT, REF> FromProdBy<RLWECt<MUT>, RLWECt<REF>> for RLWECt<MUT>
|
impl<MUT, REF> Product<MUT, REF> for RLWECt<MUT>
|
||||||
where
|
where
|
||||||
VecZnx<MUT>: VecZnxToMut + VecZnxToRef,
|
VecZnx<MUT>: VecZnxToMut + VecZnxToRef,
|
||||||
VecZnx<REF>: VecZnxToRef,
|
VecZnx<REF>: VecZnxToRef,
|
||||||
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn from_prod_by_grlwe<R>(&mut self, module: &Module<FFT64>, lhs: &RLWECt<REF>, rhs: &GRLWECt<R, FFT64>, scratch: &mut Scratch)
|
type Lhs = RLWECt<REF>;
|
||||||
where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
fn prod_by_grlwe(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
{
|
rhs.prod_with_rlwe(module, self, lhs, scratch);
|
||||||
rhs.mul_rlwe(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw<R>(&mut self, module: &Module<FFT64>, lhs: &RLWECt<REF>, rhs: &RGSWCt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_rgsw(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_rlwe(module, self, lhs, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_rlwe(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,7 +480,7 @@ where
|
|||||||
|
|
||||||
impl<C> RLWECtDft<C, FFT64>
|
impl<C> RLWECtDft<C, FFT64>
|
||||||
where
|
where
|
||||||
VecZnxDft<C, FFT64>: VecZnxDftToRef<FFT64>,
|
RLWECtDft<C, FFT64>: VecZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn idft_scratch_space(module: &Module<FFT64>, size: usize) -> usize {
|
pub(crate) fn idft_scratch_space(module: &Module<FFT64>, size: usize) -> usize {
|
||||||
@@ -505,7 +489,7 @@ where
|
|||||||
|
|
||||||
pub(crate) fn idft<R>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, scratch: &mut Scratch)
|
pub(crate) fn idft<R>(&self, module: &Module<FFT64>, res: &mut RLWECt<R>, scratch: &mut Scratch)
|
||||||
where
|
where
|
||||||
VecZnx<R>: VecZnxToMut,
|
RLWECt<R>: VecZnxToMut,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -518,8 +502,8 @@ where
|
|||||||
|
|
||||||
let (mut res_big, scratch1) = scratch.tmp_vec_znx_big(module, 2, min_size);
|
let (mut res_big, scratch1) = scratch.tmp_vec_znx_big(module, 2, min_size);
|
||||||
|
|
||||||
module.vec_znx_idft(&mut res_big, 0, &self.data, 0, scratch1);
|
module.vec_znx_idft(&mut res_big, 0, self, 0, scratch1);
|
||||||
module.vec_znx_idft(&mut res_big, 1, &self.data, 1, scratch1);
|
module.vec_znx_idft(&mut res_big, 1, self, 1, scratch1);
|
||||||
module.vec_znx_big_normalize(self.log_base2k(), res, 0, &res_big, 0, scratch1);
|
module.vec_znx_big_normalize(self.log_base2k(), res, 0, &res_big, 0, scratch1);
|
||||||
module.vec_znx_big_normalize(self.log_base2k(), res, 1, &res_big, 1, scratch1);
|
module.vec_znx_big_normalize(self.log_base2k(), res, 1, &res_big, 1, scratch1);
|
||||||
}
|
}
|
||||||
@@ -665,79 +649,53 @@ impl<C> RLWECtDft<C, FFT64> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProdByScratchSpace for RLWECtDft<Vec<u8>, FFT64> {
|
impl ProdInplaceScratchSpace for RLWECtDft<Vec<u8>, FFT64> {
|
||||||
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_dft_inplace_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_dft_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_inplace_scratch_space(module: &Module<FFT64>, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_dft_inplace_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_dft_inplace_scratch_space(module, lhs, rhs)
|
||||||
module, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromProdByScratchSpace for RLWECtDft<Vec<u8>, FFT64> {
|
impl ProdScratchSpace for RLWECtDft<Vec<u8>, FFT64> {
|
||||||
fn from_prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_grlwe_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<GRLWECt<Vec<u8>, FFT64> as MatZnxDftProducts<GRLWECt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_dft_scratch_space(
|
<GRLWECt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_dft_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
fn prod_by_rgsw_scratch_space(module: &Module<FFT64>, res_size: usize, lhs: usize, rhs: usize) -> usize {
|
||||||
<RGSWCt<Vec<u8>, FFT64> as MatZnxDftProducts<RGSWCt<Vec<u8>, FFT64>, Vec<u8>>>::mul_rlwe_dft_scratch_space(
|
<RGSWCt<Vec<u8>, FFT64> as MatRLWEProductScratchSpace>::prod_with_rlwe_dft_scratch_space(module, res_size, lhs, rhs)
|
||||||
module, res_size, lhs, rhs,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT> ProdBy<RLWECtDft<MUT, FFT64>> for RLWECtDft<MUT, FFT64>
|
impl<MUT, REF> ProdInplace<MUT, REF> for RLWECtDft<MUT, FFT64>
|
||||||
where
|
where
|
||||||
VecZnxDft<MUT, FFT64>: VecZnxDftToMut<FFT64> + VecZnxDftToRef<FFT64>,
|
VecZnxDft<MUT, FFT64>: VecZnxDftToMut<FFT64> + VecZnxDftToRef<FFT64>,
|
||||||
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn prod_by_grlwe<R>(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_grlwe_inplace(&mut self, module: &Module<FFT64>, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_rlwe_dft_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_rlwe_dft_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prod_by_rgsw<R>(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<R, FFT64>, scratch: &mut Scratch)
|
fn prod_by_rgsw_inplace(&mut self, module: &Module<FFT64>, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
where
|
rhs.prod_with_rlwe_dft_inplace(module, self, scratch);
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_rlwe_dft_inplace(module, self, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<MUT, REF> FromProdBy<RLWECtDft<MUT, FFT64>, RLWECtDft<REF, FFT64>> for RLWECtDft<MUT, FFT64>
|
impl<MUT, REF> Product<MUT, REF> for RLWECtDft<MUT, FFT64>
|
||||||
where
|
where
|
||||||
VecZnxDft<MUT, FFT64>: VecZnxDftToMut<FFT64> + VecZnxDftToRef<FFT64>,
|
VecZnxDft<MUT, FFT64>: VecZnxDftToMut<FFT64> + VecZnxDftToRef<FFT64>,
|
||||||
VecZnxDft<REF, FFT64>: VecZnxDftToRef<FFT64>,
|
VecZnxDft<REF, FFT64>: VecZnxDftToRef<FFT64>,
|
||||||
|
MatZnxDft<REF, FFT64>: MatZnxDftToRef<FFT64>,
|
||||||
{
|
{
|
||||||
fn from_prod_by_grlwe<R>(
|
type Lhs = RLWECtDft<REF, FFT64>;
|
||||||
&mut self,
|
|
||||||
module: &Module<FFT64>,
|
fn prod_by_grlwe(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &GRLWECt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
lhs: &RLWECtDft<REF, FFT64>,
|
rhs.prod_with_rlwe_dft(module, self, lhs, scratch);
|
||||||
rhs: &GRLWECt<R, FFT64>,
|
|
||||||
scratch: &mut Scratch,
|
|
||||||
) where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_rlwe_dft(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prod_by_rgsw<R>(
|
fn prod_by_rgsw(&mut self, module: &Module<FFT64>, lhs: &Self::Lhs, rhs: &RGSWCt<REF, FFT64>, scratch: &mut Scratch) {
|
||||||
&mut self,
|
rhs.prod_with_rlwe_dft(module, self, lhs, scratch);
|
||||||
module: &Module<FFT64>,
|
|
||||||
lhs: &RLWECtDft<REF, FFT64>,
|
|
||||||
rhs: &RGSWCt<R, FFT64>,
|
|
||||||
scratch: &mut Scratch,
|
|
||||||
) where
|
|
||||||
MatZnxDft<R, FFT64>: MatZnxDftToRef<FFT64>,
|
|
||||||
{
|
|
||||||
rhs.mul_rlwe_dft(module, self, lhs, scratch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
#[cfg(test)]
|
use base2k::{FFT64, Module, ScalarZnx, ScalarZnxAlloc, ScratchOwned, Stats, VecZnxOps, ZnxViewMut};
|
||||||
|
use sampling::source::Source;
|
||||||
|
|
||||||
mod tests {
|
use crate::{
|
||||||
use base2k::{FFT64, Module, ScalarZnx, ScalarZnxAlloc, ScratchOwned, Stats, VecZnxOps, ZnxViewMut};
|
elem::{GetRow, Infos, ProdInplace, ProdInplaceScratchSpace, ProdScratchSpace, Product},
|
||||||
use sampling::source::Source;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
elem::{FromProdBy, FromProdByScratchSpace, Infos, ProdBy, ProdByScratchSpace},
|
|
||||||
grlwe::GRLWECt,
|
grlwe::GRLWECt,
|
||||||
keys::{SecretKey, SecretKeyDft},
|
keys::{SecretKey, SecretKeyDft},
|
||||||
rgsw::RGSWCt,
|
rgsw::RGSWCt,
|
||||||
rlwe::{RLWECtDft, RLWEPt},
|
rlwe::{RLWECtDft, RLWEPt},
|
||||||
test_fft64::{grlwe::noise_grlwe_rlwe_product, rgsw::noise_rgsw_rlwe_product},
|
test_fft64::rgsw::noise_rgsw_product,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encrypt_sk() {
|
fn encrypt_sk() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 8;
|
let log_base2k: usize = 8;
|
||||||
let log_k_ct: usize = 54;
|
let log_k_ct: usize = 54;
|
||||||
@@ -57,7 +54,7 @@ mod tests {
|
|||||||
let mut ct_rlwe_dft: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_ct);
|
let mut ct_rlwe_dft: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_ct);
|
||||||
|
|
||||||
(0..ct.rows()).for_each(|row_i| {
|
(0..ct.rows()).for_each(|row_i| {
|
||||||
ct.get_row(&module, row_i, &mut ct_rlwe_dft);
|
ct.get_row(&module, row_i, 0, &mut ct_rlwe_dft);
|
||||||
ct_rlwe_dft.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
ct_rlwe_dft.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
||||||
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &pt_scalar, 0);
|
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &pt_scalar, 0);
|
||||||
let std_pt: f64 = pt.data.std(0, log_base2k) * (log_k_ct as f64).exp2();
|
let std_pt: f64 = pt.data.std(0, log_base2k) * (log_k_ct as f64).exp2();
|
||||||
@@ -65,10 +62,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_prod_by_grlwe() {
|
fn from_prod_by_grlwe() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -88,7 +85,7 @@ mod tests {
|
|||||||
let mut scratch: ScratchOwned = ScratchOwned::new(
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe_s0s1.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe_s0s1.size())
|
||||||
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe_s0s2.size())
|
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe_s0s2.size())
|
||||||
| GRLWECt::from_prod_by_grlwe_scratch_space(
|
| GRLWECt::prod_by_grlwe_scratch_space(
|
||||||
&module,
|
&module,
|
||||||
ct_grlwe_s0s2.size(),
|
ct_grlwe_s0s2.size(),
|
||||||
ct_grlwe_s0s1.size(),
|
ct_grlwe_s0s1.size(),
|
||||||
@@ -139,13 +136,13 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// GRLWE_{s1}(s0) (x) GRLWE_{s2}(s1) = GRLWE_{s2}(s0)
|
// GRLWE_{s1}(s0) (x) GRLWE_{s2}(s1) = GRLWE_{s2}(s0)
|
||||||
ct_grlwe_s0s2.from_prod_by_grlwe(&module, &ct_grlwe_s0s1, &ct_grlwe_s1s2, scratch.borrow());
|
ct_grlwe_s0s2.prod_by_grlwe(&module, &ct_grlwe_s0s1, &ct_grlwe_s1s2, scratch.borrow());
|
||||||
|
|
||||||
let mut ct_rlwe_dft_s0s2: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_grlwe);
|
let mut ct_rlwe_dft_s0s2: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_grlwe);
|
||||||
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
||||||
|
|
||||||
(0..ct_grlwe_s0s2.rows()).for_each(|row_i| {
|
(0..ct_grlwe_s0s2.rows()).for_each(|row_i| {
|
||||||
ct_grlwe_s0s2.get_row(&module, row_i, &mut ct_rlwe_dft_s0s2);
|
ct_grlwe_s0s2.get_row(&module, row_i, 0, &mut ct_rlwe_dft_s0s2);
|
||||||
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk2_dft, scratch.borrow());
|
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk2_dft, scratch.borrow());
|
||||||
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &sk0, 0);
|
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &sk0, 0);
|
||||||
|
|
||||||
@@ -171,10 +168,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prod_by_grlwe() {
|
fn prod_by_grlwe() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -193,7 +190,7 @@ mod tests {
|
|||||||
let mut scratch: ScratchOwned = ScratchOwned::new(
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe_s0s1.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe_s0s1.size())
|
||||||
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe_s0s1.size())
|
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe_s0s1.size())
|
||||||
| GRLWECt::prod_by_grlwe_scratch_space(&module, ct_grlwe_s0s1.size(), ct_grlwe_s1s2.size()),
|
| GRLWECt::prod_by_grlwe_inplace_scratch_space(&module, ct_grlwe_s0s1.size(), ct_grlwe_s1s2.size()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
@@ -239,7 +236,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// GRLWE_{s1}(s0) (x) GRLWE_{s2}(s1) = GRLWE_{s2}(s0)
|
// GRLWE_{s1}(s0) (x) GRLWE_{s2}(s1) = GRLWE_{s2}(s0)
|
||||||
ct_grlwe_s0s1.prod_by_grlwe(&module, &ct_grlwe_s1s2, scratch.borrow());
|
ct_grlwe_s0s1.prod_by_grlwe_inplace(&module, &ct_grlwe_s1s2, scratch.borrow());
|
||||||
|
|
||||||
let ct_grlwe_s0s2: GRLWECt<Vec<u8>, FFT64> = ct_grlwe_s0s1;
|
let ct_grlwe_s0s2: GRLWECt<Vec<u8>, FFT64> = ct_grlwe_s0s1;
|
||||||
|
|
||||||
@@ -247,7 +244,7 @@ mod tests {
|
|||||||
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
||||||
|
|
||||||
(0..ct_grlwe_s0s2.rows()).for_each(|row_i| {
|
(0..ct_grlwe_s0s2.rows()).for_each(|row_i| {
|
||||||
ct_grlwe_s0s2.get_row(&module, row_i, &mut ct_rlwe_dft_s0s2);
|
ct_grlwe_s0s2.get_row(&module, row_i, 0, &mut ct_rlwe_dft_s0s2);
|
||||||
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk2_dft, scratch.borrow());
|
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk2_dft, scratch.borrow());
|
||||||
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &sk0, 0);
|
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &sk0, 0);
|
||||||
|
|
||||||
@@ -273,10 +270,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_prod_by_rgsw() {
|
fn from_prod_by_rgsw() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -299,7 +296,7 @@ mod tests {
|
|||||||
let mut scratch: ScratchOwned = ScratchOwned::new(
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe_in.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe_in.size())
|
||||||
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe_out.size())
|
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe_out.size())
|
||||||
| GRLWECt::from_prod_by_rgsw_scratch_space(
|
| GRLWECt::prod_by_rgsw_scratch_space(
|
||||||
&module,
|
&module,
|
||||||
ct_grlwe_out.size(),
|
ct_grlwe_out.size(),
|
||||||
ct_grlwe_in.size(),
|
ct_grlwe_in.size(),
|
||||||
@@ -344,7 +341,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// GRLWE_(m) (x) RGSW_(X^k) = GRLWE_(m * X^k)
|
// GRLWE_(m) (x) RGSW_(X^k) = GRLWE_(m * X^k)
|
||||||
ct_grlwe_out.from_prod_by_rgsw(&module, &ct_grlwe_in, &ct_rgsw, scratch.borrow());
|
ct_grlwe_out.prod_by_rgsw(&module, &ct_grlwe_in, &ct_rgsw, scratch.borrow());
|
||||||
|
|
||||||
let mut ct_rlwe_dft_s0s2: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_grlwe);
|
let mut ct_rlwe_dft_s0s2: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_grlwe);
|
||||||
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
||||||
@@ -352,7 +349,7 @@ mod tests {
|
|||||||
module.vec_znx_rotate_inplace(k as i64, &mut pt_grlwe, 0);
|
module.vec_znx_rotate_inplace(k as i64, &mut pt_grlwe, 0);
|
||||||
|
|
||||||
(0..ct_grlwe_out.rows()).for_each(|row_i| {
|
(0..ct_grlwe_out.rows()).for_each(|row_i| {
|
||||||
ct_grlwe_out.get_row(&module, row_i, &mut ct_rlwe_dft_s0s2);
|
ct_grlwe_out.get_row(&module, row_i, 0, &mut ct_rlwe_dft_s0s2);
|
||||||
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
||||||
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &pt_grlwe, 0);
|
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &pt_grlwe, 0);
|
||||||
|
|
||||||
@@ -365,7 +362,7 @@ mod tests {
|
|||||||
let var_a0_err: f64 = sigma * sigma;
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
let var_a1_err: f64 = 1f64 / 12f64;
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
let noise_want: f64 = noise_rgsw_rlwe_product(
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
module.n() as f64,
|
module.n() as f64,
|
||||||
log_base2k,
|
log_base2k,
|
||||||
0.5,
|
0.5,
|
||||||
@@ -387,10 +384,10 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prod_by_rgsw() {
|
fn prod_by_rgsw() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -412,7 +409,7 @@ mod tests {
|
|||||||
let mut scratch: ScratchOwned = ScratchOwned::new(
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
||||||
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe.size())
|
| RLWECtDft::decrypt_scratch_space(&module, ct_grlwe.size())
|
||||||
| GRLWECt::prod_by_rgsw_scratch_space(&module, ct_grlwe.size(), ct_rgsw.size())
|
| GRLWECt::prod_by_rgsw_inplace_scratch_space(&module, ct_grlwe.size(), ct_rgsw.size())
|
||||||
| RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size()),
|
| RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size()),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -452,7 +449,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// GRLWE_(m) (x) RGSW_(X^k) = GRLWE_(m * X^k)
|
// GRLWE_(m) (x) RGSW_(X^k) = GRLWE_(m * X^k)
|
||||||
ct_grlwe.prod_by_rgsw(&module, &ct_rgsw, scratch.borrow());
|
ct_grlwe.prod_by_rgsw_inplace(&module, &ct_rgsw, scratch.borrow());
|
||||||
|
|
||||||
let mut ct_rlwe_dft_s0s2: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_grlwe);
|
let mut ct_rlwe_dft_s0s2: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_grlwe);
|
||||||
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_grlwe);
|
||||||
@@ -460,7 +457,7 @@ mod tests {
|
|||||||
module.vec_znx_rotate_inplace(k as i64, &mut pt_grlwe, 0);
|
module.vec_znx_rotate_inplace(k as i64, &mut pt_grlwe, 0);
|
||||||
|
|
||||||
(0..ct_grlwe.rows()).for_each(|row_i| {
|
(0..ct_grlwe.rows()).for_each(|row_i| {
|
||||||
ct_grlwe.get_row(&module, row_i, &mut ct_rlwe_dft_s0s2);
|
ct_grlwe.get_row(&module, row_i, 0, &mut ct_rlwe_dft_s0s2);
|
||||||
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
ct_rlwe_dft_s0s2.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
||||||
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &pt_grlwe, 0);
|
module.vec_znx_sub_scalar_inplace(&mut pt, 0, row_i, &pt_grlwe, 0);
|
||||||
|
|
||||||
@@ -473,7 +470,7 @@ mod tests {
|
|||||||
let var_a0_err: f64 = sigma * sigma;
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
let var_a1_err: f64 = 1f64 / 12f64;
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
let noise_want: f64 = noise_rgsw_rlwe_product(
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
module.n() as f64,
|
module.n() as f64,
|
||||||
log_base2k,
|
log_base2k,
|
||||||
0.5,
|
0.5,
|
||||||
@@ -495,10 +492,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn noise_grlwe_rlwe_product(
|
pub(crate) fn noise_grlwe_rlwe_product(
|
||||||
n: f64,
|
n: f64,
|
||||||
log_base2k: usize,
|
log_base2k: usize,
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
#[cfg(test)]
|
use base2k::{
|
||||||
mod tests {
|
|
||||||
use base2k::{
|
|
||||||
FFT64, Module, ScalarZnx, ScalarZnxAlloc, ScalarZnxDftOps, ScratchOwned, Stats, VecZnxBig, VecZnxBigAlloc, VecZnxBigOps,
|
FFT64, Module, ScalarZnx, ScalarZnxAlloc, ScalarZnxDftOps, ScratchOwned, Stats, VecZnxBig, VecZnxBigAlloc, VecZnxBigOps,
|
||||||
VecZnxDft, VecZnxDftAlloc, VecZnxDftOps, VecZnxOps, ZnxZero,
|
VecZnxDft, VecZnxDftAlloc, VecZnxDftOps, VecZnxOps, VecZnxToMut, ZnxViewMut, ZnxZero,
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
elem::{GetRow, Infos},
|
elem::{GetRow, Infos, ProdInplace, ProdInplaceScratchSpace, ProdScratchSpace, Product},
|
||||||
|
grlwe::GRLWECt,
|
||||||
keys::{SecretKey, SecretKeyDft},
|
keys::{SecretKey, SecretKeyDft},
|
||||||
rgsw::RGSWCt,
|
rgsw::RGSWCt,
|
||||||
rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
rlwe::{RLWECtDft, RLWEPt},
|
||||||
test_fft64::rgsw::noise_rgsw_rlwe_product,
|
test_fft64::grlwe::noise_grlwe_rlwe_product,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encrypt_rgsw_sk() {
|
fn encrypt_rgsw_sk() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 8;
|
let log_base2k: usize = 8;
|
||||||
let log_k_ct: usize = 54;
|
let log_k_ct: usize = 54;
|
||||||
@@ -85,11 +84,499 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[test]
|
||||||
pub(crate) fn noise_rgsw_rlwe_product(
|
fn from_prod_by_grlwe() {
|
||||||
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
|
let log_base2k: usize = 12;
|
||||||
|
let log_k_grlwe: usize = 60;
|
||||||
|
let log_k_rgsw_in: usize = 45;
|
||||||
|
let log_k_rgsw_out: usize = 45;
|
||||||
|
let rows: usize = (log_k_rgsw_in + log_base2k - 1) / log_base2k;
|
||||||
|
|
||||||
|
let sigma: f64 = 3.2;
|
||||||
|
let bound: f64 = sigma * 6.0;
|
||||||
|
|
||||||
|
let mut ct_grlwe: GRLWECt<Vec<u8>, FFT64> = GRLWECt::new(&module, log_base2k, log_k_grlwe, rows);
|
||||||
|
let mut ct_rgsw_in: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw_in, rows);
|
||||||
|
let mut ct_rgsw_out: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw_out, rows);
|
||||||
|
let mut pt_rgsw: ScalarZnx<Vec<u8>> = module.new_scalar_znx(1);
|
||||||
|
|
||||||
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
|
// Random input plaintext
|
||||||
|
pt_rgsw.fill_ternary_prob(0, 0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
||||||
|
| RLWECtDft::decrypt_scratch_space(&module, ct_rgsw_out.size())
|
||||||
|
| RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw_in.size())
|
||||||
|
| RGSWCt::prod_by_grlwe_scratch_space(
|
||||||
|
&module,
|
||||||
|
ct_rgsw_out.size(),
|
||||||
|
ct_rgsw_in.size(),
|
||||||
|
ct_grlwe.size(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
|
sk0.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut sk0_dft: SecretKeyDft<Vec<u8>, FFT64> = SecretKeyDft::new(&module);
|
||||||
|
sk0_dft.dft(&module, &sk0);
|
||||||
|
|
||||||
|
let mut sk1: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
|
sk1.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut sk1_dft: SecretKeyDft<Vec<u8>, FFT64> = SecretKeyDft::new(&module);
|
||||||
|
sk1_dft.dft(&module, &sk1);
|
||||||
|
|
||||||
|
ct_grlwe.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&sk0.data,
|
||||||
|
&sk1_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw_in.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&pt_rgsw,
|
||||||
|
&sk0_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw_out.prod_by_grlwe(&module, &ct_rgsw_in, &ct_grlwe, scratch.borrow());
|
||||||
|
|
||||||
|
let mut ct_rlwe_dft: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_rgsw_out);
|
||||||
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw_out);
|
||||||
|
let mut pt_dft: VecZnxDft<Vec<u8>, FFT64> = module.new_vec_znx_dft(1, ct_rgsw_out.size());
|
||||||
|
let mut pt_big: VecZnxBig<Vec<u8>, FFT64> = module.new_vec_znx_big(1, ct_rgsw_out.size());
|
||||||
|
let mut pt_want: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw_out);
|
||||||
|
|
||||||
|
(0..ct_rgsw_out.cols()).for_each(|col_j| {
|
||||||
|
(0..ct_rgsw_out.rows()).for_each(|row_i| {
|
||||||
|
module.vec_znx_add_scalar_inplace(&mut pt_want, 0, row_i, &pt_rgsw, 0);
|
||||||
|
|
||||||
|
if col_j == 1 {
|
||||||
|
module.vec_znx_dft(&mut pt_dft, 0, &pt_want, 0);
|
||||||
|
module.svp_apply_inplace(&mut pt_dft, 0, &sk0_dft, 0);
|
||||||
|
module.vec_znx_idft_tmp_a(&mut pt_big, 0, &mut pt_dft, 0);
|
||||||
|
module.vec_znx_big_normalize(log_base2k, &mut pt_want, 0, &pt_big, 0, scratch.borrow());
|
||||||
|
}
|
||||||
|
|
||||||
|
ct_rgsw_out.get_row(&module, row_i, col_j, &mut ct_rlwe_dft);
|
||||||
|
ct_rlwe_dft.decrypt(&module, &mut pt, &sk1_dft, scratch.borrow());
|
||||||
|
|
||||||
|
module.vec_znx_sub_ab_inplace(&mut pt, 0, &pt_want, 0);
|
||||||
|
|
||||||
|
let noise_have: f64 = pt.data.std(0, log_base2k).log2();
|
||||||
|
let noise_want: f64 = noise_grlwe_rlwe_product(
|
||||||
|
module.n() as f64,
|
||||||
|
log_base2k,
|
||||||
|
0.5,
|
||||||
|
0.5,
|
||||||
|
0f64,
|
||||||
|
sigma * sigma,
|
||||||
|
0f64,
|
||||||
|
log_k_grlwe,
|
||||||
|
log_k_grlwe,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
(noise_have - noise_want).abs() <= 0.2,
|
||||||
|
"have: {} want: {}",
|
||||||
|
noise_have,
|
||||||
|
noise_want
|
||||||
|
);
|
||||||
|
|
||||||
|
pt_want.data.zero();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_prod_by_grlwe_inplace() {
|
||||||
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
|
let log_base2k: usize = 12;
|
||||||
|
let log_k_grlwe: usize = 60;
|
||||||
|
let log_k_rgsw: usize = 45;
|
||||||
|
let rows: usize = (log_k_rgsw + log_base2k - 1) / log_base2k;
|
||||||
|
|
||||||
|
let sigma: f64 = 3.2;
|
||||||
|
let bound: f64 = sigma * 6.0;
|
||||||
|
|
||||||
|
let mut ct_grlwe: GRLWECt<Vec<u8>, FFT64> = GRLWECt::new(&module, log_base2k, log_k_grlwe, rows);
|
||||||
|
let mut ct_rgsw: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw, rows);
|
||||||
|
let mut pt_rgsw: ScalarZnx<Vec<u8>> = module.new_scalar_znx(1);
|
||||||
|
|
||||||
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
|
// Random input plaintext
|
||||||
|
pt_rgsw.fill_ternary_prob(0, 0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
||||||
|
| RLWECtDft::decrypt_scratch_space(&module, ct_rgsw.size())
|
||||||
|
| RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
||||||
|
| RGSWCt::prod_by_grlwe_inplace_scratch_space(&module, ct_rgsw.size(), ct_grlwe.size()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
|
sk0.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut sk0_dft: SecretKeyDft<Vec<u8>, FFT64> = SecretKeyDft::new(&module);
|
||||||
|
sk0_dft.dft(&module, &sk0);
|
||||||
|
|
||||||
|
let mut sk1: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
|
sk1.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut sk1_dft: SecretKeyDft<Vec<u8>, FFT64> = SecretKeyDft::new(&module);
|
||||||
|
sk1_dft.dft(&module, &sk1);
|
||||||
|
|
||||||
|
ct_grlwe.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&sk0.data,
|
||||||
|
&sk1_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&pt_rgsw,
|
||||||
|
&sk0_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw.prod_by_grlwe_inplace(&module, &ct_grlwe, scratch.borrow());
|
||||||
|
|
||||||
|
let mut ct_rlwe_dft: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_rgsw);
|
||||||
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw);
|
||||||
|
let mut pt_dft: VecZnxDft<Vec<u8>, FFT64> = module.new_vec_znx_dft(1, ct_rgsw.size());
|
||||||
|
let mut pt_big: VecZnxBig<Vec<u8>, FFT64> = module.new_vec_znx_big(1, ct_rgsw.size());
|
||||||
|
let mut pt_want: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw);
|
||||||
|
|
||||||
|
(0..ct_rgsw.cols()).for_each(|col_j| {
|
||||||
|
(0..ct_rgsw.rows()).for_each(|row_i| {
|
||||||
|
module.vec_znx_add_scalar_inplace(&mut pt_want, 0, row_i, &pt_rgsw, 0);
|
||||||
|
|
||||||
|
if col_j == 1 {
|
||||||
|
module.vec_znx_dft(&mut pt_dft, 0, &pt_want, 0);
|
||||||
|
module.svp_apply_inplace(&mut pt_dft, 0, &sk0_dft, 0);
|
||||||
|
module.vec_znx_idft_tmp_a(&mut pt_big, 0, &mut pt_dft, 0);
|
||||||
|
module.vec_znx_big_normalize(log_base2k, &mut pt_want, 0, &pt_big, 0, scratch.borrow());
|
||||||
|
}
|
||||||
|
|
||||||
|
ct_rgsw.get_row(&module, row_i, col_j, &mut ct_rlwe_dft);
|
||||||
|
ct_rlwe_dft.decrypt(&module, &mut pt, &sk1_dft, scratch.borrow());
|
||||||
|
|
||||||
|
module.vec_znx_sub_ab_inplace(&mut pt, 0, &pt_want, 0);
|
||||||
|
|
||||||
|
let noise_have: f64 = pt.data.std(0, log_base2k).log2();
|
||||||
|
let noise_want: f64 = noise_grlwe_rlwe_product(
|
||||||
|
module.n() as f64,
|
||||||
|
log_base2k,
|
||||||
|
0.5,
|
||||||
|
0.5,
|
||||||
|
0f64,
|
||||||
|
sigma * sigma,
|
||||||
|
0f64,
|
||||||
|
log_k_grlwe,
|
||||||
|
log_k_grlwe,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
(noise_have - noise_want).abs() <= 0.2,
|
||||||
|
"have: {} want: {}",
|
||||||
|
noise_have,
|
||||||
|
noise_want
|
||||||
|
);
|
||||||
|
|
||||||
|
pt_want.data.zero();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_prod_by_rgsw() {
|
||||||
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
|
let log_base2k: usize = 12;
|
||||||
|
let log_k_rgsw_rhs: usize = 60;
|
||||||
|
let log_k_rgsw_lhs_in: usize = 45;
|
||||||
|
let log_k_rgsw_lhs_out: usize = 45;
|
||||||
|
let rows: usize = (log_k_rgsw_lhs_in + log_base2k - 1) / log_base2k;
|
||||||
|
|
||||||
|
let sigma: f64 = 3.2;
|
||||||
|
let bound: f64 = sigma * 6.0;
|
||||||
|
|
||||||
|
let mut ct_rgsw_rhs: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw_rhs, rows);
|
||||||
|
let mut ct_rgsw_lhs_in: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw_lhs_in, rows);
|
||||||
|
let mut ct_rgsw_lhs_out: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw_lhs_out, rows);
|
||||||
|
let mut pt_rgsw_lhs: ScalarZnx<Vec<u8>> = module.new_scalar_znx(1);
|
||||||
|
let mut pt_rgsw_rhs: ScalarZnx<Vec<u8>> = module.new_scalar_znx(1);
|
||||||
|
|
||||||
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
|
// Random input plaintext
|
||||||
|
pt_rgsw_lhs.fill_ternary_prob(0, 0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let k: usize = 1;
|
||||||
|
|
||||||
|
pt_rgsw_rhs.to_mut().raw_mut()[k] = 1; //X^{k}
|
||||||
|
|
||||||
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_rgsw_rhs.size())
|
||||||
|
| RLWECtDft::decrypt_scratch_space(&module, ct_rgsw_lhs_out.size())
|
||||||
|
| RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw_lhs_in.size())
|
||||||
|
| RGSWCt::prod_by_rgsw_scratch_space(
|
||||||
|
&module,
|
||||||
|
ct_rgsw_lhs_out.size(),
|
||||||
|
ct_rgsw_lhs_in.size(),
|
||||||
|
ct_rgsw_rhs.size(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut sk: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut sk_dft: SecretKeyDft<Vec<u8>, FFT64> = SecretKeyDft::new(&module);
|
||||||
|
sk_dft.dft(&module, &sk);
|
||||||
|
|
||||||
|
ct_rgsw_rhs.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&pt_rgsw_rhs,
|
||||||
|
&sk_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw_lhs_in.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&pt_rgsw_lhs,
|
||||||
|
&sk_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw_lhs_out.prod_by_rgsw(&module, &ct_rgsw_lhs_in, &ct_rgsw_rhs, scratch.borrow());
|
||||||
|
|
||||||
|
let mut ct_rlwe_dft: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_rgsw_lhs_out);
|
||||||
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw_lhs_out);
|
||||||
|
let mut pt_dft: VecZnxDft<Vec<u8>, FFT64> = module.new_vec_znx_dft(1, ct_rgsw_lhs_out.size());
|
||||||
|
let mut pt_big: VecZnxBig<Vec<u8>, FFT64> = module.new_vec_znx_big(1, ct_rgsw_lhs_out.size());
|
||||||
|
let mut pt_want: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw_lhs_out);
|
||||||
|
|
||||||
|
module.vec_znx_rotate_inplace(k as i64, &mut pt_rgsw_lhs, 0);
|
||||||
|
|
||||||
|
(0..ct_rgsw_lhs_out.cols()).for_each(|col_j| {
|
||||||
|
(0..ct_rgsw_lhs_out.rows()).for_each(|row_i| {
|
||||||
|
module.vec_znx_add_scalar_inplace(&mut pt_want, 0, row_i, &pt_rgsw_lhs, 0);
|
||||||
|
|
||||||
|
if col_j == 1 {
|
||||||
|
module.vec_znx_dft(&mut pt_dft, 0, &pt_want, 0);
|
||||||
|
module.svp_apply_inplace(&mut pt_dft, 0, &sk_dft, 0);
|
||||||
|
module.vec_znx_idft_tmp_a(&mut pt_big, 0, &mut pt_dft, 0);
|
||||||
|
module.vec_znx_big_normalize(log_base2k, &mut pt_want, 0, &pt_big, 0, scratch.borrow());
|
||||||
|
}
|
||||||
|
|
||||||
|
ct_rgsw_lhs_out.get_row(&module, row_i, col_j, &mut ct_rlwe_dft);
|
||||||
|
ct_rlwe_dft.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
||||||
|
|
||||||
|
module.vec_znx_sub_ab_inplace(&mut pt, 0, &pt_want, 0);
|
||||||
|
|
||||||
|
let noise_have: f64 = pt.data.std(0, log_base2k).log2();
|
||||||
|
|
||||||
|
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||||
|
let var_gct_err_rhs: f64 = 0f64;
|
||||||
|
|
||||||
|
let var_msg: f64 = 1f64 / module.n() as f64; // X^{k}
|
||||||
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
|
module.n() as f64,
|
||||||
|
log_base2k,
|
||||||
|
0.5,
|
||||||
|
var_msg,
|
||||||
|
var_a0_err,
|
||||||
|
var_a1_err,
|
||||||
|
var_gct_err_lhs,
|
||||||
|
var_gct_err_rhs,
|
||||||
|
log_k_rgsw_lhs_in,
|
||||||
|
log_k_rgsw_rhs,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
(noise_have - noise_want).abs() <= 0.1,
|
||||||
|
"have: {} want: {}",
|
||||||
|
noise_have,
|
||||||
|
noise_want
|
||||||
|
);
|
||||||
|
|
||||||
|
pt_want.data.zero();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_prod_by_rgsw_inplace() {
|
||||||
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
|
let log_base2k: usize = 12;
|
||||||
|
let log_k_rgsw_rhs: usize = 60;
|
||||||
|
let log_k_rgsw_lhs: usize = 45;
|
||||||
|
let rows: usize = (log_k_rgsw_lhs + log_base2k - 1) / log_base2k;
|
||||||
|
|
||||||
|
let sigma: f64 = 3.2;
|
||||||
|
let bound: f64 = sigma * 6.0;
|
||||||
|
|
||||||
|
let mut ct_rgsw_rhs: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw_rhs, rows);
|
||||||
|
let mut ct_rgsw_lhs: RGSWCt<Vec<u8>, FFT64> = RGSWCt::new(&module, log_base2k, log_k_rgsw_lhs, rows);
|
||||||
|
let mut pt_rgsw_lhs: ScalarZnx<Vec<u8>> = module.new_scalar_znx(1);
|
||||||
|
let mut pt_rgsw_rhs: ScalarZnx<Vec<u8>> = module.new_scalar_znx(1);
|
||||||
|
|
||||||
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
|
// Random input plaintext
|
||||||
|
pt_rgsw_lhs.fill_ternary_prob(0, 0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let k: usize = 1;
|
||||||
|
|
||||||
|
pt_rgsw_rhs.to_mut().raw_mut()[k] = 1; //X^{k}
|
||||||
|
|
||||||
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_rgsw_rhs.size())
|
||||||
|
| RLWECtDft::decrypt_scratch_space(&module, ct_rgsw_lhs.size())
|
||||||
|
| RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw_lhs.size())
|
||||||
|
| RGSWCt::prod_by_rgsw_inplace_scratch_space(&module, ct_rgsw_lhs.size(), ct_rgsw_rhs.size()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut sk: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
|
let mut sk_dft: SecretKeyDft<Vec<u8>, FFT64> = SecretKeyDft::new(&module);
|
||||||
|
sk_dft.dft(&module, &sk);
|
||||||
|
|
||||||
|
ct_rgsw_rhs.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&pt_rgsw_rhs,
|
||||||
|
&sk_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw_lhs.encrypt_sk(
|
||||||
|
&module,
|
||||||
|
&pt_rgsw_lhs,
|
||||||
|
&sk_dft,
|
||||||
|
&mut source_xa,
|
||||||
|
&mut source_xe,
|
||||||
|
sigma,
|
||||||
|
bound,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ct_rgsw_lhs.prod_by_rgsw_inplace(&module, &ct_rgsw_rhs, scratch.borrow());
|
||||||
|
|
||||||
|
let mut ct_rlwe_dft: RLWECtDft<Vec<u8>, FFT64> = RLWECtDft::new(&module, log_base2k, log_k_rgsw_lhs);
|
||||||
|
let mut pt: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw_lhs);
|
||||||
|
let mut pt_dft: VecZnxDft<Vec<u8>, FFT64> = module.new_vec_znx_dft(1, ct_rgsw_lhs.size());
|
||||||
|
let mut pt_big: VecZnxBig<Vec<u8>, FFT64> = module.new_vec_znx_big(1, ct_rgsw_lhs.size());
|
||||||
|
let mut pt_want: RLWEPt<Vec<u8>> = RLWEPt::new(&module, log_base2k, log_k_rgsw_lhs);
|
||||||
|
|
||||||
|
module.vec_znx_rotate_inplace(k as i64, &mut pt_rgsw_lhs, 0);
|
||||||
|
|
||||||
|
(0..ct_rgsw_lhs.cols()).for_each(|col_j| {
|
||||||
|
(0..ct_rgsw_lhs.rows()).for_each(|row_i| {
|
||||||
|
module.vec_znx_add_scalar_inplace(&mut pt_want, 0, row_i, &pt_rgsw_lhs, 0);
|
||||||
|
|
||||||
|
if col_j == 1 {
|
||||||
|
module.vec_znx_dft(&mut pt_dft, 0, &pt_want, 0);
|
||||||
|
module.svp_apply_inplace(&mut pt_dft, 0, &sk_dft, 0);
|
||||||
|
module.vec_znx_idft_tmp_a(&mut pt_big, 0, &mut pt_dft, 0);
|
||||||
|
module.vec_znx_big_normalize(log_base2k, &mut pt_want, 0, &pt_big, 0, scratch.borrow());
|
||||||
|
}
|
||||||
|
|
||||||
|
ct_rgsw_lhs.get_row(&module, row_i, col_j, &mut ct_rlwe_dft);
|
||||||
|
ct_rlwe_dft.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
||||||
|
|
||||||
|
module.vec_znx_sub_ab_inplace(&mut pt, 0, &pt_want, 0);
|
||||||
|
|
||||||
|
let noise_have: f64 = pt.data.std(0, log_base2k).log2();
|
||||||
|
|
||||||
|
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||||
|
let var_gct_err_rhs: f64 = 0f64;
|
||||||
|
|
||||||
|
let var_msg: f64 = 1f64 / module.n() as f64; // X^{k}
|
||||||
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
|
module.n() as f64,
|
||||||
|
log_base2k,
|
||||||
|
0.5,
|
||||||
|
var_msg,
|
||||||
|
var_a0_err,
|
||||||
|
var_a1_err,
|
||||||
|
var_gct_err_lhs,
|
||||||
|
var_gct_err_rhs,
|
||||||
|
log_k_rgsw_lhs,
|
||||||
|
log_k_rgsw_rhs,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
(noise_have - noise_want).abs() <= 0.1,
|
||||||
|
"have: {} want: {}",
|
||||||
|
noise_have,
|
||||||
|
noise_want
|
||||||
|
);
|
||||||
|
|
||||||
|
pt_want.data.zero();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.free();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn noise_rgsw_product(
|
||||||
n: f64,
|
n: f64,
|
||||||
log_base2k: usize,
|
log_base2k: usize,
|
||||||
var_xs: f64,
|
var_xs: f64,
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
#[cfg(test)]
|
use base2k::{
|
||||||
mod tests_rlwe {
|
|
||||||
use base2k::{
|
|
||||||
Decoding, Encoding, FFT64, FillUniform, Module, ScalarZnx, ScalarZnxAlloc, ScratchOwned, Stats, VecZnxOps, VecZnxToMut,
|
Decoding, Encoding, FFT64, FillUniform, Module, ScalarZnx, ScalarZnxAlloc, ScratchOwned, Stats, VecZnxOps, VecZnxToMut,
|
||||||
ZnxViewMut, ZnxZero,
|
ZnxViewMut, ZnxZero,
|
||||||
};
|
};
|
||||||
use itertools::izip;
|
use itertools::izip;
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
elem::{FromProdBy, FromProdByScratchSpace, Infos, ProdBy, ProdByScratchSpace},
|
elem::{Infos, ProdInplace, ProdInplaceScratchSpace, ProdScratchSpace, Product},
|
||||||
grlwe::GRLWECt,
|
grlwe::GRLWECt,
|
||||||
keys::{PublicKey, SecretKey, SecretKeyDft},
|
keys::{PublicKey, SecretKey, SecretKeyDft},
|
||||||
rgsw::RGSWCt,
|
rgsw::RGSWCt,
|
||||||
rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
||||||
test_fft64::{grlwe::noise_grlwe_rlwe_product, rgsw::noise_rgsw_rlwe_product},
|
test_fft64::{grlwe::noise_grlwe_rlwe_product, rgsw::noise_rgsw_product},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encrypt_sk() {
|
fn encrypt_sk() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(32);
|
let module: Module<FFT64> = Module::<FFT64>::new(32);
|
||||||
let log_base2k: usize = 8;
|
let log_base2k: usize = 8;
|
||||||
let log_k_ct: usize = 54;
|
let log_k_ct: usize = 54;
|
||||||
@@ -85,10 +83,10 @@ mod tests_rlwe {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encrypt_zero_sk() {
|
fn encrypt_zero_sk() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(1024);
|
let module: Module<FFT64> = Module::<FFT64>::new(1024);
|
||||||
let log_base2k: usize = 8;
|
let log_base2k: usize = 8;
|
||||||
let log_k_ct: usize = 55;
|
let log_k_ct: usize = 55;
|
||||||
@@ -127,10 +125,10 @@ mod tests_rlwe {
|
|||||||
|
|
||||||
assert!((sigma - pt.data.std(0, log_base2k) * (log_k_ct as f64).exp2()) <= 0.2);
|
assert!((sigma - pt.data.std(0, log_base2k) * (log_k_ct as f64).exp2()) <= 0.2);
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encrypt_pk() {
|
fn encrypt_pk() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(32);
|
let module: Module<FFT64> = Module::<FFT64>::new(32);
|
||||||
let log_base2k: usize = 8;
|
let log_base2k: usize = 8;
|
||||||
let log_k_ct: usize = 54;
|
let log_k_ct: usize = 54;
|
||||||
@@ -198,10 +196,10 @@ mod tests_rlwe {
|
|||||||
assert!(((1.0f64 / 12.0).sqrt() - pt_want.data.std(0, log_base2k) * (log_k_ct as f64).exp2()).abs() < 0.2);
|
assert!(((1.0f64 / 12.0).sqrt() - pt_want.data.std(0, log_base2k) * (log_k_ct as f64).exp2()).abs() < 0.2);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_prod_by_grlwe() {
|
fn prod_by_grlwe() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -231,7 +229,7 @@ mod tests_rlwe {
|
|||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
||||||
| RLWECt::from_prod_by_grlwe_scratch_space(
|
| RLWECt::prod_by_grlwe_scratch_space(
|
||||||
&module,
|
&module,
|
||||||
ct_rlwe_out.size(),
|
ct_rlwe_out.size(),
|
||||||
ct_rlwe_in.size(),
|
ct_rlwe_in.size(),
|
||||||
@@ -273,7 +271,7 @@ mod tests_rlwe {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe_out.from_prod_by_grlwe(&module, &ct_rlwe_in, &ct_grlwe, scratch.borrow());
|
ct_rlwe_out.prod_by_grlwe(&module, &ct_rlwe_in, &ct_grlwe, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
||||||
|
|
||||||
@@ -300,10 +298,10 @@ mod tests_rlwe {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prod_grlwe() {
|
fn prod_by_grlwe_inplace() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -331,7 +329,7 @@ mod tests_rlwe {
|
|||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECt::prod_by_grlwe_scratch_space(&module, ct_rlwe.size(), ct_grlwe.size()),
|
| RLWECt::prod_by_grlwe_inplace_scratch_space(&module, ct_rlwe.size(), ct_grlwe.size()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
@@ -368,7 +366,7 @@ mod tests_rlwe {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe.prod_by_grlwe(&module, &ct_grlwe, scratch.borrow());
|
ct_rlwe.prod_by_grlwe_inplace(&module, &ct_grlwe, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
ct_rlwe.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
||||||
|
|
||||||
@@ -395,10 +393,10 @@ mod tests_rlwe {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_prod_by_rgsw() {
|
fn prod_by_rgsw() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -435,7 +433,7 @@ mod tests_rlwe {
|
|||||||
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
||||||
| RLWECt::from_prod_by_rgsw_scratch_space(
|
| RLWECt::prod_by_grlwe_scratch_space(
|
||||||
&module,
|
&module,
|
||||||
ct_rlwe_out.size(),
|
ct_rlwe_out.size(),
|
||||||
ct_rlwe_in.size(),
|
ct_rlwe_in.size(),
|
||||||
@@ -471,7 +469,7 @@ mod tests_rlwe {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe_out.from_prod_by_rgsw(&module, &ct_rlwe_in, &ct_rgsw, scratch.borrow());
|
ct_rlwe_out.prod_by_rgsw(&module, &ct_rlwe_in, &ct_rgsw, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
||||||
|
|
||||||
@@ -488,7 +486,7 @@ mod tests_rlwe {
|
|||||||
let var_a0_err: f64 = sigma * sigma;
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
let var_a1_err: f64 = 1f64 / 12f64;
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
let noise_want: f64 = noise_rgsw_rlwe_product(
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
module.n() as f64,
|
module.n() as f64,
|
||||||
log_base2k,
|
log_base2k,
|
||||||
0.5,
|
0.5,
|
||||||
@@ -509,10 +507,10 @@ mod tests_rlwe {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prod_by_rgsw() {
|
fn prod_by_rgsw_inplace() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -548,7 +546,7 @@ mod tests_rlwe {
|
|||||||
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECt::prod_by_rgsw_scratch_space(&module, ct_rlwe.size(), ct_rgsw.size()),
|
| RLWECt::prod_by_rgsw_inplace_scratch_space(&module, ct_rlwe.size(), ct_rgsw.size()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
let mut sk: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
@@ -579,7 +577,7 @@ mod tests_rlwe {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe.prod_by_rgsw(&module, &ct_rgsw, scratch.borrow());
|
ct_rlwe.prod_by_rgsw_inplace(&module, &ct_rgsw, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
ct_rlwe.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
||||||
|
|
||||||
@@ -596,7 +594,7 @@ mod tests_rlwe {
|
|||||||
let var_a0_err: f64 = sigma * sigma;
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
let var_a1_err: f64 = 1f64 / 12f64;
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
let noise_want: f64 = noise_rgsw_rlwe_product(
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
module.n() as f64,
|
module.n() as f64,
|
||||||
log_base2k,
|
log_base2k,
|
||||||
0.5,
|
0.5,
|
||||||
@@ -617,5 +615,4 @@ mod tests_rlwe {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,16 @@
|
|||||||
#[cfg(test)]
|
use crate::{
|
||||||
mod tests {
|
elem::{Infos, ProdInplace, ProdInplaceScratchSpace, ProdScratchSpace, Product},
|
||||||
use crate::{
|
|
||||||
elem::{FromProdBy, FromProdByScratchSpace, Infos, ProdBy, ProdByScratchSpace},
|
|
||||||
grlwe::GRLWECt,
|
grlwe::GRLWECt,
|
||||||
keys::{SecretKey, SecretKeyDft},
|
keys::{SecretKey, SecretKeyDft},
|
||||||
rgsw::RGSWCt,
|
rgsw::RGSWCt,
|
||||||
rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
||||||
test_fft64::{grlwe::noise_grlwe_rlwe_product, rgsw::noise_rgsw_rlwe_product},
|
test_fft64::{grlwe::noise_grlwe_rlwe_product, rgsw::noise_rgsw_product},
|
||||||
};
|
};
|
||||||
use base2k::{
|
use base2k::{FFT64, FillUniform, Module, ScalarZnx, ScalarZnxAlloc, ScratchOwned, Stats, VecZnxOps, VecZnxToMut, ZnxViewMut};
|
||||||
FFT64, FillUniform, Module, ScalarZnx, ScalarZnxAlloc, ScratchOwned, Stats, VecZnxOps, VecZnxToMut, ZnxViewMut,
|
use sampling::source::Source;
|
||||||
};
|
|
||||||
use sampling::source::Source;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_prod_by_grlwe() {
|
fn by_grlwe_inplace() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -46,7 +42,7 @@ mod tests {
|
|||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
||||||
| RLWECtDft::from_prod_by_grlwe_scratch_space(
|
| RLWECtDft::prod_by_grlwe_scratch_space(
|
||||||
&module,
|
&module,
|
||||||
ct_rlwe_out.size(),
|
ct_rlwe_out.size(),
|
||||||
ct_rlwe_in.size(),
|
ct_rlwe_in.size(),
|
||||||
@@ -89,7 +85,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe_in.dft(&module, &mut ct_rlwe_in_dft);
|
ct_rlwe_in.dft(&module, &mut ct_rlwe_in_dft);
|
||||||
ct_rlwe_out_dft.from_prod_by_grlwe(&module, &ct_rlwe_in_dft, &ct_grlwe, scratch.borrow());
|
ct_rlwe_out_dft.prod_by_grlwe(&module, &ct_rlwe_in_dft, &ct_grlwe, scratch.borrow());
|
||||||
ct_rlwe_out_dft.idft(&module, &mut ct_rlwe_out, scratch.borrow());
|
ct_rlwe_out_dft.idft(&module, &mut ct_rlwe_out, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
||||||
@@ -117,10 +113,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prod_by_grlwe() {
|
fn prod_by_grlwe_inplace() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -149,7 +145,7 @@ mod tests {
|
|||||||
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
GRLWECt::encrypt_sk_scratch_space(&module, ct_grlwe.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECtDft::prod_by_grlwe_scratch_space(&module, ct_rlwe_dft.size(), ct_grlwe.size()),
|
| RLWECtDft::prod_by_grlwe_inplace_scratch_space(&module, ct_rlwe_dft.size(), ct_grlwe.size()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
let mut sk0: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
@@ -187,7 +183,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe.dft(&module, &mut ct_rlwe_dft);
|
ct_rlwe.dft(&module, &mut ct_rlwe_dft);
|
||||||
ct_rlwe_dft.prod_by_grlwe(&module, &ct_grlwe, scratch.borrow());
|
ct_rlwe_dft.prod_by_grlwe_inplace(&module, &ct_grlwe, scratch.borrow());
|
||||||
ct_rlwe_dft.idft(&module, &mut ct_rlwe, scratch.borrow());
|
ct_rlwe_dft.idft(&module, &mut ct_rlwe, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
ct_rlwe.decrypt(&module, &mut pt_have, &sk1_dft, scratch.borrow());
|
||||||
@@ -215,10 +211,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_prod_by_rgsw() {
|
fn prod_by_rgsw() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -257,7 +253,7 @@ mod tests {
|
|||||||
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe_out.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe_in.size())
|
||||||
| RLWECt::from_prod_by_rgsw_scratch_space(
|
| RLWECt::prod_by_rgsw_scratch_space(
|
||||||
&module,
|
&module,
|
||||||
ct_rlwe_out.size(),
|
ct_rlwe_out.size(),
|
||||||
ct_rlwe_in.size(),
|
ct_rlwe_in.size(),
|
||||||
@@ -294,7 +290,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe_in.dft(&module, &mut ct_rlwe_dft_in);
|
ct_rlwe_in.dft(&module, &mut ct_rlwe_dft_in);
|
||||||
ct_rlwe_dft_out.from_prod_by_rgsw(&module, &ct_rlwe_dft_in, &ct_rgsw, scratch.borrow());
|
ct_rlwe_dft_out.prod_by_rgsw(&module, &ct_rlwe_dft_in, &ct_rgsw, scratch.borrow());
|
||||||
ct_rlwe_dft_out.idft(&module, &mut ct_rlwe_out, scratch.borrow());
|
ct_rlwe_dft_out.idft(&module, &mut ct_rlwe_out, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
||||||
@@ -312,7 +308,7 @@ mod tests {
|
|||||||
let var_a0_err: f64 = sigma * sigma;
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
let var_a1_err: f64 = 1f64 / 12f64;
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
let noise_want: f64 = noise_rgsw_rlwe_product(
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
module.n() as f64,
|
module.n() as f64,
|
||||||
log_base2k,
|
log_base2k,
|
||||||
0.5,
|
0.5,
|
||||||
@@ -333,10 +329,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prod_by_rgsw() {
|
fn prod_by_rgsw_inplace() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
let module: Module<FFT64> = Module::<FFT64>::new(2048);
|
||||||
let log_base2k: usize = 12;
|
let log_base2k: usize = 12;
|
||||||
let log_k_grlwe: usize = 60;
|
let log_k_grlwe: usize = 60;
|
||||||
@@ -373,7 +369,7 @@ mod tests {
|
|||||||
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
||||||
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::decrypt_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
| RLWECt::encrypt_sk_scratch_space(&module, ct_rlwe.size())
|
||||||
| RLWECt::prod_by_rgsw_scratch_space(&module, ct_rlwe.size(), ct_rgsw.size()),
|
| RLWECt::prod_by_rgsw_inplace_scratch_space(&module, ct_rlwe.size(), ct_rgsw.size()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
let mut sk: SecretKey<Vec<u8>> = SecretKey::new(&module);
|
||||||
@@ -405,7 +401,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ct_rlwe.dft(&module, &mut ct_rlwe_dft);
|
ct_rlwe.dft(&module, &mut ct_rlwe_dft);
|
||||||
ct_rlwe_dft.prod_by_rgsw(&module, &ct_rgsw, scratch.borrow());
|
ct_rlwe_dft.prod_by_rgsw_inplace(&module, &ct_rgsw, scratch.borrow());
|
||||||
ct_rlwe_dft.idft(&module, &mut ct_rlwe, scratch.borrow());
|
ct_rlwe_dft.idft(&module, &mut ct_rlwe, scratch.borrow());
|
||||||
|
|
||||||
ct_rlwe.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
ct_rlwe.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
||||||
@@ -423,7 +419,7 @@ mod tests {
|
|||||||
let var_a0_err: f64 = sigma * sigma;
|
let var_a0_err: f64 = sigma * sigma;
|
||||||
let var_a1_err: f64 = 1f64 / 12f64;
|
let var_a1_err: f64 = 1f64 / 12f64;
|
||||||
|
|
||||||
let noise_want: f64 = noise_rgsw_rlwe_product(
|
let noise_want: f64 = noise_rgsw_product(
|
||||||
module.n() as f64,
|
module.n() as f64,
|
||||||
log_base2k,
|
log_base2k,
|
||||||
0.5,
|
0.5,
|
||||||
@@ -444,5 +440,4 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module.free();
|
module.free();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user