use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Scratch, SvpPPol}; use std::marker::PhantomData; use poulpy_core::{ Distribution, layouts::{Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared}, }; use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyInfos}; pub trait BlindRotationKeyPreparedFactory { fn blind_rotation_key_prepared_alloc(&self, infos: &A) -> BlindRotationKeyPrepared, BRA, BE> where A: BlindRotationKeyInfos; fn blind_rotation_key_prepare_tmp_bytes(&self, infos: &A) -> usize where A: BlindRotationKeyInfos; fn prepare_blind_rotation_key( &self, res: &mut BlindRotationKeyPrepared, other: &BlindRotationKey, scratch: &mut Scratch, ) where DM: DataMut, DR: DataRef; } impl BlindRotationKeyPrepared, BRA, BE> { pub fn alloc(module: &M, infos: &A) -> Self where A: BlindRotationKeyInfos, M: BlindRotationKeyPreparedFactory, { module.blind_rotation_key_prepared_alloc(infos) } pub fn prepare_tmp_bytes(module: &M, infos: &A) -> usize where A: BlindRotationKeyInfos, M: BlindRotationKeyPreparedFactory, { module.blind_rotation_key_prepare_tmp_bytes(infos) } } impl BlindRotationKeyPrepared { pub fn prepare(&mut self, module: &M, other: &BlindRotationKey, scratch: &mut Scratch) where M: BlindRotationKeyPreparedFactory, { module.prepare_blind_rotation_key(self, other, scratch); } } #[derive(PartialEq, Eq)] pub struct BlindRotationKeyPrepared { pub(crate) data: Vec>, pub(crate) dist: Distribution, pub(crate) x_pow_a: Option, B>>>, pub(crate) _phantom: PhantomData, } impl BlindRotationKeyInfos for BlindRotationKeyPrepared { fn n_glwe(&self) -> Degree { self.n() } fn n_lwe(&self) -> Degree { Degree(self.data.len() as u32) } } impl LWEInfos for BlindRotationKeyPrepared { fn base2k(&self) -> Base2K { self.data[0].base2k() } fn k(&self) -> TorusPrecision { self.data[0].k() } fn n(&self) -> Degree { self.data[0].n() } fn size(&self) -> usize { self.data[0].size() } } impl GLWEInfos for BlindRotationKeyPrepared { fn rank(&self) -> Rank { self.data[0].rank() } } impl GGSWInfos for BlindRotationKeyPrepared { fn dsize(&self) -> poulpy_core::layouts::Dsize { Dsize(1) } fn dnum(&self) -> Dnum { self.data[0].dnum() } } impl BlindRotationKeyPrepared { pub fn block_size(&self) -> usize { match self.dist { Distribution::BinaryBlock(value) => value, _ => 1, } } }