use backend::hal::{ api::{ FillUniform, Reset, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, }, layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; use crate::layouts::{ Infos, LWESwitchingKey, compressed::{Decompress, GGLWESwitchingKeyCompressed}, }; use std::fmt; #[derive(PartialEq, Eq, Clone)] pub struct LWESwitchingKeyCompressed(pub(crate) GGLWESwitchingKeyCompressed); impl fmt::Debug for LWESwitchingKeyCompressed { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self) } } impl FillUniform for LWESwitchingKeyCompressed { fn fill_uniform(&mut self, source: &mut sampling::source::Source) { self.0.fill_uniform(source); } } impl Reset for LWESwitchingKeyCompressed { fn reset(&mut self) { self.0.reset(); } } impl fmt::Display for LWESwitchingKeyCompressed { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "(LWESwitchingKeyCompressed) {}", self.0) } } impl Infos for LWESwitchingKeyCompressed { type Inner = MatZnx; fn inner(&self) -> &Self::Inner { self.0.inner() } fn basek(&self) -> usize { self.0.basek() } fn k(&self) -> usize { self.0.k() } } impl LWESwitchingKeyCompressed { pub fn digits(&self) -> usize { self.0.digits() } pub fn rank(&self) -> usize { self.0.rank() } pub fn rank_in(&self) -> usize { self.0.rank_in() } pub fn rank_out(&self) -> usize { self.0.rank_out() } } impl ReaderFrom for LWESwitchingKeyCompressed { fn read_from(&mut self, reader: &mut R) -> std::io::Result<()> { self.0.read_from(reader) } } impl WriterTo for LWESwitchingKeyCompressed { fn write_to(&self, writer: &mut W) -> std::io::Result<()> { self.0.write_to(writer) } } impl LWESwitchingKeyCompressed> { pub fn alloc(n: usize, basek: usize, k: usize, rows: usize) -> Self { Self(GGLWESwitchingKeyCompressed::alloc( n, basek, k, rows, 1, 1, 1, )) } pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where Module: VecZnxDftAllocBytes + VecZnxBigNormalize + VecZnxDftFromVecZnx + SvpApplyInplace + VecZnxDftToVecZnxBigConsume + VecZnxNormalizeTmpBytes + VecZnxFillUniform + VecZnxSubABInplace + VecZnxAddInplace + VecZnxNormalizeInplace + VecZnxAddNormal + VecZnxNormalize + VecZnxSub + SvpPrepare + SvpPPolAllocBytes + SvpPPolAlloc, { LWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k) } } impl Decompress> for LWESwitchingKey { fn decompress(&mut self, module: &Module, other: &LWESwitchingKeyCompressed) where Module: VecZnxCopy + VecZnxFillUniform, { self.0.decompress(module, &other.0); } }