mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Update FheUint ciphertext naming + circuit evaluation based on GetGGSWBit
This commit is contained in:
@@ -175,12 +175,12 @@ impl GLWEToLWEKey<Vec<u8>> {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
infos.rank_out().0,
|
infos.rank_out().0,
|
||||||
1,
|
1,
|
||||||
"rank_out > 1 is not supported for GLWEToLWESwitchingKey"
|
"rank_out > 1 is not supported for GLWEToLWEKey"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
infos.dsize().0,
|
infos.dsize().0,
|
||||||
1,
|
1,
|
||||||
"dsize > 1 is not supported for GLWEToLWESwitchingKey"
|
"dsize > 1 is not supported for GLWEToLWEKey"
|
||||||
);
|
);
|
||||||
Self::bytes_of(
|
Self::bytes_of(
|
||||||
infos.n(),
|
infos.n(),
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use itertools::Itertools;
|
use std::marker::PhantomData;
|
||||||
use poulpy_core::layouts::prepared::GGSWPreparedToRef;
|
|
||||||
|
use poulpy_core::layouts::GGSWPrepared;
|
||||||
use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch};
|
use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch};
|
||||||
|
|
||||||
use crate::tfhe::bdd_arithmetic::{
|
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> {}
|
impl<T: UnsignedInteger, BE: Backend> ExecuteBDDCircuit2WTo1W<T, BE> for Module<BE> where Self: Sized + ExecuteBDDCircuit<T, BE> {}
|
||||||
@@ -15,10 +16,10 @@ where
|
|||||||
/// Operations Z x Z -> Z
|
/// Operations Z x Z -> Z
|
||||||
fn execute_bdd_circuit_2w_to_1w<R, C, A, B>(
|
fn execute_bdd_circuit_2w_to_1w<R, C, A, B>(
|
||||||
&self,
|
&self,
|
||||||
out: &mut FheUintBlocks<R, T>,
|
out: &mut FheUint<R, T>,
|
||||||
circuit: &C,
|
circuit: &C,
|
||||||
a: &FheUintBlocksPrepared<A, T, BE>,
|
a: &FheUintPrepared<A, T, BE>,
|
||||||
b: &FheUintBlocksPrepared<B, T, BE>,
|
b: &FheUintPrepared<B, T, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
C: GetBitCircuitInfo<T>,
|
C: GetBitCircuitInfo<T>,
|
||||||
@@ -26,20 +27,59 @@ where
|
|||||||
A: DataRef,
|
A: DataRef,
|
||||||
B: DataRef,
|
B: DataRef,
|
||||||
{
|
{
|
||||||
assert_eq!(out.blocks.len(), T::WORD_SIZE);
|
assert_eq!(out.bits.len(), T::WORD_SIZE);
|
||||||
assert_eq!(b.blocks.len(), T::WORD_SIZE);
|
assert_eq!(b.bits.len(), T::WORD_SIZE);
|
||||||
assert_eq!(b.blocks.len(), T::WORD_SIZE);
|
assert_eq!(b.bits.len(), T::WORD_SIZE);
|
||||||
|
|
||||||
// Collects inputs into a single array
|
// Collects inputs into a single array
|
||||||
let inputs: Vec<&dyn GGSWPreparedToRef<BE>> = a
|
let inputs: Vec<&dyn GetGGSWBit<BE>> = [a as &dyn GetGGSWBit<BE>, b as &dyn GetGGSWBit<BE>].to_vec();
|
||||||
.blocks
|
let helper: FheUintHelper<'_, T, BE> = FheUintHelper {
|
||||||
.iter()
|
data: inputs,
|
||||||
.map(|x| x as &dyn GGSWPreparedToRef<BE>)
|
_phantom: PhantomData,
|
||||||
.chain(b.blocks.iter().map(|x| x as &dyn GGSWPreparedToRef<BE>))
|
};
|
||||||
.collect_vec();
|
|
||||||
|
|
||||||
// Evaluates out[i] = circuit[i](a, b)
|
// 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 @@ macro_rules! define_bdd_2w_to_1w_trait {
|
|||||||
fn $method_name<A, M, B>(
|
fn $method_name<A, M, B>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
a: &FheUintBlocksPrepared<A, T, BE>,
|
a: &FheUintPrepared<A, T, BE>,
|
||||||
b: &FheUintBlocksPrepared<B, T, BE>,
|
b: &FheUintPrepared<B, T, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
M: ExecuteBDDCircuit2WTo1W<T, BE>,
|
M: ExecuteBDDCircuit2WTo1W<T, BE>,
|
||||||
@@ -65,12 +105,12 @@ macro_rules! define_bdd_2w_to_1w_trait {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! impl_bdd_2w_to_1w_trait {
|
macro_rules! impl_bdd_2w_to_1w_trait {
|
||||||
($trait_name:ident, $method_name:ident, $ty:ty, $n:literal, $circuit_ty:ty, $output_circuits:path) => {
|
($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>(
|
fn $method_name<A, M, B>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
a: &FheUintBlocksPrepared<A, $ty, BE>,
|
a: &FheUintPrepared<A, $ty, BE>,
|
||||||
b: &FheUintBlocksPrepared<B, $ty, BE>,
|
b: &FheUintPrepared<B, $ty, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
M: ExecuteBDDCircuit2WTo1W<$ty, BE>,
|
M: ExecuteBDDCircuit2WTo1W<$ty, BE>,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ where
|
|||||||
) where
|
) where
|
||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
A: GGSWToRef,
|
A: GGSWToRef,
|
||||||
K: GetGGSWBit<T, BE>,
|
K: GetGGSWBit<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||||
@@ -90,7 +90,7 @@ where
|
|||||||
) where
|
) where
|
||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
S: ScalarZnxToRef,
|
S: ScalarZnxToRef,
|
||||||
K: GetGGSWBit<T, BE>,
|
K: GetGGSWBit<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||||
@@ -162,7 +162,7 @@ where
|
|||||||
) where
|
) where
|
||||||
R: GLWEToMut,
|
R: GLWEToMut,
|
||||||
A: GLWEToRef,
|
A: GLWEToRef,
|
||||||
K: GetGGSWBit<T, BE>,
|
K: GetGGSWBit<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
assert!(bit_rsh + bit_mask <= T::WORD_SIZE);
|
assert!(bit_rsh + bit_mask <= T::WORD_SIZE);
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ use std::{collections::HashMap, marker::PhantomData};
|
|||||||
|
|
||||||
use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger};
|
use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger};
|
||||||
|
|
||||||
/// A FHE ciphertext encrypting a [UnsignedInteger].
|
/// An FHE ciphertext encrypting the bits of an [UnsignedInteger] in compressed format (ideal for decryption/serialization).
|
||||||
pub struct FheUintWord<D: Data, T: UnsignedInteger>(pub(crate) GLWE<D>, pub(crate) PhantomData<T>);
|
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)]
|
#[allow(dead_code)]
|
||||||
fn post_process<ATK, M, BE: Backend>(
|
fn post_process<ATK, M, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -46,7 +46,7 @@ impl<D: DataMut, T: UnsignedInteger> FheUintWord<D, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn base2k(&self) -> poulpy_core::layouts::Base2K {
|
||||||
self.0.base2k()
|
self.0.base2k()
|
||||||
}
|
}
|
||||||
@@ -60,13 +60,13 @@ impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintWord<D, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn rank(&self) -> poulpy_core::layouts::Rank {
|
||||||
self.0.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>(
|
pub fn encrypt_sk<S, M, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
@@ -109,7 +109,7 @@ impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintWord<D, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
pub fn decrypt<S, M, BE: Backend>(&self, module: &M, sk: &S, scratch: &mut Scratch<BE>) -> T
|
||||||
where
|
where
|
||||||
S: GLWESecretPreparedToRef<BE> + GLWEInfos,
|
S: GLWESecretPreparedToRef<BE> + GLWEInfos,
|
||||||
@@ -18,31 +18,24 @@ use crate::tfhe::bdd_arithmetic::ToBits;
|
|||||||
use crate::tfhe::bdd_arithmetic::UnsignedInteger;
|
use crate::tfhe::bdd_arithmetic::UnsignedInteger;
|
||||||
|
|
||||||
/// A prepared FHE ciphertext encrypting the bits of an [UnsignedInteger].
|
/// A prepared FHE ciphertext encrypting the bits of an [UnsignedInteger].
|
||||||
pub struct FheUintBlocksPrepared<D: Data, T: UnsignedInteger, B: Backend> {
|
pub struct FheUintPrepared<D: Data, T: UnsignedInteger, B: Backend> {
|
||||||
pub(crate) blocks: Vec<GGSWPrepared<D, B>>,
|
pub(crate) bits: Vec<GGSWPrepared<D, B>>,
|
||||||
pub(crate) _base: u8,
|
|
||||||
pub(crate) _phantom: PhantomData<T>,
|
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
|
impl<T: UnsignedInteger, BE: Backend> FheUintBlocksPreparedFactory<T, BE> for Module<BE> where
|
||||||
Self: Sized + GGSWPreparedFactory<BE>
|
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>;
|
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> {
|
fn get_bit(&self, bit: usize) -> GGSWPrepared<&[u8], BE> {
|
||||||
assert!(bit <= self.blocks.len());
|
assert!(bit <= self.bits.len());
|
||||||
self.blocks[bit].to_ref()
|
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>;
|
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> {
|
fn get_bit(&mut self, bit: usize) -> GGSWPrepared<&mut [u8], BE> {
|
||||||
assert!(bit <= self.blocks.len());
|
assert!(bit <= self.bits.len());
|
||||||
self.blocks[bit].to_mut()
|
self.bits[bit].to_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,28 +54,27 @@ pub trait FheUintBlocksPreparedFactory<T: UnsignedInteger, BE: Backend>
|
|||||||
where
|
where
|
||||||
Self: Sized + GGSWPreparedFactory<BE>,
|
Self: Sized + GGSWPreparedFactory<BE>,
|
||||||
{
|
{
|
||||||
fn alloc_fhe_uint_blocks_prepared(
|
fn alloc_fhe_uint_prepared(
|
||||||
&self,
|
&self,
|
||||||
base2k: Base2K,
|
base2k: Base2K,
|
||||||
k: TorusPrecision,
|
k: TorusPrecision,
|
||||||
dnum: Dnum,
|
dnum: Dnum,
|
||||||
dsize: Dsize,
|
dsize: Dsize,
|
||||||
rank: Rank,
|
rank: Rank,
|
||||||
) -> FheUintBlocksPrepared<Vec<u8>, T, BE> {
|
) -> FheUintPrepared<Vec<u8>, T, BE> {
|
||||||
FheUintBlocksPrepared {
|
FheUintPrepared {
|
||||||
blocks: (0..T::WORD_SIZE)
|
bits: (0..T::WORD_SIZE)
|
||||||
.map(|_| GGSWPrepared::alloc(self, base2k, k, dnum, dsize, rank))
|
.map(|_| GGSWPrepared::alloc(self, base2k, k, dnum, dsize, rank))
|
||||||
.collect(),
|
.collect(),
|
||||||
_base: 1,
|
|
||||||
_phantom: PhantomData,
|
_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
|
where
|
||||||
A: GGSWInfos,
|
A: GGSWInfos,
|
||||||
{
|
{
|
||||||
self.alloc_fhe_uint_blocks_prepared(
|
self.alloc_fhe_uint_prepared(
|
||||||
infos.base2k(),
|
infos.base2k(),
|
||||||
infos.k(),
|
infos.k(),
|
||||||
infos.dnum(),
|
infos.dnum(),
|
||||||
@@ -92,20 +84,20 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
pub fn alloc<A, M>(module: &M, infos: &A) -> Self
|
||||||
where
|
where
|
||||||
A: GGSWInfos,
|
A: GGSWInfos,
|
||||||
M: FheUintBlocksPreparedFactory<T, BE>,
|
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
|
pub fn alloc_with<M>(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self
|
||||||
where
|
where
|
||||||
M: FheUintBlocksPreparedFactory<T, BE>,
|
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: Backen
|
|||||||
where
|
where
|
||||||
Self: Sized + ModuleN + GGSWEncryptSk<BE> + GGSWPreparedFactory<BE>,
|
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,
|
&self,
|
||||||
res: &mut FheUintBlocksPrepared<DM, T, BE>,
|
res: &mut FheUintPrepared<DM, T, BE>,
|
||||||
value: T,
|
value: T,
|
||||||
sk: &S,
|
sk: &S,
|
||||||
source_xa: &mut Source,
|
source_xa: &mut Source,
|
||||||
@@ -145,12 +137,12 @@ where
|
|||||||
use poulpy_hal::layouts::ZnxViewMut;
|
use poulpy_hal::layouts::ZnxViewMut;
|
||||||
pt.at_mut(0, 0)[0] = value.bit(i) as i64;
|
pt.at_mut(0, 0)[0] = value.bit(i) as i64;
|
||||||
tmp_ggsw.encrypt_sk(self, &pt, sk, source_xa, source_xe, scratch_2);
|
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>(
|
pub fn encrypt_sk<M, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
@@ -164,36 +156,36 @@ impl<D: DataMut, T: UnsignedInteger + ToBits, BE: Backend> FheUintBlocksPrepared
|
|||||||
M: FheUintBlocksPreparedEncryptSk<T, BE>,
|
M: FheUintBlocksPreparedEncryptSk<T, BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<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 {
|
fn base2k(&self) -> poulpy_core::layouts::Base2K {
|
||||||
self.blocks[0].base2k()
|
self.bits[0].base2k()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn k(&self) -> poulpy_core::layouts::TorusPrecision {
|
fn k(&self) -> poulpy_core::layouts::TorusPrecision {
|
||||||
self.blocks[0].k()
|
self.bits[0].k()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn n(&self) -> poulpy_core::layouts::Degree {
|
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 {
|
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 {
|
fn dsize(&self) -> poulpy_core::layouts::Dsize {
|
||||||
self.blocks[0].dsize()
|
self.bits[0].dsize()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dnum(&self) -> poulpy_core::layouts::Dnum {
|
fn dnum(&self) -> poulpy_core::layouts::Dnum {
|
||||||
self.blocks[0].dnum()
|
self.bits[0].dnum()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use crate::tfhe::bdd_arithmetic::{BDDKeyPrepared, FheUintBlockDebugPrepare, ToBits};
|
use crate::tfhe::bdd_arithmetic::{BddKeyPrepared, FheUintBlockDebugPrepare, ToBits};
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{FheUintBlocks, UnsignedInteger},
|
bdd_arithmetic::{FheUint, UnsignedInteger},
|
||||||
blind_rotation::BlindRotationAlgo,
|
blind_rotation::BlindRotationAlgo,
|
||||||
circuit_bootstrapping::CirtuitBootstrappingExecute,
|
circuit_bootstrapping::CirtuitBootstrappingExecute,
|
||||||
};
|
};
|
||||||
@@ -18,13 +18,12 @@ use poulpy_core::{
|
|||||||
use poulpy_hal::api::ModuleN;
|
use poulpy_hal::api::ModuleN;
|
||||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||||
|
|
||||||
pub struct FheUintBlocksPreparedDebug<D: Data, T: UnsignedInteger> {
|
pub struct FheUintPreparedDebug<D: Data, T: UnsignedInteger> {
|
||||||
pub(crate) blocks: Vec<GGSW<D>>,
|
pub(crate) bits: Vec<GGSW<D>>,
|
||||||
pub(crate) _base: u8,
|
|
||||||
pub(crate) _phantom: PhantomData<T>,
|
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
|
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||||
where
|
where
|
||||||
M: ModuleN,
|
M: ModuleN,
|
||||||
@@ -45,52 +44,51 @@ impl<T: UnsignedInteger> FheUintBlocksPreparedDebug<Vec<u8>, T> {
|
|||||||
M: ModuleN,
|
M: ModuleN,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
blocks: (0..T::WORD_SIZE)
|
bits: (0..T::WORD_SIZE)
|
||||||
.map(|_| GGSW::alloc(module.n().into(), base2k, k, rank, dnum, dsize))
|
.map(|_| GGSW::alloc(module.n().into(), base2k, k, rank, dnum, dsize))
|
||||||
.collect(),
|
.collect(),
|
||||||
_base: 1,
|
|
||||||
_phantom: PhantomData,
|
_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 {
|
fn base2k(&self) -> poulpy_core::layouts::Base2K {
|
||||||
self.blocks[0].base2k()
|
self.bits[0].base2k()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn k(&self) -> poulpy_core::layouts::TorusPrecision {
|
fn k(&self) -> poulpy_core::layouts::TorusPrecision {
|
||||||
self.blocks[0].k()
|
self.bits[0].k()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn n(&self) -> poulpy_core::layouts::Degree {
|
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 {
|
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 {
|
fn dsize(&self) -> poulpy_core::layouts::Dsize {
|
||||||
self.blocks[0].dsize()
|
self.bits[0].dsize()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dnum(&self) -> poulpy_core::layouts::Dnum {
|
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)
|
pub fn print_noise<S, M, BE: Backend>(&self, module: &M, sk: &S, want: T)
|
||||||
where
|
where
|
||||||
S: GLWESecretPreparedToRef<BE>,
|
S: GLWESecretPreparedToRef<BE>,
|
||||||
M: GGSWNoise<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};
|
use poulpy_hal::layouts::{ScalarZnx, ZnxViewMut};
|
||||||
let mut pt_want = ScalarZnx::alloc(self.n().into(), 1);
|
let mut pt_want = ScalarZnx::alloc(self.n().into(), 1);
|
||||||
pt_want.at_mut(0, 0)[0] = want.bit(i) as i64;
|
pt_want.at_mut(0, 0)[0] = want.bit(i) as i64;
|
||||||
@@ -104,7 +102,7 @@ impl<D: DataRef, T: UnsignedInteger + ToBits> FheUintBlocksPreparedDebug<D, T> {
|
|||||||
M: GGSWNoise<BE>,
|
M: GGSWNoise<BE>,
|
||||||
F: Fn(usize) -> f64,
|
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};
|
use poulpy_hal::layouts::{ScalarZnx, ZnxViewMut};
|
||||||
let mut pt_want = ScalarZnx::alloc(self.n().into(), 1);
|
let mut pt_want = ScalarZnx::alloc(self.n().into(), 1);
|
||||||
pt_want.at_mut(0, 0)[0] = want.bit(i) as i64;
|
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>,
|
Self: LWEFromGLWE<BE> + CirtuitBootstrappingExecute<BRA, BE> + GGSWPreparedFactory<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn fhe_uint_block_debug_prepare<DM, DR0, DR1>(
|
fn fhe_uint_debug_prepare<DM, DR0, DR1>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut FheUintBlocksPreparedDebug<DM, T>,
|
res: &mut FheUintPreparedDebug<DM, T>,
|
||||||
bits: &FheUintBlocks<DR0, T>,
|
bits: &FheUint<DR0, T>,
|
||||||
key: &BDDKeyPrepared<DR1, BRA, BE>,
|
key: &BddKeyPrepared<DR1, BRA, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
DR0: DataRef,
|
DR0: DataRef,
|
||||||
DR1: 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
|
||||||
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);
|
lwe.from_glwe(self, src, &key.ks, scratch);
|
||||||
key.cbt.execute_to_constant(self, dst, &lwe, 1, 1, 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>(
|
pub fn prepare<BRA, M, O, K, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
other: &FheUintBlocks<O, T>,
|
other: &FheUint<O, T>,
|
||||||
key: &BDDKeyPrepared<K, BRA, BE>,
|
key: &BddKeyPrepared<K, BRA, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
BRA: BlindRotationAlgo,
|
BRA: BlindRotationAlgo,
|
||||||
@@ -153,6 +151,6 @@ impl<D: DataMut, T: UnsignedInteger> FheUintBlocksPreparedDebug<D, T> {
|
|||||||
M: FheUintBlockDebugPrepare<BRA, T, BE>,
|
M: FheUintBlockDebugPrepare<BRA, T, BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
module.fhe_uint_block_debug_prepare(self, other, key, scratch);
|
module.fhe_uint_debug_prepare(self, other, key, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,50 +13,42 @@ use poulpy_hal::source::Source;
|
|||||||
use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger};
|
use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger};
|
||||||
|
|
||||||
/// An FHE ciphertext encrypting the bits of an [UnsignedInteger].
|
/// An FHE ciphertext encrypting the bits of an [UnsignedInteger].
|
||||||
pub struct FheUintBlocks<D: Data, T: UnsignedInteger> {
|
pub struct FheUint<D: Data, T: UnsignedInteger> {
|
||||||
pub(crate) blocks: Vec<GLWE<D>>,
|
pub(crate) bits: Vec<GLWE<D>>,
|
||||||
pub(crate) _base: u8,
|
|
||||||
pub(crate) _phantom: PhantomData<T>,
|
pub(crate) _phantom: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef, T: UnsignedInteger> FheUintBlocks<D, T> {
|
impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUint<D, T> {
|
||||||
pub fn blocks(&self) -> &Vec<GLWE<D>> {
|
|
||||||
&self.blocks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintBlocks<D, T> {
|
|
||||||
fn base2k(&self) -> poulpy_core::layouts::Base2K {
|
fn base2k(&self) -> poulpy_core::layouts::Base2K {
|
||||||
self.blocks[0].base2k()
|
self.bits[0].base2k()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn k(&self) -> poulpy_core::layouts::TorusPrecision {
|
fn k(&self) -> poulpy_core::layouts::TorusPrecision {
|
||||||
self.blocks[0].k()
|
self.bits[0].k()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn n(&self) -> poulpy_core::layouts::Degree {
|
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 {
|
fn rank(&self) -> poulpy_core::layouts::Rank {
|
||||||
self.blocks[0].rank()
|
self.bits[0].rank()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data, T: UnsignedInteger> FheUintBlocks<D, T> {
|
impl<D: Data, T: UnsignedInteger> FheUint<D, T> {
|
||||||
pub fn new(blocks: Vec<GLWE<D>>) -> Self {
|
pub fn new(bits: Vec<GLWE<D>>) -> Self {
|
||||||
assert_eq!(blocks.len(), T::WORD_SIZE);
|
assert_eq!(bits.len(), T::WORD_SIZE);
|
||||||
Self {
|
Self {
|
||||||
blocks,
|
bits,
|
||||||
_base: 1,
|
|
||||||
_phantom: PhantomData,
|
_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
|
pub fn alloc_from_infos<A, BE: Backend>(module: &Module<BE>, infos: &A) -> Self
|
||||||
where
|
where
|
||||||
A: GLWEInfos,
|
A: GLWEInfos,
|
||||||
@@ -66,16 +58,15 @@ impl<T: UnsignedInteger> FheUintBlocks<Vec<u8>, T> {
|
|||||||
|
|
||||||
pub fn alloc<BE: Backend>(module: &Module<BE>, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
|
pub fn alloc<BE: Backend>(module: &Module<BE>, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
|
||||||
Self {
|
Self {
|
||||||
blocks: (0..T::WORD_SIZE)
|
bits: (0..T::WORD_SIZE)
|
||||||
.map(|_| GLWE::alloc(module.n().into(), base2k, k, rank))
|
.map(|_| GLWE::alloc(module.n().into(), base2k, k, rank))
|
||||||
.collect(),
|
.collect(),
|
||||||
_base: 1,
|
|
||||||
_phantom: PhantomData,
|
_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>(
|
pub fn encrypt_sk<S, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &Module<BE>,
|
module: &Module<BE>,
|
||||||
@@ -110,12 +101,12 @@ impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintBlocks<D, T> {
|
|||||||
|
|
||||||
for i in 0..T::WORD_SIZE {
|
for i in 0..T::WORD_SIZE {
|
||||||
pt.encode_coeff_i64(value.bit(i) as i64, TorusPrecision(2), 0);
|
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
|
pub fn decrypt<S, BE: Backend>(&self, module: &Module<BE>, sk: &S, scratch: &mut Scratch<BE>) -> T
|
||||||
where
|
where
|
||||||
Module<BE>: GLWEDecrypt<BE>,
|
Module<BE>: GLWEDecrypt<BE>,
|
||||||
@@ -143,7 +134,7 @@ impl<D: DataRef, T: UnsignedInteger + FromBits + ToBits> FheUintBlocks<D, T> {
|
|||||||
let scale: f64 = 4.0 / ((1 << base2k) as f64);
|
let scale: f64 = 4.0 / ((1 << base2k) as f64);
|
||||||
|
|
||||||
for (i, bit) in bits.iter_mut().enumerate().take(T::WORD_SIZE) {
|
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);
|
let value: i64 = pt.decode_coeff_i64(base2k.into(), 0);
|
||||||
*bit = ((value as f64) * scale).round() as u8;
|
*bit = ((value as f64) * scale).round() as u8;
|
||||||
}
|
}
|
||||||
@@ -177,7 +168,7 @@ impl<D: DataRef, T: UnsignedInteger + FromBits + ToBits> FheUintBlocks<D, T> {
|
|||||||
|
|
||||||
for (i, noise_i) in noise.iter_mut().enumerate().take(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);
|
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
|
noise
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
mod block;
|
mod fhe_uint_compressed;
|
||||||
mod block_prepared;
|
mod fhe_uint_prepared;
|
||||||
mod word;
|
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 fhe_uint_compressed::*;
|
||||||
pub use block_prepared::*;
|
pub use fhe_uint_prepared::*;
|
||||||
pub use word::*;
|
pub use fheuint::*;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use poulpy_core::{
|
|||||||
};
|
};
|
||||||
use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, ZnxZero};
|
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 {
|
pub trait BitCircuitInfo {
|
||||||
fn info(&self) -> (&[Node], usize);
|
fn info(&self) -> (&[Node], usize);
|
||||||
@@ -27,35 +27,31 @@ pub(crate) struct BitCircuit<const N: usize> {
|
|||||||
pub struct Circuit<C: BitCircuitInfo, const N: usize>(pub [C; N]);
|
pub struct Circuit<C: BitCircuitInfo, const N: usize>(pub [C; N]);
|
||||||
|
|
||||||
pub trait ExecuteBDDCircuit<T: UnsignedInteger, BE: Backend> {
|
pub trait ExecuteBDDCircuit<T: UnsignedInteger, BE: Backend> {
|
||||||
fn execute_bdd_circuit<C, O>(
|
fn execute_bdd_circuit<C, G, O>(&self, out: &mut [GLWE<O>], inputs: &G, circuit: &C, scratch: &mut Scratch<BE>)
|
||||||
&self,
|
where
|
||||||
out: &mut [GLWE<O>],
|
G: GetGGSWBit<BE> + BitSize,
|
||||||
inputs: &[&dyn GGSWPreparedToRef<BE>],
|
|
||||||
circuit: &C,
|
|
||||||
scratch: &mut Scratch<BE>,
|
|
||||||
) where
|
|
||||||
C: GetBitCircuitInfo<T>,
|
C: GetBitCircuitInfo<T>,
|
||||||
O: DataMut;
|
O: DataMut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait BitSize {
|
||||||
|
fn bit_size(&self) -> usize;
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: UnsignedInteger, BE: Backend> ExecuteBDDCircuit<T, BE> for Module<BE>
|
impl<T: UnsignedInteger, BE: Backend> ExecuteBDDCircuit<T, BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: Cmux<BE> + GLWECopy,
|
Self: Cmux<BE> + GLWECopy,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn execute_bdd_circuit<C, O>(
|
fn execute_bdd_circuit<C, G, O>(&self, out: &mut [GLWE<O>], inputs: &G, circuit: &C, scratch: &mut Scratch<BE>)
|
||||||
&self,
|
where
|
||||||
out: &mut [GLWE<O>],
|
G: GetGGSWBit<BE> + BitSize,
|
||||||
inputs: &[&dyn GGSWPreparedToRef<BE>],
|
|
||||||
circuit: &C,
|
|
||||||
scratch: &mut Scratch<BE>,
|
|
||||||
) where
|
|
||||||
C: GetBitCircuitInfo<T>,
|
C: GetBitCircuitInfo<T>,
|
||||||
O: DataMut,
|
O: DataMut,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
assert_eq!(inputs.len(), circuit.input_size());
|
assert_eq!(inputs.bit_size(), circuit.input_size());
|
||||||
assert!(out.len() >= circuit.output_size());
|
assert!(out.len() >= circuit.output_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +82,7 @@ where
|
|||||||
next_level[j],
|
next_level[j],
|
||||||
prev_level[*hi_idx],
|
prev_level[*hi_idx],
|
||||||
prev_level[*lo_idx],
|
prev_level[*lo_idx],
|
||||||
&inputs[*in_idx].to_ref(),
|
&inputs.get_bit(*in_idx),
|
||||||
scratch_1,
|
scratch_1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -106,7 +102,7 @@ where
|
|||||||
out_i,
|
out_i,
|
||||||
prev_level[*hi_idx],
|
prev_level[*hi_idx],
|
||||||
prev_level[*lo_idx],
|
prev_level[*lo_idx],
|
||||||
&inputs[*in_idx].to_ref(),
|
&inputs.get_bit(*in_idx),
|
||||||
scratch_1,
|
scratch_1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::tfhe::bdd_arithmetic::FheUintBlocksPreparedDebug;
|
use crate::tfhe::bdd_arithmetic::FheUintPreparedDebug;
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{FheUintBlocks, FheUintBlocksPrepared, UnsignedInteger},
|
bdd_arithmetic::{FheUint, FheUintPrepared, UnsignedInteger},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
circuit_bootstrapping::{
|
circuit_bootstrapping::{
|
||||||
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout,
|
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout,
|
||||||
@@ -123,7 +123,7 @@ impl<D: DataMut, BRA: BlindRotationAlgo> BDDKey<D, BRA> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BDDKeyPrepared<D, BRA, BE>
|
pub struct BddKeyPrepared<D, BRA, BE>
|
||||||
where
|
where
|
||||||
D: Data,
|
D: Data,
|
||||||
BRA: BlindRotationAlgo,
|
BRA: BlindRotationAlgo,
|
||||||
@@ -137,11 +137,11 @@ pub trait BDDKeyPreparedFactory<BRA: BlindRotationAlgo, BE: Backend>
|
|||||||
where
|
where
|
||||||
Self: Sized + CircuitBootstrappingKeyPreparedFactory<BRA, BE> + GLWEToLWEKeyPreparedFactory<BE>,
|
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
|
where
|
||||||
A: BDDKeyInfos,
|
A: BDDKeyInfos,
|
||||||
{
|
{
|
||||||
BDDKeyPrepared {
|
BddKeyPrepared {
|
||||||
cbt: CircuitBootstrappingKeyPrepared::alloc_from_infos(self, &infos.cbt_infos()),
|
cbt: CircuitBootstrappingKeyPrepared::alloc_from_infos(self, &infos.cbt_infos()),
|
||||||
ks: GLWEToLWEKeyPrepared::alloc_from_infos(self, &infos.ks_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()))
|
.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
|
where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
DR: DataRef,
|
DR: DataRef,
|
||||||
@@ -170,7 +170,7 @@ impl<BRA: BlindRotationAlgo, BE: Backend> BDDKeyPreparedFactory<BRA, BE> for Mod
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
pub fn alloc_from_infos<M, A>(module: &M, infos: &A) -> Self
|
||||||
where
|
where
|
||||||
M: BDDKeyPreparedFactory<BRA, BE>,
|
M: BDDKeyPreparedFactory<BRA, BE>,
|
||||||
@@ -180,7 +180,7 @@ impl<BRA: BlindRotationAlgo, BE: Backend> BDDKeyPrepared<Vec<u8>, BRA, BE> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>)
|
pub fn prepare<DR, M>(&mut self, module: &M, other: &BDDKey<DR, BRA>, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
DR: DataRef,
|
DR: DataRef,
|
||||||
@@ -192,21 +192,15 @@ impl<D: DataMut, BRA: BlindRotationAlgo, BE: Backend> BDDKeyPrepared<D, BRA, BE>
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait FheUintBlocksPrepare<BRA: BlindRotationAlgo, T: UnsignedInteger, BE: Backend> {
|
pub trait FheUintBlocksPrepare<BRA: BlindRotationAlgo, T: UnsignedInteger, BE: Backend> {
|
||||||
fn fhe_uint_blocks_prepare_tmp_bytes<R, A>(
|
fn fhe_uint_prepare_tmp_bytes<R, A>(&self, block_size: usize, extension_factor: usize, res_infos: &R, infos: &A) -> usize
|
||||||
&self,
|
|
||||||
block_size: usize,
|
|
||||||
extension_factor: usize,
|
|
||||||
res_infos: &R,
|
|
||||||
infos: &A,
|
|
||||||
) -> usize
|
|
||||||
where
|
where
|
||||||
R: GGSWInfos,
|
R: GGSWInfos,
|
||||||
A: BDDKeyInfos;
|
A: BDDKeyInfos;
|
||||||
fn fhe_uint_blocks_prepare<DM, DR0, DR1>(
|
fn fhe_uint_prepare<DM, DR0, DR1>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut FheUintBlocksPrepared<DM, T, BE>,
|
res: &mut FheUintPrepared<DM, T, BE>,
|
||||||
bits: &FheUintBlocks<DR0, T>,
|
bits: &FheUint<DR0, T>,
|
||||||
key: &BDDKeyPrepared<DR1, BRA, BE>,
|
key: &BddKeyPrepared<DR1, BRA, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
@@ -219,13 +213,7 @@ where
|
|||||||
Self: LWEFromGLWE<BE> + CirtuitBootstrappingExecute<BRA, BE> + GGSWPreparedFactory<BE>,
|
Self: LWEFromGLWE<BE> + CirtuitBootstrappingExecute<BRA, BE> + GGSWPreparedFactory<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn fhe_uint_blocks_prepare_tmp_bytes<R, A>(
|
fn fhe_uint_prepare_tmp_bytes<R, A>(&self, block_size: usize, extension_factor: usize, res_infos: &R, bdd_infos: &A) -> usize
|
||||||
&self,
|
|
||||||
block_size: usize,
|
|
||||||
extension_factor: usize,
|
|
||||||
res_infos: &R,
|
|
||||||
bdd_infos: &A,
|
|
||||||
) -> usize
|
|
||||||
where
|
where
|
||||||
R: GGSWInfos,
|
R: GGSWInfos,
|
||||||
A: BDDKeyInfos,
|
A: BDDKeyInfos,
|
||||||
@@ -238,22 +226,22 @@ where
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fhe_uint_blocks_prepare<DM, DR0, DR1>(
|
fn fhe_uint_prepare<DM, DR0, DR1>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut FheUintBlocksPrepared<DM, T, BE>,
|
res: &mut FheUintPrepared<DM, T, BE>,
|
||||||
bits: &FheUintBlocks<DR0, T>,
|
bits: &FheUint<DR0, T>,
|
||||||
key: &BDDKeyPrepared<DR1, BRA, BE>,
|
key: &BddKeyPrepared<DR1, BRA, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
DR0: DataRef,
|
DR0: DataRef,
|
||||||
DR1: 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);
|
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);
|
lwe.from_glwe(self, src, &key.ks, scratch_1);
|
||||||
key.cbt
|
key.cbt
|
||||||
.execute_to_constant(self, &mut tmp_ggsw, &lwe, 1, 1, scratch_1);
|
.execute_to_constant(self, &mut tmp_ggsw, &lwe, 1, 1, scratch_1);
|
||||||
@@ -262,12 +250,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>(
|
pub fn prepare<BRA, M, O, K>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
other: &FheUintBlocks<O, T>,
|
other: &FheUint<O, T>,
|
||||||
key: &BDDKeyPrepared<K, BRA, BE>,
|
key: &BddKeyPrepared<K, BRA, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
BRA: BlindRotationAlgo,
|
BRA: BlindRotationAlgo,
|
||||||
@@ -276,16 +264,16 @@ impl<D: DataMut, T: UnsignedInteger, BE: Backend> FheUintBlocksPrepared<D, T, BE
|
|||||||
M: FheUintBlocksPrepare<BRA, T, BE>,
|
M: FheUintBlocksPrepare<BRA, T, BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<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> {
|
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,
|
&self,
|
||||||
res: &mut FheUintBlocksPreparedDebug<DM, T>,
|
res: &mut FheUintPreparedDebug<DM, T>,
|
||||||
bits: &FheUintBlocks<DR0, T>,
|
bits: &FheUint<DR0, T>,
|
||||||
key: &BDDKeyPrepared<DR1, BRA, BE>,
|
key: &BddKeyPrepared<DR1, BRA, BE>,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
Add, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
Add, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory,
|
FheUintBlocksPrepare, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32();
|
let b: u32 = source.next_u32();
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
And, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
And, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory,
|
FheUintBlocksPrepare, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32();
|
let b: u32 = source.next_u32();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
use rand::RngCore;
|
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>()
|
pub fn test_scalar_to_ggsw_blind_rotation<BE: Backend>()
|
||||||
where
|
where
|
||||||
@@ -80,8 +80,7 @@ where
|
|||||||
|
|
||||||
// println!("k: {k}");
|
// println!("k: {k}");
|
||||||
|
|
||||||
let mut k_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut k_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_k_infos);
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_k_infos);
|
|
||||||
k_enc_prep.encrypt_sk(
|
k_enc_prep.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
k,
|
k,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
use rand::RngCore;
|
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>()
|
pub fn test_glwe_to_glwe_blind_rotation<BE: Backend>()
|
||||||
where
|
where
|
||||||
@@ -72,8 +72,7 @@ where
|
|||||||
|
|
||||||
let k: u32 = source.next_u32();
|
let k: u32 = source.next_u32();
|
||||||
|
|
||||||
let mut k_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut k_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
k_enc_prep.encrypt_sk(
|
k_enc_prep.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
k,
|
k,
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Or,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Or,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32();
|
let b: u32 = source.next_u32();
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKey, BDDKeyEncryptSk, BDDKeyLayout, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W,
|
BDDKey, BDDKeyEncryptSk, BDDKeyLayout, BDDKeyPreparedFactory, BddKeyPrepared, ExecuteBDDCircuit2WTo1W, FheUint,
|
||||||
FheUintBlockDebugPrepare, FheUintBlocks, FheUintBlocksPrepare, FheUintBlocksPreparedDebug,
|
FheUintBlockDebugPrepare, FheUintBlocksPrepare, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory,
|
||||||
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory,
|
FheUintPreparedDebug,
|
||||||
tests::test_suite::{TEST_BASE2K, TEST_BDD_KEY_LAYOUT, TEST_BLOCK_SIZE, TEST_GGSW_INFOS, TEST_GLWE_INFOS, TEST_N_LWE},
|
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},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -79,12 +79,12 @@ where
|
|||||||
&mut source_xe,
|
&mut source_xe,
|
||||||
scratch.borrow(),
|
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);
|
source.fill_bytes(&mut scratch.borrow().data);
|
||||||
bdd_key_prepared.prepare(&module, &bdd_key, scratch.borrow());
|
bdd_key_prepared.prepare(&module, &bdd_key, scratch.borrow());
|
||||||
|
|
||||||
// GLWE(value)
|
// 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();
|
let value: u32 = source.next_u32();
|
||||||
c_enc.encrypt_sk(
|
c_enc.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
@@ -96,8 +96,8 @@ where
|
|||||||
);
|
);
|
||||||
|
|
||||||
// GGSW(0)
|
// GGSW(0)
|
||||||
let mut c_enc_prep_debug: FheUintBlocksPreparedDebug<Vec<u8>, u32> =
|
let mut c_enc_prep_debug: FheUintPreparedDebug<Vec<u8>, u32> =
|
||||||
FheUintBlocksPreparedDebug::<Vec<u8>, u32>::alloc_from_infos(&module, &ggsw_infos);
|
FheUintPreparedDebug::<Vec<u8>, u32>::alloc_from_infos(&module, &ggsw_infos);
|
||||||
|
|
||||||
// GGSW(value)
|
// GGSW(value)
|
||||||
c_enc_prep_debug.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow());
|
c_enc_prep_debug.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow());
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sll,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sll,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32() & 15;
|
let b: u32 = source.next_u32() & 15;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Slt,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Slt,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32();
|
let b: u32 = source.next_u32();
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sltu,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sltu,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32();
|
let b: u32 = source.next_u32();
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sra,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sra,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32() & 15;
|
let b: u32 = source.next_u32() & 15;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Srl,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Srl,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32() & 15;
|
let b: u32 = source.next_u32() & 15;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sub,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Sub,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32();
|
let b: u32 = source.next_u32();
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use rand::RngCore;
|
|||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
bdd_arithmetic::{
|
bdd_arithmetic::{
|
||||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUint, FheUintBlockDebugPrepare, FheUintBlocksPrepare,
|
||||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Xor,
|
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, FheUintPrepared, Xor,
|
||||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||||
},
|
},
|
||||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||||
@@ -55,11 +55,9 @@ where
|
|||||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
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 res: FheUint<Vec<u8>, u32> = FheUint::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
let mut a_enc_prep: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||||
FheUintBlocksPrepared::<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 mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
|
||||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
|
||||||
|
|
||||||
let a: u32 = source.next_u32();
|
let a: u32 = source.next_u32();
|
||||||
let b: u32 = source.next_u32();
|
let b: u32 = source.next_u32();
|
||||||
|
|||||||
Reference in New Issue
Block a user