diff --git a/poulpy-core/src/layouts/glwe_to_lwe_key.rs b/poulpy-core/src/layouts/glwe_to_lwe_key.rs index 2541d32..65ea1cf 100644 --- a/poulpy-core/src/layouts/glwe_to_lwe_key.rs +++ b/poulpy-core/src/layouts/glwe_to_lwe_key.rs @@ -175,12 +175,12 @@ impl GLWEToLWEKey> { assert_eq!( infos.rank_out().0, 1, - "rank_out > 1 is not supported for GLWEToLWESwitchingKey" + "rank_out > 1 is not supported for GLWEToLWEKey" ); assert_eq!( infos.dsize().0, 1, - "dsize > 1 is not supported for GLWEToLWESwitchingKey" + "dsize > 1 is not supported for GLWEToLWEKey" ); Self::bytes_of( infos.n(), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs index db4a1de..3f9628f 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs @@ -1,9 +1,10 @@ -use itertools::Itertools; -use poulpy_core::layouts::prepared::GGSWPreparedToRef; +use std::marker::PhantomData; + +use poulpy_core::layouts::GGSWPrepared; use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch}; use crate::tfhe::bdd_arithmetic::{ - ExecuteBDDCircuit, FheUintBlocks, FheUintBlocksPrepared, GetBitCircuitInfo, UnsignedInteger, circuits, + BitSize, ExecuteBDDCircuit, FheUint, FheUintPrepared, GetBitCircuitInfo, GetGGSWBit, UnsignedInteger, circuits, }; impl ExecuteBDDCircuit2WTo1W for Module where Self: Sized + ExecuteBDDCircuit {} @@ -15,10 +16,10 @@ where /// Operations Z x Z -> Z fn execute_bdd_circuit_2w_to_1w( &self, - out: &mut FheUintBlocks, + out: &mut FheUint, circuit: &C, - a: &FheUintBlocksPrepared, - b: &FheUintBlocksPrepared, + a: &FheUintPrepared, + b: &FheUintPrepared, scratch: &mut Scratch, ) where C: GetBitCircuitInfo, @@ -26,20 +27,59 @@ where A: DataRef, B: DataRef, { - assert_eq!(out.blocks.len(), T::WORD_SIZE); - assert_eq!(b.blocks.len(), T::WORD_SIZE); - assert_eq!(b.blocks.len(), T::WORD_SIZE); + assert_eq!(out.bits.len(), T::WORD_SIZE); + assert_eq!(b.bits.len(), T::WORD_SIZE); + assert_eq!(b.bits.len(), T::WORD_SIZE); // Collects inputs into a single array - let inputs: Vec<&dyn GGSWPreparedToRef> = a - .blocks - .iter() - .map(|x| x as &dyn GGSWPreparedToRef) - .chain(b.blocks.iter().map(|x| x as &dyn GGSWPreparedToRef)) - .collect_vec(); + let inputs: Vec<&dyn GetGGSWBit> = [a as &dyn GetGGSWBit, b as &dyn GetGGSWBit].to_vec(); + let helper: FheUintHelper<'_, T, BE> = FheUintHelper { + data: inputs, + _phantom: PhantomData, + }; // Evaluates out[i] = circuit[i](a, b) - self.execute_bdd_circuit(&mut out.blocks, &inputs, circuit, scratch); + self.execute_bdd_circuit(&mut out.bits, &helper, circuit, scratch); + } +} + +struct FheUintHelper<'a, T: UnsignedInteger, BE: Backend> { + data: Vec<&'a dyn GetGGSWBit>, + _phantom: PhantomData, +} + +impl<'a, T: UnsignedInteger, BE: Backend> GetGGSWBit for FheUintHelper<'a, T, BE> { + fn get_bit(&self, bit: usize) -> GGSWPrepared<&[u8], BE> { + let lo: usize = bit % T::WORD_SIZE; + let hi: usize = bit / T::WORD_SIZE; + self.data[hi].get_bit(lo) + } +} + +impl<'a, T: UnsignedInteger, BE: Backend> BitSize for FheUintHelper<'a, T, BE> { + fn bit_size(&self) -> usize { + T::WORD_SIZE * self.data.len() + } +} + +pub struct JoinedBits { + pub lo: A, + pub hi: B, + pub split: usize, // 32 in your example +} + +impl GetGGSWBit for JoinedBits +where + BE: Backend, + A: GetGGSWBit, + B: GetGGSWBit, +{ + fn get_bit(&self, bit: usize) -> GGSWPrepared<&[u8], BE> { + if bit < self.split { + self.lo.get_bit(bit) + } else { + self.hi.get_bit(bit - self.split) + } } } @@ -51,8 +91,8 @@ macro_rules! define_bdd_2w_to_1w_trait { fn $method_name( &mut self, module: &M, - a: &FheUintBlocksPrepared, - b: &FheUintBlocksPrepared, + a: &FheUintPrepared, + b: &FheUintPrepared, scratch: &mut Scratch, ) where M: ExecuteBDDCircuit2WTo1W, @@ -65,12 +105,12 @@ macro_rules! define_bdd_2w_to_1w_trait { #[macro_export] macro_rules! impl_bdd_2w_to_1w_trait { ($trait_name:ident, $method_name:ident, $ty:ty, $n:literal, $circuit_ty:ty, $output_circuits:path) => { - impl $trait_name<$ty, BE> for FheUintBlocks { + impl $trait_name<$ty, BE> for FheUint { fn $method_name( &mut self, module: &M, - a: &FheUintBlocksPrepared, - b: &FheUintBlocksPrepared, + a: &FheUintPrepared, + b: &FheUintPrepared, scratch: &mut Scratch, ) where M: ExecuteBDDCircuit2WTo1W<$ty, BE>, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_rotation.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_rotation.rs index 1f552d7..77c2155 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_rotation.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/blind_rotation.rs @@ -43,7 +43,7 @@ where ) where R: GGSWToMut, A: GGSWToRef, - K: GetGGSWBit, + K: GetGGSWBit, Scratch: ScratchTakeCore, { let res: &mut GGSW<&mut [u8]> = &mut res.to_mut(); @@ -90,7 +90,7 @@ where ) where R: GGSWToMut, S: ScalarZnxToRef, - K: GetGGSWBit, + K: GetGGSWBit, Scratch: ScratchTakeCore, { let res: &mut GGSW<&mut [u8]> = &mut res.to_mut(); @@ -162,7 +162,7 @@ where ) where R: GLWEToMut, A: GLWEToRef, - K: GetGGSWBit, + K: GetGGSWBit, Scratch: ScratchTakeCore, { assert!(bit_rsh + bit_mask <= T::WORD_SIZE); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_compressed.rs similarity index 87% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs rename to poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_compressed.rs index 1d3e218..d4b180b 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_compressed.rs @@ -15,10 +15,10 @@ use std::{collections::HashMap, marker::PhantomData}; use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger}; -/// A FHE ciphertext encrypting a [UnsignedInteger]. -pub struct FheUintWord(pub(crate) GLWE, pub(crate) PhantomData); +/// An FHE ciphertext encrypting the bits of an [UnsignedInteger] in compressed format (ideal for decryption/serialization). +pub struct FheUintCompressed(pub(crate) GLWE, pub(crate) PhantomData); -impl FheUintWord { +impl FheUintCompressed { #[allow(dead_code)] fn post_process( &mut self, @@ -46,7 +46,7 @@ impl FheUintWord { } } -impl LWEInfos for FheUintWord { +impl LWEInfos for FheUintCompressed { fn base2k(&self) -> poulpy_core::layouts::Base2K { self.0.base2k() } @@ -60,13 +60,13 @@ impl LWEInfos for FheUintWord { } } -impl GLWEInfos for FheUintWord { +impl GLWEInfos for FheUintCompressed { fn rank(&self) -> poulpy_core::layouts::Rank { self.0.rank() } } -impl FheUintWord { +impl FheUintCompressed { pub fn encrypt_sk( &mut self, module: &M, @@ -109,7 +109,7 @@ impl FheUintWord { } } -impl FheUintWord { +impl FheUintCompressed { pub fn decrypt(&self, module: &M, sk: &S, scratch: &mut Scratch) -> T where S: GLWESecretPreparedToRef + GLWEInfos, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs similarity index 71% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs rename to poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs index a232dc2..050cff0 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared.rs @@ -18,31 +18,24 @@ use crate::tfhe::bdd_arithmetic::ToBits; use crate::tfhe::bdd_arithmetic::UnsignedInteger; /// A prepared FHE ciphertext encrypting the bits of an [UnsignedInteger]. -pub struct FheUintBlocksPrepared { - pub(crate) blocks: Vec>, - pub(crate) _base: u8, +pub struct FheUintPrepared { + pub(crate) bits: Vec>, pub(crate) _phantom: PhantomData, } -impl FheUintBlocksPrepared { - pub fn blocks(&self) -> &Vec> { - &self.blocks - } -} - impl FheUintBlocksPreparedFactory for Module where Self: Sized + GGSWPreparedFactory { } -pub trait GetGGSWBit { +pub trait GetGGSWBit { fn get_bit(&self, bit: usize) -> GGSWPrepared<&[u8], BE>; } -impl GetGGSWBit for FheUintBlocksPrepared { +impl GetGGSWBit for FheUintPrepared { fn get_bit(&self, bit: usize) -> GGSWPrepared<&[u8], BE> { - assert!(bit <= self.blocks.len()); - self.blocks[bit].to_ref() + assert!(bit <= self.bits.len()); + self.bits[bit].to_ref() } } @@ -50,10 +43,10 @@ pub trait GetGGSWBitMut { fn get_bit(&mut self, bit: usize) -> GGSWPrepared<&mut [u8], BE>; } -impl GetGGSWBitMut for FheUintBlocksPrepared { +impl GetGGSWBitMut for FheUintPrepared { fn get_bit(&mut self, bit: usize) -> GGSWPrepared<&mut [u8], BE> { - assert!(bit <= self.blocks.len()); - self.blocks[bit].to_mut() + assert!(bit <= self.bits.len()); + self.bits[bit].to_mut() } } @@ -61,28 +54,27 @@ pub trait FheUintBlocksPreparedFactory where Self: Sized + GGSWPreparedFactory, { - fn alloc_fhe_uint_blocks_prepared( + fn alloc_fhe_uint_prepared( &self, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank, - ) -> FheUintBlocksPrepared, T, BE> { - FheUintBlocksPrepared { - blocks: (0..T::WORD_SIZE) + ) -> FheUintPrepared, T, BE> { + FheUintPrepared { + bits: (0..T::WORD_SIZE) .map(|_| GGSWPrepared::alloc(self, base2k, k, dnum, dsize, rank)) .collect(), - _base: 1, _phantom: PhantomData, } } - fn alloc_fhe_uint_blocks_prepared_from_infos(&self, infos: &A) -> FheUintBlocksPrepared, T, BE> + fn alloc_fhe_uint_prepared_from_infos(&self, infos: &A) -> FheUintPrepared, T, BE> where A: GGSWInfos, { - self.alloc_fhe_uint_blocks_prepared( + self.alloc_fhe_uint_prepared( infos.base2k(), infos.k(), infos.dnum(), @@ -92,20 +84,20 @@ where } } -impl FheUintBlocksPrepared, T, BE> { +impl FheUintPrepared, T, BE> { pub fn alloc(module: &M, infos: &A) -> Self where A: GGSWInfos, M: FheUintBlocksPreparedFactory, { - module.alloc_fhe_uint_blocks_prepared_from_infos(infos) + module.alloc_fhe_uint_prepared_from_infos(infos) } pub fn alloc_with(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self where M: FheUintBlocksPreparedFactory, { - module.alloc_fhe_uint_blocks_prepared(base2k, k, dnum, dsize, rank) + module.alloc_fhe_uint_prepared(base2k, k, dnum, dsize, rank) } } @@ -118,9 +110,9 @@ pub trait FheUintBlocksPreparedEncryptSk + GGSWPreparedFactory, { - fn fhe_uint_blocks_prepared_encrypt_sk( + fn fhe_uint_prepared_encrypt_sk( &self, - res: &mut FheUintBlocksPrepared, + res: &mut FheUintPrepared, value: T, sk: &S, source_xa: &mut Source, @@ -145,12 +137,12 @@ where use poulpy_hal::layouts::ZnxViewMut; pt.at_mut(0, 0)[0] = value.bit(i) as i64; tmp_ggsw.encrypt_sk(self, &pt, sk, source_xa, source_xe, scratch_2); - res.blocks[i].prepare(self, &tmp_ggsw, scratch_2); + res.bits[i].prepare(self, &tmp_ggsw, scratch_2); } } } -impl FheUintBlocksPrepared { +impl FheUintPrepared { pub fn encrypt_sk( &mut self, module: &M, @@ -164,36 +156,36 @@ impl FheUintBlocksPrepared M: FheUintBlocksPreparedEncryptSk, Scratch: ScratchTakeCore, { - module.fhe_uint_blocks_prepared_encrypt_sk(self, value, sk, source_xa, source_xe, scratch); + module.fhe_uint_prepared_encrypt_sk(self, value, sk, source_xa, source_xe, scratch); } } -impl LWEInfos for FheUintBlocksPrepared { +impl LWEInfos for FheUintPrepared { fn base2k(&self) -> poulpy_core::layouts::Base2K { - self.blocks[0].base2k() + self.bits[0].base2k() } fn k(&self) -> poulpy_core::layouts::TorusPrecision { - self.blocks[0].k() + self.bits[0].k() } fn n(&self) -> poulpy_core::layouts::Degree { - self.blocks[0].n() + self.bits[0].n() } } -impl GLWEInfos for FheUintBlocksPrepared { +impl GLWEInfos for FheUintPrepared { fn rank(&self) -> poulpy_core::layouts::Rank { - self.blocks[0].rank() + self.bits[0].rank() } } -impl GGSWInfos for FheUintBlocksPrepared { +impl GGSWInfos for FheUintPrepared { fn dsize(&self) -> poulpy_core::layouts::Dsize { - self.blocks[0].dsize() + self.bits[0].dsize() } fn dnum(&self) -> poulpy_core::layouts::Dnum { - self.blocks[0].dnum() + self.bits[0].dnum() } } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_debug.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs similarity index 68% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_debug.rs rename to poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs index bf98972..890f2bf 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_debug.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fhe_uint_prepared_debug.rs @@ -1,8 +1,8 @@ use std::marker::PhantomData; -use crate::tfhe::bdd_arithmetic::{BDDKeyPrepared, FheUintBlockDebugPrepare, ToBits}; +use crate::tfhe::bdd_arithmetic::{BddKeyPrepared, FheUintBlockDebugPrepare, ToBits}; use crate::tfhe::{ - bdd_arithmetic::{FheUintBlocks, UnsignedInteger}, + bdd_arithmetic::{FheUint, UnsignedInteger}, blind_rotation::BlindRotationAlgo, circuit_bootstrapping::CirtuitBootstrappingExecute, }; @@ -18,13 +18,12 @@ use poulpy_core::{ use poulpy_hal::api::ModuleN; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; -pub struct FheUintBlocksPreparedDebug { - pub(crate) blocks: Vec>, - pub(crate) _base: u8, +pub struct FheUintPreparedDebug { + pub(crate) bits: Vec>, pub(crate) _phantom: PhantomData, } -impl FheUintBlocksPreparedDebug, T> { +impl FheUintPreparedDebug, T> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self where M: ModuleN, @@ -45,52 +44,51 @@ impl FheUintBlocksPreparedDebug, T> { M: ModuleN, { Self { - blocks: (0..T::WORD_SIZE) + bits: (0..T::WORD_SIZE) .map(|_| GGSW::alloc(module.n().into(), base2k, k, rank, dnum, dsize)) .collect(), - _base: 1, _phantom: PhantomData, } } } -impl LWEInfos for FheUintBlocksPreparedDebug { +impl LWEInfos for FheUintPreparedDebug { fn base2k(&self) -> poulpy_core::layouts::Base2K { - self.blocks[0].base2k() + self.bits[0].base2k() } fn k(&self) -> poulpy_core::layouts::TorusPrecision { - self.blocks[0].k() + self.bits[0].k() } fn n(&self) -> poulpy_core::layouts::Degree { - self.blocks[0].n() + self.bits[0].n() } } -impl GLWEInfos for FheUintBlocksPreparedDebug { +impl GLWEInfos for FheUintPreparedDebug { fn rank(&self) -> poulpy_core::layouts::Rank { - self.blocks[0].rank() + self.bits[0].rank() } } -impl GGSWInfos for FheUintBlocksPreparedDebug { +impl GGSWInfos for FheUintPreparedDebug { fn dsize(&self) -> poulpy_core::layouts::Dsize { - self.blocks[0].dsize() + self.bits[0].dsize() } fn dnum(&self) -> poulpy_core::layouts::Dnum { - self.blocks[0].dnum() + self.bits[0].dnum() } } -impl FheUintBlocksPreparedDebug { +impl FheUintPreparedDebug { pub fn print_noise(&self, module: &M, sk: &S, want: T) where S: GLWESecretPreparedToRef, M: GGSWNoise, { - for (i, ggsw) in self.blocks.iter().enumerate() { + for (i, ggsw) in self.bits.iter().enumerate() { use poulpy_hal::layouts::{ScalarZnx, ZnxViewMut}; let mut pt_want = ScalarZnx::alloc(self.n().into(), 1); pt_want.at_mut(0, 0)[0] = want.bit(i) as i64; @@ -104,7 +102,7 @@ impl FheUintBlocksPreparedDebug { M: GGSWNoise, F: Fn(usize) -> f64, { - for (i, ggsw) in self.blocks.iter().enumerate() { + for (i, ggsw) in self.bits.iter().enumerate() { use poulpy_hal::layouts::{ScalarZnx, ZnxViewMut}; let mut pt_want = ScalarZnx::alloc(self.n().into(), 1); pt_want.at_mut(0, 0)[0] = want.bit(i) as i64; @@ -118,33 +116,33 @@ where Self: LWEFromGLWE + CirtuitBootstrappingExecute + GGSWPreparedFactory, Scratch: ScratchTakeCore, { - fn fhe_uint_block_debug_prepare( + fn fhe_uint_debug_prepare( &self, - res: &mut FheUintBlocksPreparedDebug, - bits: &FheUintBlocks, - key: &BDDKeyPrepared, + res: &mut FheUintPreparedDebug, + bits: &FheUint, + key: &BddKeyPrepared, scratch: &mut Scratch, ) where DM: DataMut, DR0: DataRef, DR1: DataRef, { - assert_eq!(res.blocks.len(), bits.blocks.len()); + assert_eq!(res.bits.len(), bits.bits.len()); - let mut lwe: LWE> = LWE::alloc_from_infos(&bits.blocks[0]); //TODO: add TakeLWE - for (dst, src) in res.blocks.iter_mut().zip(bits.blocks.iter()) { + let mut lwe: LWE> = LWE::alloc_from_infos(&bits.bits[0]); //TODO: add TakeLWE + for (dst, src) in res.bits.iter_mut().zip(bits.bits.iter()) { lwe.from_glwe(self, src, &key.ks, scratch); key.cbt.execute_to_constant(self, dst, &lwe, 1, 1, scratch); } } } -impl FheUintBlocksPreparedDebug { +impl FheUintPreparedDebug { pub fn prepare( &mut self, module: &M, - other: &FheUintBlocks, - key: &BDDKeyPrepared, + other: &FheUint, + key: &BddKeyPrepared, scratch: &mut Scratch, ) where BRA: BlindRotationAlgo, @@ -153,6 +151,6 @@ impl FheUintBlocksPreparedDebug { M: FheUintBlockDebugPrepare, Scratch: ScratchTakeCore, { - module.fhe_uint_block_debug_prepare(self, other, key, scratch); + module.fhe_uint_debug_prepare(self, other, key, scratch); } } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fheuint.rs similarity index 80% rename from poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs rename to poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fheuint.rs index b708047..3865818 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/fheuint.rs @@ -13,50 +13,42 @@ use poulpy_hal::source::Source; use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger}; /// An FHE ciphertext encrypting the bits of an [UnsignedInteger]. -pub struct FheUintBlocks { - pub(crate) blocks: Vec>, - pub(crate) _base: u8, +pub struct FheUint { + pub(crate) bits: Vec>, pub(crate) _phantom: PhantomData, } -impl FheUintBlocks { - pub fn blocks(&self) -> &Vec> { - &self.blocks - } -} - -impl LWEInfos for FheUintBlocks { +impl LWEInfos for FheUint { fn base2k(&self) -> poulpy_core::layouts::Base2K { - self.blocks[0].base2k() + self.bits[0].base2k() } fn k(&self) -> poulpy_core::layouts::TorusPrecision { - self.blocks[0].k() + self.bits[0].k() } fn n(&self) -> poulpy_core::layouts::Degree { - self.blocks[0].n() + self.bits[0].n() } } -impl GLWEInfos for FheUintBlocks { +impl GLWEInfos for FheUint { fn rank(&self) -> poulpy_core::layouts::Rank { - self.blocks[0].rank() + self.bits[0].rank() } } -impl FheUintBlocks { - pub fn new(blocks: Vec>) -> Self { - assert_eq!(blocks.len(), T::WORD_SIZE); +impl FheUint { + pub fn new(bits: Vec>) -> Self { + assert_eq!(bits.len(), T::WORD_SIZE); Self { - blocks, - _base: 1, + bits, _phantom: PhantomData, } } } -impl FheUintBlocks, T> { +impl FheUint, T> { pub fn alloc_from_infos(module: &Module, infos: &A) -> Self where A: GLWEInfos, @@ -66,16 +58,15 @@ impl FheUintBlocks, T> { pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self { Self { - blocks: (0..T::WORD_SIZE) + bits: (0..T::WORD_SIZE) .map(|_| GLWE::alloc(module.n().into(), base2k, k, rank)) .collect(), - _base: 1, _phantom: PhantomData, } } } -impl FheUintBlocks { +impl FheUint { pub fn encrypt_sk( &mut self, module: &Module, @@ -110,12 +101,12 @@ impl FheUintBlocks { for i in 0..T::WORD_SIZE { pt.encode_coeff_i64(value.bit(i) as i64, TorusPrecision(2), 0); - self.blocks[i].encrypt_sk(module, &pt, sk, source_xa, source_xe, scratch_1); + self.bits[i].encrypt_sk(module, &pt, sk, source_xa, source_xe, scratch_1); } } } -impl FheUintBlocks { +impl FheUint { pub fn decrypt(&self, module: &Module, sk: &S, scratch: &mut Scratch) -> T where Module: GLWEDecrypt, @@ -143,7 +134,7 @@ impl FheUintBlocks { let scale: f64 = 4.0 / ((1 << base2k) as f64); for (i, bit) in bits.iter_mut().enumerate().take(T::WORD_SIZE) { - self.blocks[i].decrypt(module, &mut pt, sk, scratch_1); + self.bits[i].decrypt(module, &mut pt, sk, scratch_1); let value: i64 = pt.decode_coeff_i64(base2k.into(), 0); *bit = ((value as f64) * scale).round() as u8; } @@ -177,7 +168,7 @@ impl FheUintBlocks { for (i, noise_i) in noise.iter_mut().enumerate().take(T::WORD_SIZE) { pt_want.encode_coeff_i64(want.bit(i) as i64, TorusPrecision(2), 0); - *noise_i = self.blocks[i].noise(module, sk, &pt_want, scratch_1); + *noise_i = self.bits[i].noise(module, sk, &pt_want, scratch_1); } noise diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/mod.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/mod.rs index 9dcc018..22f5043 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/mod.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/mod.rs @@ -1,11 +1,11 @@ -mod block; -mod block_prepared; -mod word; +mod fhe_uint_compressed; +mod fhe_uint_prepared; +mod fheuint; -mod block_debug; +mod fhe_uint_prepared_debug; -pub use block_debug::*; +pub use fhe_uint_prepared_debug::*; -pub use block::*; -pub use block_prepared::*; -pub use word::*; +pub use fhe_uint_compressed::*; +pub use fhe_uint_prepared::*; +pub use fheuint::*; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs index 360c49a..2244eca 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs @@ -7,7 +7,7 @@ use poulpy_core::{ }; use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, ZnxZero}; -use crate::tfhe::bdd_arithmetic::UnsignedInteger; +use crate::tfhe::bdd_arithmetic::{GetGGSWBit, UnsignedInteger}; pub trait BitCircuitInfo { fn info(&self) -> (&[Node], usize); @@ -27,35 +27,31 @@ pub(crate) struct BitCircuit { pub struct Circuit(pub [C; N]); pub trait ExecuteBDDCircuit { - fn execute_bdd_circuit( - &self, - out: &mut [GLWE], - inputs: &[&dyn GGSWPreparedToRef], - circuit: &C, - scratch: &mut Scratch, - ) where + fn execute_bdd_circuit(&self, out: &mut [GLWE], inputs: &G, circuit: &C, scratch: &mut Scratch) + where + G: GetGGSWBit + BitSize, C: GetBitCircuitInfo, O: DataMut; } +pub trait BitSize { + fn bit_size(&self) -> usize; +} + impl ExecuteBDDCircuit for Module where Self: Cmux + GLWECopy, Scratch: ScratchTakeCore, { - fn execute_bdd_circuit( - &self, - out: &mut [GLWE], - inputs: &[&dyn GGSWPreparedToRef], - circuit: &C, - scratch: &mut Scratch, - ) where + fn execute_bdd_circuit(&self, out: &mut [GLWE], inputs: &G, circuit: &C, scratch: &mut Scratch) + where + G: GetGGSWBit + BitSize, C: GetBitCircuitInfo, O: DataMut, { #[cfg(debug_assertions)] { - assert_eq!(inputs.len(), circuit.input_size()); + assert_eq!(inputs.bit_size(), circuit.input_size()); assert!(out.len() >= circuit.output_size()); } @@ -86,7 +82,7 @@ where next_level[j], prev_level[*hi_idx], prev_level[*lo_idx], - &inputs[*in_idx].to_ref(), + &inputs.get_bit(*in_idx), scratch_1, ); } @@ -106,7 +102,7 @@ where out_i, prev_level[*hi_idx], prev_level[*lo_idx], - &inputs[*in_idx].to_ref(), + &inputs.get_bit(*in_idx), scratch_1, ); } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs index 6a541cf..8ca9659 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs @@ -1,6 +1,6 @@ -use crate::tfhe::bdd_arithmetic::FheUintBlocksPreparedDebug; +use crate::tfhe::bdd_arithmetic::FheUintPreparedDebug; use crate::tfhe::{ - bdd_arithmetic::{FheUintBlocks, FheUintBlocksPrepared, UnsignedInteger}, + bdd_arithmetic::{FheUint, FheUintPrepared, UnsignedInteger}, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, circuit_bootstrapping::{ CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout, @@ -123,7 +123,7 @@ impl BDDKey { } } -pub struct BDDKeyPrepared +pub struct BddKeyPrepared where D: Data, BRA: BlindRotationAlgo, @@ -137,11 +137,11 @@ pub trait BDDKeyPreparedFactory where Self: Sized + CircuitBootstrappingKeyPreparedFactory + GLWEToLWEKeyPreparedFactory, { - fn alloc_bdd_key_from_infos(&self, infos: &A) -> BDDKeyPrepared, BRA, BE> + fn alloc_bdd_key_from_infos(&self, infos: &A) -> BddKeyPrepared, BRA, BE> where A: BDDKeyInfos, { - BDDKeyPrepared { + BddKeyPrepared { cbt: CircuitBootstrappingKeyPrepared::alloc_from_infos(self, &infos.cbt_infos()), ks: GLWEToLWEKeyPrepared::alloc_from_infos(self, &infos.ks_infos()), } @@ -155,7 +155,7 @@ where .max(self.prepare_glwe_to_lwe_key_tmp_bytes(&infos.ks_infos())) } - fn prepare_bdd_key(&self, res: &mut BDDKeyPrepared, other: &BDDKey, scratch: &mut Scratch) + fn prepare_bdd_key(&self, res: &mut BddKeyPrepared, other: &BDDKey, scratch: &mut Scratch) where DM: DataMut, DR: DataRef, @@ -170,7 +170,7 @@ impl BDDKeyPreparedFactory for Mod { } -impl BDDKeyPrepared, BRA, BE> { +impl BddKeyPrepared, BRA, BE> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self where M: BDDKeyPreparedFactory, @@ -180,7 +180,7 @@ impl BDDKeyPrepared, BRA, BE> { } } -impl BDDKeyPrepared { +impl BddKeyPrepared { pub fn prepare(&mut self, module: &M, other: &BDDKey, scratch: &mut Scratch) where DR: DataRef, @@ -192,21 +192,15 @@ impl BDDKeyPrepared } pub trait FheUintBlocksPrepare { - fn fhe_uint_blocks_prepare_tmp_bytes( - &self, - block_size: usize, - extension_factor: usize, - res_infos: &R, - infos: &A, - ) -> usize + fn fhe_uint_prepare_tmp_bytes(&self, block_size: usize, extension_factor: usize, res_infos: &R, infos: &A) -> usize where R: GGSWInfos, A: BDDKeyInfos; - fn fhe_uint_blocks_prepare( + fn fhe_uint_prepare( &self, - res: &mut FheUintBlocksPrepared, - bits: &FheUintBlocks, - key: &BDDKeyPrepared, + res: &mut FheUintPrepared, + bits: &FheUint, + key: &BddKeyPrepared, scratch: &mut Scratch, ) where DM: DataMut, @@ -219,13 +213,7 @@ where Self: LWEFromGLWE + CirtuitBootstrappingExecute + GGSWPreparedFactory, Scratch: ScratchTakeCore, { - fn fhe_uint_blocks_prepare_tmp_bytes( - &self, - block_size: usize, - extension_factor: usize, - res_infos: &R, - bdd_infos: &A, - ) -> usize + fn fhe_uint_prepare_tmp_bytes(&self, block_size: usize, extension_factor: usize, res_infos: &R, bdd_infos: &A) -> usize where R: GGSWInfos, A: BDDKeyInfos, @@ -238,22 +226,22 @@ where ) } - fn fhe_uint_blocks_prepare( + fn fhe_uint_prepare( &self, - res: &mut FheUintBlocksPrepared, - bits: &FheUintBlocks, - key: &BDDKeyPrepared, + res: &mut FheUintPrepared, + bits: &FheUint, + key: &BddKeyPrepared, scratch: &mut Scratch, ) where DM: DataMut, DR0: DataRef, DR1: DataRef, { - assert_eq!(res.blocks.len(), bits.blocks.len()); + assert_eq!(res.bits.len(), bits.bits.len()); - let mut lwe: LWE> = LWE::alloc_from_infos(&bits.blocks[0]); //TODO: add TakeLWE + let mut lwe: LWE> = LWE::alloc_from_infos(&bits.bits[0]); //TODO: add TakeLWE let (mut tmp_ggsw, scratch_1) = scratch.take_ggsw(res); - for (dst, src) in res.blocks.iter_mut().zip(bits.blocks.iter()) { + for (dst, src) in res.bits.iter_mut().zip(bits.bits.iter()) { lwe.from_glwe(self, src, &key.ks, scratch_1); key.cbt .execute_to_constant(self, &mut tmp_ggsw, &lwe, 1, 1, scratch_1); @@ -262,12 +250,12 @@ where } } -impl FheUintBlocksPrepared { +impl FheUintPrepared { pub fn prepare( &mut self, module: &M, - other: &FheUintBlocks, - key: &BDDKeyPrepared, + other: &FheUint, + key: &BddKeyPrepared, scratch: &mut Scratch, ) where BRA: BlindRotationAlgo, @@ -276,16 +264,16 @@ impl FheUintBlocksPrepared, Scratch: ScratchTakeCore, { - module.fhe_uint_blocks_prepare(self, other, key, scratch); + module.fhe_uint_prepare(self, other, key, scratch); } } pub trait FheUintBlockDebugPrepare { - fn fhe_uint_block_debug_prepare( + fn fhe_uint_debug_prepare( &self, - res: &mut FheUintBlocksPreparedDebug, - bits: &FheUintBlocks, - key: &BDDKeyPrepared, + res: &mut FheUintPreparedDebug, + bits: &FheUint, + key: &BddKeyPrepared, scratch: &mut Scratch, ) where DM: DataMut, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/add.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/add.rs index 2b568f6..1f50766 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/add.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/add.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - Add, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, + Add, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, + FheUintBlocksPrepare, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32(); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/and.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/and.rs index 41936e0..aa91e01 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/and.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/and.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - And, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, + And, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, + FheUintBlocksPrepare, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32(); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs index db68180..45f9197 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/ggsw_blind_rotations.rs @@ -12,7 +12,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::bdd_arithmetic::{FheUintBlocksPrepared, GGSWBlindRotation}; +use crate::tfhe::bdd_arithmetic::{FheUintPrepared, GGSWBlindRotation}; pub fn test_scalar_to_ggsw_blind_rotation() where @@ -80,8 +80,7 @@ where // println!("k: {k}"); - let mut k_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_k_infos); + let mut k_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_k_infos); k_enc_prep.encrypt_sk( &module, k, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs index fce0259..6448e4a 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/glwe_blind_rotation.rs @@ -12,7 +12,7 @@ use poulpy_hal::{ }; use rand::RngCore; -use crate::tfhe::bdd_arithmetic::{FheUintBlocksPrepared, GLWEBlindRotation}; +use crate::tfhe::bdd_arithmetic::{FheUintPrepared, GLWEBlindRotation}; pub fn test_glwe_to_glwe_blind_rotation() where @@ -72,8 +72,7 @@ where let k: u32 = source.next_u32(); - let mut k_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut k_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); k_enc_prep.encrypt_sk( &module, k, diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/or.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/or.rs index 779a82e..a13b8cb 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/or.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/or.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Or, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Or, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32(); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/prepare.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/prepare.rs index 3fcab1b..8cdf932 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/prepare.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/prepare.rs @@ -11,9 +11,9 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKey, BDDKeyEncryptSk, BDDKeyLayout, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, - FheUintBlockDebugPrepare, FheUintBlocks, FheUintBlocksPrepare, FheUintBlocksPreparedDebug, - FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, + BDDKey, BDDKeyEncryptSk, BDDKeyLayout, BDDKeyPreparedFactory, BddKeyPrepared, ExecuteBDDCircuit2WTo1W, FheUint, + FheUintBlockDebugPrepare, FheUintBlocksPrepare, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, + FheUintPreparedDebug, tests::test_suite::{TEST_BASE2K, TEST_BDD_KEY_LAYOUT, TEST_BLOCK_SIZE, TEST_GGSW_INFOS, TEST_GLWE_INFOS, TEST_N_LWE}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -79,12 +79,12 @@ where &mut source_xe, scratch.borrow(), ); - let mut bdd_key_prepared: BDDKeyPrepared, BRA, BE> = BDDKeyPrepared::alloc_from_infos(&module, &bdd_key_infos); + let mut bdd_key_prepared: BddKeyPrepared, BRA, BE> = BddKeyPrepared::alloc_from_infos(&module, &bdd_key_infos); source.fill_bytes(&mut scratch.borrow().data); bdd_key_prepared.prepare(&module, &bdd_key, scratch.borrow()); // GLWE(value) - let mut c_enc: FheUintBlocks, u32> = FheUintBlocks::alloc_from_infos(&module, &glwe_infos); + let mut c_enc: FheUint, u32> = FheUint::alloc_from_infos(&module, &glwe_infos); let value: u32 = source.next_u32(); c_enc.encrypt_sk( &module, @@ -96,8 +96,8 @@ where ); // GGSW(0) - let mut c_enc_prep_debug: FheUintBlocksPreparedDebug, u32> = - FheUintBlocksPreparedDebug::, u32>::alloc_from_infos(&module, &ggsw_infos); + let mut c_enc_prep_debug: FheUintPreparedDebug, u32> = + FheUintPreparedDebug::, u32>::alloc_from_infos(&module, &ggsw_infos); // GGSW(value) c_enc_prep_debug.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow()); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sll.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sll.rs index 3378d05..f0bc716 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sll.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sll.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sll, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sll, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32() & 15; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/slt.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/slt.rs index 9ae2203..3512bd6 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/slt.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/slt.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Slt, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Slt, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32(); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sltu.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sltu.rs index 4ffc2b3..9f24d7d 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sltu.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sltu.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sltu, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sltu, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32(); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sra.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sra.rs index 554a57e..ee435eb 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sra.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sra.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sra, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sra, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32() & 15; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/srl.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/srl.rs index b79ec56..9d50aad 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/srl.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/srl.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Srl, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Srl, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32() & 15; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sub.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sub.rs index 159e414..56dc5e9 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sub.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/sub.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sub, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sub, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32(); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/xor.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/xor.rs index 1f1f8ef..5c99736 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/xor.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/tests/test_suite/xor.rs @@ -11,8 +11,8 @@ use rand::RngCore; use crate::tfhe::{ bdd_arithmetic::{ - BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks, - FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Xor, + BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare, + FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Xor, tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS}, }, blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory}, @@ -55,11 +55,9 @@ where let mut sk_glwe_prep: GLWESecretPrepared, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks, u32> = FheUintBlocks::, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared, u32, BE> = - FheUintBlocksPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint, u32> = FheUint::, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared, u32, BE> = FheUintPrepared::, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();