fix remaining issues before fixing tests
jump to
@@ -1,6 +1,6 @@
use poulpy_core::layouts::{ Base2K, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, RingDegree, TorusPrecision, - prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, + prepared::{GGSWPrepared, GLWESecretPrepared}, }; use std::hint::black_box;@@ -61,9 +61,9 @@ k: k_ct_in,
rank, }; - let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_layout); - let mut ct_glwe_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_in_layout); - let mut ct_glwe_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_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(&module, &glwe_in_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 mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc(@@ -76,9 +76,11 @@ let mut source_xs = Source::new([0u8; 32]);
let mut source_xe = 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); - 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( &module,@@ -97,7 +99,8 @@ &mut source_xe,
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 || { ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow());@@ -162,23 +165,25 @@ k: k_glwe,
rank, }; - let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_layout); - let mut ct_glwe: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_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(&module, &glwe_layout); let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1); let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc( GGSW::encrypt_sk_tmp_bytes(&module, &ggsw_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_xe: 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); - 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( &module,@@ -197,8 +202,8 @@ &mut source_xe,
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 || { let scratch_borrow = scratch.borrow(); ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow);
@@ -1,7 +1,7 @@
use poulpy_core::layouts::{ AutomorphismKey, AutomorphismKeyLayout, Base2K, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, - GLWESwitchingKeyLayout, Rank, RingDegree, TorusPrecision, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc}, + GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, RingDegree, TorusPrecision, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, }; use std::{hint::black_box, time::Duration};@@ -62,9 +62,9 @@ k: k_glwe_out,
rank, }; - let mut ksk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&gglwe_atk_layout); - let mut ct_in: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_in_layout); - let mut ct_out: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_out_layout); + let mut ksk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&module, &gglwe_atk_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(&module, &glwe_out_layout); let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc( GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_atk_layout)@@ -81,9 +81,11 @@ 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 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); - 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( &module,@@ -102,7 +104,8 @@ &mut source_xe,
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 || { ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow());@@ -174,24 +177,26 @@ k: k_ct,
rank, }; - let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_layout); - let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_layout); + let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&module, &gglwe_layout); + let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&module, &glwe_layout); let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc( GLWESwitchingKey::encrypt_sk_tmp_bytes(&module, &gglwe_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_xe: 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); - 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); - let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_layout); + let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&module, &glwe_layout); sk_out.fill_ternary_prob(0.5, &mut source_xs); ksk.encrypt_sk(@@ -211,7 +216,8 @@ &mut source_xe,
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 || { ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow());
@@ -1,9 +1,9 @@
use poulpy_backend::cpu_spqlios::FFT64Spqlios; use poulpy_core::{ - GLWEOperations, SIGMA, + GLWESub, SIGMA, layouts::{ Base2K, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, RingDegree, TorusPrecision, - prepared::{GLWESecretPrepared, PrepareAlloc}, + prepared::GLWESecretPrepared, }, }; use poulpy_hal::{@@ -43,9 +43,9 @@
let glwe_pt_infos: GLWEPlaintextLayout = GLWEPlaintextLayout { n, base2k, k: k_pt }; // Allocates ciphertext & plaintexts - let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_ct_infos); - let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_infos); - let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_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(&module, &glwe_pt_infos); + let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&module, &glwe_pt_infos); // CPRNG let mut source_xs: Source = Source::new([0u8; 32]);@@ -58,11 +58,12 @@ GLWE::encrypt_sk_tmp_bytes(&module, &glwe_ct_infos) | GLWE::decrypt_tmp_bytes(&module, &glwe_ct_infos),
); // 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); // 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 module.vec_znx_fill_uniform(base2k.into(), &mut pt_want.data, 0, &mut source_xa);@@ -81,7 +82,7 @@ // Decryption
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow()); // 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 let noise_have: f64 = pt_want.data.std(base2k.into(), 0) * (ct.k().as_u32() as f64).exp2();
@@ -38,9 +38,7 @@ module.ggsw_from_gglwe(self, gglwe, tsk, scratch);
} } -impl<BE: Backend> GGSWFromGGLWE<BE> for Module<BE> where Self: GGSWExpandRows<BE> + GLWECopy {} - -pub trait GGSWFromGGLWE<BE: Backend> +impl<BE: Backend> GGSWFromGGLWE<BE> for Module<BE> where Self: GGSWExpandRows<BE> + GLWECopy, {@@ -77,6 +75,20 @@ self.ggsw_expand_row(res, tsk, scratch);
} } +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 Self: Sized + ModuleN@@ -99,7 +111,7 @@ + VecZnxNormalize<BE>
{ } -pub(crate) trait GGSWExpandRows<BE: Backend> +pub trait GGSWExpandRows<BE: Backend> where Self: Sized + ModuleN
@@ -2,4 +2,4 @@ mod glwe_ct;
mod lwe_ct; pub use glwe_ct::*; -pub use lwe_ct::*; +// pub use lwe_ct::*;
@@ -61,7 +61,7 @@ }
impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + GaloisElement + VecZnxAutomorphism + GLWESwitchingKeyCompressedEncryptSk<BE>, + Self: ModuleN + GaloisElement + VecZnxAutomorphism + GLWESwitchingKeyCompressedEncryptSk<BE>, Scratch<BE>: ScratchTakeCore<BE>, { fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize@@ -99,7 +99,7 @@
let (mut sk_out, scratch_1) = scratch.take_glwe_secret(self, sk.rank()); { - for i in 0..res.rank_out().into(){ + for i in 0..res.rank_out().into() { self.vec_znx_automorphism( self.galois_element_inv(p), &mut sk_out.data.as_vec_znx_mut(),@@ -107,7 +107,7 @@ i,
&sk.data.as_vec_znx(), i, ); - }; + } } self.glwe_switching_key_compressed_encrypt_sk(&mut res.key, sk, &sk_out, seed_xa, source_xe, scratch_1);
@@ -67,7 +67,7 @@ }
impl<BE: Backend> GGLWECompressedEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + Self: ModuleN + GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE> + VecZnxDftBytesOf
@@ -64,7 +64,7 @@ }
impl<BE: Backend> GLWESwitchingKeyCompressedEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing, + Self: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing, Scratch<BE>: ScratchTakeCore<BE>, { fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -1,9 +1,9 @@
use poulpy_hal::{ api::{ - ModuleN, ScratchTakeBasic, SvpApplyDftToDft, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare, VecZnxBigBytesOf, - VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes, + ModuleN, ScratchTakeBasic, SvpApplyDftToDft, SvpPPolBytesOf, SvpPrepare, VecZnxBigBytesOf, VecZnxBigNormalize, + VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyTmpA, }, - layouts::{Backend, DataMut, DataRef, Module, Scratch}, + layouts::{Backend, DataMut, Module, Scratch}, oep::{SvpPPolAllocBytesImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl}, source::Source, };@@ -13,7 +13,7 @@ ScratchTakeCore,
encryption::compressed::gglwe_ksk::GLWESwitchingKeyCompressedEncryptSk, encryption::gglwe_tsk::TensorKeyEncryptSk, layouts::{ - GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, LWEInfos, Rank, TensorKey, + GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, LWEInfos, Rank, compressed::{TensorKeyCompressed, TensorKeyCompressedToMut}, }, };@@ -29,23 +29,22 @@ }
} impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> { - pub fn encrypt_sk<DataSk: DataRef, BE: Backend>( + pub fn encrypt_sk<S, M, BE: Backend>( &mut self, - module: &Module<BE>, - sk: &GLWESecret<DataSk>, + module: &M, + sk: &S, seed_xa: [u8; 32], source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - GLWESecret<DataSk>: GetDist, - Module<BE>: GGLWETensorKeyCompressedEncryptSk<BE>, + S: GLWESecretToRef + GetDist, + M: GGLWETensorKeyCompressedEncryptSk<BE>, { module.gglwe_tensor_key_encrypt_sk(self, sk, seed_xa, source_xe, scratch); } } pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> { - fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize where A: GGLWEInfos;@@ -64,7 +63,7 @@ }
impl<BE: Backend> GGLWETensorKeyCompressedEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + Self: ModuleN + GLWESwitchingKeyCompressedEncryptSk<BE> + TensorKeyEncryptSk<BE> + VecZnxDftApply<BE>@@ -82,7 +81,7 @@ Scratch<BE>: ScratchTakeBasic + ScratchTakeCore<BE>,
{ fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize where - A: GGLWEInfos + A: GGLWEInfos, { self.tensor_key_encrypt_sk_tmp_bytes(infos) }@@ -154,4 +153,4 @@ );
} } } -}+}
@@ -1,6 +1,6 @@
use poulpy_hal::{ api::{ModuleN, VecZnxAddScalarInplace, VecZnxNormalizeInplace}, - layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero}, + layouts::{Backend, DataMut, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero}, source::Source, };@@ -26,21 +26,22 @@ }
impl<DataSelf: DataMut> GGSWCompressed<DataSelf> { #[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, - module: &Module<BE>, - pt: &ScalarZnx<DataPt>, - sk: &GLWESecretPrepared<DataSk, BE>, + module: &M, + pt: &P, + sk: &S, seed_xa: [u8; 32], source_xe: &mut Source, scratch: &mut Scratch<BE>, ) 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); } } - pub trait GGSWCompressedEncryptSk<BE: Backend> { fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize@@ -63,11 +64,12 @@ }
impl<BE: Backend> GGSWCompressedEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + GLWEEncryptSkInternal<BE> + GGSWEncryptSk<BE> + VecZnxAddScalarInplace + VecZnxNormalizeInplace<BE>, + Self: ModuleN + GLWEEncryptSkInternal<BE> + GGSWEncryptSk<BE> + VecZnxAddScalarInplace + VecZnxNormalizeInplace<BE>, Scratch<BE>: ScratchTakeCore<BE>, { 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) }@@ -139,4 +141,4 @@ );
} } } -}+}
@@ -1,15 +1,17 @@
use poulpy_hal::{ - api::{VecZnxDftBytesOf, VecZnxNormalizeTmpBytes}, - layouts::{Backend, DataMut, DataRef, Module, Scratch}, + layouts::{Backend, DataMut, Module, Scratch}, source::Source, }; use crate::{ - encryption::{SIGMA, glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal}}, + encryption::{ + SIGMA, + glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal}, + }, layouts::{ - GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, LWEInfos, + GLWEInfos, GLWEPlaintextToRef, LWEInfos, compressed::{GLWECompressed, GLWECompressedToMut}, - prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, + prepared::GLWESecretPreparedToRef, }, };@@ -25,21 +27,22 @@ }
impl<D: DataMut> GLWECompressed<D> { #[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, - module: &Module<BE>, - pt: &GLWEPlaintext<DataPt>, - sk: &GLWESecretPrepared<DataSk, BE>, + module: &M, + pt: &P, + sk: &S, seed_xa: [u8; 32], source_xe: &mut Source, scratch: &mut Scratch<BE>, ) 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); } } - pub trait GLWECompressedEncryptSk<BE: Backend> { fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize@@ -62,9 +65,8 @@ }
impl<BE: Backend> GLWECompressedEncryptSk<BE> for Module<BE> where - Module<BE>: GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE>, + Self: GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE>, { - fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize where A: GLWEInfos,@@ -105,4 +107,4 @@ );
res.seed = seed_xa; } -}+}
@@ -68,7 +68,7 @@ }
impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE> where - Module<BE>: GLWESwitchingKeyEncryptSk<BE> + VecZnxAutomorphism + GaloisElement, + Self: GLWESwitchingKeyEncryptSk<BE> + VecZnxAutomorphism + GaloisElement, Scratch<BE>: ScratchTakeCore<BE>, { fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize@@ -137,7 +137,7 @@ }
impl<BE: Backend> GGLWEAutomorphismKeyEncryptPk<BE> for Module<BE> where - Module<BE>:, + Self:, Scratch<BE>: ScratchTakeCore<BE>, { fn automorphism_key_encrypt_pk_tmp_bytes<A>(&self, _infos: &A) -> usize
@@ -73,7 +73,7 @@ }
impl<BE: Backend> GGLWEEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + Self: ModuleN + GLWEEncryptSk<BE> + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf
@@ -66,8 +66,7 @@ scratch: &mut Scratch<BE>,
) where R: GLWESwitchingKeyToMut, S1: GLWESecretToRef, - S2: GLWESecretToRef, - Scratch<BE>: ScratchTakeCore<BE>; + S2: GLWESecretToRef; } impl<BE: Backend> GLWESwitchingKeyEncryptSk<BE> for Module<BE>
@@ -1,7 +1,7 @@
use poulpy_hal::{ api::{ - ModuleN, ScratchAvailable, ScratchTakeBasic, SvpApplyDftToDft, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, - VecZnxDftBytesOf, VecZnxIdftApplyTmpA, + ModuleN, ScratchTakeBasic, SvpApplyDftToDft, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, + VecZnxIdftApplyTmpA, }, layouts::{Backend, DataMut, Module, Scratch}, source::Source,@@ -37,7 +37,7 @@ scratch: &mut Scratch<BE>,
) where M: TensorKeyEncryptSk<BE>, S: GLWESecretToRef + GetDist, - Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, + Scratch<BE>: ScratchTakeCore<BE>, { module.tensor_key_encrypt_sk(self, sk, source_xa, source_xe, scratch); }@@ -62,7 +62,7 @@ }
impl<BE: Backend> TensorKeyEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + VecZnxDftBytesOf + VecZnxBigBytesOf
@@ -64,7 +64,7 @@ }
impl<BE: Backend> GGSWEncryptSk<BE> for Module<BE> where - Module<BE>: ModuleN + Self: ModuleN + GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE> + VecZnxDftBytesOf
@@ -38,7 +38,7 @@ }
} 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, module: &M, pt: &P,@@ -133,7 +133,7 @@ }
impl<BE: Backend> GLWEEncryptSk<BE> for Module<BE> where - Module<BE>: Sized + ModuleN + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + GLWEEncryptSkInternal<BE>, + Self: Sized + ModuleN + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + GLWEEncryptSkInternal<BE>, Scratch<BE>: ScratchAvailable, { fn glwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize@@ -262,7 +262,7 @@ }
impl<BE: Backend> GLWEEncryptPk<BE> for Module<BE> 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 where@@ -330,7 +330,7 @@ }
impl<BE: Backend> GLWEEncryptPkInternal<BE> for Module<BE> where - Module<BE>: SvpPrepare<BE> + Self: SvpPrepare<BE> + SvpApplyDftToDft<BE> + VecZnxIdftApplyConsume<BE> + VecZnxBigAddNormal<BE>@@ -445,7 +445,7 @@ }
impl<BE: Backend> GLWEEncryptSkInternal<BE> for Module<BE> where - Module<BE>: ModuleN + Self: ModuleN + VecZnxDftBytesOf + VecZnxBigNormalize<BE> + VecZnxDftApply<BE>@@ -459,7 +459,7 @@ + VecZnxNormalizeInplace<BE>
+ VecZnxAddNormal + VecZnxNormalize<BE> + VecZnxSub, - Scratch<BE>: ScratchAvailable + ScratchTakeBasic, + Scratch<BE>: ScratchTakeBasic, { fn glwe_encrypt_sk_internal<R, P, S>( &self,
@@ -1,6 +1,6 @@
use poulpy_hal::{ api::{ScratchOwnedAlloc, ScratchOwnedBorrow}, - layouts::{Backend, DataMut, DataRef, Module, Scratch, ScratchOwned}, + layouts::{Backend, DataMut, Module, Scratch, ScratchOwned}, source::Source, };@@ -14,14 +14,10 @@ },
}; impl<D: DataMut> GLWEPublicKey<D> { - pub fn generate<S: DataRef, BE: Backend>( - &mut self, - module: &Module<BE>, - sk: &GLWESecretPrepared<S, BE>, - source_xa: &mut Source, - source_xe: &mut Source, - ) where - Module<BE>: GLWEPublicKeyGenerate<BE>, + pub fn generate<S, M, BE: Backend>(&mut self, module: &M, sk: &S, source_xa: &mut Source, source_xe: &mut Source) + where + S: GLWESecretPreparedToRef<BE>, + M: GLWEPublicKeyGenerate<BE>, { module.glwe_public_key_generate(self, sk, source_xa, source_xe); }@@ -36,7 +32,7 @@ }
impl<BE: Backend> GLWEPublicKeyGenerate<BE> for Module<BE> where - Module<BE>: GLWEEncryptSk<BE>, + Self: GLWEEncryptSk<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchTakeCore<BE>, {
@@ -64,7 +64,7 @@ }
impl<BE: Backend> GLWEToLWESwitchingKeyEncrypt<BE> for Module<BE> where - Module<BE>: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>, + Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>, Scratch<BE>: ScratchTakeCore<BE>, { fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -67,7 +67,7 @@ pub(crate) sk_in_n: usize, // Degree of sk_in
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_out_n(&mut self, sk_out_n: usize); }@@ -82,7 +82,7 @@ self.sk_out_n = sk_out_n
} } -pub(crate) trait GLWESwtichingKeyGetMetaData { +pub trait GLWESwtichingKeyGetMetaData { fn sk_in_n(&self) -> usize; fn sk_out_n(&self) -> usize; }
@@ -8,7 +8,7 @@ };
use crate::{ 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)]@@ -61,6 +61,12 @@ }
fn size(&self) -> usize { 1 + } +} + +impl<D: Data> GetDist for GLWESecret<D> { + fn get_dist(&self) -> Distribution { + self.dist } }
@@ -17,6 +17,7 @@
pub mod compressed; pub mod prepared; +pub use compressed::*; pub use gglwe_atk::*; pub use gglwe_ct::*; pub use gglwe_ksk::*;@@ -32,6 +33,7 @@ pub use lwe_ksk::*;
pub use lwe_pt::*; pub use lwe_sk::*; pub use lwe_to_glwe_ksk::*; +pub use prepared::*; use poulpy_hal::layouts::{Backend, Module};
@@ -198,7 +198,7 @@
impl<B: Backend> TensorKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<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 A: GGLWEInfos, M: TensorKeyPrepare<B>,@@ -208,7 +208,7 @@ }
} 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 O: TensorKeyToRef, M: TensorKeyPrepare<B>,
@@ -18,7 +18,7 @@ pub(crate) k: TorusPrecision,
pub(crate) dist: Distribution, } -pub(crate) trait SetDist { +pub trait SetDist { fn set_dist(&mut self, dist: Distribution); }
@@ -63,7 +63,7 @@ assert_eq!(self.ring_degree(), infos.n());
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()) } fn bytes_of_glwe_secret_prepared_from_infos<A>(&self, infos: &A) -> usize@@ -71,7 +71,7 @@ where
A: GLWEInfos, { 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 @@ pub fn bytes_of<M>(module: &M, rank: Rank) -> usize
where M: GLWESecretPreparedAlloc<B>, { - module.bytes_of_glwe_secret(rank) + module.bytes_of_glwe_secret_prepared(rank) } }
@@ -172,7 +172,7 @@ }
} 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 O: GLWEToLWESwitchingKeyToRef, M: GLWEToLWESwitchingKeyPrepare<B>,
@@ -180,7 +180,7 @@ }
} 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 O: LWESwitchingKeyToRef, M: LWESwitchingKeyPrepare<B>,
@@ -179,7 +179,7 @@ }
} 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 O: LWEToGLWESwitchingKeyToRef, M: LWEToGLWESwitchingKeyPrepare<B>,
@@ -1,19 +1,16 @@
use poulpy_hal::{ - api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxSubScalarInplace, - }, - layouts::{Backend, DataRef, Module, Scratch, ScratchOwned, ScalarZnx, ScalarZnxToRef, ZnxZero}, + api::{ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxSubScalarInplace}, + layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, ZnxZero}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, VecZnxSubScalarInplaceImpl}, }; +use crate::decryption::GLWEDecryption; use crate::layouts::{ - GGLWE, GGLWEToRef, GGLWEInfos, GLWEPlaintext, LWEInfos, + GGLWE, GGLWEInfos, GGLWEToRef, GLWEPlaintext, LWEInfos, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, }; -use crate::decryption::GLWEDecryption; impl<D: DataRef> GGLWE<D> { - pub fn assert_noise<M, BE, DataSk, DataWant>( &self, module: &M,@@ -24,11 +21,14 @@ ) where
DataSk: DataRef, DataWant: DataRef, 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); } - // pub fn assert_noise<B, DataSk, DataWant>( // &self,@@ -79,7 +79,6 @@ // });
// } } - pub trait GGLWENoise<BE: Backend> { fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64) where@@ -89,10 +88,14 @@ P: ScalarZnxToRef,
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>; } -impl<BE: Backend> GGLWENoise<BE> for Module<BE> +impl<BE: Backend> GGLWENoise<BE> for Module<BE> where 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) where@@ -101,9 +104,8 @@ S: GLWESecretPreparedToRef<BE>,
P: ScalarZnxToRef, BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>, { - let res: &GGLWE<&[u8]> = &res.to_ref(); - + let dsize: usize = res.dsize().into(); let base2k: usize = res.base2k().into();@@ -112,7 +114,12 @@ let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(self, res);
(0..res.rank_in().into()).for_each(|col_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);@@ -129,4 +136,4 @@ pt.data.zero();
}); }); } -}+}
@@ -1,18 +1,17 @@
use poulpy_hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, VecZnxAddScalarInplace, VecZnxBigAddInplace, - VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, - VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes, - VecZnxSubInplace, - ScratchTakeBasic, + ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, SvpApplyDftToDftInplace, VecZnxAddScalarInplace, + VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigBytesOf, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, + VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes, VecZnxSubInplace, }, layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, VecZnxBig, VecZnxDft, ZnxZero}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl}, }; -use crate::layouts::{GGSW, GGSWInfos, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared, GGSWToRef}; +use crate::decryption::GLWEDecryption; use crate::layouts::prepared::GLWESecretPreparedToRef; -use crate::decryption::GLWEDecryption; +use crate::layouts::{GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared}; impl<D: DataRef> GGSW<D> { pub fn assert_noise<M, BE, DataSk, DataScalar, F>(@@ -20,7 +19,7 @@ &self,
module: &M, sk_prepared: &GLWESecretPrepared<DataSk, BE>, pt_want: &ScalarZnx<DataScalar>, - max_noise: F + max_noise: F, ) where DataSk: DataRef, DataScalar: DataRef,@@ -91,7 +90,6 @@ P: ScalarZnxToRef,
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE>, F: Fn(usize) -> f64, { - let res: &GGSW<&[u8]> = &res.to_ref(); let sk_prepared: &GLWESecretPrepared<&[u8], BE> = &sk_prepared.to_ref();@@ -126,7 +124,12 @@ scratch.borrow(),
); } - 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);@@ -136,7 +139,7 @@ assert!(std_pt <= noise, "{std_pt} > {noise}");
pt.data.zero(); }); - }); + }); } fn ggsw_print_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P)@@ -180,7 +183,12 @@ scratch.borrow(),
); } - 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); let std_pt: f64 = pt_have.data.std(base2k, 0).log2();@@ -188,5 +196,5 @@ println!("col: {col_j} row: {row_i}: {std_pt}");
pt.data.zero(); }); }); - } -}+ } +}
@@ -1,8 +1,8 @@
use poulpy_hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, - VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalizeInplace, - VecZnxNormalizeTmpBytes, VecZnxSubInplace, ScratchTakeBasic, + ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, SvpApplyDftToDftInplace, VecZnxBigAddInplace, + VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSubInplace, }, layouts::{Backend, DataRef, Module, Scratch, ScratchOwned}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl},@@ -96,7 +96,6 @@ // assert!(noise_have <= max_noise, "{noise_have} {max_noise}");
// } } - 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 where@@ -126,7 +125,11 @@ + VecZnxNormalizeTmpBytes
+ VecZnxSubInplace + VecZnxNormalizeInplace<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 where@@ -157,4 +160,4 @@ let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(self.glwe_decrypt_tmp_bytes(res));
let noise_have: f64 = self.glwe_noise(res, sk_prepared, pt_want, scratch.borrow()); assert!(noise_have <= max_noise, "{noise_have} {max_noise}"); } -}+}
@@ -84,6 +84,11 @@ }
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 where 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); } +impl<B: Backend> ScratchTakeBasic for Scratch<B> where Self: TakeSlice {} + pub trait ScratchTakeBasic where Self: TakeSlice,
@@ -1,5 +1,5 @@
use crate::{ - api::ModuleNew, + api::{ModuleN, ModuleNew}, layouts::{Backend, Module}, oep::ModuleNewImpl, };@@ -12,3 +12,12 @@ fn new(n: u64) -> Self {
B::new_impl(n) } } + +impl<B> ModuleN for Module<B> +where + B: Backend, +{ + fn n(&self) -> usize { + self.n() + } +}