Clippy check & update CI (#73)

* updated CI workflow with clippy & fmt
This commit is contained in:
Jean-Philippe Bossuat
2025-08-17 13:02:47 +02:00
committed by GitHub
parent 3a828740cc
commit 0be569eca0
125 changed files with 1033 additions and 530 deletions

View File

@@ -90,7 +90,8 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
let ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, FFT64> = ct_ggsw.prepare_alloc(&module, scratch.borrow());
move || {
black_box(ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow()));
ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow());
black_box(());
}
}
@@ -185,7 +186,8 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
move || {
let scratch_borrow = scratch.borrow();
black_box(ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow));
ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow);
black_box(());
}
}

View File

@@ -96,7 +96,8 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
let ksk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, _> = ksk.prepare_alloc(&module, scratch.borrow());
move || {
black_box(ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow()));
ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow());
black_box(());
}
}
@@ -105,11 +106,11 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
let params_set: Vec<Params> = vec![Params {
log_n: 15,
basek: basek,
basek,
k_ct_in: 874 - digits * basek,
k_ct_out: 874 - digits * basek,
k_ksk: 874,
digits: digits,
digits,
rank_in: 1,
rank_out: 1,
}];
@@ -191,7 +192,8 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, FFT64> = ksk.prepare_alloc(&module, scratch.borrow());
move || {
black_box(ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow()));
ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow());
black_box(());
}
}

View File

@@ -10,6 +10,7 @@ use backend::hal::{
use crate::layouts::{GGLWEAutomorphismKey, GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared};
impl GGLWEAutomorphismKey<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn automorphism_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,
@@ -43,7 +44,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
}
impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
pub fn automorphism<'a, DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
pub fn automorphism<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
lhs: &GGLWEAutomorphismKey<DataLhs>,
@@ -149,7 +150,7 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
{
unsafe {
let self_ptr: *mut GGLWEAutomorphismKey<DataSelf> = self as *mut GGLWEAutomorphismKey<DataSelf>;
self.automorphism(&module, &*self_ptr, rhs, scratch);
self.automorphism(module, &*self_ptr, rhs, scratch);
}
}
}

View File

@@ -14,6 +14,7 @@ use crate::layouts::{
};
impl GGSWCiphertext<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn automorphism_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,
@@ -38,6 +39,7 @@ impl GGSWCiphertext<Vec<u8>> {
ci_dft + (ks_internal | expand)
}
#[allow(clippy::too_many_arguments)]
pub fn automorphism_inplace_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,

View File

@@ -10,6 +10,7 @@ use backend::hal::{
use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared};
impl GLWECiphertext<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn automorphism_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,

View File

@@ -64,7 +64,7 @@ impl<DataSelf: DataRef> GLWECiphertext<DataSelf> {
module.vec_znx_big_add_small_inplace(&mut c0_big, 0, &self.data, 0);
// pt = norm(BIG(m + e))
module.vec_znx_big_normalize(self.basek(), &mut pt.data, 0, &mut c0_big, 0, scratch_1);
module.vec_znx_big_normalize(self.basek(), &mut pt.data, 0, &c0_big, 0, scratch_1);
pt.basek = self.basek();
pt.k = pt.k().min(self.k());

View File

@@ -10,12 +10,12 @@ impl<DataSelf> LWECiphertext<DataSelf>
where
DataSelf: DataRef,
{
pub fn decrypt<DataPt, DataSk, B: Backend>(&self, module: &Module<B>, pt: &mut LWEPlaintext<DataPt>, sk: &LWESecret<DataSk>)
pub fn decrypt<DataPt, DataSk, B>(&self, module: &Module<B>, pt: &mut LWEPlaintext<DataPt>, sk: &LWESecret<DataSk>)
where
DataPt: DataMut,
DataSk: DataRef,
Module<B>: VecZnxNormalizeInplace<B>,
B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
{
#[cfg(debug_assertions)]
{

View File

@@ -27,6 +27,7 @@ impl GGLWEAutomorphismKeyCompressed<Vec<u8>> {
}
impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
@@ -96,7 +97,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, sigma, scratch_1);
self.p = p;
}

View File

@@ -24,6 +24,7 @@ impl GGLWECiphertextCompressed<Vec<u8>> {
}
impl<D: DataMut> GGLWECiphertextCompressed<D> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -33,6 +33,7 @@ impl GGLWESwitchingKeyCompressed<Vec<u8>> {
}
impl<DataSelf: DataMut> GGLWESwitchingKeyCompressed<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -73,7 +73,7 @@ impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> {
let rank: usize = self.rank();
let (mut sk_dft_prep, scratch1) = scratch.take_glwe_secret_prepared(n, rank);
sk_dft_prep.prepare(module, &sk, scratch1);
sk_dft_prep.prepare(module, sk, scratch1);
let (mut sk_dft, scratch2) = scratch1.take_vec_znx_dft(n, rank, 1);

View File

@@ -24,6 +24,7 @@ impl GGSWCiphertextCompressed<Vec<u8>> {
}
impl<DataSelf: DataMut> GGSWCiphertextCompressed<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -23,6 +23,7 @@ impl GLWECiphertextCompressed<Vec<u8>> {
}
impl<D: DataMut> GLWECiphertextCompressed<D> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
@@ -59,6 +60,7 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
);
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn encrypt_sk_internal<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -28,6 +28,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
}
impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
@@ -91,7 +92,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, sigma, scratch_1);
self.p = p;
}

View File

