mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
core refactoring (#69)
This commit is contained in:
committed by
GitHub
parent
6303346eef
commit
8d9897b88b
63
core/src/noise/gglwe_ct.rs
Normal file
63
core/src/noise/gglwe_ct.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use backend::hal::{
|
||||
api::{ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxStd, VecZnxSubScalarInplace, ZnxZero},
|
||||
layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned},
|
||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretExec},
|
||||
trait_families::GLWEDecryptFamily,
|
||||
};
|
||||
|
||||
impl<D: DataRef> GGLWECiphertext<D> {
|
||||
pub fn assert_noise<B: Backend, DataSk, DataWant>(
|
||||
self,
|
||||
module: &Module<B>,
|
||||
sk: &GLWESecretExec<DataSk, B>,
|
||||
pt_want: &ScalarZnx<DataWant>,
|
||||
max_noise: f64,
|
||||
) where
|
||||
DataSk: DataRef,
|
||||
DataWant: DataRef,
|
||||
Module<B>: GLWEDecryptFamily<B> + VecZnxStd + VecZnxSubScalarInplace,
|
||||
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||
{
|
||||
let digits: usize = self.digits();
|
||||
let basek: usize = self.basek();
|
||||
let k: usize = self.k();
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWECiphertext::decrypt_scratch_space(
|
||||
module,
|
||||
self.n(),
|
||||
basek,
|
||||
k,
|
||||
));
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), basek, k);
|
||||
|
||||
(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());
|
||||
|
||||
module.vec_znx_sub_scalar_inplace(
|
||||
&mut pt.data,
|
||||
0,
|
||||
(digits - 1) + row_i * digits,
|
||||
pt_want,
|
||||
col_i,
|
||||
);
|
||||
|
||||
let noise_have: f64 = module.vec_znx_std(basek, &pt.data, 0).log2();
|
||||
|
||||
assert!(
|
||||
noise_have <= max_noise,
|
||||
"noise_have: {} > max_noise: {}",
|
||||
noise_have,
|
||||
max_noise
|
||||
);
|
||||
|
||||
pt.data.zero();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user