Update FheUint ciphertext naming + circuit evaluation based on GetGGSWBit
jump to
@@ -175,12 +175,12 @@ {
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(),
@@ -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<T: UnsignedInteger, BE: Backend> ExecuteBDDCircuit2WTo1W<T, BE> for Module<BE> where Self: Sized + ExecuteBDDCircuit<T, BE> {}@@ -15,10 +16,10 @@ {
/// Operations Z x Z -> Z fn execute_bdd_circuit_2w_to_1w<R, C, A, B>( &self, - out: &mut FheUintBlocks<R, T>, + out: &mut FheUint<R, T>, circuit: &C, - a: &FheUintBlocksPrepared<A, T, BE>, - b: &FheUintBlocksPrepared<B, T, BE>, + a: &FheUintPrepared<A, T, BE>, + b: &FheUintPrepared<B, T, BE>, scratch: &mut Scratch<BE>, ) where C: GetBitCircuitInfo<T>,@@ -26,20 +27,59 @@ R: DataMut,
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<BE>> = a - .blocks - .iter() - .map(|x| x as &dyn GGSWPreparedToRef<BE>) - .chain(b.blocks.iter().map(|x| x as &dyn GGSWPreparedToRef<BE>)) - .collect_vec(); + let inputs: Vec<&dyn GetGGSWBit<BE>> = [a as &dyn GetGGSWBit<BE>, b as &dyn GetGGSWBit<BE>].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<BE>>, + _phantom: PhantomData<T>, +} + +impl<'a, T: UnsignedInteger, BE: Backend> GetGGSWBit<BE> 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<A, B> { + pub lo: A, + pub hi: B, + pub split: usize, // 32 in your example +} + +impl<A, B, BE> GetGGSWBit<BE> for JoinedBits<A, B> +where + BE: Backend, + A: GetGGSWBit<BE>, + B: GetGGSWBit<BE>, +{ + 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 @@ $vis trait $trait_name<T: UnsignedInteger, BE: Backend> {
fn $method_name<A, M, B>( &mut self, module: &M, - a: &FheUintBlocksPrepared<A, T, BE>, - b: &FheUintBlocksPrepared<B, T, BE>, + a: &FheUintPrepared<A, T, BE>, + b: &FheUintPrepared<B, T, BE>, scratch: &mut Scratch<BE>, ) where M: ExecuteBDDCircuit2WTo1W<T, BE>,@@ -65,12 +105,12 @@
#[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<D: DataMut, BE: Backend> $trait_name<$ty, BE> for FheUintBlocks<D, $ty> { + impl<D: DataMut, BE: Backend> $trait_name<$ty, BE> for FheUint<D, $ty> { fn $method_name<A, M, B>( &mut self, module: &M, - a: &FheUintBlocksPrepared<A, $ty, BE>, - b: &FheUintBlocksPrepared<B, $ty, BE>, + a: &FheUintPrepared<A, $ty, BE>, + b: &FheUintPrepared<B, $ty, BE>, scratch: &mut Scratch<BE>, ) where M: ExecuteBDDCircuit2WTo1W<$ty, BE>,
@@ -43,7 +43,7 @@ scratch: &mut Scratch<BE>,
) where R: GGSWToMut, A: GGSWToRef, - K: GetGGSWBit<T, BE>, + K: GetGGSWBit<BE>, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();@@ -90,7 +90,7 @@ scratch: &mut Scratch<BE>,
) where R: GGSWToMut, S: ScalarZnxToRef, - K: GetGGSWBit<T, BE>, + K: GetGGSWBit<BE>, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();@@ -162,7 +162,7 @@ scratch: &mut Scratch<BE>,
) where R: GLWEToMut, A: GLWEToRef, - K: GetGGSWBit<T, BE>, + K: GetGGSWBit<BE>, Scratch<BE>: ScratchTakeCore<BE>, { assert!(bit_rsh + bit_mask <= T::WORD_SIZE);
@@ -13,50 +13,42 @@
use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger}; /// An FHE ciphertext encrypting the bits of an [UnsignedInteger]. -pub struct FheUintBlocks<D: Data, T: UnsignedInteger> { - pub(crate) blocks: Vec<GLWE<D>>, - pub(crate) _base: u8, +pub struct FheUint<D: Data, T: UnsignedInteger> { + pub(crate) bits: Vec<GLWE<D>>, pub(crate) _phantom: PhantomData<T>, } -impl<D: DataRef, T: UnsignedInteger> FheUintBlocks<D, T> { - pub fn blocks(&self) -> &Vec<GLWE<D>> { - &self.blocks - } -} - -impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintBlocks<D, T> { +impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUint<D, T> { 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<D: DataRef, T: UnsignedInteger> GLWEInfos for FheUintBlocks<D, T> { +impl<D: DataRef, T: UnsignedInteger> GLWEInfos for FheUint<D, T> { fn rank(&self) -> poulpy_core::layouts::Rank { - self.blocks[0].rank() + self.bits[0].rank() } } -impl<D: Data, T: UnsignedInteger> FheUintBlocks<D, T> { - pub fn new(blocks: Vec<GLWE<D>>) -> Self { - assert_eq!(blocks.len(), T::WORD_SIZE); +impl<D: Data, T: UnsignedInteger> FheUint<D, T> { + pub fn new(bits: Vec<GLWE<D>>) -> Self { + assert_eq!(bits.len(), T::WORD_SIZE); Self { - blocks, - _base: 1, + bits, _phantom: PhantomData, } } } -impl<T: UnsignedInteger> FheUintBlocks<Vec<u8>, T> { +impl<T: UnsignedInteger> FheUint<Vec<u8>, T> { pub fn alloc_from_infos<A, BE: Backend>(module: &Module<BE>, infos: &A) -> Self where A: GLWEInfos,@@ -66,16 +58,15 @@ }
pub fn alloc<BE: Backend>(module: &Module<BE>, 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<D: DataMut, T: UnsignedInteger + ToBits> FheUintBlocks<D, T> { +impl<D: DataMut, T: UnsignedInteger + ToBits> FheUint<D, T> { pub fn encrypt_sk<S, BE: Backend>( &mut self, module: &Module<BE>,@@ -110,12 +101,12 @@ pt.data.zero();
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<D: DataRef, T: UnsignedInteger + FromBits + ToBits> FheUintBlocks<D, T> { +impl<D: DataRef, T: UnsignedInteger + FromBits + ToBits> FheUint<D, T> { pub fn decrypt<S, BE: Backend>(&self, module: &Module<BE>, sk: &S, scratch: &mut Scratch<BE>) -> T where Module<BE>: GLWEDecrypt<BE>,@@ -143,7 +134,7 @@ let base2k: usize = self.base2k().into();
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 @@ let mut noise: Vec<f64> = vec![0f64; T::WORD_SIZE];
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
@@ -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_hal::api::ModuleN; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; -pub struct FheUintBlocksPreparedDebug<D: Data, T: UnsignedInteger> { - pub(crate) blocks: Vec<GGSW<D>>, - pub(crate) _base: u8, +pub struct FheUintPreparedDebug<D: Data, T: UnsignedInteger> { + pub(crate) bits: Vec<GGSW<D>>, pub(crate) _phantom: PhantomData<T>, } -impl<T: UnsignedInteger> FheUintBlocksPreparedDebug<Vec<u8>, T> { +impl<T: UnsignedInteger> FheUintPreparedDebug<Vec<u8>, T> { pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self where M: ModuleN,@@ -45,52 +44,51 @@ where
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<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintBlocksPreparedDebug<D, T> { +impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintPreparedDebug<D, T> { 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<D: DataRef, T: UnsignedInteger> GLWEInfos for FheUintBlocksPreparedDebug<D, T> { +impl<D: DataRef, T: UnsignedInteger> GLWEInfos for FheUintPreparedDebug<D, T> { fn rank(&self) -> poulpy_core::layouts::Rank { - self.blocks[0].rank() + self.bits[0].rank() } } -impl<D: DataRef, T: UnsignedInteger> GGSWInfos for FheUintBlocksPreparedDebug<D, T> { +impl<D: DataRef, T: UnsignedInteger> GGSWInfos for FheUintPreparedDebug<D, T> { 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<D: DataRef, T: UnsignedInteger + ToBits> FheUintBlocksPreparedDebug<D, T> { +impl<D: DataRef, T: UnsignedInteger + ToBits> FheUintPreparedDebug<D, T> { pub fn print_noise<S, M, BE: Backend>(&self, module: &M, sk: &S, want: T) where S: GLWESecretPreparedToRef<BE>, M: GGSWNoise<BE>, { - 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 @@ S: GLWESecretPreparedToRef<BE>,
M: GGSWNoise<BE>, 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<BE> + CirtuitBootstrappingExecute<BRA, BE> + GGSWPreparedFactory<BE>, Scratch<BE>: ScratchTakeCore<BE>, { - fn fhe_uint_block_debug_prepare<DM, DR0, DR1>( + fn fhe_uint_debug_prepare<DM, DR0, DR1>( &self, - res: &mut FheUintBlocksPreparedDebug<DM, T>, - bits: &FheUintBlocks<DR0, T>, - key: &BDDKeyPrepared<DR1, BRA, BE>, + res: &mut FheUintPreparedDebug<DM, T>, + bits: &FheUint<DR0, T>, + key: &BddKeyPrepared<DR1, BRA, BE>, scratch: &mut Scratch<BE>, ) 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<Vec<u8>> = 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<Vec<u8>> = 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<D: DataMut, T: UnsignedInteger> FheUintBlocksPreparedDebug<D, T> { +impl<D: DataMut, T: UnsignedInteger> FheUintPreparedDebug<D, T> { pub fn prepare<BRA, M, O, K, BE: Backend>( &mut self, module: &M, - other: &FheUintBlocks<O, T>, - key: &BDDKeyPrepared<K, BRA, BE>, + other: &FheUint<O, T>, + key: &BddKeyPrepared<K, BRA, BE>, scratch: &mut Scratch<BE>, ) where BRA: BlindRotationAlgo,@@ -153,6 +151,6 @@ K: DataRef,
M: FheUintBlockDebugPrepare<BRA, T, BE>, Scratch<BE>: ScratchTakeCore<BE>, { - module.fhe_uint_block_debug_prepare(self, other, key, scratch); + module.fhe_uint_debug_prepare(self, other, key, scratch); } }
@@ -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<D: Data, T: UnsignedInteger, B: Backend> { - pub(crate) blocks: Vec<GGSWPrepared<D, B>>, - pub(crate) _base: u8, +pub struct FheUintPrepared<D: Data, T: UnsignedInteger, B: Backend> { + pub(crate) bits: Vec<GGSWPrepared<D, B>>, pub(crate) _phantom: PhantomData<T>, } -impl<D: Data, T: UnsignedInteger, B: Backend> FheUintBlocksPrepared<D, T, B> { - pub fn blocks(&self) -> &Vec<GGSWPrepared<D, B>> { - &self.blocks - } -} - impl<T: UnsignedInteger, BE: Backend> FheUintBlocksPreparedFactory<T, BE> for Module<BE> where Self: Sized + GGSWPreparedFactory<BE> { } -pub trait GetGGSWBit<T: UnsignedInteger, BE: Backend> { +pub trait GetGGSWBit<BE: Backend> { fn get_bit(&self, bit: usize) -> GGSWPrepared<&[u8], BE>; } -impl<D: DataRef, T: UnsignedInteger, BE: Backend> GetGGSWBit<T, BE> for FheUintBlocksPrepared<D, T, BE> { +impl<D: DataRef, T: UnsignedInteger, BE: Backend> GetGGSWBit<BE> for FheUintPrepared<D, T, BE> { 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<T: UnsignedInteger, BE: Backend> {
fn get_bit(&mut self, bit: usize) -> GGSWPrepared<&mut [u8], BE>; } -impl<D: DataMut, T: UnsignedInteger, BE: Backend> GetGGSWBitMut<T, BE> for FheUintBlocksPrepared<D, T, BE> { +impl<D: DataMut, T: UnsignedInteger, BE: Backend> GetGGSWBitMut<T, BE> for FheUintPrepared<D, T, BE> { 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<T: UnsignedInteger, BE: Backend>
where Self: Sized + GGSWPreparedFactory<BE>, { - fn alloc_fhe_uint_blocks_prepared( + fn alloc_fhe_uint_prepared( &self, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank, - ) -> FheUintBlocksPrepared<Vec<u8>, T, BE> { - FheUintBlocksPrepared { - blocks: (0..T::WORD_SIZE) + ) -> FheUintPrepared<Vec<u8>, 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<A>(&self, infos: &A) -> FheUintBlocksPrepared<Vec<u8>, T, BE> + fn alloc_fhe_uint_prepared_from_infos<A>(&self, infos: &A) -> FheUintPrepared<Vec<u8>, 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 @@ )
} } -impl<T: UnsignedInteger, BE: Backend> FheUintBlocksPrepared<Vec<u8>, T, BE> { +impl<T: UnsignedInteger, BE: Backend> FheUintPrepared<Vec<u8>, T, BE> { pub fn alloc<A, M>(module: &M, infos: &A) -> Self where A: GGSWInfos, M: FheUintBlocksPreparedFactory<T, BE>, { - module.alloc_fhe_uint_blocks_prepared_from_infos(infos) + module.alloc_fhe_uint_prepared_from_infos(infos) } pub fn alloc_with<M>(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self where M: FheUintBlocksPreparedFactory<T, BE>, { - 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<T: UnsignedInteger + ToBits, BE: Backend>
where Self: Sized + ModuleN + GGSWEncryptSk<BE> + GGSWPreparedFactory<BE>, { - fn fhe_uint_blocks_prepared_encrypt_sk<DM, S>( + fn fhe_uint_prepared_encrypt_sk<DM, S>( &self, - res: &mut FheUintBlocksPrepared<DM, T, BE>, + res: &mut FheUintPrepared<DM, T, BE>, value: T, sk: &S, source_xa: &mut Source,@@ -145,12 +137,12 @@ for i in 0..T::WORD_SIZE {
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<D: DataMut, T: UnsignedInteger + ToBits, BE: Backend> FheUintBlocksPrepared<D, T, BE> { +impl<D: DataMut, T: UnsignedInteger + ToBits, BE: Backend> FheUintPrepared<D, T, BE> { pub fn encrypt_sk<M, S>( &mut self, module: &M,@@ -164,36 +156,36 @@ S: GLWESecretPreparedToRef<BE> + GLWEInfos,
M: FheUintBlocksPreparedEncryptSk<T, BE>, Scratch<BE>: ScratchTakeCore<BE>, { - 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<D: DataRef, T: UnsignedInteger, B: Backend> LWEInfos for FheUintBlocksPrepared<D, T, B> { +impl<D: DataRef, T: UnsignedInteger, B: Backend> LWEInfos for FheUintPrepared<D, T, B> { 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<D: DataRef, T: UnsignedInteger, B: Backend> GLWEInfos for FheUintBlocksPrepared<D, T, B> { +impl<D: DataRef, T: UnsignedInteger, B: Backend> GLWEInfos for FheUintPrepared<D, T, B> { fn rank(&self) -> poulpy_core::layouts::Rank { - self.blocks[0].rank() + self.bits[0].rank() } } -impl<D: DataRef, T: UnsignedInteger, B: Backend> GGSWInfos for FheUintBlocksPrepared<D, T, B> { +impl<D: DataRef, T: UnsignedInteger, B: Backend> GGSWInfos for FheUintPrepared<D, T, B> { 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() } }
@@ -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::*;
@@ -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<D: Data, T: UnsignedInteger>(pub(crate) GLWE<D>, pub(crate) PhantomData<T>); +/// An FHE ciphertext encrypting the bits of an [UnsignedInteger] in compressed format (ideal for decryption/serialization). +pub struct FheUintCompressed<D: Data, T: UnsignedInteger>(pub(crate) GLWE<D>, pub(crate) PhantomData<T>); -impl<D: DataMut, T: UnsignedInteger> FheUintWord<D, T> { +impl<D: DataMut, T: UnsignedInteger> FheUintCompressed<D, T> { #[allow(dead_code)] fn post_process<ATK, M, BE: Backend>( &mut self,@@ -46,7 +46,7 @@ module.glwe_copy(&mut self.0, cts.remove(&0).unwrap());
} } -impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintWord<D, T> { +impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintCompressed<D, T> { fn base2k(&self) -> poulpy_core::layouts::Base2K { self.0.base2k() }@@ -60,13 +60,13 @@ self.0.n()
} } -impl<D: DataRef, T: UnsignedInteger> GLWEInfos for FheUintWord<D, T> { +impl<D: DataRef, T: UnsignedInteger> GLWEInfos for FheUintCompressed<D, T> { fn rank(&self) -> poulpy_core::layouts::Rank { self.0.rank() } } -impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintWord<D, T> { +impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintCompressed<D, T> { pub fn encrypt_sk<S, M, BE: Backend>( &mut self, module: &M,@@ -109,7 +109,7 @@ .encrypt_sk(module, &pt, sk, source_xa, source_xe, scratch_1);
} } -impl<D: DataRef, T: UnsignedInteger + FromBits> FheUintWord<D, T> { +impl<D: DataRef, T: UnsignedInteger + FromBits> FheUintCompressed<D, T> { pub fn decrypt<S, M, BE: Backend>(&self, module: &M, sk: &S, scratch: &mut Scratch<BE>) -> T where S: GLWESecretPreparedToRef<BE> + GLWEInfos,
@@ -7,7 +7,7 @@ layouts::{GGSWInfos, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, prepared::GGSWPreparedToRef},
}; 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,15 +27,15 @@
pub struct Circuit<C: BitCircuitInfo, const N: usize>(pub [C; N]); pub trait ExecuteBDDCircuit<T: UnsignedInteger, BE: Backend> { - fn execute_bdd_circuit<C, O>( - &self, - out: &mut [GLWE<O>], - inputs: &[&dyn GGSWPreparedToRef<BE>], - circuit: &C, - scratch: &mut Scratch<BE>, - ) where + fn execute_bdd_circuit<C, G, O>(&self, out: &mut [GLWE<O>], inputs: &G, circuit: &C, scratch: &mut Scratch<BE>) + where + G: GetGGSWBit<BE> + BitSize, C: GetBitCircuitInfo<T>, O: DataMut; +} + +pub trait BitSize { + fn bit_size(&self) -> usize; } impl<T: UnsignedInteger, BE: Backend> ExecuteBDDCircuit<T, BE> for Module<BE>@@ -43,19 +43,15 @@ where
Self: Cmux<BE> + GLWECopy, Scratch<BE>: ScratchTakeCore<BE>, { - fn execute_bdd_circuit<C, O>( - &self, - out: &mut [GLWE<O>], - inputs: &[&dyn GGSWPreparedToRef<BE>], - circuit: &C, - scratch: &mut Scratch<BE>, - ) where + fn execute_bdd_circuit<C, G, O>(&self, out: &mut [GLWE<O>], inputs: &G, circuit: &C, scratch: &mut Scratch<BE>) + where + G: GetGGSWBit<BE> + BitSize, C: GetBitCircuitInfo<T>, 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 @@ self.cmux(
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 @@ self.cmux(
out_i, prev_level[*hi_idx], prev_level[*lo_idx], - &inputs[*in_idx].to_ref(), + &inputs.get_bit(*in_idx), scratch_1, ); }
@@ -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 @@ module.bdd_key_encrypt_sk(self, sk_lwe, sk_glwe, source_xa, source_xe, scratch);
} } -pub struct BDDKeyPrepared<D, BRA, BE> +pub struct BddKeyPrepared<D, BRA, BE> where D: Data, BRA: BlindRotationAlgo,@@ -137,11 +137,11 @@ pub trait BDDKeyPreparedFactory<BRA: BlindRotationAlgo, BE: Backend>
where Self: Sized + CircuitBootstrappingKeyPreparedFactory<BRA, BE> + GLWEToLWEKeyPreparedFactory<BE>, { - fn alloc_bdd_key_from_infos<A>(&self, infos: &A) -> BDDKeyPrepared<Vec<u8>, BRA, BE> + fn alloc_bdd_key_from_infos<A>(&self, infos: &A) -> BddKeyPrepared<Vec<u8>, 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 @@ self.circuit_bootstrapping_key_prepare_tmp_bytes(&infos.cbt_infos())
.max(self.prepare_glwe_to_lwe_key_tmp_bytes(&infos.ks_infos())) } - fn prepare_bdd_key<DM, DR>(&self, res: &mut BDDKeyPrepared<DM, BRA, BE>, other: &BDDKey<DR, BRA>, scratch: &mut Scratch<BE>) + fn prepare_bdd_key<DM, DR>(&self, res: &mut BddKeyPrepared<DM, BRA, BE>, other: &BDDKey<DR, BRA>, scratch: &mut Scratch<BE>) where DM: DataMut, DR: DataRef,@@ -170,7 +170,7 @@ Self: Sized + CircuitBootstrappingKeyPreparedFactory<BRA, BE> + GLWEToLWEKeyPreparedFactory<BE>
{ } -impl<BRA: BlindRotationAlgo, BE: Backend> BDDKeyPrepared<Vec<u8>, BRA, BE> { +impl<BRA: BlindRotationAlgo, BE: Backend> BddKeyPrepared<Vec<u8>, BRA, BE> { pub fn alloc_from_infos<M, A>(module: &M, infos: &A) -> Self where M: BDDKeyPreparedFactory<BRA, BE>,@@ -180,7 +180,7 @@ module.alloc_bdd_key_from_infos(infos)
} } -impl<D: DataMut, BRA: BlindRotationAlgo, BE: Backend> BDDKeyPrepared<D, BRA, BE> { +impl<D: DataMut, BRA: BlindRotationAlgo, BE: Backend> BddKeyPrepared<D, BRA, BE> { pub fn prepare<DR, M>(&mut self, module: &M, other: &BDDKey<DR, BRA>, scratch: &mut Scratch<BE>) where DR: DataRef,@@ -192,21 +192,15 @@ }
} pub trait FheUintBlocksPrepare<BRA: BlindRotationAlgo, T: UnsignedInteger, BE: Backend> { - fn fhe_uint_blocks_prepare_tmp_bytes<R, A>( - &self, - block_size: usize, - extension_factor: usize, - res_infos: &R, - infos: &A, - ) -> usize + fn fhe_uint_prepare_tmp_bytes<R, A>(&self, block_size: usize, extension_factor: usize, res_infos: &R, infos: &A) -> usize where R: GGSWInfos, A: BDDKeyInfos; - fn fhe_uint_blocks_prepare<DM, DR0, DR1>( + fn fhe_uint_prepare<DM, DR0, DR1>( &self, - res: &mut FheUintBlocksPrepared<DM, T, BE>, - bits: &FheUintBlocks<DR0, T>, - key: &BDDKeyPrepared<DR1, BRA, BE>, + res: &mut FheUintPrepared<DM, T, BE>, + bits: &FheUint<DR0, T>, + key: &BddKeyPrepared<DR1, BRA, BE>, scratch: &mut Scratch<BE>, ) where DM: DataMut,@@ -219,13 +213,7 @@ where
Self: LWEFromGLWE<BE> + CirtuitBootstrappingExecute<BRA, BE> + GGSWPreparedFactory<BE>, Scratch<BE>: ScratchTakeCore<BE>, { - fn fhe_uint_blocks_prepare_tmp_bytes<R, A>( - &self, - block_size: usize, - extension_factor: usize, - res_infos: &R, - bdd_infos: &A, - ) -> usize + fn fhe_uint_prepare_tmp_bytes<R, A>(&self, block_size: usize, extension_factor: usize, res_infos: &R, bdd_infos: &A) -> usize where R: GGSWInfos, A: BDDKeyInfos,@@ -238,22 +226,22 @@ &bdd_infos.cbt_infos(),
) } - fn fhe_uint_blocks_prepare<DM, DR0, DR1>( + fn fhe_uint_prepare<DM, DR0, DR1>( &self, - res: &mut FheUintBlocksPrepared<DM, T, BE>, - bits: &FheUintBlocks<DR0, T>, - key: &BDDKeyPrepared<DR1, BRA, BE>, + res: &mut FheUintPrepared<DM, T, BE>, + bits: &FheUint<DR0, T>, + key: &BddKeyPrepared<DR1, BRA, BE>, scratch: &mut Scratch<BE>, ) 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<Vec<u8>> = LWE::alloc_from_infos(&bits.blocks[0]); //TODO: add TakeLWE + let mut lwe: LWE<Vec<u8>> = 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 @@ }
} } -impl<D: DataMut, T: UnsignedInteger, BE: Backend> FheUintBlocksPrepared<D, T, BE> { +impl<D: DataMut, T: UnsignedInteger, BE: Backend> FheUintPrepared<D, T, BE> { pub fn prepare<BRA, M, O, K>( &mut self, module: &M, - other: &FheUintBlocks<O, T>, - key: &BDDKeyPrepared<K, BRA, BE>, + other: &FheUint<O, T>, + key: &BddKeyPrepared<K, BRA, BE>, scratch: &mut Scratch<BE>, ) where BRA: BlindRotationAlgo,@@ -276,16 +264,16 @@ K: DataRef,
M: FheUintBlocksPrepare<BRA, T, BE>, Scratch<BE>: ScratchTakeCore<BE>, { - module.fhe_uint_blocks_prepare(self, other, key, scratch); + module.fhe_uint_prepare(self, other, key, scratch); } } pub trait FheUintBlockDebugPrepare<BRA: BlindRotationAlgo, T: UnsignedInteger, BE: Backend> { - fn fhe_uint_block_debug_prepare<DM, DR0, DR1>( + fn fhe_uint_debug_prepare<DM, DR0, DR1>( &self, - res: &mut FheUintBlocksPreparedDebug<DM, T>, - bits: &FheUintBlocks<DR0, T>, - key: &BDDKeyPrepared<DR1, BRA, BE>, + res: &mut FheUintPreparedDebug<DM, T>, + bits: &FheUint<DR0, T>, + key: &BddKeyPrepared<DR1, BRA, BE>, scratch: &mut Scratch<BE>, ) where DM: DataMut,
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();
@@ -12,7 +12,7 @@ source::Source,
}; 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<BE: Backend>() where@@ -80,8 +80,7 @@ let k: u32 = source.next_u32();
// println!("k: {k}"); - let mut k_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_k_infos); + let mut k_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_k_infos); k_enc_prep.encrypt_sk( &module, k,
@@ -12,7 +12,7 @@ source::Source,
}; 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<BE: Backend>() where@@ -72,8 +72,7 @@ test_glwe.encode_vec_i64(&data, base2k.as_usize().into());
let k: u32 = source.next_u32(); - let mut k_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut k_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); k_enc_prep.encrypt_sk( &module, k,
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();
@@ -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 @@ &mut source_xa,
&mut source_xe, scratch.borrow(), ); - let mut bdd_key_prepared: BDDKeyPrepared<Vec<u8>, BRA, BE> = BDDKeyPrepared::alloc_from_infos(&module, &bdd_key_infos); + let mut bdd_key_prepared: BddKeyPrepared<Vec<u8>, 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<Vec<u8>, u32> = FheUintBlocks::alloc_from_infos(&module, &glwe_infos); + let mut c_enc: FheUint<Vec<u8>, u32> = FheUint::alloc_from_infos(&module, &glwe_infos); let value: u32 = source.next_u32(); c_enc.encrypt_sk( &module,@@ -96,8 +96,8 @@ scratch.borrow(),
); // GGSW(0) - let mut c_enc_prep_debug: FheUintBlocksPreparedDebug<Vec<u8>, u32> = - FheUintBlocksPreparedDebug::<Vec<u8>, u32>::alloc_from_infos(&module, &ggsw_infos); + let mut c_enc_prep_debug: FheUintPreparedDebug<Vec<u8>, u32> = + FheUintPreparedDebug::<Vec<u8>, u32>::alloc_from_infos(&module, &ggsw_infos); // GGSW(value) c_enc_prep_debug.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow());
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32() & 15;
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32() & 15;
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32() & 15;
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();
@@ -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 @@ sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos); sk_glwe_prep.prepare(&module, &sk_glwe); - let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); - let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); - let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> = - FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos); + let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); + let mut b_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos); let a: u32 = source.next_u32(); let b: u32 = source.next_u32();