mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Add CBT prototype (#68)
This commit is contained in:
committed by
GitHub
parent
940742ce6c
commit
504cb72f82
@@ -71,3 +71,53 @@ impl<D: DataRef> GGSWCiphertext<D> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> GGSWCiphertext<D> {
|
||||
pub fn print_noise<B: Backend, DataSk, DataScalar>(
|
||||
&self,
|
||||
module: &Module<B>,
|
||||
sk_exec: &GLWESecretExec<DataSk, B>,
|
||||
pt_want: &ScalarZnx<DataScalar>,
|
||||
) where
|
||||
DataSk: DataRef,
|
||||
DataScalar: DataRef,
|
||||
Module<B>: GGSWAssertNoiseFamily<B> + VecZnxAddScalarInplace + VecZnxSubABInplace + VecZnxStd,
|
||||
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||
{
|
||||
let basek: usize = self.basek();
|
||||
let k: usize = self.k();
|
||||
let digits: usize = self.digits();
|
||||
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), basek, k);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), basek, k);
|
||||
let mut pt_dft: VecZnxDft<Vec<u8>, B> = module.vec_znx_dft_alloc(self.n(), 1, self.size());
|
||||
let mut pt_big: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(self.n(), 1, self.size());
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GLWECiphertext::decrypt_scratch_space(module, self.n(), basek, k) | module.vec_znx_normalize_tmp_bytes(module.n()),
|
||||
);
|
||||
|
||||
(0..self.rank() + 1).for_each(|col_j| {
|
||||
(0..self.rows()).for_each(|row_i| {
|
||||
module.vec_znx_add_scalar_inplace(&mut pt.data, 0, (digits - 1) + row_i * digits, pt_want, 0);
|
||||
|
||||
// mul with sk[col_j-1]
|
||||
if col_j > 0 {
|
||||
module.vec_znx_dft_from_vec_znx(1, 0, &mut pt_dft, 0, &pt.data, 0);
|
||||
module.svp_apply_inplace(&mut pt_dft, 0, &sk_exec.data, col_j - 1);
|
||||
module.vec_znx_dft_to_vec_znx_big_tmp_a(&mut pt_big, 0, &mut pt_dft, 0);
|
||||
module.vec_znx_big_normalize(basek, &mut pt.data, 0, &pt_big, 0, scratch.borrow());
|
||||
}
|
||||
|
||||
self.at(row_i, col_j)
|
||||
.decrypt(module, &mut pt_have, &sk_exec, scratch.borrow());
|
||||
|
||||
module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt.data, 0);
|
||||
|
||||
let std_pt: f64 = module.vec_znx_std(basek, &pt_have.data, 0).log2();
|
||||
println!("{}", std_pt);
|
||||
pt.data.zero();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user