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:
@@ -7,11 +7,12 @@ use crate::{
|
||||
ScratchTakeCore,
|
||||
automorphism::glwe_ct::GLWEAutomorphism,
|
||||
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
|
||||
where
|
||||
R: GGLWEInfos,
|
||||
@@ -19,11 +20,11 @@ impl AutomorphismKey<Vec<u8>> {
|
||||
K: GGLWEInfos,
|
||||
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>)
|
||||
where
|
||||
A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
|
||||
@@ -31,7 +32,7 @@ impl<DataSelf: DataMut> AutomorphismKey<DataSelf> {
|
||||
Scratch<BE>: ScratchTakeCore<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>)
|
||||
@@ -40,7 +41,7 @@ impl<DataSelf: DataMut> AutomorphismKey<DataSelf> {
|
||||
Scratch<BE>: ScratchTakeCore<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
|
||||
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
|
||||
R: GGLWEInfos,
|
||||
A: GGLWEInfos,
|
||||
@@ -62,7 +63,7 @@ where
|
||||
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
|
||||
R: GGLWEToMut + SetGaloisElement + GGLWEInfos,
|
||||
A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
|
||||
@@ -118,7 +119,7 @@ where
|
||||
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
|
||||
R: GGLWEToMut + SetGaloisElement + GetGaloisElement + GGLWEInfos,
|
||||
K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
automorphism::glwe_ct::GLWEAutomorphism,
|
||||
layouts::{
|
||||
GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GetGaloisElement,
|
||||
prepared::{TensorKeyPrepared, TensorKeyPreparedToRef},
|
||||
prepared::{GLWETensorKeyPrepared, GLWETensorKeyPreparedToRef},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ impl<D: DataMut> GGSW<D> {
|
||||
where
|
||||
A: GGSWToRef,
|
||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<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>)
|
||||
where
|
||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
M: GGSWAutomorphism<BE>,
|
||||
{
|
||||
@@ -79,12 +79,12 @@ where
|
||||
R: GGSWToMut,
|
||||
A: GGSWToRef,
|
||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||
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!(res.dnum() <= a.dnum());
|
||||
@@ -104,11 +104,11 @@ where
|
||||
where
|
||||
R: GGSWToMut,
|
||||
K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
M: GLWEAutomorphism<BE>,
|
||||
A: GLWEToRef,
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
GLWECopy, ScratchTakeCore,
|
||||
layouts::{
|
||||
GGLWE, GGLWEInfos, GGLWEToRef, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, LWEInfos,
|
||||
prepared::{TensorKeyPrepared, TensorKeyPreparedToRef},
|
||||
prepared::{GLWETensorKeyPrepared, GLWETensorKeyPreparedToRef},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ impl<D: DataMut> GGSW<D> {
|
||||
where
|
||||
M: GGSWFromGGLWE<BE>,
|
||||
G: GGLWEToRef,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
module.ggsw_from_gglwe(self, gglwe, tsk, scratch);
|
||||
@@ -54,12 +54,12 @@ where
|
||||
where
|
||||
R: GGSWToMut,
|
||||
A: GGLWEToRef,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||
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.dnum(), a.dnum());
|
||||
@@ -85,7 +85,7 @@ pub trait GGSWFromGGLWE<BE: Backend> {
|
||||
where
|
||||
R: GGSWToMut,
|
||||
A: GGLWEToRef,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<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>)
|
||||
where
|
||||
R: GGSWToMut,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
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_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
|
||||
where
|
||||
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>,
|
||||
) where
|
||||
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> {
|
||||
fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
pub trait GLWEAutomorphismKeyCompressedEncryptSk<BE: Backend> {
|
||||
fn glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos;
|
||||
|
||||
fn automorphism_key_compressed_encrypt_sk<R, S>(
|
||||
fn glwe_automorphism_key_compressed_encrypt_sk<R, S>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
p: i64,
|
||||
@@ -58,12 +58,12 @@ pub trait AutomorphismKeyCompressedEncryptSk<BE: Backend> {
|
||||
S: GLWESecretToRef + GLWEInfos;
|
||||
}
|
||||
|
||||
impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
|
||||
impl<BE: Backend> GLWEAutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
|
||||
where
|
||||
Self: ModuleN + GaloisElement + VecZnxAutomorphism + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedFactory<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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
@@ -73,7 +73,7 @@ where
|
||||
+ 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,
|
||||
res: &mut R,
|
||||
p: i64,
|
||||
|
||||
@@ -8,10 +8,10 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
GGLWECompressedEncryptSk, GetDistribution, ScratchTakeCore, TensorKeyEncryptSk,
|
||||
GGLWECompressedEncryptSk, GLWETensorKeyEncryptSk, GetDistribution, ScratchTakeCore,
|
||||
layouts::{
|
||||
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedFactory, GLWESecretToRef, LWEInfos, Rank,
|
||||
TensorKeyCompressedAtMut, compressed::GLWETensorKeyCompressed,
|
||||
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedFactory, GLWESecretToRef,
|
||||
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
|
||||
where
|
||||
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>,
|
||||
) where
|
||||
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> {
|
||||
fn tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
pub trait GLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
||||
fn glwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos;
|
||||
|
||||
fn tensor_key_compressed_encrypt_sk<R, S, D>(
|
||||
fn glwe_tensor_key_compressed_encrypt_sk<R, S, D>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
sk: &S,
|
||||
@@ -55,15 +55,15 @@ pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
D: DataMut,
|
||||
R: TensorKeyCompressedAtMut<D> + GGLWEInfos,
|
||||
R: GLWETensorKeyCompressedAtMut<D> + GGLWEInfos,
|
||||
S: GLWESecretToRef + GetDistribution;
|
||||
}
|
||||
|
||||
impl<BE: Backend> GGLWETensorKeyCompressedEncryptSk<BE> for Module<BE>
|
||||
impl<BE: Backend> GLWETensorKeyCompressedEncryptSk<BE> for Module<BE>
|
||||
where
|
||||
Self: ModuleN
|
||||
+ GGLWECompressedEncryptSk<BE>
|
||||
+ TensorKeyEncryptSk<BE>
|
||||
+ GLWETensorKeyEncryptSk<BE>
|
||||
+ VecZnxDftApply<BE>
|
||||
+ SvpApplyDftToDft<BE>
|
||||
+ VecZnxIdftApplyTmpA<BE>
|
||||
@@ -75,7 +75,7 @@ where
|
||||
+ GLWESecretPreparedFactory<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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
@@ -87,7 +87,7 @@ where
|
||||
+ 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,
|
||||
res: &mut R,
|
||||
sk: &S,
|
||||
@@ -96,7 +96,7 @@ where
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
D: DataMut,
|
||||
R: GGLWEInfos + TensorKeyCompressedAtMut<D>,
|
||||
R: GGLWEInfos + GLWETensorKeyCompressedAtMut<D>,
|
||||
S: GLWESecretToRef + GetDistribution,
|
||||
{
|
||||
let (mut sk_dft_prep, scratch_1) = scratch.take_glwe_secret_prepared(self, res.rank());
|
||||
|
||||
@@ -7,30 +7,30 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
GGLWEEncryptSk, ScratchTakeCore,
|
||||
layouts::{
|
||||
AutomorphismKey, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESecret, GLWESecretPrepared,
|
||||
GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEAutomorphismKey, GLWEInfos, GLWESecret, GLWESecretPrepared,
|
||||
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
|
||||
where
|
||||
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
|
||||
where
|
||||
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
|
||||
Self: GGLWEToRef,
|
||||
{
|
||||
@@ -44,18 +44,18 @@ where
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
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> {
|
||||
fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
pub trait GLWEAutomorphismKeyEncryptSk<BE: Backend> {
|
||||
fn glwe_automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos;
|
||||
|
||||
fn automorphism_key_encrypt_sk<R, S>(
|
||||
fn glwe_automorphism_key_encrypt_sk<R, S>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
p: i64,
|
||||
@@ -68,12 +68,12 @@ pub trait AutomorphismKeyEncryptSk<BE: Backend> {
|
||||
S: GLWESecretToRef;
|
||||
}
|
||||
|
||||
impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE>
|
||||
impl<BE: Backend> GLWEAutomorphismKeyEncryptSk<BE> for Module<BE>
|
||||
where
|
||||
Self: GGLWEEncryptSk<BE> + VecZnxAutomorphism + GaloisElement + SvpPPolBytesOf + GLWESecretPreparedFactory<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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
@@ -88,7 +88,7 @@ where
|
||||
.max(GLWESecret::bytes_of_from_infos(infos))
|
||||
}
|
||||
|
||||
fn automorphism_key_encrypt_sk<R, S>(
|
||||
fn glwe_automorphism_key_encrypt_sk<R, S>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
p: i64,
|
||||
@@ -106,10 +106,10 @@ where
|
||||
assert_eq!(res.rank_out(), res.rank_in());
|
||||
assert_eq!(sk.rank(), res.rank_out());
|
||||
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(),
|
||||
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());
|
||||
@@ -141,18 +141,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GGLWEAutomorphismKeyEncryptPk<BE: Backend> {
|
||||
fn automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
pub trait GLWEAutomorphismKeyEncryptPk<BE: Backend> {
|
||||
fn glwe_automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos;
|
||||
}
|
||||
|
||||
impl<BE: Backend> GGLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
|
||||
impl<BE: Backend> GLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
|
||||
where
|
||||
Self:,
|
||||
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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
|
||||
@@ -10,22 +10,22 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
GGLWEEncryptSk, GetDistribution, ScratchTakeCore,
|
||||
layouts::{
|
||||
GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey, TensorKeyToMut,
|
||||
GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWETensorKey, GLWETensorKeyToMut, LWEInfos, Rank,
|
||||
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
|
||||
where
|
||||
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>(
|
||||
&mut self,
|
||||
module: &M,
|
||||
@@ -34,20 +34,20 @@ impl<DataSelf: DataMut> TensorKey<DataSelf> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
M: TensorKeyEncryptSk<BE>,
|
||||
M: GLWETensorKeyEncryptSk<BE>,
|
||||
S: GLWESecretToRef + GetDistribution + GLWEInfos,
|
||||
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> {
|
||||
fn tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
pub trait GLWETensorKeyEncryptSk<BE: Backend> {
|
||||
fn glwe_tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos;
|
||||
|
||||
fn tensor_key_encrypt_sk<R, S>(
|
||||
fn glwe_tensor_key_encrypt_sk<R, S>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
sk: &S,
|
||||
@@ -55,11 +55,11 @@ pub trait TensorKeyEncryptSk<BE: Backend> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
R: TensorKeyToMut,
|
||||
R: GLWETensorKeyToMut,
|
||||
S: GLWESecretToRef + GetDistribution + GLWEInfos;
|
||||
}
|
||||
|
||||
impl<BE: Backend> TensorKeyEncryptSk<BE> for Module<BE>
|
||||
impl<BE: Backend> GLWETensorKeyEncryptSk<BE> for Module<BE>
|
||||
where
|
||||
Self: ModuleN
|
||||
+ GGLWEEncryptSk<BE>
|
||||
@@ -72,7 +72,7 @@ where
|
||||
+ VecZnxBigNormalize<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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
@@ -84,7 +84,7 @@ where
|
||||
+ GGLWE::encrypt_sk_tmp_bytes(self, infos)
|
||||
}
|
||||
|
||||
fn tensor_key_encrypt_sk<R, S>(
|
||||
fn glwe_tensor_key_encrypt_sk<R, S>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
sk: &S,
|
||||
@@ -92,10 +92,10 @@ where
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
R: TensorKeyToMut,
|
||||
R: GLWETensorKeyToMut,
|
||||
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 rank: Rank = res.rank_out();
|
||||
|
||||
@@ -3,12 +3,12 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, ZnxZero};
|
||||
use crate::{
|
||||
GLWEExternalProduct, ScratchTakeCore,
|
||||
layouts::{
|
||||
AutomorphismKey, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GGSWPrepared, GLWEInfos, GLWESwitchingKey,
|
||||
GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GGSWPrepared, GLWEAutomorphismKey, GLWEInfos, GLWESwitchingKey,
|
||||
prepared::GGSWPreparedToRef,
|
||||
},
|
||||
};
|
||||
|
||||
impl AutomorphismKey<Vec<u8>> {
|
||||
impl GLWEAutomorphismKey<Vec<u8>> {
|
||||
pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>(
|
||||
&self,
|
||||
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>)
|
||||
where
|
||||
M: GGLWEExternalProduct<BE>,
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::collections::HashMap;
|
||||
|
||||
use poulpy_hal::{
|
||||
api::ModuleLogN,
|
||||
layouts::{Backend, DataMut, GaloisElement, Module, Scratch, VecZnx},
|
||||
layouts::{Backend, DataMut, GaloisElement, Module, Scratch, VecZnx, galois_element},
|
||||
};
|
||||
|
||||
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>
|
||||
where
|
||||
Self: ModuleLogN + GaloisElement + GLWEAutomorphism<BE> + GLWEShift<BE> + GLWECopy,
|
||||
{
|
||||
fn glwe_trace_galois_elements(&self) -> Vec<i64> {
|
||||
(0..self.log_n())
|
||||
.map(|i| {
|
||||
if i == 0 {
|
||||
-1
|
||||
} else {
|
||||
self.galois_element(1 << (i - 1))
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
trace_galois_elements(self.log_n(), self.cyclotomic_order())
|
||||
}
|
||||
|
||||
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::{
|
||||
ScratchTakeCore,
|
||||
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
|
||||
where
|
||||
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>)
|
||||
where
|
||||
A: GGLWEToRef + GGLWEToRef,
|
||||
|
||||
@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, VecZnx};
|
||||
use crate::{
|
||||
GGSWExpandRows, ScratchTakeCore,
|
||||
keyswitching::GLWEKeyswitch,
|
||||
layouts::{GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, prepared::TensorKeyPreparedToRef},
|
||||
layouts::{GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, prepared::GLWETensorKeyPreparedToRef},
|
||||
};
|
||||
|
||||
impl GGSW<Vec<u8>> {
|
||||
@@ -30,7 +30,7 @@ impl<D: DataMut> GGSW<D> {
|
||||
where
|
||||
A: GGSWToRef,
|
||||
K: GGLWEPreparedToRef<BE>,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<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>)
|
||||
where
|
||||
K: GGLWEPreparedToRef<BE>,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
M: GGSWKeyswitch<BE>,
|
||||
{
|
||||
@@ -91,7 +91,7 @@ where
|
||||
R: GGSWToMut,
|
||||
A: GGSWToRef,
|
||||
K: GGLWEPreparedToRef<BE>,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||
@@ -113,7 +113,7 @@ where
|
||||
where
|
||||
R: GGSWToMut,
|
||||
K: GGLWEPreparedToRef<BE>,
|
||||
T: TensorKeyPreparedToRef<BE>,
|
||||
T: GLWETensorKeyPreparedToRef<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||
|
||||
@@ -4,8 +4,8 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut,
|
||||
GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWEDecompress, GLWEInfos, GetGaloisElement, LWEInfos, Rank,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWECompressedToRef,
|
||||
GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWEAutomorphismKey, GLWEDecompress, GLWEInfos, GetGaloisElement, LWEInfos, Rank,
|
||||
SetGaloisElement, TorusPrecision,
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
@@ -154,7 +154,7 @@ where
|
||||
|
||||
impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: GLWEDecompress {}
|
||||
|
||||
impl<D: DataMut> AutomorphismKey<D>
|
||||
impl<D: DataMut> GLWEAutomorphismKey<D>
|
||||
where
|
||||
Self: SetGaloisElement,
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
|
||||
use crate::layouts::{
|
||||
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 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>;
|
||||
}
|
||||
|
||||
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> {
|
||||
if i > 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>;
|
||||
}
|
||||
|
||||
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> {
|
||||
if i > 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
|
||||
Self: GGLWEDecompress,
|
||||
{
|
||||
fn decompress_tensor_key<R, O>(&self, res: &mut R, other: &O)
|
||||
where
|
||||
R: TensorKeyToMut,
|
||||
O: TensorKeyCompressedToRef,
|
||||
R: GLWETensorKeyToMut,
|
||||
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();
|
||||
|
||||
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)
|
||||
where
|
||||
O: TensorKeyCompressedToRef,
|
||||
M: TensorKeyDecompress,
|
||||
O: GLWETensorKeyCompressedToRef,
|
||||
M: GLWETensorKeyDecompress,
|
||||
{
|
||||
module.decompress_tensor_key(self, other);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyCompressedToMut {
|
||||
pub trait GLWETensorKeyCompressedToMut {
|
||||
fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> TensorKeyCompressedToMut for GLWETensorKeyCompressed<D>
|
||||
impl<D: DataMut> GLWETensorKeyCompressedToMut for GLWETensorKeyCompressed<D>
|
||||
where
|
||||
GGLWECompressed<D>: GGLWECompressedToMut,
|
||||
{
|
||||
@@ -230,11 +230,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyCompressedToRef {
|
||||
pub trait GLWETensorKeyCompressedToRef {
|
||||
fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataRef> TensorKeyCompressedToRef for GLWETensorKeyCompressed<D>
|
||||
impl<D: DataRef> GLWETensorKeyCompressedToRef for GLWETensorKeyCompressed<D>
|
||||
where
|
||||
GGLWECompressed<D>: GGLWECompressedToRef,
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub struct AutomorphismKeyLayout {
|
||||
pub struct GLWEAutomorphismKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
@@ -21,7 +21,7 @@ pub struct AutomorphismKeyLayout {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct AutomorphismKey<D: Data> {
|
||||
pub struct GLWEAutomorphismKey<D: Data> {
|
||||
pub(crate) key: GGLWE<D>,
|
||||
pub(crate) p: i64,
|
||||
}
|
||||
@@ -34,25 +34,25 @@ pub trait SetGaloisElement {
|
||||
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) {
|
||||
self.p = p
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> GetGaloisElement for AutomorphismKey<D> {
|
||||
impl<D: DataRef> GetGaloisElement for GLWEAutomorphismKey<D> {
|
||||
fn p(&self) -> i64 {
|
||||
self.p
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> AutomorphismKey<D> {
|
||||
impl<D: Data> GLWEAutomorphismKey<D> {
|
||||
pub fn p(&self) -> i64 {
|
||||
self.p
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> LWEInfos for AutomorphismKey<D> {
|
||||
impl<D: Data> LWEInfos for GLWEAutomorphismKey<D> {
|
||||
fn n(&self) -> Degree {
|
||||
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 {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWEInfos for AutomorphismKey<D> {
|
||||
impl<D: Data> GGLWEInfos for GLWEAutomorphismKey<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
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 {
|
||||
self.base2k
|
||||
}
|
||||
@@ -108,13 +108,13 @@ impl LWEInfos for AutomorphismKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLWEInfos for AutomorphismKeyLayout {
|
||||
impl GLWEInfos for GLWEAutomorphismKeyLayout {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWEInfos for AutomorphismKeyLayout {
|
||||
impl GGLWEInfos for GLWEAutomorphismKeyLayout {
|
||||
fn rank_in(&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 {
|
||||
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) {
|
||||
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 {
|
||||
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
|
||||
where
|
||||
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 {
|
||||
AutomorphismKey {
|
||||
GLWEAutomorphismKey {
|
||||
key: GGLWE::alloc(n, base2k, k, rank, rank, dnum, dsize),
|
||||
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]> {
|
||||
self.key.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> GGLWEToRef for AutomorphismKey<D> {
|
||||
impl<D: DataMut> GGLWEToRef for GLWEAutomorphismKey<D> {
|
||||
fn to_ref(&self) -> GGLWE<&[u8]> {
|
||||
self.key.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> AutomorphismKey<D> {
|
||||
impl<D: DataRef> GLWEAutomorphismKey<D> {
|
||||
pub fn at(&self, row: usize, col: usize) -> GLWE<&[u8]> {
|
||||
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]> {
|
||||
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<()> {
|
||||
self.p = reader.read_u64::<LittleEndian>()? as i64;
|
||||
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<()> {
|
||||
writer.write_u64::<LittleEndian>(self.p as u64)?;
|
||||
self.key.write_to(writer)
|
||||
|
||||
@@ -11,7 +11,7 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub struct TensorKeyLayout {
|
||||
pub struct GLWETensorKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
@@ -21,11 +21,11 @@ pub struct TensorKeyLayout {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct TensorKey<D: Data> {
|
||||
pub struct GLWETensorKey<D: Data> {
|
||||
pub(crate) keys: Vec<GGLWE<D>>,
|
||||
}
|
||||
|
||||
impl<D: Data> LWEInfos for TensorKey<D> {
|
||||
impl<D: Data> LWEInfos for GLWETensorKey<D> {
|
||||
fn n(&self) -> Degree {
|
||||
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 {
|
||||
self.keys[0].rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWEInfos for TensorKey<D> {
|
||||
impl<D: Data> GGLWEInfos for GLWETensorKey<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
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 {
|
||||
self.n
|
||||
}
|
||||
@@ -81,13 +81,13 @@ impl LWEInfos for TensorKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLWEInfos for TensorKeyLayout {
|
||||
impl GLWEInfos for GLWETensorKeyLayout {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWEInfos for TensorKeyLayout {
|
||||
impl GGLWEInfos for GLWETensorKeyLayout {
|
||||
fn rank_in(&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 {
|
||||
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) {
|
||||
self.keys
|
||||
.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 {
|
||||
writeln!(f, "(GLWETensorKey)",)?;
|
||||
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
|
||||
where
|
||||
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 {
|
||||
let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1);
|
||||
TensorKey {
|
||||
GLWETensorKey {
|
||||
keys: (0..pairs)
|
||||
.map(|_| GGLWE::alloc(n, base2k, k, Rank(1), rank, dnum, dsize))
|
||||
.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])
|
||||
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWE<D> {
|
||||
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])
|
||||
pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWE<D> {
|
||||
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<()> {
|
||||
let len: usize = reader.read_u64::<LittleEndian>()? as usize;
|
||||
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<()> {
|
||||
writer.write_u64::<LittleEndian>(self.keys.len() as u64)?;
|
||||
for key in &self.keys {
|
||||
@@ -231,31 +231,31 @@ impl<D: DataRef> WriterTo for TensorKey<D> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyToRef {
|
||||
fn to_ref(&self) -> TensorKey<&[u8]>;
|
||||
pub trait GLWETensorKeyToRef {
|
||||
fn to_ref(&self) -> GLWETensorKey<&[u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataRef> TensorKeyToRef for TensorKey<D>
|
||||
impl<D: DataRef> GLWETensorKeyToRef for GLWETensorKey<D>
|
||||
where
|
||||
GGLWE<D>: GGLWEToRef,
|
||||
{
|
||||
fn to_ref(&self) -> TensorKey<&[u8]> {
|
||||
TensorKey {
|
||||
fn to_ref(&self) -> GLWETensorKey<&[u8]> {
|
||||
GLWETensorKey {
|
||||
keys: self.keys.iter().map(|c| c.to_ref()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyToMut {
|
||||
fn to_mut(&mut self) -> TensorKey<&mut [u8]>;
|
||||
pub trait GLWETensorKeyToMut {
|
||||
fn to_mut(&mut self) -> GLWETensorKey<&mut [u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> TensorKeyToMut for TensorKey<D>
|
||||
impl<D: DataMut> GLWETensorKeyToMut for GLWETensorKey<D>
|
||||
where
|
||||
GGLWE<D>: GGLWEToMut,
|
||||
{
|
||||
fn to_mut(&mut self) -> TensorKey<&mut [u8]> {
|
||||
TensorKey {
|
||||
fn to_mut(&mut self) -> GLWETensorKey<&mut [u8]> {
|
||||
GLWETensorKey {
|
||||
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
pub trait LWEInfos {
|
||||
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 max_k(&self) -> TorusPrecision {
|
||||
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::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedFactory, GGLWEPreparedToMut, GGLWEPreparedToRef,
|
||||
GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
|
||||
GLWEInfos, GLWETensorKey, GLWETensorKeyToRef, LWEInfos, Rank, TorusPrecision,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct TensorKeyPrepared<D: Data, B: Backend> {
|
||||
pub struct GLWETensorKeyPrepared<D: Data, B: Backend> {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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
|
||||
Self: GGLWEPreparedFactory<B>,
|
||||
{
|
||||
@@ -63,16 +63,16 @@ where
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
rank: Rank,
|
||||
) -> TensorKeyPrepared<Vec<u8>, B> {
|
||||
) -> GLWETensorKeyPrepared<Vec<u8>, B> {
|
||||
let pairs: u32 = (((rank.as_u32() + 1) * rank.as_u32()) >> 1).max(1);
|
||||
TensorKeyPrepared {
|
||||
GLWETensorKeyPrepared {
|
||||
keys: (0..pairs)
|
||||
.map(|_| self.alloc_gglwe_prepared(base2k, k, Rank(1), rank, dnum, dsize))
|
||||
.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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
@@ -117,11 +117,11 @@ where
|
||||
|
||||
fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: TensorKeyPreparedToMut<B>,
|
||||
O: TensorKeyToRef,
|
||||
R: GLWETensorKeyPreparedToMut<B>,
|
||||
O: GLWETensorKeyToRef,
|
||||
{
|
||||
let mut res: TensorKeyPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: TensorKey<&[u8]> = other.to_ref();
|
||||
let mut res: GLWETensorKeyPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: GLWETensorKey<&[u8]> = other.to_ref();
|
||||
|
||||
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
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: TensorKeyPreparedFactory<B>,
|
||||
M: GLWETensorKeyPreparedFactory<B>,
|
||||
{
|
||||
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
|
||||
where
|
||||
M: TensorKeyPreparedFactory<B>,
|
||||
M: GLWETensorKeyPreparedFactory<B>,
|
||||
{
|
||||
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
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: TensorKeyPreparedFactory<B>,
|
||||
M: GLWETensorKeyPreparedFactory<B>,
|
||||
{
|
||||
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
|
||||
where
|
||||
M: TensorKeyPreparedFactory<B>,
|
||||
M: GLWETensorKeyPreparedFactory<B>,
|
||||
{
|
||||
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])
|
||||
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWEPrepared<D, B> {
|
||||
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])
|
||||
pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWEPrepared<D, B> {
|
||||
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
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: TensorKeyPreparedFactory<B>,
|
||||
M: GLWETensorKeyPreparedFactory<B>,
|
||||
{
|
||||
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>)
|
||||
where
|
||||
O: TensorKeyToRef,
|
||||
M: TensorKeyPreparedFactory<B>,
|
||||
O: GLWETensorKeyToRef,
|
||||
M: GLWETensorKeyPreparedFactory<B>,
|
||||
{
|
||||
module.prepare_tensor_key(self, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> TensorKeyPrepared<&mut [u8], B>;
|
||||
pub trait GLWETensorKeyPreparedToMut<B: Backend> {
|
||||
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
|
||||
GGLWEPrepared<D, B>: GGLWEPreparedToMut<B>,
|
||||
{
|
||||
fn to_mut(&mut self) -> TensorKeyPrepared<&mut [u8], B> {
|
||||
TensorKeyPrepared {
|
||||
fn to_mut(&mut self) -> GLWETensorKeyPrepared<&mut [u8], B> {
|
||||
GLWETensorKeyPrepared {
|
||||
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> TensorKeyPrepared<&[u8], B>;
|
||||
pub trait GLWETensorKeyPreparedToRef<B: Backend> {
|
||||
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
|
||||
GGLWEPrepared<D, B>: GGLWEPreparedToRef<B>,
|
||||
{
|
||||
fn to_ref(&self) -> TensorKeyPrepared<&[u8], B> {
|
||||
TensorKeyPrepared {
|
||||
fn to_ref(&self) -> GLWETensorKeyPrepared<&[u8], B> {
|
||||
GLWETensorKeyPrepared {
|
||||
keys: self.keys.iter().map(|c| c.to_ref()).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ pub use dist::*;
|
||||
pub use encryption::*;
|
||||
pub use external_product::*;
|
||||
pub use glwe_packing::*;
|
||||
pub use glwe_trace::*;
|
||||
pub use keyswitching::*;
|
||||
pub use noise::*;
|
||||
pub use scratch::*;
|
||||
|
||||
@@ -6,11 +6,11 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
dist::Distribution,
|
||||
layouts::{
|
||||
AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPrepared,
|
||||
GLWEPublicKey, GLWESecret, GLWESwitchingKey, Rank, TensorKey,
|
||||
Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEAutomorphismKey, GLWEInfos, GLWEPlaintext,
|
||||
GLWEPrepared, GLWEPublicKey, GLWESecret, GLWESwitchingKey, GLWETensorKey, Rank,
|
||||
prepared::{
|
||||
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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
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>(
|
||||
@@ -304,14 +304,14 @@ where
|
||||
(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
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
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 pairs: usize = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1) as usize;
|
||||
@@ -331,10 +331,10 @@ where
|
||||
scratch = s;
|
||||
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
|
||||
A: GGLWEInfos,
|
||||
M: ModuleN + VmpPMatBytesOf,
|
||||
@@ -364,7 +364,7 @@ where
|
||||
scratch = s;
|
||||
keys.push(gglwe);
|
||||
}
|
||||
(TensorKeyPrepared { keys }, scratch)
|
||||
(GLWETensorKeyPrepared { keys }, scratch)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use poulpy_hal::test_suite::serialization::test_reader_writer_interface;
|
||||
|
||||
use crate::layouts::{
|
||||
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE,
|
||||
LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWEAutomorphismKey, GLWESwitchingKey, GLWETensorKey, GLWEToLWESwitchingKey,
|
||||
LWE, LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TorusPrecision,
|
||||
compressed::{
|
||||
GGLWECompressed, GGSWCompressed, GLWEAutomorphismKeyCompressed, GLWECompressed, GLWESwitchingKeyCompressed,
|
||||
GLWETensorKeyCompressed, GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed,
|
||||
@@ -69,7 +69,7 @@ fn test_glwe_switching_key_compressed_serialization() {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ fn test_automorphism_key_compressed_serialization() {
|
||||
|
||||
#[test]
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AutomorphismKeyEncryptSk, GLWEAutomorphismKeyAutomorphism, GLWEDecrypt, ScratchTakeCore,
|
||||
GLWEAutomorphismKeyAutomorphism, GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, ScratchTakeCore,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GLWEAutomorphismKeyPreparedFactory, GLWEPlaintext, GLWESecret,
|
||||
GLWESecretPreparedFactory,
|
||||
GGLWEInfos, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWEPlaintext,
|
||||
GLWESecret, GLWESecretPreparedFactory,
|
||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||
},
|
||||
noise::log2_std_noise_gglwe_product,
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn test_gglwe_automorphism_key_automorphism<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: AutomorphismKeyEncryptSk<BE>
|
||||
Module<BE>: GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ GLWEAutomorphismKeyAutomorphism<BE>
|
||||
+ VecZnxAutomorphism
|
||||
@@ -46,7 +46,7 @@ where
|
||||
let dnum_out: usize = k_out / (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(),
|
||||
base2k: base2k.into(),
|
||||
k: k_in.into(),
|
||||
@@ -55,7 +55,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_out_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let auto_key_out_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -64,7 +64,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_apply_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let auto_key_apply_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_apply.into(),
|
||||
@@ -73,18 +73,18 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut auto_key_in: AutomorphismKey<Vec<u8>> = AutomorphismKey::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_apply: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_apply_infos);
|
||||
let mut auto_key_in: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_in_infos);
|
||||
let mut auto_key_out: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_out_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_xe: 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, &auto_key_in_infos)
|
||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply_infos)
|
||||
| AutomorphismKey::automorphism_tmp_bytes(
|
||||
GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_in_infos)
|
||||
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply_infos)
|
||||
| GLWEAutomorphismKey::automorphism_tmp_bytes(
|
||||
module,
|
||||
&auto_key_out_infos,
|
||||
&auto_key_in_infos,
|
||||
@@ -187,7 +187,7 @@ where
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn test_gglwe_automorphism_key_automorphism_inplace<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: AutomorphismKeyEncryptSk<BE>
|
||||
Module<BE>: GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ GLWEAutomorphismKeyAutomorphism<BE>
|
||||
+ VecZnxAutomorphism
|
||||
@@ -213,7 +213,7 @@ where
|
||||
let dnum_in: usize = k_in / (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(),
|
||||
base2k: base2k.into(),
|
||||
k: k_in.into(),
|
||||
@@ -222,7 +222,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_apply_layout: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let auto_key_apply_layout: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_apply.into(),
|
||||
@@ -231,17 +231,17 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::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: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&auto_key_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_xe: 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, &auto_key)
|
||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply)
|
||||
| AutomorphismKey::automorphism_tmp_bytes(module, &auto_key, &auto_key, &auto_key_apply),
|
||||
GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &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);
|
||||
|
||||
@@ -5,12 +5,12 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AutomorphismKeyEncryptSk, GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, TensorKeyEncryptSk,
|
||||
GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, GLWEAutomorphismKeyEncryptSk, GLWETensorKeyEncryptSk, ScratchTakeCore,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
AutomorphismKey, GGSW, GGSWLayout, GLWEAutomorphismKeyPreparedFactory, GLWESecret, GLWESecretPreparedFactory, TensorKey,
|
||||
TensorKeyLayout, TensorKeyPreparedFactory,
|
||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared},
|
||||
GGSW, GGSWLayout, GLWEAutomorphismKey, GLWEAutomorphismKeyPreparedFactory, GLWESecret, GLWESecretPreparedFactory,
|
||||
GLWETensorKey, GLWETensorKeyLayout, GLWETensorKeyPreparedFactory,
|
||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, GLWETensorKeyPrepared},
|
||||
},
|
||||
noise::noise_ggsw_keyswitch,
|
||||
};
|
||||
@@ -18,11 +18,11 @@ use crate::{
|
||||
pub fn test_ggsw_automorphism<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GGSWEncryptSk<BE>
|
||||
+ AutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ GGSWAutomorphism<BE>
|
||||
+ TensorKeyPreparedFactory<BE>
|
||||
+ TensorKeyEncryptSk<BE>
|
||||
+ GLWETensorKeyPreparedFactory<BE>
|
||||
+ GLWETensorKeyEncryptSk<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ VecZnxAutomorphismInplace<BE>
|
||||
+ GGSWNoise<BE>,
|
||||
@@ -64,7 +64,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tensor_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
let tensor_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_tsk.into(),
|
||||
@@ -73,7 +73,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
let auto_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.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_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 auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_layout);
|
||||
let mut tensor_key: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tensor_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 source_xs: Source = Source::new([0u8; 32]);
|
||||
@@ -94,8 +94,8 @@ where
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||
GGSW::encrypt_sk_tmp_bytes(module, &ct_in)
|
||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||
| TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
|
||||
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||
| GLWETensorKey::encrypt_sk_tmp_bytes(module, &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);
|
||||
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
||||
|
||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
|
||||
TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
||||
let mut tsk_prepared: GLWETensorKeyPrepared<Vec<u8>, BE> =
|
||||
GLWETensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
||||
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
||||
|
||||
ct_out.automorphism(
|
||||
@@ -177,11 +177,11 @@ where
|
||||
pub fn test_ggsw_automorphism_inplace<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GGSWEncryptSk<BE>
|
||||
+ AutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ GGSWAutomorphism<BE>
|
||||
+ TensorKeyPreparedFactory<BE>
|
||||
+ TensorKeyEncryptSk<BE>
|
||||
+ GLWETensorKeyPreparedFactory<BE>
|
||||
+ GLWETensorKeyEncryptSk<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ VecZnxAutomorphismInplace<BE>
|
||||
+ GGSWNoise<BE>,
|
||||
@@ -211,7 +211,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tensor_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
let tensor_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_tsk.into(),
|
||||
@@ -220,7 +220,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
let auto_key_layout: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.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 tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tensor_key_layout);
|
||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&auto_key_layout);
|
||||
let mut tensor_key: GLWETensorKey<Vec<u8>> = GLWETensorKey::alloc_from_infos(&tensor_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 source_xs: Source = Source::new([0u8; 32]);
|
||||
@@ -240,8 +240,8 @@ where
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||
GGSW::encrypt_sk_tmp_bytes(module, &ct)
|
||||
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||
| TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
|
||||
| GLWEAutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
|
||||
| GLWETensorKey::encrypt_sk_tmp_bytes(module, &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);
|
||||
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
||||
|
||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
|
||||
TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
||||
let mut tsk_prepared: GLWETensorKeyPrepared<Vec<u8>, BE> =
|
||||
GLWETensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
|
||||
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
||||
|
||||
ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow());
|
||||
|
||||
@@ -5,11 +5,11 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AutomorphismKeyEncryptSk, GLWEAutomorphism, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
GLWEAutomorphism, GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext, GLWESecret,
|
||||
GLWESecretPreparedFactory,
|
||||
GLWE, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext,
|
||||
GLWESecret, GLWESecretPreparedFactory,
|
||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||
},
|
||||
noise::log2_std_noise_gglwe_product,
|
||||
@@ -22,7 +22,7 @@ where
|
||||
+ VecZnxFillUniform
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWEAutomorphism<BE>
|
||||
+ AutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ VecZnxAutomorphismInplace<BE>,
|
||||
@@ -55,7 +55,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let autokey_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -64,7 +64,7 @@ where
|
||||
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_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);
|
||||
@@ -76,7 +76,7 @@ where
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
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::encrypt_sk_tmp_bytes(module, &ct_in)
|
||||
| GLWE::automorphism_tmp_bytes(module, &ct_out, &ct_in, &autokey),
|
||||
@@ -140,7 +140,7 @@ where
|
||||
+ VecZnxFillUniform
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWEAutomorphism<BE>
|
||||
+ AutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ VecZnxAutomorphismInplace<BE>,
|
||||
@@ -165,7 +165,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let autokey_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -174,7 +174,7 @@ where
|
||||
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 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);
|
||||
|
||||
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::encrypt_sk_tmp_bytes(module, &ct)
|
||||
| GLWE::automorphism_tmp_bytes(module, &ct, &ct, &autokey),
|
||||
|
||||
@@ -5,19 +5,20 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AutomorphismKeyCompressedEncryptSk, AutomorphismKeyEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk,
|
||||
GGLWEKeyswitch, GLWEAutomorphismKeyCompressedEncryptSk, GLWEAutomorphismKeyEncryptSk, GLWESwitchingKeyCompressedEncryptSk,
|
||||
GLWESwitchingKeyEncryptSk, ScratchTakeCore,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, GLWESecret, GLWESecretPreparedFactory,
|
||||
GLWESwitchingKeyDecompress, compressed::GLWEAutomorphismKeyCompressed, prepared::GLWESecretPrepared,
|
||||
AutomorphismKeyDecompress, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEInfos, GLWESecret,
|
||||
GLWESecretPreparedFactory, GLWESwitchingKeyDecompress, compressed::GLWEAutomorphismKeyCompressed,
|
||||
prepared::GLWESecretPrepared,
|
||||
},
|
||||
noise::GGLWENoise,
|
||||
};
|
||||
|
||||
pub fn test_gglwe_automorphism_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: AutomorphismKeyEncryptSk<BE>
|
||||
Module<BE>: GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GGLWEKeyswitch<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
@@ -37,7 +38,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let atk_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -46,13 +47,15 @@ where
|
||||
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_xe: 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);
|
||||
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>)
|
||||
where
|
||||
Module<BE>: AutomorphismKeyCompressedEncryptSk<BE>
|
||||
Module<BE>: GLWEAutomorphismKeyCompressedEncryptSk<BE>
|
||||
+ GGLWEKeyswitch<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
@@ -109,7 +112,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let atk_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.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());
|
||||
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.key
|
||||
|
||||
@@ -9,18 +9,18 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
GGLWETensorKeyCompressedEncryptSk, ScratchTakeCore, TensorKeyEncryptSk,
|
||||
GLWETensorKeyCompressedEncryptSk, GLWETensorKeyEncryptSk, ScratchTakeCore,
|
||||
decryption::GLWEDecrypt,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
Dsize, GLWEPlaintext, GLWESecret, GLWESecretPreparedFactory, GLWETensorKeyCompressed, TensorKey, TensorKeyLayout,
|
||||
Dsize, GLWEPlaintext, GLWESecret, GLWESecretPreparedFactory, GLWETensorKey, GLWETensorKeyCompressed, GLWETensorKeyLayout,
|
||||
prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_gglwe_tensor_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: TensorKeyEncryptSk<BE>
|
||||
Module<BE>: GLWETensorKeyEncryptSk<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ VecZnxDftAlloc<BE>
|
||||
@@ -40,7 +40,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = k / base2k;
|
||||
|
||||
let tensor_key_infos = TensorKeyLayout {
|
||||
let tensor_key_infos = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k.into(),
|
||||
@@ -49,13 +49,16 @@ where
|
||||
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_xe: 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);
|
||||
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>)
|
||||
where
|
||||
Module<BE>: TensorKeyEncryptSk<BE>
|
||||
Module<BE>: GLWETensorKeyEncryptSk<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GGLWETensorKeyCompressedEncryptSk<BE>
|
||||
+ GLWETensorKeyCompressedEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ VecZnxDftAlloc<BE>
|
||||
+ VecZnxBigAlloc<BE>
|
||||
@@ -133,7 +136,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = k / base2k;
|
||||
|
||||
let tensor_key_infos: TensorKeyLayout = TensorKeyLayout {
|
||||
let tensor_key_infos: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k.into(),
|
||||
@@ -162,7 +165,7 @@ where
|
||||
|
||||
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);
|
||||
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&tensor_key_infos);
|
||||
|
||||
@@ -5,12 +5,12 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
GGSWEncryptSk, GGSWKeyswitch, GGSWNoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, TensorKeyEncryptSk,
|
||||
GGSWEncryptSk, GGSWKeyswitch, GGSWNoise, GLWESwitchingKeyEncryptSk, GLWETensorKeyEncryptSk, ScratchTakeCore,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGSW, GGSWLayout, GLWESecret, GLWESecretPreparedFactory, GLWESwitchingKey, GLWESwitchingKeyLayout,
|
||||
GLWESwitchingKeyPreparedFactory, TensorKey, TensorKeyLayout, TensorKeyPreparedFactory,
|
||||
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared},
|
||||
GLWESwitchingKeyPreparedFactory, GLWETensorKey, GLWETensorKeyLayout, GLWETensorKeyPreparedFactory,
|
||||
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, GLWETensorKeyPrepared},
|
||||
},
|
||||
noise::noise_ggsw_keyswitch,
|
||||
};
|
||||
@@ -20,10 +20,10 @@ pub fn test_ggsw_keyswitch<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GGSWEncryptSk<BE>
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ TensorKeyEncryptSk<BE>
|
||||
+ GLWETensorKeyEncryptSk<BE>
|
||||
+ GGSWKeyswitch<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ TensorKeyPreparedFactory<BE>
|
||||
+ GLWETensorKeyPreparedFactory<BE>
|
||||
+ GLWESwitchingKeyPreparedFactory<BE>
|
||||
+ GGSWNoise<BE>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
@@ -61,7 +61,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tsk_infos: TensorKeyLayout = TensorKeyLayout {
|
||||
let tsk_infos: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.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_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 pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
@@ -93,7 +93,7 @@ where
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_in_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(
|
||||
module,
|
||||
&ggsw_out_infos,
|
||||
@@ -148,7 +148,7 @@ where
|
||||
GLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
||||
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());
|
||||
|
||||
ggsw_out.keyswitch(
|
||||
@@ -185,10 +185,10 @@ pub fn test_ggsw_keyswitch_inplace<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GGSWEncryptSk<BE>
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ TensorKeyEncryptSk<BE>
|
||||
+ GLWETensorKeyEncryptSk<BE>
|
||||
+ GGSWKeyswitch<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ TensorKeyPreparedFactory<BE>
|
||||
+ GLWETensorKeyPreparedFactory<BE>
|
||||
+ GLWESwitchingKeyPreparedFactory<BE>
|
||||
+ GGSWNoise<BE>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
@@ -216,7 +216,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tsk_infos: TensorKeyLayout = TensorKeyLayout {
|
||||
let tsk_infos: GLWETensorKeyLayout = GLWETensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.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 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 pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
@@ -247,7 +247,7 @@ where
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_out_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(
|
||||
module,
|
||||
&ggsw_out_infos,
|
||||
@@ -302,7 +302,7 @@ where
|
||||
GLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
||||
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());
|
||||
|
||||
ggsw_out.keyswitch_inplace(module, &ksk_prepared, &tsk_prepared, scratch.borrow());
|
||||
|
||||
@@ -7,10 +7,10 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWEPacker, GLWEPacking, GLWERotate, GLWESub, ScratchTakeCore,
|
||||
GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWEPacker, GLWEPacking, GLWERotate, GLWESub, ScratchTakeCore,
|
||||
layouts::{
|
||||
AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext, GLWESecret,
|
||||
GLWESecretPreparedFactory,
|
||||
GLWE, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext,
|
||||
GLWESecret, GLWESecretPreparedFactory,
|
||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||
},
|
||||
};
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
pub fn test_glwe_packing<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GLWEEncryptSk<BE>
|
||||
+ AutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ GLWEPacking<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
@@ -49,7 +49,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let key_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -60,7 +60,7 @@ where
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||
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),
|
||||
);
|
||||
|
||||
@@ -81,7 +81,7 @@ where
|
||||
let gal_els: Vec<i64> = GLWEPacker::galois_elements(module);
|
||||
|
||||
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| {
|
||||
tmp.encrypt_sk(
|
||||
module,
|
||||
|
||||
@@ -7,12 +7,12 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, ScratchTakeCore,
|
||||
GLWEAutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, ScratchTakeCore,
|
||||
encryption::SIGMA,
|
||||
glwe_trace::GLWETrace,
|
||||
layouts::{
|
||||
AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext, GLWESecret,
|
||||
GLWESecretPreparedFactory, LWEInfos,
|
||||
GLWE, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWELayout, GLWEPlaintext,
|
||||
GLWESecret, GLWESecretPreparedFactory, LWEInfos,
|
||||
prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
|
||||
},
|
||||
noise::var_noise_gglwe_product,
|
||||
@@ -23,7 +23,7 @@ where
|
||||
Module<BE>: GLWETrace<BE>
|
||||
+ GLWEEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ AutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyEncryptSk<BE>
|
||||
+ GLWEAutomorphismKeyPreparedFactory<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
@@ -49,7 +49,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
let key_infos: GLWEAutomorphismKeyLayout = GLWEAutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_autokey.into(),
|
||||
@@ -69,7 +69,7 @@ where
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||
GLWE::encrypt_sk_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),
|
||||
);
|
||||
|
||||
@@ -98,7 +98,7 @@ where
|
||||
|
||||
let mut auto_keys: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new();
|
||||
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| {
|
||||
tmp.encrypt_sk(
|
||||
module,
|
||||
|
||||
Reference in New Issue
Block a user