mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
fix remaining issues before fixing tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use poulpy_core::layouts::{
|
use poulpy_core::layouts::{
|
||||||
Base2K, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, RingDegree, TorusPrecision,
|
Base2K, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, RingDegree, TorusPrecision,
|
||||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGSWPrepared, GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
use std::hint::black_box;
|
use std::hint::black_box;
|
||||||
|
|
||||||
@@ -61,9 +61,9 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
|||||||
rank,
|
rank,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_layout);
|
let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&module, &ggsw_layout);
|
||||||
let mut ct_glwe_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_in_layout);
|
let mut ct_glwe_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_in_layout);
|
||||||
let mut ct_glwe_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout);
|
let mut ct_glwe_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_out_layout);
|
||||||
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
||||||
@@ -76,9 +76,11 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
|||||||
let mut source_xe = Source::new([0u8; 32]);
|
let mut source_xe = Source::new([0u8; 32]);
|
||||||
let mut source_xa = Source::new([0u8; 32]);
|
let mut source_xa = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_in_layout);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
|
|
||||||
|
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
|
sk_dft.prepare(&module, &sk);
|
||||||
|
|
||||||
ct_ggsw.encrypt_sk(
|
ct_ggsw.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
@@ -97,7 +99,8 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = ct_ggsw.prepare_alloc(&module, scratch.borrow());
|
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||||
|
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
||||||
|
|
||||||
move || {
|
move || {
|
||||||
ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow());
|
ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow());
|
||||||
@@ -162,23 +165,25 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
rank,
|
rank,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_layout);
|
let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&module, &ggsw_layout);
|
||||||
let mut ct_glwe: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_layout);
|
let mut ct_glwe: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_layout);
|
||||||
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout)
|
GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_layout)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
||||||
| GLWE::external_product_inplace_tmp_bytes(&module, &glwe_layout, &ggsw_layout),
|
| GLWE::external_product_tmp_bytes(&module, &glwe_layout, &glwe_layout, &ggsw_layout),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_layout);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
|
|
||||||
|
let mut sk_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
|
sk_dft.prepare(&module, &sk);
|
||||||
|
|
||||||
ct_ggsw.encrypt_sk(
|
ct_ggsw.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
@@ -197,8 +202,8 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = ct_ggsw.prepare_alloc(&module, scratch.borrow());
|
let mut ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = GGSWPrepared::alloc_from_infos(&module, &ct_ggsw);
|
||||||
|
ggsw_prepared.prepare(&module, &ct_ggsw, scratch.borrow());
|
||||||
move || {
|
move || {
|
||||||
let scratch_borrow = scratch.borrow();
|
let scratch_borrow = scratch.borrow();
|
||||||
ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow);
|
ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use poulpy_core::layouts::{
|
use poulpy_core::layouts::{
|
||||||
AutomorphismKey, AutomorphismKeyLayout, Base2K, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey,
|
AutomorphismKey, AutomorphismKeyLayout, Base2K, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey,
|
||||||
GLWESwitchingKeyLayout, Rank, RingDegree, TorusPrecision,
|
GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, RingDegree, TorusPrecision,
|
||||||
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc},
|
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
use std::{hint::black_box, time::Duration};
|
use std::{hint::black_box, time::Duration};
|
||||||
|
|
||||||
@@ -62,9 +62,9 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
|||||||
rank,
|
rank,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ksk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&gglwe_atk_layout);
|
let mut ksk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&module, &gglwe_atk_layout);
|
||||||
let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_in_layout);
|
let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_in_layout);
|
||||||
let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout);
|
let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_out_layout);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
||||||
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_atk_layout)
|
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_atk_layout)
|
||||||
@@ -81,9 +81,11 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
|||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_in_layout);
|
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_in_layout);
|
||||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk_in.prepare_alloc(&module, scratch.borrow());
|
|
||||||
|
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
|
sk_in_dft.prepare(&module, &sk_in);
|
||||||
|
|
||||||
ksk.encrypt_sk(
|
ksk.encrypt_sk(
|
||||||
&module,
|
&module,
|
||||||
@@ -102,7 +104,8 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ksk_prepared: AutomorphismKeyPrepared<Vec<u8>, _> = ksk.prepare_alloc(&module, scratch.borrow());
|
let mut ksk_prepared: AutomorphismKeyPrepared<Vec<u8>, _> = AutomorphismKeyPrepared::alloc_from_infos(&module, &ksk);
|
||||||
|
ksk_prepared.prepare(&module, &ksk, scratch.borrow());
|
||||||
|
|
||||||
move || {
|
move || {
|
||||||
ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow());
|
ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow());
|
||||||
@@ -174,24 +177,26 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
rank,
|
rank,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_layout);
|
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&module, &gglwe_layout);
|
||||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_layout);
|
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_layout);
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(
|
||||||
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_layout)
|
GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_layout)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
| GLWE::encrypt_sk_tmp_bytes(&module, &glwe_layout)
|
||||||
| GLWE::keyswitch_inplace_tmp_bytes(&module, &glwe_layout, &gglwe_layout),
|
| GLWE::keyswitch_tmp_bytes(&module, &glwe_layout, &glwe_layout, &gglwe_layout),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
|
|
||||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_layout);
|
||||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk_in.prepare_alloc(&module, scratch.borrow());
|
|
||||||
|
|
||||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout);
|
let mut sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
|
sk_in_dft.prepare(&module, &sk_in);
|
||||||
|
|
||||||
|
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_layout);
|
||||||
sk_out.fill_ternary_prob(0.5, &mut source_xs);
|
sk_out.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
ksk.encrypt_sk(
|
ksk.encrypt_sk(
|
||||||
@@ -211,7 +216,8 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, FFT64Spqlios> = ksk.prepare_alloc(&module, scratch.borrow());
|
let mut ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, _> = GLWESwitchingKeyPrepared::alloc_from_infos(&module, &ksk);
|
||||||
|
ksk_prepared.prepare(&module, &ksk, scratch.borrow());
|
||||||
|
|
||||||
move || {
|
move || {
|
||||||
ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow());
|
ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow());
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use poulpy_backend::cpu_spqlios::FFT64Spqlios;
|
use poulpy_backend::cpu_spqlios::FFT64Spqlios;
|
||||||
use poulpy_core::{
|
use poulpy_core::{
|
||||||
GLWEOperations, SIGMA,
|
GLWESub, SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
Base2K, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, RingDegree, TorusPrecision,
|
Base2K, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, RingDegree, TorusPrecision,
|
||||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
prepared::GLWESecretPrepared,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
@@ -43,9 +43,9 @@ fn main() {
|
|||||||
let glwe_pt_infos: GLWEPlaintextLayout = GLWEPlaintextLayout { n, base2k, k: k_pt };
|
let glwe_pt_infos: GLWEPlaintextLayout = GLWEPlaintextLayout { n, base2k, k: k_pt };
|
||||||
|
|
||||||
// Allocates ciphertext & plaintexts
|
// Allocates ciphertext & plaintexts
|
||||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_ct_infos);
|
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_ct_infos);
|
||||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_infos);
|
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&module, &glwe_pt_infos);
|
||||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_infos);
|
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&module, &glwe_pt_infos);
|
||||||
|
|
||||||
// CPRNG
|
// CPRNG
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
@@ -58,11 +58,12 @@ fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Generate secret-key
|
// Generate secret-key
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_ct_infos);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_ct_infos);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
// Backend-prepared secret
|
// Backend-prepared secret
|
||||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = sk.prepare_alloc(&module, scratch.borrow());
|
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Spqlios> = GLWESecretPrepared::alloc(&module, rank);
|
||||||
|
sk_prepared.prepare(&module, &sk);
|
||||||
|
|
||||||
// Uniform plaintext
|
// Uniform plaintext
|
||||||
module.vec_znx_fill_uniform(base2k.into(), &mut pt_want.data, 0, &mut source_xa);
|
module.vec_znx_fill_uniform(base2k.into(), &mut pt_want.data, 0, &mut source_xa);
|
||||||
@@ -81,7 +82,7 @@ fn main() {
|
|||||||
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
|
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
|
||||||
|
|
||||||
// Diff between pt - Dec(Enc(pt))
|
// Diff between pt - Dec(Enc(pt))
|
||||||
pt_want.sub_inplace_ab(&module, &pt_have);
|
module.glwe_sub_inplace(&mut pt_want, &pt_have);
|
||||||
|
|
||||||
// Ideal vs. actual noise
|
// Ideal vs. actual noise
|
||||||
let noise_have: f64 = pt_want.data.std(base2k.into(), 0) * (ct.k().as_u32() as f64).exp2();
|
let noise_have: f64 = pt_want.data.std(base2k.into(), 0) * (ct.k().as_u32() as f64).exp2();
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ impl<D: DataMut> GGSW<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> GGSWFromGGLWE<BE> for Module<BE> where Self: GGSWExpandRows<BE> + GLWECopy {}
|
impl<BE: Backend> GGSWFromGGLWE<BE> for Module<BE>
|
||||||
|
|
||||||
pub trait GGSWFromGGLWE<BE: Backend>
|
|
||||||
where
|
where
|
||||||
Self: GGSWExpandRows<BE> + GLWECopy,
|
Self: GGSWExpandRows<BE> + GLWECopy,
|
||||||
{
|
{
|
||||||
@@ -77,6 +75,20 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait GGSWFromGGLWE<BE: Backend> {
|
||||||
|
fn ggsw_from_gglwe_tmp_bytes<R, A>(&self, res_infos: &R, tsk_infos: &A) -> usize
|
||||||
|
where
|
||||||
|
R: GGSWInfos,
|
||||||
|
A: GGLWEInfos;
|
||||||
|
|
||||||
|
fn ggsw_from_gglwe<R, A, T>(&self, res: &mut R, a: &A, tsk: &T, scratch: &mut Scratch<BE>)
|
||||||
|
where
|
||||||
|
R: GGSWToMut,
|
||||||
|
A: GGLWEToRef,
|
||||||
|
T: TensorKeyPreparedToRef<BE>,
|
||||||
|
Scratch<BE>: ScratchTakeCore<BE>;
|
||||||
|
}
|
||||||
|
|
||||||
impl<BE: Backend> GGSWExpandRows<BE> for Module<BE> where
|
impl<BE: Backend> GGSWExpandRows<BE> for Module<BE> where
|
||||||
Self: Sized
|
Self: Sized
|
||||||
+ ModuleN
|
+ ModuleN
|
||||||
@@ -99,7 +111,7 @@ impl<BE: Backend> GGSWExpandRows<BE> for Module<BE> where
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait GGSWExpandRows<BE: Backend>
|
pub trait GGSWExpandRows<BE: Backend>
|
||||||
where
|
where
|
||||||
Self: Sized
|
Self: Sized
|
||||||
+ ModuleN
|
+ ModuleN
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ mod glwe_ct;
|
|||||||
mod lwe_ct;
|
mod lwe_ct;
|
||||||
|
|
||||||
pub use glwe_ct::*;
|
pub use glwe_ct::*;
|
||||||
pub use lwe_ct::*;
|
// pub use lwe_ct::*;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ pub trait AutomorphismKeyCompressedEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN + GaloisElement + VecZnxAutomorphism + GLWESwitchingKeyCompressedEncryptSk<BE>,
|
Self: ModuleN + GaloisElement + VecZnxAutomorphism + GLWESwitchingKeyCompressedEncryptSk<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
@@ -107,7 +107,7 @@ where
|
|||||||
&sk.data.as_vec_znx(),
|
&sk.data.as_vec_znx(),
|
||||||
i,
|
i,
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.glwe_switching_key_compressed_encrypt_sk(&mut res.key, sk, &sk_out, seed_xa, source_xe, scratch_1);
|
self.glwe_switching_key_compressed_encrypt_sk(&mut res.key, sk, &sk_out, seed_xa, source_xe, scratch_1);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub trait GGLWECompressedEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GGLWECompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GGLWECompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN
|
Self: ModuleN
|
||||||
+ GLWEEncryptSkInternal<BE>
|
+ GLWEEncryptSkInternal<BE>
|
||||||
+ GLWEEncryptSk<BE>
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxDftBytesOf
|
+ VecZnxDftBytesOf
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ pub trait GLWESwitchingKeyCompressedEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWESwitchingKeyCompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWESwitchingKeyCompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing,
|
Self: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{
|
||||||
ModuleN, ScratchTakeBasic, SvpApplyDftToDft, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare, VecZnxBigBytesOf,
|
ModuleN, ScratchTakeBasic, SvpApplyDftToDft, SvpPPolBytesOf, SvpPrepare, VecZnxBigBytesOf, VecZnxBigNormalize,
|
||||||
VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes,
|
VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyTmpA,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, Module, Scratch},
|
||||||
oep::{SvpPPolAllocBytesImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl},
|
oep::{SvpPPolAllocBytesImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl},
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
@@ -13,7 +13,7 @@ use crate::{
|
|||||||
encryption::compressed::gglwe_ksk::GLWESwitchingKeyCompressedEncryptSk,
|
encryption::compressed::gglwe_ksk::GLWESwitchingKeyCompressedEncryptSk,
|
||||||
encryption::gglwe_tsk::TensorKeyEncryptSk,
|
encryption::gglwe_tsk::TensorKeyEncryptSk,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, LWEInfos, Rank, TensorKey,
|
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, LWEInfos, Rank,
|
||||||
compressed::{TensorKeyCompressed, TensorKeyCompressedToMut},
|
compressed::{TensorKeyCompressed, TensorKeyCompressedToMut},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -29,23 +29,22 @@ impl TensorKeyCompressed<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> {
|
impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> {
|
||||||
pub fn encrypt_sk<DataSk: DataRef, BE: Backend>(
|
pub fn encrypt_sk<S, M, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &Module<BE>,
|
module: &M,
|
||||||
sk: &GLWESecret<DataSk>,
|
sk: &S,
|
||||||
seed_xa: [u8; 32],
|
seed_xa: [u8; 32],
|
||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
GLWESecret<DataSk>: GetDist,
|
S: GLWESecretToRef + GetDist,
|
||||||
Module<BE>: GGLWETensorKeyCompressedEncryptSk<BE>,
|
M: GGLWETensorKeyCompressedEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.gglwe_tensor_key_encrypt_sk(self, sk, seed_xa, source_xe, scratch);
|
module.gglwe_tensor_key_encrypt_sk(self, sk, seed_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
||||||
|
|
||||||
fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
@@ -64,7 +63,7 @@ pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GGLWETensorKeyCompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GGLWETensorKeyCompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN
|
Self: ModuleN
|
||||||
+ GLWESwitchingKeyCompressedEncryptSk<BE>
|
+ GLWESwitchingKeyCompressedEncryptSk<BE>
|
||||||
+ TensorKeyEncryptSk<BE>
|
+ TensorKeyEncryptSk<BE>
|
||||||
+ VecZnxDftApply<BE>
|
+ VecZnxDftApply<BE>
|
||||||
@@ -82,7 +81,7 @@ where
|
|||||||
{
|
{
|
||||||
fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos
|
A: GGLWEInfos,
|
||||||
{
|
{
|
||||||
self.tensor_key_encrypt_sk_tmp_bytes(infos)
|
self.tensor_key_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ModuleN, VecZnxAddScalarInplace, VecZnxNormalizeInplace},
|
api::{ModuleN, VecZnxAddScalarInplace, VecZnxNormalizeInplace},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero},
|
layouts::{Backend, DataMut, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero},
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,22 +26,23 @@ impl GGSWCompressed<Vec<u8>> {
|
|||||||
|
|
||||||
impl<DataSelf: DataMut> GGSWCompressed<DataSelf> {
|
impl<DataSelf: DataMut> GGSWCompressed<DataSelf> {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, BE: Backend>(
|
pub fn encrypt_sk<P, S, M, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &Module<BE>,
|
module: &M,
|
||||||
pt: &ScalarZnx<DataPt>,
|
pt: &P,
|
||||||
sk: &GLWESecretPrepared<DataSk, BE>,
|
sk: &S,
|
||||||
seed_xa: [u8; 32],
|
seed_xa: [u8; 32],
|
||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
Module<BE>: GGSWCompressedEncryptSk<BE>,
|
P: ScalarZnxToRef,
|
||||||
|
S: GLWESecretPreparedToRef<BE>,
|
||||||
|
M: GGSWCompressedEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.ggsw_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch);
|
module.ggsw_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait GGSWCompressedEncryptSk<BE: Backend> {
|
pub trait GGSWCompressedEncryptSk<BE: Backend> {
|
||||||
fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
@@ -63,11 +64,12 @@ pub trait GGSWCompressedEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GGSWCompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GGSWCompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN + GLWEEncryptSkInternal<BE> + GGSWEncryptSk<BE> + VecZnxAddScalarInplace + VecZnxNormalizeInplace<BE>,
|
Self: ModuleN + GLWEEncryptSkInternal<BE> + GGSWEncryptSk<BE> + VecZnxAddScalarInplace + VecZnxNormalizeInplace<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where A: GGSWInfos,
|
where
|
||||||
|
A: GGSWInfos,
|
||||||
{
|
{
|
||||||
self.ggsw_encrypt_sk_tmp_bytes(infos)
|
self.ggsw_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{VecZnxDftBytesOf, VecZnxNormalizeTmpBytes},
|
layouts::{Backend, DataMut, Module, Scratch},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
encryption::{SIGMA, glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal}},
|
encryption::{
|
||||||
|
SIGMA,
|
||||||
|
glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal},
|
||||||
|
},
|
||||||
layouts::{
|
layouts::{
|
||||||
GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, LWEInfos,
|
GLWEInfos, GLWEPlaintextToRef, LWEInfos,
|
||||||
compressed::{GLWECompressed, GLWECompressedToMut},
|
compressed::{GLWECompressed, GLWECompressedToMut},
|
||||||
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
prepared::GLWESecretPreparedToRef,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,22 +27,23 @@ impl GLWECompressed<Vec<u8>> {
|
|||||||
|
|
||||||
impl<D: DataMut> GLWECompressed<D> {
|
impl<D: DataMut> GLWECompressed<D> {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, BE: Backend>(
|
pub fn encrypt_sk<M, P, S, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &Module<BE>,
|
module: &M,
|
||||||
pt: &GLWEPlaintext<DataPt>,
|
pt: &P,
|
||||||
sk: &GLWESecretPrepared<DataSk, BE>,
|
sk: &S,
|
||||||
seed_xa: [u8; 32],
|
seed_xa: [u8; 32],
|
||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
Module<BE>: GLWECompressedEncryptSk<BE>,
|
M: GLWECompressedEncryptSk<BE>,
|
||||||
|
P: GLWEPlaintextToRef,
|
||||||
|
S: GLWESecretPreparedToRef<BE>,
|
||||||
{
|
{
|
||||||
module.glwe_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch);
|
module.glwe_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait GLWECompressedEncryptSk<BE: Backend> {
|
pub trait GLWECompressedEncryptSk<BE: Backend> {
|
||||||
fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
@@ -62,9 +65,8 @@ pub trait GLWECompressedEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWECompressedEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWECompressedEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE>,
|
Self: GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
|
|
||||||
fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GLWEInfos,
|
A: GLWEInfos,
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ pub trait AutomorphismKeyEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: GLWESwitchingKeyEncryptSk<BE> + VecZnxAutomorphism + GaloisElement,
|
Self: GLWESwitchingKeyEncryptSk<BE> + VecZnxAutomorphism + GaloisElement,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
@@ -137,7 +137,7 @@ pub trait GGLWEAutomorphismKeyEncryptPk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GGLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
|
impl<BE: Backend> GGLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>:,
|
Self:,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn automorphism_key_encrypt_pk_tmp_bytes<A>(&self, _infos: &A) -> usize
|
fn automorphism_key_encrypt_pk_tmp_bytes<A>(&self, _infos: &A) -> usize
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ pub trait GGLWEEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GGLWEEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GGLWEEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN
|
Self: ModuleN
|
||||||
+ GLWEEncryptSk<BE>
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxDftBytesOf
|
+ VecZnxDftBytesOf
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ pub trait GLWESwitchingKeyEncryptSk<BE: Backend> {
|
|||||||
) where
|
) where
|
||||||
R: GLWESwitchingKeyToMut,
|
R: GLWESwitchingKeyToMut,
|
||||||
S1: GLWESecretToRef,
|
S1: GLWESecretToRef,
|
||||||
S2: GLWESecretToRef,
|
S2: GLWESecretToRef;
|
||||||
Scratch<BE>: ScratchTakeCore<BE>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> GLWESwitchingKeyEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWESwitchingKeyEncryptSk<BE> for Module<BE>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{
|
||||||
ModuleN, ScratchAvailable, ScratchTakeBasic, SvpApplyDftToDft, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply,
|
ModuleN, ScratchTakeBasic, SvpApplyDftToDft, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf,
|
||||||
VecZnxDftBytesOf, VecZnxIdftApplyTmpA,
|
VecZnxIdftApplyTmpA,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, Module, Scratch},
|
layouts::{Backend, DataMut, Module, Scratch},
|
||||||
source::Source,
|
source::Source,
|
||||||
@@ -37,7 +37,7 @@ impl<DataSelf: DataMut> TensorKey<DataSelf> {
|
|||||||
) where
|
) where
|
||||||
M: TensorKeyEncryptSk<BE>,
|
M: TensorKeyEncryptSk<BE>,
|
||||||
S: GLWESecretToRef + GetDist,
|
S: GLWESecretToRef + GetDist,
|
||||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
module.tensor_key_encrypt_sk(self, sk, source_xa, source_xe, scratch);
|
module.tensor_key_encrypt_sk(self, sk, source_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ pub trait TensorKeyEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> TensorKeyEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> TensorKeyEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN
|
Self: ModuleN
|
||||||
+ GLWESwitchingKeyEncryptSk<BE>
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
+ VecZnxDftBytesOf
|
+ VecZnxDftBytesOf
|
||||||
+ VecZnxBigBytesOf
|
+ VecZnxBigBytesOf
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ pub trait GGSWEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GGSWEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GGSWEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN
|
Self: ModuleN
|
||||||
+ GLWEEncryptSkInternal<BE>
|
+ GLWEEncryptSkInternal<BE>
|
||||||
+ GLWEEncryptSk<BE>
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxDftBytesOf
|
+ VecZnxDftBytesOf
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ impl GLWE<Vec<u8>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> GLWE<D> {
|
impl<D: DataMut> GLWE<D> {
|
||||||
pub fn encrypt_sk<R, P, S, M, BE: Backend>(
|
pub fn encrypt_sk<P, S, M, BE: Backend>(
|
||||||
&mut self,
|
&mut self,
|
||||||
module: &M,
|
module: &M,
|
||||||
pt: &P,
|
pt: &P,
|
||||||
@@ -133,7 +133,7 @@ pub trait GLWEEncryptSk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWEEncryptSk<BE> for Module<BE>
|
impl<BE: Backend> GLWEEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: Sized + ModuleN + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + GLWEEncryptSkInternal<BE>,
|
Self: Sized + ModuleN + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + GLWEEncryptSkInternal<BE>,
|
||||||
Scratch<BE>: ScratchAvailable,
|
Scratch<BE>: ScratchAvailable,
|
||||||
{
|
{
|
||||||
fn glwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
@@ -262,7 +262,7 @@ pub trait GLWEEncryptPk<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWEEncryptPk<BE> for Module<BE>
|
impl<BE: Backend> GLWEEncryptPk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: GLWEEncryptPkInternal<BE> + VecZnxDftBytesOf + SvpPPolBytesOf + VecZnxBigBytesOf + VecZnxNormalizeTmpBytes,
|
Self: GLWEEncryptPkInternal<BE> + VecZnxDftBytesOf + SvpPPolBytesOf + VecZnxBigBytesOf + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
fn glwe_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
@@ -330,7 +330,7 @@ pub(crate) trait GLWEEncryptPkInternal<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWEEncryptPkInternal<BE> for Module<BE>
|
impl<BE: Backend> GLWEEncryptPkInternal<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: SvpPrepare<BE>
|
Self: SvpPrepare<BE>
|
||||||
+ SvpApplyDftToDft<BE>
|
+ SvpApplyDftToDft<BE>
|
||||||
+ VecZnxIdftApplyConsume<BE>
|
+ VecZnxIdftApplyConsume<BE>
|
||||||
+ VecZnxBigAddNormal<BE>
|
+ VecZnxBigAddNormal<BE>
|
||||||
@@ -445,7 +445,7 @@ pub(crate) trait GLWEEncryptSkInternal<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWEEncryptSkInternal<BE> for Module<BE>
|
impl<BE: Backend> GLWEEncryptSkInternal<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN
|
Self: ModuleN
|
||||||
+ VecZnxDftBytesOf
|
+ VecZnxDftBytesOf
|
||||||
+ VecZnxBigNormalize<BE>
|
+ VecZnxBigNormalize<BE>
|
||||||
+ VecZnxDftApply<BE>
|
+ VecZnxDftApply<BE>
|
||||||
@@ -459,7 +459,7 @@ where
|
|||||||
+ VecZnxAddNormal
|
+ VecZnxAddNormal
|
||||||
+ VecZnxNormalize<BE>
|
+ VecZnxNormalize<BE>
|
||||||
+ VecZnxSub,
|
+ VecZnxSub,
|
||||||
Scratch<BE>: ScratchAvailable + ScratchTakeBasic,
|
Scratch<BE>: ScratchTakeBasic,
|
||||||
{
|
{
|
||||||
fn glwe_encrypt_sk_internal<R, P, S>(
|
fn glwe_encrypt_sk_internal<R, P, S>(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ScratchOwnedAlloc, ScratchOwnedBorrow},
|
api::{ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch, ScratchOwned},
|
layouts::{Backend, DataMut, Module, Scratch, ScratchOwned},
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -14,14 +14,10 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
impl<D: DataMut> GLWEPublicKey<D> {
|
impl<D: DataMut> GLWEPublicKey<D> {
|
||||||
pub fn generate<S: DataRef, BE: Backend>(
|
pub fn generate<S, M, BE: Backend>(&mut self, module: &M, sk: &S, source_xa: &mut Source, source_xe: &mut Source)
|
||||||
&mut self,
|
where
|
||||||
module: &Module<BE>,
|
S: GLWESecretPreparedToRef<BE>,
|
||||||
sk: &GLWESecretPrepared<S, BE>,
|
M: GLWEPublicKeyGenerate<BE>,
|
||||||
source_xa: &mut Source,
|
|
||||||
source_xe: &mut Source,
|
|
||||||
) where
|
|
||||||
Module<BE>: GLWEPublicKeyGenerate<BE>,
|
|
||||||
{
|
{
|
||||||
module.glwe_public_key_generate(self, sk, source_xa, source_xe);
|
module.glwe_public_key_generate(self, sk, source_xa, source_xe);
|
||||||
}
|
}
|
||||||
@@ -36,7 +32,7 @@ pub trait GLWEPublicKeyGenerate<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWEPublicKeyGenerate<BE> for Module<BE>
|
impl<BE: Backend> GLWEPublicKeyGenerate<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: GLWEEncryptSk<BE>,
|
Self: GLWEEncryptSk<BE>,
|
||||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ pub trait GLWEToLWESwitchingKeyEncrypt<BE: Backend> {
|
|||||||
|
|
||||||
impl<BE: Backend> GLWEToLWESwitchingKeyEncrypt<BE> for Module<BE>
|
impl<BE: Backend> GLWEToLWESwitchingKeyEncrypt<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>,
|
Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub struct GLWESwitchingKey<D: Data> {
|
|||||||
pub(crate) sk_out_n: usize, // Degree of sk_out
|
pub(crate) sk_out_n: usize, // Degree of sk_out
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait GLWESwitchingKeySetMetaData {
|
pub trait GLWESwitchingKeySetMetaData {
|
||||||
fn set_sk_in_n(&mut self, sk_in_n: usize);
|
fn set_sk_in_n(&mut self, sk_in_n: usize);
|
||||||
fn set_sk_out_n(&mut self, sk_out_n: usize);
|
fn set_sk_out_n(&mut self, sk_out_n: usize);
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ impl<D: DataMut> GLWESwitchingKeySetMetaData for GLWESwitchingKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait GLWESwtichingKeyGetMetaData {
|
pub trait GLWESwtichingKeyGetMetaData {
|
||||||
fn sk_in_n(&self) -> usize;
|
fn sk_in_n(&self) -> usize;
|
||||||
fn sk_out_n(&self) -> usize;
|
fn sk_out_n(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use poulpy_hal::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dist::Distribution,
|
dist::Distribution,
|
||||||
layouts::{Base2K, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision},
|
layouts::{Base2K, GLWEInfos, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
@@ -64,6 +64,12 @@ impl<D: Data> LWEInfos for GLWESecret<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: Data> GetDist for GLWESecret<D> {
|
||||||
|
fn get_dist(&self) -> Distribution {
|
||||||
|
self.dist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<D: Data> GLWEInfos for GLWESecret<D> {
|
impl<D: Data> GLWEInfos for GLWESecret<D> {
|
||||||
fn rank(&self) -> Rank {
|
fn rank(&self) -> Rank {
|
||||||
Rank(self.data.cols() as u32)
|
Rank(self.data.cols() as u32)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ mod lwe_to_glwe_ksk;
|
|||||||
pub mod compressed;
|
pub mod compressed;
|
||||||
pub mod prepared;
|
pub mod prepared;
|
||||||
|
|
||||||
|
pub use compressed::*;
|
||||||
pub use gglwe_atk::*;
|
pub use gglwe_atk::*;
|
||||||
pub use gglwe_ct::*;
|
pub use gglwe_ct::*;
|
||||||
pub use gglwe_ksk::*;
|
pub use gglwe_ksk::*;
|
||||||
@@ -32,6 +33,7 @@ pub use lwe_ksk::*;
|
|||||||
pub use lwe_pt::*;
|
pub use lwe_pt::*;
|
||||||
pub use lwe_sk::*;
|
pub use lwe_sk::*;
|
||||||
pub use lwe_to_glwe_ksk::*;
|
pub use lwe_to_glwe_ksk::*;
|
||||||
|
pub use prepared::*;
|
||||||
|
|
||||||
use poulpy_hal::layouts::{Backend, Module};
|
use poulpy_hal::layouts::{Backend, Module};
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ where
|
|||||||
impl<B: Backend> TensorKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {}
|
impl<B: Backend> TensorKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {}
|
||||||
|
|
||||||
impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
||||||
fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
|
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: TensorKeyPrepare<B>,
|
M: TensorKeyPrepare<B>,
|
||||||
@@ -208,7 +208,7 @@ impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
||||||
fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||||
where
|
where
|
||||||
O: TensorKeyToRef,
|
O: TensorKeyToRef,
|
||||||
M: TensorKeyPrepare<B>,
|
M: TensorKeyPrepare<B>,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub struct GLWEPublicKeyPrepared<D: Data, B: Backend> {
|
|||||||
pub(crate) dist: Distribution,
|
pub(crate) dist: Distribution,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait SetDist {
|
pub trait SetDist {
|
||||||
fn set_dist(&mut self, dist: Distribution);
|
fn set_dist(&mut self, dist: Distribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ where
|
|||||||
self.alloc_glwe_secret_prepared(infos.rank())
|
self.alloc_glwe_secret_prepared(infos.rank())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bytes_of_glwe_secret(&self, rank: Rank) -> usize {
|
fn bytes_of_glwe_secret_prepared(&self, rank: Rank) -> usize {
|
||||||
self.bytes_of_svp_ppol(rank.into())
|
self.bytes_of_svp_ppol(rank.into())
|
||||||
}
|
}
|
||||||
fn bytes_of_glwe_secret_prepared_from_infos<A>(&self, infos: &A) -> usize
|
fn bytes_of_glwe_secret_prepared_from_infos<A>(&self, infos: &A) -> usize
|
||||||
@@ -71,7 +71,7 @@ where
|
|||||||
A: GLWEInfos,
|
A: GLWEInfos,
|
||||||
{
|
{
|
||||||
assert_eq!(self.ring_degree(), infos.n());
|
assert_eq!(self.ring_degree(), infos.n());
|
||||||
self.bytes_of_glwe_secret(infos.rank())
|
self.bytes_of_glwe_secret_prepared(infos.rank())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
|
|||||||
where
|
where
|
||||||
M: GLWESecretPreparedAlloc<B>,
|
M: GLWESecretPreparedAlloc<B>,
|
||||||
{
|
{
|
||||||
module.bytes_of_glwe_secret(rank)
|
module.bytes_of_glwe_secret_prepared(rank)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, B: Backend> GLWEToLWESwitchingKeyPrepared<D, B> {
|
impl<D: DataMut, B: Backend> GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||||
fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||||
where
|
where
|
||||||
O: GLWEToLWESwitchingKeyToRef,
|
O: GLWEToLWESwitchingKeyToRef,
|
||||||
M: GLWEToLWESwitchingKeyPrepare<B>,
|
M: GLWEToLWESwitchingKeyPrepare<B>,
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, B: Backend> LWESwitchingKeyPrepared<D, B> {
|
impl<D: DataMut, B: Backend> LWESwitchingKeyPrepared<D, B> {
|
||||||
fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||||
where
|
where
|
||||||
O: LWESwitchingKeyToRef,
|
O: LWESwitchingKeyToRef,
|
||||||
M: LWESwitchingKeyPrepare<B>,
|
M: LWESwitchingKeyPrepare<B>,
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut, B: Backend> LWEToGLWESwitchingKeyPrepared<D, B> {
|
impl<D: DataMut, B: Backend> LWEToGLWESwitchingKeyPrepared<D, B> {
|
||||||
fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||||
where
|
where
|
||||||
O: LWEToGLWESwitchingKeyToRef,
|
O: LWEToGLWESwitchingKeyToRef,
|
||||||
M: LWEToGLWESwitchingKeyPrepare<B>,
|
M: LWEToGLWESwitchingKeyPrepare<B>,
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxSubScalarInplace},
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxSubScalarInplace,
|
layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, ZnxZero},
|
||||||
},
|
|
||||||
layouts::{Backend, DataRef, Module, Scratch, ScratchOwned, ScalarZnx, ScalarZnxToRef, ZnxZero},
|
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, VecZnxSubScalarInplaceImpl},
|
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, VecZnxSubScalarInplaceImpl},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::decryption::GLWEDecryption;
|
||||||
use crate::layouts::{
|
use crate::layouts::{
|
||||||
GGLWE, GGLWEToRef, GGLWEInfos, GLWEPlaintext, LWEInfos,
|
GGLWE, GGLWEInfos, GGLWEToRef, GLWEPlaintext, LWEInfos,
|
||||||
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
||||||
};
|
};
|
||||||
use crate::decryption::GLWEDecryption;
|
|
||||||
|
|
||||||
impl<D: DataRef> GGLWE<D> {
|
impl<D: DataRef> GGLWE<D> {
|
||||||
|
|
||||||
pub fn assert_noise<M, BE, DataSk, DataWant>(
|
pub fn assert_noise<M, BE, DataSk, DataWant>(
|
||||||
&self,
|
&self,
|
||||||
module: &M,
|
module: &M,
|
||||||
@@ -24,12 +21,15 @@ impl<D: DataRef> GGLWE<D> {
|
|||||||
DataSk: DataRef,
|
DataSk: DataRef,
|
||||||
DataWant: DataRef,
|
DataWant: DataRef,
|
||||||
M: GGLWENoise<BE>,
|
M: GGLWENoise<BE>,
|
||||||
BE: Backend + ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>,
|
BE: Backend
|
||||||
|
+ ScratchOwnedAllocImpl<BE>
|
||||||
|
+ ScratchOwnedBorrowImpl<BE>
|
||||||
|
+ ScratchOwnedBorrow<BE>
|
||||||
|
+ VecZnxSubScalarInplaceImpl<BE>,
|
||||||
{
|
{
|
||||||
module.gglwe_assert_noise(self, sk_prepared, pt_want, max_noise);
|
module.gglwe_assert_noise(self, sk_prepared, pt_want, max_noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// pub fn assert_noise<B, DataSk, DataWant>(
|
// pub fn assert_noise<B, DataSk, DataWant>(
|
||||||
// &self,
|
// &self,
|
||||||
// module: &Module<B>,
|
// module: &Module<B>,
|
||||||
@@ -79,7 +79,6 @@ impl<D: DataRef> GGLWE<D> {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait GGLWENoise<BE: Backend> {
|
pub trait GGLWENoise<BE: Backend> {
|
||||||
fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64)
|
fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64)
|
||||||
where
|
where
|
||||||
@@ -92,7 +91,11 @@ pub trait GGLWENoise<BE: Backend> {
|
|||||||
impl<BE: Backend> GGLWENoise<BE> for Module<BE>
|
impl<BE: Backend> GGLWENoise<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: GLWEDecryption<BE>,
|
Module<BE>: GLWEDecryption<BE>,
|
||||||
Scratch<BE>: ScratchTakeBasic + ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE>,
|
Scratch<BE>: ScratchTakeBasic
|
||||||
|
+ ScratchOwnedAllocImpl<BE>
|
||||||
|
+ ScratchOwnedBorrowImpl<BE>
|
||||||
|
+ ScratchOwnedBorrowImpl<BE>
|
||||||
|
+ ScratchOwnedBorrow<BE>,
|
||||||
{
|
{
|
||||||
fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64)
|
fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64)
|
||||||
where
|
where
|
||||||
@@ -101,7 +104,6 @@ where
|
|||||||
P: ScalarZnxToRef,
|
P: ScalarZnxToRef,
|
||||||
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>,
|
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>,
|
||||||
{
|
{
|
||||||
|
|
||||||
let res: &GGLWE<&[u8]> = &res.to_ref();
|
let res: &GGLWE<&[u8]> = &res.to_ref();
|
||||||
|
|
||||||
let dsize: usize = res.dsize().into();
|
let dsize: usize = res.dsize().into();
|
||||||
@@ -112,7 +114,12 @@ where
|
|||||||
|
|
||||||
(0..res.rank_in().into()).for_each(|col_i| {
|
(0..res.rank_in().into()).for_each(|col_i| {
|
||||||
(0..res.dnum().into()).for_each(|row_i| {
|
(0..res.dnum().into()).for_each(|row_i| {
|
||||||
self.glwe_decrypt(&res.at(row_i, col_i), &mut pt, sk_prepared, scratch.borrow());
|
self.glwe_decrypt(
|
||||||
|
&res.at(row_i, col_i),
|
||||||
|
&mut pt,
|
||||||
|
sk_prepared,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
self.vec_znx_sub_scalar_inplace(&mut pt.data, 0, (dsize - 1) + row_i * dsize, pt_want, col_i);
|
self.vec_znx_sub_scalar_inplace(&mut pt.data, 0, (dsize - 1) + row_i * dsize, pt_want, col_i);
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, VecZnxAddScalarInplace, VecZnxBigAddInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, SvpApplyDftToDftInplace, VecZnxAddScalarInplace,
|
||||||
VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes,
|
VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigBytesOf, VecZnxBigNormalize,
|
||||||
VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes,
|
VecZnxBigNormalizeTmpBytes, VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume,
|
||||||
VecZnxSubInplace,
|
VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes, VecZnxSubInplace,
|
||||||
ScratchTakeBasic,
|
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, VecZnxBig, VecZnxDft, ZnxZero},
|
layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, VecZnxBig, VecZnxDft, ZnxZero},
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl},
|
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::layouts::{GGSW, GGSWInfos, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared, GGSWToRef};
|
|
||||||
use crate::layouts::prepared::GLWESecretPreparedToRef;
|
|
||||||
use crate::decryption::GLWEDecryption;
|
use crate::decryption::GLWEDecryption;
|
||||||
|
use crate::layouts::prepared::GLWESecretPreparedToRef;
|
||||||
|
use crate::layouts::{GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared};
|
||||||
|
|
||||||
impl<D: DataRef> GGSW<D> {
|
impl<D: DataRef> GGSW<D> {
|
||||||
pub fn assert_noise<M, BE, DataSk, DataScalar, F>(
|
pub fn assert_noise<M, BE, DataSk, DataScalar, F>(
|
||||||
@@ -20,7 +19,7 @@ impl<D: DataRef> GGSW<D> {
|
|||||||
module: &M,
|
module: &M,
|
||||||
sk_prepared: &GLWESecretPrepared<DataSk, BE>,
|
sk_prepared: &GLWESecretPrepared<DataSk, BE>,
|
||||||
pt_want: &ScalarZnx<DataScalar>,
|
pt_want: &ScalarZnx<DataScalar>,
|
||||||
max_noise: F
|
max_noise: F,
|
||||||
) where
|
) where
|
||||||
DataSk: DataRef,
|
DataSk: DataRef,
|
||||||
DataScalar: DataRef,
|
DataScalar: DataRef,
|
||||||
@@ -91,7 +90,6 @@ where
|
|||||||
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE>,
|
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE>,
|
||||||
F: Fn(usize) -> f64,
|
F: Fn(usize) -> f64,
|
||||||
{
|
{
|
||||||
|
|
||||||
let res: &GGSW<&[u8]> = &res.to_ref();
|
let res: &GGSW<&[u8]> = &res.to_ref();
|
||||||
let sk_prepared: &GLWESecretPrepared<&[u8], BE> = &sk_prepared.to_ref();
|
let sk_prepared: &GLWESecretPrepared<&[u8], BE> = &sk_prepared.to_ref();
|
||||||
|
|
||||||
@@ -126,7 +124,12 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.glwe_decrypt(&res.at(row_i, col_j), &mut pt_have, sk_prepared, scratch.borrow());
|
self.glwe_decrypt(
|
||||||
|
&res.at(row_i, col_j),
|
||||||
|
&mut pt_have,
|
||||||
|
sk_prepared,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
|
|
||||||
self.vec_znx_sub_inplace(&mut pt_have.data, 0, &pt.data, 0);
|
self.vec_znx_sub_inplace(&mut pt_have.data, 0, &pt.data, 0);
|
||||||
|
|
||||||
@@ -180,7 +183,12 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.glwe_decrypt(&res.at(row_i, col_j), &mut pt_have, sk_prepared, scratch.borrow());
|
self.glwe_decrypt(
|
||||||
|
&res.at(row_i, col_j),
|
||||||
|
&mut pt_have,
|
||||||
|
sk_prepared,
|
||||||
|
scratch.borrow(),
|
||||||
|
);
|
||||||
self.vec_znx_sub_inplace(&mut pt_have.data, 0, &pt.data, 0);
|
self.vec_znx_sub_inplace(&mut pt_have.data, 0, &pt.data, 0);
|
||||||
|
|
||||||
let std_pt: f64 = pt_have.data.std(base2k, 0).log2();
|
let std_pt: f64 = pt_have.data.std(base2k, 0).log2();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, SvpApplyDftToDftInplace, VecZnxBigAddInplace,
|
||||||
VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalizeInplace,
|
VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume,
|
||||||
VecZnxNormalizeTmpBytes, VecZnxSubInplace, ScratchTakeBasic,
|
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSubInplace,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataRef, Module, Scratch, ScratchOwned},
|
layouts::{Backend, DataRef, Module, Scratch, ScratchOwned},
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl},
|
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl},
|
||||||
@@ -96,7 +96,6 @@ impl<D: DataRef> GLWE<D> {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait GLWENoise<BE: Backend> {
|
pub trait GLWENoise<BE: Backend> {
|
||||||
fn glwe_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, scratch: &mut Scratch<BE>) -> f64
|
fn glwe_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, scratch: &mut Scratch<BE>) -> f64
|
||||||
where
|
where
|
||||||
@@ -126,7 +125,11 @@ where
|
|||||||
+ VecZnxSubInplace
|
+ VecZnxSubInplace
|
||||||
+ VecZnxNormalizeInplace<BE>
|
+ VecZnxNormalizeInplace<BE>
|
||||||
+ GLWEDecryption<BE>,
|
+ GLWEDecryption<BE>,
|
||||||
Scratch<BE>: ScratchTakeBasic + ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE>,
|
Scratch<BE>: ScratchTakeBasic
|
||||||
|
+ ScratchOwnedAllocImpl<BE>
|
||||||
|
+ ScratchOwnedBorrowImpl<BE>
|
||||||
|
+ ScratchOwnedBorrowImpl<BE>
|
||||||
|
+ ScratchOwnedBorrow<BE>,
|
||||||
{
|
{
|
||||||
fn glwe_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, scratch: &mut Scratch<BE>) -> f64
|
fn glwe_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, scratch: &mut Scratch<BE>) -> f64
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ where
|
|||||||
|
|
||||||
impl<BE: Backend> GLWEAdd for Module<BE> where Self: ModuleN + VecZnxAdd + VecZnxCopy + VecZnxAddInplace {}
|
impl<BE: Backend> GLWEAdd for Module<BE> where Self: ModuleN + VecZnxAdd + VecZnxCopy + VecZnxAddInplace {}
|
||||||
|
|
||||||
|
impl<BE: Backend> GLWESub for Module<BE> where
|
||||||
|
Self: ModuleN + VecZnxSub + VecZnxCopy + VecZnxNegateInplace + VecZnxSubInplace + VecZnxSubNegateInplace
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
pub trait GLWESub
|
pub trait GLWESub
|
||||||
where
|
where
|
||||||
Self: ModuleN + VecZnxSub + VecZnxCopy + VecZnxNegateInplace + VecZnxSubInplace + VecZnxSubNegateInplace,
|
Self: ModuleN + VecZnxSub + VecZnxCopy + VecZnxNegateInplace + VecZnxSubInplace + VecZnxSubNegateInplace,
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ pub trait TakeSlice {
|
|||||||
fn take_slice<T>(&mut self, len: usize) -> (&mut [T], &mut Self);
|
fn take_slice<T>(&mut self, len: usize) -> (&mut [T], &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<B: Backend> ScratchTakeBasic for Scratch<B> where Self: TakeSlice {}
|
||||||
|
|
||||||
pub trait ScratchTakeBasic
|
pub trait ScratchTakeBasic
|
||||||
where
|
where
|
||||||
Self: TakeSlice,
|
Self: TakeSlice,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
api::ModuleNew,
|
api::{ModuleN, ModuleNew},
|
||||||
layouts::{Backend, Module},
|
layouts::{Backend, Module},
|
||||||
oep::ModuleNewImpl,
|
oep::ModuleNewImpl,
|
||||||
};
|
};
|
||||||
@@ -12,3 +12,12 @@ where
|
|||||||
B::new_impl(n)
|
B::new_impl(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<B> ModuleN for Module<B>
|
||||||
|
where
|
||||||
|
B: Backend,
|
||||||
|
{
|
||||||
|
fn n(&self) -> usize {
|
||||||
|
self.n()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user