diff --git a/core/src/gglwe_ciphertext.rs b/core/src/gglwe_ciphertext.rs index 9d7c45a..9d2c79a 100644 --- a/core/src/gglwe_ciphertext.rs +++ b/core/src/gglwe_ciphertext.rs @@ -97,7 +97,6 @@ where source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where ScalarZnx: ScalarZnxToRef, @@ -153,7 +152,6 @@ where source_xa, source_xe, sigma, - bound, scratch_3, ); diff --git a/core/src/ggsw_ciphertext.rs b/core/src/ggsw_ciphertext.rs index 9d42df8..d277d78 100644 --- a/core/src/ggsw_ciphertext.rs +++ b/core/src/ggsw_ciphertext.rs @@ -119,7 +119,6 @@ where source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where ScalarZnx: ScalarZnxToRef, @@ -168,7 +167,6 @@ where source_xa, source_xe, sigma, - bound, scrach_2, ); diff --git a/core/src/glwe_ciphertext.rs b/core/src/glwe_ciphertext.rs index 56ca1a9..5f8d086 100644 --- a/core/src/glwe_ciphertext.rs +++ b/core/src/glwe_ciphertext.rs @@ -7,6 +7,7 @@ use base2k::{ use sampling::source::Source; use crate::{ + SIX_SIGMA, elem::Infos, gglwe_ciphertext::GGLWECiphertext, ggsw_ciphertext::GGSWCiphertext, @@ -145,7 +146,6 @@ where source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where VecZnx: VecZnxToRef, @@ -158,7 +158,6 @@ where source_xa, source_xe, sigma, - bound, scratch, ); } @@ -170,14 +169,11 @@ where source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where ScalarZnxDft: ScalarZnxDftToRef, { - self.encrypt_sk_private( - module, None, sk_dft, source_xa, source_xe, sigma, bound, scratch, - ); + self.encrypt_sk_private(module, None, sk_dft, source_xa, source_xe, sigma, scratch); } pub fn encrypt_pk( @@ -188,7 +184,6 @@ where source_xu: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where VecZnx: VecZnxToRef, @@ -201,7 +196,6 @@ where source_xu, source_xe, sigma, - bound, scratch, ); } @@ -213,14 +207,11 @@ where source_xu: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where VecZnxDft: VecZnxDftToRef, { - self.encrypt_pk_private( - module, None, pk, source_xu, source_xe, sigma, bound, scratch, - ); + self.encrypt_pk_private(module, None, pk, source_xu, source_xe, sigma, scratch); } pub fn keyswitch( @@ -279,7 +270,6 @@ where source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where VecZnx: VecZnxToRef, @@ -335,7 +325,7 @@ where } // c[0] += e - c0_big.add_normal(log_base2k, 0, log_k, source_xe, sigma, bound); + c0_big.add_normal(log_base2k, 0, log_k, source_xe, sigma, sigma * SIX_SIGMA); // c[0] += m if col = 0 if let Some((pt, col)) = pt { @@ -356,7 +346,6 @@ where source_xu: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where VecZnx: VecZnxToRef, @@ -406,7 +395,7 @@ where let mut ci_big = module.vec_znx_idft_consume(ci_dft); // ci_big = u * pk[i] + e - ci_big.add_normal(log_base2k, 0, pk.k(), source_xe, sigma, bound); + ci_big.add_normal(log_base2k, 0, pk.k(), source_xe, sigma, sigma * SIX_SIGMA); // ci_big = u * pk[i] + e + m (if col = i) if let Some((pt, col)) = pt { diff --git a/core/src/glwe_ciphertext_fourier.rs b/core/src/glwe_ciphertext_fourier.rs index bcc7648..e31d0dc 100644 --- a/core/src/glwe_ciphertext_fourier.rs +++ b/core/src/glwe_ciphertext_fourier.rs @@ -122,7 +122,6 @@ where source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where ScalarZnxDft: ScalarZnxDftToRef, @@ -133,9 +132,7 @@ where basek: self.basek, k: self.k, }; - ct_idft.encrypt_zero_sk( - module, sk_dft, source_xa, source_xe, sigma, bound, scratch_1, - ); + ct_idft.encrypt_zero_sk(module, sk_dft, source_xa, source_xe, sigma, scratch_1); ct_idft.dft(module, self); } diff --git a/core/src/keys.rs b/core/src/keys.rs index d57fa73..8a4d5e1 100644 --- a/core/src/keys.rs +++ b/core/src/keys.rs @@ -216,7 +216,6 @@ impl GLWEPublicKey { source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, ) where VecZnxDft: VecZnxDftToMut + VecZnxDftToRef, ScalarZnxDft: ScalarZnxDftToRef + ZnxInfos, @@ -241,7 +240,6 @@ impl GLWEPublicKey { source_xa, source_xe, sigma, - bound, scratch.borrow(), ); self.dist = sk_dft.dist; diff --git a/core/src/keyswitch_key.rs b/core/src/keyswitch_key.rs index 33d2a45..f9500a7 100644 --- a/core/src/keyswitch_key.rs +++ b/core/src/keyswitch_key.rs @@ -111,15 +111,13 @@ where source_xa: &mut Source, source_xe: &mut Source, sigma: f64, - bound: f64, scratch: &mut Scratch, ) where ScalarZnx: ScalarZnxToRef, ScalarZnxDft: ScalarZnxDftToRef, { - self.0.encrypt_sk( - module, pt, sk_dft, source_xa, source_xe, sigma, bound, scratch, - ); + self.0 + .encrypt_sk(module, pt, sk_dft, source_xa, source_xe, sigma, scratch); } } diff --git a/core/src/lib.rs b/core/src/lib.rs index cdd83d1..14392df 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -10,3 +10,5 @@ pub mod keyswitch_key; mod test_fft64; mod utils; pub mod vec_glwe_product; + +pub(crate) const SIX_SIGMA: f64 = 6.0; diff --git a/core/src/test_fft64/gglwe.rs b/core/src/test_fft64/gglwe.rs index 7a7de6d..e4a566d 100644 --- a/core/src/test_fft64/gglwe.rs +++ b/core/src/test_fft64/gglwe.rs @@ -21,7 +21,6 @@ fn encrypt_sk() { let rank_out: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_ct, rows, rank, rank_out); let mut pt: GLWEPlaintext> = GLWEPlaintext::new(&module, log_base2k, log_k_ct); @@ -52,7 +51,6 @@ fn encrypt_sk() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -77,7 +75,6 @@ fn keyswitch() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe_s0s1: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank); @@ -127,7 +124,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -139,7 +135,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -188,7 +183,6 @@ fn keyswitch_inplace() { let rank_out: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe_s0s1: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank_out); @@ -231,7 +225,6 @@ fn keyswitch_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -243,7 +236,6 @@ fn keyswitch_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -294,7 +286,6 @@ fn external_product() { let rank_out: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe_in: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank_out); @@ -341,7 +332,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -352,7 +342,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -408,11 +397,10 @@ fn external_product_inplace() { let log_k_grlwe: usize = 60; let rows: usize = (log_k_grlwe + log_base2k - 1) / log_base2k; - let rank = 1; - let rank_out = 1; + let rank: usize = 1; + let rank_out: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank_out); @@ -452,7 +440,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -463,7 +450,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); diff --git a/core/src/test_fft64/ggsw.rs b/core/src/test_fft64/ggsw.rs index ce16ea5..f1903c1 100644 --- a/core/src/test_fft64/ggsw.rs +++ b/core/src/test_fft64/ggsw.rs @@ -23,7 +23,6 @@ fn encrypt_sk() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_ct, rows, rank); let mut pt_have: GLWEPlaintext> = GLWEPlaintext::new(&module, log_base2k, log_k_ct); @@ -54,7 +53,6 @@ fn encrypt_sk() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -99,7 +97,6 @@ fn keyswitch() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank); @@ -145,7 +142,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -156,7 +152,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -220,7 +215,6 @@ fn keyswitch_inplace() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank); @@ -260,7 +254,6 @@ fn keyswitch_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -271,7 +264,6 @@ fn keyswitch_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -336,7 +328,6 @@ fn external_product() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_rgsw_rhs: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_rgsw_rhs, rows, rank); let mut ct_rgsw_lhs_in: GGSWCiphertext, FFT64> = @@ -382,7 +373,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -393,7 +383,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -468,7 +457,6 @@ fn external_product_inplace() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_rgsw_rhs: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_rgsw_rhs, rows, rank); let mut ct_rgsw_lhs: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_rgsw_lhs, rows, rank); @@ -506,7 +494,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -517,7 +504,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); diff --git a/core/src/test_fft64/glwe.rs b/core/src/test_fft64/glwe.rs index 5ffe2dd..8e97eff 100644 --- a/core/src/test_fft64/glwe.rs +++ b/core/src/test_fft64/glwe.rs @@ -1,6 +1,6 @@ use base2k::{ Decoding, Encoding, FFT64, FillUniform, Module, ScalarZnx, ScalarZnxAlloc, ScratchOwned, Stats, VecZnxOps, VecZnxToMut, - ZnxView, ZnxViewMut, ZnxZero, + ZnxViewMut, ZnxZero, }; use itertools::izip; use sampling::source::Source; @@ -33,7 +33,6 @@ fn encrypt_sk_rank_3() { fn encrypt_sk(log_n: usize, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize) { let module: Module = Module::::new(1 << log_n); - let bound: f64 = sigma * 6.0; let mut ct: GLWECiphertext> = GLWECiphertext::new(&module, basek, k_ct, rank); let mut pt: GLWEPlaintext> = GLWEPlaintext::new(&module, basek, k_pt); @@ -68,7 +67,6 @@ fn encrypt_sk(log_n: usize, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -102,7 +100,6 @@ fn encrypt_zero_sk() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut pt: GLWEPlaintext> = GLWEPlaintext::new(&module, basek, k_ct); @@ -128,7 +125,6 @@ fn encrypt_zero_sk() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); ct_dft.decrypt(&module, &mut pt, &sk_dft, scratch.borrow()); @@ -145,7 +141,6 @@ fn encrypt_pk() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct: GLWECiphertext> = GLWECiphertext::new(&module, basek, k_ct, rank); let mut pt_want: GLWEPlaintext> = GLWEPlaintext::new(&module, basek, k_ct); @@ -161,14 +156,7 @@ fn encrypt_pk() { sk_dft.dft(&module, &sk); let mut pk: GLWEPublicKey, FFT64> = GLWEPublicKey::new(&module, basek, log_k_pk, rank); - pk.generate( - &module, - &sk_dft, - &mut source_xa, - &mut source_xe, - sigma, - bound, - ); + pk.generate(&module, &sk_dft, &mut source_xa, &mut source_xe, sigma); let mut scratch: ScratchOwned = ScratchOwned::new( GLWECiphertext::encrypt_sk_scratch_space(&module, rank, ct.size()) @@ -191,7 +179,6 @@ fn encrypt_pk() { &mut source_xu, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -215,7 +202,6 @@ fn keyswitch() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, basek, log_k_grlwe, rows, rank, rank); let mut ct_rlwe_in: GLWECiphertext> = GLWECiphertext::new(&module, basek, log_k_rlwe_in, rank); @@ -263,7 +249,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -274,7 +259,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -315,7 +299,6 @@ fn keyswich_inplace() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, basek, log_k_grlwe, rows, rank, rank); let mut ct_rlwe: GLWECiphertext> = GLWECiphertext::new(&module, basek, log_k_rlwe, rank); @@ -357,7 +340,6 @@ fn keyswich_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -368,7 +350,6 @@ fn keyswich_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -410,7 +391,6 @@ fn external_product() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_rgsw: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, basek, log_k_grlwe, rows, rank); let mut ct_rlwe_in: GLWECiphertext> = GLWECiphertext::new(&module, basek, log_k_rlwe_in, rank); @@ -459,7 +439,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -470,7 +449,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -523,7 +501,6 @@ fn external_product_inplace() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_rgsw: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, basek, log_k_grlwe, rows, rank); let mut ct_rlwe: GLWECiphertext> = GLWECiphertext::new(&module, basek, log_k_rlwe_in, rank); @@ -566,7 +543,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -577,7 +553,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); diff --git a/core/src/test_fft64/glwe_fourier.rs b/core/src/test_fft64/glwe_fourier.rs index 661a1e5..16f9eca 100644 --- a/core/src/test_fft64/glwe_fourier.rs +++ b/core/src/test_fft64/glwe_fourier.rs @@ -23,7 +23,6 @@ fn keyswitch() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank); @@ -76,7 +75,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -87,7 +85,6 @@ fn keyswitch() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -130,7 +127,6 @@ fn keyswich_inplace() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_grlwe: GLWESwitchingKey, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_grlwe, rows, rank, rank); @@ -175,7 +171,6 @@ fn keyswich_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -186,7 +181,6 @@ fn keyswich_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -230,7 +224,6 @@ fn external_product() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_rgsw: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_grlwe, rows, rank); let mut ct_rlwe_in: GLWECiphertext> = GLWECiphertext::new(&module, log_base2k, log_k_rlwe_in, rank); @@ -283,7 +276,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -294,7 +286,6 @@ fn external_product() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -349,7 +340,6 @@ fn external_product_inplace() { let rank: usize = 1; let sigma: f64 = 3.2; - let bound: f64 = sigma * 6.0; let mut ct_rgsw: GGSWCiphertext, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_grlwe, rows, rank); let mut ct_rlwe: GLWECiphertext> = GLWECiphertext::new(&module, log_base2k, log_k_rlwe_in, rank); @@ -394,7 +384,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), ); @@ -405,7 +394,6 @@ fn external_product_inplace() { &mut source_xa, &mut source_xe, sigma, - bound, scratch.borrow(), );