use poulpy_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 GLWECiphertext { pub fn assert_noise( &self, module: &Module, sk_prepared: &GLWESecretPrepared, pt_want: &GLWEPlaintext, max_noise: f64, ) where DataSk: DataRef, DataPt: DataRef, Module: VecZnxDftAllocBytes + VecZnxBigAllocBytes + VecZnxDftFromVecZnx + SvpApplyInplace + VecZnxDftToVecZnxBigConsume + VecZnxBigAddInplace + VecZnxBigAddSmallInplace + VecZnxBigNormalize + VecZnxNormalizeTmpBytes + VecZnxSubABInplace + VecZnxNormalizeInplace, B: Backend + TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc(self.n(), self.basek(), self.k()); let mut scratch: ScratchOwned = ScratchOwned::alloc(GLWECiphertext::decrypt_scratch_space( module, 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); } }