mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-09 20:56:47 +01:00
dbg normalize check
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use poulpy_core::{
|
||||
GLWESub, SIGMA,
|
||||
layouts::{
|
||||
Base2K, Degree, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::GLWESecretPrepared,
|
||||
prepared::GLWESecretPrepared, Base2K, Degree, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank,
|
||||
TorusPrecision, GLWE,
|
||||
},
|
||||
GLWESub, SIGMA,
|
||||
};
|
||||
|
||||
#[cfg(all(feature = "enable-avx", target_arch = "x86_64"))]
|
||||
@@ -71,18 +71,38 @@ fn main() {
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BackendImpl> = GLWESecretPrepared::alloc(&module, rank);
|
||||
sk_prepared.prepare(&module, &sk);
|
||||
|
||||
// DBG:
|
||||
// obtain pk from sk
|
||||
let mut pk = poulpy_core::layouts::GLWEPublicKey::alloc_from_infos(&glwe_ct_infos);
|
||||
pk.generate(&module, &sk_prepared, &mut source_xa, &mut source_xe);
|
||||
// Backend-prepared publickey:
|
||||
let mut pk_prepared: poulpy_core::layouts::GLWEPublicKeyPrepared<Vec<u8>, BackendImpl> =
|
||||
poulpy_core::layouts::GLWEPublicKeyPrepared::alloc(&module, base2k, k_ct, rank);
|
||||
pk_prepared.prepare(&module, &pk);
|
||||
|
||||
// Uniform plaintext
|
||||
module.vec_znx_fill_uniform(base2k.into(), &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
// Encryption
|
||||
ct.encrypt_sk(
|
||||
// ct.encrypt_sk(
|
||||
// &module,
|
||||
// &pt_want,
|
||||
// &sk_prepared,
|
||||
// &mut source_xa,
|
||||
// &mut source_xe,
|
||||
// scratch.borrow(),
|
||||
// );
|
||||
|
||||
// DBG: encrypt with public key
|
||||
ct.encrypt_pk(
|
||||
&module,
|
||||
&pt_want,
|
||||
&sk_prepared,
|
||||
&pk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
dbg!("encrypted");
|
||||
|
||||
// Decryption
|
||||
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
|
||||
|
||||
@@ -339,6 +339,7 @@ where
|
||||
+ SvpPPolBytesOf
|
||||
+ ModuleN
|
||||
+ VecZnxDftBytesOf,
|
||||
BE: Backend<ScalarBig = i64>,
|
||||
Scratch<BE>: ScratchTakeBasic,
|
||||
{
|
||||
fn glwe_encrypt_pk_internal<R, P, K>(
|
||||
@@ -413,11 +414,31 @@ where
|
||||
|
||||
// ct[i] = norm(ci_big)
|
||||
self.vec_znx_big_normalize(&mut res.data, base2k, 0, i, &ci_big, base2k, 0, scratch_2);
|
||||
|
||||
use poulpy_hal::layouts::ZnxView;
|
||||
for k in 0..res.size(){
|
||||
normalize_check(i, k, ci_big.at(i, k), res.data.at(i, k));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DBG
|
||||
fn normalize_check(i: usize /*col*/, k: usize, a: &[i64], b: &[i64]) {
|
||||
assert_eq!(a.len(), b.len());
|
||||
// let c_{i,j} be the coefficients of the normalized polynomial, then
|
||||
// i. it is K-normalized if c_{i,j} \in [-2^{K-1}, 2^{K-1}) \forall i=0,\ldots,N-1; j \geq 1
|
||||
// ii. it is reduced if additionally c_{i,0}=0 ~\forall~ i=0, \ldots, N-1
|
||||
if k == 0 {
|
||||
for j in 0..a.len() {
|
||||
assert_eq!(b[j], a[j]);
|
||||
}
|
||||
}
|
||||
// println!("a {:?}", a);
|
||||
// println!("b {:?}", b);
|
||||
}
|
||||
|
||||
pub(crate) trait GLWEEncryptSkInternal<BE: Backend> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn glwe_encrypt_sk_internal<R, P, S>(
|
||||
|
||||
Reference in New Issue
Block a user