mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Replace hasmap of glweautomorphismkeys by helper trait, enabling not having to pass, for example, but full CBT key for ops that do not require it
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use poulpy_core::{
|
||||
GLWEAdd, GLWECopy, GLWEDecrypt, GLWEEncryptSk, GLWEPacking, GLWERotate, GLWESub, GLWETrace, LWEFromGLWE, ScratchTakeCore,
|
||||
layouts::{
|
||||
Base2K, Degree, GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEPlaintextLayout, GLWESecretPreparedToRef, GLWEToMut,
|
||||
GLWEToRef, LWEInfos, LWEToMut, Rank, TorusPrecision,
|
||||
Base2K, Degree, GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEAutomorphismKeyHelper, GLWEInfos, GLWEPlaintextLayout,
|
||||
GLWESecretPreparedToRef, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos, LWEToMut, Rank, TorusPrecision,
|
||||
},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
@@ -171,20 +171,20 @@ impl<D: DataMut, T: UnsignedInteger> FheUint<D, T> {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn splice_u16<D0, A, B, BRA, M, BE: Backend>(
|
||||
pub fn splice_u16<A, B, H, K, M, BE: Backend>(
|
||||
&mut self,
|
||||
module: &M,
|
||||
dst: usize,
|
||||
src: usize,
|
||||
a: &A,
|
||||
b: &B,
|
||||
keys: &BDDKeyPrepared<D0, BRA, BE>,
|
||||
keys: &H,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
D0: DataRef,
|
||||
A: GLWEToRef + GLWEInfos,
|
||||
B: GLWEToRef + GLWEInfos,
|
||||
BRA: BlindRotationAlgo,
|
||||
H: GLWEAutomorphismKeyHelper<K, BE>,
|
||||
K: GGLWEPreparedToRef<BE> + GGLWEInfos + GetGaloisElement,
|
||||
M: ModuleLogN + GLWERotate<BE> + GLWETrace<BE> + GLWESub + GLWEAdd + GLWECopy,
|
||||
Scratch<BE>: ScratchTakeBDD<T, BE>,
|
||||
{
|
||||
@@ -206,20 +206,20 @@ impl<D: DataMut, T: UnsignedInteger> FheUint<D, T> {
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
// Store on the receiver a where the byte_a-th byte of a has been replaced by byte_src2 of src2.
|
||||
pub fn splice_u8<D0, A, B, BRA, M, BE: Backend>(
|
||||
pub fn splice_u8<A, B, H, K, M, BE: Backend>(
|
||||
&mut self,
|
||||
module: &M,
|
||||
dst: usize,
|
||||
src: usize,
|
||||
a: &A,
|
||||
b: &B,
|
||||
keys: &BDDKeyPrepared<D0, BRA, BE>,
|
||||
keys: &H,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
D0: DataRef,
|
||||
A: GLWEToRef + GLWEInfos,
|
||||
B: GLWEToRef + GLWEInfos,
|
||||
BRA: BlindRotationAlgo,
|
||||
H: GLWEAutomorphismKeyHelper<K, BE>,
|
||||
K: GGLWEPreparedToRef<BE> + GGLWEInfos + GetGaloisElement,
|
||||
M: ModuleLogN + GLWERotate<BE> + GLWETrace<BE> + GLWESub + GLWEAdd + GLWECopy,
|
||||
Scratch<BE>: ScratchTakeBDD<T, BE>,
|
||||
{
|
||||
@@ -241,7 +241,7 @@ impl<D: DataMut, T: UnsignedInteger> FheUint<D, T> {
|
||||
trace_start,
|
||||
module.log_n(),
|
||||
self,
|
||||
&keys.cbt.atk,
|
||||
keys,
|
||||
scratch_1,
|
||||
);
|
||||
|
||||
@@ -263,7 +263,7 @@ impl<D: DataMut, T: UnsignedInteger> FheUint<D, T> {
|
||||
&mut tmp_fhe_uint_byte,
|
||||
trace_start,
|
||||
module.log_n(),
|
||||
&keys.cbt.atk,
|
||||
keys,
|
||||
scratch_1,
|
||||
);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::tfhe::{
|
||||
},
|
||||
};
|
||||
|
||||
use poulpy_core::layouts::{GLWEAutomorphismKeyHelper, GLWEAutomorphismKeyPrepared};
|
||||
use poulpy_core::{
|
||||
GLWEToLWESwitchingKeyEncryptSk, GetDistribution, LWEFromGLWE, ScratchTakeCore,
|
||||
layouts::{
|
||||
@@ -134,6 +135,18 @@ where
|
||||
pub(crate) ks: GLWEToLWEKeyPrepared<D, BE>,
|
||||
}
|
||||
|
||||
impl<D: DataRef, BRA: BlindRotationAlgo, BE: Backend> GLWEAutomorphismKeyHelper<GLWEAutomorphismKeyPrepared<D, BE>, BE>
|
||||
for BDDKeyPrepared<D, BRA, BE>
|
||||
{
|
||||
fn automorphism_key_infos(&self) -> poulpy_core::layouts::GGLWELayout {
|
||||
self.cbt.automorphism_key_infos()
|
||||
}
|
||||
|
||||
fn get_automorphism_key(&self, k: i64) -> Option<&GLWEAutomorphismKeyPrepared<D, BE>> {
|
||||
self.cbt.get_automorphism_key(k)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BDDKeyPreparedFactory<BRA: BlindRotationAlgo, BE: Backend>
|
||||
where
|
||||
Self: Sized + CircuitBootstrappingKeyPreparedFactory<BRA, BE> + GLWEToLWEKeyPreparedFactory<BE>,
|
||||
|
||||
@@ -8,11 +8,12 @@ use poulpy_hal::{
|
||||
use poulpy_core::{
|
||||
GGSWFromGGLWE, GLWEDecrypt, GLWEPacking, GLWERotate, GLWETrace, ScratchTakeCore,
|
||||
layouts::{
|
||||
Dsize, GGLWELayout, GGSWInfos, GGSWToMut, GLWEInfos, GLWESecretPreparedFactory, GLWEToMut, GLWEToRef, LWEInfos, LWEToRef,
|
||||
Dsize, GGLWEInfos, GGLWELayout, GGLWEPreparedToRef, GGSWInfos, GGSWToMut, GLWEAutomorphismKeyHelper, GLWEInfos,
|
||||
GLWESecretPreparedFactory, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos, LWEToRef,
|
||||
},
|
||||
};
|
||||
|
||||
use poulpy_core::layouts::{GGSW, GLWE, LWE, prepared::GLWEAutomorphismKeyPrepared};
|
||||
use poulpy_core::layouts::{GGSW, GLWE, LWE};
|
||||
|
||||
use crate::tfhe::{
|
||||
blind_rotation::{
|
||||
@@ -323,18 +324,20 @@ pub fn circuit_bootstrap_core<R, L, D, M, BRA: BlindRotationAlgo, BE: Backend>(
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn post_process<R, A, M, BE: Backend>(
|
||||
fn post_process<R, A, M, H, K, BE: Backend>(
|
||||
module: &M,
|
||||
res: &mut R,
|
||||
a: &A,
|
||||
log_gap_in: usize,
|
||||
log_gap_out: usize,
|
||||
log_domain: usize,
|
||||
auto_keys: &HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>>,
|
||||
auto_keys: &H,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
R: GLWEToMut,
|
||||
A: GLWEToRef,
|
||||
H: GLWEAutomorphismKeyHelper<K, BE>,
|
||||
K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
|
||||
M: ModuleLogN + GLWETrace<BE> + GLWEPacking<BE> + GLWERotate<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use poulpy_core::{
|
||||
layouts::{
|
||||
GGLWEInfos, GGLWEToGGSWKeyPrepared, GGLWEToGGSWKeyPreparedFactory, GGSWInfos, GLWEAutomorphismKeyLayout,
|
||||
GLWEAutomorphismKeyPreparedFactory, GLWEInfos, GLWETensorKeyLayout, GLWETensorKeyPreparedFactory, LWEInfos,
|
||||
prepared::GLWEAutomorphismKeyPrepared,
|
||||
GGLWEInfos, GGLWEToGGSWKeyPrepared, GGLWEToGGSWKeyPreparedFactory, GGSWInfos, GLWEAutomorphismKeyHelper,
|
||||
GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWEInfos, GLWETensorKeyLayout,
|
||||
GLWETensorKeyPreparedFactory, LWEInfos, prepared::GLWEAutomorphismKeyPrepared,
|
||||
},
|
||||
trace_galois_elements,
|
||||
};
|
||||
@@ -105,8 +105,20 @@ where
|
||||
|
||||
pub struct CircuitBootstrappingKeyPrepared<D: Data, BRA: BlindRotationAlgo, B: Backend> {
|
||||
pub(crate) brk: BlindRotationKeyPrepared<D, BRA, B>,
|
||||
pub(crate) tsk: GGLWEToGGSWKeyPrepared<Vec<u8>, B>,
|
||||
pub(crate) atk: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
||||
pub(crate) tsk: GGLWEToGGSWKeyPrepared<D, B>,
|
||||
pub(crate) atk: HashMap<i64, GLWEAutomorphismKeyPrepared<D, B>>,
|
||||
}
|
||||
|
||||
impl<D: DataRef, BRA: BlindRotationAlgo, BE: Backend> GLWEAutomorphismKeyHelper<GLWEAutomorphismKeyPrepared<D, BE>, BE>
|
||||
for CircuitBootstrappingKeyPrepared<D, BRA, BE>
|
||||
{
|
||||
fn get_automorphism_key(&self, k: i64) -> Option<&GLWEAutomorphismKeyPrepared<D, BE>> {
|
||||
self.atk.get_automorphism_key(k)
|
||||
}
|
||||
|
||||
fn automorphism_key_infos(&self) -> poulpy_core::layouts::GGLWELayout {
|
||||
self.atk.automorphism_key_infos()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyPrepared<D, BRA, B> {
|
||||
|
||||
Reference in New Issue
Block a user