This commit is contained in:
Pro7ech
2025-10-13 12:14:11 +02:00
parent 662e533eac
commit cf377ff243
94 changed files with 1892 additions and 1235 deletions

View File

@@ -3,8 +3,8 @@ use std::hint::black_box;
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use poulpy_backend::{FFT64Avx, FFT64Ref, FFT64Spqlios};
use poulpy_core::layouts::{
Dsize, GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWESecret, LWECiphertext,
LWECiphertextLayout, LWESecret, prepared::PrepareAlloc,
AutomorphismKeyLayout, Dsize, GGSW, GGSWCiphertextLayout, GLWESecret, LWECiphertext, LWECiphertextLayout, LWESecret,
TensorKeyLayout, prepared::PrepareAlloc,
};
use poulpy_hal::{
api::{
@@ -218,7 +218,7 @@ where
scratch.borrow(),
);
let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&params.ggsw_infos);
let mut res: GGSW<Vec<u8>> = GGSW::alloc(&params.ggsw_infos);
let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> = cbt_key.prepare_alloc(&module, scratch.borrow());
move || {
@@ -261,7 +261,7 @@ where
dnum: 3_u32.into(),
rank: 2_u32.into(),
},
layout_atk: GGLWEAutomorphismKeyLayout {
layout_atk: AutomorphismKeyLayout {
n: 1024_u32.into(),
base2k: 13_u32.into(),
k: 52_u32.into(),
@@ -269,7 +269,7 @@ where
dsize: Dsize(1),
rank: 2_u32.into(),
},
layout_tsk: GGLWETensorKeyLayout {
layout_tsk: TensorKeyLayout {
n: 1024_u32.into(),
base2k: 13_u32.into(),
k: 52_u32.into(),

View File

@@ -1,9 +1,9 @@
use poulpy_core::{
GLWEOperations,
layouts::{
GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWECiphertext,
GLWECiphertextLayout, GLWEPlaintext, GLWESecret, LWECiphertext, LWECiphertextLayout, LWEInfos, LWEPlaintext, LWESecret,
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
AutomorphismKeyLayout, GGSW, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
LWECiphertext, LWECiphertextLayout, LWEInfos, LWEPlaintext, LWESecret, TensorKeyLayout,
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
},
};
use std::time::Instant;
@@ -89,7 +89,7 @@ fn main() {
dnum: rows_brk.into(),
rank: rank.into(),
},
layout_atk: GGLWEAutomorphismKeyLayout {
layout_atk: AutomorphismKeyLayout {
n: n_glwe.into(),
base2k: base2k.into(),
k: k_trace.into(),
@@ -97,7 +97,7 @@ fn main() {
dsize: 1_u32.into(),
rank: rank.into(),
},
layout_tsk: GGLWETensorKeyLayout {
layout_tsk: TensorKeyLayout {
n: n_glwe.into(),
base2k: base2k.into(),
k: k_tsk.into(),
@@ -187,7 +187,7 @@ fn main() {
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
// Output GGSW
let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos);
let mut res: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos);
// Circuit bootstrapping key prepared (opaque backend dependant write only struct)
let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, CGGI, BackendImpl> =
@@ -249,7 +249,7 @@ fn main() {
);
// Prepare GGSW output of circuit bootstrapping (opaque backend dependant write only struct)
let res_prepared: GGSWCiphertextPrepared<Vec<u8>, BackendImpl> = res.prepare_alloc(&module, scratch.borrow());
let res_prepared: GGSWPrepared<Vec<u8>, BackendImpl> = res.prepare_alloc(&module, scratch.borrow());
// Apply GLWE x GGSW
ct_glwe.external_product_inplace(&module, &res_prepared, scratch.borrow());

View File

@@ -1,12 +1,10 @@
use std::marker::PhantomData;
use poulpy_core::layouts::{
Base2K, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWCiphertextPrepared,
};
use poulpy_core::layouts::{Base2K, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared};
#[cfg(test)]
use poulpy_core::{
TakeGGSW,
layouts::{GGSWCiphertext, prepared::GLWESecretPrepared},
layouts::{GGSW, prepared::GLWESecretPrepared},
};
use poulpy_hal::{
api::VmpPMatAlloc,
@@ -29,7 +27,7 @@ use crate::tfhe::bdd_arithmetic::{FheUintBlocks, FheUintPrepare, ToBits, Unsigne
#[cfg(test)]
pub(crate) struct FheUintBlocksPrepDebug<D: Data, T: UnsignedInteger> {
pub(crate) blocks: Vec<GGSWCiphertext<D>>,
pub(crate) blocks: Vec<GGSW<D>>,
pub(crate) _base: u8,
pub(crate) _phantom: PhantomData<T>,
}
@@ -62,7 +60,7 @@ impl<T: UnsignedInteger> FheUintBlocksPrepDebug<Vec<u8>, T> {
) -> Self {
Self {
blocks: (0..T::WORD_SIZE)
.map(|_| GGSWCiphertext::alloc_with(module.n().into(), base2k, k, rank, dnum, dsize))
.map(|_| GGSW::alloc_with(module.n().into(), base2k, k, rank, dnum, dsize))
.collect(),
_base: 1,
_phantom: PhantomData,
@@ -72,7 +70,7 @@ impl<T: UnsignedInteger> FheUintBlocksPrepDebug<Vec<u8>, T> {
/// A prepared FHE ciphertext encrypting the bits of an [UnsignedInteger].
pub struct FheUintBlocksPrep<D: Data, B: Backend, T: UnsignedInteger> {
pub(crate) blocks: Vec<GGSWCiphertextPrepared<D, B>>,
pub(crate) blocks: Vec<GGSWPrepared<D, B>>,
pub(crate) _base: u8,
pub(crate) _phantom: PhantomData<T>,
}
@@ -103,7 +101,7 @@ where
{
Self {
blocks: (0..T::WORD_SIZE)
.map(|_| GGSWCiphertextPrepared::alloc_with(module, base2k, k, dnum, dsize, rank))
.map(|_| GGSWPrepared::alloc_with(module, base2k, k, dnum, dsize, rank))
.collect(),
_base: 1,
_phantom: PhantomData,

View File

@@ -3,7 +3,7 @@ use poulpy_core::{
GLWEOperations, TakeGLWECtSlice, TakeGLWEPt, glwe_packing,
layouts::{
GLWECiphertext, GLWEInfos, GLWEPlaintextLayout, LWEInfos, TorusPrecision,
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared},
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared},
},
};
use poulpy_hal::{
@@ -32,7 +32,7 @@ impl<D: DataMut, T: UnsignedInteger> FheUintWord<D, T> {
&mut self,
module: &Module<BE>,
mut tmp_res: Vec<GLWECiphertext<&mut [u8]>>,
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<ATK, BE>>,
auto_keys: &HashMap<i64, AutomorphismKeyPrepared<ATK, BE>>,
scratch: &mut Scratch<BE>,
) where
ATK: DataRef,

View File

@@ -3,7 +3,7 @@ use poulpy_core::{
GLWEExternalProductInplace, GLWEOperations, TakeGLWECtSlice,
layouts::{
GLWECiphertext, GLWECiphertextToMut, LWEInfos,
prepared::{GGSWCiphertextPrepared, GGSWCiphertextPreparedToRef},
prepared::{GGSWCiphertextPreparedToRef, GGSWPrepared},
},
};
use poulpy_hal::{
@@ -164,7 +164,7 @@ pub trait Cmux<BE: Backend> {
out: &mut GLWECiphertext<O>,
t: &GLWECiphertext<T>,
f: &GLWECiphertext<F>,
s: &GGSWCiphertextPrepared<S, BE>,
s: &GGSWPrepared<S, BE>,
scratch: &mut Scratch<BE>,
) where
O: DataMut,
@@ -182,7 +182,7 @@ where
out: &mut GLWECiphertext<O>,
t: &GLWECiphertext<T>,
f: &GLWECiphertext<F>,
s: &GGSWCiphertextPrepared<S, BE>,
s: &GGSWPrepared<S, BE>,
scratch: &mut Scratch<BE>,
) where
O: DataMut,

View File

@@ -11,7 +11,7 @@ use crate::tfhe::{
use poulpy_core::{
TakeGGSW, TakeGLWECt,
layouts::{
GLWESecret, GLWEToLWEKey, GLWEToLWEKeyLayout, LWECiphertext, LWESecret,
GLWESecret, GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, LWECiphertext, LWESecret,
prepared::{GLWEToLWESwitchingKeyPrepared, Prepare, PrepareAlloc},
},
};
@@ -56,7 +56,7 @@ where
BRA: BlindRotationAlgo,
{
cbt: CircuitBootstrappingKey<CBT, BRA>,
ks: GLWEToLWEKey<LWE>,
ks: GLWEToLWESwitchingKey<LWE>,
}
impl<BRA: BlindRotationAlgo> BDDKey<Vec<u8>, Vec<u8>, BRA> {
@@ -98,7 +98,7 @@ impl<BRA: BlindRotationAlgo> BDDKey<Vec<u8>, Vec<u8>, BRA> {
+ VecZnxAutomorphismInplace<BE>,
Scratch<BE>: TakeVecZnxDft<BE> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeSvpPPol<BE> + TakeVecZnxBig<BE>,
{
let mut ks: GLWEToLWEKey<Vec<u8>> = GLWEToLWEKey::alloc(&infos.ks_infos());
let mut ks: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(&infos.ks_infos());
ks.encrypt_sk(module, sk_lwe, sk_glwe, source_xa, source_xe, scratch);
Self {
@@ -131,7 +131,7 @@ impl<CBT: DataMut, LWE: DataMut, BRA: BlindRotationAlgo, BE: Backend> PrepareAll
for BDDKey<CBT, LWE, BRA>
where
CircuitBootstrappingKey<CBT, BRA>: PrepareAlloc<BE, CircuitBootstrappingKeyPrepared<CBT, BRA, BE>>,
GLWEToLWEKey<LWE>: PrepareAlloc<BE, GLWEToLWESwitchingKeyPrepared<LWE, BE>>,
GLWEToLWESwitchingKey<LWE>: PrepareAlloc<BE, GLWEToLWESwitchingKeyPrepared<LWE, BE>>,
{
fn prepare_alloc(&self, module: &Module<BE>, scratch: &mut Scratch<BE>) -> BDDKeyPrepared<CBT, LWE, BRA, BE> {
BDDKeyPrepared {

View File

@@ -1,7 +1,7 @@
#[cfg(test)]
use poulpy_core::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertextLayout, GLWECiphertextLayout,
GLWEToLWEKeyLayout, Rank, TorusPrecision,
AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GGSWCiphertextLayout, GLWECiphertextLayout, GLWEToLWEKeyLayout, Rank,
TensorKeyLayout, TorusPrecision,
};
#[cfg(test)]
@@ -53,7 +53,7 @@ pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout {
dnum: Dnum(3),
rank: Rank(TEST_RANK),
},
layout_atk: GGLWEAutomorphismKeyLayout {
layout_atk: AutomorphismKeyLayout {
n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(52),
@@ -61,7 +61,7 @@ pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout {
dnum: Dnum(3),
dsize: Dsize(1),
},
layout_tsk: GGLWETensorKeyLayout {
layout_tsk: TensorKeyLayout {
n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(52),

View File

@@ -14,9 +14,9 @@ use std::marker::PhantomData;
use poulpy_core::{
Distribution,
layouts::{
GGSWCiphertext, GGSWInfos, LWESecret,
GGSW, GGSWInfos, LWESecret,
compressed::GGSWCiphertextCompressed,
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared},
prepared::{GGSWPrepared, GLWESecretPrepared},
},
};
@@ -30,9 +30,9 @@ impl BlindRotationKeyAlloc for BlindRotationKey<Vec<u8>, CGGI> {
where
A: BlindRotationKeyInfos,
{
let mut data: Vec<GGSWCiphertext<Vec<u8>>> = Vec::with_capacity(infos.n_lwe().into());
let mut data: Vec<GGSW<Vec<u8>>> = Vec::with_capacity(infos.n_lwe().into());
for _ in 0..infos.n_lwe().as_usize() {
data.push(GGSWCiphertext::alloc(infos));
data.push(GGSW::alloc(infos));
}
Self {
@@ -49,7 +49,7 @@ impl BlindRotationKey<Vec<u8>, CGGI> {
A: GGSWInfos,
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
{
GGSWCiphertext::encrypt_sk_scratch_space(module, infos)
GGSW::encrypt_sk_scratch_space(module, infos)
}
}
@@ -121,8 +121,8 @@ where
where
A: BlindRotationKeyInfos,
{
let mut data: Vec<GGSWCiphertextPrepared<Vec<u8>, B>> = Vec::with_capacity(infos.n_lwe().into());
(0..infos.n_lwe().as_usize()).for_each(|_| data.push(GGSWCiphertextPrepared::alloc(module, infos)));
let mut data: Vec<GGSWPrepared<Vec<u8>, B>> = Vec::with_capacity(infos.n_lwe().into());
(0..infos.n_lwe().as_usize()).for_each(|_| data.push(GGSWPrepared::alloc(module, infos)));
Self {
data,
dist: Distribution::NONE,

View File

@@ -8,7 +8,7 @@ use std::{fmt, marker::PhantomData};
use poulpy_core::{
Distribution,
layouts::{
Base2K, Degree, Dnum, Dsize, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, TorusPrecision,
Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, TorusPrecision,
prepared::GLWESecretPrepared,
},
};
@@ -98,7 +98,7 @@ pub trait BlindRotationKeyEncryptSk<B: Backend> {
#[derive(Clone)]
pub struct BlindRotationKey<D: Data, BRT: BlindRotationAlgo> {
pub(crate) keys: Vec<GGSWCiphertext<D>>,
pub(crate) keys: Vec<GGSW<D>>,
pub(crate) dist: Distribution,
pub(crate) _phantom: PhantomData<BRT>,
}

View File

@@ -9,7 +9,7 @@ use poulpy_core::{
Distribution,
layouts::{
Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
prepared::{GGSWCiphertextPrepared, Prepare, PrepareAlloc},
prepared::{GGSWPrepared, Prepare, PrepareAlloc},
},
};
@@ -23,7 +23,7 @@ pub trait BlindRotationKeyPreparedAlloc<B: Backend> {
#[derive(PartialEq, Eq)]
pub struct BlindRotationKeyPrepared<D: Data, BRT: BlindRotationAlgo, B: Backend> {
pub(crate) data: Vec<GGSWCiphertextPrepared<D, B>>,
pub(crate) data: Vec<GGSWPrepared<D, B>>,
pub(crate) dist: Distribution,
pub(crate) x_pow_a: Option<Vec<SvpPPol<Vec<u8>, B>>>,
pub(crate) _phantom: PhantomData<BRT>,

View File

@@ -20,7 +20,7 @@ use poulpy_core::{
};
use poulpy_core::glwe_packing;
use poulpy_core::layouts::{GGSWCiphertext, GLWECiphertext, LWECiphertext, prepared::GGLWEAutomorphismKeyPrepared};
use poulpy_core::layouts::{GGSW, GLWECiphertext, LWECiphertext, prepared::AutomorphismKeyPrepared};
use crate::tfhe::{
blind_rotation::{
@@ -74,7 +74,7 @@ where
fn execute_to_constant<DM: DataMut, DR: DataRef>(
&self,
module: &Module<B>,
res: &mut GGSWCiphertext<DM>,
res: &mut GGSW<DM>,
lwe: &LWECiphertext<DR>,
log_domain: usize,
extension_factor: usize,
@@ -97,7 +97,7 @@ where
&self,
module: &Module<B>,
log_gap_out: usize,
res: &mut GGSWCiphertext<DM>,
res: &mut GGSW<DM>,
lwe: &LWECiphertext<DR>,
log_domain: usize,
extension_factor: usize,
@@ -122,7 +122,7 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>(
to_exponent: bool,
module: &Module<B>,
log_gap_out: usize,
res: &mut GGSWCiphertext<DRes>,
res: &mut GGSW<DRes>,
lwe: &LWECiphertext<DLwe>,
log_domain: usize,
extension_factor: usize,
@@ -268,7 +268,7 @@ fn post_process<DataRes, DataA, B: Backend>(
log_gap_in: usize,
log_gap_out: usize,
log_domain: usize,
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
auto_keys: &HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>>,
scratch: &mut Scratch<B>,
) where
DataRes: DataMut,

View File

@@ -1,7 +1,7 @@
use poulpy_core::layouts::{
GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GGLWEInfos, GGLWETensorKey, GGLWETensorKeyLayout, GGSWInfos,
GLWECiphertext, GLWEInfos, GLWESecret, LWEInfos, LWESecret,
prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc},
AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GGSWInfos, GLWECiphertext, GLWEInfos, GLWESecret, LWEInfos, LWESecret,
TensorKey, TensorKeyLayout,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc, TensorKeyPrepared},
};
use std::collections::HashMap;
@@ -24,19 +24,19 @@ use crate::tfhe::blind_rotation::{
pub trait CircuitBootstrappingKeyInfos {
fn brk_infos(&self) -> BlindRotationKeyLayout;
fn atk_infos(&self) -> GGLWEAutomorphismKeyLayout;
fn tsk_infos(&self) -> GGLWETensorKeyLayout;
fn atk_infos(&self) -> AutomorphismKeyLayout;
fn tsk_infos(&self) -> TensorKeyLayout;
}
#[derive(Debug, Clone, Copy)]
pub struct CircuitBootstrappingKeyLayout {
pub layout_brk: BlindRotationKeyLayout,
pub layout_atk: GGLWEAutomorphismKeyLayout,
pub layout_tsk: GGLWETensorKeyLayout,
pub layout_atk: AutomorphismKeyLayout,
pub layout_tsk: TensorKeyLayout,
}
impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout {
fn atk_infos(&self) -> GGLWEAutomorphismKeyLayout {
fn atk_infos(&self) -> AutomorphismKeyLayout {
self.layout_atk
}
@@ -44,7 +44,7 @@ impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout {
self.layout_brk
}
fn tsk_infos(&self) -> GGLWETensorKeyLayout {
fn tsk_infos(&self) -> TensorKeyLayout {
self.layout_tsk
}
}
@@ -68,8 +68,8 @@ pub trait CircuitBootstrappingKeyEncryptSk<B: Backend> {
pub struct CircuitBootstrappingKey<D: Data, BRA: BlindRotationAlgo> {
pub(crate) brk: BlindRotationKey<D, BRA>,
pub(crate) tsk: GGLWETensorKey<Vec<u8>>,
pub(crate) atk: HashMap<i64, GGLWEAutomorphismKey<Vec<u8>>>,
pub(crate) tsk: TensorKey<Vec<u8>>,
pub(crate) atk: HashMap<i64, AutomorphismKey<Vec<u8>>>,
}
impl<BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyEncryptSk<B> for CircuitBootstrappingKey<Vec<u8>, BRA>
@@ -117,14 +117,14 @@ where
assert_eq!(sk_glwe.n(), cbt_infos.atk_infos().n());
assert_eq!(sk_glwe.n(), cbt_infos.tsk_infos().n());
let atk_infos: GGLWEAutomorphismKeyLayout = cbt_infos.atk_infos();
let atk_infos: AutomorphismKeyLayout = cbt_infos.atk_infos();
let brk_infos: BlindRotationKeyLayout = cbt_infos.brk_infos();
let trk_infos: GGLWETensorKeyLayout = cbt_infos.tsk_infos();
let trk_infos: TensorKeyLayout = cbt_infos.tsk_infos();
let mut auto_keys: HashMap<i64, GGLWEAutomorphismKey<Vec<u8>>> = HashMap::new();
let mut auto_keys: HashMap<i64, AutomorphismKey<Vec<u8>>> = HashMap::new();
let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(module);
gal_els.iter().for_each(|gal_el| {
let mut key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&atk_infos);
let mut key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&atk_infos);
key.encrypt_sk(module, *gal_el, sk_glwe, source_xa, source_xe, scratch);
auto_keys.insert(*gal_el, key);
});
@@ -141,7 +141,7 @@ where
scratch,
);
let mut tsk: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&trk_infos);
let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc(&trk_infos);
tsk.encrypt_sk(module, sk_glwe, source_xa, source_xe, scratch);
Self {
@@ -154,14 +154,14 @@ where
pub struct CircuitBootstrappingKeyPrepared<D: Data, BRA: BlindRotationAlgo, B: Backend> {
pub(crate) brk: BlindRotationKeyPrepared<D, BRA, B>,
pub(crate) tsk: GGLWETensorKeyPrepared<Vec<u8>, B>,
pub(crate) atk: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
pub(crate) tsk: TensorKeyPrepared<Vec<u8>, B>,
pub(crate) atk: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>>,
}
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyPrepared<D, BRA, B> {
fn atk_infos(&self) -> GGLWEAutomorphismKeyLayout {
fn atk_infos(&self) -> AutomorphismKeyLayout {
let (_, atk) = self.atk.iter().next().expect("atk is empty");
GGLWEAutomorphismKeyLayout {
AutomorphismKeyLayout {
n: atk.n(),
base2k: atk.base2k(),
k: atk.k(),
@@ -182,8 +182,8 @@ impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfo
}
}
fn tsk_infos(&self) -> GGLWETensorKeyLayout {
GGLWETensorKeyLayout {
fn tsk_infos(&self) -> TensorKeyLayout {
TensorKeyLayout {
n: self.tsk.n(),
base2k: self.tsk.base2k(),
k: self.tsk.k(),
@@ -199,13 +199,13 @@ impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> PrepareAlloc<B, CircuitBoot
where
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
BlindRotationKey<D, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
GGLWETensorKey<D>: PrepareAlloc<B, GGLWETensorKeyPrepared<Vec<u8>, B>>,
GGLWEAutomorphismKey<D>: PrepareAlloc<B, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
TensorKey<D>: PrepareAlloc<B, TensorKeyPrepared<Vec<u8>, B>>,
AutomorphismKey<D>: PrepareAlloc<B, AutomorphismKeyPrepared<Vec<u8>, B>>,
{
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> {
let brk: BlindRotationKeyPrepared<Vec<u8>, BRA, B> = self.brk.prepare_alloc(module, scratch);
let tsk: GGLWETensorKeyPrepared<Vec<u8>, B> = self.tsk.prepare_alloc(module, scratch);
let mut atk: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new();
let tsk: TensorKeyPrepared<Vec<u8>, B> = self.tsk.prepare_alloc(module, scratch);
let mut atk: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new();
for (key, value) in &self.atk {
atk.insert(*key, value.prepare_alloc(module, scratch));
}

View File

@@ -5,7 +5,7 @@ pub mod tests;
pub use circuit::*;
pub use key::*;
use poulpy_core::layouts::{GGSWCiphertext, LWECiphertext};
use poulpy_core::layouts::{GGSW, LWECiphertext};
use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch};
@@ -13,7 +13,7 @@ pub trait CirtuitBootstrappingExecute<B: Backend> {
fn execute_to_constant<DM: DataMut, DR: DataRef>(
&self,
module: &Module<B>,
res: &mut GGSWCiphertext<DM>,
res: &mut GGSW<DM>,
lwe: &LWECiphertext<DR>,
log_domain: usize,
extension_factor: usize,
@@ -25,7 +25,7 @@ pub trait CirtuitBootstrappingExecute<B: Backend> {
&self,
module: &Module<B>,
log_gap_out: usize,
res: &mut GGSWCiphertext<DM>,
res: &mut GGSW<DM>,
lwe: &LWECiphertext<DR>,
log_domain: usize,
extension_factor: usize,

View File

@@ -32,12 +32,12 @@ use crate::tfhe::{
};
use poulpy_core::layouts::{
Dsize, GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertextLayout, LWECiphertextLayout, prepared::PrepareAlloc,
AutomorphismKeyLayout, Dsize, GGSWCiphertextLayout, LWECiphertextLayout, TensorKeyLayout, prepared::PrepareAlloc,
};
use poulpy_core::layouts::{
GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret,
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared},
GGSW, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret,
prepared::{GGSWPrepared, GLWESecretPrepared},
};
pub fn test_circuit_bootstrapping_to_exponent<B, BRA: BlindRotationAlgo>(module: &Module<B>)
@@ -143,7 +143,7 @@ where
dnum: rows_brk.into(),
rank: rank.into(),
},
layout_atk: GGLWEAutomorphismKeyLayout {
layout_atk: AutomorphismKeyLayout {
n: n_glwe.into(),
base2k: base2k.into(),
k: k_atk.into(),
@@ -151,7 +151,7 @@ where
rank: rank.into(),
dsize: Dsize(1),
},
layout_tsk: GGLWETensorKeyLayout {
layout_tsk: TensorKeyLayout {
n: n_glwe.into(),
base2k: base2k.into(),
k: k_tsk.into(),
@@ -206,7 +206,7 @@ where
);
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos);
let mut res: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos);
let log_gap_out = 1;
@@ -249,7 +249,7 @@ where
scratch.borrow(),
);
let res_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow());
let res_prepared: GGSWPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow());
ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());
@@ -365,7 +365,7 @@ where
dnum: rows_brk.into(),
rank: rank.into(),
},
layout_atk: GGLWEAutomorphismKeyLayout {
layout_atk: AutomorphismKeyLayout {
n: n_glwe.into(),
base2k: base2k.into(),
k: k_atk.into(),
@@ -373,7 +373,7 @@ where
rank: rank.into(),
dsize: Dsize(1),
},
layout_tsk: GGLWETensorKeyLayout {
layout_tsk: TensorKeyLayout {
n: n_glwe.into(),
base2k: base2k.into(),
k: k_tsk.into(),
@@ -428,7 +428,7 @@ where
);
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos);
let mut res: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos);
let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> = cbt_key.prepare_alloc(module, scratch.borrow());
@@ -462,7 +462,7 @@ where
scratch.borrow(),
);
let res_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow());
let res_prepared: GGSWPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow());
ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());