use backend::hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}; use crate::{ GGLWEExecLayoutFamily, GLWESwitchingKeyExec, Infos, lwe::keyswtich_layouts::{GLWEToLWESwitchingKey, LWESwitchingKey, LWEToGLWESwitchingKey}, }; #[derive(PartialEq, Eq)] pub struct GLWEToLWESwitchingKeyExec(pub(crate) GLWESwitchingKeyExec); impl Infos for GLWEToLWESwitchingKeyExec { type Inner = VmpPMat; fn inner(&self) -> &Self::Inner { &self.0.inner() } fn basek(&self) -> usize { self.0.basek() } fn k(&self) -> usize { self.0.k() } } impl GLWEToLWESwitchingKeyExec { 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 GLWEToLWESwitchingKeyExec, B> { pub fn alloc(module: &Module, n: usize, basek: usize, k: usize, rows: usize, rank_in: usize) -> Self where Module: GGLWEExecLayoutFamily, { Self(GLWESwitchingKeyExec::alloc( module, n, basek, k, rows, 1, rank_in, 1, )) } pub fn bytes_of(module: &Module, n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank_in: usize) -> usize where Module: GGLWEExecLayoutFamily, { GLWESwitchingKeyExec::, B>::bytes_of(module, n, basek, k, rows, digits, rank_in, 1) } pub fn from( module: &Module, other: &GLWEToLWESwitchingKey, scratch: &mut Scratch, ) -> Self where Module: GGLWEExecLayoutFamily, { let mut ksk_exec: GLWEToLWESwitchingKeyExec, B> = Self::alloc( module, other.0.n(), other.0.basek(), other.0.k(), other.0.rows(), other.0.rank_in(), ); ksk_exec.prepare(module, other, scratch); ksk_exec } } impl GLWEToLWESwitchingKeyExec { pub fn prepare(&mut self, module: &Module, other: &GLWEToLWESwitchingKey, scratch: &mut Scratch) where DataOther: DataRef, Module: GGLWEExecLayoutFamily, { self.0.prepare(module, &other.0, scratch); } } /// A special [GLWESwitchingKey] required to for the conversion from [LWECiphertext] to [GLWECiphertext]. #[derive(PartialEq, Eq)] pub struct LWEToGLWESwitchingKeyExec(pub(crate) GLWESwitchingKeyExec); impl Infos for LWEToGLWESwitchingKeyExec { type Inner = VmpPMat; fn inner(&self) -> &Self::Inner { &self.0.inner() } fn basek(&self) -> usize { self.0.basek() } fn k(&self) -> usize { self.0.k() } } impl LWEToGLWESwitchingKeyExec { 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 LWEToGLWESwitchingKeyExec, B> { pub fn alloc(module: &Module, n: usize, basek: usize, k: usize, rows: usize, rank_out: usize) -> Self where Module: GGLWEExecLayoutFamily, { Self(GLWESwitchingKeyExec::alloc( module, n, basek, k, rows, 1, 1, rank_out, )) } pub fn bytes_of(module: &Module, n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank_out: usize) -> usize where Module: GGLWEExecLayoutFamily, { GLWESwitchingKeyExec::, B>::bytes_of(module, n, basek, k, rows, digits, 1, rank_out) } pub fn from( module: &Module, other: &LWEToGLWESwitchingKey, scratch: &mut Scratch, ) -> Self where Module: GGLWEExecLayoutFamily, { let mut ksk_exec: LWEToGLWESwitchingKeyExec, B> = Self::alloc( module, other.0.n(), other.0.basek(), other.0.k(), other.0.rows(), other.0.rank(), ); ksk_exec.prepare(module, other, scratch); ksk_exec } } impl LWEToGLWESwitchingKeyExec { pub fn prepare(&mut self, module: &Module, other: &LWEToGLWESwitchingKey, scratch: &mut Scratch) where DataOther: DataRef, Module: GGLWEExecLayoutFamily, { self.0.prepare(module, &other.0, scratch); } } #[derive(PartialEq, Eq)] pub struct LWESwitchingKeyExec(pub(crate) GLWESwitchingKeyExec); impl Infos for LWESwitchingKeyExec { type Inner = VmpPMat; fn inner(&self) -> &Self::Inner { &self.0.inner() } fn basek(&self) -> usize { self.0.basek() } fn k(&self) -> usize { self.0.k() } } impl LWESwitchingKeyExec { 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 LWESwitchingKeyExec, B> { pub fn alloc(module: &Module, n: usize, basek: usize, k: usize, rows: usize) -> Self where Module: GGLWEExecLayoutFamily, { Self(GLWESwitchingKeyExec::alloc( module, n, basek, k, rows, 1, 1, 1, )) } pub fn bytes_of(module: &Module, n: usize, basek: usize, k: usize, rows: usize, digits: usize) -> usize where Module: GGLWEExecLayoutFamily, { GLWESwitchingKeyExec::, B>::bytes_of(module, n, basek, k, rows, digits, 1, 1) } pub fn from(module: &Module, other: &LWESwitchingKey, scratch: &mut Scratch) -> Self where Module: GGLWEExecLayoutFamily, { let mut ksk_exec: LWESwitchingKeyExec, B> = Self::alloc( module, other.0.n(), other.0.basek(), other.0.k(), other.0.rows(), ); ksk_exec.prepare(module, other, scratch); ksk_exec } } impl LWESwitchingKeyExec { pub fn prepare(&mut self, module: &Module, other: &LWESwitchingKey, scratch: &mut Scratch) where DataOther: DataRef, Module: GGLWEExecLayoutFamily, { self.0.prepare(module, &other.0, scratch); } }