fix remaining issues before fixing tests

This commit is contained in:
Pro7ech
2025-10-18 11:59:50 +02:00
parent a282e88126
commit 0b8dcb1f16
34 changed files with 224 additions and 160 deletions

View File

@@ -1,9 +1,9 @@
use poulpy_backend::cpu_spqlios::FFT64Spqlios;
use poulpy_core::{
GLWEOperations, SIGMA,
GLWESub, SIGMA,
layouts::{
Base2K, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, RingDegree, TorusPrecision,
prepared::{GLWESecretPrepared, PrepareAlloc},
prepared::GLWESecretPrepared,
},
};
use poulpy_hal::{
@@ -43,9 +43,9 @@ fn main() {
let glwe_pt_infos: GLWEPlaintextLayout = GLWEPlaintextLayout { n, base2k, k: k_pt };
// Allocates ciphertext & plaintexts
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_ct_infos);
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_infos);
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_infos);
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_ct_infos);
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&module, &glwe_pt_infos);
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&module, &glwe_pt_infos);
// CPRNG
let mut source_xs: Source = Source::new([0u8; 32]);
@@ -58,11 +58,12 @@ fn main() {
);
// Generate secret-key
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_ct_infos);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_ct_infos);
sk.fill_ternary_prob(0.5, &mut source_xs);
// Backend-prepared secret
let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
sk_prepared.prepare(&module, &sk);
// Uniform plaintext
module.vec_znx_fill_uniform(base2k.into(), &mut pt_want.data, 0, &mut source_xa);
@@ -81,7 +82,7 @@ fn main() {
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
// Diff between pt - Dec(Enc(pt))
pt_want.sub_inplace_ab(&module, &pt_have);
module.glwe_sub_inplace(&mut pt_want, &pt_have);
// Ideal vs. actual noise
let noise_have: f64 = pt_want.data.std(base2k.into(), 0) * (ct.k().as_u32() as f64).exp2();