Remove Zn (replaced by VecZnx), add more cross-base2k ops & tests

This commit is contained in:
Pro7ech
2025-11-18 01:08:20 +01:00
parent a3264b8851
commit f39e3e2865
52 changed files with 952 additions and 1550 deletions

View File

@@ -2,7 +2,7 @@ use poulpy_core::{
GLWENormalize,
layouts::{
GGLWEToGGSWKeyLayout, GGSW, GGSWLayout, GLWE, GLWEAutomorphismKeyLayout, GLWELayout, GLWEPlaintext, GLWESecret, LWE,
LWEInfos, LWELayout, LWEPlaintext, LWESecret,
LWELayout, LWEPlaintext, LWESecret,
prepared::{GGSWPrepared, GLWESecretPrepared},
},
};
@@ -15,7 +15,7 @@ use poulpy_backend::FFT64Avx as BackendImpl;
use poulpy_backend::FFT64Ref as BackendImpl;
use poulpy_hal::{
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, ZnNormalizeInplace},
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxNormalizeInplace},
layouts::{Module, ScalarZnx, ScratchOwned, ZnxView, ZnxViewMut},
source::Source,
};
@@ -155,20 +155,21 @@ fn main() {
pt_lwe.encode_i64(data, (k_lwe_pt + 1).into()); // +1 for padding bit
// Normalize plaintext to nicely print coefficients
module.zn_normalize_inplace(
pt_lwe.n().into(),
base2k,
pt_lwe.data_mut(),
0,
scratch.borrow(),
);
module.vec_znx_normalize_inplace(base2k, pt_lwe.data_mut(), 0, scratch.borrow());
println!("pt_lwe: {pt_lwe}");
// LWE ciphertext
let mut ct_lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(&lwe_infos);
// Encrypt LWE Plaintext
ct_lwe.encrypt_sk(&module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
ct_lwe.encrypt_sk(
&module,
&pt_lwe,
&sk_lwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
let now: Instant = Instant::now();

View File

@@ -111,7 +111,14 @@ pub fn test_blind_rotation<BRA: BlindRotationAlgo, M, BE: Backend>(
pt_lwe.encode_i64(x, (log_message_modulus + 1).into());
lwe.encrypt_sk(module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
lwe.encrypt_sk(
module,
&pt_lwe,
&sk_lwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
let f = |x: i64| -> i64 { 2 * x + 1 };

View File

@@ -132,7 +132,14 @@ where
println!("pt_lwe: {pt_lwe}");
let mut ct_lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(&lwe_infos);
ct_lwe.encrypt_sk(module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
ct_lwe.encrypt_sk(
module,
&pt_lwe,
&sk_lwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
let now: Instant = Instant::now();
let mut cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::alloc_from_infos(&cbt_infos);
@@ -313,7 +320,14 @@ where
println!("pt_lwe: {pt_lwe}");
let mut ct_lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(&lwe_infos);
ct_lwe.encrypt_sk(module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
ct_lwe.encrypt_sk(
module,
&pt_lwe,
&sk_lwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
let now: Instant = Instant::now();
let mut cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::alloc_from_infos(&cbt_infos);