mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
updated repo for publishing (#74)
This commit is contained in:
committed by
GitHub
parent
0be569eca0
commit
62eb87cc07
57
poulpy-core/src/noise/glwe_ct.rs
Normal file
57
poulpy-core/src/noise/glwe_ct.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use poulpy_backend::hal::{
|
||||
api::{
|
||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace,
|
||||
VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume,
|
||||
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSubABInplace,
|
||||
},
|
||||
layouts::{Backend, DataRef, Module, ScratchOwned},
|
||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
layouts::GLWEPlaintext,
|
||||
layouts::prepared::GLWESecretPrepared,
|
||||
layouts::{GLWECiphertext, Infos},
|
||||
};
|
||||
|
||||
impl<D: DataRef> GLWECiphertext<D> {
|
||||
pub fn assert_noise<B, DataSk, DataPt>(
|
||||
&self,
|
||||
module: &Module<B>,
|
||||
sk_prepared: &GLWESecretPrepared<DataSk, B>,
|
||||
pt_want: &GLWEPlaintext<DataPt>,
|
||||
max_noise: f64,
|
||||
) where
|
||||
DataSk: DataRef,
|
||||
DataPt: DataRef,
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigAllocBytes
|
||||
+ VecZnxDftFromVecZnx<B>
|
||||
+ SvpApplyInplace<B>
|
||||
+ VecZnxDftToVecZnxBigConsume<B>
|
||||
+ VecZnxBigAddInplace<B>
|
||||
+ VecZnxBigAddSmallInplace<B>
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxNormalizeTmpBytes
|
||||
+ VecZnxSubABInplace
|
||||
+ VecZnxNormalizeInplace<B>,
|
||||
B: Backend + TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||
{
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), self.basek(), self.k());
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWECiphertext::decrypt_scratch_space(
|
||||
module,
|
||||
self.n(),
|
||||
self.basek(),
|
||||
self.k(),
|
||||
));
|
||||
|
||||
self.decrypt(module, &mut pt_have, sk_prepared, scratch.borrow());
|
||||
|
||||
module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt_want.data, 0);
|
||||
module.vec_znx_normalize_inplace(self.basek(), &mut pt_have.data, 0, scratch.borrow());
|
||||
|
||||
let noise_have: f64 = pt_have.data.std(self.basek(), 0).log2();
|
||||
assert!(noise_have <= max_noise, "{} {}", noise_have, max_noise);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user