mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
wip
This commit is contained in:
@@ -18,8 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GGLWEInfos, GLWEPlaintext, GLWESecret,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GLWEPlaintext, GLWESecret,
|
||||
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
},
|
||||
noise::log2_std_noise_gglwe_product,
|
||||
};
|
||||
@@ -84,7 +84,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: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let auto_key_in_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_in.into(),
|
||||
@@ -93,7 +93,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_out_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let auto_key_out_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -102,7 +102,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_apply_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let auto_key_apply_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_apply.into(),
|
||||
@@ -111,18 +111,18 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut auto_key_in: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_in_infos);
|
||||
let mut auto_key_out: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_out_infos);
|
||||
let mut auto_key_apply: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_apply_infos);
|
||||
let mut auto_key_in: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_in_infos);
|
||||
let mut auto_key_out: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_out_infos);
|
||||
let mut auto_key_apply: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&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<B> = ScratchOwned::alloc(
|
||||
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_in_infos)
|
||||
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply_infos)
|
||||
| GGLWEAutomorphismKey::automorphism_scratch_space(
|
||||
AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_in_infos)
|
||||
| AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply_infos)
|
||||
| AutomorphismKey::automorphism_scratch_space(
|
||||
module,
|
||||
&auto_key_out_infos,
|
||||
&auto_key_in_infos,
|
||||
@@ -153,8 +153,8 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut auto_key_apply_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_apply_infos);
|
||||
let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
AutomorphismKeyPrepared::alloc(module, &auto_key_apply_infos);
|
||||
|
||||
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
|
||||
|
||||
@@ -293,7 +293,7 @@ where
|
||||
let dnum_in: usize = k_in / (base2k * di);
|
||||
let dnum_apply: usize = k_in.div_ceil(base2k * di);
|
||||
|
||||
let auto_key_layout: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let auto_key_layout: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_in.into(),
|
||||
@@ -302,7 +302,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_apply_layout: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let auto_key_apply_layout: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_apply.into(),
|
||||
@@ -311,17 +311,17 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut auto_key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_layout);
|
||||
let mut auto_key_apply: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_apply_layout);
|
||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_layout);
|
||||
let mut auto_key_apply: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&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<B> = ScratchOwned::alloc(
|
||||
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key)
|
||||
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply)
|
||||
| GGLWEAutomorphismKey::automorphism_inplace_scratch_space(module, &auto_key, &auto_key_apply),
|
||||
AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key)
|
||||
| AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply)
|
||||
| AutomorphismKey::automorphism_inplace_scratch_space(module, &auto_key, &auto_key_apply),
|
||||
);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(&auto_key);
|
||||
@@ -347,8 +347,8 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut auto_key_apply_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_apply_layout);
|
||||
let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
AutomorphismKeyPrepared::alloc(module, &auto_key_apply_layout);
|
||||
|
||||
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWETensorKey, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWESecret,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
AutomorphismKey, GGSW, GGSWCiphertextLayout, GLWESecret, TensorKey, TensorKeyLayout,
|
||||
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc, TensorKeyPrepared},
|
||||
},
|
||||
noise::noise_ggsw_keyswitch,
|
||||
};
|
||||
@@ -110,7 +110,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tensor_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout {
|
||||
let tensor_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_tsk.into(),
|
||||
@@ -119,7 +119,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout {
|
||||
let auto_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -128,10 +128,10 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ct_in: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_in_layout);
|
||||
let mut ct_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_layout);
|
||||
let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_layout);
|
||||
let mut auto_key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_layout);
|
||||
let mut ct_in: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_in_layout);
|
||||
let mut ct_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_layout);
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&tensor_key_layout);
|
||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_layout);
|
||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
@@ -139,10 +139,10 @@ where
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ct_in)
|
||||
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key)
|
||||
| GGLWETensorKey::encrypt_sk_scratch_space(module, &tensor_key)
|
||||
| GGSWCiphertext::automorphism_scratch_space(module, &ct_out, &ct_in, &auto_key, &tensor_key),
|
||||
GGSW::encrypt_sk_scratch_space(module, &ct_in)
|
||||
| AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key)
|
||||
| TensorKey::encrypt_sk_scratch_space(module, &tensor_key)
|
||||
| GGSW::automorphism_scratch_space(module, &ct_out, &ct_in, &auto_key, &tensor_key),
|
||||
);
|
||||
|
||||
let var_xs: f64 = 0.5;
|
||||
@@ -178,11 +178,11 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut auto_key_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_layout);
|
||||
let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
AutomorphismKeyPrepared::alloc(module, &auto_key_layout);
|
||||
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
||||
|
||||
let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = GGLWETensorKeyPrepared::alloc(module, &tensor_key_layout);
|
||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = TensorKeyPrepared::alloc(module, &tensor_key_layout);
|
||||
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
||||
|
||||
ct_out.automorphism(
|
||||
@@ -291,7 +291,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tensor_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout {
|
||||
let tensor_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_tsk.into(),
|
||||
@@ -300,7 +300,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let auto_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout {
|
||||
let auto_key_layout: TensorKeyLayout = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -309,9 +309,9 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_layout);
|
||||
let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_layout);
|
||||
let mut auto_key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_layout);
|
||||
let mut ct: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_layout);
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&tensor_key_layout);
|
||||
let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_layout);
|
||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
@@ -319,10 +319,10 @@ where
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ct)
|
||||
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key)
|
||||
| GGLWETensorKey::encrypt_sk_scratch_space(module, &tensor_key)
|
||||
| GGSWCiphertext::automorphism_inplace_scratch_space(module, &ct, &auto_key, &tensor_key),
|
||||
GGSW::encrypt_sk_scratch_space(module, &ct)
|
||||
| AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key)
|
||||
| TensorKey::encrypt_sk_scratch_space(module, &tensor_key)
|
||||
| GGSW::automorphism_inplace_scratch_space(module, &ct, &auto_key, &tensor_key),
|
||||
);
|
||||
|
||||
let var_xs: f64 = 0.5;
|
||||
@@ -358,11 +358,11 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut auto_key_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_layout);
|
||||
let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
AutomorphismKeyPrepared::alloc(module, &auto_key_layout);
|
||||
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
|
||||
|
||||
let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = GGLWETensorKeyPrepared::alloc(module, &tensor_key_layout);
|
||||
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = TensorKeyPrepared::alloc(module, &tensor_key_layout);
|
||||
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
|
||||
|
||||
ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow());
|
||||
|
||||
@@ -18,8 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
AutomorphismKey, AutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
},
|
||||
noise::log2_std_noise_gglwe_product,
|
||||
};
|
||||
@@ -91,7 +91,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let autokey_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -100,7 +100,7 @@ where
|
||||
dsize: di.into(),
|
||||
};
|
||||
|
||||
let mut autokey: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&autokey_infos);
|
||||
let mut autokey: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&autokey_infos);
|
||||
let mut ct_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&ct_in_infos);
|
||||
let mut ct_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&ct_out_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&ct_out_infos);
|
||||
@@ -112,7 +112,7 @@ where
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &autokey)
|
||||
AutomorphismKey::encrypt_sk_scratch_space(module, &autokey)
|
||||
| GLWECiphertext::decrypt_scratch_space(module, &ct_out)
|
||||
| GLWECiphertext::encrypt_sk_scratch_space(module, &ct_in)
|
||||
| GLWECiphertext::automorphism_scratch_space(module, &ct_out, &ct_in, &autokey),
|
||||
@@ -140,8 +140,8 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut autokey_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
GGLWEAutomorphismKeyPrepared::alloc(module, &autokey_infos);
|
||||
let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
AutomorphismKeyPrepared::alloc(module, &autokey_infos);
|
||||
autokey_prepared.prepare(module, &autokey, scratch.borrow());
|
||||
|
||||
ct_out.automorphism(module, &ct_in, &autokey_prepared, scratch.borrow());
|
||||
@@ -226,7 +226,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let autokey_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -235,7 +235,7 @@ where
|
||||
dsize: di.into(),
|
||||
};
|
||||
|
||||
let mut autokey: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&autokey_infos);
|
||||
let mut autokey: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&autokey_infos);
|
||||
let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&ct_out_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&ct_out_infos);
|
||||
|
||||
@@ -246,7 +246,7 @@ where
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &autokey)
|
||||
AutomorphismKey::encrypt_sk_scratch_space(module, &autokey)
|
||||
| GLWECiphertext::decrypt_scratch_space(module, &ct)
|
||||
| GLWECiphertext::encrypt_sk_scratch_space(module, &ct)
|
||||
| GLWECiphertext::automorphism_inplace_scratch_space(module, &ct, &autokey),
|
||||
@@ -274,8 +274,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut autokey_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
|
||||
GGLWEAutomorphismKeyPrepared::alloc(module, &autokey);
|
||||
let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = AutomorphismKeyPrepared::alloc(module, &autokey);
|
||||
autokey_prepared.prepare(module, &autokey, scratch.borrow());
|
||||
|
||||
ct.automorphism_inplace(module, &autokey_prepared, scratch.borrow());
|
||||
|
||||
@@ -16,9 +16,9 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, GLWEToLWEKey, GLWEToLWEKeyLayout,
|
||||
LWECiphertext, LWECiphertextLayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, Rank,
|
||||
TorusPrecision,
|
||||
Base2K, Degree, Dnum, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, GLWEToLWEKeyLayout,
|
||||
GLWEToLWESwitchingKey, LWECiphertext, LWECiphertextLayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey,
|
||||
LWEToGLWESwitchingKeyLayout, Rank, TorusPrecision,
|
||||
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -214,7 +214,7 @@ where
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GLWEToLWEKey::encrypt_sk_scratch_space(module, &glwe_to_lwe_infos)
|
||||
GLWEToLWESwitchingKey::encrypt_sk_scratch_space(module, &glwe_to_lwe_infos)
|
||||
| LWECiphertext::from_glwe_scratch_space(module, &lwe_infos, &glwe_infos, &glwe_to_lwe_infos)
|
||||
| GLWECiphertext::decrypt_scratch_space(module, &glwe_infos),
|
||||
);
|
||||
@@ -241,7 +241,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut ksk: GLWEToLWEKey<Vec<u8>> = GLWEToLWEKey::alloc(&glwe_to_lwe_infos);
|
||||
let mut ksk: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(&glwe_to_lwe_infos);
|
||||
|
||||
ksk.encrypt_sk(
|
||||
module,
|
||||
|
||||
@@ -18,8 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWEInfos, GLWESecret,
|
||||
compressed::{Decompress, GGLWEAutomorphismKeyCompressed},
|
||||
AutomorphismKey, AutomorphismKeyLayout, GLWEInfos, GLWESecret,
|
||||
compressed::{AutomorphismKeyCompressed, Decompress},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
@@ -75,7 +75,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let atk_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -84,13 +84,13 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut atk: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&atk_infos);
|
||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&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<B> = ScratchOwned::alloc(GGLWEAutomorphismKey::encrypt_sk_scratch_space(
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_scratch_space(
|
||||
module, &atk_infos,
|
||||
));
|
||||
|
||||
@@ -178,7 +178,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let atk_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -187,12 +187,12 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut atk_compressed: GGLWEAutomorphismKeyCompressed<Vec<u8>> = GGLWEAutomorphismKeyCompressed::alloc(&atk_infos);
|
||||
let mut atk_compressed: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc(&atk_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWEAutomorphismKey::encrypt_sk_scratch_space(
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_scratch_space(
|
||||
module, &atk_infos,
|
||||
));
|
||||
|
||||
@@ -217,7 +217,7 @@ where
|
||||
});
|
||||
let sk_out_prepared = sk_out.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
let mut atk: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&atk_infos);
|
||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&atk_infos);
|
||||
atk.decompress(module, &atk_compressed);
|
||||
|
||||
atk.key
|
||||
|
||||
@@ -17,8 +17,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWECiphertextLayout, GGLWESwitchingKey, GLWESecret,
|
||||
compressed::{Decompress, GGLWEKeyCompressed},
|
||||
GGLWECiphertextLayout, GLWESecret, GLWESwitchingKey,
|
||||
compressed::{Decompress, GLWESwitchingKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
@@ -81,13 +81,13 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_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<B> = ScratchOwned::alloc(GGLWESwitchingKey::encrypt_sk_scratch_space(
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKey::encrypt_sk_scratch_space(
|
||||
module,
|
||||
&gglwe_infos,
|
||||
));
|
||||
@@ -173,12 +173,12 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut ksk_compressed: GGLWEKeyCompressed<Vec<u8>> = GGLWEKeyCompressed::alloc(&gglwe_infos);
|
||||
let mut ksk_compressed: GLWESwitchingKeyCompressed<Vec<u8>> = GLWESwitchingKeyCompressed::alloc(&gglwe_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWEKeyCompressed::encrypt_sk_scratch_space(
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKeyCompressed::encrypt_sk_scratch_space(
|
||||
module,
|
||||
&gglwe_infos,
|
||||
));
|
||||
@@ -201,7 +201,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_infos);
|
||||
ksk.decompress(module, &ksk_compressed);
|
||||
|
||||
ksk.key
|
||||
|
||||
@@ -17,53 +17,16 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGSWCiphertext, GGSWCiphertextLayout, GLWESecret,
|
||||
GGSW, GGSWCiphertextLayout, GLWESecret,
|
||||
compressed::{Decompress, GGSWCiphertextCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_ggsw_encrypt_sk<B>(module: &Module<B>)
|
||||
pub fn test_ggsw_encrypt_sk<B: Backend>(module: &Module<B>)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxDftApply<B>
|
||||
+ SvpApplyDftToDftInplace<B>
|
||||
+ VecZnxIdftApplyConsume<B>
|
||||
+ VecZnxNormalizeTmpBytes
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxSubInplace
|
||||
+ VecZnxAddInplace
|
||||
+ VecZnxNormalizeInplace<B>
|
||||
+ VecZnxAddNormal
|
||||
+ VecZnxNormalize<B>
|
||||
+ VecZnxSub
|
||||
+ SvpPrepare<B>
|
||||
+ SvpPPolAllocBytes
|
||||
+ SvpPPolAlloc<B>
|
||||
+ VecZnxBigAddSmallInplace<B>
|
||||
+ VecZnxAddScalarInplace
|
||||
+ VecZnxBigAllocBytes
|
||||
+ VecZnxBigAddInplace<B>
|
||||
+ VecZnxCopy
|
||||
+ VmpPMatAlloc<B>
|
||||
+ VmpPrepare<B>
|
||||
+ VecZnxBigAlloc<B>
|
||||
+ VecZnxDftAlloc<B>
|
||||
+ VecZnxBigNormalizeTmpBytes
|
||||
+ VecZnxIdftApplyTmpA<B>,
|
||||
B: Backend
|
||||
+ TakeVecZnxDftImpl<B>
|
||||
+ TakeVecZnxBigImpl<B>
|
||||
+ TakeSvpPPolImpl<B>
|
||||
+ ScratchOwnedAllocImpl<B>
|
||||
+ ScratchOwnedBorrowImpl<B>
|
||||
+ ScratchAvailableImpl<B>
|
||||
+ TakeScalarZnxImpl<B>
|
||||
+ TakeVecZnxImpl<B>
|
||||
+ VecZnxDftAllocBytesImpl<B>
|
||||
+ VecZnxBigAllocBytesImpl<B>
|
||||
+ TakeSvpPPolImpl<B>,
|
||||
ScratchOwned<B>: ScratchOwnedAlloc<B>,
|
||||
Module<B>: SvpPrepare<B>,
|
||||
{
|
||||
let base2k: usize = 12;
|
||||
let k: usize = 54;
|
||||
@@ -82,7 +45,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos);
|
||||
let mut ct: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos);
|
||||
|
||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
@@ -92,10 +55,7 @@ where
|
||||
|
||||
pt_scalar.fill_ternary_hw(0, n, &mut source_xs);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGSWCiphertext::encrypt_sk_scratch_space(
|
||||
module,
|
||||
&ggsw_infos,
|
||||
));
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGSW::encrypt_sk_scratch_space(module, &ggsw_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(&ggsw_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
@@ -206,7 +166,7 @@ where
|
||||
|
||||
let noise_f = |_col_i: usize| -(k as f64) + SIGMA.log2() + 0.5;
|
||||
|
||||
let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos);
|
||||
let mut ct: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos);
|
||||
ct.decompress(module, &ct_compressed);
|
||||
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f);
|
||||
|
||||
@@ -17,8 +17,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
Dsize, GGLWETensorKey, GGLWETensorKeyLayout, GLWEPlaintext, GLWESecret,
|
||||
compressed::{Decompress, GGLWETensorKeyCompressed},
|
||||
Dsize, GLWEPlaintext, GLWESecret, TensorKey, TensorKeyLayout,
|
||||
compressed::{Decompress, TensorKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
@@ -71,7 +71,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = k / base2k;
|
||||
|
||||
let tensor_key_infos = GGLWETensorKeyLayout {
|
||||
let tensor_key_infos = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k.into(),
|
||||
@@ -80,13 +80,13 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_infos);
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&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<B> = ScratchOwned::alloc(GGLWETensorKey::encrypt_sk_scratch_space(
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(TensorKey::encrypt_sk_scratch_space(
|
||||
module,
|
||||
&tensor_key_infos,
|
||||
));
|
||||
@@ -190,7 +190,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = k / base2k;
|
||||
|
||||
let tensor_key_infos: GGLWETensorKeyLayout = GGLWETensorKeyLayout {
|
||||
let tensor_key_infos: TensorKeyLayout = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k.into(),
|
||||
@@ -199,12 +199,12 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut tensor_key_compressed: GGLWETensorKeyCompressed<Vec<u8>> = GGLWETensorKeyCompressed::alloc(&tensor_key_infos);
|
||||
let mut tensor_key_compressed: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc(&tensor_key_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWETensorKeyCompressed::encrypt_sk_scratch_space(
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(TensorKeyCompressed::encrypt_sk_scratch_space(
|
||||
module,
|
||||
&tensor_key_infos,
|
||||
));
|
||||
@@ -217,7 +217,7 @@ where
|
||||
|
||||
tensor_key_compressed.encrypt_sk(module, &sk, seed_xa, &mut source_xe, scratch.borrow());
|
||||
|
||||
let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_infos);
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&tensor_key_infos);
|
||||
tensor_key.decompress(module, &tensor_key_compressed);
|
||||
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&tensor_key_infos);
|
||||
|
||||
@@ -18,8 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GGLWESwitchingKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWESecret,
|
||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
GGSW, GGSWCiphertextLayout, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout,
|
||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
noise::noise_ggsw_product,
|
||||
};
|
||||
@@ -81,7 +81,7 @@ where
|
||||
let dnum: usize = k_in.div_ceil(base2k * di);
|
||||
let dsize_in: usize = 1;
|
||||
|
||||
let gglwe_in_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_in_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_in.into(),
|
||||
@@ -91,7 +91,7 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let gglwe_out_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_out_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -110,9 +110,9 @@ where
|
||||
rank: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut ct_gglwe_in: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_in_infos);
|
||||
let mut ct_gglwe_out: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_out_infos);
|
||||
let mut ct_rgsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos);
|
||||
let mut ct_gglwe_in: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_in_infos);
|
||||
let mut ct_gglwe_out: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_out_infos);
|
||||
let mut ct_rgsw: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos);
|
||||
|
||||
let mut pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
@@ -121,14 +121,14 @@ where
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_in_infos)
|
||||
| GGLWESwitchingKey::external_product_scratch_space(
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_in_infos)
|
||||
| GLWESwitchingKey::external_product_scratch_space(
|
||||
module,
|
||||
&gglwe_out_infos,
|
||||
&gglwe_in_infos,
|
||||
&ggsw_infos,
|
||||
)
|
||||
| GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_infos),
|
||||
| GGSW::encrypt_sk_scratch_space(module, &ggsw_infos),
|
||||
);
|
||||
|
||||
let r: usize = 1;
|
||||
@@ -163,7 +163,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ct_rgsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow());
|
||||
let ct_rgsw_prepared: GGSWPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
// gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k)
|
||||
ct_gglwe_out.external_product(module, &ct_gglwe_in, &ct_rgsw_prepared, scratch.borrow());
|
||||
@@ -263,7 +263,7 @@ where
|
||||
|
||||
let dsize_in: usize = 1;
|
||||
|
||||
let gglwe_out_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_out_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -282,8 +282,8 @@ where
|
||||
rank: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut ct_gglwe: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_out_infos);
|
||||
let mut ct_rgsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos);
|
||||
let mut ct_gglwe: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_out_infos);
|
||||
let mut ct_rgsw: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos);
|
||||
|
||||
let mut pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
@@ -292,9 +292,9 @@ where
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_out_infos)
|
||||
| GGLWESwitchingKey::external_product_inplace_scratch_space(module, &gglwe_out_infos, &ggsw_infos)
|
||||
| GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_infos),
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_out_infos)
|
||||
| GLWESwitchingKey::external_product_inplace_scratch_space(module, &gglwe_out_infos, &ggsw_infos)
|
||||
| GGSW::encrypt_sk_scratch_space(module, &ggsw_infos),
|
||||
);
|
||||
|
||||
let r: usize = 1;
|
||||
@@ -329,7 +329,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ct_rgsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow());
|
||||
let ct_rgsw_prepared: GGSWPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
// gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k)
|
||||
ct_gglwe.external_product_inplace(module, &ct_rgsw_prepared, scratch.borrow());
|
||||
|
||||
@@ -18,8 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGSWCiphertext, GGSWCiphertextLayout, GLWESecret,
|
||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
GGSW, GGSWCiphertextLayout, GLWESecret,
|
||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
noise::noise_ggsw_product,
|
||||
};
|
||||
@@ -111,9 +111,9 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ggsw_in: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_in_infos);
|
||||
let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos);
|
||||
let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos);
|
||||
let mut ggsw_in: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_in_infos);
|
||||
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos);
|
||||
let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos);
|
||||
let mut pt_in: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
let mut pt_apply: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
@@ -128,9 +128,9 @@ where
|
||||
pt_apply.to_mut().raw_mut()[k] = 1; //X^{k}
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
| GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_in_infos)
|
||||
| GGSWCiphertext::external_product_scratch_space(module, &ggsw_out_infos, &ggsw_in_infos, &ggsw_apply_infos),
|
||||
GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
| GGSW::encrypt_sk_scratch_space(module, &ggsw_in_infos)
|
||||
| GGSW::external_product_scratch_space(module, &ggsw_out_infos, &ggsw_in_infos, &ggsw_apply_infos),
|
||||
);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_with(n.into(), rank.into());
|
||||
@@ -155,7 +155,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ct_rhs_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
let ct_rhs_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
ggsw_out.external_product(module, &ggsw_in, &ct_rhs_prepared, scratch.borrow());
|
||||
|
||||
@@ -265,8 +265,8 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos);
|
||||
let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos);
|
||||
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos);
|
||||
let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos);
|
||||
|
||||
let mut pt_in: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
let mut pt_apply: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
@@ -282,9 +282,9 @@ where
|
||||
pt_apply.to_mut().raw_mut()[k] = 1; //X^{k}
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
| GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_out_infos)
|
||||
| GGSWCiphertext::external_product_inplace_scratch_space(module, &ggsw_out_infos, &ggsw_apply_infos),
|
||||
GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
| GGSW::encrypt_sk_scratch_space(module, &ggsw_out_infos)
|
||||
| GGSW::external_product_inplace_scratch_space(module, &ggsw_out_infos, &ggsw_apply_infos),
|
||||
);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_with(n.into(), rank.into());
|
||||
@@ -309,7 +309,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ct_rhs_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
let ct_rhs_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
ggsw_out.external_product_inplace(module, &ct_rhs_prepared, scratch.borrow());
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGSWCiphertext, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
GGSW, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
noise::noise_ggsw_product,
|
||||
};
|
||||
@@ -96,7 +96,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos);
|
||||
let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos);
|
||||
let mut glwe_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_in_infos);
|
||||
let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos);
|
||||
let mut pt_ggsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
@@ -116,7 +116,7 @@ where
|
||||
pt_ggsw.raw_mut()[k] = 1; // X^{k}
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
| GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_in_infos)
|
||||
| GLWECiphertext::external_product_scratch_space(module, &glwe_out_infos, &glwe_in_infos, &ggsw_apply_infos),
|
||||
);
|
||||
@@ -143,7 +143,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ct_ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
let ct_ggsw_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
glwe_out.external_product(module, &glwe_in, &ct_ggsw_prepared, scratch.borrow());
|
||||
|
||||
@@ -240,7 +240,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos);
|
||||
let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos);
|
||||
let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos);
|
||||
let mut pt_ggsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&glwe_out_infos);
|
||||
@@ -259,7 +259,7 @@ where
|
||||
pt_ggsw.raw_mut()[k] = 1; // X^{k}
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos)
|
||||
| GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos)
|
||||
| GLWECiphertext::external_product_inplace_scratch_space(module, &glwe_out_infos, &ggsw_apply_infos),
|
||||
);
|
||||
@@ -286,7 +286,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ct_ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
let ct_ggsw_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
glwe_out.external_product_inplace(module, &ct_ggsw_prepared, scratch.borrow());
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GGLWESwitchingKeyLayout, GLWESecret,
|
||||
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout,
|
||||
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc},
|
||||
},
|
||||
noise::log2_std_noise_gglwe_product,
|
||||
};
|
||||
@@ -80,7 +80,7 @@ where
|
||||
let dnum_apply: usize = k_in.div_ceil(base2k * di);
|
||||
let dsize_in: usize = 1;
|
||||
|
||||
let gglwe_s0s1_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_s0s1_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_in.into(),
|
||||
@@ -90,7 +90,7 @@ where
|
||||
rank_out: rank_out_s0s1.into(),
|
||||
};
|
||||
|
||||
let gglwe_s1s2_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_s1s2_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -100,7 +100,7 @@ where
|
||||
rank_out: rank_out_s1s2.into(),
|
||||
};
|
||||
|
||||
let gglwe_s0s2_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_s0s2_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -110,20 +110,20 @@ where
|
||||
rank_out: rank_out_s1s2.into(),
|
||||
};
|
||||
|
||||
let mut gglwe_s0s1: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s0s1_infos);
|
||||
let mut gglwe_s1s2: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s1s2_infos);
|
||||
let mut gglwe_s0s2: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s0s2_infos);
|
||||
let mut gglwe_s0s1: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s0s1_infos);
|
||||
let mut gglwe_s1s2: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s1s2_infos);
|
||||
let mut gglwe_s0s2: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s0s2_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_enc: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos)
|
||||
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos)
|
||||
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s2_infos),
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos)
|
||||
| GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos)
|
||||
| GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s2_infos),
|
||||
);
|
||||
let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::keyswitch_scratch_space(
|
||||
let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKey::keyswitch_scratch_space(
|
||||
module,
|
||||
&gglwe_s0s1_infos,
|
||||
&gglwe_s0s2_infos,
|
||||
@@ -160,7 +160,7 @@ where
|
||||
scratch_enc.borrow(),
|
||||
);
|
||||
|
||||
let gglwe_s1s2_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> =
|
||||
let gglwe_s1s2_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> =
|
||||
gglwe_s1s2.prepare_alloc(module, scratch_apply.borrow());
|
||||
|
||||
// gglwe_{s1}(s0) (x) gglwe_{s2}(s1) = gglwe_{s2}(s0)
|
||||
@@ -246,7 +246,7 @@ where
|
||||
let dnum: usize = k_out.div_ceil(base2k * di);
|
||||
let dsize_in: usize = 1;
|
||||
|
||||
let gglwe_s0s1_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_s0s1_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_out.into(),
|
||||
@@ -256,7 +256,7 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let gglwe_s1s2_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let gglwe_s1s2_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -266,18 +266,18 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut gglwe_s0s1: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s0s1_infos);
|
||||
let mut gglwe_s1s2: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s1s2_infos);
|
||||
let mut gglwe_s0s1: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s0s1_infos);
|
||||
let mut gglwe_s1s2: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s1s2_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_enc: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos)
|
||||
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos),
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos)
|
||||
| GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos),
|
||||
);
|
||||
let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::keyswitch_inplace_scratch_space(
|
||||
let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKey::keyswitch_inplace_scratch_space(
|
||||
module,
|
||||
&gglwe_s0s1_infos,
|
||||
&gglwe_s1s2_infos,
|
||||
@@ -315,13 +315,13 @@ where
|
||||
scratch_enc.borrow(),
|
||||
);
|
||||
|
||||
let gglwe_s1s2_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> =
|
||||
let gglwe_s1s2_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> =
|
||||
gglwe_s1s2.prepare_alloc(module, scratch_apply.borrow());
|
||||
|
||||
// gglwe_{s1}(s0) (x) gglwe_{s2}(s1) = gglwe_{s2}(s0)
|
||||
gglwe_s0s1.keyswitch_inplace(module, &gglwe_s1s2_prepared, scratch_apply.borrow());
|
||||
|
||||
let gglwe_s0s2: GGLWESwitchingKey<Vec<u8>> = gglwe_s0s1;
|
||||
let gglwe_s0s2: GLWESwitchingKey<Vec<u8>> = gglwe_s0s1;
|
||||
|
||||
let max_noise: f64 = log2_std_noise_gglwe_product(
|
||||
n as f64,
|
||||
|
||||
@@ -18,9 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GGLWESwitchingKeyLayout, GGLWETensorKey, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout,
|
||||
GLWESecret,
|
||||
prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
GGSW, GGSWCiphertextLayout, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout, TensorKey, TensorKeyLayout,
|
||||
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc, TensorKeyPrepared},
|
||||
},
|
||||
noise::noise_ggsw_keyswitch,
|
||||
};
|
||||
@@ -103,7 +102,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tsk_infos: GGLWETensorKeyLayout = GGLWETensorKeyLayout {
|
||||
let tsk_infos: TensorKeyLayout = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_tsk.into(),
|
||||
@@ -112,7 +111,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let ksk_apply_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let ksk_apply_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -122,10 +121,10 @@ where
|
||||
rank_out: rank.into(),
|
||||
};
|
||||
|
||||
let mut ggsw_in: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_in_infos);
|
||||
let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos);
|
||||
let mut tsk: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tsk_infos);
|
||||
let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&ksk_apply_infos);
|
||||
let mut ggsw_in: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_in_infos);
|
||||
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos);
|
||||
let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc(&tsk_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&ksk_apply_infos);
|
||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
@@ -133,10 +132,10 @@ where
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_in_infos)
|
||||
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos)
|
||||
| GGLWETensorKey::encrypt_sk_scratch_space(module, &tsk_infos)
|
||||
| GGSWCiphertext::keyswitch_scratch_space(
|
||||
GGSW::encrypt_sk_scratch_space(module, &ggsw_in_infos)
|
||||
| GLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos)
|
||||
| TensorKey::encrypt_sk_scratch_space(module, &tsk_infos)
|
||||
| GGSW::keyswitch_scratch_space(
|
||||
module,
|
||||
&ggsw_out_infos,
|
||||
&ggsw_in_infos,
|
||||
@@ -182,8 +181,8 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
||||
let tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow());
|
||||
let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
||||
let tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
ggsw_out.keyswitch(
|
||||
module,
|
||||
@@ -282,7 +281,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let tsk_infos: GGLWETensorKeyLayout = GGLWETensorKeyLayout {
|
||||
let tsk_infos: TensorKeyLayout = TensorKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_tsk.into(),
|
||||
@@ -291,7 +290,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let ksk_apply_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let ksk_apply_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -301,9 +300,9 @@ where
|
||||
rank_out: rank.into(),
|
||||
};
|
||||
|
||||
let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos);
|
||||
let mut tsk: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tsk_infos);
|
||||
let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&ksk_apply_infos);
|
||||
let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos);
|
||||
let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc(&tsk_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&ksk_apply_infos);
|
||||
let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
@@ -311,10 +310,10 @@ where
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_out_infos)
|
||||
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos)
|
||||
| GGLWETensorKey::encrypt_sk_scratch_space(module, &tsk_infos)
|
||||
| GGSWCiphertext::keyswitch_inplace_scratch_space(module, &ggsw_out_infos, &ksk_apply_infos, &tsk_infos),
|
||||
GGSW::encrypt_sk_scratch_space(module, &ggsw_out_infos)
|
||||
| GLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos)
|
||||
| TensorKey::encrypt_sk_scratch_space(module, &tsk_infos)
|
||||
| GGSW::keyswitch_inplace_scratch_space(module, &ggsw_out_infos, &ksk_apply_infos, &tsk_infos),
|
||||
);
|
||||
|
||||
let var_xs: f64 = 0.5;
|
||||
@@ -354,8 +353,8 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
||||
let tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow());
|
||||
let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
||||
let tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
ggsw_out.keyswitch_inplace(module, &ksk_prepared, &tsk_prepared, scratch.borrow());
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GGLWESwitchingKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout,
|
||||
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc},
|
||||
},
|
||||
noise::log2_std_noise_gglwe_product,
|
||||
};
|
||||
@@ -91,7 +91,7 @@ where
|
||||
rank: rank_out.into(),
|
||||
};
|
||||
|
||||
let key_apply: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let key_apply: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -101,7 +101,7 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&key_apply);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&key_apply);
|
||||
let mut glwe_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_in_infos);
|
||||
let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&glwe_in_infos);
|
||||
@@ -113,7 +113,7 @@ where
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply)
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply)
|
||||
| GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_in_infos)
|
||||
| GLWECiphertext::keyswitch_scratch_space(module, &glwe_out_infos, &glwe_in_infos, &key_apply),
|
||||
);
|
||||
@@ -144,7 +144,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
||||
let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
glwe_out.keyswitch(module, &glwe_in, &ksk_prepared, scratch.borrow());
|
||||
|
||||
@@ -224,7 +224,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let key_apply_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout {
|
||||
let key_apply_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -234,7 +234,7 @@ where
|
||||
rank_out: rank.into(),
|
||||
};
|
||||
|
||||
let mut key_apply: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&key_apply_infos);
|
||||
let mut key_apply: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&key_apply_infos);
|
||||
let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&glwe_out_infos);
|
||||
|
||||
@@ -245,7 +245,7 @@ where
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply_infos)
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply_infos)
|
||||
| GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos)
|
||||
| GLWECiphertext::keyswitch_inplace_scratch_space(module, &glwe_out_infos, &key_apply_infos),
|
||||
);
|
||||
@@ -276,7 +276,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = key_apply.prepare_alloc(module, scratch.borrow());
|
||||
let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = key_apply.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
glwe_out.keyswitch_inplace(module, &ksk_prepared, scratch.borrow());
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
GLWEOperations, GLWEPacker,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
AutomorphismKey, AutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -95,7 +95,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let key_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -106,7 +106,7 @@ where
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos)
|
||||
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &key_infos)
|
||||
| AutomorphismKey::encrypt_sk_scratch_space(module, &key_infos)
|
||||
| GLWEPacker::scratch_space(module, &glwe_out_infos, &key_infos),
|
||||
);
|
||||
|
||||
@@ -124,8 +124,8 @@ where
|
||||
|
||||
let gal_els: Vec<i64> = GLWEPacker::galois_elements(module);
|
||||
|
||||
let mut auto_keys: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new();
|
||||
let mut tmp: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&key_infos);
|
||||
let mut auto_keys: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new();
|
||||
let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&key_infos);
|
||||
gal_els.iter().for_each(|gal_el| {
|
||||
tmp.encrypt_sk(
|
||||
module,
|
||||
@@ -135,7 +135,7 @@ where
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
let atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow());
|
||||
let atk_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow());
|
||||
auto_keys.insert(*gal_el, atk_prepared);
|
||||
});
|
||||
|
||||
|
||||
@@ -21,9 +21,8 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret,
|
||||
LWEInfos,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
AutomorphismKey, AutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, LWEInfos,
|
||||
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
noise::var_noise_gglwe_product,
|
||||
};
|
||||
@@ -90,7 +89,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let key_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout {
|
||||
let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_autokey.into(),
|
||||
@@ -110,7 +109,7 @@ where
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos)
|
||||
| GLWECiphertext::decrypt_scratch_space(module, &glwe_out_infos)
|
||||
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &key_infos)
|
||||
| AutomorphismKey::encrypt_sk_scratch_space(module, &key_infos)
|
||||
| GLWECiphertext::trace_inplace_scratch_space(module, &glwe_out_infos, &key_infos),
|
||||
);
|
||||
|
||||
@@ -135,9 +134,9 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut auto_keys: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new();
|
||||
let mut auto_keys: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new();
|
||||
let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(module);
|
||||
let mut tmp: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&key_infos);
|
||||
let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&key_infos);
|
||||
gal_els.iter().for_each(|gal_el| {
|
||||
tmp.encrypt_sk(
|
||||
module,
|
||||
@@ -147,7 +146,7 @@ where
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
let atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow());
|
||||
let atk_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow());
|
||||
auto_keys.insert(*gal_el, atk_prepared);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user