diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs index ccb7e07..3e6d447 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs @@ -217,6 +217,18 @@ pub trait FheUintPrepare; + fn fhe_uint_prepare_partial( + &self, + res: &mut FheUintPrepared, + bits: &FheUint, + count: usize, + key: &K, + scratch: &mut Scratch, + ) where + DM: DataMut, + DB: DataRef, + DK: DataRef, + K: BDDKeyHelper; } impl FheUintPrepare for Module @@ -259,6 +271,30 @@ where dst.prepare(self, &tmp_ggsw, scratch_1); } } + + fn fhe_uint_prepare_partial( + &self, + res: &mut FheUintPrepared, + bits: &FheUint, + count: usize, + key: &K, + scratch: &mut Scratch, + ) where + DM: DataMut, + DB: DataRef, + DK: DataRef, + K: BDDKeyHelper, + { + let (cbt, ks) = key.get_cbt_key(); + + let mut lwe: LWE> = LWE::alloc_from_infos(bits); //TODO: add TakeLWE + let (mut tmp_ggsw, scratch_1) = scratch.take_ggsw(res); + for (bit, dst) in res.bits[0..count].iter_mut().enumerate() { // TODO: set the rest of the bits to a prepared zero GGSW + bits.get_bit_lwe(self, bit, &mut lwe, ks, scratch_1); + cbt.execute_to_constant(self, &mut tmp_ggsw, &lwe, 1, 1, scratch_1); + dst.prepare(self, &tmp_ggsw, scratch_1); + } + } } impl FheUintPrepared { @@ -273,4 +309,15 @@ impl FheUintPrepared { { module.fhe_uint_prepare(self, other, key, scratch); } + pub fn prepare_partial(&mut self, module: &M, other: &FheUint, count: usize, key: &K, scratch: &mut Scratch) + where + BRA: BlindRotationAlgo, + O: DataRef, + DK: DataRef, + K: BDDKeyHelper, + M: FheUintPrepare, + Scratch: ScratchTakeCore, + { + module.fhe_uint_prepare_partial(self, other, count, key, scratch); + } }