mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
Update READMEs & add SECURITY.md (#78)
This commit is contained in:
committed by
GitHub
parent
3b94ab047e
commit
ccd94e36cc
@@ -35,7 +35,6 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAutomorphism
|
||||
@@ -97,7 +96,7 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> {
|
||||
}
|
||||
|
||||
self.key
|
||||
.encrypt_sk(module, sk, &sk_out, seed_xa, source_xe, sigma, scratch_1);
|
||||
.encrypt_sk(module, sk, &sk_out, seed_xa, source_xe, scratch_1);
|
||||
|
||||
self.p = p;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use poulpy_hal::{
|
||||
|
||||
use crate::{
|
||||
TakeGLWEPt,
|
||||
encryption::glwe_encrypt_sk_internal,
|
||||
encryption::{SIGMA, glwe_encrypt_sk_internal},
|
||||
layouts::{GGLWECiphertext, Infos, compressed::GGLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
||||
};
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<D: DataMut> GGLWECiphertextCompressed<D> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -128,7 +127,7 @@ impl<D: DataMut> GGLWECiphertextCompressed<D> {
|
||||
sk,
|
||||
&mut source_xa_tmp,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scrach_1,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -41,7 +41,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKeyCompressed<DataSelf> {
|
||||
sk_out: &GLWESecret<DataSkOut>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -119,7 +118,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKeyCompressed<DataSelf> {
|
||||
&sk_out_tmp,
|
||||
seed_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch2,
|
||||
);
|
||||
self.sk_in_n = sk_in.n();
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpApply<B>
|
||||
@@ -104,7 +103,7 @@ impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> {
|
||||
let (seed_xa_tmp, _) = source_xa.branch();
|
||||
|
||||
self.at_mut(i, j)
|
||||
.encrypt_sk(module, &sk_ij, sk, seed_xa_tmp, source_xe, sigma, scratch5);
|
||||
.encrypt_sk(module, &sk_ij, sk, seed_xa_tmp, source_xe, scratch5);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use poulpy_hal::{
|
||||
|
||||
use crate::{
|
||||
TakeGLWEPt,
|
||||
encryption::glwe_encrypt_sk_internal,
|
||||
encryption::{SIGMA, glwe_encrypt_sk_internal},
|
||||
layouts::{GGSWCiphertext, Infos, compressed::GGSWCiphertextCompressed, prepared::GLWESecretPrepared},
|
||||
};
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<DataSelf: DataMut> GGSWCiphertextCompressed<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -97,7 +96,7 @@ impl<DataSelf: DataMut> GGSWCiphertextCompressed<DataSelf> {
|
||||
sk,
|
||||
&mut source_xa_tmp,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scratch_1,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::glwe_ct::glwe_encrypt_sk_internal,
|
||||
encryption::{SIGMA, glwe_ct::glwe_encrypt_sk_internal},
|
||||
layouts::{GLWECiphertext, GLWEPlaintext, Infos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -49,15 +48,7 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
+ VecZnxSub,
|
||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||
{
|
||||
self.encrypt_sk_internal(
|
||||
module,
|
||||
Some((pt, 0)),
|
||||
sk,
|
||||
seed_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
self.encrypt_sk_internal(module, Some((pt, 0)), sk, seed_xa, source_xe, scratch);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -68,7 +59,6 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -99,7 +89,7 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
sk,
|
||||
&mut source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scratch,
|
||||
);
|
||||
self.seed = seed_xa;
|
||||
|
||||
@@ -36,7 +36,6 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -92,7 +91,7 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
||||
}
|
||||
|
||||
self.key
|
||||
.encrypt_sk(module, sk, &sk_out, source_xa, source_xe, sigma, scratch_1);
|
||||
.encrypt_sk(module, sk, &sk_out, source_xa, source_xe, scratch_1);
|
||||
|
||||
self.p = p;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -127,7 +126,7 @@ impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> {
|
||||
|
||||
// rlwe encrypt of vec_znx_pt into vec_znx_ct
|
||||
self.at_mut(row_i, col_i)
|
||||
.encrypt_sk(module, &tmp_pt, sk, source_xa, source_xe, sigma, scrach_1);
|
||||
.encrypt_sk(module, &tmp_pt, sk, source_xa, source_xe, scrach_1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
||||
sk_out: &GLWESecret<DataSkOut>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -130,7 +129,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
||||
&sk_out_tmp,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch2,
|
||||
);
|
||||
self.sk_in_n = sk_in.n();
|
||||
|
||||
@@ -39,7 +39,6 @@ impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpApply<B>
|
||||
@@ -102,7 +101,7 @@ impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> {
|
||||
);
|
||||
|
||||
self.at_mut(i, j)
|
||||
.encrypt_sk(module, &sk_ij, sk, source_xa, source_xe, sigma, scratch5);
|
||||
.encrypt_sk(module, &sk_ij, sk, source_xa, source_xe, scratch5);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -86,7 +85,6 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch1,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,8 +10,8 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
SIX_SIGMA,
|
||||
dist::Distribution,
|
||||
encryption::{SIGMA, SIGMA_BOUND},
|
||||
layouts::{
|
||||
GLWECiphertext, GLWEPlaintext, Infos,
|
||||
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared},
|
||||
@@ -46,7 +46,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -77,15 +76,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
)
|
||||
}
|
||||
|
||||
self.encrypt_sk_internal(
|
||||
module,
|
||||
Some((pt, 0)),
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
self.encrypt_sk_internal(module, Some((pt, 0)), sk, source_xa, source_xe, scratch);
|
||||
}
|
||||
|
||||
pub fn encrypt_zero_sk<DataSk: DataRef, B: Backend>(
|
||||
@@ -94,7 +85,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -129,7 +119,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
}
|
||||
@@ -142,7 +131,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -172,7 +160,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scratch,
|
||||
);
|
||||
}
|
||||
@@ -185,7 +173,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk: &GLWEPublicKeyPrepared<DataPk, B>,
|
||||
source_xu: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -196,15 +183,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
+ VecZnxBigNormalize<B>,
|
||||
Scratch<B>: TakeSvpPPol<B> + TakeScalarZnx + TakeVecZnxDft<B>,
|
||||
{
|
||||
self.encrypt_pk_internal::<DataPt, DataPk, B>(
|
||||
module,
|
||||
Some((pt, 0)),
|
||||
pk,
|
||||
source_xu,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
self.encrypt_pk_internal::<DataPt, DataPk, B>(module, Some((pt, 0)), pk, source_xu, source_xe, scratch);
|
||||
}
|
||||
|
||||
pub fn encrypt_zero_pk<DataPk: DataRef, B: Backend>(
|
||||
@@ -213,7 +192,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk: &GLWEPublicKeyPrepared<DataPk, B>,
|
||||
source_xu: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -230,7 +208,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk,
|
||||
source_xu,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
}
|
||||
@@ -243,7 +220,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk: &GLWEPublicKeyPrepared<DataPk, B>,
|
||||
source_xu: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -300,15 +276,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
let mut ci_big = module.vec_znx_dft_to_vec_znx_big_consume(ci_dft);
|
||||
|
||||
// ci_big = u * pk[i] + e
|
||||
module.vec_znx_big_add_normal(
|
||||
basek,
|
||||
&mut ci_big,
|
||||
0,
|
||||
pk.k(),
|
||||
source_xe,
|
||||
sigma,
|
||||
sigma * SIX_SIGMA,
|
||||
);
|
||||
module.vec_znx_big_add_normal(basek, &mut ci_big, 0, pk.k(), source_xe, SIGMA, SIGMA_BOUND);
|
||||
|
||||
// ci_big = u * pk[i] + e + m (if col = i)
|
||||
if let Some((pt, col)) = pt
|
||||
@@ -412,7 +380,7 @@ pub(crate) fn glwe_encrypt_sk_internal<DataCt: DataMut, DataPt: DataRef, DataSk:
|
||||
}
|
||||
|
||||
// c[0] += e
|
||||
module.vec_znx_add_normal(basek, &mut c0, 0, k, source_xe, sigma, sigma * SIX_SIGMA);
|
||||
module.vec_znx_add_normal(basek, &mut c0, 0, k, source_xe, sigma, SIGMA_BOUND);
|
||||
|
||||
// c[0] += m if col = 0
|
||||
if let Some((pt, col)) = pt
|
||||
|
||||
@@ -18,7 +18,6 @@ impl<D: DataMut> GLWEPublicKey<D> {
|
||||
sk: &GLWESecretPrepared<S, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>:,
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -61,7 +60,7 @@ impl<D: DataMut> GLWEPublicKey<D> {
|
||||
));
|
||||
|
||||
let mut tmp: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(self.n(), self.basek(), self.k(), self.rank());
|
||||
tmp.encrypt_zero_sk(module, sk, source_xa, source_xe, sigma, scratch.borrow());
|
||||
tmp.encrypt_zero_sk(module, sk, source_xa, source_xe, scratch.borrow());
|
||||
self.dist = sk.dist;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
||||
sk_glwe: &GLWESecret<DGlwe>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
DLwe: DataRef,
|
||||
@@ -75,7 +74,6 @@ impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
||||
&sk_lwe_as_glwe,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch1,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
SIX_SIGMA,
|
||||
encryption::{SIGMA, SIGMA_BOUND},
|
||||
layouts::{Infos, LWECiphertext, LWEPlaintext, LWESecret},
|
||||
};
|
||||
|
||||
@@ -20,7 +20,6 @@ impl<DataSelf: DataMut> LWECiphertext<DataSelf> {
|
||||
sk: &LWESecret<DataSk>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
) where
|
||||
DataPt: DataRef,
|
||||
DataSk: DataRef,
|
||||
@@ -58,15 +57,7 @@ impl<DataSelf: DataMut> LWECiphertext<DataSelf> {
|
||||
.sum::<i64>();
|
||||
});
|
||||
|
||||
module.vec_znx_add_normal(
|
||||
basek,
|
||||
&mut self.data,
|
||||
0,
|
||||
k,
|
||||
source_xe,
|
||||
sigma,
|
||||
sigma * SIX_SIGMA,
|
||||
);
|
||||
module.vec_znx_add_normal(basek, &mut self.data, 0, k, source_xe, SIGMA, SIGMA_BOUND);
|
||||
|
||||
module.vec_znx_normalize_inplace(
|
||||
basek,
|
||||
|
||||
@@ -34,7 +34,6 @@ impl<D: DataMut> LWESwitchingKey<D> {
|
||||
sk_lwe_out: &LWESecret<DOut>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
DIn: DataRef,
|
||||
@@ -83,7 +82,6 @@ impl<D: DataMut> LWESwitchingKey<D> {
|
||||
&sk_out_glwe,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch2,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<D: DataMut> LWEToGLWESwitchingKey<D> {
|
||||
sk_glwe: &GLWESecret<DGlwe>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
DLwe: DataRef,
|
||||
@@ -73,7 +72,6 @@ impl<D: DataMut> LWEToGLWESwitchingKey<D> {
|
||||
sk_glwe,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch1,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,3 +12,6 @@ mod lwe_ksk;
|
||||
mod lwe_to_glwe_ksk;
|
||||
|
||||
pub(crate) use glwe_ct::glwe_encrypt_sk_internal;
|
||||
|
||||
pub const SIGMA: f64 = 3.2;
|
||||
pub(crate) const SIGMA_BOUND: f64 = 6.0 * SIGMA;
|
||||
|
||||
Reference in New Issue
Block a user