mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
fixed rgsw mul rlwe test
This commit is contained in:
@@ -194,7 +194,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 + ZnxInfos,
|
VecZnx<R>: VecZnxToMut,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use base2k::{
|
use base2k::{
|
||||||
FillUniform, Module, ScalarZnx, ScalarZnxAlloc, ScalarZnxDftOps, ScratchOwned, Stats, VecZnxBig, VecZnxBigAlloc, VecZnxBigOps, VecZnxDft, VecZnxDftAlloc, VecZnxDftOps, VecZnxOps, VecZnxToMut, VecZnxToRef, ZnxView, ZnxViewMut, ZnxZero, FFT64
|
FFT64, Module, ScalarZnx, ScalarZnxAlloc, ScalarZnxDftOps, ScratchOwned, Stats, VecZnxBig, VecZnxBigAlloc, VecZnxBigOps,
|
||||||
|
VecZnxDft, VecZnxDftAlloc, VecZnxDftOps, VecZnxOps, VecZnxToMut, ZnxViewMut, ZnxZero,
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
@@ -9,7 +10,8 @@ mod tests {
|
|||||||
elem::Infos,
|
elem::Infos,
|
||||||
elem_rgsw::RGSWCt,
|
elem_rgsw::RGSWCt,
|
||||||
elem_rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
elem_rlwe::{RLWECt, RLWECtDft, RLWEPt},
|
||||||
keys::{SecretKey, SecretKeyDft}, test_fft64::elem_rgsw::noise_rgsw_rlwe_product,
|
keys::{SecretKey, SecretKeyDft},
|
||||||
|
test_fft64::elem_rgsw::noise_rgsw_rlwe_product,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -87,7 +89,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mul_rlwe() {
|
fn mul_rlwe() {
|
||||||
let module: Module<FFT64> = Module::<FFT64>::new(32);
|
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;
|
||||||
let log_k_rlwe_in: usize = 45;
|
let log_k_rlwe_in: usize = 45;
|
||||||
@@ -109,13 +111,15 @@ mod tests {
|
|||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
// Random input plaintext
|
// Random input plaintext
|
||||||
//pt_want
|
// pt_want
|
||||||
// .data
|
// .data
|
||||||
// .fill_uniform(log_base2k, 0, pt_want.size(), &mut source_xa);
|
// .fill_uniform(log_base2k, 0, pt_want.size(), &mut source_xa);
|
||||||
|
|
||||||
pt_want.to_mut().at_mut(0, 0)[0] = 1;
|
pt_want.to_mut().at_mut(0, 0)[1] = 1;
|
||||||
|
|
||||||
pt_rgsw.raw_mut()[1] = 1; // X^{1}
|
let r: usize = 1;
|
||||||
|
|
||||||
|
pt_rgsw.raw_mut()[r] = 1; // X^{r}
|
||||||
|
|
||||||
let mut scratch: ScratchOwned = ScratchOwned::new(
|
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||||
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
RGSWCt::encrypt_sk_scratch_space(&module, ct_rgsw.size())
|
||||||
@@ -161,22 +165,28 @@ mod tests {
|
|||||||
|
|
||||||
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
ct_rlwe_out.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
||||||
|
|
||||||
|
module.vec_znx_rotate_inplace(r as i64, &mut pt_want, 0);
|
||||||
|
|
||||||
module.vec_znx_sub_ab_inplace(&mut pt_have, 0, &pt_want, 0);
|
module.vec_znx_sub_ab_inplace(&mut pt_have, 0, &pt_want, 0);
|
||||||
|
|
||||||
|
|
||||||
println!("{}", pt_want.data);
|
|
||||||
println!("{}", pt_have.data);
|
|
||||||
|
|
||||||
let noise_have: f64 = pt_have.data.std(0, log_base2k).log2();
|
let noise_have: f64 = pt_have.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_rlwe_product(
|
let noise_want: f64 = noise_rgsw_rlwe_product(
|
||||||
module.n() as f64,
|
module.n() as f64,
|
||||||
log_base2k,
|
log_base2k,
|
||||||
0.5,
|
0.5,
|
||||||
0.5,
|
var_msg,
|
||||||
0f64,
|
var_a0_err,
|
||||||
0f64,
|
var_a1_err,
|
||||||
sigma * sigma,
|
var_gct_err_lhs,
|
||||||
0f64,
|
var_gct_err_rhs,
|
||||||
log_k_rlwe_in,
|
log_k_rlwe_in,
|
||||||
log_k_grlwe,
|
log_k_grlwe,
|
||||||
);
|
);
|
||||||
@@ -222,4 +232,4 @@ pub(crate) fn noise_rgsw_rlwe_product(
|
|||||||
noise = noise.sqrt();
|
noise = noise.sqrt();
|
||||||
noise /= b_scale;
|
noise /= b_scale;
|
||||||
noise.log2().min(-1.0) // max noise is [-2^{-1}, 2^{-1}]
|
noise.log2().min(-1.0) // max noise is [-2^{-1}, 2^{-1}]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user