hard coded noise bound to 6 sigma

This commit is contained in:
Jean-Philippe Bossuat
2025-05-14 09:18:46 +02:00
parent 66188a12a6
commit d489bef105
11 changed files with 14 additions and 99 deletions

View File

@@ -97,7 +97,6 @@ where
source_xa: &mut Source,
source_xe: &mut Source,
sigma: f64,
bound: f64,
scratch: &mut Scratch,
) where
ScalarZnx<DataPt>: ScalarZnxToRef,
@@ -153,7 +152,6 @@ where
source_xa,
source_xe,
sigma,
bound,
scratch_3,
);

View File

@@ -119,7 +119,6 @@ where
source_xa: &mut Source,
source_xe: &mut Source,
sigma: f64,
bound: f64,
scratch: &mut Scratch,
) where
ScalarZnx<DataPt>: ScalarZnxToRef,
@@ -168,7 +167,6 @@ where
source_xa,
source_xe,
sigma,
bound,
scrach_2,
);

View File

@@ -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<DataPt>: 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<DataSk, FFT64>: ScalarZnxDftToRef<FFT64>,
{
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<DataPt, DataPk>(
@@ -188,7 +184,6 @@ where
source_xu: &mut Source,
source_xe: &mut Source,
sigma: f64,
bound: f64,
scratch: &mut Scratch,
) where
VecZnx<DataPt>: 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<DataPk, FFT64>: VecZnxDftToRef<FFT64>,
{
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<DataLhs, DataRhs>(
@@ -279,7 +270,6 @@ where
source_xa: &mut Source,
source_xe: &mut Source,
sigma: f64,
bound: f64,
scratch: &mut Scratch,
) where
VecZnx<DataPt>: 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<DataPt>: 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 {

View File

@@ -122,7 +122,6 @@ where
source_xa: &mut Source,
source_xe: &mut Source,
sigma: f64,
bound: f64,
scratch: &mut Scratch,
) where
ScalarZnxDft<DataSk, FFT64>: ScalarZnxDftToRef<FFT64>,
@@ -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);
}

View File

@@ -216,7 +216,6 @@ impl<C> GLWEPublicKey<C, FFT64> {
source_xa: &mut Source,
source_xe: &mut Source,
sigma: f64,
bound: f64,
) where
VecZnxDft<C, FFT64>: VecZnxDftToMut<FFT64> + VecZnxDftToRef<FFT64>,
ScalarZnxDft<S, FFT64>: ScalarZnxDftToRef<FFT64> + ZnxInfos,
@@ -241,7 +240,6 @@ impl<C> GLWEPublicKey<C, FFT64> {
source_xa,
source_xe,
sigma,
bound,
scratch.borrow(),
);
self.dist = sk_dft.dist;

View File

@@ -111,15 +111,13 @@ where
source_xa: &mut Source,
source_xe: &mut Source,
sigma: f64,
bound: f64,
scratch: &mut Scratch,
) where
ScalarZnx<DataPt>: ScalarZnxToRef,
ScalarZnxDft<DataSk, FFT64>: ScalarZnxDftToRef<FFT64>,
{
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);
}
}

View File

@@ -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;

View File

@@ -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<Vec<u8>, FFT64> = GLWESwitchingKey::new(&module, log_base2k, log_k_ct, rows, rank, rank_out);
let mut pt: GLWEPlaintext<Vec<u8>> = 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<Vec<u8>, 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<Vec<u8>, 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<Vec<u8>, 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<Vec<u8>, 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(),
);

View File

@@ -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<Vec<u8>, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_ct, rows, rank);
let mut pt_have: GLWEPlaintext<Vec<u8>> = 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<Vec<u8>, 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<Vec<u8>, 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<Vec<u8>, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_rgsw_rhs, rows, rank);
let mut ct_rgsw_lhs_in: GGSWCiphertext<Vec<u8>, 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<Vec<u8>, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_rgsw_rhs, rows, rank);
let mut ct_rgsw_lhs: GGSWCiphertext<Vec<u8>, 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(),
);

View File

@@ -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<FFT64> = Module::<FFT64>::new(1 << log_n);
let bound: f64 = sigma * 6.0;
let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::new(&module, basek, k_ct, rank);
let mut pt: GLWEPlaintext<Vec<u8>> = 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<Vec<u8>> = 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<Vec<u8>> = GLWECiphertext::new(&module, basek, k_ct, rank);
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::new(&module, basek, k_ct);
@@ -161,14 +156,7 @@ fn encrypt_pk() {
sk_dft.dft(&module, &sk);
let mut pk: GLWEPublicKey<Vec<u8>, 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<Vec<u8>, FFT64> = GLWESwitchingKey::new(&module, basek, log_k_grlwe, rows, rank, rank);
let mut ct_rlwe_in: GLWECiphertext<Vec<u8>> = 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<Vec<u8>, FFT64> = GLWESwitchingKey::new(&module, basek, log_k_grlwe, rows, rank, rank);
let mut ct_rlwe: GLWECiphertext<Vec<u8>> = 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<Vec<u8>, FFT64> = GGSWCiphertext::new(&module, basek, log_k_grlwe, rows, rank);
let mut ct_rlwe_in: GLWECiphertext<Vec<u8>> = 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<Vec<u8>, FFT64> = GGSWCiphertext::new(&module, basek, log_k_grlwe, rows, rank);
let mut ct_rlwe: GLWECiphertext<Vec<u8>> = 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(),
);

View File

@@ -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<Vec<u8>, 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<Vec<u8>, 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<Vec<u8>, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_grlwe, rows, rank);
let mut ct_rlwe_in: GLWECiphertext<Vec<u8>> = 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<Vec<u8>, FFT64> = GGSWCiphertext::new(&module, log_base2k, log_k_grlwe, rows, rank);
let mut ct_rlwe: GLWECiphertext<Vec<u8>> = 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(),
);