mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Add helper trait for BDDKey
This commit is contained in:
@@ -210,16 +210,17 @@ pub trait FheUintBlocksPrepare<BRA: BlindRotationAlgo, T: UnsignedInteger, BE: B
|
|||||||
where
|
where
|
||||||
R: GGSWInfos,
|
R: GGSWInfos,
|
||||||
A: BDDKeyInfos;
|
A: BDDKeyInfos;
|
||||||
fn fhe_uint_prepare<DM, DR0, DR1>(
|
fn fhe_uint_prepare<DM, DB, DK, K>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut FheUintPrepared<DM, T, BE>,
|
res: &mut FheUintPrepared<DM, T, BE>,
|
||||||
bits: &FheUint<DR0, T>,
|
bits: &FheUint<DB, T>,
|
||||||
key: &BDDKeyPrepared<DR1, BRA, BE>,
|
key: &K,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
DR0: DataRef,
|
DB: DataRef,
|
||||||
DR1: DataRef;
|
DK: DataRef,
|
||||||
|
K: BDDKeyHelper<DK, BRA, BE>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BRA: BlindRotationAlgo, BE: Backend, T: UnsignedInteger> FheUintBlocksPrepare<BRA, T, BE> for Module<BE>
|
impl<BRA: BlindRotationAlgo, BE: Backend, T: UnsignedInteger> FheUintBlocksPrepare<BRA, T, BE> for Module<BE>
|
||||||
@@ -240,39 +241,46 @@ where
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fhe_uint_prepare<DM, DR0, DR1>(
|
fn fhe_uint_prepare<DM, DB, DK, K>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut FheUintPrepared<DM, T, BE>,
|
res: &mut FheUintPrepared<DM, T, BE>,
|
||||||
bits: &FheUint<DR0, T>,
|
bits: &FheUint<DB, T>,
|
||||||
key: &BDDKeyPrepared<DR1, BRA, BE>,
|
key: &K,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
DR0: DataRef,
|
DB: DataRef,
|
||||||
DR1: DataRef,
|
DK: DataRef,
|
||||||
|
K: BDDKeyHelper<DK, BRA, BE>,
|
||||||
{
|
{
|
||||||
|
let (cbt, ks) = key.get_cbt_key();
|
||||||
|
|
||||||
let mut lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(bits); //TODO: add TakeLWE
|
let mut lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(bits); //TODO: add TakeLWE
|
||||||
let (mut tmp_ggsw, scratch_1) = scratch.take_ggsw(res);
|
let (mut tmp_ggsw, scratch_1) = scratch.take_ggsw(res);
|
||||||
for (bit, dst) in res.bits.iter_mut().enumerate() {
|
for (bit, dst) in res.bits.iter_mut().enumerate() {
|
||||||
bits.get_bit(self, bit, &mut lwe, &key.ks, scratch_1);
|
bits.get_bit(self, bit, &mut lwe, ks, scratch_1);
|
||||||
key.cbt
|
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);
|
|
||||||
dst.prepare(self, &tmp_ggsw, scratch_1);
|
dst.prepare(self, &tmp_ggsw, scratch_1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait BDDKeyHelper<D: DataRef, BRA: BlindRotationAlgo, BE: Backend> {
|
||||||
|
fn get_cbt_key(
|
||||||
|
&self,
|
||||||
|
) -> (
|
||||||
|
&CircuitBootstrappingKeyPrepared<D, BRA, BE>,
|
||||||
|
&GLWEToLWEKeyPrepared<D, BE>,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
impl<D: DataMut, T: UnsignedInteger, BE: Backend> FheUintPrepared<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, DK>(&mut self, module: &M, other: &FheUint<O, T>, key: &K, scratch: &mut Scratch<BE>)
|
||||||
&mut self,
|
where
|
||||||
module: &M,
|
|
||||||
other: &FheUint<O, T>,
|
|
||||||
key: &BDDKeyPrepared<K, BRA, BE>,
|
|
||||||
scratch: &mut Scratch<BE>,
|
|
||||||
) where
|
|
||||||
BRA: BlindRotationAlgo,
|
BRA: BlindRotationAlgo,
|
||||||
O: DataRef,
|
O: DataRef,
|
||||||
K: DataRef,
|
DK: DataRef,
|
||||||
|
K: BDDKeyHelper<DK, BRA, BE>,
|
||||||
M: FheUintBlocksPrepare<BRA, T, BE>,
|
M: FheUintBlocksPrepare<BRA, T, BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user