use backend::hal::{ api::{SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, ZnxInfos}, layouts::{Backend, Data, DataMut, DataRef, Module, SvpPPol}, }; use crate::{dist::Distribution, layouts::GLWESecret, trait_families::GLWESecretExecModuleFamily}; pub struct GLWESecretExec { pub(crate) data: SvpPPol, pub(crate) dist: Distribution, } impl GLWESecretExec, B> { pub fn alloc(module: &Module, n: usize, rank: usize) -> Self where Module: GLWESecretExecModuleFamily, { Self { data: module.svp_ppol_alloc(n, rank), dist: Distribution::NONE, } } pub fn bytes_of(module: &Module, n: usize, rank: usize) -> usize where Module: GLWESecretExecModuleFamily, { module.svp_ppol_alloc_bytes(n, rank) } } impl GLWESecretExec, B> { pub fn from(module: &Module, sk: &GLWESecret) -> Self where D: DataRef, Module: GLWESecretExecModuleFamily, { let mut sk_dft: GLWESecretExec, B> = Self::alloc(module, sk.n(), sk.rank()); sk_dft.prepare(module, sk); sk_dft } } impl GLWESecretExec { pub fn n(&self) -> usize { self.data.n() } pub fn log_n(&self) -> usize { self.data.log_n() } pub fn rank(&self) -> usize { self.data.cols() } } impl GLWESecretExec { pub(crate) fn prepare(&mut self, module: &Module, sk: &GLWESecret) where O: DataRef, Module: GLWESecretExecModuleFamily, { (0..self.rank()).for_each(|i| { module.svp_prepare(&mut self.data, i, &sk.data, i); }); self.dist = sk.dist } }