mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
compiling CBT but failing tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use poulpy_core::layouts::{
|
use poulpy_core::layouts::{
|
||||||
AutomorphismKey, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey,
|
Base2K, Degree, Dnum, Dsize, GLWE, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWELayout, GLWESecret, GLWESwitchingKey,
|
||||||
GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, TorusPrecision,
|
GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, TorusPrecision,
|
||||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
@@ -39,7 +39,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
|||||||
|
|
||||||
let dnum: Dnum = p.k_ct_in.div_ceil(p.base2k.0 * dsize.0).into();
|
let dnum: Dnum = p.k_ct_in.div_ceil(p.base2k.0 * dsize.0).into();
|
||||||
|
|
||||||
let gglwe_atk_layout: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let gglwe_atk_layout: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n,
|
n,
|
||||||
base2k,
|
base2k,
|
||||||
k: k_gglwe,
|
k: k_gglwe,
|
||||||
@@ -62,7 +62,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
|||||||
rank,
|
rank,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ksk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&gglwe_atk_layout);
|
let mut ksk: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&gglwe_atk_layout);
|
||||||
let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_in_layout);
|
let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_in_layout);
|
||||||
let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout);
|
let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout);
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ use crate::{
|
|||||||
ScratchTakeCore,
|
ScratchTakeCore,
|
||||||
automorphism::glwe_ct::GLWEAutomorphism,
|
automorphism::glwe_ct::GLWEAutomorphism,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWE, GetGaloisElement, SetGaloisElement,
|
GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWE, GLWEAutomorphismKey, GetGaloisElement,
|
||||||
|
SetGaloisElement,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl AutomorphismKey<Vec<u8>> {
|
impl GLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn automorphism_tmp_bytes<R, A, K, M, BE: Backend>(module: &M, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
pub fn automorphism_tmp_bytes<R, A, K, M, BE: Backend>(module: &M, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
||||||
where
|
where
|
||||||
R: GGLWEInfos,
|
R: GGLWEInfos,
|
||||||
@@ -19,11 +20,11 @@ impl AutomorphismKey<Vec<u8>> {
|
|||||||
K: GGLWEInfos,
|
K: GGLWEInfos,
|
||||||
M: GLWEAutomorphismKeyAutomorphism<BE>,
|
M: GLWEAutomorphismKeyAutomorphism<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_automorphism_tmp_bytes(res_infos, a_infos, key_infos)
|
module.glwe_automorphism_key_automorphism_tmp_bytes(res_infos, a_infos, key_infos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DataSelf: DataMut> AutomorphismKey<DataSelf> {
|
impl<DataSelf: DataMut> GLWEAutomorphismKey<DataSelf> {
|
||||||
pub fn automorphism<A, K, M, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
pub fn automorphism<A, K, M, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
|
A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
|
||||||
@@ -31,7 +32,7 @@ impl<DataSelf: DataMut> AutomorphismKey<DataSelf> {
|
|||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
M: GLWEAutomorphismKeyAutomorphism<BE>,
|
M: GLWEAutomorphismKeyAutomorphism<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_automorphism(self, a, key, scratch);
|
module.glwe_automorphism_key_automorphism(self, a, key, scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn automorphism_inplace<K, M, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>)
|
pub fn automorphism_inplace<K, M, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>)
|
||||||
@@ -40,7 +41,7 @@ impl<DataSelf: DataMut> AutomorphismKey<DataSelf> {
|
|||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
M: GLWEAutomorphismKeyAutomorphism<BE>,
|
M: GLWEAutomorphismKeyAutomorphism<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_automorphism_inplace(self, key, scratch);
|
module.glwe_automorphism_key_automorphism_inplace(self, key, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ pub trait GLWEAutomorphismKeyAutomorphism<BE: Backend>
|
|||||||
where
|
where
|
||||||
Self: GaloisElement + GLWEAutomorphism<BE> + VecZnxAutomorphism,
|
Self: GaloisElement + GLWEAutomorphism<BE> + VecZnxAutomorphism,
|
||||||
{
|
{
|
||||||
fn automorphism_key_automorphism_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
fn glwe_automorphism_key_automorphism_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
||||||
where
|
where
|
||||||
R: GGLWEInfos,
|
R: GGLWEInfos,
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
@@ -62,7 +63,7 @@ where
|
|||||||
self.glwe_keyswitch_tmp_bytes(res_infos, a_infos, key_infos)
|
self.glwe_keyswitch_tmp_bytes(res_infos, a_infos, key_infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn automorphism_key_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
fn glwe_automorphism_key_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
R: GGLWEToMut + SetGaloisElement + GGLWEInfos,
|
R: GGLWEToMut + SetGaloisElement + GGLWEInfos,
|
||||||
A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
|
A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
|
||||||
@@ -118,7 +119,7 @@ where
|
|||||||
res.set_p((p * key.p()) % (self.cyclotomic_order() as i64));
|
res.set_p((p * key.p()) % (self.cyclotomic_order() as i64));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn automorphism_key_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
|
fn glwe_automorphism_key_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
R: GGLWEToMut + SetGaloisElement + GetGaloisElement + GGLWEInfos,
|
R: GGLWEToMut + SetGaloisElement + GetGaloisElement + GGLWEInfos,
|
||||||
K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
|
K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
automorphism::glwe_ct::GLWEAutomorphism,
|
automorphism::glwe_ct::GLWEAutomorphism,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GetGaloisElement,
|
GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GetGaloisElement,
|
||||||
prepared::{TensorKeyPrepared, TensorKeyPreparedToRef},
|
prepared::{GLWETensorKeyPrepared, GLWETensorKeyPreparedToRef},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ impl<D: DataMut> GGSW<D> {
|
|||||||
where
|
where
|
||||||
A: GGSWToRef,
|
A: GGSWToRef,
|
||||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
M: GGSWAutomorphism<BE>,
|
M: GGSWAutomorphism<BE>,
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ impl<D: DataMut> GGSW<D> {
|
|||||||
pub fn automorphism_inplace<K, T, M, BE: Backend>(&mut self, module: &M, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
|
pub fn automorphism_inplace<K, T, M, BE: Backend>(&mut self, module: &M, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
M: GGSWAutomorphism<BE>,
|
M: GGSWAutomorphism<BE>,
|
||||||
{
|
{
|
||||||
@@ -79,12 +79,12 @@ where
|
|||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
A: GGSWToRef,
|
A: GGSWToRef,
|
||||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<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();
|
||||||
let a: &GGSW<&[u8]> = &a.to_ref();
|
let a: &GGSW<&[u8]> = &a.to_ref();
|
||||||
let tsk: &TensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
let tsk: &GLWETensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
||||||
|
|
||||||
assert_eq!(res.dsize(), a.dsize());
|
assert_eq!(res.dsize(), a.dsize());
|
||||||
assert!(res.dnum() <= a.dnum());
|
assert!(res.dnum() <= a.dnum());
|
||||||
@@ -104,11 +104,11 @@ where
|
|||||||
where
|
where
|
||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<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();
|
||||||
let tsk: &TensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
let tsk: &GLWETensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
||||||
|
|
||||||
// Keyswitch the j-th row of the col 0
|
// Keyswitch the j-th row of the col 0
|
||||||
for row in 0..res.dnum().as_usize() {
|
for row in 0..res.dnum().as_usize() {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
|
|||||||
module.glwe_automorphism_sub(self, a, key, scratch);
|
module.glwe_automorphism_sub(self, a, key, scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn glwe_automorphism_sub_negate<M, A, K, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
pub fn automorphism_sub_negate<M, A, K, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
M: GLWEAutomorphism<BE>,
|
M: GLWEAutomorphism<BE>,
|
||||||
A: GLWEToRef,
|
A: GLWEToRef,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use crate::{
|
|||||||
GLWECopy, ScratchTakeCore,
|
GLWECopy, ScratchTakeCore,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGLWE, GGLWEInfos, GGLWEToRef, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, LWEInfos,
|
GGLWE, GGLWEInfos, GGLWEToRef, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, LWEInfos,
|
||||||
prepared::{TensorKeyPrepared, TensorKeyPreparedToRef},
|
prepared::{GLWETensorKeyPrepared, GLWETensorKeyPreparedToRef},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ impl<D: DataMut> GGSW<D> {
|
|||||||
where
|
where
|
||||||
M: GGSWFromGGLWE<BE>,
|
M: GGSWFromGGLWE<BE>,
|
||||||
G: GGLWEToRef,
|
G: GGLWEToRef,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
module.ggsw_from_gglwe(self, gglwe, tsk, scratch);
|
module.ggsw_from_gglwe(self, gglwe, tsk, scratch);
|
||||||
@@ -54,12 +54,12 @@ where
|
|||||||
where
|
where
|
||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
A: GGLWEToRef,
|
A: GGLWEToRef,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<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();
|
||||||
let a: &GGLWE<&[u8]> = &a.to_ref();
|
let a: &GGLWE<&[u8]> = &a.to_ref();
|
||||||
let tsk: &TensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
let tsk: &GLWETensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
||||||
|
|
||||||
assert_eq!(res.rank(), a.rank_out());
|
assert_eq!(res.rank(), a.rank_out());
|
||||||
assert_eq!(res.dnum(), a.dnum());
|
assert_eq!(res.dnum(), a.dnum());
|
||||||
@@ -85,7 +85,7 @@ pub trait GGSWFromGGLWE<BE: Backend> {
|
|||||||
where
|
where
|
||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
A: GGLWEToRef,
|
A: GGLWEToRef,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>;
|
Scratch<BE>: ScratchTakeCore<BE>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,11 +158,11 @@ where
|
|||||||
fn ggsw_expand_row<R, T>(&self, res: &mut R, tsk: &T, scratch: &mut Scratch<BE>)
|
fn ggsw_expand_row<R, T>(&self, res: &mut R, tsk: &T, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<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();
|
||||||
let tsk: &TensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
let tsk: &GLWETensorKeyPrepared<&[u8], BE> = &tsk.to_ref();
|
||||||
|
|
||||||
let basek_in: usize = res.base2k().into();
|
let basek_in: usize = res.base2k().into();
|
||||||
let basek_tsk: usize = tsk.base2k().into();
|
let basek_tsk: usize = tsk.base2k().into();
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ impl GLWEAutomorphismKeyCompressed<Vec<u8>> {
|
|||||||
pub fn encrypt_sk_tmp_bytes<M, BE: Backend, A>(module: &M, infos: &A) -> usize
|
pub fn encrypt_sk_tmp_bytes<M, BE: Backend, A>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: AutomorphismKeyCompressedEncryptSk<BE>,
|
M: GLWEAutomorphismKeyCompressedEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_compressed_encrypt_sk_tmp_bytes(infos)
|
module.glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,18 +34,18 @@ impl<DataSelf: DataMut> GLWEAutomorphismKeyCompressed<DataSelf> {
|
|||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
S: GLWESecretToRef + GLWEInfos,
|
S: GLWESecretToRef + GLWEInfos,
|
||||||
M: AutomorphismKeyCompressedEncryptSk<BE>,
|
M: GLWEAutomorphismKeyCompressedEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_compressed_encrypt_sk(self, p, sk, seed_xa, source_xe, scratch);
|
module.glwe_automorphism_key_compressed_encrypt_sk(self, p, sk, seed_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AutomorphismKeyCompressedEncryptSk<BE: Backend> {
|
pub trait GLWEAutomorphismKeyCompressedEncryptSk<BE: Backend> {
|
||||||
fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
|
|
||||||
fn automorphism_key_compressed_encrypt_sk<R, S>(
|
fn glwe_automorphism_key_compressed_encrypt_sk<R, S>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
p: i64,
|
p: i64,
|
||||||
@@ -58,12 +58,12 @@ pub trait AutomorphismKeyCompressedEncryptSk<BE: Backend> {
|
|||||||
S: GLWESecretToRef + GLWEInfos;
|
S: GLWESecretToRef + GLWEInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWEAutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: ModuleN + GaloisElement + VecZnxAutomorphism + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedFactory<BE>,
|
Self: ModuleN + GaloisElement + VecZnxAutomorphism + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedFactory<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
@@ -73,7 +73,7 @@ where
|
|||||||
+ GLWESecretPrepared::bytes_of_from_infos(self, infos)
|
+ GLWESecretPrepared::bytes_of_from_infos(self, infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn automorphism_key_compressed_encrypt_sk<R, S>(
|
fn glwe_automorphism_key_compressed_encrypt_sk<R, S>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
p: i64,
|
p: i64,
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
GGLWECompressedEncryptSk, GetDistribution, ScratchTakeCore, TensorKeyEncryptSk,
|
GGLWECompressedEncryptSk, GLWETensorKeyEncryptSk, GetDistribution, ScratchTakeCore,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedFactory, GLWESecretToRef, LWEInfos, Rank,
|
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedFactory, GLWESecretToRef,
|
||||||
TensorKeyCompressedAtMut, compressed::GLWETensorKeyCompressed,
|
GLWETensorKeyCompressedAtMut, LWEInfos, Rank, compressed::GLWETensorKeyCompressed,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ impl GLWETensorKeyCompressed<Vec<u8>> {
|
|||||||
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: GGLWETensorKeyCompressedEncryptSk<BE>,
|
M: GLWETensorKeyCompressedEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.tensor_key_compressed_encrypt_sk_tmp_bytes(infos)
|
module.glwe_tensor_key_compressed_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,18 +35,18 @@ impl<DataSelf: DataMut> GLWETensorKeyCompressed<DataSelf> {
|
|||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
S: GLWESecretToRef + GetDistribution,
|
S: GLWESecretToRef + GetDistribution,
|
||||||
M: GGLWETensorKeyCompressedEncryptSk<BE>,
|
M: GLWETensorKeyCompressedEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.tensor_key_compressed_encrypt_sk(self, sk, seed_xa, source_xe, scratch);
|
module.glwe_tensor_key_compressed_encrypt_sk(self, sk, seed_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
pub trait GLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
||||||
fn tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
|
|
||||||
fn tensor_key_compressed_encrypt_sk<R, S, D>(
|
fn glwe_tensor_key_compressed_encrypt_sk<R, S, D>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
sk: &S,
|
sk: &S,
|
||||||
@@ -55,15 +55,15 @@ pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
|||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
D: DataMut,
|
D: DataMut,
|
||||||
R: TensorKeyCompressedAtMut<D> + GGLWEInfos,
|
R: GLWETensorKeyCompressedAtMut<D> + GGLWEInfos,
|
||||||
S: GLWESecretToRef + GetDistribution;
|
S: GLWESecretToRef + GetDistribution;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> GGLWETensorKeyCompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWETensorKeyCompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: ModuleN
|
Self: ModuleN
|
||||||
+ GGLWECompressedEncryptSk<BE>
|
+ GGLWECompressedEncryptSk<BE>
|
||||||
+ TensorKeyEncryptSk<BE>
|
+ GLWETensorKeyEncryptSk<BE>
|
||||||
+ VecZnxDftApply<BE>
|
+ VecZnxDftApply<BE>
|
||||||
+ SvpApplyDftToDft<BE>
|
+ SvpApplyDftToDft<BE>
|
||||||
+ VecZnxIdftApplyTmpA<BE>
|
+ VecZnxIdftApplyTmpA<BE>
|
||||||
@@ -75,7 +75,7 @@ where
|
|||||||
+ GLWESecretPreparedFactory<BE>,
|
+ GLWESecretPreparedFactory<BE>,
|
||||||
Scratch<BE>: ScratchTakeBasic + ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeBasic + ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
@@ -87,7 +87,7 @@ where
|
|||||||
+ self.gglwe_compressed_encrypt_sk_tmp_bytes(infos)
|
+ self.gglwe_compressed_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tensor_key_compressed_encrypt_sk<R, S, D>(
|
fn glwe_tensor_key_compressed_encrypt_sk<R, S, D>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
sk: &S,
|
sk: &S,
|
||||||
@@ -96,7 +96,7 @@ where
|
|||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
D: DataMut,
|
D: DataMut,
|
||||||
R: GGLWEInfos + TensorKeyCompressedAtMut<D>,
|
R: GGLWEInfos + GLWETensorKeyCompressedAtMut<D>,
|
||||||
S: GLWESecretToRef + GetDistribution,
|
S: GLWESecretToRef + GetDistribution,
|
||||||
{
|
{
|
||||||
let (mut sk_dft_prep, scratch_1) = scratch.take_glwe_secret_prepared(self, res.rank());
|
let (mut sk_dft_prep, scratch_1) = scratch.take_glwe_secret_prepared(self, res.rank());
|
||||||
|
|||||||
@@ -7,30 +7,30 @@ use poulpy_hal::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
GGLWEEncryptSk, ScratchTakeCore,
|
GGLWEEncryptSk, ScratchTakeCore,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESecret, GLWESecretPrepared,
|
GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEAutomorphismKey, GLWEInfos, GLWESecret, GLWESecretPrepared,
|
||||||
GLWESecretPreparedFactory, GLWESecretToRef, LWEInfos, SetGaloisElement,
|
GLWESecretPreparedFactory, GLWESecretToRef, LWEInfos, SetGaloisElement,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl AutomorphismKey<Vec<u8>> {
|
impl GLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: AutomorphismKeyEncryptSk<BE>,
|
M: GLWEAutomorphismKeyEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_encrypt_sk_tmp_bytes(infos)
|
module.glwe_automorphism_key_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encrypt_pk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
pub fn encrypt_pk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: GGLWEAutomorphismKeyEncryptPk<BE>,
|
M: GLWEAutomorphismKeyEncryptPk<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_encrypt_pk_tmp_bytes(infos)
|
module.glwe_automorphism_key_encrypt_pk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DM: DataMut> AutomorphismKey<DM>
|
impl<DM: DataMut> GLWEAutomorphismKey<DM>
|
||||||
where
|
where
|
||||||
Self: GGLWEToRef,
|
Self: GGLWEToRef,
|
||||||
{
|
{
|
||||||
@@ -44,18 +44,18 @@ where
|
|||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
S: GLWESecretToRef,
|
S: GLWESecretToRef,
|
||||||
M: AutomorphismKeyEncryptSk<BE>,
|
M: GLWEAutomorphismKeyEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.automorphism_key_encrypt_sk(self, p, sk, source_xa, source_xe, scratch);
|
module.glwe_automorphism_key_encrypt_sk(self, p, sk, source_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AutomorphismKeyEncryptSk<BE: Backend> {
|
pub trait GLWEAutomorphismKeyEncryptSk<BE: Backend> {
|
||||||
fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
|
|
||||||
fn automorphism_key_encrypt_sk<R, S>(
|
fn glwe_automorphism_key_encrypt_sk<R, S>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
p: i64,
|
p: i64,
|
||||||
@@ -68,12 +68,12 @@ pub trait AutomorphismKeyEncryptSk<BE: Backend> {
|
|||||||
S: GLWESecretToRef;
|
S: GLWESecretToRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWEAutomorphismKeyEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: GGLWEEncryptSk<BE> + VecZnxAutomorphism + GaloisElement + SvpPPolBytesOf + GLWESecretPreparedFactory<BE>,
|
Self: GGLWEEncryptSk<BE> + VecZnxAutomorphism + GaloisElement + SvpPPolBytesOf + GLWESecretPreparedFactory<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,7 @@ where
|
|||||||
.max(GLWESecret::bytes_of_from_infos(infos))
|
.max(GLWESecret::bytes_of_from_infos(infos))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn automorphism_key_encrypt_sk<R, S>(
|
fn glwe_automorphism_key_encrypt_sk<R, S>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
p: i64,
|
p: i64,
|
||||||
@@ -106,10 +106,10 @@ where
|
|||||||
assert_eq!(res.rank_out(), res.rank_in());
|
assert_eq!(res.rank_out(), res.rank_in());
|
||||||
assert_eq!(sk.rank(), res.rank_out());
|
assert_eq!(sk.rank(), res.rank_out());
|
||||||
assert!(
|
assert!(
|
||||||
scratch.available() >= self.automorphism_key_encrypt_sk_tmp_bytes(res),
|
scratch.available() >= self.glwe_automorphism_key_encrypt_sk_tmp_bytes(res),
|
||||||
"scratch.available(): {} < AutomorphismKey::encrypt_sk_tmp_bytes: {:?}",
|
"scratch.available(): {} < AutomorphismKey::encrypt_sk_tmp_bytes: {:?}",
|
||||||
scratch.available(),
|
scratch.available(),
|
||||||
self.automorphism_key_encrypt_sk_tmp_bytes(res)
|
self.glwe_automorphism_key_encrypt_sk_tmp_bytes(res)
|
||||||
);
|
);
|
||||||
|
|
||||||
let (mut sk_out_prepared, scratch_1) = scratch.take_glwe_secret_prepared(self, sk.rank());
|
let (mut sk_out_prepared, scratch_1) = scratch.take_glwe_secret_prepared(self, sk.rank());
|
||||||
@@ -141,18 +141,18 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GGLWEAutomorphismKeyEncryptPk<BE: Backend> {
|
pub trait GLWEAutomorphismKeyEncryptPk<BE: Backend> {
|
||||||
fn automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> GGLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
|
impl<BE: Backend> GLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self:,
|
Self:,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn automorphism_key_encrypt_pk_tmp_bytes<A>(&self, _infos: &A) -> usize
|
fn glwe_automorphism_key_encrypt_pk_tmp_bytes<A>(&self, _infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,22 +10,22 @@ use poulpy_hal::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
GGLWEEncryptSk, GetDistribution, ScratchTakeCore,
|
GGLWEEncryptSk, GetDistribution, ScratchTakeCore,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey, TensorKeyToMut,
|
GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWETensorKey, GLWETensorKeyToMut, LWEInfos, Rank,
|
||||||
prepared::{GLWESecretPrepared, GLWESecretPreparedFactory},
|
prepared::{GLWESecretPrepared, GLWESecretPreparedFactory},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl TensorKey<Vec<u8>> {
|
impl GLWETensorKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: TensorKeyEncryptSk<BE>,
|
M: GLWETensorKeyEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.tensor_key_encrypt_sk_tmp_bytes(infos)
|
module.glwe_tensor_key_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DataSelf: DataMut> TensorKey<DataSelf> {
|
impl<DataSelf: DataMut> GLWETensorKey<DataSelf> {
|
||||||
pub fn encrypt_sk<M, S, BE: Backend>(
|
pub fn encrypt_sk<M, S, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
@@ -34,20 +34,20 @@ impl<DataSelf: DataMut> TensorKey<DataSelf> {
|
|||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
M: TensorKeyEncryptSk<BE>,
|
M: GLWETensorKeyEncryptSk<BE>,
|
||||||
S: GLWESecretToRef + GetDistribution + GLWEInfos,
|
S: GLWESecretToRef + GetDistribution + GLWEInfos,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
module.tensor_key_encrypt_sk(self, sk, source_xa, source_xe, scratch);
|
module.glwe_tensor_key_encrypt_sk(self, sk, source_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyEncryptSk<BE: Backend> {
|
pub trait GLWETensorKeyEncryptSk<BE: Backend> {
|
||||||
fn tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
|
|
||||||
fn tensor_key_encrypt_sk<R, S>(
|
fn glwe_tensor_key_encrypt_sk<R, S>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
sk: &S,
|
sk: &S,
|
||||||
@@ -55,11 +55,11 @@ pub trait TensorKeyEncryptSk<BE: Backend> {
|
|||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
R: TensorKeyToMut,
|
R: GLWETensorKeyToMut,
|
||||||
S: GLWESecretToRef + GetDistribution + GLWEInfos;
|
S: GLWESecretToRef + GetDistribution + GLWEInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> TensorKeyEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWETensorKeyEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: ModuleN
|
Self: ModuleN
|
||||||
+ GGLWEEncryptSk<BE>
|
+ GGLWEEncryptSk<BE>
|
||||||
@@ -72,7 +72,7 @@ where
|
|||||||
+ VecZnxBigNormalize<BE>,
|
+ VecZnxBigNormalize<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
@@ -84,7 +84,7 @@ where
|
|||||||
+ GGLWE::encrypt_sk_tmp_bytes(self, infos)
|
+ GGLWE::encrypt_sk_tmp_bytes(self, infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tensor_key_encrypt_sk<R, S>(
|
fn glwe_tensor_key_encrypt_sk<R, S>(
|
||||||
&self,
|
&self,
|
||||||
res: &mut R,
|
res: &mut R,
|
||||||
sk: &S,
|
sk: &S,
|
||||||
@@ -92,10 +92,10 @@ where
|
|||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
R: TensorKeyToMut,
|
R: GLWETensorKeyToMut,
|
||||||
S: GLWESecretToRef + GetDistribution + GLWEInfos,
|
S: GLWESecretToRef + GetDistribution + GLWEInfos,
|
||||||
{
|
{
|
||||||
let res: &mut TensorKey<&mut [u8]> = &mut res.to_mut();
|
let res: &mut GLWETensorKey<&mut [u8]> = &mut res.to_mut();
|
||||||
|
|
||||||
// let n: RingDegree = sk.n();
|
// let n: RingDegree = sk.n();
|
||||||
let rank: Rank = res.rank_out();
|
let rank: Rank = res.rank_out();
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, ZnxZero};
|
|||||||
use crate::{
|
use crate::{
|
||||||
GLWEExternalProduct, ScratchTakeCore,
|
GLWEExternalProduct, ScratchTakeCore,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GGSWPrepared, GLWEInfos, GLWESwitchingKey,
|
GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GGSWPrepared, GLWEAutomorphismKey, GLWEInfos, GLWESwitchingKey,
|
||||||
prepared::GGSWPreparedToRef,
|
prepared::GGSWPreparedToRef,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl AutomorphismKey<Vec<u8>> {
|
impl GLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>(
|
pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>(
|
||||||
&self,
|
&self,
|
||||||
module: &M,
|
module: &M,
|
||||||
@@ -26,7 +26,7 @@ impl AutomorphismKey<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DataSelf: DataMut> AutomorphismKey<DataSelf> {
|
impl<DataSelf: DataMut> GLWEAutomorphismKey<DataSelf> {
|
||||||
pub fn external_product<A, B, M, BE: Backend>(&mut self, module: &M, a: &A, b: &B, scratch: &mut Scratch<BE>)
|
pub fn external_product<A, B, M, BE: Backend>(&mut self, module: &M, a: &A, b: &B, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
M: GGLWEExternalProduct<BE>,
|
M: GGLWEExternalProduct<BE>,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::ModuleLogN,
|
api::ModuleLogN,
|
||||||
layouts::{Backend, DataMut, GaloisElement, Module, Scratch, VecZnx},
|
layouts::{Backend, DataMut, GaloisElement, Module, Scratch, VecZnx, galois_element},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -70,20 +70,25 @@ impl<BE: Backend> GLWETrace<BE> for Module<BE> where
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn trace_galois_elements(log_n: usize, cyclotomic_order: i64) -> Vec<i64> {
|
||||||
|
(0..log_n)
|
||||||
|
.map(|i| {
|
||||||
|
if i == 0 {
|
||||||
|
-1
|
||||||
|
} else {
|
||||||
|
galois_element(1 << (i - 1), cyclotomic_order)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub trait GLWETrace<BE: Backend>
|
pub trait GLWETrace<BE: Backend>
|
||||||
where
|
where
|
||||||
Self: ModuleLogN + GaloisElement + GLWEAutomorphism<BE> + GLWEShift<BE> + GLWECopy,
|
Self: ModuleLogN + GaloisElement + GLWEAutomorphism<BE> + GLWEShift<BE> + GLWECopy,
|
||||||
{
|
{
|
||||||
fn glwe_trace_galois_elements(&self) -> Vec<i64> {
|
fn glwe_trace_galois_elements(&self) -> Vec<i64> {
|
||||||
(0..self.log_n())
|
trace_galois_elements(self.log_n(), self.cyclotomic_order())
|
||||||
.map(|i| {
|
|
||||||
if i == 0 {
|
|
||||||
-1
|
|
||||||
} else {
|
|
||||||
self.galois_element(1 << (i - 1))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glwe_trace_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
fn glwe_trace_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch};
|
|||||||
use crate::{
|
use crate::{
|
||||||
ScratchTakeCore,
|
ScratchTakeCore,
|
||||||
keyswitching::GLWEKeyswitch,
|
keyswitching::GLWEKeyswitch,
|
||||||
layouts::{AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWESwitchingKey},
|
layouts::{GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWEAutomorphismKey, GLWESwitchingKey},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl AutomorphismKey<Vec<u8>> {
|
impl GLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn keyswitch_tmp_bytes<R, A, K, M, BE: Backend>(module: &M, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
pub fn keyswitch_tmp_bytes<R, A, K, M, BE: Backend>(module: &M, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
|
||||||
where
|
where
|
||||||
R: GGLWEInfos,
|
R: GGLWEInfos,
|
||||||
@@ -18,7 +18,7 @@ impl AutomorphismKey<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DataSelf: DataMut> AutomorphismKey<DataSelf> {
|
impl<DataSelf: DataMut> GLWEAutomorphismKey<DataSelf> {
|
||||||
pub fn keyswitch<A, B, M, BE: Backend>(&mut self, module: &M, a: &A, b: &B, scratch: &mut Scratch<BE>)
|
pub fn keyswitch<A, B, M, BE: Backend>(&mut self, module: &M, a: &A, b: &B, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
A: GGLWEToRef + GGLWEToRef,
|
A: GGLWEToRef + GGLWEToRef,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, VecZnx};
|
|||||||
use crate::{
|
use crate::{
|
||||||
GGSWExpandRows, ScratchTakeCore,
|
GGSWExpandRows, ScratchTakeCore,
|
||||||
keyswitching::GLWEKeyswitch,
|
keyswitching::GLWEKeyswitch,
|
||||||
layouts::{GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, prepared::TensorKeyPreparedToRef},
|
layouts::{GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, prepared::GLWETensorKeyPreparedToRef},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl GGSW<Vec<u8>> {
|
impl GGSW<Vec<u8>> {
|
||||||
@@ -30,7 +30,7 @@ impl<D: DataMut> GGSW<D> {
|
|||||||
where
|
where
|
||||||
A: GGSWToRef,
|
A: GGSWToRef,
|
||||||
K: GGLWEPreparedToRef<BE>,
|
K: GGLWEPreparedToRef<BE>,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
M: GGSWKeyswitch<BE>,
|
M: GGSWKeyswitch<BE>,
|
||||||
{
|
{
|
||||||
@@ -40,7 +40,7 @@ impl<D: DataMut> GGSW<D> {
|
|||||||
pub fn keyswitch_inplace<M, K, T, BE: Backend>(&mut self, module: &M, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
|
pub fn keyswitch_inplace<M, K, T, BE: Backend>(&mut self, module: &M, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
K: GGLWEPreparedToRef<BE>,
|
K: GGLWEPreparedToRef<BE>,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
M: GGSWKeyswitch<BE>,
|
M: GGSWKeyswitch<BE>,
|
||||||
{
|
{
|
||||||
@@ -91,7 +91,7 @@ where
|
|||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
A: GGSWToRef,
|
A: GGSWToRef,
|
||||||
K: GGLWEPreparedToRef<BE>,
|
K: GGLWEPreparedToRef<BE>,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<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();
|
||||||
@@ -113,7 +113,7 @@ where
|
|||||||
where
|
where
|
||||||
R: GGSWToMut,
|
R: GGSWToMut,
|
||||||
K: GGLWEPreparedToRef<BE>,
|
K: GGLWEPreparedToRef<BE>,
|
||||||
T: TensorKeyPreparedToRef<BE>,
|
T: GLWETensorKeyPreparedToRef<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();
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::layouts::{
|
use crate::layouts::{
|
||||||
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut,
|
Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWECompressedToRef,
|
||||||
GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWEDecompress, GLWEInfos, GetGaloisElement, LWEInfos, Rank,
|
GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWEAutomorphismKey, GLWEDecompress, GLWEInfos, GetGaloisElement, LWEInfos, Rank,
|
||||||
SetGaloisElement, TorusPrecision,
|
SetGaloisElement, TorusPrecision,
|
||||||
};
|
};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
@@ -154,7 +154,7 @@ where
|
|||||||
|
|
||||||
impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: GLWEDecompress {}
|
impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: GLWEDecompress {}
|
||||||
|
|
||||||
impl<D: DataMut> AutomorphismKey<D>
|
impl<D: DataMut> GLWEAutomorphismKey<D>
|
||||||
where
|
where
|
||||||
Self: SetGaloisElement,
|
Self: SetGaloisElement,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
|||||||
|
|
||||||
use crate::layouts::{
|
use crate::layouts::{
|
||||||
Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedToMut, GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos,
|
Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedToMut, GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos,
|
||||||
GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToMut, TorusPrecision,
|
GLWEInfos, GLWETensorKey, GLWETensorKeyToMut, LWEInfos, Rank, TorusPrecision,
|
||||||
};
|
};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@@ -149,11 +149,11 @@ impl<D: DataRef> WriterTo for GLWETensorKeyCompressed<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyCompressedAtRef<D: DataRef> {
|
pub trait GLWETensorKeyCompressedAtRef<D: DataRef> {
|
||||||
fn at(&self, i: usize, j: usize) -> &GGLWECompressed<D>;
|
fn at(&self, i: usize, j: usize) -> &GGLWECompressed<D>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> TensorKeyCompressedAtRef<D> for GLWETensorKeyCompressed<D> {
|
impl<D: DataRef> GLWETensorKeyCompressedAtRef<D> for GLWETensorKeyCompressed<D> {
|
||||||
fn at(&self, mut i: usize, mut j: usize) -> &GGLWECompressed<D> {
|
fn at(&self, mut i: usize, mut j: usize) -> &GGLWECompressed<D> {
|
||||||
if i > j {
|
if i > j {
|
||||||
std::mem::swap(&mut i, &mut j);
|
std::mem::swap(&mut i, &mut j);
|
||||||
@@ -163,11 +163,11 @@ impl<D: DataRef> TensorKeyCompressedAtRef<D> for GLWETensorKeyCompressed<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyCompressedAtMut<D: DataMut> {
|
pub trait GLWETensorKeyCompressedAtMut<D: DataMut> {
|
||||||
fn at_mut(&mut self, i: usize, j: usize) -> &mut GGLWECompressed<D>;
|
fn at_mut(&mut self, i: usize, j: usize) -> &mut GGLWECompressed<D>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> TensorKeyCompressedAtMut<D> for GLWETensorKeyCompressed<D> {
|
impl<D: DataMut> GLWETensorKeyCompressedAtMut<D> for GLWETensorKeyCompressed<D> {
|
||||||
fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWECompressed<D> {
|
fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWECompressed<D> {
|
||||||
if i > j {
|
if i > j {
|
||||||
std::mem::swap(&mut i, &mut j);
|
std::mem::swap(&mut i, &mut j);
|
||||||
@@ -177,16 +177,16 @@ impl<D: DataMut> TensorKeyCompressedAtMut<D> for GLWETensorKeyCompressed<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyDecompress
|
pub trait GLWETensorKeyDecompress
|
||||||
where
|
where
|
||||||
Self: GGLWEDecompress,
|
Self: GGLWEDecompress,
|
||||||
{
|
{
|
||||||
fn decompress_tensor_key<R, O>(&self, res: &mut R, other: &O)
|
fn decompress_tensor_key<R, O>(&self, res: &mut R, other: &O)
|
||||||
where
|
where
|
||||||
R: TensorKeyToMut,
|
R: GLWETensorKeyToMut,
|
||||||
O: TensorKeyCompressedToRef,
|
O: GLWETensorKeyCompressedToRef,
|
||||||
{
|
{
|
||||||
let res: &mut TensorKey<&mut [u8]> = &mut res.to_mut();
|
let res: &mut GLWETensorKey<&mut [u8]> = &mut res.to_mut();
|
||||||
let other: &GLWETensorKeyCompressed<&[u8]> = &other.to_ref();
|
let other: &GLWETensorKeyCompressed<&[u8]> = &other.to_ref();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -203,23 +203,23 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TensorKeyDecompress for Module<B> where Self: GGLWEDecompress {}
|
impl<B: Backend> GLWETensorKeyDecompress for Module<B> where Self: GGLWEDecompress {}
|
||||||
|
|
||||||
impl<D: DataMut> TensorKey<D> {
|
impl<D: DataMut> GLWETensorKey<D> {
|
||||||
pub fn decompress<O, M>(&mut self, module: &M, other: &O)
|
pub fn decompress<O, M>(&mut self, module: &M, other: &O)
|
||||||
where
|
where
|
||||||
O: TensorKeyCompressedToRef,
|
O: GLWETensorKeyCompressedToRef,
|
||||||
M: TensorKeyDecompress,
|
M: GLWETensorKeyDecompress,
|
||||||
{
|
{
|
||||||
module.decompress_tensor_key(self, other);
|
module.decompress_tensor_key(self, other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyCompressedToMut {
|
pub trait GLWETensorKeyCompressedToMut {
|
||||||
fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]>;
|
fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> TensorKeyCompressedToMut for GLWETensorKeyCompressed<D>
|
impl<D: DataMut> GLWETensorKeyCompressedToMut for GLWETensorKeyCompressed<D>
|
||||||
where
|
where
|
||||||
GGLWECompressed<D>: GGLWECompressedToMut,
|
GGLWECompressed<D>: GGLWECompressedToMut,
|
||||||
{
|
{
|
||||||
@@ -230,11 +230,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyCompressedToRef {
|
pub trait GLWETensorKeyCompressedToRef {
|
||||||
fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]>;
|
fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> TensorKeyCompressedToRef for GLWETensorKeyCompressed<D>
|
impl<D: DataRef> GLWETensorKeyCompressedToRef for GLWETensorKeyCompressed<D>
|
||||||
where
|
where
|
||||||
GGLWECompressed<D>: GGLWECompressedToRef,
|
GGLWECompressed<D>: GGLWECompressedToRef,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
pub struct AutomorphismKeyLayout {
|
pub struct GLWEAutomorphismKeyLayout {
|
||||||
pub n: Degree,
|
pub n: Degree,
|
||||||
pub base2k: Base2K,
|
pub base2k: Base2K,
|
||||||
pub k: TorusPrecision,
|
pub k: TorusPrecision,
|
||||||
@@ -21,7 +21,7 @@ pub struct AutomorphismKeyLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct AutomorphismKey<D: Data> {
|
pub struct GLWEAutomorphismKey<D: Data> {
|
||||||
pub(crate) key: GGLWE<D>,
|
pub(crate) key: GGLWE<D>,
|
||||||
pub(crate) p: i64,
|
pub(crate) p: i64,
|
||||||
}
|
}
|
||||||
@@ -34,25 +34,25 @@ pub trait SetGaloisElement {
|
|||||||
fn set_p(&mut self, p: i64);
|
fn set_p(&mut self, p: i64);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> SetGaloisElement for AutomorphismKey<D> {
|
impl<D: DataMut> SetGaloisElement for GLWEAutomorphismKey<D> {
|
||||||
fn set_p(&mut self, p: i64) {
|
fn set_p(&mut self, p: i64) {
|
||||||
self.p = p
|
self.p = p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> GetGaloisElement for AutomorphismKey<D> {
|
impl<D: DataRef> GetGaloisElement for GLWEAutomorphismKey<D> {
|
||||||
fn p(&self) -> i64 {
|
fn p(&self) -> i64 {
|
||||||
self.p
|
self.p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data> AutomorphismKey<D> {
|
impl<D: Data> GLWEAutomorphismKey<D> {
|
||||||
pub fn p(&self) -> i64 {
|
pub fn p(&self) -> i64 {
|
||||||
self.p
|
self.p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data> LWEInfos for AutomorphismKey<D> {
|
impl<D: Data> LWEInfos for GLWEAutomorphismKey<D> {
|
||||||
fn n(&self) -> Degree {
|
fn n(&self) -> Degree {
|
||||||
self.key.n()
|
self.key.n()
|
||||||
}
|
}
|
||||||
@@ -70,13 +70,13 @@ impl<D: Data> LWEInfos for AutomorphismKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data> GLWEInfos for AutomorphismKey<D> {
|
impl<D: Data> GLWEInfos for GLWEAutomorphismKey<D> {
|
||||||
fn rank(&self) -> Rank {
|
fn rank(&self) -> Rank {
|
||||||
self.rank_out()
|
self.rank_out()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data> GGLWEInfos for AutomorphismKey<D> {
|
impl<D: Data> GGLWEInfos for GLWEAutomorphismKey<D> {
|
||||||
fn rank_in(&self) -> Rank {
|
fn rank_in(&self) -> Rank {
|
||||||
self.key.rank_in()
|
self.key.rank_in()
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ impl<D: Data> GGLWEInfos for AutomorphismKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LWEInfos for AutomorphismKeyLayout {
|
impl LWEInfos for GLWEAutomorphismKeyLayout {
|
||||||
fn base2k(&self) -> Base2K {
|
fn base2k(&self) -> Base2K {
|
||||||
self.base2k
|
self.base2k
|
||||||
}
|
}
|
||||||
@@ -108,13 +108,13 @@ impl LWEInfos for AutomorphismKeyLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GLWEInfos for AutomorphismKeyLayout {
|
impl GLWEInfos for GLWEAutomorphismKeyLayout {
|
||||||
fn rank(&self) -> Rank {
|
fn rank(&self) -> Rank {
|
||||||
self.rank
|
self.rank
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GGLWEInfos for AutomorphismKeyLayout {
|
impl GGLWEInfos for GLWEAutomorphismKeyLayout {
|
||||||
fn rank_in(&self) -> Rank {
|
fn rank_in(&self) -> Rank {
|
||||||
self.rank
|
self.rank
|
||||||
}
|
}
|
||||||
@@ -132,25 +132,25 @@ impl GGLWEInfos for AutomorphismKeyLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> fmt::Debug for AutomorphismKey<D> {
|
impl<D: DataRef> fmt::Debug for GLWEAutomorphismKey<D> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{self}")
|
write!(f, "{self}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> FillUniform for AutomorphismKey<D> {
|
impl<D: DataMut> FillUniform for GLWEAutomorphismKey<D> {
|
||||||
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
||||||
self.key.fill_uniform(log_bound, source);
|
self.key.fill_uniform(log_bound, source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> fmt::Display for AutomorphismKey<D> {
|
impl<D: DataRef> fmt::Display for GLWEAutomorphismKey<D> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "(AutomorphismKey: p={}) {}", self.p, self.key)
|
write!(f, "(AutomorphismKey: p={}) {}", self.p, self.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AutomorphismKey<Vec<u8>> {
|
impl GLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn alloc_from_infos<A>(infos: &A) -> Self
|
pub fn alloc_from_infos<A>(infos: &A) -> Self
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
@@ -166,7 +166,7 @@ impl AutomorphismKey<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||||
AutomorphismKey {
|
GLWEAutomorphismKey {
|
||||||
key: GGLWE::alloc(n, base2k, k, rank, rank, dnum, dsize),
|
key: GGLWE::alloc(n, base2k, k, rank, rank, dnum, dsize),
|
||||||
p: 0,
|
p: 0,
|
||||||
}
|
}
|
||||||
@@ -196,38 +196,38 @@ impl AutomorphismKey<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> GGLWEToMut for AutomorphismKey<D> {
|
impl<D: DataMut> GGLWEToMut for GLWEAutomorphismKey<D> {
|
||||||
fn to_mut(&mut self) -> GGLWE<&mut [u8]> {
|
fn to_mut(&mut self) -> GGLWE<&mut [u8]> {
|
||||||
self.key.to_mut()
|
self.key.to_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> GGLWEToRef for AutomorphismKey<D> {
|
impl<D: DataMut> GGLWEToRef for GLWEAutomorphismKey<D> {
|
||||||
fn to_ref(&self) -> GGLWE<&[u8]> {
|
fn to_ref(&self) -> GGLWE<&[u8]> {
|
||||||
self.key.to_ref()
|
self.key.to_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> AutomorphismKey<D> {
|
impl<D: DataRef> GLWEAutomorphismKey<D> {
|
||||||
pub fn at(&self, row: usize, col: usize) -> GLWE<&[u8]> {
|
pub fn at(&self, row: usize, col: usize) -> GLWE<&[u8]> {
|
||||||
self.key.at(row, col)
|
self.key.at(row, col)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> AutomorphismKey<D> {
|
impl<D: DataMut> GLWEAutomorphismKey<D> {
|
||||||
pub fn at_mut(&mut self, row: usize, col: usize) -> GLWE<&mut [u8]> {
|
pub fn at_mut(&mut self, row: usize, col: usize) -> GLWE<&mut [u8]> {
|
||||||
self.key.at_mut(row, col)
|
self.key.at_mut(row, col)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> ReaderFrom for AutomorphismKey<D> {
|
impl<D: DataMut> ReaderFrom for GLWEAutomorphismKey<D> {
|
||||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||||
self.p = reader.read_u64::<LittleEndian>()? as i64;
|
self.p = reader.read_u64::<LittleEndian>()? as i64;
|
||||||
self.key.read_from(reader)
|
self.key.read_from(reader)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> WriterTo for AutomorphismKey<D> {
|
impl<D: DataRef> WriterTo for GLWEAutomorphismKey<D> {
|
||||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||||
writer.write_u64::<LittleEndian>(self.p as u64)?;
|
writer.write_u64::<LittleEndian>(self.p as u64)?;
|
||||||
self.key.write_to(writer)
|
self.key.write_to(writer)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
pub struct TensorKeyLayout {
|
pub struct GLWETensorKeyLayout {
|
||||||
pub n: Degree,
|
pub n: Degree,
|
||||||
pub base2k: Base2K,
|
pub base2k: Base2K,
|
||||||
pub k: TorusPrecision,
|
pub k: TorusPrecision,
|
||||||
@@ -21,11 +21,11 @@ pub struct TensorKeyLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct TensorKey<D: Data> {
|
pub struct GLWETensorKey<D: Data> {
|
||||||
pub(crate) keys: Vec<GGLWE<D>>,
|
pub(crate) keys: Vec<GGLWE<D>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data> LWEInfos for TensorKey<D> {
|
impl<D: Data> LWEInfos for GLWETensorKey<D> {
|
||||||
fn n(&self) -> Degree {
|
fn n(&self) -> Degree {
|
||||||
self.keys[0].n()
|
self.keys[0].n()
|
||||||
}
|
}
|
||||||
@@ -43,13 +43,13 @@ impl<D: Data> LWEInfos for TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data> GLWEInfos for TensorKey<D> {
|
impl<D: Data> GLWEInfos for GLWETensorKey<D> {
|
||||||
fn rank(&self) -> Rank {
|
fn rank(&self) -> Rank {
|
||||||
self.keys[0].rank_out()
|
self.keys[0].rank_out()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data> GGLWEInfos for TensorKey<D> {
|
impl<D: Data> GGLWEInfos for GLWETensorKey<D> {
|
||||||
fn rank_in(&self) -> Rank {
|
fn rank_in(&self) -> Rank {
|
||||||
self.rank_out()
|
self.rank_out()
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ impl<D: Data> GGLWEInfos for TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LWEInfos for TensorKeyLayout {
|
impl LWEInfos for GLWETensorKeyLayout {
|
||||||
fn n(&self) -> Degree {
|
fn n(&self) -> Degree {
|
||||||
self.n
|
self.n
|
||||||
}
|
}
|
||||||
@@ -81,13 +81,13 @@ impl LWEInfos for TensorKeyLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GLWEInfos for TensorKeyLayout {
|
impl GLWEInfos for GLWETensorKeyLayout {
|
||||||
fn rank(&self) -> Rank {
|
fn rank(&self) -> Rank {
|
||||||
self.rank_out()
|
self.rank_out()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GGLWEInfos for TensorKeyLayout {
|
impl GGLWEInfos for GLWETensorKeyLayout {
|
||||||
fn rank_in(&self) -> Rank {
|
fn rank_in(&self) -> Rank {
|
||||||
self.rank
|
self.rank
|
||||||
}
|
}
|
||||||
@@ -105,13 +105,13 @@ impl GGLWEInfos for TensorKeyLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> fmt::Debug for TensorKey<D> {
|
impl<D: DataRef> fmt::Debug for GLWETensorKey<D> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{self}")
|
write!(f, "{self}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> FillUniform for TensorKey<D> {
|
impl<D: DataMut> FillUniform for GLWETensorKey<D> {
|
||||||
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
||||||
self.keys
|
self.keys
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
@@ -119,7 +119,7 @@ impl<D: DataMut> FillUniform for TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> fmt::Display for TensorKey<D> {
|
impl<D: DataRef> fmt::Display for GLWETensorKey<D> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
writeln!(f, "(GLWETensorKey)",)?;
|
writeln!(f, "(GLWETensorKey)",)?;
|
||||||
for (i, key) in self.keys.iter().enumerate() {
|
for (i, key) in self.keys.iter().enumerate() {
|
||||||
@@ -129,7 +129,7 @@ impl<D: DataRef> fmt::Display for TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TensorKey<Vec<u8>> {
|
impl GLWETensorKey<Vec<u8>> {
|
||||||
pub fn alloc_from_infos<A>(infos: &A) -> Self
|
pub fn alloc_from_infos<A>(infos: &A) -> Self
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
@@ -151,7 +151,7 @@ impl TensorKey<Vec<u8>> {
|
|||||||
|
|
||||||
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||||
let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1);
|
let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1);
|
||||||
TensorKey {
|
GLWETensorKey {
|
||||||
keys: (0..pairs)
|
keys: (0..pairs)
|
||||||
.map(|_| GGLWE::alloc(n, base2k, k, Rank(1), rank, dnum, dsize))
|
.map(|_| GGLWE::alloc(n, base2k, k, Rank(1), rank, dnum, dsize))
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -183,7 +183,7 @@ impl TensorKey<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> TensorKey<D> {
|
impl<D: DataMut> GLWETensorKey<D> {
|
||||||
// Returns a mutable reference to GGLWE_{s}(s[i] * s[j])
|
// Returns a mutable reference to GGLWE_{s}(s[i] * s[j])
|
||||||
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWE<D> {
|
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWE<D> {
|
||||||
if i > j {
|
if i > j {
|
||||||
@@ -194,7 +194,7 @@ impl<D: DataMut> TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> TensorKey<D> {
|
impl<D: DataRef> GLWETensorKey<D> {
|
||||||
// Returns a reference to GGLWE_{s}(s[i] * s[j])
|
// Returns a reference to GGLWE_{s}(s[i] * s[j])
|
||||||
pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWE<D> {
|
pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWE<D> {
|
||||||
if i > j {
|
if i > j {
|
||||||
@@ -205,7 +205,7 @@ impl<D: DataRef> TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> ReaderFrom for TensorKey<D> {
|
impl<D: DataMut> ReaderFrom for GLWETensorKey<D> {
|
||||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||||
let len: usize = reader.read_u64::<LittleEndian>()? as usize;
|
let len: usize = reader.read_u64::<LittleEndian>()? as usize;
|
||||||
if self.keys.len() != len {
|
if self.keys.len() != len {
|
||||||
@@ -221,7 +221,7 @@ impl<D: DataMut> ReaderFrom for TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> WriterTo for TensorKey<D> {
|
impl<D: DataRef> WriterTo for GLWETensorKey<D> {
|
||||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||||
writer.write_u64::<LittleEndian>(self.keys.len() as u64)?;
|
writer.write_u64::<LittleEndian>(self.keys.len() as u64)?;
|
||||||
for key in &self.keys {
|
for key in &self.keys {
|
||||||
@@ -231,31 +231,31 @@ impl<D: DataRef> WriterTo for TensorKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyToRef {
|
pub trait GLWETensorKeyToRef {
|
||||||
fn to_ref(&self) -> TensorKey<&[u8]>;
|
fn to_ref(&self) -> GLWETensorKey<&[u8]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef> TensorKeyToRef for TensorKey<D>
|
impl<D: DataRef> GLWETensorKeyToRef for GLWETensorKey<D>
|
||||||
where
|
where
|
||||||
GGLWE<D>: GGLWEToRef,
|
GGLWE<D>: GGLWEToRef,
|
||||||
{
|
{
|
||||||
fn to_ref(&self) -> TensorKey<&[u8]> {
|
fn to_ref(&self) -> GLWETensorKey<&[u8]> {
|
||||||
TensorKey {
|
GLWETensorKey {
|
||||||
keys: self.keys.iter().map(|c| c.to_ref()).collect(),
|
keys: self.keys.iter().map(|c| c.to_ref()).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyToMut {
|
pub trait GLWETensorKeyToMut {
|
||||||
fn to_mut(&mut self) -> TensorKey<&mut [u8]>;
|
fn to_mut(&mut self) -> GLWETensorKey<&mut [u8]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> TensorKeyToMut for TensorKey<D>
|
impl<D: DataMut> GLWETensorKeyToMut for GLWETensorKey<D>
|
||||||
where
|
where
|
||||||
GGLWE<D>: GGLWEToMut,
|
GGLWE<D>: GGLWEToMut,
|
||||||
{
|
{
|
||||||
fn to_mut(&mut self) -> TensorKey<&mut [u8]> {
|
fn to_mut(&mut self) -> GLWETensorKey<&mut [u8]> {
|
||||||
TensorKey {
|
GLWETensorKey {
|
||||||
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
|
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
|||||||
|
|
||||||
pub trait LWEInfos {
|
pub trait LWEInfos {
|
||||||
fn n(&self) -> Degree;
|
fn n(&self) -> Degree;
|
||||||
|
fn log_n(&self) -> usize {
|
||||||
|
(u64::BITS - (self.n().as_usize() as u64 - 1).leading_zeros()) as usize
|
||||||
|
}
|
||||||
fn k(&self) -> TorusPrecision;
|
fn k(&self) -> TorusPrecision;
|
||||||
fn max_k(&self) -> TorusPrecision {
|
fn max_k(&self) -> TorusPrecision {
|
||||||
TorusPrecision(self.k().0 * self.size() as u32)
|
TorusPrecision(self.k().0 * self.size() as u32)
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
|||||||
|
|
||||||
use crate::layouts::{
|
use crate::layouts::{
|
||||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedFactory, GGLWEPreparedToMut, GGLWEPreparedToRef,
|
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedFactory, GGLWEPreparedToMut, GGLWEPreparedToRef,
|
||||||
GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
|
GLWEInfos, GLWETensorKey, GLWETensorKeyToRef, LWEInfos, Rank, TorusPrecision,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub struct TensorKeyPrepared<D: Data, B: Backend> {
|
pub struct GLWETensorKeyPrepared<D: Data, B: Backend> {
|
||||||
pub(crate) keys: Vec<GGLWEPrepared<D, B>>,
|
pub(crate) keys: Vec<GGLWEPrepared<D, B>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data, B: Backend> LWEInfos for TensorKeyPrepared<D, B> {
|
impl<D: Data, B: Backend> LWEInfos for GLWETensorKeyPrepared<D, B> {
|
||||||
fn n(&self) -> Degree {
|
fn n(&self) -> Degree {
|
||||||
self.keys[0].n()
|
self.keys[0].n()
|
||||||
}
|
}
|
||||||
@@ -28,13 +28,13 @@ impl<D: Data, B: Backend> LWEInfos for TensorKeyPrepared<D, B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data, B: Backend> GLWEInfos for TensorKeyPrepared<D, B> {
|
impl<D: Data, B: Backend> GLWEInfos for GLWETensorKeyPrepared<D, B> {
|
||||||
fn rank(&self) -> Rank {
|
fn rank(&self) -> Rank {
|
||||||
self.rank_out()
|
self.rank_out()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Data, B: Backend> GGLWEInfos for TensorKeyPrepared<D, B> {
|
impl<D: Data, B: Backend> GGLWEInfos for GLWETensorKeyPrepared<D, B> {
|
||||||
fn rank_in(&self) -> Rank {
|
fn rank_in(&self) -> Rank {
|
||||||
self.rank_out()
|
self.rank_out()
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ impl<D: Data, B: Backend> GGLWEInfos for TensorKeyPrepared<D, B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyPreparedFactory<B: Backend>
|
pub trait GLWETensorKeyPreparedFactory<B: Backend>
|
||||||
where
|
where
|
||||||
Self: GGLWEPreparedFactory<B>,
|
Self: GGLWEPreparedFactory<B>,
|
||||||
{
|
{
|
||||||
@@ -63,16 +63,16 @@ where
|
|||||||
dnum: Dnum,
|
dnum: Dnum,
|
||||||
dsize: Dsize,
|
dsize: Dsize,
|
||||||
rank: Rank,
|
rank: Rank,
|
||||||
) -> TensorKeyPrepared<Vec<u8>, B> {
|
) -> GLWETensorKeyPrepared<Vec<u8>, B> {
|
||||||
let pairs: u32 = (((rank.as_u32() + 1) * rank.as_u32()) >> 1).max(1);
|
let pairs: u32 = (((rank.as_u32() + 1) * rank.as_u32()) >> 1).max(1);
|
||||||
TensorKeyPrepared {
|
GLWETensorKeyPrepared {
|
||||||
keys: (0..pairs)
|
keys: (0..pairs)
|
||||||
.map(|_| self.alloc_gglwe_prepared(base2k, k, Rank(1), rank, dnum, dsize))
|
.map(|_| self.alloc_gglwe_prepared(base2k, k, Rank(1), rank, dnum, dsize))
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc_tensor_key_prepared_from_infos<A>(&self, infos: &A) -> TensorKeyPrepared<Vec<u8>, B>
|
fn alloc_tensor_key_prepared_from_infos<A>(&self, infos: &A) -> GLWETensorKeyPrepared<Vec<u8>, B>
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
@@ -117,11 +117,11 @@ where
|
|||||||
|
|
||||||
fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||||
where
|
where
|
||||||
R: TensorKeyPreparedToMut<B>,
|
R: GLWETensorKeyPreparedToMut<B>,
|
||||||
O: TensorKeyToRef,
|
O: GLWETensorKeyToRef,
|
||||||
{
|
{
|
||||||
let mut res: TensorKeyPrepared<&mut [u8], B> = res.to_mut();
|
let mut res: GLWETensorKeyPrepared<&mut [u8], B> = res.to_mut();
|
||||||
let other: TensorKey<&[u8]> = other.to_ref();
|
let other: GLWETensorKey<&[u8]> = other.to_ref();
|
||||||
|
|
||||||
assert_eq!(res.keys.len(), other.keys.len());
|
assert_eq!(res.keys.len(), other.keys.len());
|
||||||
|
|
||||||
@@ -131,20 +131,20 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TensorKeyPreparedFactory<B> for Module<B> where Module<B>: GGLWEPreparedFactory<B> {}
|
impl<B: Backend> GLWETensorKeyPreparedFactory<B> for Module<B> where Module<B>: GGLWEPreparedFactory<B> {}
|
||||||
|
|
||||||
impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
impl<B: Backend> GLWETensorKeyPrepared<Vec<u8>, B> {
|
||||||
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
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: TensorKeyPreparedFactory<B>,
|
M: GLWETensorKeyPreparedFactory<B>,
|
||||||
{
|
{
|
||||||
module.alloc_tensor_key_prepared_from_infos(infos)
|
module.alloc_tensor_key_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: TensorKeyPreparedFactory<B>,
|
M: GLWETensorKeyPreparedFactory<B>,
|
||||||
{
|
{
|
||||||
module.alloc_tensor_key_prepared(base2k, k, dnum, dsize, rank)
|
module.alloc_tensor_key_prepared(base2k, k, dnum, dsize, rank)
|
||||||
}
|
}
|
||||||
@@ -152,20 +152,20 @@ impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
|||||||
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
|
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: TensorKeyPreparedFactory<B>,
|
M: GLWETensorKeyPreparedFactory<B>,
|
||||||
{
|
{
|
||||||
module.bytes_of_tensor_key_prepared_from_infos(infos)
|
module.bytes_of_tensor_key_prepared_from_infos(infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize
|
pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize
|
||||||
where
|
where
|
||||||
M: TensorKeyPreparedFactory<B>,
|
M: GLWETensorKeyPreparedFactory<B>,
|
||||||
{
|
{
|
||||||
module.bytes_of_tensor_key_prepared(base2k, k, rank, dnum, dsize)
|
module.bytes_of_tensor_key_prepared(base2k, k, rank, dnum, dsize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
impl<D: DataMut, B: Backend> GLWETensorKeyPrepared<D, B> {
|
||||||
// Returns a mutable reference to GGLWE_{s}(s[i] * s[j])
|
// Returns a mutable reference to GGLWE_{s}(s[i] * s[j])
|
||||||
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWEPrepared<D, B> {
|
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWEPrepared<D, B> {
|
||||||
if i > j {
|
if i > j {
|
||||||
@@ -176,7 +176,7 @@ impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef, B: Backend> TensorKeyPrepared<D, B> {
|
impl<D: DataRef, B: Backend> GLWETensorKeyPrepared<D, B> {
|
||||||
// Returns a reference to GGLWE_{s}(s[i] * s[j])
|
// Returns a reference to GGLWE_{s}(s[i] * s[j])
|
||||||
pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWEPrepared<D, B> {
|
pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWEPrepared<D, B> {
|
||||||
if i > j {
|
if i > j {
|
||||||
@@ -187,51 +187,51 @@ impl<D: DataRef, B: Backend> TensorKeyPrepared<D, B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
impl<B: Backend> GLWETensorKeyPrepared<Vec<u8>, B> {
|
||||||
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
|
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: TensorKeyPreparedFactory<B>,
|
M: GLWETensorKeyPreparedFactory<B>,
|
||||||
{
|
{
|
||||||
module.prepare_tensor_key_tmp_bytes(infos)
|
module.prepare_tensor_key_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
impl<D: DataMut, B: Backend> GLWETensorKeyPrepared<D, B> {
|
||||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||||
where
|
where
|
||||||
O: TensorKeyToRef,
|
O: GLWETensorKeyToRef,
|
||||||
M: TensorKeyPreparedFactory<B>,
|
M: GLWETensorKeyPreparedFactory<B>,
|
||||||
{
|
{
|
||||||
module.prepare_tensor_key(self, other, scratch);
|
module.prepare_tensor_key(self, other, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyPreparedToMut<B: Backend> {
|
pub trait GLWETensorKeyPreparedToMut<B: Backend> {
|
||||||
fn to_mut(&mut self) -> TensorKeyPrepared<&mut [u8], B>;
|
fn to_mut(&mut self) -> GLWETensorKeyPrepared<&mut [u8], B>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, B: Backend> TensorKeyPreparedToMut<B> for TensorKeyPrepared<D, B>
|
impl<D: DataMut, B: Backend> GLWETensorKeyPreparedToMut<B> for GLWETensorKeyPrepared<D, B>
|
||||||
where
|
where
|
||||||
GGLWEPrepared<D, B>: GGLWEPreparedToMut<B>,
|
GGLWEPrepared<D, B>: GGLWEPreparedToMut<B>,
|
||||||
{
|
{
|
||||||
fn to_mut(&mut self) -> TensorKeyPrepared<&mut [u8], B> {
|
fn to_mut(&mut self) -> GLWETensorKeyPrepared<&mut [u8], B> {
|
||||||
TensorKeyPrepared {
|
GLWETensorKeyPrepared {
|
||||||
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
|
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TensorKeyPreparedToRef<B: Backend> {
|
pub trait GLWETensorKeyPreparedToRef<B: Backend> {
|
||||||
fn to_ref(&self) -> TensorKeyPrepared<&[u8], B>;
|
fn to_ref(&self) -> GLWETensorKeyPrepared<&[u8], B>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef, B: Backend> TensorKeyPreparedToRef<B> for TensorKeyPrepared<D, B>
|
impl<D: DataRef, B: Backend> GLWETensorKeyPreparedToRef<B> for GLWETensorKeyPrepared<D, B>
|
||||||
where
|
where
|
||||||
GGLWEPrepared<D, B>: GGLWEPreparedToRef<B>,
|
GGLWEPrepared<D, B>: GGLWEPreparedToRef<B>,
|
||||||
{
|
{
|
||||||
fn to_ref(&self) -> TensorKeyPrepared<&[u8], B> {
|
fn to_ref(&self) -> GLWETensorKeyPrepared<&[u8], B> {
|
||||||
TensorKeyPrepared {
|
GLWETensorKeyPrepared {
|
||||||
keys: self.keys.iter().map(|c| c.to_ref()).collect(),
|
keys: self.keys.iter().map(|c| c.to_ref()).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pub use dist::*;
|
|||||||
pub use encryption::*;
|
pub use encryption::*;
|
||||||
pub use external_product::*;
|
pub use external_product::*;
|
||||||
pub use glwe_packing::*;
|
pub use glwe_packing::*;
|
||||||
|
pub use glwe_trace::*;
|
||||||
pub use keyswitching::*;
|
pub use keyswitching::*;
|
||||||
pub use noise::*;
|
pub use noise::*;
|
||||||
pub use scratch::*;
|
pub use scratch::*;
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ use poulpy_hal::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
dist::Distribution,
|
dist::Distribution,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPrepared,
|
Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEAutomorphismKey, GLWEInfos, GLWEPlaintext,
|
||||||
GLWEPublicKey, GLWESecret, GLWESwitchingKey, Rank, TensorKey,
|
GLWEPrepared, GLWEPublicKey, GLWESecret, GLWESwitchingKey, GLWETensorKey, Rank,
|
||||||
prepared::{
|
prepared::{
|
||||||
GGLWEPrepared, GGSWPrepared, GLWEAutomorphismKeyPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared,
|
GGLWEPrepared, GGSWPrepared, GLWEAutomorphismKeyPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared,
|
||||||
GLWESwitchingKeyPrepared, TensorKeyPrepared,
|
GLWESwitchingKeyPrepared, GLWETensorKeyPrepared,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -282,12 +282,12 @@ where
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_glwe_automorphism_key<A>(&mut self, infos: &A) -> (AutomorphismKey<&mut [u8]>, &mut Self)
|
fn take_glwe_automorphism_key<A>(&mut self, infos: &A) -> (GLWEAutomorphismKey<&mut [u8]>, &mut Self)
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
let (data, scratch) = self.take_gglwe(infos);
|
let (data, scratch) = self.take_gglwe(infos);
|
||||||
(AutomorphismKey { key: data, p: 0 }, scratch)
|
(GLWEAutomorphismKey { key: data, p: 0 }, scratch)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_glwe_automorphism_key_prepared<A, M>(
|
fn take_glwe_automorphism_key_prepared<A, M>(
|
||||||
@@ -304,14 +304,14 @@ where
|
|||||||
(GLWEAutomorphismKeyPrepared { key: data, p: 0 }, scratch)
|
(GLWEAutomorphismKeyPrepared { key: data, p: 0 }, scratch)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_glwe_tensor_key<A, M>(&mut self, infos: &A) -> (TensorKey<&mut [u8]>, &mut Self)
|
fn take_glwe_tensor_key<A, M>(&mut self, infos: &A) -> (GLWETensorKey<&mut [u8]>, &mut Self)
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
infos.rank_in(),
|
infos.rank_in(),
|
||||||
infos.rank_out(),
|
infos.rank_out(),
|
||||||
"rank_in != rank_out is not supported for GGLWETensorKey"
|
"rank_in != rank_out is not supported for GLWETensorKey"
|
||||||
);
|
);
|
||||||
let mut keys: Vec<GGLWE<&mut [u8]>> = Vec::new();
|
let mut keys: Vec<GGLWE<&mut [u8]>> = Vec::new();
|
||||||
let pairs: usize = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1) as usize;
|
let pairs: usize = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1) as usize;
|
||||||
@@ -331,10 +331,10 @@ where
|
|||||||
scratch = s;
|
scratch = s;
|
||||||
keys.push(gglwe);
|
keys.push(gglwe);
|
||||||
}
|
}
|
||||||
(TensorKey { keys }, scratch)
|
(GLWETensorKey { keys }, scratch)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_glwe_tensor_key_prepared<A, M>(&mut self, module: &M, infos: &A) -> (TensorKeyPrepared<&mut [u8], B>, &mut Self)
|
fn take_glwe_tensor_key_prepared<A, M>(&mut self, module: &M, infos: &A) -> (GLWETensorKeyPrepared<&mut [u8], B>, &mut Self)
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: ModuleN + VmpPMatBytesOf,
|
M: ModuleN + VmpPMatBytesOf,
|
||||||
@@ -364,7 +364,7 @@ where
|
|||||||
scratch = s;
|
scratch = s;
|
||||||
keys.push(gglwe);
|
keys.push(gglwe);
|
||||||
}
|
}
|
||||||
(TensorKeyPrepared { keys }, scratch)
|
(GLWETensorKeyPrepared { keys }, scratch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use poulpy_hal::test_suite::serialization::test_reader_writer_interface;
|
use poulpy_hal::test_suite::serialization::test_reader_writer_interface;
|
||||||
|
|
||||||
use crate::layouts::{
|
use crate::layouts::{
|
||||||
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE,
|
Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWEAutomorphismKey, GLWESwitchingKey, GLWETensorKey, GLWEToLWESwitchingKey,
|
||||||
LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision,
|
LWE, LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TorusPrecision,
|
||||||
compressed::{
|
compressed::{
|
||||||
GGLWECompressed, GGSWCompressed, GLWEAutomorphismKeyCompressed, GLWECompressed, GLWESwitchingKeyCompressed,
|
GGLWECompressed, GGSWCompressed, GLWEAutomorphismKeyCompressed, GLWECompressed, GLWESwitchingKeyCompressed,
|
||||||
GLWETensorKeyCompressed, GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed,
|
GLWETensorKeyCompressed, GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed,
|
||||||
@@ -69,7 +69,7 @@ fn test_glwe_switching_key_compressed_serialization() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_automorphism_key_serialization() {
|
fn test_automorphism_key_serialization() {
|
||||||
let original: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
|
let original: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
|
||||||
test_reader_writer_interface(original);
|
test_reader_writer_interface(original);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ fn test_automorphism_key_compressed_serialization() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tensor_key_serialization() {
|
fn test_tensor_key_serialization() {
|
||||||
let original: TensorKey<Vec<u8>> = TensorKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
|
let original: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE);
|
||||||
test_reader_writer_interface(original);
|
test_reader_writer_interface(original);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AutomorphismKeyEncryptSk, GLWEAutomorphismKeyAutomorphism, GLWEDecrypt, ScratchTakeCore,
|
GLWEAutomorphismKeyAutomorphism, GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GLWEAutomorphismKeyPreparedFactory, GLWEPlaintext, GLWESecret,
|
GGLWEInfos, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWEPlaintext,
|
||||||
GLWESecretPreparedFactory,
|
GLWESecret, GLWESecretPreparedFactory,
|
||||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
noise::log2_std_noise_gglwe_product,
|
noise::log2_std_noise_gglwe_product,
|
||||||
@@ -18,7 +18,7 @@ use crate::{
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_gglwe_automorphism_key_automorphism<BE: Backend>(module: &Module<BE>)
|
pub fn test_gglwe_automorphism_key_automorphism<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: AutomorphismKeyEncryptSk<BE>
|
Module<BE>: GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ GLWEAutomorphismKeyAutomorphism<BE>
|
+ GLWEAutomorphismKeyAutomorphism<BE>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
@@ -46,7 +46,7 @@ where
|
|||||||
let dnum_out: usize = k_out / (base2k * di);
|
let dnum_out: usize = k_out / (base2k * di);
|
||||||
let dnum_apply: usize = k_in.div_ceil(base2k * di);
|
let dnum_apply: usize = k_in.div_ceil(base2k * di);
|
||||||
|
|
||||||
let auto_key_in_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let auto_key_in_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_in.into(),
|
k: k_in.into(),
|
||||||
@@ -55,7 +55,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let auto_key_out_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let auto_key_out_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_out.into(),
|
k: k_out.into(),
|
||||||
@@ -64,7 +64,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let auto_key_apply_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let auto_key_apply_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_apply.into(),
|
k: k_apply.into(),
|
||||||
@@ -73,18 +73,18 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut auto_key_in: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_in_infos);
|
let mut auto_key_in: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_in_infos);
|
||||||
let mut auto_key_out: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_out_infos);
|
let mut auto_key_out: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_out_infos);
|
||||||
let mut auto_key_apply: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_apply_infos);
|
let mut auto_key_apply: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_apply_infos);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_in_infos)
|
GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_in_infos)
|
||||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply_infos)
|
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply_infos)
|
||||||
| AutomorphismKey::automorphism_tmp_bytes(
|
| GLWEAutomorphismKey::automorphism_tmp_bytes(
|
||||||
module,
|
module,
|
||||||
&auto_key_out_infos,
|
&auto_key_out_infos,
|
||||||
&auto_key_in_infos,
|
&auto_key_in_infos,
|
||||||
@@ -187,7 +187,7 @@ where
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_gglwe_automorphism_key_automorphism_inplace<BE: Backend>(module: &Module<BE>)
|
pub fn test_gglwe_automorphism_key_automorphism_inplace<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: AutomorphismKeyEncryptSk<BE>
|
Module<BE>: GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ GLWEAutomorphismKeyAutomorphism<BE>
|
+ GLWEAutomorphismKeyAutomorphism<BE>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
@@ -213,7 +213,7 @@ where
|
|||||||
let dnum_in: usize = k_in / (base2k * di);
|
let dnum_in: usize = k_in / (base2k * di);
|
||||||
let dnum_apply: usize = k_in.div_ceil(base2k * di);
|
let dnum_apply: usize = k_in.div_ceil(base2k * di);
|
||||||
|
|
||||||
let auto_key_layout: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let auto_key_layout: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_in.into(),
|
k: k_in.into(),
|
||||||
@@ -222,7 +222,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let auto_key_apply_layout: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let auto_key_apply_layout: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_apply.into(),
|
k: k_apply.into(),
|
||||||
@@ -231,17 +231,17 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_layout);
|
let mut auto_key: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_layout);
|
||||||
let mut auto_key_apply: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_apply_layout);
|
let mut auto_key_apply: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_apply_layout);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply)
|
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply)
|
||||||
| AutomorphismKey::automorphism_tmp_bytes(module, &auto_key, &auto_key, &auto_key_apply),
|
| GLWEAutomorphismKey::automorphism_tmp_bytes(module, &auto_key, &auto_key, &auto_key_apply),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&auto_key);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&auto_key);
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AutomorphismKeyEncryptSk, GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, TensorKeyEncryptSk,
|
GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, GLWEAutomorphismKeyEncryptSk, GLWETensorKeyEncryptSk, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, GGSW, GGSWLayout, GLWEAutomorphismKeyPreparedFactory, GLWESecret, GLWESecretPreparedFactory, TensorKey,
|
GGSW, GGSWLayout, GLWEAutomorphismKey, GLWEAutomorphismKeyPreparedFactory, GLWESecret, GLWESecretPreparedFactory,
|
||||||
TensorKeyLayout, TensorKeyPreparedFactory,
|
GLWETensorKey, GLWETensorKeyLayout, GLWETensorKeyPreparedFactory,
|
||||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared},
|
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, GLWETensorKeyPrepared},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_keyswitch,
|
noise::noise_ggsw_keyswitch,
|
||||||
};
|
};
|
||||||
@@ -18,11 +18,11 @@ use crate::{
|
|||||||
pub fn test_ggsw_automorphism<BE: Backend>(module: &Module<BE>)
|
pub fn test_ggsw_automorphism<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: GGSWEncryptSk<BE>
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ AutomorphismKeyEncryptSk<BE>
|
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ GGSWAutomorphism<BE>
|
+ GGSWAutomorphism<BE>
|
||||||
+ TensorKeyPreparedFactory<BE>
|
+ GLWETensorKeyPreparedFactory<BE>
|
||||||
+ TensorKeyEncryptSk<BE>
|
+ GLWETensorKeyEncryptSk<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ VecZnxAutomorphismInplace<BE>
|
+ VecZnxAutomorphismInplace<BE>
|
||||||
+ GGSWNoise<BE>,
|
+ GGSWNoise<BE>,
|
||||||
@@ -64,7 +64,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let tensor_key_layout: TensorKeyLayout = TensorKeyLayout {
|
let tensor_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_tsk.into(),
|
k: k_tsk.into(),
|
||||||
@@ -73,7 +73,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let auto_key_layout: TensorKeyLayout = TensorKeyLayout {
|
let auto_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -84,8 +84,8 @@ where
|
|||||||
|
|
||||||
let mut ct_in: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_in_layout);
|
let mut ct_in: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_in_layout);
|
||||||
let mut ct_out: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_layout);
|
let mut ct_out: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_layout);
|
||||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tensor_key_layout);
|
let mut tensor_key: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tensor_key_layout);
|
||||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_layout);
|
let mut auto_key: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_layout);
|
||||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
@@ -94,8 +94,8 @@ where
|
|||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ct_in)
|
GGSW::encrypt_sk_tmp_bytes(module, &ct_in)
|
||||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||||
| TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
|
| GLWETensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
|
||||||
| GGSW::automorphism_tmp_bytes(module, &ct_out, &ct_in, &auto_key, &tensor_key),
|
| GGSW::automorphism_tmp_bytes(module, &ct_out, &ct_in, &auto_key, &tensor_key),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -138,8 +138,8 @@ where
|
|||||||
GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
|
GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
|
||||||
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
||||||
|
|
||||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
|
let mut tsk_prepared: GLWETensorKeyPrepared<Vec<u8>, BE> =
|
||||||
TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
GLWETensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
||||||
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
||||||
|
|
||||||
ct_out.automorphism(
|
ct_out.automorphism(
|
||||||
@@ -177,11 +177,11 @@ where
|
|||||||
pub fn test_ggsw_automorphism_inplace<BE: Backend>(module: &Module<BE>)
|
pub fn test_ggsw_automorphism_inplace<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: GGSWEncryptSk<BE>
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ AutomorphismKeyEncryptSk<BE>
|
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ GGSWAutomorphism<BE>
|
+ GGSWAutomorphism<BE>
|
||||||
+ TensorKeyPreparedFactory<BE>
|
+ GLWETensorKeyPreparedFactory<BE>
|
||||||
+ TensorKeyEncryptSk<BE>
|
+ GLWETensorKeyEncryptSk<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ VecZnxAutomorphismInplace<BE>
|
+ VecZnxAutomorphismInplace<BE>
|
||||||
+ GGSWNoise<BE>,
|
+ GGSWNoise<BE>,
|
||||||
@@ -211,7 +211,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let tensor_key_layout: TensorKeyLayout = TensorKeyLayout {
|
let tensor_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_tsk.into(),
|
k: k_tsk.into(),
|
||||||
@@ -220,7 +220,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let auto_key_layout: TensorKeyLayout = TensorKeyLayout {
|
let auto_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -230,8 +230,8 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut ct: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_layout);
|
let mut ct: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_layout);
|
||||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tensor_key_layout);
|
let mut tensor_key: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tensor_key_layout);
|
||||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_layout);
|
let mut auto_key: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_layout);
|
||||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
@@ -240,8 +240,8 @@ where
|
|||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ct)
|
GGSW::encrypt_sk_tmp_bytes(module, &ct)
|
||||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||||
| TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
|
| GLWETensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
|
||||||
| GGSW::automorphism_tmp_bytes(module, &ct, &ct, &auto_key, &tensor_key),
|
| GGSW::automorphism_tmp_bytes(module, &ct, &ct, &auto_key, &tensor_key),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -284,8 +284,8 @@ where
|
|||||||
GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
|
GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
|
||||||
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
||||||
|
|
||||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
|
let mut tsk_prepared: GLWETensorKeyPrepared<Vec<u8>, BE> =
|
||||||
TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
GLWETensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
||||||
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
||||||
|
|
||||||
ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow());
|
ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow());
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AutomorphismKeyEncryptSk, GLWEAutomorphism, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
GLWEAutomorphism, GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext, GLWESecret,
|
GLWE, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext,
|
||||||
GLWESecretPreparedFactory,
|
GLWESecret, GLWESecretPreparedFactory,
|
||||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
noise::log2_std_noise_gglwe_product,
|
noise::log2_std_noise_gglwe_product,
|
||||||
@@ -22,7 +22,7 @@ where
|
|||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ GLWEDecrypt<BE>
|
+ GLWEDecrypt<BE>
|
||||||
+ GLWEAutomorphism<BE>
|
+ GLWEAutomorphism<BE>
|
||||||
+ AutomorphismKeyEncryptSk<BE>
|
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ GLWENoise<BE>
|
+ GLWENoise<BE>
|
||||||
+ VecZnxAutomorphismInplace<BE>,
|
+ VecZnxAutomorphismInplace<BE>,
|
||||||
@@ -55,7 +55,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let autokey_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_out.into(),
|
k: k_out.into(),
|
||||||
@@ -64,7 +64,7 @@ where
|
|||||||
dsize: di.into(),
|
dsize: di.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut autokey: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&autokey_infos);
|
let mut autokey: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&autokey_infos);
|
||||||
let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ct_in_infos);
|
let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ct_in_infos);
|
||||||
let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ct_out_infos);
|
let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ct_out_infos);
|
||||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&ct_out_infos);
|
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&ct_out_infos);
|
||||||
@@ -76,7 +76,7 @@ where
|
|||||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
AutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey)
|
GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey)
|
||||||
| GLWE::decrypt_tmp_bytes(module, &ct_out)
|
| GLWE::decrypt_tmp_bytes(module, &ct_out)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(module, &ct_in)
|
| GLWE::encrypt_sk_tmp_bytes(module, &ct_in)
|
||||||
| GLWE::automorphism_tmp_bytes(module, &ct_out, &ct_in, &autokey),
|
| GLWE::automorphism_tmp_bytes(module, &ct_out, &ct_in, &autokey),
|
||||||
@@ -140,7 +140,7 @@ where
|
|||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ GLWEDecrypt<BE>
|
+ GLWEDecrypt<BE>
|
||||||
+ GLWEAutomorphism<BE>
|
+ GLWEAutomorphism<BE>
|
||||||
+ AutomorphismKeyEncryptSk<BE>
|
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ GLWENoise<BE>
|
+ GLWENoise<BE>
|
||||||
+ VecZnxAutomorphismInplace<BE>,
|
+ VecZnxAutomorphismInplace<BE>,
|
||||||
@@ -165,7 +165,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let autokey_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -174,7 +174,7 @@ where
|
|||||||
dsize: di.into(),
|
dsize: di.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut autokey: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&autokey_infos);
|
let mut autokey: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&autokey_infos);
|
||||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ct_out_infos);
|
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ct_out_infos);
|
||||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&ct_out_infos);
|
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&ct_out_infos);
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ where
|
|||||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
AutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey)
|
GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey)
|
||||||
| GLWE::decrypt_tmp_bytes(module, &ct)
|
| GLWE::decrypt_tmp_bytes(module, &ct)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(module, &ct)
|
| GLWE::encrypt_sk_tmp_bytes(module, &ct)
|
||||||
| GLWE::automorphism_tmp_bytes(module, &ct, &ct, &autokey),
|
| GLWE::automorphism_tmp_bytes(module, &ct, &ct, &autokey),
|
||||||
|
|||||||
@@ -5,19 +5,20 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AutomorphismKeyCompressedEncryptSk, AutomorphismKeyEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk,
|
GGLWEKeyswitch, GLWEAutomorphismKeyCompressedEncryptSk, GLWEAutomorphismKeyEncryptSk, GLWESwitchingKeyCompressedEncryptSk,
|
||||||
GLWESwitchingKeyEncryptSk, ScratchTakeCore,
|
GLWESwitchingKeyEncryptSk, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, GLWESecret, GLWESecretPreparedFactory,
|
AutomorphismKeyDecompress, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEInfos, GLWESecret,
|
||||||
GLWESwitchingKeyDecompress, compressed::GLWEAutomorphismKeyCompressed, prepared::GLWESecretPrepared,
|
GLWESecretPreparedFactory, GLWESwitchingKeyDecompress, compressed::GLWEAutomorphismKeyCompressed,
|
||||||
|
prepared::GLWESecretPrepared,
|
||||||
},
|
},
|
||||||
noise::GGLWENoise,
|
noise::GGLWENoise,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_gglwe_automorphism_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
pub fn test_gglwe_automorphism_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: AutomorphismKeyEncryptSk<BE>
|
Module<BE>: GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GGLWEKeyswitch<BE>
|
+ GGLWEKeyswitch<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ GLWESwitchingKeyEncryptSk<BE>
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
@@ -37,7 +38,7 @@ where
|
|||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||||
|
|
||||||
let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let atk_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -46,13 +47,15 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&atk_infos);
|
let mut atk: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&atk_infos);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_tmp_bytes(module, &atk_infos));
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWEAutomorphismKey::encrypt_sk_tmp_bytes(
|
||||||
|
module, &atk_infos,
|
||||||
|
));
|
||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&atk_infos);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&atk_infos);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
@@ -89,7 +92,7 @@ where
|
|||||||
|
|
||||||
pub fn test_gglwe_automorphism_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
pub fn test_gglwe_automorphism_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: AutomorphismKeyCompressedEncryptSk<BE>
|
Module<BE>: GLWEAutomorphismKeyCompressedEncryptSk<BE>
|
||||||
+ GGLWEKeyswitch<BE>
|
+ GGLWEKeyswitch<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ GLWESwitchingKeyEncryptSk<BE>
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
@@ -109,7 +112,7 @@ where
|
|||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||||
|
|
||||||
let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let atk_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -150,7 +153,7 @@ where
|
|||||||
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank().into());
|
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank().into());
|
||||||
sk_out_prepared.prepare(module, &sk_out);
|
sk_out_prepared.prepare(module, &sk_out);
|
||||||
|
|
||||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&atk_infos);
|
let mut atk: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&atk_infos);
|
||||||
atk.decompress(module, &atk_compressed);
|
atk.decompress(module, &atk_compressed);
|
||||||
|
|
||||||
atk.key
|
atk.key
|
||||||
|
|||||||
@@ -9,18 +9,18 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
GGLWETensorKeyCompressedEncryptSk, ScratchTakeCore, TensorKeyEncryptSk,
|
GLWETensorKeyCompressedEncryptSk, GLWETensorKeyEncryptSk, ScratchTakeCore,
|
||||||
decryption::GLWEDecrypt,
|
decryption::GLWEDecrypt,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
Dsize, GLWEPlaintext, GLWESecret, GLWESecretPreparedFactory, GLWETensorKeyCompressed, TensorKey, TensorKeyLayout,
|
Dsize, GLWEPlaintext, GLWESecret, GLWESecretPreparedFactory, GLWETensorKey, GLWETensorKeyCompressed, GLWETensorKeyLayout,
|
||||||
prepared::GLWESecretPrepared,
|
prepared::GLWESecretPrepared,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_gglwe_tensor_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
pub fn test_gglwe_tensor_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: TensorKeyEncryptSk<BE>
|
Module<BE>: GLWETensorKeyEncryptSk<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ GLWEDecrypt<BE>
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxDftAlloc<BE>
|
+ VecZnxDftAlloc<BE>
|
||||||
@@ -40,7 +40,7 @@ where
|
|||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let dnum: usize = k / base2k;
|
let dnum: usize = k / base2k;
|
||||||
|
|
||||||
let tensor_key_infos = TensorKeyLayout {
|
let tensor_key_infos = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k.into(),
|
k: k.into(),
|
||||||
@@ -49,13 +49,16 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tensor_key_infos);
|
let mut tensor_key: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tensor_key_infos);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key_infos));
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWETensorKey::encrypt_sk_tmp_bytes(
|
||||||
|
module,
|
||||||
|
&tensor_key_infos,
|
||||||
|
));
|
||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&tensor_key_infos);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&tensor_key_infos);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
@@ -111,9 +114,9 @@ where
|
|||||||
|
|
||||||
pub fn test_gglwe_tensor_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
pub fn test_gglwe_tensor_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: TensorKeyEncryptSk<BE>
|
Module<BE>: GLWETensorKeyEncryptSk<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ GGLWETensorKeyCompressedEncryptSk<BE>
|
+ GLWETensorKeyCompressedEncryptSk<BE>
|
||||||
+ GLWEDecrypt<BE>
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxDftAlloc<BE>
|
+ VecZnxDftAlloc<BE>
|
||||||
+ VecZnxBigAlloc<BE>
|
+ VecZnxBigAlloc<BE>
|
||||||
@@ -133,7 +136,7 @@ where
|
|||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let dnum: usize = k / base2k;
|
let dnum: usize = k / base2k;
|
||||||
|
|
||||||
let tensor_key_infos: TensorKeyLayout = TensorKeyLayout {
|
let tensor_key_infos: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k.into(),
|
k: k.into(),
|
||||||
@@ -162,7 +165,7 @@ where
|
|||||||
|
|
||||||
tensor_key_compressed.encrypt_sk(module, &sk, seed_xa, &mut source_xe, scratch.borrow());
|
tensor_key_compressed.encrypt_sk(module, &sk, seed_xa, &mut source_xe, scratch.borrow());
|
||||||
|
|
||||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tensor_key_infos);
|
let mut tensor_key: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tensor_key_infos);
|
||||||
tensor_key.decompress(module, &tensor_key_compressed);
|
tensor_key.decompress(module, &tensor_key_compressed);
|
||||||
|
|
||||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&tensor_key_infos);
|
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&tensor_key_infos);
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
GGSWEncryptSk, GGSWKeyswitch, GGSWNoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, TensorKeyEncryptSk,
|
GGSWEncryptSk, GGSWKeyswitch, GGSWNoise, GLWESwitchingKeyEncryptSk, GLWETensorKeyEncryptSk, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGSW, GGSWLayout, GLWESecret, GLWESecretPreparedFactory, GLWESwitchingKey, GLWESwitchingKeyLayout,
|
GGSW, GGSWLayout, GLWESecret, GLWESecretPreparedFactory, GLWESwitchingKey, GLWESwitchingKeyLayout,
|
||||||
GLWESwitchingKeyPreparedFactory, TensorKey, TensorKeyLayout, TensorKeyPreparedFactory,
|
GLWESwitchingKeyPreparedFactory, GLWETensorKey, GLWETensorKeyLayout, GLWETensorKeyPreparedFactory,
|
||||||
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared},
|
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, GLWETensorKeyPrepared},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_keyswitch,
|
noise::noise_ggsw_keyswitch,
|
||||||
};
|
};
|
||||||
@@ -20,10 +20,10 @@ pub fn test_ggsw_keyswitch<BE: Backend>(module: &Module<BE>)
|
|||||||
where
|
where
|
||||||
Module<BE>: GGSWEncryptSk<BE>
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ GLWESwitchingKeyEncryptSk<BE>
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
+ TensorKeyEncryptSk<BE>
|
+ GLWETensorKeyEncryptSk<BE>
|
||||||
+ GGSWKeyswitch<BE>
|
+ GGSWKeyswitch<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ TensorKeyPreparedFactory<BE>
|
+ GLWETensorKeyPreparedFactory<BE>
|
||||||
+ GLWESwitchingKeyPreparedFactory<BE>
|
+ GLWESwitchingKeyPreparedFactory<BE>
|
||||||
+ GGSWNoise<BE>,
|
+ GGSWNoise<BE>,
|
||||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
@@ -61,7 +61,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let tsk_infos: TensorKeyLayout = TensorKeyLayout {
|
let tsk_infos: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_tsk.into(),
|
k: k_tsk.into(),
|
||||||
@@ -82,7 +82,7 @@ where
|
|||||||
|
|
||||||
let mut ggsw_in: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_in_infos);
|
let mut ggsw_in: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_in_infos);
|
||||||
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_infos);
|
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_infos);
|
||||||
let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tsk_infos);
|
let mut tsk: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tsk_infos);
|
||||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&ksk_apply_infos);
|
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&ksk_apply_infos);
|
||||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ where
|
|||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_in_infos)
|
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_in_infos)
|
||||||
| GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &ksk_apply_infos)
|
| GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &ksk_apply_infos)
|
||||||
| TensorKey::encrypt_sk_tmp_bytes(module, &tsk_infos)
|
| GLWETensorKey::encrypt_sk_tmp_bytes(module, &tsk_infos)
|
||||||
| GGSW::keyswitch_tmp_bytes(
|
| GGSW::keyswitch_tmp_bytes(
|
||||||
module,
|
module,
|
||||||
&ggsw_out_infos,
|
&ggsw_out_infos,
|
||||||
@@ -148,7 +148,7 @@ where
|
|||||||
GLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
GLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
||||||
ksk_prepared.prepare(module, &ksk, scratch.borrow());
|
ksk_prepared.prepare(module, &ksk, scratch.borrow());
|
||||||
|
|
||||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> = TensorKeyPrepared::alloc_from_infos(module, &tsk);
|
let mut tsk_prepared: GLWETensorKeyPrepared<Vec<u8>, BE> = GLWETensorKeyPrepared::alloc_from_infos(module, &tsk);
|
||||||
tsk_prepared.prepare(module, &tsk, scratch.borrow());
|
tsk_prepared.prepare(module, &tsk, scratch.borrow());
|
||||||
|
|
||||||
ggsw_out.keyswitch(
|
ggsw_out.keyswitch(
|
||||||
@@ -185,10 +185,10 @@ pub fn test_ggsw_keyswitch_inplace<BE: Backend>(module: &Module<BE>)
|
|||||||
where
|
where
|
||||||
Module<BE>: GGSWEncryptSk<BE>
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ GLWESwitchingKeyEncryptSk<BE>
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
+ TensorKeyEncryptSk<BE>
|
+ GLWETensorKeyEncryptSk<BE>
|
||||||
+ GGSWKeyswitch<BE>
|
+ GGSWKeyswitch<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ TensorKeyPreparedFactory<BE>
|
+ GLWETensorKeyPreparedFactory<BE>
|
||||||
+ GLWESwitchingKeyPreparedFactory<BE>
|
+ GLWESwitchingKeyPreparedFactory<BE>
|
||||||
+ GGSWNoise<BE>,
|
+ GGSWNoise<BE>,
|
||||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
@@ -216,7 +216,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let tsk_infos: TensorKeyLayout = TensorKeyLayout {
|
let tsk_infos: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_tsk.into(),
|
k: k_tsk.into(),
|
||||||
@@ -236,7 +236,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_infos);
|
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_out_infos);
|
||||||
let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tsk_infos);
|
let mut tsk: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tsk_infos);
|
||||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&ksk_apply_infos);
|
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&ksk_apply_infos);
|
||||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ where
|
|||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_out_infos)
|
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_out_infos)
|
||||||
| GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &ksk_apply_infos)
|
| GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &ksk_apply_infos)
|
||||||
| TensorKey::encrypt_sk_tmp_bytes(module, &tsk_infos)
|
| GLWETensorKey::encrypt_sk_tmp_bytes(module, &tsk_infos)
|
||||||
| GGSW::keyswitch_tmp_bytes(
|
| GGSW::keyswitch_tmp_bytes(
|
||||||
module,
|
module,
|
||||||
&ggsw_out_infos,
|
&ggsw_out_infos,
|
||||||
@@ -302,7 +302,7 @@ where
|
|||||||
GLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
GLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
||||||
ksk_prepared.prepare(module, &ksk, scratch.borrow());
|
ksk_prepared.prepare(module, &ksk, scratch.borrow());
|
||||||
|
|
||||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> = TensorKeyPrepared::alloc_from_infos(module, &tsk);
|
let mut tsk_prepared: GLWETensorKeyPrepared<Vec<u8>, BE> = GLWETensorKeyPrepared::alloc_from_infos(module, &tsk);
|
||||||
tsk_prepared.prepare(module, &tsk, scratch.borrow());
|
tsk_prepared.prepare(module, &tsk, scratch.borrow());
|
||||||
|
|
||||||
ggsw_out.keyswitch_inplace(module, &ksk_prepared, &tsk_prepared, scratch.borrow());
|
ggsw_out.keyswitch_inplace(module, &ksk_prepared, &tsk_prepared, scratch.borrow());
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWEPacker, GLWEPacking, GLWERotate, GLWESub, ScratchTakeCore,
|
GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWEPacker, GLWEPacking, GLWERotate, GLWESub, ScratchTakeCore,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext, GLWESecret,
|
GLWE, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext,
|
||||||
GLWESecretPreparedFactory,
|
GLWESecret, GLWESecretPreparedFactory,
|
||||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -18,7 +18,7 @@ use crate::{
|
|||||||
pub fn test_glwe_packing<BE: Backend>(module: &Module<BE>)
|
pub fn test_glwe_packing<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<BE>: GLWEEncryptSk<BE>
|
Module<BE>: GLWEEncryptSk<BE>
|
||||||
+ AutomorphismKeyEncryptSk<BE>
|
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ GLWEPacking<BE>
|
+ GLWEPacking<BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
@@ -49,7 +49,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let key_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -60,7 +60,7 @@ where
|
|||||||
|
|
||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GLWE::encrypt_sk_tmp_bytes(module, &glwe_out_infos)
|
GLWE::encrypt_sk_tmp_bytes(module, &glwe_out_infos)
|
||||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &key_infos)
|
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &key_infos)
|
||||||
| GLWEPacker::tmp_bytes(module, &glwe_out_infos, &key_infos),
|
| GLWEPacker::tmp_bytes(module, &glwe_out_infos, &key_infos),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ where
|
|||||||
let gal_els: Vec<i64> = GLWEPacker::galois_elements(module);
|
let gal_els: Vec<i64> = GLWEPacker::galois_elements(module);
|
||||||
|
|
||||||
let mut auto_keys: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new();
|
let mut auto_keys: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new();
|
||||||
let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&key_infos);
|
let mut tmp: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&key_infos);
|
||||||
gal_els.iter().for_each(|gal_el| {
|
gal_els.iter().for_each(|gal_el| {
|
||||||
tmp.encrypt_sk(
|
tmp.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, ScratchTakeCore,
|
GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
glwe_trace::GLWETrace,
|
glwe_trace::GLWETrace,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext, GLWESecret,
|
GLWE, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext,
|
||||||
GLWESecretPreparedFactory, LWEInfos,
|
GLWESecret, GLWESecretPreparedFactory, LWEInfos,
|
||||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
noise::var_noise_gglwe_product,
|
noise::var_noise_gglwe_product,
|
||||||
@@ -23,7 +23,7 @@ where
|
|||||||
Module<BE>: GLWETrace<BE>
|
Module<BE>: GLWETrace<BE>
|
||||||
+ GLWEEncryptSk<BE>
|
+ GLWEEncryptSk<BE>
|
||||||
+ GLWEDecrypt<BE>
|
+ GLWEDecrypt<BE>
|
||||||
+ AutomorphismKeyEncryptSk<BE>
|
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ GLWESecretPreparedFactory<BE>
|
+ GLWESecretPreparedFactory<BE>
|
||||||
@@ -49,7 +49,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
let key_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_autokey.into(),
|
k: k_autokey.into(),
|
||||||
@@ -69,7 +69,7 @@ where
|
|||||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GLWE::encrypt_sk_tmp_bytes(module, &glwe_out_infos)
|
GLWE::encrypt_sk_tmp_bytes(module, &glwe_out_infos)
|
||||||
| GLWE::decrypt_tmp_bytes(module, &glwe_out_infos)
|
| GLWE::decrypt_tmp_bytes(module, &glwe_out_infos)
|
||||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &key_infos)
|
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &key_infos)
|
||||||
| GLWE::trace_tmp_bytes(module, &glwe_out_infos, &glwe_out_infos, &key_infos),
|
| GLWE::trace_tmp_bytes(module, &glwe_out_infos, &glwe_out_infos, &key_infos),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ where
|
|||||||
|
|
||||||
let mut auto_keys: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new();
|
let mut auto_keys: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new();
|
||||||
let gal_els: Vec<i64> = GLWE::trace_galois_elements(module);
|
let gal_els: Vec<i64> = GLWE::trace_galois_elements(module);
|
||||||
let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&key_infos);
|
let mut tmp: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&key_infos);
|
||||||
gal_els.iter().for_each(|gal_el| {
|
gal_els.iter().for_each(|gal_el| {
|
||||||
tmp.encrypt_sk(
|
tmp.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
|
|||||||
@@ -97,18 +97,23 @@ impl<BE: Backend> ModuleLogN for Module<BE> where Self: ModuleN {}
|
|||||||
|
|
||||||
impl<BE: Backend> CyclotomicOrder for Module<BE> where Self: ModuleN {}
|
impl<BE: Backend> CyclotomicOrder for Module<BE> where Self: ModuleN {}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn galois_element(generator: i64, cyclotomic_order: i64) -> i64 {
|
||||||
|
if generator == 0 {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let g_exp: u64 = mod_exp_u64(GALOISGENERATOR, generator.unsigned_abs() as usize) & (cyclotomic_order - 1) as u64;
|
||||||
|
g_exp as i64 * generator.signum()
|
||||||
|
}
|
||||||
|
|
||||||
pub trait GaloisElement
|
pub trait GaloisElement
|
||||||
where
|
where
|
||||||
Self: CyclotomicOrder,
|
Self: CyclotomicOrder,
|
||||||
{
|
{
|
||||||
// Returns GALOISGENERATOR^|generator| * sign(generator)
|
// Returns GALOISGENERATOR^|generator| * sign(generator)
|
||||||
fn galois_element(&self, generator: i64) -> i64 {
|
fn galois_element(&self, generator: i64) -> i64 {
|
||||||
if generator == 0 {
|
galois_element(generator, self.cyclotomic_order())
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let g_exp: u64 = mod_exp_u64(GALOISGENERATOR, generator.unsigned_abs() as usize) & (self.cyclotomic_order() - 1) as u64;
|
|
||||||
g_exp as i64 * generator.signum()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns gen^-1
|
// Returns gen^-1
|
||||||
|
|||||||
@@ -2,107 +2,46 @@ use std::hint::black_box;
|
|||||||
|
|
||||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||||
use poulpy_backend::{FFT64Avx, FFT64Ref, FFT64Spqlios};
|
use poulpy_backend::{FFT64Avx, FFT64Ref, FFT64Spqlios};
|
||||||
use poulpy_core::layouts::{
|
use poulpy_core::{
|
||||||
AutomorphismKeyLayout, Dsize, GGSW, GGSWLayout, GLWESecret, LWE, LWELayout, LWESecret, TensorKeyLayout,
|
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore,
|
||||||
prepared::PrepareAlloc,
|
layouts::{
|
||||||
|
Dsize, GGSW, GGSWLayout, GGSWPreparedFactory, GLWEAutomorphismKeyLayout, GLWESecret, GLWESecretPreparedFactory,
|
||||||
|
GLWETensorKeyLayout, LWE, LWELayout, LWESecret,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ModuleN, ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace},
|
||||||
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolAlloc,
|
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||||
SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism,
|
|
||||||
VecZnxAutomorphismInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAutomorphismInplace,
|
|
||||||
VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallNegateInplace, VecZnxCopy,
|
|
||||||
VecZnxDftAddInplace, VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf, VecZnxDftCopy, VecZnxFillUniform,
|
|
||||||
VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNegateInplace, VecZnxNormalize, VecZnxNormalizeInplace,
|
|
||||||
VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRotateInplaceTmpBytes, VecZnxRshInplace, VecZnxSub,
|
|
||||||
VecZnxSubInplace, VecZnxSwitchRing, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, VmpPMatAlloc,
|
|
||||||
VmpPrepare, ZnAddNormal, ZnFillUniform, ZnNormalizeInplace,
|
|
||||||
},
|
|
||||||
layouts::{Backend, Module, ScratchOwned},
|
|
||||||
oep::{
|
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeMatZnxImpl, TakeScalarZnxImpl, TakeSliceImpl,
|
|
||||||
TakeSvpPPolImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxDftSliceImpl, TakeVecZnxImpl, TakeVecZnxSliceImpl,
|
|
||||||
},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
use poulpy_schemes::tfhe::{
|
use poulpy_schemes::tfhe::{
|
||||||
blind_rotation::{
|
blind_rotation::{
|
||||||
BlincRotationExecute, BlindRotationAlgo, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk,
|
BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, BlindRotationKeyInfos, BlindRotationKeyLayout, CGGI,
|
||||||
BlindRotationKeyInfos, BlindRotationKeyLayout, BlindRotationKeyPrepared, CGGI,
|
|
||||||
},
|
},
|
||||||
circuit_bootstrapping::{
|
circuit_bootstrapping::{
|
||||||
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout,
|
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout,
|
||||||
CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute,
|
CircuitBootstrappingKeyPrepared, CircuitBootstrappingKeyPreparedFactory, CirtuitBootstrappingExecute,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn benc_circuit_bootstrapping<B: Backend, BRA: BlindRotationAlgo>(c: &mut Criterion, label: &str)
|
pub fn benc_circuit_bootstrapping<BE: Backend, BRA: BlindRotationAlgo>(c: &mut Criterion, label: &str)
|
||||||
where
|
where
|
||||||
Module<B>: ModuleNew<B>
|
Module<BE>: ModuleNew<BE>
|
||||||
+ VecZnxFillUniform
|
+ ModuleN
|
||||||
+ VecZnxAddNormal
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWEExternalProduct<BE>
|
||||||
+ VecZnxDftBytesOf
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ LWEEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ CircuitBootstrappingKeyEncryptSk<BRA, BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ CircuitBootstrappingKeyPreparedFactory<BRA, BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ CirtuitBootstrappingExecute<BRA, BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GGSWPreparedFactory<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWNoise<BE>
|
||||||
+ VecZnxAddInplace
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxNormalize<B>
|
+ VecZnxRotateInplace<BE>,
|
||||||
+ VecZnxSub
|
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>, // TODO find a way to remove this bound or move it to CBT KEY
|
||||||
+ VecZnxAddScalarInplace
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxAutomorphism
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
|
||||||
+ SvpApplyDftToDft<B>
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigAlloc<B>
|
|
||||||
+ VecZnxDftAlloc<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxRshInplace<B>
|
|
||||||
+ VecZnxDftCopy<B>
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ VecZnxBigSubSmallNegateInplace<B>
|
|
||||||
+ VecZnxRotateInplaceTmpBytes
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxDftAddInplace<B>
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ ZnFillUniform
|
|
||||||
+ ZnAddNormal
|
|
||||||
+ ZnNormalizeInplace<B>,
|
|
||||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
|
||||||
B: Backend
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeVecZnxDftSliceImpl<B>
|
|
||||||
+ TakeMatZnxImpl<B>
|
|
||||||
+ TakeVecZnxSliceImpl<B>
|
|
||||||
+ TakeSliceImpl<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
|
|
||||||
BlindRotationKeyPrepared<Vec<u8>, BRA, B>: BlincRotationExecute<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<B>,
|
|
||||||
{
|
{
|
||||||
let group_name: String = format!("circuit_bootstrapping::{label}");
|
let group_name: String = format!("circuit_bootstrapping::{label}");
|
||||||
|
|
||||||
@@ -118,81 +57,33 @@ where
|
|||||||
cbt_infos: CircuitBootstrappingKeyLayout,
|
cbt_infos: CircuitBootstrappingKeyLayout,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runner<B: Backend, BRA: BlindRotationAlgo>(params: &Params) -> impl FnMut()
|
fn runner<BE: Backend, BRA: BlindRotationAlgo>(params: &Params) -> impl FnMut()
|
||||||
where
|
where
|
||||||
Module<B>: ModuleNew<B>
|
Module<BE>: ModuleNew<BE>
|
||||||
+ VecZnxFillUniform
|
+ ModuleN
|
||||||
+ VecZnxAddNormal
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWEExternalProduct<BE>
|
||||||
+ VecZnxDftBytesOf
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ LWEEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ CircuitBootstrappingKeyEncryptSk<BRA, BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ CircuitBootstrappingKeyPreparedFactory<BRA, BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ CirtuitBootstrappingExecute<BRA, BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GGSWPreparedFactory<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWNoise<BE>
|
||||||
+ VecZnxAddInplace
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxNormalize<B>
|
+ VecZnxRotateInplace<BE>,
|
||||||
+ VecZnxSub
|
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>, /* TODO find a way to remove this bound or move it to CBT KEY */
|
||||||
+ VecZnxAddScalarInplace
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxAutomorphism
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
|
||||||
+ SvpApplyDftToDft<B>
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigAlloc<B>
|
|
||||||
+ VecZnxDftAlloc<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxRshInplace<B>
|
|
||||||
+ VecZnxDftCopy<B>
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ VecZnxBigSubSmallNegateInplace<B>
|
|
||||||
+ VecZnxRotateInplaceTmpBytes
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxDftAddInplace<B>
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ ZnFillUniform
|
|
||||||
+ ZnAddNormal
|
|
||||||
+ ZnNormalizeInplace<B>,
|
|
||||||
B: Backend
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeVecZnxDftSliceImpl<B>
|
|
||||||
+ TakeMatZnxImpl<B>
|
|
||||||
+ TakeVecZnxSliceImpl<B>
|
|
||||||
+ TakeSliceImpl<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
|
|
||||||
BlindRotationKeyPrepared<Vec<u8>, BRA, B>: BlincRotationExecute<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<B>,
|
|
||||||
{
|
{
|
||||||
// Scratch space (4MB)
|
// Scratch space (4MB)
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(1 << 22);
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||||
|
|
||||||
let n_glwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_glwe();
|
let n_glwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_glwe();
|
||||||
let n_lwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_lwe();
|
let n_lwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_lwe();
|
||||||
let rank: poulpy_core::layouts::Rank = params.cbt_infos.layout_brk.rank;
|
let rank: poulpy_core::layouts::Rank = params.cbt_infos.layout_brk.rank;
|
||||||
|
|
||||||
let module: Module<B> = Module::<B>::new(n_glwe.as_u32() as u64);
|
let module: Module<BE> = Module::<BE>::new(n_glwe.as_u32() as u64);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([1u8; 32]);
|
let mut source_xa: Source = Source::new([1u8; 32]);
|
||||||
@@ -208,19 +99,20 @@ where
|
|||||||
let ct_lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(¶ms.lwe_infos);
|
let ct_lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(¶ms.lwe_infos);
|
||||||
|
|
||||||
// Circuit bootstrapping evaluation key
|
// Circuit bootstrapping evaluation key
|
||||||
let cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::encrypt_sk(
|
let mut cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::alloc_from_infos(¶ms.cbt_infos);
|
||||||
|
cbt_key.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
&sk_lwe,
|
&sk_lwe,
|
||||||
&sk_glwe,
|
&sk_glwe,
|
||||||
¶ms.cbt_infos,
|
|
||||||
&mut source_xa,
|
&mut source_xa,
|
||||||
&mut source_xe,
|
&mut source_xe,
|
||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(¶ms.ggsw_infos);
|
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(¶ms.ggsw_infos);
|
||||||
let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> = cbt_key.prepare_alloc(&module, scratch.borrow());
|
let mut cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, BE> =
|
||||||
|
CircuitBootstrappingKeyPrepared::alloc_from_infos(&module, ¶ms.cbt_infos);
|
||||||
|
cbt_prepared.prepare(&module, &cbt_key, scratch.borrow());
|
||||||
move || {
|
move || {
|
||||||
cbt_prepared.execute_to_constant(
|
cbt_prepared.execute_to_constant(
|
||||||
&module,
|
&module,
|
||||||
@@ -261,7 +153,7 @@ where
|
|||||||
dnum: 3_u32.into(),
|
dnum: 3_u32.into(),
|
||||||
rank: 2_u32.into(),
|
rank: 2_u32.into(),
|
||||||
},
|
},
|
||||||
layout_atk: AutomorphismKeyLayout {
|
layout_atk: GLWEAutomorphismKeyLayout {
|
||||||
n: 1024_u32.into(),
|
n: 1024_u32.into(),
|
||||||
base2k: 13_u32.into(),
|
base2k: 13_u32.into(),
|
||||||
k: 52_u32.into(),
|
k: 52_u32.into(),
|
||||||
@@ -269,7 +161,7 @@ where
|
|||||||
dsize: Dsize(1),
|
dsize: Dsize(1),
|
||||||
rank: 2_u32.into(),
|
rank: 2_u32.into(),
|
||||||
},
|
},
|
||||||
layout_tsk: TensorKeyLayout {
|
layout_tsk: GLWETensorKeyLayout {
|
||||||
n: 1024_u32.into(),
|
n: 1024_u32.into(),
|
||||||
base2k: 13_u32.into(),
|
base2k: 13_u32.into(),
|
||||||
k: 52_u32.into(),
|
k: 52_u32.into(),
|
||||||
@@ -280,7 +172,7 @@ where
|
|||||||
},
|
},
|
||||||
}] {
|
}] {
|
||||||
let id: BenchmarkId = BenchmarkId::from_parameter(params.name.clone());
|
let id: BenchmarkId = BenchmarkId::from_parameter(params.name.clone());
|
||||||
let mut runner = runner::<B, BRA>(¶ms);
|
let mut runner = runner::<BE, BRA>(¶ms);
|
||||||
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use poulpy_core::{
|
use poulpy_core::{
|
||||||
GLWEOperations,
|
GLWENormalize,
|
||||||
layouts::{
|
layouts::{
|
||||||
AutomorphismKeyLayout, GGSW, GGSWLayout, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, LWE, LWEInfos, LWELayout,
|
GGSW, GGSWLayout, GLWE, GLWEAutomorphismKeyLayout, GLWELayout, GLWEPlaintext, GLWESecret, GLWETensorKeyLayout, LWE,
|
||||||
LWEPlaintext, LWESecret, TensorKeyLayout,
|
LWEInfos, LWELayout, LWEPlaintext, LWESecret,
|
||||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGSWPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
@@ -22,10 +22,7 @@ use poulpy_hal::{
|
|||||||
|
|
||||||
use poulpy_schemes::tfhe::{
|
use poulpy_schemes::tfhe::{
|
||||||
blind_rotation::{BlindRotationKeyLayout, CGGI},
|
blind_rotation::{BlindRotationKeyLayout, CGGI},
|
||||||
circuit_bootstrapping::{
|
circuit_bootstrapping::{CircuitBootstrappingKey, CircuitBootstrappingKeyLayout, CircuitBootstrappingKeyPrepared},
|
||||||
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout,
|
|
||||||
CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -89,7 +86,7 @@ fn main() {
|
|||||||
dnum: rows_brk.into(),
|
dnum: rows_brk.into(),
|
||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
},
|
},
|
||||||
layout_atk: AutomorphismKeyLayout {
|
layout_atk: GLWEAutomorphismKeyLayout {
|
||||||
n: n_glwe.into(),
|
n: n_glwe.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_trace.into(),
|
k: k_trace.into(),
|
||||||
@@ -97,7 +94,7 @@ fn main() {
|
|||||||
dsize: 1_u32.into(),
|
dsize: 1_u32.into(),
|
||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
},
|
},
|
||||||
layout_tsk: TensorKeyLayout {
|
layout_tsk: GLWETensorKeyLayout {
|
||||||
n: n_glwe.into(),
|
n: n_glwe.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_tsk.into(),
|
k: k_tsk.into(),
|
||||||
@@ -145,7 +142,8 @@ fn main() {
|
|||||||
// sk_glwe.fill_zero();
|
// sk_glwe.fill_zero();
|
||||||
|
|
||||||
// GLWE secret prepared (opaque backend dependant write only struct)
|
// GLWE secret prepared (opaque backend dependant write only struct)
|
||||||
let sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, BackendImpl> = sk_glwe.prepare_alloc(&module, scratch.borrow());
|
let mut sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, BackendImpl> = GLWESecretPrepared::alloc(&module, rank.into());
|
||||||
|
sk_glwe_prepared.prepare(&module, &sk_glwe);
|
||||||
|
|
||||||
// Plaintext value to circuit bootstrap
|
// Plaintext value to circuit bootstrap
|
||||||
let data: i64 = 1 % (1 << k_lwe_pt);
|
let data: i64 = 1 % (1 << k_lwe_pt);
|
||||||
@@ -175,23 +173,26 @@ fn main() {
|
|||||||
let now: Instant = Instant::now();
|
let now: Instant = Instant::now();
|
||||||
|
|
||||||
// Circuit bootstrapping evaluation key
|
// Circuit bootstrapping evaluation key
|
||||||
let cbt_key: CircuitBootstrappingKey<Vec<u8>, CGGI> = CircuitBootstrappingKey::encrypt_sk(
|
let mut cbt_key: CircuitBootstrappingKey<Vec<u8>, CGGI> = CircuitBootstrappingKey::alloc_from_infos(&cbt_infos);
|
||||||
|
|
||||||
|
cbt_key.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
&sk_lwe,
|
&sk_lwe,
|
||||||
&sk_glwe,
|
&sk_glwe,
|
||||||
&cbt_infos,
|
|
||||||
&mut source_xa,
|
&mut source_xa,
|
||||||
&mut source_xe,
|
&mut source_xe,
|
||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
|
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
|
||||||
|
|
||||||
// Output GGSW
|
// Output GGSW
|
||||||
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_infos);
|
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_infos);
|
||||||
|
|
||||||
// Circuit bootstrapping key prepared (opaque backend dependant write only struct)
|
// Circuit bootstrapping key prepared (opaque backend dependant write only struct)
|
||||||
let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, CGGI, BackendImpl> =
|
let mut cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, CGGI, BackendImpl> =
|
||||||
cbt_key.prepare_alloc(&module, scratch.borrow());
|
CircuitBootstrappingKeyPrepared::alloc_from_infos(&module, &cbt_infos);
|
||||||
|
cbt_prepared.prepare(&module, &cbt_key, scratch.borrow());
|
||||||
|
|
||||||
// Apply circuit bootstrapping: LWE(data * 2^{- (k_lwe_pt + 2)}) -> GGSW(data)
|
// Apply circuit bootstrapping: LWE(data * 2^{- (k_lwe_pt + 2)}) -> GGSW(data)
|
||||||
let now: Instant = Instant::now();
|
let now: Instant = Instant::now();
|
||||||
@@ -234,7 +235,7 @@ fn main() {
|
|||||||
.for_each(|(x, y)| *y = (x % (1 << (k_glwe_pt - 1))) as i64 - (1 << (k_glwe_pt - 2)));
|
.for_each(|(x, y)| *y = (x % (1 << (k_glwe_pt - 1))) as i64 - (1 << (k_glwe_pt - 2)));
|
||||||
|
|
||||||
pt_glwe.encode_vec_i64(&data_vec, (k_lwe_pt + 2).into());
|
pt_glwe.encode_vec_i64(&data_vec, (k_lwe_pt + 2).into());
|
||||||
pt_glwe.normalize_inplace(&module, scratch.borrow());
|
module.glwe_normalize_inplace(&mut pt_glwe, scratch.borrow());
|
||||||
|
|
||||||
println!("{}", pt_glwe);
|
println!("{}", pt_glwe);
|
||||||
|
|
||||||
@@ -249,7 +250,8 @@ fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Prepare GGSW output of circuit bootstrapping (opaque backend dependant write only struct)
|
// Prepare GGSW output of circuit bootstrapping (opaque backend dependant write only struct)
|
||||||
let res_prepared: GGSWPrepared<Vec<u8>, BackendImpl> = res.prepare_alloc(&module, scratch.borrow());
|
let mut res_prepared: GGSWPrepared<Vec<u8>, BackendImpl> = GGSWPrepared::alloc_from_infos(&module, &res);
|
||||||
|
res_prepared.prepare(&module, &res, scratch.borrow());
|
||||||
|
|
||||||
// Apply GLWE x GGSW
|
// Apply GLWE x GGSW
|
||||||
ct_glwe.external_product_inplace(&module, &res_prepared, scratch.borrow());
|
ct_glwe.external_product_inplace(&module, &res_prepared, scratch.borrow());
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ impl<D: DataRef> BlindRotationKeyFactory<CGGI> for BlindRotationKey<D, CGGI> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> BlindRotationKeyEncryptSk<BE, CGGI> for Module<BE>
|
impl<BE: Backend> BlindRotationKeyEncryptSk<CGGI, BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: GGSWEncryptSk<BE>,
|
Self: GGSWEncryptSk<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::tfhe::blind_rotation::{
|
|||||||
utils::set_xai_plus_y,
|
utils::set_xai_plus_y,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<BE: Backend> BlindRotationKeyPreparedFactory<BE, CGGI> for Module<BE>
|
impl<BE: Backend> BlindRotationKeyPreparedFactory<CGGI, BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: GGSWPreparedFactory<BE> + SvpPPolAlloc<BE> + SvpPrepare<BE>,
|
Self: GGSWPreparedFactory<BE> + SvpPPolAlloc<BE> + SvpPrepare<BE>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use poulpy_core::{
|
|||||||
|
|
||||||
use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey};
|
use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey};
|
||||||
|
|
||||||
pub trait BlindRotationKeyEncryptSk<B: Backend, BRA: BlindRotationAlgo> {
|
pub trait BlindRotationKeyEncryptSk<BRA: BlindRotationAlgo, B: Backend> {
|
||||||
fn blind_rotation_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn blind_rotation_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGSWInfos;
|
A: GGSWInfos;
|
||||||
@@ -43,7 +43,7 @@ impl<D: DataMut, BRA: BlindRotationAlgo> BlindRotationKey<D, BRA> {
|
|||||||
S0: GLWESecretPreparedToRef<BE> + GLWEInfos,
|
S0: GLWESecretPreparedToRef<BE> + GLWEInfos,
|
||||||
S1: LWESecretToRef + LWEInfos + GetDistribution,
|
S1: LWESecretToRef + LWEInfos + GetDistribution,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
M: BlindRotationKeyEncryptSk<BE, BRA>,
|
M: BlindRotationKeyEncryptSk<BRA, BE>,
|
||||||
{
|
{
|
||||||
module.blind_rotation_key_encrypt_sk(self, sk_glwe, sk_lwe, source_xa, source_xe, scratch);
|
module.blind_rotation_key_encrypt_sk(self, sk_glwe, sk_lwe, source_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ impl<BRA: BlindRotationAlgo> BlindRotationKey<Vec<u8>, BRA> {
|
|||||||
pub fn encrypt_sk_tmp_bytes<A, M, BE: Backend>(module: &M, infos: &A) -> usize
|
pub fn encrypt_sk_tmp_bytes<A, M, BE: Backend>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGSWInfos,
|
A: GGSWInfos,
|
||||||
M: BlindRotationKeyEncryptSk<BE, BRA>,
|
M: BlindRotationKeyEncryptSk<BRA, BE>,
|
||||||
{
|
{
|
||||||
module.blind_rotation_key_encrypt_sk_tmp_bytes(infos)
|
module.blind_rotation_key_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Scratch, SvpPPol};
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use poulpy_core::{
|
use poulpy_core::{
|
||||||
Distribution, ScratchTakeCore,
|
Distribution,
|
||||||
layouts::{Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared},
|
layouts::{Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyInfos};
|
use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyInfos};
|
||||||
|
|
||||||
pub trait BlindRotationKeyPreparedFactory<BE: Backend, BRA: BlindRotationAlgo> {
|
pub trait BlindRotationKeyPreparedFactory<BRA: BlindRotationAlgo, BE: Backend> {
|
||||||
fn blind_rotation_key_prepared_alloc<A>(&self, infos: &A) -> BlindRotationKeyPrepared<Vec<u8>, BRA, BE>
|
fn blind_rotation_key_prepared_alloc<A>(&self, infos: &A) -> BlindRotationKeyPrepared<Vec<u8>, BRA, BE>
|
||||||
where
|
where
|
||||||
A: BlindRotationKeyInfos;
|
A: BlindRotationKeyInfos;
|
||||||
@@ -21,27 +21,23 @@ pub trait BlindRotationKeyPreparedFactory<BE: Backend, BRA: BlindRotationAlgo> {
|
|||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DM: DataMut,
|
DM: DataMut,
|
||||||
DR: DataRef,
|
DR: DataRef;
|
||||||
Scratch<BE>: ScratchTakeCore<BE>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend, BRA: BlindRotationAlgo> BlindRotationKeyPrepared<Vec<u8>, BRA, BE> {
|
impl<BE: Backend, BRA: BlindRotationAlgo> BlindRotationKeyPrepared<Vec<u8>, BRA, BE> {
|
||||||
pub fn alloc<A, M>(module: &M, infos: &A) -> Self
|
pub fn alloc<A, M>(module: &M, infos: &A) -> Self
|
||||||
where
|
where
|
||||||
A: BlindRotationKeyInfos,
|
A: BlindRotationKeyInfos,
|
||||||
M: BlindRotationKeyPreparedFactory<BE, BRA>,
|
M: BlindRotationKeyPreparedFactory<BRA, BE>,
|
||||||
{
|
{
|
||||||
module.blind_rotation_key_prepared_alloc(infos)
|
module.blind_rotation_key_prepared_alloc(infos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, BRA: BlindRotationAlgo, BE: Backend> BlindRotationKeyPrepared<D, BRA, BE>
|
impl<D: DataMut, BRA: BlindRotationAlgo, BE: Backend> BlindRotationKeyPrepared<D, BRA, BE> {
|
||||||
where
|
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
|
||||||
{
|
|
||||||
pub fn prepare<DR: DataRef, M>(&mut self, module: &M, other: &BlindRotationKey<DR, BRA>, scratch: &mut Scratch<BE>)
|
pub fn prepare<DR: DataRef, M>(&mut self, module: &M, other: &BlindRotationKey<DR, BRA>, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
M: BlindRotationKeyPreparedFactory<BE, BRA>,
|
M: BlindRotationKeyPreparedFactory<BRA, BE>,
|
||||||
{
|
{
|
||||||
module.blind_rotation_key_prepare(self, other, scratch);
|
module.blind_rotation_key_prepare(self, other, scratch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,13 @@ pub fn test_blind_rotation<BRA: BlindRotationAlgo, M, BE: Backend>(
|
|||||||
block_size: usize,
|
block_size: usize,
|
||||||
extension_factor: usize,
|
extension_factor: usize,
|
||||||
) where
|
) where
|
||||||
M: BlindRotationKeyEncryptSk<BE, BRA>
|
M: BlindRotationKeyEncryptSk<BRA, BE>
|
||||||
+ BlindRotationKeyPreparedFactory<BE, BRA>
|
+ BlindRotationKeyPreparedFactory<BRA, BE>
|
||||||
+ BlindRotationExecute<BRA, BE>
|
+ BlindRotationExecute<BRA, BE>
|
||||||
+ GLWESecretPreparedFactory<BE>
|
|
||||||
+ BlindRotationExecute<BRA, BE>
|
|
||||||
+ LWEEncryptSk<BE>
|
|
||||||
+ LookupTableFactory
|
+ LookupTableFactory
|
||||||
+ GLWEDecrypt<BE>,
|
+ GLWESecretPreparedFactory<BE>
|
||||||
|
+ GLWEDecrypt<BE>
|
||||||
|
+ LWEEncryptSk<BE>,
|
||||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
|
|||||||
@@ -1,185 +1,182 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ModuleLogN, ModuleN, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||||
ScratchAvailable, TakeMatZnx, TakeSlice, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice, TakeVecZnxSlice,
|
layouts::{Backend, DataRef, Module, Scratch, ScratchOwned, ToOwnedDeep},
|
||||||
VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace, VecZnxBigBytesOf,
|
|
||||||
VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallNegateInplace, VecZnxCopy, VecZnxDftAddInplace,
|
|
||||||
VecZnxDftApply, VecZnxDftBytesOf, VecZnxDftCopy, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNegateInplace,
|
|
||||||
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace,
|
|
||||||
VecZnxRotateInplaceTmpBytes, VecZnxRshInplace, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, VmpApplyDftToDft,
|
|
||||||
VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes,
|
|
||||||
},
|
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch, ToOwnedDeep},
|
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use poulpy_core::{
|
use poulpy_core::{
|
||||||
GLWEOperations, TakeGGLWE, TakeGLWE,
|
GGSWFromGGLWE, GLWEPacking, GLWETrace, ScratchTakeCore,
|
||||||
layouts::{Dsize, GGLWELayout, GGSWInfos, GLWEInfos, LWEInfos},
|
layouts::{Dsize, GGLWELayout, GGSWInfos, GGSWToMut, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, LWEToRef},
|
||||||
};
|
};
|
||||||
|
|
||||||
use poulpy_core::glwe_packing;
|
|
||||||
use poulpy_core::layouts::{GGSW, GLWE, LWE, prepared::GLWEAutomorphismKeyPrepared};
|
use poulpy_core::layouts::{GGSW, GLWE, LWE, prepared::GLWEAutomorphismKeyPrepared};
|
||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
blind_rotation::{
|
blind_rotation::{
|
||||||
BlincRotationExecute, BlindRotationAlgo, BlindRotationKeyPrepared, LookUpTable, LookUpTableRotationDirection,
|
BlindRotationAlgo, BlindRotationExecute, LookUpTableLayout, LookUpTableRotationDirection, LookupTable, LookupTableFactory,
|
||||||
},
|
},
|
||||||
circuit_bootstrapping::{CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute},
|
circuit_bootstrapping::CircuitBootstrappingKeyPrepared,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<D: DataRef, BRA: BlindRotationAlgo, B> CirtuitBootstrappingExecute<B> for CircuitBootstrappingKeyPrepared<D, BRA, B>
|
pub trait CirtuitBootstrappingExecute<BRA: BlindRotationAlgo, BE: Backend> {
|
||||||
where
|
fn circuit_bootstrapping_execute_to_constant<R, L, D>(
|
||||||
Module<B>: VecZnxRotateInplace<B>
|
|
||||||
+ VecZnxNormalizeInplace<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxRshInplace<B>
|
|
||||||
+ VecZnxDftCopy<B>
|
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ VecZnxAddInplace
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxSubInplace
|
|
||||||
+ VecZnxDftBytesOf
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ VecZnxDftApply<B>
|
|
||||||
+ VecZnxIdftApplyConsume<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ VecZnxBigSubSmallNegateInplace<B>
|
|
||||||
+ VecZnxRotateInplaceTmpBytes
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxDftAddInplace<B>
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ VecZnxNormalize<B>,
|
|
||||||
B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
|
||||||
Scratch<B>: TakeVecZnx
|
|
||||||
+ TakeVecZnxDftSlice<B>
|
|
||||||
+ TakeVecZnxBig<B>
|
|
||||||
+ TakeVecZnxDft<B>
|
|
||||||
+ TakeMatZnx
|
|
||||||
+ ScratchAvailable
|
|
||||||
+ TakeVecZnxSlice
|
|
||||||
+ TakeSlice,
|
|
||||||
BlindRotationKeyPrepared<D, BRA, B>: BlincRotationExecute<B>,
|
|
||||||
{
|
|
||||||
fn execute_to_constant<DM: DataMut, DR: DataRef>(
|
|
||||||
&self,
|
&self,
|
||||||
module: &Module<B>,
|
res: &mut R,
|
||||||
res: &mut GGSW<DM>,
|
lwe: &L,
|
||||||
lwe: &LWE<DR>,
|
key: &CircuitBootstrappingKeyPrepared<D, BRA, BE>,
|
||||||
log_domain: usize,
|
log_domain: usize,
|
||||||
extension_factor: usize,
|
extension_factor: usize,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<BE>,
|
||||||
) {
|
) where
|
||||||
|
R: GGSWToMut + GGSWInfos,
|
||||||
|
L: LWEToRef + LWEInfos,
|
||||||
|
D: DataRef;
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn circuit_bootstrapping_execute_to_exponent<R, L, D>(
|
||||||
|
&self,
|
||||||
|
log_gap_out: usize,
|
||||||
|
res: &mut R,
|
||||||
|
lwe: &L,
|
||||||
|
key: &CircuitBootstrappingKeyPrepared<D, BRA, BE>,
|
||||||
|
log_domain: usize,
|
||||||
|
extension_factor: usize,
|
||||||
|
scratch: &mut Scratch<BE>,
|
||||||
|
) where
|
||||||
|
R: GGSWToMut + GGSWInfos,
|
||||||
|
L: LWEToRef + LWEInfos,
|
||||||
|
D: DataRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<D: DataRef, BRA: BlindRotationAlgo, BE: Backend> CircuitBootstrappingKeyPrepared<D, BRA, BE> {
|
||||||
|
pub fn execute_to_constant<M, L, R>(
|
||||||
|
&self,
|
||||||
|
module: &M,
|
||||||
|
res: &mut R,
|
||||||
|
lwe: &L,
|
||||||
|
log_domain: usize,
|
||||||
|
extension_factor: usize,
|
||||||
|
scratch: &mut Scratch<BE>,
|
||||||
|
) where
|
||||||
|
M: CirtuitBootstrappingExecute<BRA, BE>,
|
||||||
|
R: GGSWToMut + GGSWInfos,
|
||||||
|
L: LWEToRef + LWEInfos,
|
||||||
|
{
|
||||||
|
module.circuit_bootstrapping_execute_to_constant(res, lwe, self, log_domain, extension_factor, scratch);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute_to_exponent<R, L, M>(
|
||||||
|
&self,
|
||||||
|
module: &M,
|
||||||
|
log_gap_out: usize,
|
||||||
|
res: &mut R,
|
||||||
|
lwe: &L,
|
||||||
|
log_domain: usize,
|
||||||
|
extension_factor: usize,
|
||||||
|
scratch: &mut Scratch<BE>,
|
||||||
|
) where
|
||||||
|
M: CirtuitBootstrappingExecute<BRA, BE>,
|
||||||
|
R: GGSWToMut + GGSWInfos,
|
||||||
|
L: LWEToRef + LWEInfos,
|
||||||
|
{
|
||||||
|
module.circuit_bootstrapping_execute_to_exponent(
|
||||||
|
log_gap_out,
|
||||||
|
res,
|
||||||
|
lwe,
|
||||||
|
self,
|
||||||
|
log_domain,
|
||||||
|
extension_factor,
|
||||||
|
scratch,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<BRA: BlindRotationAlgo, BE: Backend> CirtuitBootstrappingExecute<BRA, BE> for Module<BE>
|
||||||
|
where
|
||||||
|
Self: ModuleN + LookupTableFactory + BlindRotationExecute<BRA, BE> + GLWETrace<BE> + GLWEPacking<BE> + GGSWFromGGLWE<BE>,
|
||||||
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
|
{
|
||||||
|
fn circuit_bootstrapping_execute_to_constant<R, L, D>(
|
||||||
|
&self,
|
||||||
|
res: &mut R,
|
||||||
|
lwe: &L,
|
||||||
|
key: &CircuitBootstrappingKeyPrepared<D, BRA, BE>,
|
||||||
|
log_domain: usize,
|
||||||
|
extension_factor: usize,
|
||||||
|
scratch: &mut Scratch<BE>,
|
||||||
|
) where
|
||||||
|
R: GGSWToMut + GGSWInfos,
|
||||||
|
L: LWEToRef + LWEInfos,
|
||||||
|
D: DataRef,
|
||||||
|
{
|
||||||
circuit_bootstrap_core(
|
circuit_bootstrap_core(
|
||||||
false,
|
false,
|
||||||
module,
|
self,
|
||||||
0,
|
0,
|
||||||
res,
|
res,
|
||||||
lwe,
|
lwe,
|
||||||
log_domain,
|
log_domain,
|
||||||
extension_factor,
|
extension_factor,
|
||||||
self,
|
key,
|
||||||
scratch,
|
scratch,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_to_exponent<DM: DataMut, DR: DataRef>(
|
fn circuit_bootstrapping_execute_to_exponent<R, L, D>(
|
||||||
&self,
|
&self,
|
||||||
module: &Module<B>,
|
|
||||||
log_gap_out: usize,
|
log_gap_out: usize,
|
||||||
res: &mut GGSW<DM>,
|
res: &mut R,
|
||||||
lwe: &LWE<DR>,
|
lwe: &L,
|
||||||
|
key: &CircuitBootstrappingKeyPrepared<D, BRA, BE>,
|
||||||
log_domain: usize,
|
log_domain: usize,
|
||||||
extension_factor: usize,
|
extension_factor: usize,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<BE>,
|
||||||
) {
|
) where
|
||||||
|
R: GGSWToMut + GGSWInfos,
|
||||||
|
L: LWEToRef + LWEInfos,
|
||||||
|
D: DataRef,
|
||||||
|
{
|
||||||
circuit_bootstrap_core(
|
circuit_bootstrap_core(
|
||||||
true,
|
true,
|
||||||
module,
|
self,
|
||||||
log_gap_out,
|
log_gap_out,
|
||||||
res,
|
res,
|
||||||
lwe,
|
lwe,
|
||||||
log_domain,
|
log_domain,
|
||||||
extension_factor,
|
extension_factor,
|
||||||
self,
|
key,
|
||||||
scratch,
|
scratch,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>(
|
pub fn circuit_bootstrap_core<R, L, D, M, BRA: BlindRotationAlgo, BE: Backend>(
|
||||||
to_exponent: bool,
|
to_exponent: bool,
|
||||||
module: &Module<B>,
|
module: &M,
|
||||||
log_gap_out: usize,
|
log_gap_out: usize,
|
||||||
res: &mut GGSW<DRes>,
|
res: &mut R,
|
||||||
lwe: &LWE<DLwe>,
|
lwe: &L,
|
||||||
log_domain: usize,
|
log_domain: usize,
|
||||||
extension_factor: usize,
|
extension_factor: usize,
|
||||||
key: &CircuitBootstrappingKeyPrepared<DBrk, BRA, B>,
|
key: &CircuitBootstrappingKeyPrepared<D, BRA, BE>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DRes: DataMut,
|
R: GGSWToMut,
|
||||||
DLwe: DataRef,
|
L: LWEToRef,
|
||||||
DBrk: DataRef,
|
D: DataRef,
|
||||||
Module<B>: VecZnxRotateInplace<B>
|
M: ModuleN + LookupTableFactory + BlindRotationExecute<BRA, BE> + GLWETrace<BE> + GLWEPacking<BE> + GGSWFromGGLWE<BE>,
|
||||||
+ VecZnxNormalizeInplace<B>
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxNormalizeTmpBytes
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxRshInplace<B>
|
|
||||||
+ VecZnxDftCopy<B>
|
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ VecZnxAddInplace
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxSubInplace
|
|
||||||
+ VecZnxDftBytesOf
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ VecZnxDftApply<B>
|
|
||||||
+ VecZnxIdftApplyConsume<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ VecZnxBigSubSmallNegateInplace<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxDftAddInplace<B>
|
|
||||||
+ VecZnxRotateInplaceTmpBytes
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ VecZnxNormalize<B>,
|
|
||||||
B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
|
||||||
Scratch<B>: TakeVecZnxDftSlice<B>
|
|
||||||
+ TakeVecZnxBig<B>
|
|
||||||
+ TakeVecZnxDft<B>
|
|
||||||
+ TakeVecZnx
|
|
||||||
+ ScratchAvailable
|
|
||||||
+ TakeVecZnxSlice
|
|
||||||
+ TakeMatZnx
|
|
||||||
+ TakeSlice,
|
|
||||||
BlindRotationKeyPrepared<DBrk, BRA, B>: BlincRotationExecute<B>,
|
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||||
{
|
let lwe: &LWE<&[u8]> = &lwe.to_ref();
|
||||||
use poulpy_core::layouts::LWEInfos;
|
|
||||||
|
|
||||||
assert_eq!(res.n(), key.brk.n());
|
assert_eq!(res.n(), key.brk.n());
|
||||||
assert_eq!(lwe.base2k(), key.brk.base2k());
|
assert_eq!(lwe.base2k(), key.brk.base2k());
|
||||||
assert_eq!(res.base2k(), key.brk.base2k());
|
assert_eq!(res.base2k(), key.brk.base2k());
|
||||||
}
|
|
||||||
|
|
||||||
let n: usize = res.n().into();
|
let n: usize = res.n().into();
|
||||||
let base2k: usize = res.base2k().into();
|
let base2k: usize = res.base2k().into();
|
||||||
@@ -203,8 +200,15 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lut_infos: LookUpTableLayout = LookUpTableLayout {
|
||||||
|
n: module.n().into(),
|
||||||
|
extension_factor,
|
||||||
|
k: (base2k * dnum).into(),
|
||||||
|
base2k: base2k.into(),
|
||||||
|
};
|
||||||
|
|
||||||
// Lut precision, basically must be able to hold the decomposition power basis of the GGSW
|
// Lut precision, basically must be able to hold the decomposition power basis of the GGSW
|
||||||
let mut lut: LookUpTable = LookUpTable::alloc(module, base2k, base2k * dnum, extension_factor);
|
let mut lut: LookupTable = LookupTable::alloc(&lut_infos);
|
||||||
lut.set(module, &f, base2k * dnum);
|
lut.set(module, &f, base2k * dnum);
|
||||||
|
|
||||||
if to_exponent {
|
if to_exponent {
|
||||||
@@ -212,7 +216,7 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: separate GGSW k from output of blind rotation k
|
// TODO: separate GGSW k from output of blind rotation k
|
||||||
let (mut res_glwe, scratch_1) = scratch.take_glwe_ct(res);
|
let (mut res_glwe, scratch_1) = scratch.take_glwe(res);
|
||||||
|
|
||||||
let gglwe_infos: GGLWELayout = GGLWELayout {
|
let gglwe_infos: GGLWELayout = GGLWELayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
@@ -252,7 +256,7 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if i < dnum {
|
if i < dnum {
|
||||||
res_glwe.rotate_inplace(module, -(gap as i64), scratch_2);
|
module.glwe_rotate_inplace(-(gap as i64), &mut res_glwe, scratch_2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -261,46 +265,24 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn post_process<DataRes, DataA, B: Backend>(
|
fn post_process<R, A, M, BE: Backend>(
|
||||||
module: &Module<B>,
|
module: &M,
|
||||||
res: &mut GLWE<DataRes>,
|
res: &mut R,
|
||||||
a: &GLWE<DataA>,
|
a: &A,
|
||||||
log_gap_in: usize,
|
log_gap_in: usize,
|
||||||
log_gap_out: usize,
|
log_gap_out: usize,
|
||||||
log_domain: usize,
|
log_domain: usize,
|
||||||
auto_keys: &HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
auto_keys: &HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
DataRes: DataMut,
|
R: GLWEToMut,
|
||||||
DataA: DataRef,
|
A: GLWEToRef,
|
||||||
Module<B>: VecZnxRotateInplace<B>
|
M: ModuleLogN + GLWETrace<BE> + GLWEPacking<BE>,
|
||||||
+ VecZnxNormalizeInplace<B>
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxRshInplace<B>
|
|
||||||
+ VecZnxDftCopy<B>
|
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ VecZnxAddInplace
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxSubInplace
|
|
||||||
+ VecZnxDftBytesOf
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ VecZnxDftApply<B>
|
|
||||||
+ VecZnxIdftApplyConsume<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ VecZnxBigSubSmallNegateInplace<B>
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ VecZnxNormalize<B>,
|
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
|
||||||
{
|
{
|
||||||
|
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
|
||||||
|
let a: &GLWE<&[u8]> = &a.to_ref();
|
||||||
|
|
||||||
let log_n: usize = module.log_n();
|
let log_n: usize = module.log_n();
|
||||||
|
|
||||||
let mut cts: HashMap<usize, &mut GLWE<Vec<u8>>> = HashMap::new();
|
let mut cts: HashMap<usize, &mut GLWE<Vec<u8>>> = HashMap::new();
|
||||||
@@ -326,7 +308,7 @@ fn post_process<DataRes, DataA, B: Backend>(
|
|||||||
|
|
||||||
for i in 0..steps {
|
for i in 0..steps {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
res.rotate_inplace(module, -(1 << log_gap_in), scratch);
|
module.glwe_rotate_inplace(-(1 << log_gap_in), res, scratch);
|
||||||
}
|
}
|
||||||
cts_vec.push(res.to_owned_deep());
|
cts_vec.push(res.to_owned_deep());
|
||||||
}
|
}
|
||||||
@@ -335,7 +317,8 @@ fn post_process<DataRes, DataA, B: Backend>(
|
|||||||
cts.insert(i * (1 << log_gap_out), ct);
|
cts.insert(i * (1 << log_gap_out), ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
glwe_packing(module, &mut cts, log_gap_out, auto_keys, scratch);
|
module.glwe_pack(&mut cts, log_gap_out, auto_keys, scratch);
|
||||||
|
|
||||||
let packed: &mut GLWE<Vec<u8>> = cts.remove(&0).unwrap();
|
let packed: &mut GLWE<Vec<u8>> = cts.remove(&0).unwrap();
|
||||||
res.trace(
|
res.trace(
|
||||||
module,
|
module,
|
||||||
|
|||||||
@@ -1,41 +1,38 @@
|
|||||||
use poulpy_core::layouts::{
|
use poulpy_core::{
|
||||||
AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GGSWInfos, GLWE, GLWEInfos, GLWESecret, LWEInfos, LWESecret, TensorKey,
|
GLWEAutomorphismKeyEncryptSk, GLWETensorKeyEncryptSk, GetDistribution, ScratchTakeCore,
|
||||||
TensorKeyLayout,
|
layouts::{
|
||||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared},
|
GGLWEInfos, GGSWInfos, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEInfos, GLWESecretPreparedFactory,
|
||||||
|
GLWESecretToRef, GLWETensorKey, GLWETensorKeyLayout, LWEInfos, LWESecretToRef, prepared::GLWESecretPrepared,
|
||||||
|
},
|
||||||
|
trace_galois_elements,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch},
|
||||||
ScratchAvailable, SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace,
|
|
||||||
VecZnxAutomorphism, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume,
|
|
||||||
VecZnxIdftApplyTmpA, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace,
|
|
||||||
VecZnxSwitchRing, VmpPMatAlloc, VmpPrepare,
|
|
||||||
},
|
|
||||||
layouts::{Backend, Data, DataRef, Module, Scratch},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tfhe::blind_rotation::{
|
use crate::tfhe::blind_rotation::{
|
||||||
BlindRotationAlgo, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyInfos,
|
BlindRotationAlgo, BlindRotationKey, BlindRotationKeyEncryptSk, BlindRotationKeyFactory, BlindRotationKeyInfos,
|
||||||
BlindRotationKeyLayout, BlindRotationKeyPrepared,
|
BlindRotationKeyLayout,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait CircuitBootstrappingKeyInfos {
|
pub trait CircuitBootstrappingKeyInfos {
|
||||||
fn brk_infos(&self) -> BlindRotationKeyLayout;
|
fn brk_infos(&self) -> BlindRotationKeyLayout;
|
||||||
fn atk_infos(&self) -> AutomorphismKeyLayout;
|
fn atk_infos(&self) -> GLWEAutomorphismKeyLayout;
|
||||||
fn tsk_infos(&self) -> TensorKeyLayout;
|
fn tsk_infos(&self) -> GLWETensorKeyLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct CircuitBootstrappingKeyLayout {
|
pub struct CircuitBootstrappingKeyLayout {
|
||||||
pub layout_brk: BlindRotationKeyLayout,
|
pub layout_brk: BlindRotationKeyLayout,
|
||||||
pub layout_atk: AutomorphismKeyLayout,
|
pub layout_atk: GLWEAutomorphismKeyLayout,
|
||||||
pub layout_tsk: TensorKeyLayout,
|
pub layout_tsk: GLWETensorKeyLayout,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout {
|
impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout {
|
||||||
fn atk_infos(&self) -> AutomorphismKeyLayout {
|
fn atk_infos(&self) -> GLWEAutomorphismKeyLayout {
|
||||||
self.layout_atk
|
self.layout_atk
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,96 +40,114 @@ impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout {
|
|||||||
self.layout_brk
|
self.layout_brk
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tsk_infos(&self) -> TensorKeyLayout {
|
fn tsk_infos(&self) -> GLWETensorKeyLayout {
|
||||||
self.layout_tsk
|
self.layout_tsk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CircuitBootstrappingKeyEncryptSk<B: Backend> {
|
pub trait CircuitBootstrappingKeyEncryptSk<BRA: BlindRotationAlgo, BE: Backend> {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn encrypt_sk<DLwe, DGlwe, INFOS>(
|
fn circuit_bootstrapping_key_encrypt_sk<D, S0, S1>(
|
||||||
module: &Module<B>,
|
&self,
|
||||||
sk_lwe: &LWESecret<DLwe>,
|
res: &mut CircuitBootstrappingKey<D, BRA>,
|
||||||
sk_glwe: &GLWESecret<DGlwe>,
|
sk_lwe: &S0,
|
||||||
cbt_infos: &INFOS,
|
sk_glwe: &S1,
|
||||||
source_xa: &mut Source,
|
source_xa: &mut Source,
|
||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<BE>,
|
||||||
) -> Self
|
) where
|
||||||
|
D: DataMut,
|
||||||
|
S0: LWESecretToRef + GetDistribution + LWEInfos,
|
||||||
|
S1: GLWESecretToRef + GLWEInfos + GetDistribution;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<BRA: BlindRotationAlgo> CircuitBootstrappingKey<Vec<u8>, BRA> {
|
||||||
|
pub fn alloc_from_infos<A>(infos: &A) -> Self
|
||||||
where
|
where
|
||||||
INFOS: CircuitBootstrappingKeyInfos,
|
A: CircuitBootstrappingKeyInfos,
|
||||||
DLwe: DataRef,
|
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||||
DGlwe: DataRef;
|
{
|
||||||
|
let atk_infos: &GLWEAutomorphismKeyLayout = &infos.atk_infos();
|
||||||
|
let brk_infos: &BlindRotationKeyLayout = &infos.brk_infos();
|
||||||
|
let trk_infos: &GLWETensorKeyLayout = &infos.tsk_infos();
|
||||||
|
let gal_els: Vec<i64> = trace_galois_elements(atk_infos.log_n(), 2 * atk_infos.n().as_usize() as i64);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
brk: <BlindRotationKey<Vec<u8>, BRA> as BlindRotationKeyFactory<BRA>>::blind_rotation_key_alloc(brk_infos),
|
||||||
|
atk: gal_els
|
||||||
|
.iter()
|
||||||
|
.map(|&gal_el| {
|
||||||
|
let key = GLWEAutomorphismKey::alloc_from_infos(atk_infos);
|
||||||
|
(gal_el, key)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
tsk: GLWETensorKey::alloc_from_infos(trk_infos),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CircuitBootstrappingKey<D: Data, BRA: BlindRotationAlgo> {
|
pub struct CircuitBootstrappingKey<D: Data, BRA: BlindRotationAlgo> {
|
||||||
pub(crate) brk: BlindRotationKey<D, BRA>,
|
pub(crate) brk: BlindRotationKey<D, BRA>,
|
||||||
pub(crate) tsk: TensorKey<Vec<u8>>,
|
pub(crate) tsk: GLWETensorKey<Vec<u8>>,
|
||||||
pub(crate) atk: HashMap<i64, AutomorphismKey<Vec<u8>>>,
|
pub(crate) atk: HashMap<i64, GLWEAutomorphismKey<Vec<u8>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyEncryptSk<B> for CircuitBootstrappingKey<Vec<u8>, BRA>
|
impl<D: DataMut, BRA: BlindRotationAlgo> CircuitBootstrappingKey<D, BRA> {
|
||||||
where
|
pub fn encrypt_sk<M, S0, S1, BE: Backend>(
|
||||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<B>,
|
&mut self,
|
||||||
Module<B>: SvpApplyDftToDft<B>
|
module: &M,
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
sk_lwe: &S0,
|
||||||
+ VecZnxAddScalarInplace
|
sk_glwe: &S1,
|
||||||
+ VecZnxDftBytesOf
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxDftApply<B>
|
|
||||||
+ SvpApplyDftToDftInplace<B>
|
|
||||||
+ VecZnxIdftApplyConsume<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxFillUniform
|
|
||||||
+ VecZnxSubInplace
|
|
||||||
+ VecZnxAddInplace
|
|
||||||
+ VecZnxNormalizeInplace<B>
|
|
||||||
+ VecZnxAddNormal
|
|
||||||
+ VecZnxNormalize<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxAutomorphism,
|
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeSvpPPol<B> + TakeVecZnxBig<B>,
|
|
||||||
{
|
|
||||||
fn encrypt_sk<DLwe, DGlwe, INFOS>(
|
|
||||||
module: &Module<B>,
|
|
||||||
sk_lwe: &LWESecret<DLwe>,
|
|
||||||
sk_glwe: &GLWESecret<DGlwe>,
|
|
||||||
cbt_infos: &INFOS,
|
|
||||||
source_xa: &mut Source,
|
source_xa: &mut Source,
|
||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<BE>,
|
||||||
) -> Self
|
) where
|
||||||
where
|
S0: LWESecretToRef + GetDistribution + LWEInfos,
|
||||||
INFOS: CircuitBootstrappingKeyInfos,
|
S1: GLWESecretToRef + GLWEInfos + GetDistribution,
|
||||||
DLwe: DataRef,
|
M: CircuitBootstrappingKeyEncryptSk<BRA, BE>,
|
||||||
DGlwe: DataRef,
|
|
||||||
{
|
{
|
||||||
assert_eq!(sk_lwe.n(), cbt_infos.brk_infos().n_lwe());
|
module.circuit_bootstrapping_key_encrypt_sk(self, sk_lwe, sk_glwe, source_xa, source_xe, scratch);
|
||||||
assert_eq!(sk_glwe.n(), cbt_infos.brk_infos().n_glwe());
|
}
|
||||||
assert_eq!(sk_glwe.n(), cbt_infos.atk_infos().n());
|
}
|
||||||
assert_eq!(sk_glwe.n(), cbt_infos.tsk_infos().n());
|
|
||||||
|
|
||||||
let atk_infos: AutomorphismKeyLayout = cbt_infos.atk_infos();
|
impl<BRA: BlindRotationAlgo, BE: Backend> CircuitBootstrappingKeyEncryptSk<BRA, BE> for Module<BE>
|
||||||
let brk_infos: BlindRotationKeyLayout = cbt_infos.brk_infos();
|
where
|
||||||
let trk_infos: TensorKeyLayout = cbt_infos.tsk_infos();
|
Self: GLWETensorKeyEncryptSk<BE>
|
||||||
|
+ BlindRotationKeyEncryptSk<BRA, BE>
|
||||||
|
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||||
|
+ GLWESecretPreparedFactory<BE>,
|
||||||
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
|
{
|
||||||
|
fn circuit_bootstrapping_key_encrypt_sk<D, S0, S1>(
|
||||||
|
&self,
|
||||||
|
res: &mut CircuitBootstrappingKey<D, BRA>,
|
||||||
|
sk_lwe: &S0,
|
||||||
|
sk_glwe: &S1,
|
||||||
|
source_xa: &mut Source,
|
||||||
|
source_xe: &mut Source,
|
||||||
|
scratch: &mut Scratch<BE>,
|
||||||
|
) where
|
||||||
|
D: DataMut,
|
||||||
|
S0: LWESecretToRef + GetDistribution + LWEInfos,
|
||||||
|
S1: GLWESecretToRef + GLWEInfos + GetDistribution,
|
||||||
|
{
|
||||||
|
let brk_infos: &BlindRotationKeyLayout = &res.brk_infos();
|
||||||
|
let atk_infos: &GLWEAutomorphismKeyLayout = &res.atk_infos();
|
||||||
|
let tsk_infos: &GLWETensorKeyLayout = &res.tsk_infos();
|
||||||
|
|
||||||
let mut auto_keys: HashMap<i64, AutomorphismKey<Vec<u8>>> = HashMap::new();
|
assert_eq!(sk_lwe.n(), brk_infos.n_lwe());
|
||||||
let gal_els: Vec<i64> = GLWE::trace_galois_elements(module);
|
assert_eq!(sk_glwe.n(), brk_infos.n_glwe());
|
||||||
gal_els.iter().for_each(|gal_el| {
|
assert_eq!(sk_glwe.n(), atk_infos.n());
|
||||||
let mut key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&atk_infos);
|
assert_eq!(sk_glwe.n(), tsk_infos.n());
|
||||||
key.encrypt_sk(module, *gal_el, sk_glwe, source_xa, source_xe, scratch);
|
|
||||||
auto_keys.insert(*gal_el, key);
|
|
||||||
});
|
|
||||||
|
|
||||||
let sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_glwe.prepare_alloc(module, scratch);
|
for (p, atk) in res.atk.iter_mut() {
|
||||||
|
atk.encrypt_sk(self, *p, sk_glwe, source_xa, source_xe, scratch);
|
||||||
|
}
|
||||||
|
|
||||||
let mut brk: BlindRotationKey<Vec<u8>, BRA> = BlindRotationKey::<Vec<u8>, BRA>::alloc(&brk_infos);
|
let sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(self, brk_infos.rank());
|
||||||
brk.encrypt_sk(
|
|
||||||
module,
|
res.brk.encrypt_sk(
|
||||||
|
self,
|
||||||
&sk_glwe_prepared,
|
&sk_glwe_prepared,
|
||||||
sk_lwe,
|
sk_lwe,
|
||||||
source_xa,
|
source_xa,
|
||||||
@@ -140,27 +155,15 @@ where
|
|||||||
scratch,
|
scratch,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&trk_infos);
|
res.tsk
|
||||||
tsk.encrypt_sk(module, sk_glwe, source_xa, source_xe, scratch);
|
.encrypt_sk(self, sk_glwe, source_xa, source_xe, scratch);
|
||||||
|
|
||||||
Self {
|
|
||||||
brk,
|
|
||||||
atk: auto_keys,
|
|
||||||
tsk,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CircuitBootstrappingKeyPrepared<D: Data, BRA: BlindRotationAlgo, B: Backend> {
|
impl<D: DataRef, BRA: BlindRotationAlgo> CircuitBootstrappingKeyInfos for CircuitBootstrappingKey<D, BRA> {
|
||||||
pub(crate) brk: BlindRotationKeyPrepared<D, BRA, B>,
|
fn atk_infos(&self) -> GLWEAutomorphismKeyLayout {
|
||||||
pub(crate) tsk: TensorKeyPrepared<Vec<u8>, B>,
|
|
||||||
pub(crate) atk: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyPrepared<D, BRA, B> {
|
|
||||||
fn atk_infos(&self) -> AutomorphismKeyLayout {
|
|
||||||
let (_, atk) = self.atk.iter().next().expect("atk is empty");
|
let (_, atk) = self.atk.iter().next().expect("atk is empty");
|
||||||
AutomorphismKeyLayout {
|
GLWEAutomorphismKeyLayout {
|
||||||
n: atk.n(),
|
n: atk.n(),
|
||||||
base2k: atk.base2k(),
|
base2k: atk.base2k(),
|
||||||
k: atk.k(),
|
k: atk.k(),
|
||||||
@@ -181,8 +184,8 @@ impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tsk_infos(&self) -> TensorKeyLayout {
|
fn tsk_infos(&self) -> GLWETensorKeyLayout {
|
||||||
TensorKeyLayout {
|
GLWETensorKeyLayout {
|
||||||
n: self.tsk.n(),
|
n: self.tsk.n(),
|
||||||
base2k: self.tsk.base2k(),
|
base2k: self.tsk.base2k(),
|
||||||
k: self.tsk.k(),
|
k: self.tsk.k(),
|
||||||
@@ -192,22 +195,3 @@ impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> PrepareAlloc<B, CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B>>
|
|
||||||
for CircuitBootstrappingKey<D, BRA>
|
|
||||||
where
|
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
|
||||||
BlindRotationKey<D, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
|
|
||||||
TensorKey<D>: PrepareAlloc<B, TensorKeyPrepared<Vec<u8>, B>>,
|
|
||||||
AutomorphismKey<D>: PrepareAlloc<B, GLWEAutomorphismKeyPrepared<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: TensorKeyPrepared<Vec<u8>, B> = self.tsk.prepare_alloc(module, scratch);
|
|
||||||
let mut atk: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new();
|
|
||||||
for (key, value) in &self.atk {
|
|
||||||
atk.insert(*key, value.prepare_alloc(module, scratch));
|
|
||||||
}
|
|
||||||
CircuitBootstrappingKeyPrepared { brk, tsk, atk }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use poulpy_core::layouts::{GLWEAutomorphismKeyCompressed, GLWETensorKeyCompressed};
|
||||||
|
use poulpy_hal::layouts::Data;
|
||||||
|
|
||||||
|
use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyCompressed};
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct CircuitBootstrappingKey<D: Data, BRA: BlindRotationAlgo> {
|
||||||
|
pub(crate) brk: BlindRotationKeyCompressed<D, BRA>,
|
||||||
|
pub(crate) tsk: GLWETensorKeyCompressed<Vec<u8>>,
|
||||||
|
pub(crate) atk: HashMap<i64, GLWEAutomorphismKeyCompressed<Vec<u8>>>,
|
||||||
|
}
|
||||||
136
poulpy-schemes/src/tfhe/circuit_bootstrapping/key_prepared.rs
Normal file
136
poulpy-schemes/src/tfhe/circuit_bootstrapping/key_prepared.rs
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
use poulpy_core::{
|
||||||
|
layouts::{
|
||||||
|
GGLWEInfos, GGSWInfos, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWEInfos, GLWETensorKeyLayout,
|
||||||
|
GLWETensorKeyPreparedFactory, LWEInfos,
|
||||||
|
prepared::{GLWEAutomorphismKeyPrepared, GLWETensorKeyPrepared},
|
||||||
|
},
|
||||||
|
trace_galois_elements,
|
||||||
|
};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||||
|
|
||||||
|
use crate::tfhe::{
|
||||||
|
blind_rotation::{
|
||||||
|
BlindRotationAlgo, BlindRotationKeyInfos, BlindRotationKeyLayout, BlindRotationKeyPrepared,
|
||||||
|
BlindRotationKeyPreparedFactory,
|
||||||
|
},
|
||||||
|
circuit_bootstrapping::{CircuitBootstrappingKey, CircuitBootstrappingKeyInfos},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<BRA: BlindRotationAlgo, BE: Backend> CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, BE> {
|
||||||
|
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, BE>
|
||||||
|
where
|
||||||
|
A: CircuitBootstrappingKeyInfos,
|
||||||
|
M: CircuitBootstrappingKeyPreparedFactory<BRA, BE>,
|
||||||
|
{
|
||||||
|
module.circuit_bootstrapping_key_prepared_alloc_from_infos(infos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<D: DataMut, BRA: BlindRotationAlgo, BE: Backend> CircuitBootstrappingKeyPrepared<D, BRA, BE> {
|
||||||
|
pub fn prepare<DR, M>(&mut self, module: &M, other: &CircuitBootstrappingKey<DR, BRA>, scratch: &mut Scratch<BE>)
|
||||||
|
where
|
||||||
|
DR: DataRef,
|
||||||
|
M: CircuitBootstrappingKeyPreparedFactory<BRA, BE>,
|
||||||
|
{
|
||||||
|
module.circuit_bootstrapping_key_prepare(self, other, scratch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<BE: Backend, BRA: BlindRotationAlgo> CircuitBootstrappingKeyPreparedFactory<BRA, BE> for Module<BE> where
|
||||||
|
Self: Sized
|
||||||
|
+ BlindRotationKeyPreparedFactory<BRA, BE>
|
||||||
|
+ GLWETensorKeyPreparedFactory<BE>
|
||||||
|
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait CircuitBootstrappingKeyPreparedFactory<BRA: BlindRotationAlgo, BE: Backend>
|
||||||
|
where
|
||||||
|
Self: Sized
|
||||||
|
+ BlindRotationKeyPreparedFactory<BRA, BE>
|
||||||
|
+ GLWETensorKeyPreparedFactory<BE>
|
||||||
|
+ GLWEAutomorphismKeyPreparedFactory<BE>,
|
||||||
|
{
|
||||||
|
fn circuit_bootstrapping_key_prepared_alloc_from_infos<A>(
|
||||||
|
&self,
|
||||||
|
infos: &A,
|
||||||
|
) -> CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, BE>
|
||||||
|
where
|
||||||
|
A: CircuitBootstrappingKeyInfos,
|
||||||
|
{
|
||||||
|
let atk_infos: &GLWEAutomorphismKeyLayout = &infos.atk_infos();
|
||||||
|
let gal_els: Vec<i64> = trace_galois_elements(atk_infos.log_n(), 2 * atk_infos.n().as_usize() as i64);
|
||||||
|
|
||||||
|
CircuitBootstrappingKeyPrepared {
|
||||||
|
brk: BlindRotationKeyPrepared::alloc(self, &infos.brk_infos()),
|
||||||
|
tsk: GLWETensorKeyPrepared::alloc_from_infos(self, &infos.tsk_infos()),
|
||||||
|
atk: gal_els
|
||||||
|
.iter()
|
||||||
|
.map(|&gal_el| {
|
||||||
|
let key = GLWEAutomorphismKeyPrepared::alloc_from_infos(self, atk_infos);
|
||||||
|
(gal_el, key)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn circuit_bootstrapping_key_prepare<DM, DR>(
|
||||||
|
&self,
|
||||||
|
res: &mut CircuitBootstrappingKeyPrepared<DM, BRA, BE>,
|
||||||
|
other: &CircuitBootstrappingKey<DR, BRA>,
|
||||||
|
scratch: &mut Scratch<BE>,
|
||||||
|
) where
|
||||||
|
DM: DataMut,
|
||||||
|
DR: DataRef,
|
||||||
|
{
|
||||||
|
res.brk.prepare(self, &other.brk, scratch);
|
||||||
|
res.tsk.prepare(self, &other.tsk, scratch);
|
||||||
|
|
||||||
|
for (k, a) in res.atk.iter_mut() {
|
||||||
|
a.prepare(self, other.atk.get(k).unwrap(), scratch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CircuitBootstrappingKeyPrepared<D: Data, BRA: BlindRotationAlgo, B: Backend> {
|
||||||
|
pub(crate) brk: BlindRotationKeyPrepared<D, BRA, B>,
|
||||||
|
pub(crate) tsk: GLWETensorKeyPrepared<Vec<u8>, B>,
|
||||||
|
pub(crate) atk: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyPrepared<D, BRA, B> {
|
||||||
|
fn atk_infos(&self) -> GLWEAutomorphismKeyLayout {
|
||||||
|
let (_, atk) = self.atk.iter().next().expect("atk is empty");
|
||||||
|
GLWEAutomorphismKeyLayout {
|
||||||
|
n: atk.n(),
|
||||||
|
base2k: atk.base2k(),
|
||||||
|
k: atk.k(),
|
||||||
|
dnum: atk.dnum(),
|
||||||
|
dsize: atk.dsize(),
|
||||||
|
rank: atk.rank(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn brk_infos(&self) -> BlindRotationKeyLayout {
|
||||||
|
BlindRotationKeyLayout {
|
||||||
|
n_glwe: self.brk.n_glwe(),
|
||||||
|
n_lwe: self.brk.n_lwe(),
|
||||||
|
base2k: self.brk.base2k(),
|
||||||
|
k: self.brk.k(),
|
||||||
|
dnum: self.brk.dnum(),
|
||||||
|
rank: self.brk.rank(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tsk_infos(&self) -> GLWETensorKeyLayout {
|
||||||
|
GLWETensorKeyLayout {
|
||||||
|
n: self.tsk.n(),
|
||||||
|
base2k: self.tsk.base2k(),
|
||||||
|
k: self.tsk.k(),
|
||||||
|
dnum: self.tsk.dnum(),
|
||||||
|
dsize: self.tsk.dsize(),
|
||||||
|
rank: self.tsk.rank(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,36 +1,12 @@
|
|||||||
mod circuit;
|
mod circuit;
|
||||||
mod key;
|
mod key;
|
||||||
|
mod key_compressed;
|
||||||
|
mod key_prepared;
|
||||||
|
|
||||||
//[cfg(tests)]
|
#[cfg(test)]
|
||||||
//pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
pub use circuit::*;
|
pub use circuit::*;
|
||||||
pub use key::*;
|
pub use key::*;
|
||||||
|
// pub use key_compressed::*;
|
||||||
use poulpy_core::layouts::{GGSW, LWE};
|
pub use key_prepared::*;
|
||||||
|
|
||||||
use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch};
|
|
||||||
|
|
||||||
pub trait CirtuitBootstrappingExecute<B: Backend> {
|
|
||||||
fn execute_to_constant<DM: DataMut, DR: DataRef>(
|
|
||||||
&self,
|
|
||||||
module: &Module<B>,
|
|
||||||
res: &mut GGSW<DM>,
|
|
||||||
lwe: &LWE<DR>,
|
|
||||||
log_domain: usize,
|
|
||||||
extension_factor: usize,
|
|
||||||
scratch: &mut Scratch<B>,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn execute_to_exponent<DM: DataMut, DR: DataRef>(
|
|
||||||
&self,
|
|
||||||
module: &Module<B>,
|
|
||||||
log_gap_out: usize,
|
|
||||||
res: &mut GGSW<DM>,
|
|
||||||
lwe: &LWE<DR>,
|
|
||||||
log_domain: usize,
|
|
||||||
extension_factor: usize,
|
|
||||||
scratch: &mut Scratch<B>,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,108 +1,49 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ModuleN, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace},
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf,
|
layouts::{Backend, ScalarZnx, Scratch, ScratchOwned, ZnxView, ZnxViewMut},
|
||||||
SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace,
|
|
||||||
VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAutomorphismInplace, VecZnxBigBytesOf,
|
|
||||||
VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallNegateInplace, VecZnxCopy, VecZnxDftAddInplace,
|
|
||||||
VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf, VecZnxDftCopy, VecZnxFillUniform, VecZnxIdftApplyConsume,
|
|
||||||
VecZnxIdftApplyTmpA, VecZnxNegateInplace, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate,
|
|
||||||
VecZnxRotateInplace, VecZnxRotateInplaceTmpBytes, VecZnxRshInplace, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing,
|
|
||||||
VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare, ZnAddNormal, ZnFillUniform,
|
|
||||||
ZnNormalizeInplace,
|
|
||||||
},
|
|
||||||
layouts::{Backend, Module, ScalarZnx, ScratchOwned, ZnxView, ZnxViewMut},
|
|
||||||
oep::{
|
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeMatZnxImpl, TakeScalarZnxImpl, TakeSliceImpl,
|
|
||||||
TakeSvpPPolImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxDftSliceImpl, TakeVecZnxImpl, TakeVecZnxSliceImpl,
|
|
||||||
},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
blind_rotation::{
|
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, BlindRotationKeyLayout},
|
||||||
BlincRotationExecute, BlindRotationAlgo, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk,
|
|
||||||
BlindRotationKeyLayout, BlindRotationKeyPrepared,
|
|
||||||
},
|
|
||||||
circuit_bootstrapping::{
|
circuit_bootstrapping::{
|
||||||
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout,
|
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyLayout,
|
||||||
CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute,
|
CircuitBootstrappingKeyPrepared, CircuitBootstrappingKeyPreparedFactory, CirtuitBootstrappingExecute,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use poulpy_core::layouts::{AutomorphismKeyLayout, Dsize, GGSWLayout, LWELayout, TensorKeyLayout, prepared::PrepareAlloc};
|
use poulpy_core::{
|
||||||
|
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore,
|
||||||
|
layouts::{
|
||||||
|
Dsize, GGSWLayout, GGSWPreparedFactory, GLWEAutomorphismKeyLayout, GLWESecretPreparedFactory, GLWETensorKeyLayout,
|
||||||
|
LWELayout,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
use poulpy_core::layouts::{
|
use poulpy_core::layouts::{
|
||||||
GGSW, GLWE, GLWEPlaintext, GLWESecret, LWE, LWEPlaintext, LWESecret,
|
GGSW, GLWE, GLWEPlaintext, GLWESecret, LWE, LWEPlaintext, LWESecret,
|
||||||
prepared::{GGSWPrepared, GLWESecretPrepared},
|
prepared::{GGSWPrepared, GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_circuit_bootstrapping_to_exponent<B, BRA: BlindRotationAlgo>(module: &Module<B>)
|
pub fn test_circuit_bootstrapping_to_exponent<BE: Backend, M, BRA: BlindRotationAlgo>(module: &M)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxFillUniform
|
M: ModuleN
|
||||||
+ VecZnxAddNormal
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWEExternalProduct<BE>
|
||||||
+ VecZnxDftBytesOf
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ LWEEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ CircuitBootstrappingKeyEncryptSk<BRA, BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ CircuitBootstrappingKeyPreparedFactory<BRA, BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ CirtuitBootstrappingExecute<BRA, BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GGSWPreparedFactory<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWNoise<BE>
|
||||||
+ VecZnxAddInplace
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxNormalize<B>
|
+ VecZnxRotateInplace<BE>,
|
||||||
+ VecZnxSub
|
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>, // TODO find a way to remove this bound or move it to CBT KEY
|
||||||
+ VecZnxAddScalarInplace
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxAutomorphism
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
|
||||||
+ SvpApplyDftToDft<B>
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigAlloc<B>
|
|
||||||
+ VecZnxDftAlloc<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxRshInplace<B>
|
|
||||||
+ VecZnxDftCopy<B>
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ VecZnxBigSubSmallNegateInplace<B>
|
|
||||||
+ VecZnxRotateInplaceTmpBytes
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxDftAddInplace<B>
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ ZnFillUniform
|
|
||||||
+ ZnAddNormal
|
|
||||||
+ ZnNormalizeInplace<B>,
|
|
||||||
B: Backend
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeVecZnxDftSliceImpl<B>
|
|
||||||
+ TakeMatZnxImpl<B>
|
|
||||||
+ TakeVecZnxSliceImpl<B>
|
|
||||||
+ TakeSliceImpl<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
|
|
||||||
BlindRotationKeyPrepared<Vec<u8>, BRA, B>: BlincRotationExecute<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<B>,
|
|
||||||
{
|
{
|
||||||
let n_glwe: usize = module.n();
|
let n_glwe: usize = module.n();
|
||||||
let base2k: usize = 17;
|
let base2k: usize = 17;
|
||||||
@@ -141,7 +82,7 @@ where
|
|||||||
dnum: rows_brk.into(),
|
dnum: rows_brk.into(),
|
||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
},
|
},
|
||||||
layout_atk: AutomorphismKeyLayout {
|
layout_atk: GLWEAutomorphismKeyLayout {
|
||||||
n: n_glwe.into(),
|
n: n_glwe.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_atk.into(),
|
k: k_atk.into(),
|
||||||
@@ -149,7 +90,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
dsize: Dsize(1),
|
dsize: Dsize(1),
|
||||||
},
|
},
|
||||||
layout_tsk: TensorKeyLayout {
|
layout_tsk: GLWETensorKeyLayout {
|
||||||
n: n_glwe.into(),
|
n: n_glwe.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_tsk.into(),
|
k: k_tsk.into(),
|
||||||
@@ -168,7 +109,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(1 << 23);
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 23);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([1u8; 32]);
|
let mut source_xa: Source = Source::new([1u8; 32]);
|
||||||
@@ -180,7 +121,8 @@ where
|
|||||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc(n_glwe.into(), rank.into());
|
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc(n_glwe.into(), rank.into());
|
||||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_glwe.prepare_alloc(module, scratch.borrow());
|
let mut sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||||
|
sk_glwe_prepared.prepare(module, &sk_glwe);
|
||||||
|
|
||||||
let data: i64 = 1;
|
let data: i64 = 1;
|
||||||
|
|
||||||
@@ -193,22 +135,27 @@ where
|
|||||||
ct_lwe.encrypt_sk(module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
|
ct_lwe.encrypt_sk(module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
|
||||||
|
|
||||||
let now: Instant = Instant::now();
|
let now: Instant = Instant::now();
|
||||||
let cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::encrypt_sk(
|
let mut cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::alloc_from_infos(&cbt_infos);
|
||||||
|
println!("CBT-ALLOC: {} ms", now.elapsed().as_millis());
|
||||||
|
|
||||||
|
let now: Instant = Instant::now();
|
||||||
|
cbt_key.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
&sk_lwe,
|
&sk_lwe,
|
||||||
&sk_glwe,
|
&sk_glwe,
|
||||||
&cbt_infos,
|
|
||||||
&mut source_xa,
|
&mut source_xa,
|
||||||
&mut source_xe,
|
&mut source_xe,
|
||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
|
println!("CBT-ENCRYPT: {} ms", now.elapsed().as_millis());
|
||||||
|
|
||||||
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_infos);
|
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_infos);
|
||||||
|
|
||||||
let log_gap_out = 1;
|
let log_gap_out = 1;
|
||||||
|
|
||||||
let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> = cbt_key.prepare_alloc(module, scratch.borrow());
|
let mut cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, BE> =
|
||||||
|
CircuitBootstrappingKeyPrepared::alloc_from_infos(module, &cbt_infos);
|
||||||
|
cbt_prepared.prepare(module, &cbt_key, scratch.borrow());
|
||||||
|
|
||||||
let now: Instant = Instant::now();
|
let now: Instant = Instant::now();
|
||||||
cbt_prepared.execute_to_exponent(
|
cbt_prepared.execute_to_exponent(
|
||||||
@@ -247,7 +194,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let res_prepared: GGSWPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow());
|
let mut res_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &res);
|
||||||
|
res_prepared.prepare(module, &res, scratch.borrow());
|
||||||
|
|
||||||
ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());
|
ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());
|
||||||
|
|
||||||
@@ -260,71 +208,23 @@ where
|
|||||||
assert_eq!(pt_res.data.at(0, 0), pt_want);
|
assert_eq!(pt_res.data.at(0, 0), pt_want);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_circuit_bootstrapping_to_constant<B, BRA: BlindRotationAlgo>(module: &Module<B>)
|
pub fn test_circuit_bootstrapping_to_constant<BE: Backend, M, BRA: BlindRotationAlgo>(module: &M)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxFillUniform
|
M: ModuleN
|
||||||
+ VecZnxAddNormal
|
+ GLWESecretPreparedFactory<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWEExternalProduct<BE>
|
||||||
+ VecZnxDftBytesOf
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ LWEEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ CircuitBootstrappingKeyEncryptSk<BRA, BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ CircuitBootstrappingKeyPreparedFactory<BRA, BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ CirtuitBootstrappingExecute<BRA, BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GGSWPreparedFactory<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWNoise<BE>
|
||||||
+ VecZnxAddInplace
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxNormalize<B>
|
+ VecZnxRotateInplace<BE>,
|
||||||
+ VecZnxSub
|
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>, // TODO find a way to remove this bound or move it to CBT KEY
|
||||||
+ VecZnxAddScalarInplace
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxAutomorphism
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxIdftApplyTmpA<B>
|
|
||||||
+ SvpApplyDftToDft<B>
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigAlloc<B>
|
|
||||||
+ VecZnxDftAlloc<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxRotateInplaceTmpBytes
|
|
||||||
+ VecZnxRshInplace<B>
|
|
||||||
+ VecZnxDftCopy<B>
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ VecZnxBigSubSmallNegateInplace<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxDftAddInplace<B>
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ ZnFillUniform
|
|
||||||
+ ZnAddNormal
|
|
||||||
+ ZnNormalizeInplace<B>,
|
|
||||||
B: Backend
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeVecZnxDftSliceImpl<B>
|
|
||||||
+ TakeMatZnxImpl<B>
|
|
||||||
+ TakeVecZnxSliceImpl<B>
|
|
||||||
+ TakeSliceImpl<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
|
|
||||||
BlindRotationKeyPrepared<Vec<u8>, BRA, B>: BlincRotationExecute<B>,
|
|
||||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<B>,
|
|
||||||
{
|
{
|
||||||
let n_glwe: usize = module.n();
|
let n_glwe: usize = module.n();
|
||||||
let base2k: usize = 14;
|
let base2k: usize = 14;
|
||||||
@@ -363,7 +263,7 @@ where
|
|||||||
dnum: rows_brk.into(),
|
dnum: rows_brk.into(),
|
||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
},
|
},
|
||||||
layout_atk: AutomorphismKeyLayout {
|
layout_atk: GLWEAutomorphismKeyLayout {
|
||||||
n: n_glwe.into(),
|
n: n_glwe.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_atk.into(),
|
k: k_atk.into(),
|
||||||
@@ -371,7 +271,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
dsize: Dsize(1),
|
dsize: Dsize(1),
|
||||||
},
|
},
|
||||||
layout_tsk: TensorKeyLayout {
|
layout_tsk: GLWETensorKeyLayout {
|
||||||
n: n_glwe.into(),
|
n: n_glwe.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_tsk.into(),
|
k: k_tsk.into(),
|
||||||
@@ -390,7 +290,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(1 << 23);
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 23);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([1u8; 32]);
|
let mut source_xa: Source = Source::new([1u8; 32]);
|
||||||
@@ -402,7 +302,8 @@ where
|
|||||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc(n_glwe.into(), rank.into());
|
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc(n_glwe.into(), rank.into());
|
||||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_glwe.prepare_alloc(module, scratch.borrow());
|
let mut sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||||
|
sk_glwe_prepared.prepare(module, &sk_glwe);
|
||||||
|
|
||||||
let data: i64 = 1;
|
let data: i64 = 1;
|
||||||
|
|
||||||
@@ -415,20 +316,25 @@ where
|
|||||||
ct_lwe.encrypt_sk(module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
|
ct_lwe.encrypt_sk(module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe);
|
||||||
|
|
||||||
let now: Instant = Instant::now();
|
let now: Instant = Instant::now();
|
||||||
let cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::encrypt_sk(
|
let mut cbt_key: CircuitBootstrappingKey<Vec<u8>, BRA> = CircuitBootstrappingKey::alloc_from_infos(&cbt_infos);
|
||||||
|
println!("CBT-ALLOC: {} ms", now.elapsed().as_millis());
|
||||||
|
|
||||||
|
let now: Instant = Instant::now();
|
||||||
|
cbt_key.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
&sk_lwe,
|
&sk_lwe,
|
||||||
&sk_glwe,
|
&sk_glwe,
|
||||||
&cbt_infos,
|
|
||||||
&mut source_xa,
|
&mut source_xa,
|
||||||
&mut source_xe,
|
&mut source_xe,
|
||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
|
println!("CBT-ENCRYPT: {} ms", now.elapsed().as_millis());
|
||||||
|
|
||||||
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_infos);
|
let mut res: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_infos);
|
||||||
|
|
||||||
let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> = cbt_key.prepare_alloc(module, scratch.borrow());
|
let mut cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, BE> =
|
||||||
|
CircuitBootstrappingKeyPrepared::alloc_from_infos(module, &cbt_infos);
|
||||||
|
cbt_prepared.prepare(module, &cbt_key, scratch.borrow());
|
||||||
|
|
||||||
let now: Instant = Instant::now();
|
let now: Instant = Instant::now();
|
||||||
cbt_prepared.execute_to_constant(
|
cbt_prepared.execute_to_constant(
|
||||||
@@ -460,7 +366,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let res_prepared: GGSWPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow());
|
let mut res_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &res);
|
||||||
|
res_prepared.prepare(module, &res, scratch.borrow());
|
||||||
|
|
||||||
ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());
|
ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());
|
||||||
|
|
||||||
|
|||||||
21
poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/fft64.rs
Normal file
21
poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/fft64.rs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
use poulpy_backend::cpu_fft64_ref::FFT64Ref;
|
||||||
|
use poulpy_hal::{api::ModuleNew, layouts::Module};
|
||||||
|
|
||||||
|
use crate::tfhe::{
|
||||||
|
blind_rotation::CGGI,
|
||||||
|
circuit_bootstrapping::tests::circuit_bootstrapping::{
|
||||||
|
test_circuit_bootstrapping_to_constant, test_circuit_bootstrapping_to_exponent,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_to_constant_cggi() {
|
||||||
|
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(256);
|
||||||
|
test_circuit_bootstrapping_to_constant::<FFT64Ref, _, CGGI>(&module);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_to_exponent_cggi() {
|
||||||
|
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(256);
|
||||||
|
test_circuit_bootstrapping_to_exponent::<FFT64Ref, _, CGGI>(&module);
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
use poulpy_backend::cpu_spqlios::FFT64Spqlios;
|
|
||||||
use poulpy_hal::{api::ModuleNew, layouts::Module};
|
|
||||||
|
|
||||||
use crate::tfhe::{
|
|
||||||
blind_rotation::CGGI,
|
|
||||||
circuit_bootstrapping::tests::circuit_bootstrapping::{
|
|
||||||
test_circuit_bootstrapping_to_constant, test_circuit_bootstrapping_to_exponent,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_to_constant() {
|
|
||||||
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(256);
|
|
||||||
test_circuit_bootstrapping_to_constant::<FFT64Spqlios, CGGI>(&module);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_to_exponent() {
|
|
||||||
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(256);
|
|
||||||
test_circuit_bootstrapping_to_exponent::<FFT64Spqlios, CGGI>(&module);
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
mod fft64;
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
mod cpu_spqlios;
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod circuit_bootstrapping;
|
pub mod circuit_bootstrapping;
|
||||||
|
|
||||||
mod implementation;
|
mod fft64;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
// pub mod bdd_arithmetic;
|
// pub mod bdd_arithmetic;
|
||||||
pub mod blind_rotation;
|
pub mod blind_rotation;
|
||||||
//pub mod circuit_bootstrapping;
|
pub mod circuit_bootstrapping;
|
||||||
|
|||||||
Reference in New Issue
Block a user