@@ -28,6 +28,7 @@ impl GGLWECiphertext<Vec<u8>> {
}
impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -44,6 +44,7 @@ impl GGLWESwitchingKey<Vec<u8>> {
}
impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -75,7 +75,7 @@ impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> {
let rank: usize = self.rank();
let (mut sk_dft_prep, scratch1) = scratch.take_glwe_secret_prepared(n, rank);
sk_dft_prep.prepare(module, &sk, scratch1);
sk_dft_prep.prepare(module, sk, scratch1);
let (mut sk_dft, scratch2) = scratch1.take_vec_znx_dft(n, rank, 1);

View File

@@ -27,6 +27,7 @@ impl GGSWCiphertext<Vec<u8>> {
}
impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -38,6 +38,7 @@ impl GLWECiphertext<Vec<u8>> {
}
impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
@@ -133,6 +134,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
);
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn encrypt_sk_internal<DataPt: DataRef, DataSk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
@@ -175,6 +177,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
);
}
#[allow(clippy::too_many_arguments)]
pub fn encrypt_pk<DataPt: DataRef, DataPk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
@@ -232,6 +235,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
);
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn encrypt_pk_internal<DataPt: DataRef, DataPk: DataRef, B: Backend>(
&mut self,
module: &Module<B>,
@@ -307,10 +311,10 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
);
// ci_big = u * pk[i] + e + m (if col = i)
if let Some((pt, col)) = pt {
if col == i {
module.vec_znx_big_add_small_inplace(&mut ci_big, 0, &pt.data, 0);
}
if let Some((pt, col)) = pt
&& col == i
{
module.vec_znx_big_add_small_inplace(&mut ci_big, 0, &pt.data, 0);
}
// ct[i] = norm(ci_big)
@@ -319,6 +323,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
}
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn glwe_encrypt_sk_internal<DataCt: DataMut, DataPt: DataRef, DataSk: DataRef, B: Backend>(
module: &Module<B>,
basek: usize,
@@ -373,12 +378,7 @@ pub(crate) fn glwe_encrypt_sk_internal<DataCt: DataMut, DataPt: DataRef, DataSk:
// ct[i] = uniform
// ct[0] -= c[i] * s[i],
(1..cols).for_each(|i| {
let col_ct: usize;
if compressed {
col_ct = 0;
} else {
col_ct = i;
}
let col_ct: usize = if compressed { 0 } else { i };
// ct[i] = uniform (+ pt)
module.vec_znx_fill_uniform(basek, ct, col_ct, k, source_xa);
@@ -415,10 +415,10 @@ pub(crate) fn glwe_encrypt_sk_internal<DataCt: DataMut, DataPt: DataRef, DataSk:
module.vec_znx_add_normal(basek, &mut c0, 0, k, source_xe, sigma, sigma * SIX_SIGMA);
// c[0] += m if col = 0
if let Some((pt, col)) = pt {
if col == 0 {
module.vec_znx_add_inplace(&mut c0, 0, &pt.data, 0);
}
if let Some((pt, col)) = pt
&& col == 0
{
module.vec_znx_add_inplace(&mut c0, 0, &pt.data, 0);
}
// c[0] = norm(c[0])

View File

@@ -12,7 +12,7 @@ use sampling::source::Source;
use crate::layouts::{GLWECiphertext, GLWEPublicKey, Infos, prepared::GLWESecretPrepared};
impl<D: DataMut> GLWEPublicKey<D> {
pub fn generate_from_sk<S: DataRef, B: Backend>(
pub fn generate_from_sk<S: DataRef, B>(
&mut self,
module: &Module<B>,
sk: &GLWESecretPrepared<S, B>,
@@ -34,7 +34,8 @@ impl<D: DataMut> GLWEPublicKey<D> {
+ VecZnxAddNormal
+ VecZnxNormalize<B>
+ VecZnxSub,
B: ScratchOwnedAllocImpl<B>
B: Backend
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
+ TakeVecZnxDftImpl<B>
+ ScratchAvailableImpl<B>
@@ -46,9 +47,8 @@ impl<D: DataMut> GLWEPublicKey<D> {
assert_eq!(self.n(), sk.n());
match sk.dist {
Distribution::NONE => panic!("invalid sk: SecretDistribution::NONE"),
_ => {}
if sk.dist == Distribution::NONE {
panic!("invalid sk: SecretDistribution::NONE")
}
}

View File

@@ -26,6 +26,7 @@ impl GLWEToLWESwitchingKey<Vec<u8>> {
}
impl<D: DataMut> GLWEToLWESwitchingKey<D> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DLwe, DGlwe, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -13,7 +13,7 @@ use crate::{
};
impl<DataSelf: DataMut> LWECiphertext<DataSelf> {
pub fn encrypt_sk<DataPt, DataSk, B: Backend>(
pub fn encrypt_sk<DataPt, DataSk, B>(
&mut self,
module: &Module<B>,
pt: &LWEPlaintext<DataPt>,
@@ -25,7 +25,7 @@ impl<DataSelf: DataMut> LWECiphertext<DataSelf> {
DataPt: DataRef,
DataSk: DataRef,
Module<B>: VecZnxFillUniform + VecZnxAddNormal + VecZnxNormalizeInplace<B>,
B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
{
#[cfg(debug_assertions)]
{

View File

@@ -26,6 +26,7 @@ impl LWESwitchingKey<Vec<u8>> {
}
impl<D: DataMut> LWESwitchingKey<D> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DIn, DOut, B: Backend>(
&mut self,
module: &Module<B>,

View File

@@ -24,6 +24,7 @@ impl LWEToGLWESwitchingKey<Vec<u8>> {
}
impl<D: DataMut> LWEToGLWESwitchingKey<D> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DLwe, DGlwe, B: Backend>(
&mut self,
module: &Module<B>,
@@ -69,7 +70,7 @@ impl<D: DataMut> LWEToGLWESwitchingKey<D> {
self.0.encrypt_sk(
module,
&sk_lwe_as_glwe,
&sk_glwe,
sk_glwe,
source_xa,
source_xe,
sigma,

View File

@@ -9,6 +9,7 @@ use backend::hal::{
use crate::layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, prepared::GGSWCiphertextPrepared};
impl GGLWEAutomorphismKey<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn external_product_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,

View File

@@ -9,6 +9,7 @@ use backend::hal::{
use crate::layouts::{GGLWESwitchingKey, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared};
impl GGLWESwitchingKey<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn external_product_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,

View File

@@ -9,6 +9,7 @@ use backend::hal::{
use crate::layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared};
impl GGSWCiphertext<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn external_product_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,

View File

@@ -9,6 +9,7 @@ use backend::hal::{
use crate::layouts::{GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared};
impl GLWECiphertext<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn external_product_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,
@@ -160,7 +161,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
{
unsafe {
let self_ptr: *mut GLWECiphertext<DataSelf> = self as *mut GLWECiphertext<DataSelf>;
self.external_product(&module, &*self_ptr, rhs, scratch);
self.external_product(module, &*self_ptr, rhs, scratch);
}
}
}

View File

@@ -55,14 +55,14 @@ impl Accumulator {
impl GLWEPacker {
/// Instantiates a new [GLWEPacker].
///
/// #Arguments
/// # Arguments
///
/// * `module`: static backend FFT tables.
/// * `log_batch`: packs coefficients which are multiples of X^{N/2^log_batch}.
/// i.e. with `log_batch=0` only the constant coefficient is packed
/// and N GLWE ciphertext can be packed. With `log_batch=2` all coefficients
/// which are multiples of X^{N/4} are packed. Meaning that N/4 ciphertexts
/// can be packed.
/// i.e. with `log_batch=0` only the constant coefficient is packed
/// and N GLWE ciphertext can be packed. With `log_batch=2` all coefficients
/// which are multiples of X^{N/4} are packed. Meaning that N/4 ciphertexts
/// can be packed.
/// * `basek`: base 2 logarithm of the GLWE ciphertext in memory digit representation.
/// * `k`: base 2 precision of the GLWE ciphertext precision over the Torus.
/// * `rank`: rank of the GLWE ciphertext.
@@ -71,7 +71,7 @@ impl GLWEPacker {
let log_n: usize = (usize::BITS - (n - 1).leading_zeros()) as _;
(0..log_n - log_batch).for_each(|_| accumulators.push(Accumulator::alloc(n, basek, k, rank)));
Self {
accumulators: accumulators,
accumulators,
log_batch,
counter: 0,
}
@@ -111,7 +111,7 @@ impl GLWEPacker {
///
/// * `module`: static backend FFT tables.
/// * `res`: space to append fully packed ciphertext. Only when the number
/// of packed ciphertexts reaches N/2^log_batch is a result written.
/// of packed ciphertexts reaches N/2^log_batch is a result written.
/// * `a`: ciphertext to pack. Can optionally give None to pack a 0 ciphertext.
/// * `auto_keys`: a [HashMap] containing the [AutomorphismKeyExec]s.
/// * `scratch`: scratch space of size at least [Self::scratch_space].
@@ -329,13 +329,11 @@ fn combine<D: DataRef, DataAK: DataRef, B: Backend>(
let k: usize = a.k();
let rank: usize = a.rank();
let gal_el: i64;
if i == 0 {
gal_el = -1;
let gal_el: i64 = if i == 0 {
-1
} else {
gal_el = module.galois_element(1 << (i - 1))
}
module.galois_element(1 << (i - 1))
};
let t: i64 = 1 << (log_n - i - 1);
@@ -390,20 +388,18 @@ fn combine<D: DataRef, DataAK: DataRef, B: Backend>(
panic!("auto_key[{}] not found", gal_el);
}
}
} else {
if let Some(b) = b {
let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(n, basek, k, rank);
tmp_b.rotate(module, 1 << (log_n - i - 1), b);
tmp_b.rsh(module, 1);
} else if let Some(b) = b {
let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(n, basek, k, rank);
tmp_b.rotate(module, 1 << (log_n - i - 1), b);
tmp_b.rsh(module, 1);
// a = (b* X^t - phi(b* X^t))
if let Some(key) = auto_keys.get(&gal_el) {
a.automorphism_sub_ba(module, &tmp_b, key, scratch_1);
} else {
panic!("auto_key[{}] not found", gal_el);
}
acc.value = true;
// a = (b* X^t - phi(b* X^t))
if let Some(key) = auto_keys.get(&gal_el) {
a.automorphism_sub_ba(module, &tmp_b, key, scratch_1);
} else {
panic!("auto_key[{}] not found", gal_el);
}
acc.value = true;
}
}

View File

@@ -27,6 +27,7 @@ impl GLWECiphertext<Vec<u8>> {
gal_els
}
#[allow(clippy::too_many_arguments)]
pub fn trace_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,
@@ -111,12 +112,11 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
(start..end).for_each(|i| {
self.rsh(module, 1);
let p: i64;
if i == 0 {
p = -1;
let p: i64 = if i == 0 {
-1
} else {
p = module.galois_element(1 << (i - 1));
}
module.galois_element(1 << (i - 1))
};
if let Some(key) = auto_keys.get(&p) {
self.automorphism_add_inplace(module, key, scratch);

View File

@@ -12,6 +12,7 @@ use crate::layouts::{
};
impl GGLWEAutomorphismKey<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn keyswitch_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,
@@ -88,6 +89,7 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
}
impl GGLWESwitchingKey<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn keyswitch_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,

View File

@@ -49,6 +49,7 @@ impl GGSWCiphertext<Vec<u8>> {
tmp_dft_i + ((tmp_a + vmp) | (tmp_idft + norm))
}
#[allow(clippy::too_many_arguments)]
pub fn keyswitch_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,
@@ -74,6 +75,7 @@ impl GGSWCiphertext<Vec<u8>> {
res_znx + ci_dft + (ks | expand_rows | res_dft)
}
#[allow(clippy::too_many_arguments)]
pub fn keyswitch_inplace_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,

View File

@@ -9,6 +9,7 @@ use backend::hal::{
use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWESwitchingKeyPrepared};
impl GLWECiphertext<Vec<u8>> {
#[allow(clippy::too_many_arguments)]
pub fn keyswitch_scratch_space<B: Backend>(
module: &Module<B>,
n: usize,
@@ -38,7 +39,7 @@ impl GLWECiphertext<Vec<u8>> {
ksk_size,
) + module.vec_znx_dft_alloc_bytes(n, rank_in, in_size);
let normalize: usize = module.vec_znx_big_normalize_tmp_bytes(n);
return res_dft + ((ai_dft + vmp) | normalize);
res_dft + ((ai_dft + vmp) | normalize)
}
pub fn keyswitch_inplace_scratch_space<B: Backend>(
@@ -180,7 +181,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
{
unsafe {
let self_ptr: *mut GLWECiphertext<DataSelf> = self as *mut GLWECiphertext<DataSelf>;
self.keyswitch(&module, &*self_ptr, rhs, scratch);
self.keyswitch(module, &*self_ptr, rhs, scratch);
}
}
}

View File

@@ -61,7 +61,7 @@ impl<D: Data> Infos for GGLWEAutomorphismKeyCompressed<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.key.inner()
self.key.inner()
}
fn basek(&self) -> usize {

View File

@@ -76,7 +76,7 @@ impl GGLWECiphertextCompressed<Vec<u8>> {
Self {
data: MatZnx::alloc(n, rows, rank_in, 1, size),
basek: basek,
basek,
k,
rank_out,
digits,

View File

@@ -54,7 +54,7 @@ impl<D: Data> Infos for GGLWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.key.inner()
self.key.inner()
}
fn basek(&self) -> usize {

View File

@@ -59,7 +59,7 @@ impl GGLWETensorKeyCompressed<Vec<u8>> {
n, basek, k, rows, digits, 1, rank,
));
});
Self { keys: keys }
Self { keys }
}
pub fn bytes_of(n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank: usize) -> usize {
@@ -72,7 +72,7 @@ impl<D: Data> Infos for GGLWETensorKeyCompressed<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.keys[0].inner()
self.keys[0].inner()
}
fn basek(&self) -> usize {

View File

@@ -76,7 +76,7 @@ impl GGSWCiphertextCompressed<Vec<u8>> {
Self {
data: MatZnx::alloc(n, rows, rank + 1, 1, k.div_ceil(basek)),
basek,
k: k,
k,
digits,
rank,
seed: Vec::new(),
@@ -123,7 +123,7 @@ impl<D: DataMut> GGSWCiphertextCompressed<D> {
data: self.data.at_mut(row, col),
basek: self.basek,
k: self.k,
rank: rank,
rank,
seed: self.seed[row * (rank + 1) + col],
}
}

View File

@@ -96,7 +96,7 @@ impl<D: DataMut> ReaderFrom for GLWECiphertextCompressed<D> {
self.k = reader.read_u64::<LittleEndian>()? as usize;
self.basek = reader.read_u64::<LittleEndian>()? as usize;
self.rank = reader.read_u64::<LittleEndian>()? as usize;
reader.read(&mut self.seed)?;
reader.read_exact(&mut self.seed)?;
self.data.read_from(reader)
}
}

View File

@@ -43,7 +43,7 @@ impl<D: Data> Infos for GLWEToLWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -57,8 +57,8 @@ impl LWECiphertextCompressed<Vec<u8>> {
pub fn alloc(basek: usize, k: usize) -> Self {
Self {
data: VecZnx::alloc(1, 1, k.div_ceil(basek)),
k: k,
basek: basek,
k,
basek,
seed: [0u8; 32],
}
}
@@ -103,7 +103,7 @@ impl<D: DataMut> ReaderFrom for LWECiphertextCompressed<D> {
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
self.k = reader.read_u64::<LittleEndian>()? as usize;
self.basek = reader.read_u64::<LittleEndian>()? as usize;
reader.read(&mut self.seed)?;
reader.read_exact(&mut self.seed)?;
self.data.read_from(reader)
}
}

View File

@@ -44,7 +44,7 @@ impl<D: Data> Infos for LWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -45,7 +45,7 @@ impl<D: Data> Infos for LWEToGLWESwitchingKeyCompressed<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -59,7 +59,7 @@ impl<D: Data> Infos for GGLWEAutomorphismKey<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.key.inner()
self.key.inner()
}
fn basek(&self) -> usize {

View File

@@ -87,7 +87,7 @@ impl GGLWECiphertext<Vec<u8>> {
Self {
data: MatZnx::alloc(n, rows, rank_in, rank_out + 1, size),
basek: basek,
basek,
k,
digits,
}

View File

@@ -55,7 +55,7 @@ impl GGLWETensorKey<Vec<u8>> {
(0..pairs).for_each(|_| {
keys.push(GGLWESwitchingKey::alloc(n, basek, k, rows, digits, 1, rank));
});
Self { keys: keys }
Self { keys }
}
pub fn bytes_of(n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank: usize) -> usize {
@@ -68,7 +68,7 @@ impl<D: Data> Infos for GGLWETensorKey<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.keys[0].inner()
self.keys[0].inner()
}
fn basek(&self) -> usize {

View File

@@ -88,7 +88,7 @@ impl GGSWCiphertext<Vec<u8>> {
Self {
data: MatZnx::alloc(n, rows, rank + 1, rank + 1, k.div_ceil(basek)),
basek,
k: k,
k,
digits,
}
}

View File

@@ -1,6 +1,6 @@
use backend::hal::{
api::{FillUniform, Reset},
layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, VecZnxToMut, VecZnxToRef, WriterTo},
layouts::{Data, DataMut, DataRef, ReaderFrom, ToOwnedDeep, VecZnx, VecZnxToMut, VecZnxToRef, WriterTo},
};
use sampling::source::Source;
@@ -15,6 +15,17 @@ pub struct GLWECiphertext<D: Data> {
pub k: usize,
}
impl<D: DataRef> ToOwnedDeep for GLWECiphertext<D> {
type Owned = GLWECiphertext<Vec<u8>>;
fn to_owned_deep(&self) -> Self::Owned {
GLWECiphertext {
data: self.data.to_owned_deep(),
basek: self.basek,
k: self.k,
}
}
}
impl<D: DataRef> fmt::Debug for GLWECiphertext<D> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
@@ -86,16 +97,6 @@ impl<D: Data> GLWECiphertext<D> {
}
}
impl<D: DataRef> GLWECiphertext<D> {
pub fn clone(&self) -> GLWECiphertext<Vec<u8>> {
GLWECiphertext {
data: self.data.clone(),
basek: self.basek(),
k: self.k(),
}
}
}
impl<D: DataMut> SetMetaData for GLWECiphertext<D> {
fn set_k(&mut self, k: usize) {
self.k = k

View File

@@ -15,8 +15,8 @@ impl GLWEPublicKey<Vec<u8>> {
pub fn alloc(n: usize, basek: usize, k: usize, rank: usize) -> Self {
Self {
data: VecZnx::alloc(n, rank + 1, k.div_ceil(basek)),
basek: basek,
k: k,
basek,
k,
dist: Distribution::NONE,
}
}

View File

@@ -52,7 +52,7 @@ impl GLWEPlaintext<Vec<u8>> {
pub fn alloc(n: usize, basek: usize, k: usize) -> Self {
Self {
data: VecZnx::alloc(n, 1, k.div_ceil(basek)),
basek: basek,
basek,
k,
}
}

View File

@@ -39,7 +39,7 @@ impl<D: Data> Infos for GLWEToLWESwitchingKey<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -64,8 +64,8 @@ impl LWECiphertext<Vec<u8>> {
pub fn alloc(n: usize, basek: usize, k: usize) -> Self {
Self {
data: VecZnx::alloc(n + 1, 1, k.div_ceil(basek)),
k: k,
basek: basek,
k,
basek,
}
}
}

View File

@@ -44,7 +44,7 @@ impl<D: Data> Infos for LWESwitchingKey<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -14,8 +14,8 @@ impl LWEPlaintext<Vec<u8>> {
pub fn alloc(basek: usize, k: usize) -> Self {
Self {
data: VecZnx::alloc(1, 1, k.div_ceil(basek)),
k: k,
basek: basek,
k,
basek,
}
}
}

View File

@@ -38,7 +38,7 @@ impl<D: Data> Infos for LWEToGLWESwitchingKey<D> {
type Inner = MatZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -37,7 +37,7 @@ impl<D: Data, B: Backend> Infos for GGLWEAutomorphismKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>;
fn inner(&self) -> &Self::Inner {
&self.key.inner()
self.key.inner()
}
fn basek(&self) -> usize {

View File

@@ -17,6 +17,7 @@ pub struct GGLWECiphertextPrepared<D: Data, B: Backend> {
}
impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> {
#[allow(clippy::too_many_arguments)]
pub fn alloc(
module: &Module<B>,
n: usize,
@@ -48,12 +49,13 @@ impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> {
Self {
data: module.vmp_pmat_alloc(n, rows, rank_in, rank_out + 1, size),
basek: basek,
basek,
k,
digits,
}
}
#[allow(clippy::too_many_arguments)]
pub fn bytes_of(
module: &Module<B>,
n: usize,

View File

@@ -16,6 +16,7 @@ pub struct GGLWESwitchingKeyPrepared<D: Data, B: Backend> {
}
impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
#[allow(clippy::too_many_arguments)]
pub fn alloc(
module: &Module<B>,
n: usize,
@@ -36,6 +37,7 @@ impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
}
}
#[allow(clippy::too_many_arguments)]
pub fn bytes_of(
module: &Module<B>,
n: usize,

View File

@@ -41,7 +41,7 @@ impl<D: Data, B: Backend> Infos for GGLWETensorKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>;
fn inner(&self) -> &Self::Inner {
&self.keys[0].inner()
self.keys[0].inner()
}
fn basek(&self) -> usize {

View File

@@ -42,7 +42,7 @@ impl<B: Backend> GGSWCiphertextPrepared<Vec<u8>, B> {
Self {
data: module.vmp_pmat_alloc(n, rows, rank + 1, rank + 1, k.div_ceil(basek)),
basek,
k: k,
k,
digits,
}
}

View File

@@ -0,0 +1,177 @@
use backend::hal::{
api::{FillUniform, Reset, VecZnxCopy, VecZnxFillUniform},
layouts::{Backend, Data, DataMut, DataRef, Module, ReaderFrom, VecZnx, WriterTo},
};
use sampling::source::Source;
use crate::layouts::{GLWECiphertext, Infos, compressed::Decompress};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt;
#[derive(PartialEq, Eq, Clone)]
pub struct GLWECiphertextCompressed<D: Data> {
pub(crate) data: VecZnx<D>,
pub(crate) basek: usize,
pub(crate) k: usize,
pub(crate) rank: usize,
pub(crate) seed: [u8; 32],
}
impl<D: DataRef> fmt::Debug for GLWECiphertextCompressed<D> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
}
}
impl<D: DataRef> fmt::Display for GLWECiphertextCompressed<D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"GLWECiphertextCompressed: basek={} k={} rank={} seed={:?}: {}",
self.basek(),
self.k(),
self.rank,
self.seed,
self.data
)
}
}
impl<D: DataMut> Reset for GLWECiphertextCompressed<D> {
fn reset(&mut self) {
self.data.reset();
self.basek = 0;
self.k = 0;
self.rank = 0;
self.seed = [0u8; 32];
}
}
impl<D: DataMut> FillUniform for GLWECiphertextCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.data.fill_uniform(source);
}
}
impl<D: Data> Infos for GLWECiphertextCompressed<D> {
type Inner = VecZnx<D>;
fn inner(&self) -> &Self::Inner {
&self.data
}
fn basek(&self) -> usize {
self.basek
}
fn k(&self) -> usize {
self.k
}
}
impl<D: Data> GLWECiphertextCompressed<D> {
pub fn rank(&self) -> usize {
self.rank
}
}
impl GLWECiphertextCompressed<Vec<u8>> {
pub fn alloc(n: usize, basek: usize, k: usize, rank: usize) -> Self {
Self {
data: VecZnx::alloc(n, 1, k.div_ceil(basek)),
basek,
k,
rank,
seed: [0u8; 32],
}
}
pub fn bytes_of(n: usize, basek: usize, k: usize) -> usize {
GLWECiphertext::bytes_of(n, basek, k, 1)
}
}
impl<D: DataMut> ReaderFrom for GLWECiphertextCompressed<D> {
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
self.k = reader.read_u64::<LittleEndian>()? as usize;
self.basek = reader.read_u64::<LittleEndian>()? as usize;
self.rank = reader.read_u64::<LittleEndian>()? as usize;
reader.read_exact(&mut self.seed)?;
self.data.read_from(reader)
}
}
impl<D: DataRef> WriterTo for GLWECiphertextCompressed<D> {
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
writer.write_u64::<LittleEndian>(self.k as u64)?;
writer.write_u64::<LittleEndian>(self.basek as u64)?;
writer.write_u64::<LittleEndian>(self.rank as u64)?;
writer.write_all(&self.seed)?;
self.data.write_to(writer)
}
}
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D> {
fn decompress(&mut self, module: &Module<B>, other: &GLWECiphertextCompressed<DR>)
where
Module<B>: VecZnxCopy + VecZnxFillUniform,
{
#[cfg(debug_assertions)]
{
use backend::hal::api::ZnxInfos;
assert_eq!(
self.n(),
other.data.n(),
"invalid receiver: self.n()={} != other.n()={}",
self.n(),
other.data.n()
);
assert_eq!(
self.size(),
other.size(),
"invalid receiver: self.size()={} != other.size()={}",
self.size(),
other.size()
);
assert_eq!(
self.rank(),
other.rank(),
"invalid receiver: self.rank()={} != other.rank()={}",
self.rank(),
other.rank()
);
}
let mut source: Source = Source::new(other.seed);
self.decompress_internal(module, other, &mut source);
}
}
impl<D: DataMut> GLWECiphertext<D> {
pub(crate) fn decompress_internal<DataOther, B: Backend>(
&mut self,
module: &Module<B>,
other: &GLWECiphertextCompressed<DataOther>,
source: &mut Source,
) where
DataOther: DataRef,
Module<B>: VecZnxCopy + VecZnxFillUniform,
{
#[cfg(debug_assertions)]
{
assert_eq!(self.rank(), other.rank())
}
let k: usize = other.k;
let basek: usize = other.basek;
let cols: usize = other.rank() + 1;
module.vec_znx_copy(&mut self.data, 0, &other.data, 0);
(1..cols).for_each(|i| {
module.vec_znx_fill_uniform(basek, &mut self.data, i, k, source);
});
self.basek = basek;
self.k = k;
}
}

View File

@@ -48,8 +48,8 @@ impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> {
{
Self {
data: module.vec_znx_dft_alloc(n, rank + 1, k.div_ceil(basek)),
basek: basek,
k: k,
basek,
k,
dist: Distribution::NONE,
}
}

View File

@@ -15,7 +15,7 @@ impl<D: Data, B: Backend> Infos for GLWEToLWESwitchingKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -15,7 +15,7 @@ impl<D: Data, B: Backend> Infos for LWESwitchingKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -16,7 +16,7 @@ impl<D: Data, B: Backend> Infos for LWEToGLWESwitchingKeyPrepared<D, B> {
type Inner = VmpPMat<D, B>;
fn inner(&self) -> &Self::Inner {
&self.0.inner()
self.0.inner()
}
fn basek(&self) -> usize {

View File

@@ -11,7 +11,7 @@ use backend::hal::{
use crate::layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared};
impl<D: DataRef> GGLWECiphertext<D> {
pub fn assert_noise<B: Backend, DataSk, DataWant>(
pub fn assert_noise<B, DataSk, DataWant>(
self,
module: &Module<B>,
sk: &GLWESecretPrepared<DataSk, B>,
@@ -30,7 +30,7 @@ impl<D: DataRef> GGLWECiphertext<D> {
+ VecZnxBigNormalize<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxSubScalarInplace,
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
{
let digits: usize = self.digits();
let basek: usize = self.basek();
@@ -47,7 +47,7 @@ impl<D: DataRef> GGLWECiphertext<D> {
(0..self.rank_in()).for_each(|col_i| {
(0..self.rows()).for_each(|row_i| {
self.at(row_i, col_i)
.decrypt(&module, &mut pt, &sk, scratch.borrow());
.decrypt(module, &mut pt, sk, scratch.borrow());
module.vec_znx_sub_scalar_inplace(
&mut pt.data,

View File

@@ -12,7 +12,7 @@ use backend::hal::{
use crate::layouts::{GGSWCiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared};
impl<D: DataRef> GGSWCiphertext<D> {
pub fn assert_noise<B: Backend, DataSk, DataScalar, F>(
pub fn assert_noise<B, DataSk, DataScalar, F>(
&self,
module: &Module<B>,
sk_prepared: &GLWESecretPrepared<DataSk, B>,
@@ -36,7 +36,7 @@ impl<D: DataRef> GGSWCiphertext<D> {
+ VecZnxDftToVecZnxBigTmpA<B>
+ VecZnxAddScalarInplace
+ VecZnxSubABInplace,
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
F: Fn(usize) -> f64,
{
let basek: usize = self.basek();
@@ -65,7 +65,7 @@ impl<D: DataRef> GGSWCiphertext<D> {
}
self.at(row_i, col_j)
.decrypt(module, &mut pt_have, &sk_prepared, scratch.borrow());
.decrypt(module, &mut pt_have, sk_prepared, scratch.borrow());
module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt.data, 0);
@@ -81,7 +81,7 @@ impl<D: DataRef> GGSWCiphertext<D> {
}
impl<D: DataRef> GGSWCiphertext<D> {
pub fn print_noise<B: Backend, DataSk, DataScalar>(
pub fn print_noise<B, DataSk, DataScalar>(
&self,
module: &Module<B>,
sk_prepared: &GLWESecretPrepared<DataSk, B>,
@@ -104,7 +104,7 @@ impl<D: DataRef> GGSWCiphertext<D> {
+ VecZnxDftToVecZnxBigTmpA<B>
+ VecZnxAddScalarInplace
+ VecZnxSubABInplace,
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
{
let basek: usize = self.basek();
let k: usize = self.k();
@@ -132,7 +132,7 @@ impl<D: DataRef> GGSWCiphertext<D> {
}
self.at(row_i, col_j)
.decrypt(module, &mut pt_have, &sk_prepared, scratch.borrow());
.decrypt(module, &mut pt_have, sk_prepared, scratch.borrow());
module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt.data, 0);

View File

@@ -15,7 +15,7 @@ use crate::{
};
impl<D: DataRef> GLWECiphertext<D> {
pub fn assert_noise<B: Backend, DataSk, DataPt>(
pub fn assert_noise<B, DataSk, DataPt>(
&self,
module: &Module<B>,
sk_prepared: &GLWESecretPrepared<DataSk, B>,
@@ -35,7 +35,7 @@ impl<D: DataRef> GLWECiphertext<D> {
+ VecZnxNormalizeTmpBytes
+ VecZnxSubABInplace
+ VecZnxNormalizeInplace<B>,
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
{
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), self.basek(), self.k());
@@ -46,7 +46,7 @@ impl<D: DataRef> GLWECiphertext<D> {
self.k(),
));
self.decrypt(module, &mut pt_have, &sk_prepared, scratch.borrow());
self.decrypt(module, &mut pt_have, sk_prepared, scratch.borrow());
module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt_want.data, 0);
module.vec_znx_normalize_inplace(self.basek(), &mut pt_have.data, 0, scratch.borrow());

View File

@@ -2,6 +2,7 @@ mod gglwe_ct;
mod ggsw_ct;
mod glwe_ct;
#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
pub(crate) fn var_noise_gglwe_product(
n: f64,
@@ -33,6 +34,7 @@ pub(crate) fn var_noise_gglwe_product(
noise
}
#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
pub(crate) fn log2_std_noise_gglwe_product(
n: f64,
@@ -62,6 +64,7 @@ pub(crate) fn log2_std_noise_gglwe_product(
noise.log2().min(-1.0).max(-(a_logq as f64)) // max noise is [-2^{-1}, 2^{-1}]
}
#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
pub(crate) fn noise_ggsw_product(
n: f64,
@@ -95,6 +98,7 @@ pub(crate) fn noise_ggsw_product(
noise.log2().min(-1.0) // max noise is [-2^{-1}, 2^{-1}]
}
#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
pub(crate) fn noise_ggsw_keyswitch(
n: f64,

View File

@@ -41,6 +41,7 @@ pub trait TakeGLWEPt<B: Backend> {
}
pub trait TakeGGLWE {
#[allow(clippy::too_many_arguments)]
fn take_gglwe(
&mut self,
n: usize,
@@ -54,6 +55,7 @@ pub trait TakeGGLWE {
}
pub trait TakeGGLWEPrepared<B: Backend> {
#[allow(clippy::too_many_arguments)]
fn take_gglwe_prepared(
&mut self,
n: usize,
@@ -113,6 +115,7 @@ pub trait TakeGLWEPkPrepared<B: Backend> {
}
pub trait TakeGLWESwitchingKey {
#[allow(clippy::too_many_arguments)]
fn take_glwe_switching_key(
&mut self,
n: usize,
@@ -126,6 +129,7 @@ pub trait TakeGLWESwitchingKey {
}
pub trait TakeGLWESwitchingKeyPrepared<B: Backend> {
#[allow(clippy::too_many_arguments)]
fn take_glwe_switching_key_prepared(
&mut self,
n: usize,
@@ -292,8 +296,8 @@ where
);
(
GGLWECiphertext {
data: data,
basek: basek,
data,
basek,
k,
digits,
},
@@ -353,8 +357,8 @@ where
);
(
GGLWECiphertextPrepared {
data: data,
basek: basek,
data,
basek,
k,
digits,
},

View File

@@ -23,7 +23,8 @@ use crate::{
noise::log2_std_noise_gglwe_product,
};
pub fn test_gglwe_automorphism_key_automorphism<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_gglwe_automorphism_key_automorphism<B>(
module: &Module<B>,
p0: i64,
p1: i64,
@@ -65,7 +66,8 @@ pub fn test_gglwe_automorphism_key_automorphism<B: Backend>(
+ SvpPPolAlloc<B>
+ VecZnxBigAddInplace<B>
+ VecZnxSubScalarInplace,
B: ScratchOwnedAllocImpl<B>
B: Backend
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
+ ScratchAvailableImpl<B>
+ TakeScalarZnxImpl<B>
@@ -186,7 +188,8 @@ pub fn test_gglwe_automorphism_key_automorphism<B: Backend>(
});
}
pub fn test_gglwe_automorphism_key_automorphism_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(
module: &Module<B>,
p0: i64,
p1: i64,
@@ -241,7 +244,8 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B: Backend>(
+ VecZnxCopy
+ VmpPMatAlloc<B>
+ VmpPrepare<B>,
B: ScratchOwnedAllocImpl<B>
B: Backend
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
+ ScratchAvailableImpl<B>
+ TakeScalarZnxImpl<B>

View File

@@ -24,7 +24,8 @@ use crate::{
noise::noise_ggsw_keyswitch,
};
pub fn test_ggsw_automorphism<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_ggsw_automorphism<B>(
p: i64,
module: &Module<B>,
basek: usize,
@@ -72,7 +73,8 @@ pub fn test_ggsw_automorphism<B: Backend>(
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace
+ VecZnxAutomorphism,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -178,10 +180,11 @@ pub fn test_ggsw_automorphism<B: Backend>(
) + 0.5
};
ct_out.assert_noise(module, &sk_prepared, &pt_scalar, &max_noise);
ct_out.assert_noise(module, &sk_prepared, &pt_scalar, max_noise);
}
pub fn test_ggsw_automorphism_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_ggsw_automorphism_inplace<B>(
p: i64,
module: &Module<B>,
basek: usize,
@@ -229,7 +232,8 @@ pub fn test_ggsw_automorphism_inplace<B: Backend>(
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace
+ VecZnxAutomorphism,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -325,5 +329,5 @@ pub fn test_ggsw_automorphism_inplace<B: Backend>(
) + 0.5
};
ct.assert_noise(module, &sk_prepared, &pt_scalar, &max_noise);
ct.assert_noise(module, &sk_prepared, &pt_scalar, max_noise);
}

View File

@@ -23,7 +23,8 @@ use crate::{
noise::log2_std_noise_gglwe_product,
};
pub fn test_glwe_automorphism<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_glwe_automorphism<B>(
module: &Module<B>,
basek: usize,
p: i64,
@@ -63,7 +64,8 @@ pub fn test_glwe_automorphism<B: Backend>(
+ VecZnxAutomorphismInplace
+ VmpPMatAlloc<B>
+ VmpPrepare<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -150,7 +152,8 @@ pub fn test_glwe_automorphism<B: Backend>(
ct_out.assert_noise(module, &sk_prepared, &pt_want, max_noise + 1.0);
}
pub fn test_glwe_automorphism_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_glwe_automorphism_inplace<B>(
module: &Module<B>,
basek: usize,
p: i64,
@@ -189,7 +192,8 @@ pub fn test_glwe_automorphism_inplace<B: Backend>(
+ VecZnxAutomorphismInplace
+ VmpPMatAlloc<B>
+ VmpPrepare<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>

View File

@@ -21,7 +21,7 @@ use crate::layouts::{
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc},
};
pub fn test_lwe_to_glwe<B: Backend>(module: &Module<B>)
pub fn test_lwe_to_glwe<B>(module: &Module<B>)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -51,7 +51,8 @@ where
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -131,7 +132,7 @@ where
assert_eq!(glwe_pt.data.at(0, 0)[0], lwe_pt.data.at(0, 0)[0]);
}
pub fn test_glwe_to_lwe<B: Backend>(module: &Module<B>)
pub fn test_glwe_to_lwe<B>(module: &Module<B>)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -161,7 +162,8 @@ where
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>

View File

@@ -21,7 +21,7 @@ use crate::layouts::{
prepared::{GLWESecretPrepared, PrepareAlloc},
};
pub fn test_gglwe_automorphisk_key_encrypt_sk<B: Backend>(
pub fn test_gglwe_automorphisk_key_encrypt_sk<B>(
module: &Module<B>,
basek: usize,
k_ksk: usize,
@@ -60,7 +60,8 @@ pub fn test_gglwe_automorphisk_key_encrypt_sk<B: Backend>(
+ VecZnxCopy
+ VmpPMatAlloc<B>
+ VmpPrepare<B>,
B: ScratchOwnedAllocImpl<B>
B: Backend
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
+ ScratchAvailableImpl<B>
+ TakeScalarZnxImpl<B>
@@ -114,7 +115,7 @@ pub fn test_gglwe_automorphisk_key_encrypt_sk<B: Backend>(
.assert_noise(module, &sk_out_prepared, &sk.data, sigma);
}
pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B: Backend>(
pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>(
module: &Module<B>,
basek: usize,
k_ksk: usize,
@@ -153,7 +154,8 @@ pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B: Backend>(
+ VecZnxCopy
+ VmpPMatAlloc<B>
+ VmpPrepare<B>,
B: ScratchOwnedAllocImpl<B>
B: Backend
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
+ ScratchAvailableImpl<B>
+ TakeScalarZnxImpl<B>

View File

@@ -20,7 +20,7 @@ use crate::layouts::{
prepared::{GLWESecretPrepared, PrepareAlloc},
};
pub fn test_gglwe_switching_key_encrypt_sk<B: Backend>(
pub fn test_gglwe_switching_key_encrypt_sk<B>(
module: &Module<B>,
basek: usize,
k_ksk: usize,
@@ -54,7 +54,8 @@ pub fn test_gglwe_switching_key_encrypt_sk<B: Backend>(
+ VecZnxCopy
+ VmpPMatAlloc<B>
+ VmpPrepare<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -99,7 +100,7 @@ pub fn test_gglwe_switching_key_encrypt_sk<B: Backend>(
.assert_noise(module, &sk_out_prepared, &sk_in.data, sigma);
}
pub fn test_gglwe_switching_key_compressed_encrypt_sk<B: Backend>(
pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>(
module: &Module<B>,
basek: usize,
k_ksk: usize,
@@ -133,7 +134,8 @@ pub fn test_gglwe_switching_key_compressed_encrypt_sk<B: Backend>(
+ VecZnxCopy
+ VmpPMatAlloc<B>
+ VmpPrepare<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>

View File

@@ -20,7 +20,7 @@ use crate::layouts::{
prepared::{GLWESecretPrepared, PrepareAlloc},
};
pub fn test_ggsw_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64)
pub fn test_ggsw_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -49,7 +49,8 @@ where
+ VecZnxDftAlloc<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxDftToVecZnxBigTmpA<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -94,17 +95,11 @@ where
let noise_f = |_col_i: usize| -(k as f64) + sigma.log2() + 0.5;
ct.assert_noise(module, &sk_prepared, &pt_scalar, &noise_f);
ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f);
}
pub fn test_ggsw_compressed_encrypt_sk<B: Backend>(
module: &Module<B>,
basek: usize,
k: usize,
digits: usize,
rank: usize,
sigma: f64,
) where
pub fn test_ggsw_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
+ VecZnxDftFromVecZnx<B>
@@ -132,7 +127,8 @@ pub fn test_ggsw_compressed_encrypt_sk<B: Backend>(
+ VecZnxDftAlloc<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxDftToVecZnxBigTmpA<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -180,5 +176,5 @@ pub fn test_ggsw_compressed_encrypt_sk<B: Backend>(
let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(n, basek, k, rows, digits, rank);
ct.decompress(module, &ct_compressed);
ct.assert_noise(module, &sk_prepared, &pt_scalar, &noise_f);
ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f);
}

View File

@@ -23,7 +23,7 @@ use crate::{
operations::GLWEOperations,
};
pub fn test_glwe_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize)
pub fn test_glwe_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigAllocBytes
@@ -60,7 +60,8 @@ where
+ VecZnxAddNormal
+ VecZnxNormalize<B>
+ VecZnxSub,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -109,14 +110,8 @@ where
assert!(noise_have <= noise_want + 0.2);
}
pub fn test_glwe_compressed_encrypt_sk<B: Backend>(
module: &Module<B>,
basek: usize,
k_ct: usize,
k_pt: usize,
sigma: f64,
rank: usize,
) where
pub fn test_glwe_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigAllocBytes
+ VecZnxDftFromVecZnx<B>
@@ -153,7 +148,8 @@ pub fn test_glwe_compressed_encrypt_sk<B: Backend>(
+ VecZnxNormalize<B>
+ VecZnxSub
+ VecZnxCopy,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -213,7 +209,7 @@ pub fn test_glwe_compressed_encrypt_sk<B: Backend>(
);
}
pub fn test_glwe_encrypt_zero_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, sigma: f64, rank: usize)
pub fn test_glwe_encrypt_zero_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, sigma: f64, rank: usize)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigAllocBytes
@@ -250,7 +246,8 @@ where
+ VecZnxAddNormal
+ VecZnxNormalize<B>
+ VecZnxSub,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -290,7 +287,7 @@ where
assert!((sigma - pt.data.std(basek, 0) * (k_ct as f64).exp2()) <= 0.2);
}
pub fn test_glwe_encrypt_pk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize)
pub fn test_glwe_encrypt_pk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -315,7 +312,8 @@ where
+ VecZnxDftAlloc<B>
+ SvpApply<B>
+ VecZnxBigAddNormal<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>

View File

@@ -20,7 +20,7 @@ use crate::layouts::{
prepared::{GLWESecretPrepared, PrepareAlloc},
};
pub fn test_glwe_tensor_key_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
pub fn test_glwe_tensor_key_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -49,7 +49,8 @@ where
+ VecZnxAddScalarInplace
+ VecZnxSwithcDegree
+ VecZnxSubScalarInplace,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -130,7 +131,7 @@ where
})
}
pub fn test_glwe_tensor_key_compressed_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
pub fn test_glwe_tensor_key_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -159,7 +160,8 @@ where
+ VecZnxAddScalarInplace
+ VecZnxSwithcDegree
+ VecZnxSubScalarInplace,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>

View File

@@ -23,7 +23,8 @@ use crate::{
noise::noise_ggsw_product,
};
pub fn test_gglwe_switching_key_external_product<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_gglwe_switching_key_external_product<B>(
module: &Module<B>,
basek: usize,
k_out: usize,
@@ -63,7 +64,8 @@ pub fn test_gglwe_switching_key_external_product<B: Backend>(
+ VmpApply<B>
+ VmpApplyAdd<B>
+ VmpPrepare<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -165,7 +167,8 @@ pub fn test_gglwe_switching_key_external_product<B: Backend>(
.assert_noise(module, &sk_out_prepared, &sk_in.data, max_noise + 0.5);
}
pub fn test_gglwe_switching_key_external_product_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_gglwe_switching_key_external_product_inplace<B>(
module: &Module<B>,
basek: usize,
k_ct: usize,
@@ -204,7 +207,8 @@ pub fn test_gglwe_switching_key_external_product_inplace<B: Backend>(
+ VmpApply<B>
+ VmpApplyAdd<B>
+ VmpPrepare<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>

View File

@@ -23,7 +23,8 @@ use crate::{
noise::noise_ggsw_product,
};
pub fn test_ggsw_external_product<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_ggsw_external_product<B>(
module: &Module<B>,
basek: usize,
k_in: usize,
@@ -64,7 +65,8 @@ pub fn test_ggsw_external_product<B: Backend>(
+ VecZnxDftAlloc<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxDftToVecZnxBigTmpA<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -154,10 +156,11 @@ pub fn test_ggsw_external_product<B: Backend>(
) + 0.5
};
ct_ggsw_lhs_out.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, &max_noise);
ct_ggsw_lhs_out.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, max_noise);
}
pub fn test_ggsw_external_product_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_ggsw_external_product_inplace<B>(
module: &Module<B>,
basek: usize,
k_ct: usize,
@@ -197,7 +200,8 @@ pub fn test_ggsw_external_product_inplace<B: Backend>(
+ VecZnxDftAlloc<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxDftToVecZnxBigTmpA<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
@@ -287,5 +291,5 @@ pub fn test_ggsw_external_product_inplace<B: Backend>(
) + 0.5
};
ct_ggsw_lhs.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, &max_noise);
ct_ggsw_lhs.assert_noise(module, &sk_prepared, &pt_ggsw_lhs, max_noise);
}

View File

@@ -22,7 +22,8 @@ use crate::{
noise::noise_ggsw_product,
};
pub fn test_glwe_external_product<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_glwe_external_product<B>(
module: &Module<B>,
basek: usize,
k_out: usize,
@@ -58,7 +59,8 @@ pub fn test_glwe_external_product<B: Backend>(
+ VmpApplyTmpBytes
+ VmpApply<B>
+ VmpApplyAdd<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -158,7 +160,8 @@ pub fn test_glwe_external_product<B: Backend>(
ct_glwe_out.assert_noise(module, &sk_prepared, &pt_want, max_noise + 0.5);
}
pub fn test_glwe_external_product_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_glwe_external_product_inplace<B>(
module: &Module<B>,
basek: usize,
k_ct: usize,
@@ -193,7 +196,8 @@ pub fn test_glwe_external_product_inplace<B: Backend>(
+ VmpApplyTmpBytes
+ VmpApply<B>
+ VmpApplyAdd<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>

View File

@@ -22,7 +22,8 @@ use crate::{
noise::log2_std_noise_gglwe_product,
};
pub fn test_gglwe_switching_key_keyswitch<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_gglwe_switching_key_keyswitch<B>(
module: &Module<B>,
basek: usize,
k_out: usize,
@@ -62,7 +63,8 @@ pub fn test_gglwe_switching_key_keyswitch<B: Backend>(
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxSubScalarInplace,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -174,7 +176,8 @@ pub fn test_gglwe_switching_key_keyswitch<B: Backend>(
.assert_noise(module, &sk2_prepared, &sk0.data, max_noise + 0.5);
}
pub fn test_gglwe_switching_key_keyswitch_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_gglwe_switching_key_keyswitch_inplace<B>(
module: &Module<B>,
basek: usize,
k_ct: usize,
@@ -212,7 +215,8 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B: Backend>(
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxSubScalarInplace,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>

View File

@@ -23,7 +23,8 @@ use crate::{
noise::noise_ggsw_keyswitch,
};
pub fn test_ggsw_keyswitch<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_ggsw_keyswitch<B>(
module: &Module<B>,
basek: usize,
k_out: usize,
@@ -67,7 +68,8 @@ pub fn test_ggsw_keyswitch<B: Backend>(
+ VecZnxDftAddInplace<B>
+ VecZnxBigAlloc<B>
+ VecZnxDftAlloc<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -167,10 +169,11 @@ pub fn test_ggsw_keyswitch<B: Backend>(
) + 0.5
};
ct_out.assert_noise(module, &sk_out_prepared, &pt_scalar, &max_noise);
ct_out.assert_noise(module, &sk_out_prepared, &pt_scalar, max_noise);
}
pub fn test_ggsw_keyswitch_inplace<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_ggsw_keyswitch_inplace<B>(
module: &Module<B>,
basek: usize,
k_ct: usize,
@@ -213,7 +216,8 @@ pub fn test_ggsw_keyswitch_inplace<B: Backend>(
+ VecZnxDftAddInplace<B>
+ VecZnxBigAlloc<B>
+ VecZnxDftAlloc<B>,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -304,5 +308,5 @@ pub fn test_ggsw_keyswitch_inplace<B: Backend>(
) + 0.5
};
ct.assert_noise(module, &sk_out_prepared, &pt_scalar, &max_noise);
ct.assert_noise(module, &sk_out_prepared, &pt_scalar, max_noise);
}

View File

@@ -22,7 +22,8 @@ use crate::{
noise::log2_std_noise_gglwe_product,
};
pub fn test_glwe_keyswitch<B: Backend>(
#[allow(clippy::too_many_arguments)]
pub fn test_glwe_keyswitch<B>(
module: &Module<B>,
basek: usize,
k_out: usize,
@@ -60,7 +61,8 @@ pub fn test_glwe_keyswitch<B: Backend>(
+ VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -147,7 +149,7 @@ pub fn test_glwe_keyswitch<B: Backend>(
ct_out.assert_noise(module, &sk_out_prepared, &pt_want, max_noise + 0.5);
}
pub fn test_glwe_keyswitch_inplace<B: Backend>(
pub fn test_glwe_keyswitch_inplace<B>(
module: &Module<B>,
basek: usize,
k_ct: usize,
@@ -183,7 +185,8 @@ pub fn test_glwe_keyswitch_inplace<B: Backend>(
+ VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>

View File

@@ -20,7 +20,7 @@ use crate::layouts::{
prepared::{LWESwitchingKeyPrepared, PrepareAlloc},
};
pub fn test_lwe_keyswitch<B: Backend>(module: &Module<B>)
pub fn test_lwe_keyswitch<B>(module: &Module<B>)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -50,7 +50,8 @@ where
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>

View File

@@ -26,7 +26,7 @@ use crate::{
},
};
pub fn test_glwe_packing<B: Backend>(module: &Module<B>)
pub fn test_glwe_packing<B>(module: &Module<B>)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxAutomorphism
@@ -64,7 +64,8 @@ where
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace
+ VecZnxCopy,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>
@@ -155,7 +156,7 @@ where
pt.rotate_inplace(module, -(1 << log_batch)); // X^-batch * pt
if reverse_bits_msb(i, log_n as u32) % 5 == 0 {
if reverse_bits_msb(i, log_n as u32).is_multiple_of(5) {
packer.add(module, Some(&ct), &auto_keys, scratch.borrow());
} else {
packer.add(
@@ -173,7 +174,7 @@ where
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_ct);
let mut data: Vec<i64> = vec![0i64; n];
data.iter_mut().enumerate().for_each(|(i, x)| {
if i % 5 == 0 {
if i.is_multiple_of(5) {
*x = reverse_bits_msb(i, log_n as u32) as i64;
}
});

View File

@@ -26,7 +26,7 @@ use crate::{
noise::var_noise_gglwe_product,
};
pub fn test_glwe_trace_inplace<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
pub fn test_glwe_trace_inplace<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxAutomorphism
@@ -61,7 +61,8 @@ where
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxCopy,
B: TakeVecZnxDftImpl<B>
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
+ TakeSvpPPolImpl<B>
+ ScratchOwnedAllocImpl<B>