diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_rotation.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_rotation.rs index a3bbf2e..7124907 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_rotation.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_rotation.rs @@ -1,21 +1,64 @@ use poulpy_core::{ GLWECopy, GLWERotate, ScratchTakeCore, - layouts::{GLWE, GLWEToMut}, + layouts::{GGSW, GGSWInfos, GGSWToMut, GLWE, GLWEInfos, GLWEToMut}, }; use poulpy_hal::layouts::{Backend, Scratch}; use crate::tfhe::bdd_arithmetic::{Cmux, GetGGSWBit, UnsignedInteger}; -pub trait BDDRotation +pub trait GGSWBlindRotation +where + Self: GLWEBlindRotation, + Scratch: ScratchTakeCore, +{ + fn ggsw_blind_rotation( + &self, + res: &mut R, + k: &K, + bit_start: usize, + bit_size: usize, + bit_step: usize, + scratch: &mut Scratch, + ) where + R: GGSWToMut, + K: GetGGSWBit, + Scratch: ScratchTakeCore, + { + let res: &mut GGSW<&mut [u8]> = &mut res.to_mut(); + + for row in 0..res.dnum().into() { + for col in 0..(res.rank() + 1).into() { + self.glwe_blind_rotation( + &mut res.at_mut(row, col), + k, + bit_start, + bit_size, + bit_step, + scratch, + ); + } + } + } +} + +pub trait GLWEBlindRotation where Self: GLWECopy + GLWERotate + Cmux, Scratch: ScratchTakeCore, { + fn glwe_blind_rotation_tmp_bytes(&self, res_infos: &R, b_infos: &B) -> usize + where + R: GLWEInfos, + B: GGSWInfos, + { + self.cmux_tmp_bytes(res_infos, res_infos, b_infos) + GLWE::bytes_of_from_infos(res_infos) + } + /// Homomorphic multiplication of res by X^{k[bit_start..bit_start + bit_size] * bit_step}. - fn bdd_rotate( + fn glwe_blind_rotation( &self, res: &mut R, - k: K, + k: &K, bit_start: usize, bit_size: usize, bit_step: usize, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs index 3c34f94..4613208 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs @@ -3,7 +3,7 @@ use core::panic; use itertools::Itertools; use poulpy_core::{ GLWEAdd, GLWECopy, GLWEExternalProduct, GLWESub, ScratchTakeCore, - layouts::{GLWE, GLWEToMut, GLWEToRef, LWEInfos, prepared::GGSWPreparedToRef}, + layouts::{GGSWInfos, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, prepared::GGSWPreparedToRef}, }; use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, ZnxZero}; @@ -148,6 +148,15 @@ where Self: GLWEExternalProduct + GLWESub + GLWEAdd, Scratch: ScratchTakeCore, { + fn cmux_tmp_bytes(&self, res_infos: &R, a_infos: &A, b_infos: &B) -> usize + where + R: GLWEInfos, + A: GLWEInfos, + B: GGSWInfos, + { + self.glwe_external_product_tmp_bytes(res_infos, a_infos, b_infos) + } + fn cmux(&self, res: &mut R, t: &T, f: &F, s: &S, scratch: &mut Scratch) where R: GLWEToMut,