arnaucube
arnaucube/poulpyPublic Self-hosted repository
wip
Pro7ech jeanphilippe.bossuat@gmail.com
Mon, 13 Oct 2025 12:14:11 +0200
commit

cf377ff243a986abe095af6dd4d0cd8bb3abb79d

parent

662e533eacc3977e9a8a4c9f9f8f7073e5f52d1e

94 files changed, 1881 insertions(+), 1224 deletions(-)

jump to
M poulpy-core/benches/external_product_glwe_fft64.rs → poulpy-core/benches/external_product_glwe_fft64.rs

@@ -1,7 +1,7 @@

use poulpy_core::layouts::{ - Base2K, Degree, Dnum, Dsize, GGSWCiphertext, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWESecret, Rank, + Base2K, Degree, Dnum, Dsize, GGSW, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWESecret, Rank, TorusPrecision, - prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, + prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, }; use std::hint::black_box;

@@ -62,13 +62,13 @@ k: k_ct_in,

rank, }; - let mut ct_ggsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_layout); + let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_layout); let mut ct_glwe_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_in_layout); let mut ct_glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_layout); let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1); let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(&module, &ggsw_layout) + GGSW::encrypt_sk_scratch_space(&module, &ggsw_layout) | GLWECiphertext::encrypt_sk_scratch_space(&module, &glwe_in_layout) | GLWECiphertext::external_product_scratch_space(&module, &glwe_out_layout, &glwe_in_layout, &ggsw_layout), );

@@ -98,7 +98,7 @@ &mut source_xe,

scratch.borrow(), ); - let ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, FFT64Spqlios> = ct_ggsw.prepare_alloc(&module, scratch.borrow()); + let ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = ct_ggsw.prepare_alloc(&module, scratch.borrow()); move || { ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow());

@@ -163,12 +163,12 @@ k: k_glwe,

rank, }; - let mut ct_ggsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_layout); + let mut ct_ggsw: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_layout); let mut ct_glwe: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_layout); let pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n.into(), 1); let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(&module, &ggsw_layout) + GGSW::encrypt_sk_scratch_space(&module, &ggsw_layout) | GLWECiphertext::encrypt_sk_scratch_space(&module, &glwe_layout) | GLWECiphertext::external_product_inplace_scratch_space(&module, &glwe_layout, &ggsw_layout), );

@@ -198,7 +198,7 @@ &mut source_xe,

scratch.borrow(), ); - let ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, FFT64Spqlios> = ct_ggsw.prepare_alloc(&module, scratch.borrow()); + let ggsw_prepared: GGSWPrepared<Vec<u8>, FFT64Spqlios> = ct_ggsw.prepare_alloc(&module, scratch.borrow()); move || { let scratch_borrow = scratch.borrow();
M poulpy-core/benches/keyswitch_glwe_fft64.rs → poulpy-core/benches/keyswitch_glwe_fft64.rs

@@ -1,7 +1,7 @@

use poulpy_core::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GGLWESwitchingKey, GGLWESwitchingKeyLayout, - GLWECiphertext, GLWECiphertextLayout, GLWESecret, Rank, TorusPrecision, - prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc}, + AutomorphismKey, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GLWECiphertext, GLWECiphertextLayout, GLWESecret, + GLWESwitchingKey, GLWESwitchingKeyLayout, Rank, TorusPrecision, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc}, }; use std::{hint::black_box, time::Duration};

@@ -39,7 +39,7 @@ let dsize: Dsize = p.dsize;

let dnum: Dnum = p.k_ct_in.div_ceil(p.base2k.0 * dsize.0).into(); - let gglwe_atk_layout: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let gglwe_atk_layout: AutomorphismKeyLayout = AutomorphismKeyLayout { n, base2k, k: k_gglwe,

@@ -62,12 +62,12 @@ k: k_glwe_out,

rank, }; - let mut ksk: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&gglwe_atk_layout); + let mut ksk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&gglwe_atk_layout); let mut ct_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_in_layout); let mut ct_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_layout); let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(&module, &gglwe_atk_layout) + GLWESwitchingKey::encrypt_sk_scratch_space(&module, &gglwe_atk_layout) | GLWECiphertext::encrypt_sk_scratch_space(&module, &glwe_in_layout) | GLWECiphertext::keyswitch_scratch_space( &module,

@@ -102,7 +102,7 @@ &mut source_xe,

scratch.borrow(), ); - let ksk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, _> = ksk.prepare_alloc(&module, scratch.borrow()); + let ksk_prepared: AutomorphismKeyPrepared<Vec<u8>, _> = ksk.prepare_alloc(&module, scratch.borrow()); move || { ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow());

@@ -157,7 +157,7 @@ let dsize: Dsize = Dsize(1);

let dnum: Dnum = p.k_ct.div_ceil(p.base2k).into(); - let gglwe_layout: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_layout: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n, base2k, k: k_ksk,

@@ -174,11 +174,11 @@ k: k_ct,

rank, }; - let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_layout); + let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_layout); let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_layout); let mut scratch: ScratchOwned<FFT64Spqlios> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(&module, &gglwe_layout) + GLWESwitchingKey::encrypt_sk_scratch_space(&module, &gglwe_layout) | GLWECiphertext::encrypt_sk_scratch_space(&module, &glwe_layout) | GLWECiphertext::keyswitch_inplace_scratch_space(&module, &glwe_layout, &gglwe_layout), );

@@ -211,7 +211,7 @@ &mut source_xe,

scratch.borrow(), ); - let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, FFT64Spqlios> = ksk.prepare_alloc(&module, scratch.borrow()); + let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, FFT64Spqlios> = ksk.prepare_alloc(&module, scratch.borrow()); move || { ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow());
M poulpy-core/src/automorphism/gglwe_atk.rs → poulpy-core/src/automorphism/gglwe_atk.rs

@@ -7,9 +7,9 @@ },

layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero}, }; -use crate::layouts::{GGLWEAutomorphismKey, GGLWEInfos, GLWECiphertext, prepared::GGLWEAutomorphismKeyPrepared}; +use crate::layouts::{AutomorphismKey, GGLWEInfos, GLWECiphertext, prepared::AutomorphismKeyPrepared}; -impl GGLWEAutomorphismKey<Vec<u8>> { +impl AutomorphismKey<Vec<u8>> { pub fn automorphism_scratch_space<B: Backend, OUT, IN, KEY>( module: &Module<B>, out_infos: &OUT,

@@ -36,16 +36,16 @@ OUT: GGLWEInfos,

KEY: GGLWEInfos, Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VecZnxNormalizeTmpBytes, { - GGLWEAutomorphismKey::automorphism_scratch_space(module, out_infos, out_infos, key_infos) + AutomorphismKey::automorphism_scratch_space(module, out_infos, out_infos, key_infos) } } -impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> { +impl<DataSelf: DataMut> AutomorphismKey<DataSelf> { pub fn automorphism<DataLhs: DataRef, DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGLWEAutomorphismKey<DataLhs>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + lhs: &AutomorphismKey<DataLhs>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -133,7 +133,7 @@

pub fn automorphism_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/automorphism/ggsw_ct.rs → poulpy-core/src/automorphism/ggsw_ct.rs

@@ -9,11 +9,11 @@ layouts::{Backend, DataMut, DataRef, Module, Scratch},

}; use crate::layouts::{ - GGLWEInfos, GGSWCiphertext, GGSWInfos, GLWECiphertext, - prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared}, + GGLWEInfos, GGSW, GGSWInfos, GLWECiphertext, + prepared::{AutomorphismKeyPrepared, TensorKeyPrepared}, }; -impl GGSWCiphertext<Vec<u8>> { +impl GGSW<Vec<u8>> { pub fn automorphism_scratch_space<B: Backend, OUT, IN, KEY, TSK>( module: &Module<B>, out_infos: &OUT,

@@ -40,7 +40,7 @@ &out_infos.glwe_layout(),

&in_infos.glwe_layout(), key_infos, ); - let expand: usize = GGSWCiphertext::expand_row_scratch_space(module, out_infos, tsk_infos); + let expand: usize = GGSW::expand_row_scratch_space(module, out_infos, tsk_infos); ci_dft + (ks_internal | expand) }

@@ -60,17 +60,17 @@ + VecZnxBigAllocBytes

+ VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes, { - GGSWCiphertext::automorphism_scratch_space(module, out_infos, out_infos, key_infos, tsk_infos) + GGSW::automorphism_scratch_space(module, out_infos, out_infos, key_infos, tsk_infos) } } -impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> { +impl<DataSelf: DataMut> GGSW<DataSelf> { pub fn automorphism<DataLhs: DataRef, DataAk: DataRef, DataTsk: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGSWCiphertext<DataLhs>, - auto_key: &GGLWEAutomorphismKeyPrepared<DataAk, B>, - tensor_key: &GGLWETensorKeyPrepared<DataTsk, B>, + lhs: &GGSW<DataLhs>, + auto_key: &AutomorphismKeyPrepared<DataAk, B>, + tensor_key: &TensorKeyPrepared<DataTsk, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -121,7 +121,7 @@ "ggsw_in rank: {} != tensor_key rank: {}",

self.rank(), tensor_key.rank_out() ); - assert!(scratch.available() >= GGSWCiphertext::automorphism_scratch_space(module, self, lhs, auto_key, tensor_key)) + assert!(scratch.available() >= GGSW::automorphism_scratch_space(module, self, lhs, auto_key, tensor_key)) }; // Keyswitch the j-th row of the col 0

@@ -137,8 +137,8 @@

pub fn automorphism_inplace<DataKsk: DataRef, DataTsk: DataRef, B: Backend>( &mut self, module: &Module<B>, - auto_key: &GGLWEAutomorphismKeyPrepared<DataKsk, B>, - tensor_key: &GGLWETensorKeyPrepared<DataTsk, B>, + auto_key: &AutomorphismKeyPrepared<DataKsk, B>, + tensor_key: &TensorKeyPrepared<DataTsk, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/automorphism/glwe_ct.rs → poulpy-core/src/automorphism/glwe_ct.rs

@@ -8,7 +8,7 @@ },

layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig}, }; -use crate::layouts::{GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, prepared::GGLWEAutomorphismKeyPrepared}; +use crate::layouts::{GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, prepared::AutomorphismKeyPrepared}; impl GLWECiphertext<Vec<u8>> { pub fn automorphism_scratch_space<B: Backend, OUT, IN, KEY>(

@@ -41,7 +41,7 @@ pub fn automorphism<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(

&mut self, module: &Module<B>, lhs: &GLWECiphertext<DataLhs>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -67,7 +67,7 @@

pub fn automorphism_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -94,7 +94,7 @@ pub fn automorphism_add<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(

&mut self, module: &Module<B>, lhs: &GLWECiphertext<DataLhs>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -135,7 +135,7 @@

pub fn automorphism_add_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -177,7 +177,7 @@ pub fn automorphism_sub_ab<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(

&mut self, module: &Module<B>, lhs: &GLWECiphertext<DataLhs>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -219,7 +219,7 @@

pub fn automorphism_sub_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -262,7 +262,7 @@ pub fn automorphism_sub_negate<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(

&mut self, module: &Module<B>, lhs: &GLWECiphertext<DataLhs>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -304,7 +304,7 @@

pub fn automorphism_sub_negate_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/encryption/compressed/gglwe_atk.rs → poulpy-core/src/encryption/compressed/gglwe_atk.rs

@@ -9,18 +9,19 @@ TakeGLWESecret,

encryption::compressed::gglwe_ksk::GGLWEKeyCompressedEncryptSk, layouts::{ GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, - compressed::{GGLWEAutomorphismKeyCompressed, GGLWEAutomorphismKeyCompressedToMut, GGLWEKeyCompressed}, + compressed::{AutomorphismKeyCompressed, AutomorphismKeyCompressedToMut, GLWESwitchingKeyCompressed}, }, }; -impl GGLWEAutomorphismKeyCompressed<Vec<u8>> { +impl AutomorphismKeyCompressed<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGLWEInfos, Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes, { assert_eq!(module.n() as u32, infos.n()); - GGLWEKeyCompressed::encrypt_sk_scratch_space(module, infos) + GLWESecret::alloc_bytes_with(infos.n(), infos.rank_out()) + GLWESwitchingKeyCompressed::encrypt_sk_scratch_space(module, infos) + + GLWESecret::alloc_bytes_with(infos.n(), infos.rank_out()) } }

@@ -34,7 +35,7 @@ seed_xa: [u8; 32],

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGLWEAutomorphismKeyCompressedToMut, + R: AutomorphismKeyCompressedToMut, S: GLWESecretToRef; }

@@ -53,10 +54,10 @@ seed_xa: [u8; 32],

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGLWEAutomorphismKeyCompressedToMut, + R: AutomorphismKeyCompressedToMut, S: GLWESecretToRef, { - let res: &mut GGLWEAutomorphismKeyCompressed<&mut [u8]> = &mut res.to_mut(); + let res: &mut AutomorphismKeyCompressed<&mut [u8]> = &mut res.to_mut(); let sk: &GLWESecret<&[u8]> = &sk.to_ref(); #[cfg(debug_assertions)]

@@ -65,10 +66,10 @@ assert_eq!(res.n(), sk.n());

assert_eq!(res.rank_out(), res.rank_in()); assert_eq!(sk.rank(), res.rank_out()); assert!( - scratch.available() >= GGLWEAutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res), + scratch.available() >= AutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res), "scratch.available(): {} < AutomorphismKey::encrypt_sk_scratch_space: {}", scratch.available(), - GGLWEAutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res) + AutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res) ) }

@@ -92,7 +93,7 @@ res.p = p;

} } -impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> { +impl<DataSelf: DataMut> AutomorphismKeyCompressed<DataSelf> { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSk: DataRef, B: Backend>( &mut self,
M poulpy-core/src/encryption/compressed/gglwe_ct.rs → poulpy-core/src/encryption/compressed/gglwe_ct.rs

@@ -11,7 +11,7 @@ use crate::{

TakeGLWEPt, encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal}, layouts::{ - GGLWECiphertext, GGLWEInfos, LWEInfos, + GGLWE, GGLWEInfos, LWEInfos, compressed::{GGLWECiphertextCompressed, GGLWECiphertextCompressedToMut}, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, },

@@ -40,7 +40,7 @@ where

A: GGLWEInfos, Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { - GGLWECiphertext::encrypt_sk_scratch_space(module, infos) + GGLWE::encrypt_sk_scratch_space(module, infos) } }
M poulpy-core/src/encryption/compressed/gglwe_ksk.rs → poulpy-core/src/encryption/compressed/gglwe_ksk.rs

@@ -11,25 +11,25 @@ use crate::{

TakeGLWESecretPrepared, encryption::compressed::gglwe_ct::GGLWECompressedEncryptSk, layouts::{ - Degree, GGLWECiphertext, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, - compressed::{GGLWEKeyCompressed, GGLWEKeyCompressedToMut}, + Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, + compressed::{GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedToMut}, prepared::GLWESecretPrepared, }, }; -impl GGLWEKeyCompressed<Vec<u8>> { +impl GLWESwitchingKeyCompressed<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGLWEInfos, Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes, { - (GGLWECiphertext::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1)) + (GGLWE::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1)) + ScalarZnx::alloc_bytes(module.n(), infos.rank_in().into()) + GLWESecretPrepared::alloc_bytes_with(module, infos.rank_out()) } } -impl<DataSelf: DataMut> GGLWEKeyCompressed<DataSelf> { +impl<DataSelf: DataMut> GLWESwitchingKeyCompressed<DataSelf> { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>( &mut self,

@@ -56,7 +56,7 @@ seed_xa: [u8; 32],

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGLWEKeyCompressedToMut, + R: GLWESwitchingKeyCompressedToMut, SI: GLWESecretToRef, SO: GLWESecretToRef; }

@@ -80,25 +80,25 @@ seed_xa: [u8; 32],

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGLWEKeyCompressedToMut, + R: GLWESwitchingKeyCompressedToMut, SI: GLWESecretToRef, SO: GLWESecretToRef, { - let res: &mut GGLWEKeyCompressed<&mut [u8]> = &mut res.to_mut(); + let res: &mut GLWESwitchingKeyCompressed<&mut [u8]> = &mut res.to_mut(); let sk_in: &GLWESecret<&[u8]> = &sk_in.to_ref(); let sk_out: &GLWESecret<&[u8]> = &sk_out.to_ref(); #[cfg(debug_assertions)] { - use crate::layouts::GGLWESwitchingKey; + use crate::layouts::GLWESwitchingKey; assert!(sk_in.n().0 <= self.n() as u32); assert!(sk_out.n().0 <= self.n() as u32); assert!( - scratch.available() >= GGLWESwitchingKey::encrypt_sk_scratch_space(self, res), + scratch.available() >= GLWESwitchingKey::encrypt_sk_scratch_space(self, res), "scratch.available()={} < GLWESwitchingKey::encrypt_sk_scratch_space={}", scratch.available(), - GGLWESwitchingKey::encrypt_sk_scratch_space(self, res) + GLWESwitchingKey::encrypt_sk_scratch_space(self, res) ) }
M poulpy-core/src/encryption/compressed/gglwe_tsk.rs → poulpy-core/src/encryption/compressed/gglwe_tsk.rs

@@ -11,20 +11,19 @@ use crate::{

TakeGLWESecret, TakeGLWESecretPrepared, encryption::compressed::gglwe_ksk::GGLWEKeyCompressedEncryptSk, layouts::{ - GGLWEInfos, GGLWETensorKey, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, - compressed::{GGLWETensorKeyCompressed, GGLWETensorKeyCompressedToMut}, - prepared::Prepare, + GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey, + compressed::{TensorKeyCompressed, TensorKeyCompressedToMut}, }, }; -impl GGLWETensorKeyCompressed<Vec<u8>> { +impl TensorKeyCompressed<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGLWEInfos, Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigAllocBytes, { - GGLWETensorKey::encrypt_sk_scratch_space(module, infos) + TensorKey::encrypt_sk_scratch_space(module, infos) } }

@@ -37,7 +36,7 @@ seed_xa: [u8; 32],

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGLWETensorKeyCompressedToMut, + R: TensorKeyCompressedToMut, S: GLWESecretToRef; }

@@ -59,10 +58,10 @@ seed_xa: [u8; 32],

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGLWETensorKeyCompressedToMut, + R: TensorKeyCompressedToMut, S: GLWESecretToRef, { - let res: &mut GGLWETensorKeyCompressed<&mut [u8]> = &mut res.to_mut(); + let res: &mut TensorKeyCompressed<&mut [u8]> = &mut res.to_mut(); let sk: &GLWESecret<&[u8]> = &sk.to_ref(); #[cfg(debug_assertions)]

@@ -119,7 +118,7 @@ }

} } -impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> { +impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> { pub fn encrypt_sk<DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,
M poulpy-core/src/encryption/compressed/ggsw_ct.rs → poulpy-core/src/encryption/compressed/ggsw_ct.rs

@@ -8,7 +8,7 @@ use crate::{

TakeGLWEPt, encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal}, layouts::{ - GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, + GGSW, GGSWInfos, GLWEInfos, LWEInfos, compressed::{GGSWCiphertextCompressed, GGSWCiphertextCompressedToMut}, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, },

@@ -20,7 +20,7 @@ where

A: GGSWInfos, Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { - GGSWCiphertext::encrypt_sk_scratch_space(module, infos) + GGSW::encrypt_sk_scratch_space(module, infos) } }
M poulpy-core/src/encryption/compressed/glwe_ct.rs → poulpy-core/src/encryption/compressed/glwe_ct.rs

@@ -1,17 +1,15 @@

use poulpy_hal::{ - api::{ - ScratchAvailable, SvpApplyDftToDftInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, - VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftApply, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, - VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, - }, + api::{VecZnxDftAllocBytes, VecZnxNormalizeTmpBytes}, layouts::{Backend, DataMut, DataRef, Module, Scratch}, source::Source, }; use crate::{ - encryption::{SIGMA, glwe_ct::glwe_encrypt_sk_internal}, + encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal}, layouts::{ - GLWECiphertext, GLWEInfos, GLWEPlaintext, LWEInfos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared, + GLWECiphertext, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, LWEInfos, + compressed::{GLWECiphertextCompressed, GLWECiphertextCompressedToMut}, + prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, }, };

@@ -25,76 +23,73 @@ GLWECiphertext::encrypt_sk_scratch_space(module, infos)

} } -impl<D: DataMut> GLWECiphertextCompressed<D> { - #[allow(clippy::too_many_arguments)] - pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( - &mut self, - module: &Module<B>, - pt: &GLWEPlaintext<DataPt>, - sk: &GLWESecretPrepared<DataSk, B>, +pub trait GLWECompressedEncryptSk<B: Backend> { + fn glwe_compressed_encrypt_sk<R, P, S>( + &self, + res: &mut R, + pt: &P, + sk: &S, seed_xa: [u8; 32], source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - Module<B>: VecZnxDftAllocBytes - + VecZnxBigNormalize<B> - + VecZnxDftApply<B> - + SvpApplyDftToDftInplace<B> - + VecZnxIdftApplyConsume<B> - + VecZnxNormalizeTmpBytes - + VecZnxFillUniform - + VecZnxSubInplace - + VecZnxAddInplace - + VecZnxNormalizeInplace<B> - + VecZnxAddNormal - + VecZnxNormalize<B> - + VecZnxSub, - Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx, - { - self.encrypt_sk_internal(module, Some((pt, 0)), sk, seed_xa, source_xe, scratch); - } + R: GLWECiphertextCompressedToMut, + P: GLWEPlaintextToRef, + S: GLWESecretPreparedToRef<B>; +} - #[allow(clippy::too_many_arguments)] - pub(crate) fn encrypt_sk_internal<DataPt: DataRef, DataSk: DataRef, B: Backend>( - &mut self, - module: &Module<B>, - pt: Option<(&GLWEPlaintext<DataPt>, usize)>, - sk: &GLWESecretPrepared<DataSk, B>, +impl<B: Backend> GLWECompressedEncryptSk<B> for Module<B> +where + Module<B>: GLWEEncryptSkInternal<B>, +{ + fn glwe_compressed_encrypt_sk<R, P, S>( + &self, + res: &mut R, + pt: &P, + sk: &S, seed_xa: [u8; 32], source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - Module<B>: VecZnxDftAllocBytes - + VecZnxBigNormalize<B> - + VecZnxDftApply<B> - + SvpApplyDftToDftInplace<B> - + VecZnxIdftApplyConsume<B> - + VecZnxNormalizeTmpBytes - + VecZnxFillUniform - + VecZnxSubInplace - + VecZnxAddInplace - + VecZnxNormalizeInplace<B> - + VecZnxAddNormal - + VecZnxNormalize<B> - + VecZnxSub, - Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx, + R: GLWECiphertextCompressedToMut, + P: GLWEPlaintextToRef, + S: GLWESecretPreparedToRef<B>, { - let mut source_xa = Source::new(seed_xa); - let cols: usize = (self.rank() + 1).into(); - glwe_encrypt_sk_internal( - module, - self.base2k().into(), - self.k().into(), - &mut self.data, + let res: &mut GLWECiphertextCompressed<&mut [u8]> = &mut res.to_mut(); + let mut source_xa: Source = Source::new(seed_xa); + let cols: usize = (res.rank() + 1).into(); + + self.glwe_encrypt_sk_internal( + res.base2k().into(), + res.k().into(), + &mut res.data, cols, true, - pt, + Some((pt, 0)), sk, &mut source_xa, source_xe, SIGMA, scratch, ); - self.seed = seed_xa; + + res.seed = seed_xa; + } +} + +impl<D: DataMut> GLWECiphertextCompressed<D> { + #[allow(clippy::too_many_arguments)] + pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( + &mut self, + module: &Module<B>, + pt: &GLWEPlaintext<DataPt>, + sk: &GLWESecretPrepared<DataSk, B>, + seed_xa: [u8; 32], + source_xe: &mut Source, + scratch: &mut Scratch<B>, + ) where + Module<B>: GLWECompressedEncryptSk<B>, + { + module.glwe_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch); } }
M poulpy-core/src/encryption/gglwe_atk.rs → poulpy-core/src/encryption/gglwe_atk.rs

@@ -12,12 +12,11 @@

use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, layouts::{ - GGLWEAutomorphismKey, GGLWEAutomorphismKeyToMut, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, GLWESecret, GLWESecretToRef, - LWEInfos, + AutomorphismKey, AutomorphismKeyToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, LWEInfos, }, }; -impl GGLWEAutomorphismKey<Vec<u8>> { +impl AutomorphismKey<Vec<u8>> { pub fn encrypt_sk_scratch_space<BE: Backend, A>(module: &Module<BE>, infos: &A) -> usize where A: GGLWEInfos,

@@ -28,7 +27,7 @@ infos.rank_in(),

infos.rank_out(), "rank_in != rank_out is not supported for GGLWEAutomorphismKey" ); - GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESecret::alloc_bytes(&infos.glwe_layout()) + GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESecret::alloc_bytes(&infos.glwe_layout()) } pub fn encrypt_pk_scratch_space<BE: Backend, A>(module: &Module<BE>, _infos: &A) -> usize

@@ -40,7 +39,7 @@ _infos.rank_in(),

_infos.rank_out(), "rank_in != rank_out is not supported for GGLWEAutomorphismKey" ); - GGLWESwitchingKey::encrypt_pk_scratch_space(module, _infos) + GLWESwitchingKey::encrypt_pk_scratch_space(module, _infos) } }

@@ -54,13 +53,13 @@ source_xa: &mut Source,

source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - A: GGLWEAutomorphismKeyToMut, + A: AutomorphismKeyToMut, B: GLWESecretToRef; } -impl<DM: DataMut> GGLWEAutomorphismKey<DM> +impl<DM: DataMut> AutomorphismKey<DM> where - Self: GGLWEAutomorphismKeyToMut, + Self: AutomorphismKeyToMut, { pub fn encrypt_sk<S, BE: Backend>( &mut self,

@@ -109,10 +108,10 @@ source_xa: &mut Source,

source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - A: GGLWEAutomorphismKeyToMut, + A: AutomorphismKeyToMut, B: GLWESecretToRef, { - let res: &mut GGLWEAutomorphismKey<&mut [u8]> = &mut res.to_mut(); + let res: &mut AutomorphismKey<&mut [u8]> = &mut res.to_mut(); let sk: &GLWESecret<&[u8]> = &sk.to_ref(); #[cfg(debug_assertions)]

@@ -123,10 +122,10 @@ assert_eq!(res.n(), sk.n());

assert_eq!(res.rank_out(), res.rank_in()); assert_eq!(sk.rank(), res.rank_out()); assert!( - scratch.available() >= GGLWEAutomorphismKey::encrypt_sk_scratch_space(self, res), + scratch.available() >= AutomorphismKey::encrypt_sk_scratch_space(self, res), "scratch.available(): {} < AutomorphismKey::encrypt_sk_scratch_space: {:?}", scratch.available(), - GGLWEAutomorphismKey::encrypt_sk_scratch_space(self, res) + AutomorphismKey::encrypt_sk_scratch_space(self, res) ) }
M poulpy-core/src/encryption/gglwe_ct.rs → poulpy-core/src/encryption/gglwe_ct.rs

@@ -11,12 +11,12 @@ use crate::{

TakeGLWEPt, encryption::glwe_ct::GLWEEncryptSk, layouts::{ - GGLWECiphertext, GGLWECiphertextToMut, GGLWEInfos, GLWECiphertext, GLWEPlaintext, LWEInfos, + GGLWE, GGLWECiphertextToMut, GGLWEInfos, GLWECiphertext, GLWEPlaintext, LWEInfos, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, }, }; -impl GGLWECiphertext<Vec<u8>> { +impl GGLWE<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGLWEInfos,

@@ -68,7 +68,7 @@ R: GGLWECiphertextToMut,

P: ScalarZnxToRef, S: GLWESecretPreparedToRef<B>, { - let res: &mut GGLWECiphertext<&mut [u8]> = &mut res.to_mut(); + let res: &mut GGLWE<&mut [u8]> = &mut res.to_mut(); let pt: &ScalarZnx<&[u8]> = &pt.to_ref(); #[cfg(debug_assertions)]

@@ -93,12 +93,12 @@ );

assert_eq!(res.n(), sk.n()); assert_eq!(pt.n() as u32, sk.n()); assert!( - scratch.available() >= GGLWECiphertext::encrypt_sk_scratch_space(self, res), + scratch.available() >= GGLWE::encrypt_sk_scratch_space(self, res), "scratch.available: {} < GGLWECiphertext::encrypt_sk_scratch_space(self, res.rank()={}, res.size()={}): {}", scratch.available(), res.rank_out(), res.size(), - GGLWECiphertext::encrypt_sk_scratch_space(self, res) + GGLWE::encrypt_sk_scratch_space(self, res) ); assert!( res.dnum().0 * res.dsize().0 * res.base2k().0 <= res.k().0,

@@ -148,7 +148,7 @@ }

} } -impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> { +impl<DataSelf: DataMut> GGLWE<DataSelf> { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self,
M poulpy-core/src/encryption/gglwe_ksk.rs → poulpy-core/src/encryption/gglwe_ksk.rs

@@ -11,18 +11,16 @@ };

use crate::{ TakeGLWESecretPrepared, - layouts::{ - Degree, GGLWECiphertext, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, GLWESecret, LWEInfos, prepared::GLWESecretPrepared, - }, + layouts::{Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, prepared::GLWESecretPrepared}, }; -impl GGLWESwitchingKey<Vec<u8>> { +impl GLWESwitchingKey<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGLWEInfos, Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { - (GGLWECiphertext::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1)) + (GGLWE::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1)) + ScalarZnx::alloc_bytes(module.n(), infos.rank_in().into()) + GLWESecretPrepared::alloc_bytes(module, &infos.glwe_layout()) }

@@ -31,11 +29,11 @@ pub fn encrypt_pk_scratch_space<B: Backend, A>(module: &Module<B>, _infos: &A) -> usize

where A: GGLWEInfos, { - GGLWECiphertext::encrypt_pk_scratch_space(module, _infos) + GGLWE::encrypt_pk_scratch_space(module, _infos) } } -impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> { +impl<DataSelf: DataMut> GLWESwitchingKey<DataSelf> { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>( &mut self,

@@ -70,10 +68,10 @@ {

assert!(sk_in.n().0 <= module.n() as u32); assert!(sk_out.n().0 <= module.n() as u32); assert!( - scratch.available() >= GGLWESwitchingKey::encrypt_sk_scratch_space(module, self), + scratch.available() >= GLWESwitchingKey::encrypt_sk_scratch_space(module, self), "scratch.available()={} < GLWESwitchingKey::encrypt_sk_scratch_space={}", scratch.available(), - GGLWESwitchingKey::encrypt_sk_scratch_space(module, self) + GLWESwitchingKey::encrypt_sk_scratch_space(module, self) ) }
M poulpy-core/src/encryption/gglwe_tsk.rs → poulpy-core/src/encryption/gglwe_tsk.rs

@@ -12,12 +12,11 @@

use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, layouts::{ - Degree, GGLWEInfos, GGLWESwitchingKey, GGLWETensorKey, GLWEInfos, GLWESecret, LWEInfos, Rank, - prepared::{GLWESecretPrepared, Prepare}, + Degree, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, TensorKey, prepared::GLWESecretPrepared, }, }; -impl GGLWETensorKey<Vec<u8>> { +impl TensorKey<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGLWEInfos,

@@ -29,11 +28,11 @@ + module.vec_znx_dft_alloc_bytes(infos.rank_out().into(), 1)

+ module.vec_znx_big_alloc_bytes(1, 1) + module.vec_znx_dft_alloc_bytes(1, 1) + GLWESecret::alloc_bytes_with(Degree(module.n() as u32), Rank(1)) - + GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + + GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) } } -impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> { +impl<DataSelf: DataMut> TensorKey<DataSelf> { pub fn encrypt_sk<DataSk: DataRef, B: Backend>( &mut self, module: &Module<B>,
M poulpy-core/src/encryption/ggsw_ct.rs → poulpy-core/src/encryption/ggsw_ct.rs

@@ -8,12 +8,12 @@ use crate::{

SIGMA, TakeGLWEPt, encryption::glwe_ct::GLWEEncryptSkInternal, layouts::{ - GGSWCiphertext, GGSWCiphertextToMut, GGSWInfos, GLWECiphertext, GLWEInfos, LWEInfos, + GGSW, GGSWInfos, GGSWToMut, GLWECiphertext, GLWEInfos, LWEInfos, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, }, }; -impl GGSWCiphertext<Vec<u8>> { +impl GGSW<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGSWInfos,

@@ -37,7 +37,7 @@ source_xa: &mut Source,

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGSWCiphertextToMut, + R: GGSWToMut, P: ScalarZnxToRef, S: GLWESecretPreparedToRef<B>; }

@@ -56,11 +56,11 @@ source_xa: &mut Source,

source_xe: &mut Source, scratch: &mut Scratch<B>, ) where - R: GGSWCiphertextToMut, + R: GGSWToMut, P: ScalarZnxToRef, S: GLWESecretPreparedToRef<B>, { - let res: &mut GGSWCiphertext<&mut [u8]> = &mut res.to_mut(); + let res: &mut GGSW<&mut [u8]> = &mut res.to_mut(); let pt: &ScalarZnx<&[u8]> = &pt.to_ref(); let sk: &GLWESecretPrepared<&[u8], B> = &sk.to_ref();

@@ -106,7 +106,7 @@ }

} } -impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> { +impl<DataSelf: DataMut> GGSW<DataSelf> { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>( &mut self,
M poulpy-core/src/encryption/glwe_to_lwe_ksk.rs → poulpy-core/src/encryption/glwe_to_lwe_ksk.rs

@@ -11,22 +11,24 @@ };

use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{GGLWEInfos, GGLWESwitchingKey, GLWESecret, GLWEToLWEKey, LWEInfos, LWESecret, Rank, prepared::GLWESecretPrepared}, + layouts::{ + GGLWEInfos, GLWESecret, GLWESwitchingKey, GLWEToLWESwitchingKey, LWEInfos, LWESecret, Rank, prepared::GLWESecretPrepared, + }, }; -impl GLWEToLWEKey<Vec<u8>> { +impl GLWEToLWESwitchingKey<Vec<u8>> { pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize where A: GGLWEInfos, Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { GLWESecretPrepared::alloc_bytes_with(module, infos.rank_in()) - + (GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + + (GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) | GLWESecret::alloc_bytes_with(infos.n(), infos.rank_in())) } } -impl<D: DataMut> GLWEToLWEKey<D> { +impl<D: DataMut> GLWEToLWESwitchingKey<D> { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<DLwe, DGlwe, B: Backend>( &mut self,
M poulpy-core/src/encryption/lwe_ksk.rs → poulpy-core/src/encryption/lwe_ksk.rs

@@ -12,7 +12,7 @@

use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, layouts::{ - Degree, GGLWEInfos, GGLWESwitchingKey, GLWESecret, LWEInfos, LWESecret, LWESwitchingKey, Rank, + Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank, prepared::GLWESecretPrepared, }, };

@@ -40,7 +40,7 @@ "rank_out > 1 is not supported for LWESwitchingKey"

); GLWESecret::alloc_bytes_with(Degree(module.n() as u32), Rank(1)) + GLWESecretPrepared::alloc_bytes_with(module, Rank(1)) - + GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + + GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) } }
M poulpy-core/src/encryption/lwe_to_glwe_ksk.rs → poulpy-core/src/encryption/lwe_to_glwe_ksk.rs

@@ -11,7 +11,7 @@ };

use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{Degree, GGLWEInfos, GGLWESwitchingKey, GLWESecret, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank}, + layouts::{Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank}, }; impl LWEToGLWESwitchingKey<Vec<u8>> {

@@ -25,7 +25,7 @@ infos.rank_in(),

Rank(1), "rank_in != 1 is not supported for LWEToGLWESwitchingKey" ); - GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESecret::alloc_bytes_with(Degree(module.n() as u32), infos.rank_in()) } }
M poulpy-core/src/external_product/gglwe_atk.rs → poulpy-core/src/external_product/gglwe_atk.rs

@@ -7,9 +7,9 @@ },

layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::layouts::{GGLWEAutomorphismKey, GGLWEInfos, GGLWESwitchingKey, GGSWInfos, prepared::GGSWCiphertextPrepared}; +use crate::layouts::{AutomorphismKey, GGLWEInfos, GGSWInfos, GLWESwitchingKey, prepared::GGSWPrepared}; -impl GGLWEAutomorphismKey<Vec<u8>> { +impl AutomorphismKey<Vec<u8>> { pub fn external_product_scratch_space<B: Backend, OUT, IN, GGSW>( module: &Module<B>, out_infos: &OUT,

@@ -22,7 +22,7 @@ IN: GGLWEInfos,

GGSW: GGSWInfos, Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes, { - GGLWESwitchingKey::external_product_scratch_space(module, out_infos, in_infos, ggsw_infos) + GLWESwitchingKey::external_product_scratch_space(module, out_infos, in_infos, ggsw_infos) } pub fn external_product_inplace_scratch_space<B: Backend, OUT, GGSW>(

@@ -35,16 +35,16 @@ OUT: GGLWEInfos,

GGSW: GGSWInfos, Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes, { - GGLWESwitchingKey::external_product_inplace_scratch_space(module, out_infos, ggsw_infos) + GLWESwitchingKey::external_product_inplace_scratch_space(module, out_infos, ggsw_infos) } } -impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> { +impl<DataSelf: DataMut> AutomorphismKey<DataSelf> { pub fn external_product<DataLhs: DataRef, DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGLWEAutomorphismKey<DataLhs>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + lhs: &AutomorphismKey<DataLhs>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -64,7 +64,7 @@

pub fn external_product_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/external_product/gglwe_ksk.rs → poulpy-core/src/external_product/gglwe_ksk.rs

@@ -7,9 +7,9 @@ },

layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero}, }; -use crate::layouts::{GGLWEInfos, GGLWESwitchingKey, GGSWInfos, GLWECiphertext, prepared::GGSWCiphertextPrepared}; +use crate::layouts::{GGLWEInfos, GGSWInfos, GLWECiphertext, GLWESwitchingKey, prepared::GGSWPrepared}; -impl GGLWESwitchingKey<Vec<u8>> { +impl GLWESwitchingKey<Vec<u8>> { pub fn external_product_scratch_space<B: Backend, OUT, IN, GGSW>( module: &Module<B>, out_infos: &OUT,

@@ -44,12 +44,12 @@ GLWECiphertext::external_product_inplace_scratch_space(module, &out_infos.glwe_layout(), ggsw_infos)

} } -impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> { +impl<DataSelf: DataMut> GLWESwitchingKey<DataSelf> { pub fn external_product<DataLhs: DataRef, DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGLWESwitchingKey<DataLhs>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + lhs: &GLWESwitchingKey<DataLhs>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -107,7 +107,7 @@

pub fn external_product_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/external_product/ggsw_ct.rs → poulpy-core/src/external_product/ggsw_ct.rs

@@ -7,9 +7,9 @@ },

layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero}, }; -use crate::layouts::{GGSWCiphertext, GGSWInfos, GLWECiphertext, GLWEInfos, prepared::GGSWCiphertextPrepared}; +use crate::layouts::{GGSW, GGSWInfos, GLWECiphertext, GLWEInfos, prepared::GGSWPrepared}; -impl GGSWCiphertext<Vec<u8>> { +impl GGSW<Vec<u8>> { #[allow(clippy::too_many_arguments)] pub fn external_product_scratch_space<B: Backend, OUT, IN, GGSW>( module: &Module<B>,

@@ -45,12 +45,12 @@ GLWECiphertext::external_product_inplace_scratch_space(module, &out_infos.glwe_layout(), apply_infos)

} } -impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> { +impl<DataSelf: DataMut> GGSW<DataSelf> { pub fn external_product<DataLhs: DataRef, DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGSWCiphertext<DataLhs>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + lhs: &GGSW<DataLhs>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -86,7 +86,7 @@ self.rank(),

rhs.rank() ); - assert!(scratch.available() >= GGSWCiphertext::external_product_scratch_space(module, self, lhs, rhs)) + assert!(scratch.available() >= GGSW::external_product_scratch_space(module, self, lhs, rhs)) } let min_dnum: usize = self.dnum().min(lhs.dnum()).into();

@@ -105,7 +105,7 @@

pub fn external_product_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/external_product/glwe_ct.rs → poulpy-core/src/external_product/glwe_ct.rs

@@ -11,7 +11,7 @@ use crate::{

GLWEExternalProduct, GLWEExternalProductInplace, layouts::{ GGSWInfos, GLWECiphertext, GLWECiphertextToMut, GLWECiphertextToRef, GLWEInfos, LWEInfos, - prepared::{GGSWCiphertextPrepared, GGSWCiphertextPreparedToRef}, + prepared::{GGSWCiphertextPreparedToRef, GGSWPrepared}, }, };

@@ -74,7 +74,7 @@ pub fn external_product<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(

&mut self, module: &Module<B>, lhs: &GLWECiphertext<DataLhs>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: GLWEExternalProduct<B>,

@@ -85,7 +85,7 @@

pub fn external_product_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGSWCiphertextPrepared<DataRhs, B>, + rhs: &GGSWPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: GLWEExternalProductInplace<B>,

@@ -113,7 +113,7 @@ R: GLWECiphertextToMut,

D: GGSWCiphertextPreparedToRef<BE>, { let res: &mut GLWECiphertext<&mut [u8]> = &mut res.to_mut(); - let rhs: &GGSWCiphertextPrepared<&[u8], BE> = &ggsw.to_ref(); + let rhs: &GGSWPrepared<&[u8], BE> = &ggsw.to_ref(); let basek_in: usize = res.base2k().into(); let basek_ggsw: usize = rhs.base2k().into();

@@ -237,7 +237,7 @@ {

let res: &mut GLWECiphertext<&mut [u8]> = &mut res.to_mut(); let lhs: &GLWECiphertext<&[u8]> = &lhs.to_ref(); - let rhs: &GGSWCiphertextPrepared<&[u8], BE> = &rhs.to_ref(); + let rhs: &GGSWPrepared<&[u8], BE> = &rhs.to_ref(); let basek_in: usize = lhs.base2k().into(); let basek_ggsw: usize = rhs.base2k().into();
M poulpy-core/src/glwe_packing.rs → poulpy-core/src/glwe_packing.rs

@@ -13,7 +13,7 @@ };

use crate::{ GLWEOperations, TakeGLWECt, - layouts::{GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, prepared::GGLWEAutomorphismKeyPrepared}, + layouts::{GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, prepared::AutomorphismKeyPrepared}, }; /// [GLWEPacker] enables only the fly GLWE packing

@@ -116,7 +116,7 @@ pub fn add<DataA: DataRef, DataAK: DataRef, B: Backend>(

&mut self, module: &Module<B>, a: Option<&GLWECiphertext<DataA>>, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<DataAK, B>>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -191,7 +191,7 @@ module: &Module<B>,

a: Option<&GLWECiphertext<D>>, accumulators: &mut [Accumulator], i: usize, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<DataAK, B>>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -285,7 +285,7 @@ module: &Module<B>,

acc: &mut Accumulator, b: Option<&GLWECiphertext<D>>, i: usize, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<DataAK, B>>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -397,7 +397,7 @@ pub fn glwe_packing<D: DataMut, ATK, B: Backend>(

module: &Module<B>, cts: &mut HashMap<usize, &mut GLWECiphertext<D>>, log_gap_out: usize, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<ATK, B>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<ATK, B>>, scratch: &mut Scratch<B>, ) where ATK: DataRef,

@@ -439,7 +439,7 @@

(0..log_n - log_gap_out).for_each(|i| { let t: usize = (1 << log_n).min(1 << (log_n - 1 - i)); - let auto_key: &GGLWEAutomorphismKeyPrepared<ATK, B> = if i == 0 { + let auto_key: &AutomorphismKeyPrepared<ATK, B> = if i == 0 { auto_keys.get(&-1).unwrap() } else { auto_keys.get(&module.galois_element(1 << (i - 1))).unwrap()

@@ -466,7 +466,7 @@ module: &Module<B>,

a: &mut Option<&mut GLWECiphertext<A>>, b: &mut Option<&mut GLWECiphertext<D>>, i: usize, - auto_key: &GGLWEAutomorphismKeyPrepared<DataAK, B>, + auto_key: &AutomorphismKeyPrepared<DataAK, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxRotateInplace<B>
M poulpy-core/src/glwe_trace.rs → poulpy-core/src/glwe_trace.rs

@@ -11,9 +11,7 @@ };

use crate::{ TakeGLWECt, - layouts::{ - Base2K, GGLWEInfos, GLWECiphertext, GLWECiphertextLayout, GLWEInfos, LWEInfos, prepared::GGLWEAutomorphismKeyPrepared, - }, + layouts::{Base2K, GGLWEInfos, GLWECiphertext, GLWECiphertextLayout, GLWEInfos, LWEInfos, prepared::AutomorphismKeyPrepared}, operations::GLWEOperations, };

@@ -72,7 +70,7 @@ module: &Module<B>,

start: usize, end: usize, lhs: &GLWECiphertext<DataLhs>, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<DataAK, B>>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -100,7 +98,7 @@ &mut self,

module: &Module<B>, start: usize, end: usize, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<DataAK, B>>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/keyswitching/gglwe_ct.rs → poulpy-core/src/keyswitching/gglwe_ct.rs

@@ -8,11 +8,11 @@ layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero},

}; use crate::layouts::{ - GGLWEAutomorphismKey, GGLWEInfos, GGLWESwitchingKey, GLWECiphertext, GLWEInfos, - prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared}, + AutomorphismKey, GGLWEInfos, GLWECiphertext, GLWEInfos, GLWESwitchingKey, + prepared::{AutomorphismKeyPrepared, GLWESwitchingKeyPrepared}, }; -impl GGLWEAutomorphismKey<Vec<u8>> { +impl AutomorphismKey<Vec<u8>> { pub fn keyswitch_scratch_space<B: Backend, OUT, IN, KEY>( module: &Module<B>, out_infos: &OUT,

@@ -25,7 +25,7 @@ IN: GGLWEInfos,

KEY: GGLWEInfos, Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VecZnxNormalizeTmpBytes, { - GGLWESwitchingKey::keyswitch_scratch_space(module, out_infos, in_infos, key_infos) + GLWESwitchingKey::keyswitch_scratch_space(module, out_infos, in_infos, key_infos) } pub fn keyswitch_inplace_scratch_space<B: Backend, OUT, KEY>(module: &Module<B>, out_infos: &OUT, key_infos: &KEY) -> usize

@@ -34,16 +34,16 @@ OUT: GGLWEInfos,

KEY: GGLWEInfos, Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VecZnxNormalizeTmpBytes, { - GGLWESwitchingKey::keyswitch_inplace_scratch_space(module, out_infos, key_infos) + GLWESwitchingKey::keyswitch_inplace_scratch_space(module, out_infos, key_infos) } } -impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> { +impl<DataSelf: DataMut> AutomorphismKey<DataSelf> { pub fn keyswitch<DataLhs: DataRef, DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGLWEAutomorphismKey<DataLhs>, - rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>, + lhs: &AutomorphismKey<DataLhs>, + rhs: &GLWESwitchingKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -65,7 +65,7 @@

pub fn keyswitch_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>, + rhs: &AutomorphismKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -85,7 +85,7 @@ self.key.keyswitch_inplace(module, &rhs.key, scratch);

} } -impl GGLWESwitchingKey<Vec<u8>> { +impl GLWESwitchingKey<Vec<u8>> { pub fn keyswitch_scratch_space<B: Backend, OUT, IN, KEY>( module: &Module<B>, out_infos: &OUT,

@@ -111,12 +111,12 @@ GLWECiphertext::keyswitch_inplace_scratch_space(module, out_infos, key_apply)

} } -impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> { +impl<DataSelf: DataMut> GLWESwitchingKey<DataSelf> { pub fn keyswitch<DataLhs: DataRef, DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGLWESwitchingKey<DataLhs>, - rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>, + lhs: &GLWESwitchingKey<DataLhs>, + rhs: &GLWESwitchingKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -187,7 +187,7 @@

pub fn keyswitch_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>, + rhs: &GLWESwitchingKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes
M poulpy-core/src/keyswitching/ggsw_ct.rs → poulpy-core/src/keyswitching/ggsw_ct.rs

@@ -10,13 +10,13 @@ };

use crate::{ layouts::{ - GGLWECiphertext, GGLWEInfos, GGSWCiphertext, GGSWInfos, GLWECiphertext, GLWEInfos, LWEInfos, - prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared}, + GGLWE, GGLWEInfos, GGSW, GGSWInfos, GLWECiphertext, GLWEInfos, LWEInfos, + prepared::{GLWESwitchingKeyPrepared, TensorKeyPrepared}, }, operations::GLWEOperations, }; -impl GGSWCiphertext<Vec<u8>> { +impl GGSW<Vec<u8>> { pub(crate) fn expand_row_scratch_space<B: Backend, OUT, TSK>(module: &Module<B>, out_infos: &OUT, tsk_infos: &TSK) -> usize where OUT: GGSWInfos,

@@ -77,7 +77,7 @@ let size_out: usize = out_infos.k().div_ceil(out_infos.base2k()) as usize;

let res_znx: usize = VecZnx::alloc_bytes(module.n(), rank + 1, size_out); let ci_dft: usize = module.vec_znx_dft_alloc_bytes(rank + 1, size_out); let ks: usize = GLWECiphertext::keyswitch_scratch_space(module, out_infos, in_infos, apply_infos); - let expand_rows: usize = GGSWCiphertext::expand_row_scratch_space(module, out_infos, tsk_infos); + let expand_rows: usize = GGSW::expand_row_scratch_space(module, out_infos, tsk_infos); let res_dft: usize = module.vec_znx_dft_alloc_bytes(rank + 1, size_out); if in_infos.base2k() == tsk_infos.base2k() {

@@ -109,16 +109,16 @@ + VecZnxBigAllocBytes

+ VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes, { - GGSWCiphertext::keyswitch_scratch_space(module, out_infos, out_infos, apply_infos, tsk_infos) + GGSW::keyswitch_scratch_space(module, out_infos, out_infos, apply_infos, tsk_infos) } } -impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> { +impl<DataSelf: DataMut> GGSW<DataSelf> { pub fn from_gglwe<DataA, DataTsk, B: Backend>( &mut self, module: &Module<B>, - a: &GGLWECiphertext<DataA>, - tsk: &GGLWETensorKeyPrepared<DataTsk, B>, + a: &GGLWE<DataA>, + tsk: &TensorKeyPrepared<DataTsk, B>, scratch: &mut Scratch<B>, ) where DataA: DataRef,

@@ -157,9 +157,9 @@

pub fn keyswitch<DataLhs: DataRef, DataKsk: DataRef, DataTsk: DataRef, B: Backend>( &mut self, module: &Module<B>, - lhs: &GGSWCiphertext<DataLhs>, - ksk: &GGLWESwitchingKeyPrepared<DataKsk, B>, - tsk: &GGLWETensorKeyPrepared<DataTsk, B>, + lhs: &GGSW<DataLhs>, + ksk: &GLWESwitchingKeyPrepared<DataKsk, B>, + tsk: &TensorKeyPrepared<DataTsk, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -192,8 +192,8 @@

pub fn keyswitch_inplace<DataKsk: DataRef, DataTsk: DataRef, B: Backend>( &mut self, module: &Module<B>, - ksk: &GGLWESwitchingKeyPrepared<DataKsk, B>, - tsk: &GGLWETensorKeyPrepared<DataTsk, B>, + ksk: &GLWESwitchingKeyPrepared<DataKsk, B>, + tsk: &TensorKeyPrepared<DataTsk, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -226,7 +226,7 @@

pub fn expand_row<DataTsk: DataRef, B: Backend>( &mut self, module: &Module<B>, - tsk: &GGLWETensorKeyPrepared<DataTsk, B>, + tsk: &TensorKeyPrepared<DataTsk, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -246,7 +246,7 @@ {

let basek_in: usize = self.base2k().into(); let basek_tsk: usize = tsk.base2k().into(); - assert!(scratch.available() >= GGSWCiphertext::expand_row_scratch_space(module, self, tsk)); + assert!(scratch.available() >= GGSW::expand_row_scratch_space(module, self, tsk)); let n: usize = self.n().into(); let rank: usize = self.rank().into();
M poulpy-core/src/keyswitching/glwe_ct.rs → poulpy-core/src/keyswitching/glwe_ct.rs

@@ -7,7 +7,7 @@ },

layouts::{Backend, DataMut, DataRef, DataViewMut, Module, Scratch, VecZnx, VecZnxBig, VecZnxDft, VmpPMat, ZnxInfos}, }; -use crate::layouts::{GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, prepared::GGLWESwitchingKeyPrepared}; +use crate::layouts::{GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, prepared::GLWESwitchingKeyPrepared}; impl GLWECiphertext<Vec<u8>> { pub fn keyswitch_scratch_space<B: Backend, OUT, IN, KEY>(

@@ -68,7 +68,7 @@ pub(crate) fn assert_keyswitch<B: Backend, DataLhs, DataRhs>(

&self, module: &Module<B>, lhs: &GLWECiphertext<DataLhs>, - rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>, + rhs: &GLWESwitchingKeyPrepared<DataRhs, B>, scratch: &Scratch<B>, ) where DataLhs: DataRef,

@@ -117,7 +117,7 @@ #[allow(dead_code)]

pub(crate) fn assert_keyswitch_inplace<B: Backend, DataRhs>( &self, module: &Module<B>, - rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>, + rhs: &GLWESwitchingKeyPrepared<DataRhs, B>, scratch: &Scratch<B>, ) where DataRhs: DataRef,

@@ -149,7 +149,7 @@ pub fn keyswitch<DataLhs: DataRef, DataRhs: DataRef, B: Backend>(

&mut self, module: &Module<B>, glwe_in: &GLWECiphertext<DataLhs>, - rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>, + rhs: &GLWESwitchingKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -191,7 +191,7 @@

pub fn keyswitch_inplace<DataRhs: DataRef, B: Backend>( &mut self, module: &Module<B>, - rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>, + rhs: &GLWESwitchingKeyPrepared<DataRhs, B>, scratch: &mut Scratch<B>, ) where Module<B>: VecZnxDftAllocBytes

@@ -237,7 +237,7 @@ pub(crate) fn keyswitch_internal<B: Backend, DataRes, DataKey>(

&self, module: &Module<B>, res_dft: VecZnxDft<DataRes, B>, - rhs: &GGLWESwitchingKeyPrepared<DataKey, B>, + rhs: &GLWESwitchingKeyPrepared<DataKey, B>, scratch: &mut Scratch<B>, ) -> VecZnxBig<DataRes, B> where
M poulpy-core/src/layouts/compressed/gglwe_atk.rs → poulpy-core/src/layouts/compressed/gglwe_atk.rs

@@ -5,19 +5,19 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKey, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, - compressed::{Decompress, GGLWEKeyCompressed, GGLWEKeyCompressedToMut, GGLWEKeyCompressedToRef}, + AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, + compressed::{Decompress, GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; #[derive(PartialEq, Eq, Clone)] -pub struct GGLWEAutomorphismKeyCompressed<D: Data> { - pub(crate) key: GGLWEKeyCompressed<D>, +pub struct AutomorphismKeyCompressed<D: Data> { + pub(crate) key: GLWESwitchingKeyCompressed<D>, pub(crate) p: i64, } -impl<D: Data> LWEInfos for GGLWEAutomorphismKeyCompressed<D> { +impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> { fn n(&self) -> Degree { self.key.n() }

@@ -34,13 +34,13 @@ fn size(&self) -> usize {

self.key.size() } } -impl<D: Data> GLWEInfos for GGLWEAutomorphismKeyCompressed<D> { +impl<D: Data> GLWEInfos for AutomorphismKeyCompressed<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for GGLWEAutomorphismKeyCompressed<D> { +impl<D: Data> GGLWEInfos for AutomorphismKeyCompressed<D> { fn rank_in(&self) -> Rank { self.key.rank_in() }

@@ -58,39 +58,39 @@ self.key.dnum()

} } -impl<D: DataRef> fmt::Debug for GGLWEAutomorphismKeyCompressed<D> { +impl<D: DataRef> fmt::Debug for AutomorphismKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for GGLWEAutomorphismKeyCompressed<D> { +impl<D: DataMut> FillUniform for AutomorphismKeyCompressed<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.key.fill_uniform(log_bound, source); } } -impl<D: DataRef> fmt::Display for GGLWEAutomorphismKeyCompressed<D> { +impl<D: DataRef> fmt::Display for AutomorphismKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "(AutomorphismKeyCompressed: p={}) {}", self.p, self.key) } } -impl GGLWEAutomorphismKeyCompressed<Vec<u8>> { +impl AutomorphismKeyCompressed<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos, { debug_assert_eq!(infos.rank_in(), infos.rank_out()); Self { - key: GGLWEKeyCompressed::alloc(infos), + key: GLWESwitchingKeyCompressed::alloc(infos), p: 0, } } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { Self { - key: GGLWEKeyCompressed::alloc_with(n, base2k, k, rank, rank, dnum, dsize), + key: GLWESwitchingKeyCompressed::alloc_with(n, base2k, k, rank, rank, dnum, dsize), p: 0, } }

@@ -100,64 +100,64 @@ where

A: GGLWEInfos, { debug_assert_eq!(infos.rank_in(), infos.rank_out()); - GGLWEKeyCompressed::alloc_bytes(infos) + GLWESwitchingKeyCompressed::alloc_bytes(infos) } pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize { - GGLWEKeyCompressed::alloc_bytes_with(n, base2k, k, rank, dnum, dsize) + GLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rank, dnum, dsize) } } -impl<D: DataMut> ReaderFrom for GGLWEAutomorphismKeyCompressed<D> { +impl<D: DataMut> ReaderFrom for AutomorphismKeyCompressed<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.p = reader.read_u64::<LittleEndian>()? as i64; self.key.read_from(reader) } } -impl<D: DataRef> WriterTo for GGLWEAutomorphismKeyCompressed<D> { +impl<D: DataRef> WriterTo for AutomorphismKeyCompressed<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u64::<LittleEndian>(self.p as u64)?; self.key.write_to(writer) } } -impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWEAutomorphismKeyCompressed<DR>> for GGLWEAutomorphismKey<D> +impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, AutomorphismKeyCompressed<DR>> for AutomorphismKey<D> where Module<B>: VecZnxFillUniform + VecZnxCopy, { - fn decompress(&mut self, module: &Module<B>, other: &GGLWEAutomorphismKeyCompressed<DR>) { + fn decompress(&mut self, module: &Module<B>, other: &AutomorphismKeyCompressed<DR>) { self.key.decompress(module, &other.key); self.p = other.p; } } -pub trait GGLWEAutomorphismKeyCompressedToRef { - fn to_ref(&self) -> GGLWEAutomorphismKeyCompressed<&[u8]>; +pub trait AutomorphismKeyCompressedToRef { + fn to_ref(&self) -> AutomorphismKeyCompressed<&[u8]>; } -impl<D: DataRef> GGLWEAutomorphismKeyCompressedToRef for GGLWEAutomorphismKeyCompressed<D> +impl<D: DataRef> AutomorphismKeyCompressedToRef for AutomorphismKeyCompressed<D> where - GGLWEKeyCompressed<D>: GGLWEKeyCompressedToRef, + GLWESwitchingKeyCompressed<D>: GLWESwitchingKeyCompressedToRef, { - fn to_ref(&self) -> GGLWEAutomorphismKeyCompressed<&[u8]> { - GGLWEAutomorphismKeyCompressed { + fn to_ref(&self) -> AutomorphismKeyCompressed<&[u8]> { + AutomorphismKeyCompressed { key: self.key.to_ref(), p: self.p, } } } -pub trait GGLWEAutomorphismKeyCompressedToMut { - fn to_mut(&mut self) -> GGLWEAutomorphismKeyCompressed<&mut [u8]>; +pub trait AutomorphismKeyCompressedToMut { + fn to_mut(&mut self) -> AutomorphismKeyCompressed<&mut [u8]>; } -impl<D: DataRef> GGLWEAutomorphismKeyCompressedToMut for GGLWEAutomorphismKeyCompressed<D> +impl<D: DataMut> AutomorphismKeyCompressedToMut for AutomorphismKeyCompressed<D> where - GGLWEKeyCompressed<D>: GGLWEKeyCompressedToMut, + GLWESwitchingKeyCompressed<D>: GLWESwitchingKeyCompressedToMut, { - fn to_mut(&mut self) -> GGLWEAutomorphismKeyCompressed<&mut [u8]> { - GGLWEAutomorphismKeyCompressed { + fn to_mut(&mut self) -> AutomorphismKeyCompressed<&mut [u8]> { + AutomorphismKeyCompressed { p: self.p, key: self.key.to_mut(), }
M poulpy-core/src/layouts/compressed/gglwe_ct.rs → poulpy-core/src/layouts/compressed/gglwe_ct.rs

@@ -7,7 +7,7 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWECiphertext, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::{Decompress, GLWECiphertextCompressed}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};

@@ -235,7 +235,7 @@ self.data.write_to(writer)

} } -impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGLWECiphertextCompressed<DR>> for GGLWECiphertext<D> +impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGLWECiphertextCompressed<DR>> for GGLWE<D> where Module<B>: VecZnxFillUniform + VecZnxCopy, {

@@ -313,7 +313,7 @@ pub trait GGLWECiphertextCompressedToRef {

fn to_ref(&self) -> GGLWECiphertextCompressed<&[u8]>; } -impl<D: DataMut> GGLWECiphertextCompressedToRef for GGLWECiphertextCompressed<D> { +impl<D: DataRef> GGLWECiphertextCompressedToRef for GGLWECiphertextCompressed<D> { fn to_ref(&self) -> GGLWECiphertextCompressed<&[u8]> { GGLWECiphertextCompressed { k: self.k(),
M poulpy-core/src/layouts/compressed/gglwe_ksk.rs → poulpy-core/src/layouts/compressed/gglwe_ksk.rs

@@ -5,20 +5,20 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, LWEInfos, Rank, TorusPrecision, compressed::{Decompress, GGLWECiphertextCompressed, GGLWECiphertextCompressedToMut, GGLWECiphertextCompressedToRef}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; #[derive(PartialEq, Eq, Clone)] -pub struct GGLWEKeyCompressed<D: Data> { +pub struct GLWESwitchingKeyCompressed<D: Data> { pub(crate) key: GGLWECiphertextCompressed<D>, pub(crate) sk_in_n: usize, // Degree of sk_in pub(crate) sk_out_n: usize, // Degree of sk_out } -impl<D: Data> LWEInfos for GGLWEKeyCompressed<D> { +impl<D: Data> LWEInfos for GLWESwitchingKeyCompressed<D> { fn n(&self) -> Degree { self.key.n() }

@@ -35,13 +35,13 @@ fn size(&self) -> usize {

self.key.size() } } -impl<D: Data> GLWEInfos for GGLWEKeyCompressed<D> { +impl<D: Data> GLWEInfos for GLWESwitchingKeyCompressed<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for GGLWEKeyCompressed<D> { +impl<D: Data> GGLWEInfos for GLWESwitchingKeyCompressed<D> { fn rank_in(&self) -> Rank { self.key.rank_in() }

@@ -59,19 +59,19 @@ self.key.dnum()

} } -impl<D: DataRef> fmt::Debug for GGLWEKeyCompressed<D> { +impl<D: DataRef> fmt::Debug for GLWESwitchingKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for GGLWEKeyCompressed<D> { +impl<D: DataMut> FillUniform for GLWESwitchingKeyCompressed<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.key.fill_uniform(log_bound, source); } } -impl<D: DataRef> fmt::Display for GGLWEKeyCompressed<D> { +impl<D: DataRef> fmt::Display for GLWESwitchingKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f,

@@ -81,12 +81,12 @@ )

} } -impl GGLWEKeyCompressed<Vec<u8>> { +impl GLWESwitchingKeyCompressed<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos, { - GGLWEKeyCompressed { + GLWESwitchingKeyCompressed { key: GGLWECiphertextCompressed::alloc(infos), sk_in_n: 0, sk_out_n: 0,

@@ -102,7 +102,7 @@ rank_out: Rank,

dnum: Dnum, dsize: Dsize, ) -> Self { - GGLWEKeyCompressed { + GLWESwitchingKeyCompressed { key: GGLWECiphertextCompressed::alloc_with(n, base2k, k, rank_in, rank_out, dnum, dsize), sk_in_n: 0, sk_out_n: 0,

@@ -121,7 +121,7 @@ GGLWECiphertextCompressed::alloc_bytes_with(n, base2k, k, rank_in, dnum, dsize)

} } -impl<D: DataMut> ReaderFrom for GGLWEKeyCompressed<D> { +impl<D: DataMut> ReaderFrom for GLWESwitchingKeyCompressed<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.sk_in_n = reader.read_u64::<LittleEndian>()? as usize; self.sk_out_n = reader.read_u64::<LittleEndian>()? as usize;

@@ -129,7 +129,7 @@ self.key.read_from(reader)

} } -impl<D: DataRef> WriterTo for GGLWEKeyCompressed<D> { +impl<D: DataRef> WriterTo for GLWESwitchingKeyCompressed<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u64::<LittleEndian>(self.sk_in_n as u64)?; writer.write_u64::<LittleEndian>(self.sk_out_n as u64)?;

@@ -137,27 +137,27 @@ self.key.write_to(writer)

} } -impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWEKeyCompressed<DR>> for GGLWESwitchingKey<D> +impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GLWESwitchingKeyCompressed<DR>> for GLWESwitchingKey<D> where Module<B>: VecZnxFillUniform + VecZnxCopy, { - fn decompress(&mut self, module: &Module<B>, other: &GGLWEKeyCompressed<DR>) { + fn decompress(&mut self, module: &Module<B>, other: &GLWESwitchingKeyCompressed<DR>) { self.key.decompress(module, &other.key); self.sk_in_n = other.sk_in_n; self.sk_out_n = other.sk_out_n; } } -pub trait GGLWEKeyCompressedToMut { - fn to_mut(&mut self) -> GGLWEKeyCompressed<&mut [u8]>; +pub trait GLWESwitchingKeyCompressedToMut { + fn to_mut(&mut self) -> GLWESwitchingKeyCompressed<&mut [u8]>; } -impl<D: DataMut> GGLWEKeyCompressedToMut for GGLWEKeyCompressed<D> +impl<D: DataMut> GLWESwitchingKeyCompressedToMut for GLWESwitchingKeyCompressed<D> where GGLWECiphertextCompressed<D>: GGLWECiphertextCompressedToMut, { - fn to_mut(&mut self) -> GGLWEKeyCompressed<&mut [u8]> { - GGLWEKeyCompressed { + fn to_mut(&mut self) -> GLWESwitchingKeyCompressed<&mut [u8]> { + GLWESwitchingKeyCompressed { sk_in_n: self.sk_in_n, sk_out_n: self.sk_out_n, key: self.key.to_mut(),

@@ -165,16 +165,16 @@ }

} } -pub trait GGLWEKeyCompressedToRef { - fn to_ref(&self) -> GGLWEKeyCompressed<&[u8]>; +pub trait GLWESwitchingKeyCompressedToRef { + fn to_ref(&self) -> GLWESwitchingKeyCompressed<&[u8]>; } -impl<D: DataMut> GGLWEKeyCompressedToRef for GGLWEKeyCompressed<D> +impl<D: DataRef> GLWESwitchingKeyCompressedToRef for GLWESwitchingKeyCompressed<D> where GGLWECiphertextCompressed<D>: GGLWECiphertextCompressedToRef, { - fn to_ref(&self) -> GGLWEKeyCompressed<&[u8]> { - GGLWEKeyCompressed { + fn to_ref(&self) -> GLWESwitchingKeyCompressed<&[u8]> { + GLWESwitchingKeyCompressed { sk_in_n: self.sk_in_n, sk_out_n: self.sk_out_n, key: self.key.to_ref(),
M poulpy-core/src/layouts/compressed/gglwe_tsk.rs → poulpy-core/src/layouts/compressed/gglwe_tsk.rs

@@ -5,18 +5,18 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWETensorKey, GLWEInfos, LWEInfos, Rank, TorusPrecision, - compressed::{Decompress, GGLWEKeyCompressed, GGLWEKeyCompressedToMut, GGLWEKeyCompressedToRef}, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TorusPrecision, + compressed::{Decompress, GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; #[derive(PartialEq, Eq, Clone)] -pub struct GGLWETensorKeyCompressed<D: Data> { - pub(crate) keys: Vec<GGLWEKeyCompressed<D>>, +pub struct TensorKeyCompressed<D: Data> { + pub(crate) keys: Vec<GLWESwitchingKeyCompressed<D>>, } -impl<D: Data> LWEInfos for GGLWETensorKeyCompressed<D> { +impl<D: Data> LWEInfos for TensorKeyCompressed<D> { fn n(&self) -> Degree { self.keys[0].n() }

@@ -32,13 +32,13 @@ fn size(&self) -> usize {

self.keys[0].size() } } -impl<D: Data> GLWEInfos for GGLWETensorKeyCompressed<D> { +impl<D: Data> GLWEInfos for TensorKeyCompressed<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for GGLWETensorKeyCompressed<D> { +impl<D: Data> GGLWEInfos for TensorKeyCompressed<D> { fn rank_in(&self) -> Rank { self.rank_out() }

@@ -56,21 +56,21 @@ self.keys[0].dnum()

} } -impl<D: DataRef> fmt::Debug for GGLWETensorKeyCompressed<D> { +impl<D: DataRef> fmt::Debug for TensorKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for GGLWETensorKeyCompressed<D> { +impl<D: DataMut> FillUniform for TensorKeyCompressed<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.keys .iter_mut() - .for_each(|key: &mut GGLWEKeyCompressed<D>| key.fill_uniform(log_bound, source)) + .for_each(|key: &mut GLWESwitchingKeyCompressed<D>| key.fill_uniform(log_bound, source)) } } -impl<D: DataRef> fmt::Display for GGLWETensorKeyCompressed<D> { +impl<D: DataRef> fmt::Display for TensorKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "(GLWETensorKeyCompressed)",)?; for (i, key) in self.keys.iter().enumerate() {

@@ -80,7 +80,7 @@ Ok(())

} } -impl GGLWETensorKeyCompressed<Vec<u8>> { +impl TensorKeyCompressed<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos,

@@ -101,10 +101,10 @@ )

} pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { - let mut keys: Vec<GGLWEKeyCompressed<Vec<u8>>> = Vec::new(); + let mut keys: Vec<GLWESwitchingKeyCompressed<Vec<u8>>> = Vec::new(); let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1); (0..pairs).for_each(|_| { - keys.push(GGLWEKeyCompressed::alloc_with( + keys.push(GLWESwitchingKeyCompressed::alloc_with( n, base2k, k,

@@ -129,7 +129,7 @@ );

let rank_out: usize = infos.rank_out().into(); let pairs: usize = (((rank_out + 1) * rank_out) >> 1).max(1); pairs - * GGLWEKeyCompressed::alloc_bytes_with( + * GLWESwitchingKeyCompressed::alloc_bytes_with( infos.n(), infos.base2k(), infos.k(),

@@ -141,11 +141,11 @@ }

pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize { let pairs: usize = (((rank.0 + 1) * rank.0) >> 1).max(1) as usize; - pairs * GGLWEKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, dsize) + pairs * GLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, dsize) } } -impl<D: DataMut> ReaderFrom for GGLWETensorKeyCompressed<D> { +impl<D: DataMut> ReaderFrom for TensorKeyCompressed<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { let len: usize = reader.read_u64::<LittleEndian>()? as usize; if self.keys.len() != len {

@@ -161,7 +161,7 @@ Ok(())

} } -impl<D: DataRef> WriterTo for GGLWETensorKeyCompressed<D> { +impl<D: DataRef> WriterTo for TensorKeyCompressed<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u64::<LittleEndian>(self.keys.len() as u64)?; for key in &self.keys {

@@ -171,8 +171,8 @@ Ok(())

} } -impl<D: DataMut> GGLWETensorKeyCompressed<D> { - pub(crate) fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWEKeyCompressed<D> { +impl<D: DataMut> TensorKeyCompressed<D> { + pub(crate) fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GLWESwitchingKeyCompressed<D> { if i > j { std::mem::swap(&mut i, &mut j); };

@@ -181,11 +181,11 @@ &mut self.keys[i * rank + j - (i * (i + 1) / 2)]

} } -impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWETensorKeyCompressed<DR>> for GGLWETensorKey<D> +impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, TensorKeyCompressed<DR>> for TensorKey<D> where Module<B>: VecZnxFillUniform + VecZnxCopy, { - fn decompress(&mut self, module: &Module<B>, other: &GGLWETensorKeyCompressed<DR>) { + fn decompress(&mut self, module: &Module<B>, other: &TensorKeyCompressed<DR>) { #[cfg(debug_assertions)] { assert_eq!(

@@ -206,31 +206,31 @@ });

} } -pub trait GGLWETensorKeyCompressedToMut { - fn to_mut(&mut self) -> GGLWETensorKeyCompressed<&mut [u8]>; +pub trait TensorKeyCompressedToMut { + fn to_mut(&mut self) -> TensorKeyCompressed<&mut [u8]>; } -impl<D: DataMut> GGLWETensorKeyCompressedToMut for GGLWETensorKeyCompressed<D> +impl<D: DataMut> TensorKeyCompressedToMut for TensorKeyCompressed<D> where - GGLWEKeyCompressed<D>: GGLWEKeyCompressedToMut, + GLWESwitchingKeyCompressed<D>: GLWESwitchingKeyCompressedToMut, { - fn to_mut(&mut self) -> GGLWETensorKeyCompressed<&mut [u8]> { - GGLWETensorKeyCompressed { + fn to_mut(&mut self) -> TensorKeyCompressed<&mut [u8]> { + TensorKeyCompressed { keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(), } } } -pub trait GGLWETensorKeyCompressedToRef { - fn to_ref(&self) -> GGLWETensorKeyCompressed<&[u8]>; +pub trait TensorKeyCompressedToRef { + fn to_ref(&self) -> TensorKeyCompressed<&[u8]>; } -impl<D: DataMut> GGLWETensorKeyCompressedToRef for GGLWETensorKeyCompressed<D> +impl<D: DataRef> TensorKeyCompressedToRef for TensorKeyCompressed<D> where - GGLWEKeyCompressed<D>: GGLWEKeyCompressedToRef, + GLWESwitchingKeyCompressed<D>: GLWESwitchingKeyCompressedToRef, { - fn to_ref(&self) -> GGLWETensorKeyCompressed<&[u8]> { - GGLWETensorKeyCompressed { + fn to_ref(&self) -> TensorKeyCompressed<&[u8]> { + TensorKeyCompressed { keys: self.keys.iter().map(|c| c.to_ref()).collect(), } }
M poulpy-core/src/layouts/compressed/ggsw_ct.rs → poulpy-core/src/layouts/compressed/ggsw_ct.rs

@@ -7,7 +7,7 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::{Decompress, GLWECiphertextCompressed}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};

@@ -217,7 +217,7 @@ self.data.write_to(writer)

} } -impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGSWCiphertextCompressed<DR>> for GGSWCiphertext<D> +impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGSWCiphertextCompressed<DR>> for GGSW<D> where Module<B>: VecZnxFillUniform + VecZnxCopy, {
M poulpy-core/src/layouts/compressed/glwe_ct.rs → poulpy-core/src/layouts/compressed/glwe_ct.rs

@@ -1,10 +1,14 @@

use poulpy_hal::{ api::{VecZnxCopy, VecZnxFillUniform}, - layouts::{Backend, Data, DataMut, DataRef, FillUniform, Module, ReaderFrom, VecZnx, WriterTo, ZnxInfos}, + layouts::{ + Backend, Data, DataMut, DataRef, FillUniform, Module, ReaderFrom, VecZnx, VecZnxToMut, VecZnxToRef, WriterTo, ZnxInfos, + }, source::Source, }; -use crate::layouts::{Base2K, Degree, GLWECiphertext, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::Decompress}; +use crate::layouts::{ + Base2K, BuildError, Degree, GLWECiphertext, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::Decompress, +}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt;

@@ -96,6 +100,101 @@ VecZnx::alloc_bytes(n.into(), 1, k.0.div_ceil(base2k.0) as usize)

} } +pub struct GLWECiphertextCompressedBuilder<D: Data> { + data: Option<VecZnx<D>>, + base2k: Option<Base2K>, + k: Option<TorusPrecision>, + rank: Option<Rank>, +} + +impl<D: Data> GLWECiphertextCompressed<D> { + #[inline] + pub fn builder() -> GLWECiphertextCompressedBuilder<D> { + GLWECiphertextCompressedBuilder { + data: None, + base2k: None, + k: None, + rank: None, + } + } +} + +impl GLWECiphertextCompressedBuilder<Vec<u8>> { + #[inline] + pub fn layout<A>(mut self, layout: &A) -> Self + where + A: GLWEInfos, + { + self.data = Some(VecZnx::alloc(layout.n().into(), 1, layout.size())); + self.base2k = Some(layout.base2k()); + self.k = Some(layout.k()); + self.rank = Some(layout.rank()); + self + } +} + +impl<D: Data> GLWECiphertextCompressedBuilder<D> { + #[inline] + pub fn data(mut self, data: VecZnx<D>) -> Self { + self.data = Some(data); + self + } + #[inline] + pub fn base2k(mut self, base2k: Base2K) -> Self { + self.base2k = Some(base2k); + self + } + #[inline] + pub fn k(mut self, k: TorusPrecision) -> Self { + self.k = Some(k); + self + } + #[inline] + pub fn rank(mut self, rank: Rank) -> Self { + self.rank = Some(rank); + self + } + + pub fn build(self) -> Result<GLWECiphertextCompressed<D>, BuildError> { + let data: VecZnx<D> = self.data.ok_or(BuildError::MissingData)?; + let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?; + let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?; + let rank: Rank = self.rank.ok_or(BuildError::MissingK)?; + + if base2k == 0_u32 { + return Err(BuildError::ZeroBase2K); + } + + if k == 0_u32 { + return Err(BuildError::ZeroTorusPrecision); + } + + if rank == 0_u32 { + return Err(BuildError::ZeroRank); + } + + if data.n() == 0 { + return Err(BuildError::ZeroDegree); + } + + if data.cols() != 1 { + return Err(BuildError::VecZnxColsNotOne); + } + + if data.size() == 0 { + return Err(BuildError::ZeroLimbs); + } + + Ok(GLWECiphertextCompressed { + data, + base2k, + k, + rank, + seed: [0u8; 32], + }) + } +} + impl<D: DataMut> ReaderFrom for GLWECiphertextCompressed<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?);

@@ -176,3 +275,35 @@ self.base2k = other.base2k;

self.k = other.k; } } + +pub trait GLWECiphertextCompressedToRef { + fn to_ref(&self) -> GLWECiphertextCompressed<&[u8]>; +} + +impl<D: DataRef> GLWECiphertextCompressedToRef for GLWECiphertextCompressed<D> { + fn to_ref(&self) -> GLWECiphertextCompressed<&[u8]> { + GLWECiphertextCompressed::builder() + .k(self.k()) + .base2k(self.base2k()) + .rank(self.rank()) + .data(self.data.to_ref()) + .build() + .unwrap() + } +} + +pub trait GLWECiphertextCompressedToMut { + fn to_mut(&mut self) -> GLWECiphertextCompressed<&mut [u8]>; +} + +impl<D: DataMut> GLWECiphertextCompressedToMut for GLWECiphertextCompressed<D> { + fn to_mut(&mut self) -> GLWECiphertextCompressed<&mut [u8]> { + GLWECiphertextCompressed::builder() + .k(self.k()) + .base2k(self.base2k()) + .rank(self.rank()) + .data(self.data.to_mut()) + .build() + .unwrap() + } +}
M poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs → poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs

@@ -6,11 +6,11 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::GGLWEKeyCompressed, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::GLWESwitchingKeyCompressed, }; #[derive(PartialEq, Eq, Clone)] -pub struct GLWEToLWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWEKeyCompressed<D>); +pub struct GLWEToLWESwitchingKeyCompressed<D: Data>(pub(crate) GLWESwitchingKeyCompressed<D>); impl<D: Data> LWEInfos for GLWEToLWESwitchingKeyCompressed<D> { fn base2k(&self) -> Base2K {

@@ -98,11 +98,11 @@ infos.dsize().0,

1, "dsize > 1 is unsupported for GLWEToLWESwitchingKeyCompressed" ); - Self(GGLWEKeyCompressed::alloc(infos)) + Self(GLWESwitchingKeyCompressed::alloc(infos)) } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self { - Self(GGLWEKeyCompressed::alloc_with( + Self(GLWESwitchingKeyCompressed::alloc_with( n, base2k, k,

@@ -127,10 +127,10 @@ infos.dsize().0,

1, "dsize > 1 is unsupported for GLWEToLWESwitchingKeyCompressed" ); - GGLWEKeyCompressed::alloc_bytes(infos) + GLWESwitchingKeyCompressed::alloc_bytes(infos) } pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_in: Rank) -> usize { - GGLWEKeyCompressed::alloc_bytes_with(n, base2k, k, rank_in, dnum, Dsize(1)) + GLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rank_in, dnum, Dsize(1)) } }
M poulpy-core/src/layouts/compressed/lwe_ksk.rs → poulpy-core/src/layouts/compressed/lwe_ksk.rs

@@ -6,12 +6,12 @@ };

use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, Rank, TorusPrecision, - compressed::{Decompress, GGLWEKeyCompressed}, + compressed::{Decompress, GLWESwitchingKeyCompressed}, }; use std::fmt; #[derive(PartialEq, Eq, Clone)] -pub struct LWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWEKeyCompressed<D>); +pub struct LWESwitchingKeyCompressed<D: Data>(pub(crate) GLWESwitchingKeyCompressed<D>); impl<D: Data> LWEInfos for LWESwitchingKeyCompressed<D> { fn base2k(&self) -> Base2K {

@@ -103,11 +103,11 @@ infos.rank_out().0,

1, "rank_out > 1 is not supported for LWESwitchingKeyCompressed" ); - Self(GGLWEKeyCompressed::alloc(infos)) + Self(GLWESwitchingKeyCompressed::alloc(infos)) } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self { - Self(GGLWEKeyCompressed::alloc_with( + Self(GLWESwitchingKeyCompressed::alloc_with( n, base2k, k,

@@ -137,11 +137,11 @@ infos.rank_out().0,

1, "rank_out > 1 is not supported for LWESwitchingKey" ); - GGLWEKeyCompressed::alloc_bytes(infos) + GLWESwitchingKeyCompressed::alloc_bytes(infos) } pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize { - GGLWEKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, Dsize(1)) + GLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, Dsize(1)) } }
M poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs → poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs

@@ -6,12 +6,12 @@ };

use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, Rank, TorusPrecision, - compressed::{Decompress, GGLWEKeyCompressed}, + compressed::{Decompress, GLWESwitchingKeyCompressed}, }; use std::fmt; #[derive(PartialEq, Eq, Clone)] -pub struct LWEToGLWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWEKeyCompressed<D>); +pub struct LWEToGLWESwitchingKeyCompressed<D: Data>(pub(crate) GLWESwitchingKeyCompressed<D>); impl<D: Data> LWEInfos for LWEToGLWESwitchingKeyCompressed<D> { fn n(&self) -> Degree {

@@ -98,11 +98,11 @@ infos.rank_in().0,

1, "rank_in > 1 is not supported for LWEToGLWESwitchingKeyCompressed" ); - Self(GGLWEKeyCompressed::alloc(infos)) + Self(GLWESwitchingKeyCompressed::alloc(infos)) } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self { - Self(GGLWEKeyCompressed::alloc_with( + Self(GLWESwitchingKeyCompressed::alloc_with( n, base2k, k,

@@ -127,11 +127,11 @@ infos.dsize().0,

1, "dsize > 1 is not supported for LWEToGLWESwitchingKey" ); - GGLWEKeyCompressed::alloc_bytes(infos) + GLWESwitchingKeyCompressed::alloc_bytes(infos) } pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize { - GGLWEKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, Dsize(1)) + GLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, Dsize(1)) } }
M poulpy-core/src/layouts/gglwe_atk.rs → poulpy-core/src/layouts/gglwe_atk.rs

@@ -4,15 +4,15 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GGLWESwitchingKeyToMut, GLWECiphertext, GLWEInfos, LWEInfos, - Rank, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWECiphertext, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] -pub struct GGLWEAutomorphismKeyLayout { +pub struct AutomorphismKeyLayout { pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision,

@@ -22,18 +22,18 @@ pub dsize: Dsize,

} #[derive(PartialEq, Eq, Clone)] -pub struct GGLWEAutomorphismKey<D: Data> { - pub(crate) key: GGLWESwitchingKey<D>, +pub struct AutomorphismKey<D: Data> { + pub(crate) key: GLWESwitchingKey<D>, pub(crate) p: i64, } -impl<D: Data> GGLWEAutomorphismKey<D> { +impl<D: Data> AutomorphismKey<D> { pub fn p(&self) -> i64 { self.p } } -impl<D: Data> LWEInfos for GGLWEAutomorphismKey<D> { +impl<D: Data> LWEInfos for AutomorphismKey<D> { fn n(&self) -> Degree { self.key.n() }

@@ -51,13 +51,13 @@ self.key.size()

} } -impl<D: Data> GLWEInfos for GGLWEAutomorphismKey<D> { +impl<D: Data> GLWEInfos for AutomorphismKey<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for GGLWEAutomorphismKey<D> { +impl<D: Data> GGLWEInfos for AutomorphismKey<D> { fn rank_in(&self) -> Rank { self.key.rank_in() }

@@ -75,7 +75,7 @@ self.key.dnum()

} } -impl LWEInfos for GGLWEAutomorphismKeyLayout { +impl LWEInfos for AutomorphismKeyLayout { fn base2k(&self) -> Base2K { self.base2k }

@@ -89,13 +89,13 @@ self.n

} } -impl GLWEInfos for GGLWEAutomorphismKeyLayout { +impl GLWEInfos for AutomorphismKeyLayout { fn rank(&self) -> Rank { self.rank } } -impl GGLWEInfos for GGLWEAutomorphismKeyLayout { +impl GGLWEInfos for AutomorphismKeyLayout { fn rank_in(&self) -> Rank { self.rank }

@@ -113,25 +113,25 @@ self.dnum

} } -impl<D: DataRef> fmt::Debug for GGLWEAutomorphismKey<D> { +impl<D: DataRef> fmt::Debug for AutomorphismKey<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for GGLWEAutomorphismKey<D> { +impl<D: DataMut> FillUniform for AutomorphismKey<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.key.fill_uniform(log_bound, source); } } -impl<D: DataRef> fmt::Display for GGLWEAutomorphismKey<D> { +impl<D: DataRef> fmt::Display for AutomorphismKey<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "(AutomorphismKey: p={}) {}", self.p, self.key) } } -impl GGLWEAutomorphismKey<Vec<u8>> { +impl AutomorphismKey<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos,

@@ -141,15 +141,15 @@ infos.rank_in(),

infos.rank_out(), "rank_in != rank_out is not supported for GGLWEAutomorphismKey" ); - GGLWEAutomorphismKey { - key: GGLWESwitchingKey::alloc(infos), + AutomorphismKey { + key: GLWESwitchingKey::alloc(infos), p: 0, } } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { - GGLWEAutomorphismKey { - key: GGLWESwitchingKey::alloc_with(n, base2k, k, rank, rank, dnum, dsize), + AutomorphismKey { + key: GLWESwitchingKey::alloc_with(n, base2k, k, rank, rank, dnum, dsize), p: 0, } }

@@ -163,54 +163,66 @@ infos.rank_in(),

infos.rank_out(), "rank_in != rank_out is not supported for GGLWEAutomorphismKey" ); - GGLWESwitchingKey::alloc_bytes(infos) + GLWESwitchingKey::alloc_bytes(infos) } pub fn bytes_of(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize { - GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rank, rank, dnum, dsize) + GLWESwitchingKey::alloc_bytes_with(n, base2k, k, rank, rank, dnum, dsize) } } -pub trait GGLWEAutomorphismKeyToMut { - fn to_mut(&mut self) -> GGLWEAutomorphismKey<&mut [u8]>; +pub trait AutomorphismKeyToMut { + fn to_mut(&mut self) -> AutomorphismKey<&mut [u8]>; } -impl<D: DataMut> GGLWEAutomorphismKeyToMut for GGLWEAutomorphismKey<D> +impl<D: DataMut> AutomorphismKeyToMut for AutomorphismKey<D> where - GGLWESwitchingKey<D>: GGLWESwitchingKeyToMut, + GLWESwitchingKey<D>: GLWESwitchingKeyToMut, { - fn to_mut(&mut self) -> GGLWEAutomorphismKey<&mut [u8]> { - GGLWEAutomorphismKey { + fn to_mut(&mut self) -> AutomorphismKey<&mut [u8]> { + AutomorphismKey { key: self.key.to_mut(), p: self.p, } } } -pub trait GGLWEAutomorphismKeyToRef { - fn to_ref(&self) -> GGLWEAutomorphismKey<&[u8]>; +pub trait AutomorphismKeyToRef { + fn to_ref(&self) -> AutomorphismKey<&[u8]>; } -impl<D: DataRef> GGLWEAutomorphismKey<D> { +impl<D: DataRef> AutomorphismKeyToRef for AutomorphismKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToRef, +{ + fn to_ref(&self) -> AutomorphismKey<&[u8]> { + AutomorphismKey { + p: self.p, + key: self.key.to_ref(), + } + } +} + +impl<D: DataRef> AutomorphismKey<D> { pub fn at(&self, row: usize, col: usize) -> GLWECiphertext<&[u8]> { self.key.at(row, col) } } -impl<D: DataMut> GGLWEAutomorphismKey<D> { +impl<D: DataMut> AutomorphismKey<D> { pub fn at_mut(&mut self, row: usize, col: usize) -> GLWECiphertext<&mut [u8]> { self.key.at_mut(row, col) } } -impl<D: DataMut> ReaderFrom for GGLWEAutomorphismKey<D> { +impl<D: DataMut> ReaderFrom for AutomorphismKey<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.p = reader.read_u64::<LittleEndian>()? as i64; self.key.read_from(reader) } } -impl<D: DataRef> WriterTo for GGLWEAutomorphismKey<D> { +impl<D: DataRef> WriterTo for AutomorphismKey<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u64::<LittleEndian>(self.p as u64)?; self.key.write_to(writer)
M poulpy-core/src/layouts/gglwe_ct.rs → poulpy-core/src/layouts/gglwe_ct.rs

@@ -29,6 +29,10 @@ }

} } +pub trait SetGGLWEInfos { + fn set_dsize(&mut self, dsize: usize); +} + #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GGLWECiphertextLayout { pub n: Degree,

@@ -79,14 +83,14 @@ }

} #[derive(PartialEq, Eq, Clone)] -pub struct GGLWECiphertext<D: Data> { +pub struct GGLWE<D: Data> { pub(crate) data: MatZnx<D>, pub(crate) k: TorusPrecision, pub(crate) base2k: Base2K, pub(crate) dsize: Dsize, } -impl<D: Data> LWEInfos for GGLWECiphertext<D> { +impl<D: Data> LWEInfos for GGLWE<D> { fn base2k(&self) -> Base2K { self.base2k }

@@ -104,13 +108,13 @@ self.data.size()

} } -impl<D: Data> GLWEInfos for GGLWECiphertext<D> { +impl<D: Data> GLWEInfos for GGLWE<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for GGLWECiphertext<D> { +impl<D: Data> GGLWEInfos for GGLWE<D> { fn rank_in(&self) -> Rank { Rank(self.data.cols_in() as u32) }

@@ -135,7 +139,7 @@ k: Option<TorusPrecision>,

dsize: Option<Dsize>, } -impl<D: Data> GGLWECiphertext<D> { +impl<D: Data> GGLWE<D> { #[inline] pub fn builder() -> GGLWECiphertextBuilder<D> { GGLWECiphertextBuilder {

@@ -190,7 +194,7 @@ self.dsize = Some(dsize);

self } - pub fn build(self) -> Result<GGLWECiphertext<D>, BuildError> { + pub fn build(self) -> Result<GGLWE<D>, BuildError> { let data: MatZnx<D> = self.data.ok_or(BuildError::MissingData)?; let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?; let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;

@@ -220,7 +224,7 @@ if data.size() == 0 {

return Err(BuildError::ZeroLimbs); } - Ok(GGLWECiphertext { + Ok(GGLWE { data, base2k, k,

@@ -229,31 +233,31 @@ })

} } -impl<D: DataRef> GGLWECiphertext<D> { +impl<D: DataRef> GGLWE<D> { pub fn data(&self) -> &MatZnx<D> { &self.data } } -impl<D: DataMut> GGLWECiphertext<D> { +impl<D: DataMut> GGLWE<D> { pub fn data_mut(&mut self) -> &mut MatZnx<D> { &mut self.data } } -impl<D: DataRef> fmt::Debug for GGLWECiphertext<D> { +impl<D: DataRef> fmt::Debug for GGLWE<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for GGLWECiphertext<D> { +impl<D: DataMut> FillUniform for GGLWE<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.data.fill_uniform(log_bound, source); } } -impl<D: DataRef> fmt::Display for GGLWECiphertext<D> { +impl<D: DataRef> fmt::Display for GGLWE<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f,

@@ -266,7 +270,7 @@ )

} } -impl<D: DataRef> GGLWECiphertext<D> { +impl<D: DataRef> GGLWE<D> { pub fn at(&self, row: usize, col: usize) -> GLWECiphertext<&[u8]> { GLWECiphertext::builder() .data(self.data.at(row, col))

@@ -277,7 +281,7 @@ .unwrap()

} } -impl<D: DataMut> GGLWECiphertext<D> { +impl<D: DataMut> GGLWE<D> { pub fn at_mut(&mut self, row: usize, col: usize) -> GLWECiphertext<&mut [u8]> { GLWECiphertext::builder() .base2k(self.base2k())

@@ -288,7 +292,7 @@ .unwrap()

} } -impl GGLWECiphertext<Vec<u8>> { +impl GGLWE<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos,

@@ -390,12 +394,12 @@ }

} pub trait GGLWECiphertextToMut { - fn to_mut(&mut self) -> GGLWECiphertext<&mut [u8]>; + fn to_mut(&mut self) -> GGLWE<&mut [u8]>; } -impl<D: DataMut> GGLWECiphertextToMut for GGLWECiphertext<D> { - fn to_mut(&mut self) -> GGLWECiphertext<&mut [u8]> { - GGLWECiphertext { +impl<D: DataMut> GGLWECiphertextToMut for GGLWE<D> { + fn to_mut(&mut self) -> GGLWE<&mut [u8]> { + GGLWE { k: self.k(), base2k: self.base2k(), dsize: self.dsize(),

@@ -404,13 +408,13 @@ }

} } -pub trait GGLWECiphertextToRef { - fn to_ref(&self) -> GGLWECiphertext<&[u8]>; +pub trait GGLWEToRef { + fn to_ref(&self) -> GGLWE<&[u8]>; } -impl<D: DataMut> GGLWECiphertextToRef for GGLWECiphertext<D> { - fn to_ref(&self) -> GGLWECiphertext<&[u8]> { - GGLWECiphertext { +impl<D: DataRef> GGLWEToRef for GGLWE<D> { + fn to_ref(&self) -> GGLWE<&[u8]> { + GGLWE { k: self.k(), base2k: self.base2k(), dsize: self.dsize(),

@@ -419,7 +423,7 @@ }

} } -impl<D: DataMut> ReaderFrom for GGLWECiphertext<D> { +impl<D: DataMut> ReaderFrom for GGLWE<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?); self.base2k = Base2K(reader.read_u32::<LittleEndian>()?);

@@ -428,7 +432,7 @@ self.data.read_from(reader)

} } -impl<D: DataRef> WriterTo for GGLWECiphertext<D> { +impl<D: DataRef> WriterTo for GGLWE<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u32::<LittleEndian>(self.k.0)?; writer.write_u32::<LittleEndian>(self.base2k.0)?;
M poulpy-core/src/layouts/gglwe_ksk.rs → poulpy-core/src/layouts/gglwe_ksk.rs

@@ -4,7 +4,7 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWECiphertext, GGLWECiphertextToMut, GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, Rank, + Base2K, Degree, Dnum, Dsize, GGLWE, GGLWECiphertextToMut, GGLWEInfos, GGLWEToRef, GLWECiphertext, GLWEInfos, LWEInfos, Rank, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};

@@ -12,7 +12,7 @@

use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] -pub struct GGLWESwitchingKeyLayout { +pub struct GLWESwitchingKeyLayout { pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision,

@@ -22,7 +22,7 @@ pub dnum: Dnum,

pub dsize: Dsize, } -impl LWEInfos for GGLWESwitchingKeyLayout { +impl LWEInfos for GLWESwitchingKeyLayout { fn n(&self) -> Degree { self.n }

@@ -36,13 +36,13 @@ self.k

} } -impl GLWEInfos for GGLWESwitchingKeyLayout { +impl GLWEInfos for GLWESwitchingKeyLayout { fn rank(&self) -> Rank { self.rank_out() } } -impl GGLWEInfos for GGLWESwitchingKeyLayout { +impl GGLWEInfos for GLWESwitchingKeyLayout { fn rank_in(&self) -> Rank { self.rank_in }

@@ -61,13 +61,13 @@ }

} #[derive(PartialEq, Eq, Clone)] -pub struct GGLWESwitchingKey<D: Data> { - pub(crate) key: GGLWECiphertext<D>, +pub struct GLWESwitchingKey<D: Data> { + pub(crate) key: GGLWE<D>, pub(crate) sk_in_n: usize, // Degree of sk_in pub(crate) sk_out_n: usize, // Degree of sk_out } -impl<D: Data> LWEInfos for GGLWESwitchingKey<D> { +impl<D: Data> LWEInfos for GLWESwitchingKey<D> { fn n(&self) -> Degree { self.key.n() }

@@ -85,13 +85,13 @@ self.key.size()

} } -impl<D: Data> GLWEInfos for GGLWESwitchingKey<D> { +impl<D: Data> GLWEInfos for GLWESwitchingKey<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for GGLWESwitchingKey<D> { +impl<D: Data> GGLWEInfos for GLWESwitchingKey<D> { fn rank_in(&self) -> Rank { self.key.rank_in() }

@@ -109,13 +109,13 @@ self.key.dnum()

} } -impl<D: DataRef> fmt::Debug for GGLWESwitchingKey<D> { +impl<D: DataRef> fmt::Debug for GLWESwitchingKey<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataRef> fmt::Display for GGLWESwitchingKey<D> { +impl<D: DataRef> fmt::Display for GLWESwitchingKey<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f,

@@ -127,19 +127,19 @@ )

} } -impl<D: DataMut> FillUniform for GGLWESwitchingKey<D> { +impl<D: DataMut> FillUniform for GLWESwitchingKey<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.key.fill_uniform(log_bound, source); } } -impl GGLWESwitchingKey<Vec<u8>> { +impl GLWESwitchingKey<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos, { - GGLWESwitchingKey { - key: GGLWECiphertext::alloc(infos), + GLWESwitchingKey { + key: GGLWE::alloc(infos), sk_in_n: 0, sk_out_n: 0, }

@@ -154,8 +154,8 @@ rank_out: Rank,

dnum: Dnum, dsize: Dsize, ) -> Self { - GGLWESwitchingKey { - key: GGLWECiphertext::alloc_with(n, base2k, k, rank_in, rank_out, dnum, dsize), + GLWESwitchingKey { + key: GGLWE::alloc_with(n, base2k, k, rank_in, rank_out, dnum, dsize), sk_in_n: 0, sk_out_n: 0, }

@@ -165,7 +165,7 @@ pub fn alloc_bytes<A>(infos: &A) -> usize

where A: GGLWEInfos, { - GGLWECiphertext::alloc_bytes(infos) + GGLWE::alloc_bytes(infos) } pub fn alloc_bytes_with(

@@ -177,20 +177,20 @@ rank_out: Rank,

dnum: Dnum, dsize: Dsize, ) -> usize { - GGLWECiphertext::alloc_bytes_with(n, base2k, k, rank_in, rank_out, dnum, dsize) + GGLWE::alloc_bytes_with(n, base2k, k, rank_in, rank_out, dnum, dsize) } } -pub trait GGLWESwitchingKeyToMut { - fn to_mut(&mut self) -> GGLWESwitchingKey<&mut [u8]>; +pub trait GLWESwitchingKeyToMut { + fn to_mut(&mut self) -> GLWESwitchingKey<&mut [u8]>; } -impl<D: DataMut> GGLWESwitchingKeyToMut for GGLWESwitchingKey<D> +impl<D: DataMut> GLWESwitchingKeyToMut for GLWESwitchingKey<D> where - GGLWECiphertext<D>: GGLWECiphertextToMut, + GGLWE<D>: GGLWECiphertextToMut, { - fn to_mut(&mut self) -> GGLWESwitchingKey<&mut [u8]> { - GGLWESwitchingKey { + fn to_mut(&mut self) -> GLWESwitchingKey<&mut [u8]> { + GLWESwitchingKey { key: self.key.to_mut(), sk_in_n: self.sk_in_n, sk_out_n: self.sk_out_n,

@@ -198,19 +198,36 @@ }

} } -impl<D: DataRef> GGLWESwitchingKey<D> { +pub trait GLWESwitchingKeyToRef { + fn to_ref(&self) -> GLWESwitchingKey<&[u8]>; +} + +impl<D: DataRef> GLWESwitchingKeyToRef for GLWESwitchingKey<D> +where + GGLWE<D>: GGLWEToRef, +{ + fn to_ref(&self) -> GLWESwitchingKey<&[u8]> { + GLWESwitchingKey { + key: self.key.to_ref(), + sk_in_n: self.sk_in_n, + sk_out_n: self.sk_out_n, + } + } +} + +impl<D: DataRef> GLWESwitchingKey<D> { pub fn at(&self, row: usize, col: usize) -> GLWECiphertext<&[u8]> { self.key.at(row, col) } } -impl<D: DataMut> GGLWESwitchingKey<D> { +impl<D: DataMut> GLWESwitchingKey<D> { pub fn at_mut(&mut self, row: usize, col: usize) -> GLWECiphertext<&mut [u8]> { self.key.at_mut(row, col) } } -impl<D: DataMut> ReaderFrom for GGLWESwitchingKey<D> { +impl<D: DataMut> ReaderFrom for GLWESwitchingKey<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.sk_in_n = reader.read_u64::<LittleEndian>()? as usize; self.sk_out_n = reader.read_u64::<LittleEndian>()? as usize;

@@ -218,7 +235,7 @@ self.key.read_from(reader)

} } -impl<D: DataRef> WriterTo for GGLWESwitchingKey<D> { +impl<D: DataRef> WriterTo for GLWESwitchingKey<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u64::<LittleEndian>(self.sk_in_n as u64)?; writer.write_u64::<LittleEndian>(self.sk_out_n as u64)?;
M poulpy-core/src/layouts/gglwe_tsk.rs → poulpy-core/src/layouts/gglwe_tsk.rs

@@ -3,13 +3,16 @@ layouts::{Data, DataMut, DataRef, FillUniform, ReaderFrom, WriterTo},

source::Source, }; -use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision}; +use crate::layouts::{ + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyToMut, GLWESwitchingKeyToRef, LWEInfos, + Rank, TorusPrecision, +}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] -pub struct GGLWETensorKeyLayout { +pub struct TensorKeyLayout { pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision,

@@ -19,11 +22,11 @@ pub dsize: Dsize,

} #[derive(PartialEq, Eq, Clone)] -pub struct GGLWETensorKey<D: Data> { - pub(crate) keys: Vec<GGLWESwitchingKey<D>>, +pub struct TensorKey<D: Data> { + pub(crate) keys: Vec<GLWESwitchingKey<D>>, } -impl<D: Data> LWEInfos for GGLWETensorKey<D> { +impl<D: Data> LWEInfos for TensorKey<D> { fn n(&self) -> Degree { self.keys[0].n() }

@@ -41,13 +44,13 @@ self.keys[0].size()

} } -impl<D: Data> GLWEInfos for GGLWETensorKey<D> { +impl<D: Data> GLWEInfos for TensorKey<D> { fn rank(&self) -> Rank { self.keys[0].rank_out() } } -impl<D: Data> GGLWEInfos for GGLWETensorKey<D> { +impl<D: Data> GGLWEInfos for TensorKey<D> { fn rank_in(&self) -> Rank { self.rank_out() }

@@ -65,7 +68,7 @@ self.keys[0].dnum()

} } -impl LWEInfos for GGLWETensorKeyLayout { +impl LWEInfos for TensorKeyLayout { fn n(&self) -> Degree { self.n }

@@ -79,13 +82,13 @@ self.k

} } -impl GLWEInfos for GGLWETensorKeyLayout { +impl GLWEInfos for TensorKeyLayout { fn rank(&self) -> Rank { self.rank_out() } } -impl GGLWEInfos for GGLWETensorKeyLayout { +impl GGLWEInfos for TensorKeyLayout { fn rank_in(&self) -> Rank { self.rank }

@@ -103,21 +106,21 @@ self.dnum

} } -impl<D: DataRef> fmt::Debug for GGLWETensorKey<D> { +impl<D: DataRef> fmt::Debug for TensorKey<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for GGLWETensorKey<D> { +impl<D: DataMut> FillUniform for TensorKey<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.keys .iter_mut() - .for_each(|key: &mut GGLWESwitchingKey<D>| key.fill_uniform(log_bound, source)) + .for_each(|key: &mut GLWESwitchingKey<D>| key.fill_uniform(log_bound, source)) } } -impl<D: DataRef> fmt::Display for GGLWETensorKey<D> { +impl<D: DataRef> fmt::Display for TensorKey<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "(GLWETensorKey)",)?; for (i, key) in self.keys.iter().enumerate() {

@@ -127,7 +130,7 @@ Ok(())

} } -impl GGLWETensorKey<Vec<u8>> { +impl TensorKey<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos,

@@ -148,10 +151,10 @@ )

} pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { - let mut keys: Vec<GGLWESwitchingKey<Vec<u8>>> = Vec::new(); + let mut keys: Vec<GLWESwitchingKey<Vec<u8>>> = Vec::new(); let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1); (0..pairs).for_each(|_| { - keys.push(GGLWESwitchingKey::alloc_with( + keys.push(GLWESwitchingKey::alloc_with( n, base2k, k,

@@ -176,7 +179,7 @@ );

let rank_out: usize = infos.rank_out().into(); let pairs: usize = (((rank_out + 1) * rank_out) >> 1).max(1); pairs - * GGLWESwitchingKey::alloc_bytes_with( + * GLWESwitchingKey::alloc_bytes_with( infos.n(), infos.base2k(), infos.k(),

@@ -189,13 +192,13 @@ }

pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize { let pairs: usize = (((rank.0 + 1) * rank.0) >> 1).max(1) as usize; - pairs * GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), rank, dnum, dsize) + pairs * GLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), rank, dnum, dsize) } } -impl<D: DataMut> GGLWETensorKey<D> { +impl<D: DataMut> TensorKey<D> { // Returns a mutable reference to GLWESwitchingKey_{s}(s[i] * s[j]) - pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWESwitchingKey<D> { + pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GLWESwitchingKey<D> { if i > j { std::mem::swap(&mut i, &mut j); };

@@ -204,9 +207,9 @@ &mut self.keys[i * rank + j - (i * (i + 1) / 2)]

} } -impl<D: DataRef> GGLWETensorKey<D> { +impl<D: DataRef> TensorKey<D> { // Returns a reference to GLWESwitchingKey_{s}(s[i] * s[j]) - pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWESwitchingKey<D> { + pub fn at(&self, mut i: usize, mut j: usize) -> &GLWESwitchingKey<D> { if i > j { std::mem::swap(&mut i, &mut j); };

@@ -215,7 +218,7 @@ &self.keys[i * rank + j - (i * (i + 1) / 2)]

} } -impl<D: DataMut> ReaderFrom for GGLWETensorKey<D> { +impl<D: DataMut> ReaderFrom for TensorKey<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { let len: usize = reader.read_u64::<LittleEndian>()? as usize; if self.keys.len() != len {

@@ -231,7 +234,7 @@ Ok(())

} } -impl<D: DataRef> WriterTo for GGLWETensorKey<D> { +impl<D: DataRef> WriterTo for TensorKey<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u64::<LittleEndian>(self.keys.len() as u64)?; for key in &self.keys {

@@ -240,3 +243,33 @@ }

Ok(()) } } + +pub trait TensorKeyToRef { + fn to_ref(&self) -> TensorKey<&[u8]>; +} + +impl<D: DataRef> TensorKeyToRef for TensorKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToRef, +{ + fn to_ref(&self) -> TensorKey<&[u8]> { + TensorKey { + keys: self.keys.iter().map(|c| c.to_ref()).collect(), + } + } +} + +pub trait TensorKeyToMut { + fn to_ref(&mut self) -> TensorKey<&mut [u8]>; +} + +impl<D: DataMut> TensorKeyToMut for TensorKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToMut, +{ + fn to_ref(&mut self) -> TensorKey<&mut [u8]> { + TensorKey { + keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(), + } + } +}
M poulpy-core/src/layouts/ggsw_ct.rs → poulpy-core/src/layouts/ggsw_ct.rs

@@ -64,14 +64,14 @@ }

} #[derive(PartialEq, Eq, Clone)] -pub struct GGSWCiphertext<D: Data> { +pub struct GGSW<D: Data> { pub(crate) data: MatZnx<D>, pub(crate) k: TorusPrecision, pub(crate) base2k: Base2K, pub(crate) dsize: Dsize, } -impl<D: Data> LWEInfos for GGSWCiphertext<D> { +impl<D: Data> LWEInfos for GGSW<D> { fn n(&self) -> Degree { Degree(self.data.n() as u32) }

@@ -89,13 +89,13 @@ self.data.size()

} } -impl<D: Data> GLWEInfos for GGSWCiphertext<D> { +impl<D: Data> GLWEInfos for GGSW<D> { fn rank(&self) -> Rank { Rank(self.data.cols_out() as u32 - 1) } } -impl<D: Data> GGSWInfos for GGSWCiphertext<D> { +impl<D: Data> GGSWInfos for GGSW<D> { fn dsize(&self) -> Dsize { self.dsize }

@@ -112,7 +112,7 @@ k: Option<TorusPrecision>,

dsize: Option<Dsize>, } -impl<D: Data> GGSWCiphertext<D> { +impl<D: Data> GGSW<D> { #[inline] pub fn builder() -> GGSWCiphertextBuilder<D> { GGSWCiphertextBuilder {

@@ -182,7 +182,7 @@ self.dsize = Some(dsize);

self } - pub fn build(self) -> Result<GGSWCiphertext<D>, BuildError> { + pub fn build(self) -> Result<GGSW<D>, BuildError> { let data: MatZnx<D> = self.data.ok_or(BuildError::MissingData)?; let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?; let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;

@@ -212,7 +212,7 @@ if data.size() == 0 {

return Err(BuildError::ZeroLimbs); } - Ok(GGSWCiphertext { + Ok(GGSW { data, base2k, k,

@@ -221,13 +221,13 @@ })

} } -impl<D: DataRef> fmt::Debug for GGSWCiphertext<D> { +impl<D: DataRef> fmt::Debug for GGSW<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.data) } } -impl<D: DataRef> fmt::Display for GGSWCiphertext<D> { +impl<D: DataRef> fmt::Display for GGSW<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f,

@@ -240,13 +240,13 @@ )

} } -impl<D: DataMut> FillUniform for GGSWCiphertext<D> { +impl<D: DataMut> FillUniform for GGSW<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.data.fill_uniform(log_bound, source); } } -impl<D: DataRef> GGSWCiphertext<D> { +impl<D: DataRef> GGSW<D> { pub fn at(&self, row: usize, col: usize) -> GLWECiphertext<&[u8]> { GLWECiphertext::builder() .data(self.data.at(row, col))

@@ -257,7 +257,7 @@ .unwrap()

} } -impl<D: DataMut> GGSWCiphertext<D> { +impl<D: DataMut> GGSW<D> { pub fn at_mut(&mut self, row: usize, col: usize) -> GLWECiphertext<&mut [u8]> { GLWECiphertext::builder() .base2k(self.base2k())

@@ -268,7 +268,7 @@ .unwrap()

} } -impl GGSWCiphertext<Vec<u8>> { +impl GGSW<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGSWInfos,

@@ -353,7 +353,7 @@ }

use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -impl<D: DataMut> ReaderFrom for GGSWCiphertext<D> { +impl<D: DataMut> ReaderFrom for GGSW<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?); self.base2k = Base2K(reader.read_u32::<LittleEndian>()?);

@@ -362,7 +362,7 @@ self.data.read_from(reader)

} } -impl<D: DataRef> WriterTo for GGSWCiphertext<D> { +impl<D: DataRef> WriterTo for GGSW<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { writer.write_u32::<LittleEndian>(self.k.into())?; writer.write_u32::<LittleEndian>(self.base2k.into())?;

@@ -371,34 +371,32 @@ self.data.write_to(writer)

} } -pub trait GGSWCiphertextToMut { - fn to_mut(&mut self) -> GGSWCiphertext<&mut [u8]>; +pub trait GGSWToMut { + fn to_mut(&mut self) -> GGSW<&mut [u8]>; } -impl<D: DataMut> GGSWCiphertextToMut for GGSWCiphertext<D> { - fn to_mut(&mut self) -> GGSWCiphertext<&mut [u8]> { - GGSWCiphertext::builder() - .base2k(self.base2k()) - .dsize(self.dsize()) - .k(self.k()) - .data(self.data.to_mut()) - .build() - .unwrap() +impl<D: DataMut> GGSWToMut for GGSW<D> { + fn to_mut(&mut self) -> GGSW<&mut [u8]> { + GGSW { + dsize: self.dsize, + k: self.k, + base2k: self.base2k, + data: self.data.to_mut(), + } } } -pub trait GGSWCiphertextToRef { - fn to_ref(&self) -> GGSWCiphertext<&[u8]>; +pub trait GGSWToRef { + fn to_ref(&self) -> GGSW<&[u8]>; } -impl<D: DataRef> GGSWCiphertextToRef for GGSWCiphertext<D> { - fn to_ref(&self) -> GGSWCiphertext<&[u8]> { - GGSWCiphertext::builder() - .base2k(self.base2k()) - .dsize(self.dsize()) - .k(self.k()) - .data(self.data.to_ref()) - .build() - .unwrap() +impl<D: DataRef> GGSWToRef for GGSW<D> { + fn to_ref(&self) -> GGSW<&[u8]> { + GGSW { + dsize: self.dsize, + k: self.k, + base2k: self.base2k, + data: self.data.to_ref(), + } } }
M poulpy-core/src/layouts/glwe_ct.rs → poulpy-core/src/layouts/glwe_ct.rs

@@ -253,18 +253,33 @@ VecZnx::alloc_bytes(n.into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize)

} } +impl<D: DataMut> ReaderFrom for GLWECiphertext<D> { + fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { + self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?); + self.base2k = Base2K(reader.read_u32::<LittleEndian>()?); + self.data.read_from(reader) + } +} + +impl<D: DataRef> WriterTo for GLWECiphertext<D> { + fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { + writer.write_u32::<LittleEndian>(self.k.0)?; + writer.write_u32::<LittleEndian>(self.base2k.0)?; + self.data.write_to(writer) + } +} + pub trait GLWECiphertextToRef { fn to_ref(&self) -> GLWECiphertext<&[u8]>; } impl<D: DataRef> GLWECiphertextToRef for GLWECiphertext<D> { fn to_ref(&self) -> GLWECiphertext<&[u8]> { - GLWECiphertext::builder() - .k(self.k()) - .base2k(self.base2k()) - .data(self.data.to_ref()) - .build() - .unwrap() + GLWECiphertext { + k: self.k, + base2k: self.base2k, + data: self.data.to_ref(), + } } }

@@ -274,27 +289,10 @@ }

impl<D: DataMut> GLWECiphertextToMut for GLWECiphertext<D> { fn to_mut(&mut self) -> GLWECiphertext<&mut [u8]> { - GLWECiphertext::builder() - .k(self.k()) - .base2k(self.base2k()) - .data(self.data.to_mut()) - .build() - .unwrap() - } -} - -impl<D: DataMut> ReaderFrom for GLWECiphertext<D> { - fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { - self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?); - self.base2k = Base2K(reader.read_u32::<LittleEndian>()?); - self.data.read_from(reader) - } -} - -impl<D: DataRef> WriterTo for GLWECiphertext<D> { - fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { - writer.write_u32::<LittleEndian>(self.k.0)?; - writer.write_u32::<LittleEndian>(self.base2k.0)?; - self.data.write_to(writer) + GLWECiphertext { + k: self.k, + base2k: self.base2k, + data: self.data.to_mut(), + } } }
M poulpy-core/src/layouts/glwe_to_lwe_ksk.rs → poulpy-core/src/layouts/glwe_to_lwe_ksk.rs

@@ -3,7 +3,10 @@ layouts::{Data, DataMut, DataRef, FillUniform, ReaderFrom, WriterTo},

source::Source, }; -use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision}; +use crate::layouts::{ + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyToMut, GLWESwitchingKeyToRef, LWEInfos, + Rank, TorusPrecision, +}; use std::fmt;

@@ -56,9 +59,9 @@ }

/// A special [GLWESwitchingKey] required to for the conversion from [GLWECiphertext] to [LWECiphertext]. #[derive(PartialEq, Eq, Clone)] -pub struct GLWEToLWEKey<D: Data>(pub(crate) GGLWESwitchingKey<D>); +pub struct GLWEToLWESwitchingKey<D: Data>(pub(crate) GLWESwitchingKey<D>); -impl<D: Data> LWEInfos for GLWEToLWEKey<D> { +impl<D: Data> LWEInfos for GLWEToLWESwitchingKey<D> { fn base2k(&self) -> Base2K { self.0.base2k() }

@@ -76,12 +79,12 @@ self.0.size()

} } -impl<D: Data> GLWEInfos for GLWEToLWEKey<D> { +impl<D: Data> GLWEInfos for GLWEToLWESwitchingKey<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for GLWEToLWEKey<D> { +impl<D: Data> GGLWEInfos for GLWEToLWESwitchingKey<D> { fn rank_in(&self) -> Rank { self.0.rank_in() }

@@ -99,37 +102,37 @@ self.0.dnum()

} } -impl<D: DataRef> fmt::Debug for GLWEToLWEKey<D> { +impl<D: DataRef> fmt::Debug for GLWEToLWESwitchingKey<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for GLWEToLWEKey<D> { +impl<D: DataMut> FillUniform for GLWEToLWESwitchingKey<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.0.fill_uniform(log_bound, source); } } -impl<D: DataRef> fmt::Display for GLWEToLWEKey<D> { +impl<D: DataRef> fmt::Display for GLWEToLWESwitchingKey<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "(GLWEToLWESwitchingKey) {}", self.0) } } -impl<D: DataMut> ReaderFrom for GLWEToLWEKey<D> { +impl<D: DataMut> ReaderFrom for GLWEToLWESwitchingKey<D> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { self.0.read_from(reader) } } -impl<D: DataRef> WriterTo for GLWEToLWEKey<D> { +impl<D: DataRef> WriterTo for GLWEToLWESwitchingKey<D> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { self.0.write_to(writer) } } -impl GLWEToLWEKey<Vec<u8>> { +impl GLWEToLWESwitchingKey<Vec<u8>> { pub fn alloc<A>(infos: &A) -> Self where A: GGLWEInfos,

@@ -144,11 +147,11 @@ infos.dsize().0,

1, "dsize > 1 is not supported for GLWEToLWESwitchingKey" ); - Self(GGLWESwitchingKey::alloc(infos)) + Self(GLWESwitchingKey::alloc(infos)) } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self { - Self(GGLWESwitchingKey::alloc_with( + Self(GLWESwitchingKey::alloc_with( n, base2k, k,

@@ -173,10 +176,36 @@ infos.dsize().0,

1, "dsize > 1 is not supported for GLWEToLWESwitchingKey" ); - GGLWESwitchingKey::alloc_bytes(infos) + GLWESwitchingKey::alloc_bytes(infos) } pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize { - GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rank_in, Rank(1), dnum, Dsize(1)) + GLWESwitchingKey::alloc_bytes_with(n, base2k, k, rank_in, Rank(1), dnum, Dsize(1)) + } +} + +pub trait GLWEToLWESwitchingKeyToRef { + fn to_ref(&self) -> GLWEToLWESwitchingKey<&[u8]>; +} + +impl<D: DataRef> GLWEToLWESwitchingKeyToRef for GLWEToLWESwitchingKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToRef, +{ + fn to_ref(&self) -> GLWEToLWESwitchingKey<&[u8]> { + GLWEToLWESwitchingKey(self.0.to_ref()) + } +} + +pub trait GLWEToLWESwitchingKeyToMut { + fn to_mut(&mut self) -> GLWEToLWESwitchingKey<&mut [u8]>; +} + +impl<D: DataMut> GLWEToLWESwitchingKeyToMut for GLWEToLWESwitchingKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToMut, +{ + fn to_mut(&mut self) -> GLWEToLWESwitchingKey<&mut [u8]> { + GLWEToLWESwitchingKey(self.0.to_mut()) } }
M poulpy-core/src/layouts/lwe_ct.rs → poulpy-core/src/layouts/lwe_ct.rs

@@ -27,6 +27,11 @@ }

} } +pub trait SetLWEInfos { + fn set_k(&mut self, k: TorusPrecision); + fn set_base2k(&mut self, base2k: Base2K); +} + #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWECiphertextLayout { pub n: Degree,

@@ -47,7 +52,6 @@ fn n(&self) -> Degree {

self.n } } - #[derive(PartialEq, Eq, Clone)] pub struct LWECiphertext<D: Data> { pub(crate) data: Zn<D>,

@@ -69,6 +73,16 @@ }

fn size(&self) -> usize { self.data.size() + } +} + +impl<D: Data> SetLWEInfos for LWECiphertext<D> { + fn set_base2k(&mut self, base2k: Base2K) { + self.base2k = base2k + } + + fn set_k(&mut self, k: TorusPrecision) { + self.k = k } }

@@ -221,12 +235,11 @@ }

impl<D: DataRef> LWECiphertextToRef for LWECiphertext<D> { fn to_ref(&self) -> LWECiphertext<&[u8]> { - LWECiphertext::builder() - .base2k(self.base2k()) - .k(self.k()) - .data(self.data.to_ref()) - .build() - .unwrap() + LWECiphertext { + k: self.k, + base2k: self.base2k, + data: self.data.to_ref(), + } } }

@@ -237,12 +250,11 @@ }

impl<D: DataMut> LWECiphertextToMut for LWECiphertext<D> { fn to_mut(&mut self) -> LWECiphertext<&mut [u8]> { - LWECiphertext::builder() - .base2k(self.base2k()) - .k(self.k()) - .data(self.data.to_mut()) - .build() - .unwrap() + LWECiphertext { + k: self.k, + base2k: self.base2k, + data: self.data.to_mut(), + } } }
M poulpy-core/src/layouts/lwe_ksk.rs → poulpy-core/src/layouts/lwe_ksk.rs

@@ -5,7 +5,10 @@ layouts::{Data, DataMut, DataRef, FillUniform, ReaderFrom, WriterTo},

source::Source, }; -use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision}; +use crate::layouts::{ + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyToMut, GLWESwitchingKeyToRef, LWEInfos, + Rank, TorusPrecision, +}; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWESwitchingKeyLayout {

@@ -54,7 +57,7 @@ }

} #[derive(PartialEq, Eq, Clone)] -pub struct LWESwitchingKey<D: Data>(pub(crate) GGLWESwitchingKey<D>); +pub struct LWESwitchingKey<D: Data>(pub(crate) GLWESwitchingKey<D>); impl<D: Data> LWEInfos for LWESwitchingKey<D> { fn base2k(&self) -> Base2K {

@@ -118,11 +121,11 @@ infos.rank_out().0,

1, "rank_out > 1 is not supported for LWESwitchingKey" ); - Self(GGLWESwitchingKey::alloc(infos)) + Self(GLWESwitchingKey::alloc(infos)) } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self { - Self(GGLWESwitchingKey::alloc_with( + Self(GLWESwitchingKey::alloc_with( n, base2k, k,

@@ -152,11 +155,11 @@ infos.rank_out().0,

1, "rank_out > 1 is not supported for LWESwitchingKey" ); - GGLWESwitchingKey::alloc_bytes(infos) + GLWESwitchingKey::alloc_bytes(infos) } pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize { - GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), Rank(1), dnum, Dsize(1)) + GLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), Rank(1), dnum, Dsize(1)) } }

@@ -189,3 +192,29 @@ fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {

self.0.write_to(writer) } } + +pub trait LWEToLWEKeyToRef { + fn to_ref(&self) -> LWESwitchingKey<&[u8]>; +} + +impl<D: DataRef> LWEToLWEKeyToRef for LWESwitchingKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToRef, +{ + fn to_ref(&self) -> LWESwitchingKey<&[u8]> { + LWESwitchingKey(self.0.to_ref()) + } +} + +pub trait LWEToLWEKeyToMut { + fn to_mut(&mut self) -> LWESwitchingKey<&mut [u8]>; +} + +impl<D: DataMut> LWEToLWEKeyToMut for LWESwitchingKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToMut, +{ + fn to_mut(&mut self) -> LWESwitchingKey<&mut [u8]> { + LWESwitchingKey(self.0.to_mut()) + } +}
M poulpy-core/src/layouts/lwe_sk.rs → poulpy-core/src/layouts/lwe_sk.rs

@@ -1,5 +1,5 @@

use poulpy_hal::{ - layouts::{Data, DataMut, DataRef, ScalarZnx, ZnxInfos, ZnxView, ZnxZero}, + layouts::{Data, DataMut, DataRef, ScalarZnx, ScalarZnxToMut, ScalarZnxToRef, ZnxInfos, ZnxView, ZnxZero}, source::Source, };

@@ -84,3 +84,29 @@ self.data.zero();

self.dist = Distribution::ZERO; } } + +pub trait LWESecretToRef { + fn to_ref(&self) -> LWESecret<&[u8]>; +} + +impl<D: DataRef> LWESecretToRef for LWESecret<D> { + fn to_ref(&self) -> LWESecret<&[u8]> { + LWESecret { + dist: self.dist, + data: self.data.to_ref(), + } + } +} + +pub trait LWESecretToMut { + fn to_mut(&mut self) -> LWESecret<&mut [u8]>; +} + +impl<D: DataMut> LWESecretToMut for LWESecret<D> { + fn to_mut(&mut self) -> LWESecret<&mut [u8]> { + LWESecret { + dist: self.dist, + data: self.data.to_mut(), + } + } +}
M poulpy-core/src/layouts/lwe_to_glwe_ksk.rs → poulpy-core/src/layouts/lwe_to_glwe_ksk.rs

@@ -5,7 +5,10 @@ layouts::{Data, DataMut, DataRef, FillUniform, ReaderFrom, WriterTo},

source::Source, }; -use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision}; +use crate::layouts::{ + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyToMut, GLWESwitchingKeyToRef, LWEInfos, + Rank, TorusPrecision, +}; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWEToGLWESwitchingKeyLayout {

@@ -55,7 +58,7 @@ }

} #[derive(PartialEq, Eq, Clone)] -pub struct LWEToGLWESwitchingKey<D: Data>(pub(crate) GGLWESwitchingKey<D>); +pub struct LWEToGLWESwitchingKey<D: Data>(pub(crate) GLWESwitchingKey<D>); impl<D: Data> LWEInfos for LWEToGLWESwitchingKey<D> { fn base2k(&self) -> Base2K {

@@ -143,11 +146,11 @@ infos.dsize().0,

1, "dsize > 1 is not supported for LWEToGLWESwitchingKey" ); - Self(GGLWESwitchingKey::alloc(infos)) + Self(GLWESwitchingKey::alloc(infos)) } pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self { - Self(GGLWESwitchingKey::alloc_with( + Self(GLWESwitchingKey::alloc_with( n, base2k, k,

@@ -172,10 +175,36 @@ infos.dsize().0,

1, "dsize > 1 is not supported for LWEToGLWESwitchingKey" ); - GGLWESwitchingKey::alloc_bytes(infos) + GLWESwitchingKey::alloc_bytes(infos) } pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_out: Rank) -> usize { - GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), rank_out, dnum, Dsize(1)) + GLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), rank_out, dnum, Dsize(1)) + } +} + +pub trait LWEToGLWESwitchingKeyToRef { + fn to_ref(&self) -> LWEToGLWESwitchingKey<&[u8]>; +} + +impl<D: DataRef> LWEToGLWESwitchingKeyToRef for LWEToGLWESwitchingKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToRef, +{ + fn to_ref(&self) -> LWEToGLWESwitchingKey<&[u8]> { + LWEToGLWESwitchingKey(self.0.to_ref()) + } +} + +pub trait LWEToGLWESwitchingKeyToMut { + fn to_mut(&mut self) -> LWEToGLWESwitchingKey<&mut [u8]>; +} + +impl<D: DataMut> LWEToGLWESwitchingKeyToMut for LWEToGLWESwitchingKey<D> +where + GLWESwitchingKey<D>: GLWESwitchingKeyToMut, +{ + fn to_mut(&mut self) -> LWEToGLWESwitchingKey<&mut [u8]> { + LWEToGLWESwitchingKey(self.0.to_mut()) } }
M poulpy-core/src/layouts/mod.rs → poulpy-core/src/layouts/mod.rs

@@ -47,6 +47,7 @@ ZeroCols,

ZeroLimbs, ZeroRank, ZeroDigits, + VecZnxColsNotOne, } /// Newtype over `u32` with arithmetic and comparisons against same type and `u32`.
M poulpy-core/src/layouts/prepared/gglwe_atk.rs → poulpy-core/src/layouts/prepared/gglwe_atk.rs

@@ -4,23 +4,25 @@ layouts::{Backend, Data, DataMut, DataRef, Module, Scratch},

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKey, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc, PrepareScratchSpace}, + AutomorphismKeyToRef, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, + prepared::{ + GLWESwitchingKeyPrepareTmpBytes, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, + }, }; #[derive(PartialEq, Eq)] -pub struct GGLWEAutomorphismKeyPrepared<D: Data, B: Backend> { - pub(crate) key: GGLWESwitchingKeyPrepared<D, B>, +pub struct AutomorphismKeyPrepared<D: Data, B: Backend> { + pub(crate) key: GLWESwitchingKeyPrepared<D, B>, pub(crate) p: i64, } -impl<D: Data, B: Backend> GGLWEAutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> AutomorphismKeyPrepared<D, B> { pub fn p(&self) -> i64 { self.p } } -impl<D: Data, B: Backend> LWEInfos for GGLWEAutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> LWEInfos for AutomorphismKeyPrepared<D, B> { fn n(&self) -> Degree { self.key.n() }

@@ -38,13 +40,23 @@ self.key.size()

} } -impl<D: Data, B: Backend> GLWEInfos for GGLWEAutomorphismKeyPrepared<D, B> { +pub trait SetP { + fn set_p(&mut self, p: i64); +} + +impl<D: Data, B: Backend> SetP for AutomorphismKeyPrepared<D, B> { + fn set_p(&mut self, p: i64) { + self.p = p + } +} + +impl<D: Data, B: Backend> GLWEInfos for AutomorphismKeyPrepared<D, B> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data, B: Backend> GGLWEInfos for GGLWEAutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> GGLWEInfos for AutomorphismKeyPrepared<D, B> { fn rank_in(&self) -> Rank { self.key.rank_in() }

@@ -62,7 +74,7 @@ self.key.dnum()

} } -impl<B: Backend> GGLWEAutomorphismKeyPrepared<Vec<u8>, B> { +impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> { pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self where A: GGLWEInfos,

@@ -73,8 +85,8 @@ infos.rank_in(),

infos.rank_out(), "rank_in != rank_out is not supported for GGLWEAutomorphismKeyPrepared" ); - GGLWEAutomorphismKeyPrepared::<Vec<u8>, B> { - key: GGLWESwitchingKeyPrepared::alloc(module, infos), + AutomorphismKeyPrepared::<Vec<u8>, B> { + key: GLWESwitchingKeyPrepared::alloc(module, infos), p: 0, } }

@@ -83,8 +95,8 @@ pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self

where Module<B>: VmpPMatAlloc<B>, { - GGLWEAutomorphismKeyPrepared { - key: GGLWESwitchingKeyPrepared::alloc_with(module, base2k, k, rank, rank, dnum, dsize), + AutomorphismKeyPrepared { + key: GLWESwitchingKeyPrepared::alloc_with(module, base2k, k, rank, rank, dnum, dsize), p: 0, } }

@@ -99,43 +111,104 @@ infos.rank_in(),

infos.rank_out(), "rank_in != rank_out is not supported for GGLWEAutomorphismKeyPrepared" ); - GGLWESwitchingKeyPrepared::alloc_bytes(module, infos) + GLWESwitchingKeyPrepared::alloc_bytes(module, infos) } pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize where Module<B>: VmpPMatAllocBytes, { - GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rank, rank, dnum, dsize) + GLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rank, rank, dnum, dsize) } } -impl<B: Backend, A: GGLWEInfos> PrepareScratchSpace<B, A> for GGLWEAutomorphismKeyPrepared<Vec<u8>, B> +pub trait AutomorphismKeyPrepareTmpBytes { + fn automorphism_key_prepare_tmp_bytes<A>(&self, infos: &A) + where + A: GGLWEInfos; +} + +impl<B: Backend> AutomorphismKeyPrepareTmpBytes for Module<B> where - GGLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, + Module<B>: GLWESwitchingKeyPrepareTmpBytes, { - fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - GGLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) + fn automorphism_key_prepare_tmp_bytes<A>(&self, infos: &A) + where + A: GGLWEInfos, + { + self.glwe_switching_key_prepare_tmp_bytes(infos) + } +} + +impl<D: DataRef, B: Backend> AutomorphismKeyPrepared<D, B> { + pub fn prepare_tmp_bytes(&self, module: &Module<B>) -> usize + where + Module<B>: AutomorphismKeyPrepareTmpBytes, + { + module.automorphism_key_prepare_tmp_bytes(self); } } -impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWEAutomorphismKey<DR>> for GGLWEAutomorphismKeyPrepared<D, B> -where - Module<B>: VmpPrepare<B>, -{ - fn prepare(&mut self, module: &Module<B>, other: &GGLWEAutomorphismKey<DR>, scratch: &mut Scratch<B>) { - self.key.prepare(module, &other.key, scratch); +pub trait AutomorphismKeyPrepare<B: Backend> { + fn automorphism_key_prepare<R, O>(&self, res: &R, other: &O, scratch: &Scratch<B>) + where + R: AutomorphismKeyPreparedToMut<B>, + O: AutomorphismKeyToRef; +} + +impl<B: Backend> AutomorphismKeyPrepare<B> for Module<B> { + fn automorphism_key_prepare<R, O>(&self, res: &R, other: &O, scratch: &Scratch<B>) + where + R: AutomorphismKeyPreparedToMut<B>, + O: AutomorphismKeyToRef, + { + self.key.prepare(self, &other.to_ref().key, scratch); self.p = other.p; } } -impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> for GGLWEAutomorphismKey<D> +pub trait AutomorphismKeyPrepareAlloc<B: Backend> { + fn automorphism_key_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) -> AutomorphismKeyPrepared<Vec<u8>, B> + where + O: AutomorphismKeyToRef; +} + +impl<B: Backend> AutomorphismKeyPrepareAlloc<B> for Module<B> where Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>, { - fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWEAutomorphismKeyPrepared<Vec<u8>, B> { - let mut atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = GGLWEAutomorphismKeyPrepared::alloc(module, self); - atk_prepared.prepare(module, self, scratch); + fn automorphism_key_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) -> AutomorphismKeyPrepared<Vec<u8>, B> + where + O: AutomorphismKeyToRef, + { + let mut atk_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = AutomorphismKeyPrepared::alloc(self, &other.to_ref()); + atk_prepared.prepare(self, &other.to_ref(), scratch); atk_prepared } } + +pub trait AutomorphismKeyPreparedToMut<B: Backend> { + fn to_mut(&mut self) -> AutomorphismKeyPrepared<&mut [u8], B>; +} + +impl<D: DataMut, B: Backend> AutomorphismKeyPreparedToMut<B> for AutomorphismKeyPrepared<D, B> { + fn to_mut(&mut self) -> AutomorphismKeyPrepared<&mut [u8], B> { + AutomorphismKeyPrepared { + p: self.p, + key: self.key.to_mut(), + } + } +} + +pub trait AutomorphismKeyPreparedToRef<B: Backend> { + fn to_ref(&self) -> AutomorphismKeyPrepared<&[u8], B>; +} + +impl<D: DataRef, B: Backend> AutomorphismKeyPreparedToRef<B> for AutomorphismKeyPrepared<D, B> { + fn to_ref(&self) -> AutomorphismKeyPrepared<&[u8], B> { + AutomorphismKeyPrepared { + p: self.p, + key: self.key.to_ref(), + } + } +}
M poulpy-core/src/layouts/prepared/gglwe_ct.rs → poulpy-core/src/layouts/prepared/gglwe_ct.rs

@@ -1,23 +1,22 @@

use poulpy_hal::{ api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare, VmpPrepareTmpBytes}, - layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat, ZnxInfos}, + layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat, VmpPMatToMut, VmpPMatToRef, ZnxInfos}, oep::VmpPMatAllocBytesImpl, }; use crate::layouts::{ - Base2K, BuildError, Degree, Dnum, Dsize, GGLWECiphertext, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{Prepare, PrepareAlloc, PrepareScratchSpace}, + Base2K, BuildError, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToRef, GLWEInfos, LWEInfos, Rank, TorusPrecision, }; #[derive(PartialEq, Eq)] -pub struct GGLWECiphertextPrepared<D: Data, B: Backend> { +pub struct GGLWEPrepared<D: Data, B: Backend> { pub(crate) data: VmpPMat<D, B>, pub(crate) k: TorusPrecision, pub(crate) base2k: Base2K, pub(crate) dsize: Dsize, } -impl<D: Data, B: Backend> LWEInfos for GGLWECiphertextPrepared<D, B> { +impl<D: Data, B: Backend> LWEInfos for GGLWEPrepared<D, B> { fn n(&self) -> Degree { Degree(self.data.n() as u32) }

@@ -35,13 +34,13 @@ self.data.size()

} } -impl<D: Data, B: Backend> GLWEInfos for GGLWECiphertextPrepared<D, B> { +impl<D: Data, B: Backend> GLWEInfos for GGLWEPrepared<D, B> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data, B: Backend> GGLWEInfos for GGLWECiphertextPrepared<D, B> { +impl<D: Data, B: Backend> GGLWEInfos for GGLWEPrepared<D, B> { fn rank_in(&self) -> Rank { Rank(self.data.cols_in() as u32) }

@@ -59,17 +58,17 @@ Dnum(self.data.rows() as u32)

} } -pub struct GGLWECiphertextPreparedBuilder<D: Data, B: Backend> { +pub struct GGLWEPreparedBuilder<D: Data, B: Backend> { data: Option<VmpPMat<D, B>>, base2k: Option<Base2K>, k: Option<TorusPrecision>, dsize: Option<Dsize>, } -impl<D: Data, B: Backend> GGLWECiphertextPrepared<D, B> { +impl<D: Data, B: Backend> GGLWEPrepared<D, B> { #[inline] - pub fn builder() -> GGLWECiphertextPreparedBuilder<D, B> { - GGLWECiphertextPreparedBuilder { + pub fn builder() -> GGLWEPreparedBuilder<D, B> { + GGLWEPreparedBuilder { data: None, base2k: None, k: None,

@@ -78,7 +77,7 @@ }

} } -impl<B: Backend> GGLWECiphertextPreparedBuilder<Vec<u8>, B> { +impl<B: Backend> GGLWEPreparedBuilder<Vec<u8>, B> { #[inline] pub fn layout<A>(mut self, infos: &A) -> Self where

@@ -99,7 +98,7 @@ self

} } -impl<D: Data, B: Backend> GGLWECiphertextPreparedBuilder<D, B> { +impl<D: Data, B: Backend> GGLWEPreparedBuilder<D, B> { #[inline] pub fn data(mut self, data: VmpPMat<D, B>) -> Self { self.data = Some(data);

@@ -122,7 +121,7 @@ self.dsize = Some(dsize);

self } - pub fn build(self) -> Result<GGLWECiphertextPrepared<D, B>, BuildError> { + pub fn build(self) -> Result<GGLWEPrepared<D, B>, BuildError> { let data: VmpPMat<D, B> = self.data.ok_or(BuildError::MissingData)?; let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?; let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;

@@ -152,7 +151,7 @@ if data.size() == 0 {

return Err(BuildError::ZeroLimbs); } - Ok(GGLWECiphertextPrepared { + Ok(GGLWEPrepared { data, base2k, k,

@@ -161,7 +160,7 @@ })

} } -impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> { +impl<B: Backend> GGLWEPrepared<Vec<u8>, B> { pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self where A: GGLWEInfos,

@@ -260,12 +259,21 @@ module.vmp_pmat_alloc_bytes(dnum.into(), rank_in.into(), (rank_out + 1).into(), size)

} } -impl<B: Backend, A: GGLWEInfos> PrepareScratchSpace<B, A> for GGLWECiphertextPrepared<Vec<u8>, B> +pub trait GGLWEPrepareTmpBytes { + fn gglwe_prepare_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGLWEInfos; +} + +impl<B: Backend> GGLWEPrepareTmpBytes for Module<B> where Module<B>: VmpPrepareTmpBytes, { - fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - module.vmp_prepare_tmp_bytes( + fn gglwe_prepare_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGLWEInfos, + { + self.vmp_prepare_tmp_bytes( infos.dnum().into(), infos.rank_in().into(), (infos.rank() + 1).into(),

@@ -274,25 +282,106 @@ )

} } -impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWECiphertext<DR>> for GGLWECiphertextPrepared<D, B> +impl<B: Backend> GGLWEPrepared<Vec<u8>, B> { + pub fn prepare_tmp_bytes(&self, module: &Module<B>) + where + Module<B>: GGLWEPrepareTmpBytes, + { + module.gglwe_prepare_tmp_bytes(self) + } +} + +pub trait GGLWEPrepare<B: Backend> { + fn gglwe_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGLWEPreparedToMut<B>, + O: GGLWEToRef; +} + +impl<B: Backend> GGLWEPrepare<B> for Module<B> where Module<B>: VmpPrepare<B>, { - fn prepare(&mut self, module: &Module<B>, other: &GGLWECiphertext<DR>, scratch: &mut Scratch<B>) { - module.vmp_prepare(&mut self.data, &other.data, scratch); - self.k = other.k; - self.base2k = other.base2k; - self.dsize = other.dsize; + fn gglwe_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGLWEPreparedToMut<B>, + O: GGLWEToRef, + { + let mut res: GGLWEPrepared<&mut [u8], B> = self.to_mut(); + let other: GGLWE<&[u8]> = other.to_ref(); + + assert_eq!(res.n(), self.n() as u32); + assert_eq!(other.n(), self.n() as u32); + assert_eq!(res.base2k, other.base2k); + assert_eq!(res.k, other.k); + assert_eq!(res.dsize, other.dsize); + + self.vmp_prepare(&mut res.data, &other.data, scratch); + } +} + +impl<D: DataMut, B: Backend> GGLWEPrepared<D, B> +where + Module<B>: GGLWEPrepare<B>, +{ + fn prepare<O>(&mut self, module: &Module<B>, other: &O, scratch: &mut Scratch<B>) + where + O: GGLWEToRef, + { + module.gglwe_prepare(self, other, scratch); } } -impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWECiphertextPrepared<Vec<u8>, B>> for GGLWECiphertext<D> +pub trait GGLWEPrepareAlloc<B: Backend> { + fn gglwe_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) -> GGLWEPrepared<Vec<u8>, B>; +} + +impl<B: Backend> GGLWEPrepareAlloc<B> for Module<B> where Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>, { - fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWECiphertextPrepared<Vec<u8>, B> { - let mut atk_prepared: GGLWECiphertextPrepared<Vec<u8>, B> = GGLWECiphertextPrepared::alloc(module, self); - atk_prepared.prepare(module, self, scratch); - atk_prepared + fn gglwe_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) -> GGLWEPrepared<Vec<u8>, B> { + let mut ct_prepared: GGLWEPrepared<Vec<u8>, B> = GGLWEPrepared::alloc(self, &other.to_ref()); + ct_prepared.prepare(self, &other.to_ref(), scratch); + ct_prepared + } +} + +impl<D: DataRef> GGLWE<D> { + fn prepare_alloc<B: Backend>(&self, module: &Module<B>, scratch: &Scratch<B>) -> GGLWEPrepared<Vec<u8>, B> + where + Module<B>: GGLWEPrepareAlloc<B>, + { + module.gglwe_prepare_alloc(self, scratch) + } +} + +pub trait GGLWEPreparedToMut<B: Backend> { + fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B>; +} + +impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for GGLWEPrepared<D, B> { + fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> { + GGLWEPrepared { + k: self.k, + base2k: self.base2k, + dsize: self.dsize, + data: self.data.to_mut(), + } + } +} + +pub trait GGLWEPreparedToRef<B: Backend> { + fn to_ref(&self) -> GGLWEPrepared<&[u8], B>; +} + +impl<D: DataRef, B: Backend> GGLWEPreparedToRef<B> for GGLWEPrepared<D, B> { + fn to_ref(&self) -> GGLWEPrepared<&[u8], B> { + GGLWEPrepared { + k: self.k, + base2k: self.base2k, + dsize: self.dsize, + data: self.data.to_ref(), + } } }
M poulpy-core/src/layouts/prepared/gglwe_ksk.rs → poulpy-core/src/layouts/prepared/gglwe_ksk.rs

@@ -1,21 +1,36 @@

use poulpy_hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}, }; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{GGLWECiphertextPrepared, Prepare, PrepareAlloc, PrepareScratchSpace}, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, + prepared::{GGLWEPrepare, GGLWEPrepareTmpBytes, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef}, }; #[derive(PartialEq, Eq)] -pub struct GGLWESwitchingKeyPrepared<D: Data, B: Backend> { - pub(crate) key: GGLWECiphertextPrepared<D, B>, +pub struct GLWESwitchingKeyPrepared<D: Data, B: Backend> { + pub(crate) key: GGLWEPrepared<D, B>, pub(crate) sk_in_n: usize, // Degree of sk_in pub(crate) sk_out_n: usize, // Degree of sk_out } -impl<D: Data, B: Backend> LWEInfos for GGLWESwitchingKeyPrepared<D, B> { +pub(crate) trait GLWESwitchingKeyPreparedSetMetaData { + fn set_sk_in_n(&mut self, sk_in_n: usize); + fn set_sk_out_n(&mut self, sk_out_n: usize); +} + +impl<D: DataMut, B: Backend> GLWESwitchingKeyPreparedSetMetaData for GLWESwitchingKeyPrepared<D, B> { + fn set_sk_in_n(&mut self, sk_in_n: usize) { + self.sk_in_n = sk_in_n + } + + fn set_sk_out_n(&mut self, sk_out_n: usize) { + self.sk_out_n = self.sk_out_n + } +} + +impl<D: Data, B: Backend> LWEInfos for GLWESwitchingKeyPrepared<D, B> { fn n(&self) -> Degree { self.key.n() }

@@ -33,13 +48,13 @@ self.key.size()

} } -impl<D: Data, B: Backend> GLWEInfos for GGLWESwitchingKeyPrepared<D, B> { +impl<D: Data, B: Backend> GLWEInfos for GLWESwitchingKeyPrepared<D, B> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data, B: Backend> GGLWEInfos for GGLWESwitchingKeyPrepared<D, B> { +impl<D: Data, B: Backend> GGLWEInfos for GLWESwitchingKeyPrepared<D, B> { fn rank_in(&self) -> Rank { self.key.rank_in() }

@@ -57,15 +72,15 @@ self.key.dnum()

} } -impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> { +impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> { pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self where A: GGLWEInfos, Module<B>: VmpPMatAlloc<B>, { debug_assert_eq!(module.n() as u32, infos.n(), "module.n() != infos.n()"); - GGLWESwitchingKeyPrepared::<Vec<u8>, B> { - key: GGLWECiphertextPrepared::alloc(module, infos), + GLWESwitchingKeyPrepared::<Vec<u8>, B> { + key: GGLWEPrepared::alloc(module, infos), sk_in_n: 0, sk_out_n: 0, }

@@ -83,8 +98,8 @@ ) -> Self

where Module<B>: VmpPMatAlloc<B>, { - GGLWESwitchingKeyPrepared::<Vec<u8>, B> { - key: GGLWECiphertextPrepared::alloc_with(module, base2k, k, rank_in, rank_out, dnum, dsize), + GLWESwitchingKeyPrepared::<Vec<u8>, B> { + key: GGLWEPrepared::alloc_with(module, base2k, k, rank_in, rank_out, dnum, dsize), sk_in_n: 0, sk_out_n: 0, }

@@ -96,7 +111,7 @@ A: GGLWEInfos,

Module<B>: VmpPMatAllocBytes, { debug_assert_eq!(module.n() as u32, infos.n(), "module.n() != infos.n()"); - GGLWECiphertextPrepared::alloc_bytes(module, infos) + GGLWEPrepared::alloc_bytes(module, infos) } pub fn alloc_bytes_with(

@@ -111,37 +126,122 @@ ) -> usize

where Module<B>: VmpPMatAllocBytes, { - GGLWECiphertextPrepared::alloc_bytes_with(module, base2k, k, rank_in, rank_out, dnum, dsize) + GGLWEPrepared::alloc_bytes_with(module, base2k, k, rank_in, rank_out, dnum, dsize) } } -impl<B: Backend, A: GGLWEInfos> PrepareScratchSpace<B, A> for GGLWESwitchingKeyPrepared<Vec<u8>, B> +pub trait GLWESwitchingKeyPrepareTmpBytes { + fn glwe_switching_key_prepare_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGLWEInfos; +} + +impl<B: Backend> GLWESwitchingKeyPrepareTmpBytes for Module<B> where - GGLWECiphertextPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, + Module<B>: GGLWEPrepareTmpBytes, { - fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - GGLWECiphertextPrepared::prepare_scratch_space(module, infos) + fn glwe_switching_key_prepare_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGLWEInfos, + { + self.gglwe_prepare_tmp_bytes(infos) } } -impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWESwitchingKey<DR>> for GGLWESwitchingKeyPrepared<D, B> +impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> where - Module<B>: VmpPrepare<B>, + Module<B>: GGLWEPrepareTmpBytes, { - fn prepare(&mut self, module: &Module<B>, other: &GGLWESwitchingKey<DR>, scratch: &mut Scratch<B>) { - self.key.prepare(module, &other.key, scratch); - self.sk_in_n = other.sk_in_n; - self.sk_out_n = other.sk_out_n; + pub fn prepare_tmp_bytes(&self, module: &Module<B>) -> usize { + module.gglwe_prepare_tmp_bytes(self) } } -impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWESwitchingKeyPrepared<Vec<u8>, B>> for GGLWESwitchingKey<D> +pub trait GLWESwitchingKeyPrepare<B: Backend> { + fn glwe_switching_prepare<R, O>(&self, res: &R, other: &O, scratch: &mut Scratch<B>) + where + R: GLWESwitchingKeyPreparedToMut<B> + GLWESwitchingKeyPreparedSetMetaData, + O: GLWESwitchingKeyToRef; +} + +impl<B: Backend> GLWESwitchingKeyPrepare<B> for Module<B> where - Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>, + Module<B>: GGLWEPrepare<B>, +{ + fn glwe_switching_prepare<R, O>(&self, res: &R, other: &O, scratch: &mut Scratch<B>) + where + R: GLWESwitchingKeyPreparedToMut<B> + GLWESwitchingKeyPreparedSetMetaData, + O: GLWESwitchingKeyToRef, + { + self.gglwe_prepare(&res.to_mut(), other, scratch); + res.set_sk_in_n(other.sk_in_n); + res.set_sk_out_n(other.sk_out_n); + } +} + +impl<D: DataMut, B: Backend> GLWESwitchingKeyPrepared<D, B> { + pub fn prepare<O>(&mut self, module: &Module<B>, other: &O, scratch: &mut Scratch<B>) + where + O: GLWESwitchingKeyToRef, + Module<B>: GLWESwitchingKeyPrepare<B>, + { + module.glwe_switching_prepare(self, other, scratch); + } +} + +pub trait GLWESwitchingKeyPrepareAlloc<B: Backend> { + fn glwe_switching_key_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) + where + O: GLWESwitchingKeyToRef; +} + +impl<B: Backend> GLWESwitchingKeyPrepareAlloc<B> for Module<B> +where + Module<B>: GLWESwitchingKeyPrepare<B>, { - fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWESwitchingKeyPrepared<Vec<u8>, B> { - let mut atk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = GGLWESwitchingKeyPrepared::alloc(module, self); - atk_prepared.prepare(module, self, scratch); - atk_prepared + fn glwe_switching_key_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) + where + O: GLWESwitchingKeyToRef, + { + let mut ct_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = GLWESwitchingKeyPrepared::alloc(self, self); + self.glwe_switching_prepare(&mut ct_prepared, other, scratch); + ct_prepared + } +} + +impl<D: DataRef> GLWESwitchingKey<D> { + pub fn prepare_alloc<B: Backend>(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GLWESwitchingKeyPrepared<Vec<u8>, B> + where + Module<B>: GLWESwitchingKeyPrepareAlloc<B>, + { + module.glwe_switching_key_prepare_alloc(self, scratch); + } +} + +pub trait GLWESwitchingKeyPreparedToMut<B: Backend> { + fn to_mut(&mut self) -> GLWESwitchingKeyPrepared<&mut [u8], B>; +} + +impl<D: DataMut, B: Backend> GLWESwitchingKeyPreparedToMut<B> for GLWESwitchingKeyPrepared<D, B> { + fn to_mut(&mut self) -> GLWESwitchingKeyPrepared<&mut [u8], B> { + GLWESwitchingKeyPrepared { + sk_in_n: self.sk_in_n, + sk_out_n: self.sk_out_n, + key: self.key.to_mut(), + } + } +} + +pub trait GLWESwitchingKeyPreparedToRef<B: Backend> { + fn to_ref(&self) -> GLWESwitchingKeyPrepared<&[u8], B>; +} + +impl<D: DataRef, B: Backend> GLWESwitchingKeyPreparedToRef<B> for GLWESwitchingKeyPrepared<D, B> { + fn to_ref(&self) -> GLWESwitchingKeyPrepared<&[u8], B> { + GLWESwitchingKeyPrepared { + sk_in_n: self.sk_in_n, + sk_out_n: self.sk_out_n, + key: self.key.to_ref(), + } } }
M poulpy-core/src/layouts/prepared/gglwe_tsk.rs → poulpy-core/src/layouts/prepared/gglwe_tsk.rs

@@ -1,19 +1,23 @@

use poulpy_hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}, }; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWETensorKey, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc, PrepareScratchSpace}, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision, + compressed::TensorKeyCompressedToMut, + prepared::{ + GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepareTmpBytes, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedToMut, + GLWESwitchingKeyPreparedToRef, + }, }; #[derive(PartialEq, Eq)] -pub struct GGLWETensorKeyPrepared<D: Data, B: Backend> { - pub(crate) keys: Vec<GGLWESwitchingKeyPrepared<D, B>>, +pub struct TensorKeyPrepared<D: Data, B: Backend> { + pub(crate) keys: Vec<GLWESwitchingKeyPrepared<D, B>>, } -impl<D: Data, B: Backend> LWEInfos for GGLWETensorKeyPrepared<D, B> { +impl<D: Data, B: Backend> LWEInfos for TensorKeyPrepared<D, B> { fn n(&self) -> Degree { self.keys[0].n() }

@@ -31,13 +35,13 @@ self.keys[0].size()

} } -impl<D: Data, B: Backend> GLWEInfos for GGLWETensorKeyPrepared<D, B> { +impl<D: Data, B: Backend> GLWEInfos for TensorKeyPrepared<D, B> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data, B: Backend> GGLWEInfos for GGLWETensorKeyPrepared<D, B> { +impl<D: Data, B: Backend> GGLWEInfos for TensorKeyPrepared<D, B> { fn rank_in(&self) -> Rank { self.rank_out() }

@@ -55,7 +59,7 @@ self.keys[0].dnum()

} } -impl<B: Backend> GGLWETensorKeyPrepared<Vec<u8>, B> { +impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> { pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self where A: GGLWEInfos,

@@ -80,10 +84,10 @@ pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self

where Module<B>: VmpPMatAlloc<B>, { - let mut keys: Vec<GGLWESwitchingKeyPrepared<Vec<u8>, B>> = Vec::new(); + let mut keys: Vec<GLWESwitchingKeyPrepared<Vec<u8>, B>> = Vec::new(); let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1); (0..pairs).for_each(|_| { - keys.push(GGLWESwitchingKeyPrepared::alloc_with( + keys.push(GLWESwitchingKeyPrepared::alloc_with( module, base2k, k,

@@ -109,7 +113,7 @@ );

let rank_out: usize = infos.rank_out().into(); let pairs: usize = (((rank_out + 1) * rank_out) >> 1).max(1); pairs - * GGLWESwitchingKeyPrepared::alloc_bytes_with( + * GLWESwitchingKeyPrepared::alloc_bytes_with( module, infos.base2k(), infos.k(),

@@ -125,13 +129,13 @@ where

Module<B>: VmpPMatAllocBytes, { let pairs: usize = (((rank.0 + 1) * rank.0) >> 1).max(1) as usize; - pairs * GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), rank, dnum, dsize) + pairs * GLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), rank, dnum, dsize) } } -impl<D: DataMut, B: Backend> GGLWETensorKeyPrepared<D, B> { +impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> { // Returns a mutable reference to GLWESwitchingKey_{s}(s[i] * s[j]) - pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWESwitchingKeyPrepared<D, B> { + pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GLWESwitchingKeyPrepared<D, B> { if i > j { std::mem::swap(&mut i, &mut j); };

@@ -140,9 +144,9 @@ &mut self.keys[i * rank + j - (i * (i + 1) / 2)]

} } -impl<D: DataRef, B: Backend> GGLWETensorKeyPrepared<D, B> { +impl<D: DataRef, B: Backend> TensorKeyPrepared<D, B> { // Returns a reference to GLWESwitchingKey_{s}(s[i] * s[j]) - pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWESwitchingKeyPrepared<D, B> { + pub fn at(&self, mut i: usize, mut j: usize) -> &GLWESwitchingKeyPrepared<D, B> { if i > j { std::mem::swap(&mut i, &mut j); };

@@ -151,40 +155,125 @@ &self.keys[i * rank + j - (i * (i + 1) / 2)]

} } -impl<B: Backend, A: GGLWEInfos> PrepareScratchSpace<B, A> for GGLWETensorKeyPrepared<Vec<u8>, B> +pub trait TensorKeyPrepareTmpBytes { + fn tensor_key_prepare_tmp_bytes<A>(&self, infos: &A) -> usize; +} + +impl<B: Backend> TensorKeyPrepareTmpBytes for Module<B> +where + Module<B>: GLWESwitchingKeyPrepareTmpBytes, +{ + fn tensor_key_prepare_tmp_bytes<A>(&self, infos: &A) -> usize { + self.glwe_switching_key_prepare_tmp_bytes(infos) + } +} + +impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> +where + Module<B>: TensorKeyPrepareTmpBytes, +{ + fn prepare_tmp_bytes<A>(&self, module: &Module<B>, infos: &A) -> usize + where + A: GGLWEInfos, + { + module.tensor_key_prepare_tmp_bytes(infos) + } +} + +pub trait TensorKeyPrepare<B: Backend> { + fn tensor_key_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &Scratch<B>) + where + R: TensorKeyPreparedToMut<B>, + O: TensorKeyToRef; +} + +impl<B: Backend> TensorKeyPrepare<B> for Module<B> +where + Module<B>: GLWESwitchingKeyPrepare<B>, +{ + fn tensor_key_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &Scratch<B>) + where + R: TensorKeyPreparedToMut<B>, + O: TensorKeyToRef, + { + let res = res.to_mut(); + let other = other.to_ref(); + + assert_eq!(self.keys.len(), other.keys.len()); + + for (a, b) in res.keys.iter_mut().zip(other.keys.iter()) { + self.glwe_switching_prepare(a, b, scratch); + } + } +} + +impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> where - GGLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, + Module<B>: TensorKeyPrepare<B>, { - fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - GGLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) + fn prepare<O>(&mut self, module: &Module<B>, other: &O, scratch: &mut Scratch<B>) + where + O: TensorKeyToRef, + { + module.tensor_key_prepare(self, other, scratch); + } +} + +pub trait TensorKeyPrepareAlloc<B: Backend> { + fn tensor_key_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) + where + O: TensorKeyToRef; +} + +impl<B: Backend> TensorKeyPrepareAlloc<B> for Module<B> +where + Module<B>: TensorKeyPrepare<B>, +{ + fn tensor_key_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) + where + O: TensorKeyToRef, + { + let mut ct_prepared: TensorKeyPrepared<Vec<u8>, B> = TensorKeyPrepared::alloc(self, other); + self.tensor_key_prepare(ct_prepared, other, scratch); + ct_prepared + } +} + +impl<D: DataRef> TensorKey<D> { + pub fn prepare_alloc<B: Backend>(&self, module: &Module<B>, scratch: &Scratch<B>) + where + Module<B>: TensorKeyPrepareAlloc<B>, + { + module.tensor_key_prepare_alloc(self, scratch); } } -impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWETensorKey<DR>> for GGLWETensorKeyPrepared<D, B> +pub trait TensorKeyPreparedToMut<B: Backend> { + fn to_mut(&mut self) -> TensorKeyPrepared<&mut [u8], B>; +} + +impl<D: DataMut, B: Backend> TensorKeyPreparedToMut<B> for TensorKeyPrepared<D, B> where - Module<B>: VmpPrepare<B>, + GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToMut<B>, { - fn prepare(&mut self, module: &Module<B>, other: &GGLWETensorKey<DR>, scratch: &mut Scratch<B>) { - #[cfg(debug_assertions)] - { - assert_eq!(self.keys.len(), other.keys.len()); + fn to_mut(&mut self) -> TensorKeyPrepared<&mut [u8], B> { + TensorKeyPrepared { + keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(), } - self.keys - .iter_mut() - .zip(other.keys.iter()) - .for_each(|(a, b)| { - a.prepare(module, b, scratch); - }); } } -impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWETensorKeyPrepared<Vec<u8>, B>> for GGLWETensorKey<D> +pub trait TensorKeyPreparedToRef<B: Backend> { + fn to_ref(&self) -> TensorKeyPrepared<&[u8], B>; +} + +impl<D: DataRef, B: Backend> TensorKeyPreparedToRef<B> for TensorKeyPrepared<D, B> where - Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>, + GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToRef<B>, { - fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWETensorKeyPrepared<Vec<u8>, B> { - let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = GGLWETensorKeyPrepared::alloc(module, self); - tsk_prepared.prepare(module, self, scratch); - tsk_prepared + fn to_ref(&self) -> TensorKeyPrepared<&[u8], B> { + TensorKeyPrepared { + keys: self.keys.iter().map(|c| c.to_ref()).collect(), + } } }
M poulpy-core/src/layouts/prepared/ggsw_ct.rs → poulpy-core/src/layouts/prepared/ggsw_ct.rs

@@ -5,19 +5,18 @@ oep::VmpPMatAllocBytesImpl,

}; use crate::layouts::{ - Base2K, BuildError, Degree, Dnum, Dsize, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{Prepare, PrepareAlloc, PrepareScratchSpace}, + Base2K, BuildError, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GLWEInfos, LWEInfos, Rank, TorusPrecision, }; #[derive(PartialEq, Eq)] -pub struct GGSWCiphertextPrepared<D: Data, B: Backend> { +pub struct GGSWPrepared<D: Data, B: Backend> { pub(crate) data: VmpPMat<D, B>, pub(crate) k: TorusPrecision, pub(crate) base2k: Base2K, pub(crate) dsize: Dsize, } -impl<D: Data, B: Backend> LWEInfos for GGSWCiphertextPrepared<D, B> { +impl<D: Data, B: Backend> LWEInfos for GGSWPrepared<D, B> { fn n(&self) -> Degree { Degree(self.data.n() as u32) }

@@ -35,13 +34,13 @@ self.data.size()

} } -impl<D: Data, B: Backend> GLWEInfos for GGSWCiphertextPrepared<D, B> { +impl<D: Data, B: Backend> GLWEInfos for GGSWPrepared<D, B> { fn rank(&self) -> Rank { Rank(self.data.cols_out() as u32 - 1) } } -impl<D: Data, B: Backend> GGSWInfos for GGSWCiphertextPrepared<D, B> { +impl<D: Data, B: Backend> GGSWInfos for GGSWPrepared<D, B> { fn dsize(&self) -> Dsize { self.dsize }

@@ -58,7 +57,7 @@ k: Option<TorusPrecision>,

dsize: Option<Dsize>, } -impl<D: Data, B: Backend> GGSWCiphertextPrepared<D, B> { +impl<D: Data, B: Backend> GGSWPrepared<D, B> { #[inline] pub fn builder() -> GGSWCiphertextPreparedBuilder<D, B> { GGSWCiphertextPreparedBuilder {

@@ -129,7 +128,7 @@ self.dsize = Some(dsize);

self } - pub fn build(self) -> Result<GGSWCiphertextPrepared<D, B>, BuildError> { + pub fn build(self) -> Result<GGSWPrepared<D, B>, BuildError> { let data: VmpPMat<D, B> = self.data.ok_or(BuildError::MissingData)?; let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?; let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;

@@ -159,7 +158,7 @@ if data.size() == 0 {

return Err(BuildError::ZeroLimbs); } - Ok(GGSWCiphertextPrepared { + Ok(GGSWPrepared { data, base2k, k,

@@ -168,7 +167,7 @@ })

} } -impl<B: Backend> GGSWCiphertextPrepared<Vec<u8>, B> { +impl<B: Backend> GGSWPrepared<Vec<u8>, B> { pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self where A: GGSWInfos,

@@ -252,18 +251,27 @@ module.vmp_pmat_alloc_bytes(dnum.into(), (rank + 1).into(), (rank + 1).into(), size)

} } -impl<D: DataRef, B: Backend> GGSWCiphertextPrepared<D, B> { +impl<D: DataRef, B: Backend> GGSWPrepared<D, B> { pub fn data(&self) -> &VmpPMat<D, B> { &self.data } } -impl<B: Backend, A: GGSWInfos> PrepareScratchSpace<B, A> for GGSWCiphertextPrepared<Vec<u8>, B> +pub trait GGSWPrepareTmpBytes { + fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGSWInfos; +} + +impl<B: Backend> GGSWPrepareTmpBytes for Module<B> where Module<B>: VmpPrepareTmpBytes, { - fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - module.vmp_prepare_tmp_bytes( + fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGSWInfos, + { + self.vmp_prepare_tmp_bytes( infos.dnum().into(), (infos.rank() + 1).into(), (infos.rank() + 1).into(),

@@ -272,57 +280,110 @@ )

} } -impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGSWCiphertext<DR>> for GGSWCiphertextPrepared<D, B> +impl<B: Backend> GGSWPrepared<Vec<u8>, B> +where + Module<B>: GGSWPrepareTmpBytes, +{ + pub fn prepare_tmp_bytes<A>(&self, module: Module<B>, infos: &A) -> usize + where + A: GGSWInfos, + { + module.ggsw_prepare_tmp_bytes(self) + } +} + +pub trait GGSWPrepare<B: Backend> { + fn ggsw_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGSWPreparedToMut<B>, + O: GGSWToRef; +} + +impl<B: Backend> GGSWPrepare<B> for Module<B> where Module<B>: VmpPrepare<B>, { - fn prepare(&mut self, module: &Module<B>, other: &GGSWCiphertext<DR>, scratch: &mut Scratch<B>) { - module.vmp_prepare(&mut self.data, &other.data, scratch); - self.k = other.k; - self.base2k = other.base2k; - self.dsize = other.dsize; + fn ggsw_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGSWPreparedToMut<B>, + O: GGSWToRef, + { + let mut res: GGSWPrepared<&mut [u8], B> = res.to_mut(); + let other: GGSW<&[u8]> = other.to_ref(); + assert_eq!(res.k, other.k); + assert_eq!(res.base2k, other.base2k); + assert_eq!(res.dsize, other.dsize); + self.vmp_prepare(&mut res.data, &other.data, scratch); + } +} + +impl<D: DataMut, B: Backend> GGSWPrepared<D, B> +where + Module<B>: GGSWPrepare<B>, +{ + pub fn prepare<O>(&mut self, module: &Module<B>, other: &O, scratch: &mut Scratch<B>) + where + O: GGSWToRef, + { + module.ggsw_prepare(self, other, scratch); } } -impl<D: DataRef, B: Backend> PrepareAlloc<B, GGSWCiphertextPrepared<Vec<u8>, B>> for GGSWCiphertext<D> +pub trait GGSWPrepareAlloc<B: Backend> { + fn ggsw_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) + where + O: GGSWToRef; +} + +impl<B: Backend> GGSWPrepareAlloc<B> for Module<B> where - Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>, + Module<B>: GGSWPrepare<B>, { - fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGSWCiphertextPrepared<Vec<u8>, B> { - let mut ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = GGSWCiphertextPrepared::alloc(module, self); - ggsw_prepared.prepare(module, self, scratch); - ggsw_prepared + fn ggsw_prepare_alloc<O>(&self, other: &O, scratch: &mut Scratch<B>) + where + O: GGSWToRef, + { + let mut ct_prepared: GGSWPrepared<Vec<u8>, B> = GGSWPrepared::alloc(self, other); + self.ggsw_prepare(&mut ct_prepared, other, scratch); + ct_prepared + } +} + +impl<D: DataRef> GGSW<D> { + fn prepare_alloc<B: Backend>(&self, module: &Module<B>, scratch: &mut Scratch<B>) + where + Module<B>: GGSWPrepareAlloc<B>, + { + module.ggsw_prepare_alloc(self, scratch); } } -pub trait GGSWCiphertextPreparedToMut<B: Backend> { - fn to_ref(&mut self) -> GGSWCiphertextPrepared<&mut [u8], B>; +pub trait GGSWPreparedToMut<B: Backend> { + fn to_mut(&mut self) -> GGSWPrepared<&mut [u8], B>; } -impl<D: DataMut, B: Backend> GGSWCiphertextPreparedToMut<B> for GGSWCiphertextPrepared<D, B> { - fn to_ref(&mut self) -> GGSWCiphertextPrepared<&mut [u8], B> { - GGSWCiphertextPrepared::builder() - .base2k(self.base2k()) - .dsize(self.dsize()) - .k(self.k()) - .data(self.data.to_mut()) - .build() - .unwrap() +impl<D: DataMut, B: Backend> GGSWPreparedToMut<B> for GGSWPrepared<D, B> { + fn to_mut(&mut self) -> GGSWPrepared<&mut [u8], B> { + GGSWPrepared { + base2k: self.base2k, + k: self.k, + dsize: self.dsize, + data: self.data.to_mut(), + } } } pub trait GGSWCiphertextPreparedToRef<B: Backend> { - fn to_ref(&self) -> GGSWCiphertextPrepared<&[u8], B>; + fn to_ref(&self) -> GGSWPrepared<&[u8], B>; } -impl<D: DataRef, B: Backend> GGSWCiphertextPreparedToRef<B> for GGSWCiphertextPrepared<D, B> { - fn to_ref(&self) -> GGSWCiphertextPrepared<&[u8], B> { - GGSWCiphertextPrepared::builder() - .base2k(self.base2k()) - .dsize(self.dsize()) - .k(self.k()) - .data(self.data.to_ref()) - .build() - .unwrap() +impl<D: DataRef, B: Backend> GGSWCiphertextPreparedToRef<B> for GGSWPrepared<D, B> { + fn to_ref(&self) -> GGSWPrepared<&[u8], B> { + GGSWPrepared { + base2k: self.base2k, + k: self.k, + dsize: self.dsize, + data: self.data.to_mut(), + } } }
M poulpy-core/src/layouts/prepared/glwe_pk.rs → poulpy-core/src/layouts/prepared/glwe_pk.rs

@@ -6,10 +6,7 @@ };

use crate::{ dist::Distribution, - layouts::{ - Base2K, BuildError, Degree, GLWEInfos, GLWEPublicKey, LWEInfos, Rank, TorusPrecision, - prepared::{Prepare, PrepareAlloc, PrepareScratchSpace}, - }, + layouts::{Base2K, BuildError, Degree, GLWEInfos, GLWEPublicKey, LWEInfos, Rank, TorusPrecision}, }; #[derive(PartialEq, Eq)]
M poulpy-core/src/layouts/prepared/glwe_sk.rs → poulpy-core/src/layouts/prepared/glwe_sk.rs

@@ -5,10 +5,7 @@ };

use crate::{ dist::Distribution, - layouts::{ - Base2K, Degree, GLWEInfos, GLWESecret, LWEInfos, Rank, TorusPrecision, - prepared::{Prepare, PrepareAlloc, PrepareScratchSpace}, - }, + layouts::{Base2K, Degree, GLWEInfos, GLWESecret, LWEInfos, Rank, TorusPrecision}, }; pub struct GLWESecretPrepared<D: Data, B: Backend> {

@@ -128,11 +125,11 @@ }

} pub trait GLWESecretPreparedToMut<B: Backend> { - fn to_ref(&mut self) -> GLWESecretPrepared<&mut [u8], B>; + fn to_mut(&mut self) -> GLWESecretPrepared<&mut [u8], B>; } impl<D: DataMut, B: Backend> GLWESecretPreparedToMut<B> for GLWESecretPrepared<D, B> { - fn to_ref(&mut self) -> GLWESecretPrepared<&mut [u8], B> { + fn to_mut(&mut self) -> GLWESecretPrepared<&mut [u8], B> { GLWESecretPrepared { dist: self.dist, data: self.data.to_mut(),
M poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs → poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs

@@ -4,12 +4,12 @@ layouts::{Backend, Data, DataMut, DataRef, Module, Scratch},

}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWEKey, LWEInfos, Rank, TorusPrecision, - prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc, PrepareScratchSpace}, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKey, LWEInfos, Rank, TorusPrecision, + prepared::GLWESwitchingKeyPrepared, }; #[derive(PartialEq, Eq)] -pub struct GLWEToLWESwitchingKeyPrepared<D: Data, B: Backend>(pub(crate) GGLWESwitchingKeyPrepared<D, B>); +pub struct GLWEToLWESwitchingKeyPrepared<D: Data, B: Backend>(pub(crate) GLWESwitchingKeyPrepared<D, B>); impl<D: Data, B: Backend> LWEInfos for GLWEToLWESwitchingKeyPrepared<D, B> { fn base2k(&self) -> Base2K {

@@ -69,14 +69,14 @@ infos.dsize().0,

1, "dsize > 1 is not supported for GLWEToLWESwitchingKeyPrepared" ); - Self(GGLWESwitchingKeyPrepared::alloc(module, infos)) + Self(GLWESwitchingKeyPrepared::alloc(module, infos)) } pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self where Module<B>: VmpPMatAlloc<B>, { - Self(GGLWESwitchingKeyPrepared::alloc_with( + Self(GLWESwitchingKeyPrepared::alloc_with( module, base2k, k,

@@ -102,27 +102,27 @@ infos.dsize().0,

1, "dsize > 1 is not supported for GLWEToLWESwitchingKeyPrepared" ); - GGLWESwitchingKeyPrepared::alloc_bytes(module, infos) + GLWESwitchingKeyPrepared::alloc_bytes(module, infos) } pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize where Module<B>: VmpPMatAllocBytes, { - GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rank_in, Rank(1), dnum, Dsize(1)) + GLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rank_in, Rank(1), dnum, Dsize(1)) } } impl<B: Backend, A: GGLWEInfos> PrepareScratchSpace<B, A> for GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> where - GGLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, + GLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, { fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - GGLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) + GLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) } } -impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWEToLWESwitchingKeyPrepared<Vec<u8>, B>> for GLWEToLWEKey<D> +impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWEToLWESwitchingKeyPrepared<Vec<u8>, B>> for GLWEToLWESwitchingKey<D> where Module<B>: VmpPrepare<B> + VmpPMatAlloc<B>, {

@@ -133,11 +133,11 @@ ksk_prepared

} } -impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, GLWEToLWEKey<DR>> for GLWEToLWESwitchingKeyPrepared<DM, B> +impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, GLWEToLWESwitchingKey<DR>> for GLWEToLWESwitchingKeyPrepared<DM, B> where Module<B>: VmpPrepare<B>, { - fn prepare(&mut self, module: &Module<B>, other: &GLWEToLWEKey<DR>, scratch: &mut Scratch<B>) { + fn prepare(&mut self, module: &Module<B>, other: &GLWEToLWESwitchingKey<DR>, scratch: &mut Scratch<B>) { self.0.prepare(module, &other.0, scratch); } }
M poulpy-core/src/layouts/prepared/lwe_ksk.rs → poulpy-core/src/layouts/prepared/lwe_ksk.rs

@@ -5,11 +5,11 @@ };

use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, Rank, TorusPrecision, - prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc, PrepareScratchSpace}, + prepared::GLWESwitchingKeyPrepared, }; #[derive(PartialEq, Eq)] -pub struct LWESwitchingKeyPrepared<D: Data, B: Backend>(pub(crate) GGLWESwitchingKeyPrepared<D, B>); +pub struct LWESwitchingKeyPrepared<D: Data, B: Backend>(pub(crate) GLWESwitchingKeyPrepared<D, B>); impl<D: Data, B: Backend> LWEInfos for LWESwitchingKeyPrepared<D, B> { fn base2k(&self) -> Base2K {

@@ -73,14 +73,14 @@ infos.rank_out().0,

1, "rank_out > 1 is not supported for LWESwitchingKey" ); - Self(GGLWESwitchingKeyPrepared::alloc(module, infos)) + Self(GLWESwitchingKeyPrepared::alloc(module, infos)) } pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self where Module<B>: VmpPMatAlloc<B>, { - Self(GGLWESwitchingKeyPrepared::alloc_with( + Self(GLWESwitchingKeyPrepared::alloc_with( module, base2k, k,

@@ -111,23 +111,23 @@ infos.rank_out().0,

1, "rank_out > 1 is not supported for LWESwitchingKey" ); - GGLWESwitchingKeyPrepared::alloc_bytes(module, infos) + GLWESwitchingKeyPrepared::alloc_bytes(module, infos) } pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize where Module<B>: VmpPMatAllocBytes, { - GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), Rank(1), dnum, Dsize(1)) + GLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), Rank(1), dnum, Dsize(1)) } } impl<B: Backend, A: GGLWEInfos> PrepareScratchSpace<B, A> for LWESwitchingKeyPrepared<Vec<u8>, B> where - GGLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, + GLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, { fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - GGLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) + GLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) } }
M poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs → poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs

@@ -5,12 +5,12 @@ };

use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, Rank, TorusPrecision, - prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc, PrepareScratchSpace}, + prepared::GLWESwitchingKeyPrepared, }; /// A special [GLWESwitchingKey] required to for the conversion from [LWECiphertext] to [GLWECiphertext]. #[derive(PartialEq, Eq)] -pub struct LWEToGLWESwitchingKeyPrepared<D: Data, B: Backend>(pub(crate) GGLWESwitchingKeyPrepared<D, B>); +pub struct LWEToGLWESwitchingKeyPrepared<D: Data, B: Backend>(pub(crate) GLWESwitchingKeyPrepared<D, B>); impl<D: Data, B: Backend> LWEInfos for LWEToGLWESwitchingKeyPrepared<D, B> { fn base2k(&self) -> Base2K {

@@ -70,14 +70,14 @@ infos.dsize().0,

1, "dsize > 1 is not supported for LWEToGLWESwitchingKey" ); - Self(GGLWESwitchingKeyPrepared::alloc(module, infos)) + Self(GLWESwitchingKeyPrepared::alloc(module, infos)) } pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self where Module<B>: VmpPMatAlloc<B>, { - Self(GGLWESwitchingKeyPrepared::alloc_with( + Self(GLWESwitchingKeyPrepared::alloc_with( module, base2k, k,

@@ -103,23 +103,23 @@ infos.dsize().0,

1, "dsize > 1 is not supported for LWEToGLWESwitchingKey" ); - GGLWESwitchingKeyPrepared::alloc_bytes(module, infos) + GLWESwitchingKeyPrepared::alloc_bytes(module, infos) } pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_out: Rank) -> usize where Module<B>: VmpPMatAllocBytes, { - GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), rank_out, dnum, Dsize(1)) + GLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), rank_out, dnum, Dsize(1)) } } impl<B: Backend, A: GGLWEInfos> PrepareScratchSpace<B, A> for LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> where - GGLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, + GLWESwitchingKeyPrepared<Vec<u8>, B>: PrepareScratchSpace<B, A>, { fn prepare_scratch_space(module: &Module<B>, infos: &A) -> usize { - GGLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) + GLWESwitchingKeyPrepared::prepare_scratch_space(module, infos) } }
M poulpy-core/src/layouts/prepared/mod.rs → poulpy-core/src/layouts/prepared/mod.rs

@@ -19,16 +19,3 @@ pub use glwe_sk::*;

pub use glwe_to_lwe_ksk::*; pub use lwe_ksk::*; pub use lwe_to_glwe_ksk::*; -use poulpy_hal::layouts::{Backend, Module, Scratch}; - -pub trait PrepareScratchSpace<B: Backend, T> { - fn prepare_scratch_space(module: &Module<B>, infos: &T) -> usize; -} - -pub trait PrepareAlloc<B: Backend, T> { - fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> T; -} - -pub trait Prepare<B: Backend, T> { - fn prepare(&mut self, module: &Module<B>, other: &T, scratch: &mut Scratch<B>); -}
M poulpy-core/src/noise/gglwe_ct.rs → poulpy-core/src/noise/gglwe_ct.rs

@@ -8,9 +8,9 @@ layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned, ZnxZero},

oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, }; -use crate::layouts::{GGLWECiphertext, GGLWEInfos, GLWECiphertext, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared}; +use crate::layouts::{GGLWE, GGLWEInfos, GLWECiphertext, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared}; -impl<D: DataRef> GGLWECiphertext<D> { +impl<D: DataRef> GGLWE<D> { pub fn assert_noise<B, DataSk, DataWant>( &self, module: &Module<B>,
M poulpy-core/src/noise/ggsw_ct.rs → poulpy-core/src/noise/ggsw_ct.rs

@@ -9,11 +9,9 @@ layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned, VecZnxBig, VecZnxDft, ZnxZero},

oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, }; -use crate::layouts::{ - GGSWCiphertext, GGSWInfos, GLWECiphertext, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared, -}; +use crate::layouts::{GGSW, GGSWInfos, GLWECiphertext, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared}; -impl<D: DataRef> GGSWCiphertext<D> { +impl<D: DataRef> GGSW<D> { pub fn assert_noise<B, DataSk, DataScalar, F>( &self, module: &Module<B>,

@@ -87,7 +85,7 @@ });

} } -impl<D: DataRef> GGSWCiphertext<D> { +impl<D: DataRef> GGSW<D> { pub fn print_noise<B, DataSk, DataScalar>( &self, module: &Module<B>,
M poulpy-core/src/scratch.rs → poulpy-core/src/scratch.rs

@@ -6,11 +6,11 @@

use crate::{ dist::Distribution, layouts::{ - Degree, GGLWEAutomorphismKey, GGLWECiphertext, GGLWEInfos, GGLWESwitchingKey, GGLWETensorKey, GGSWCiphertext, GGSWInfos, - GLWECiphertext, GLWEInfos, GLWEPlaintext, GLWEPublicKey, GLWESecret, Rank, + AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGSW, GGSWInfos, GLWECiphertext, GLWEInfos, GLWEPlaintext, GLWEPublicKey, + GLWESecret, GLWESwitchingKey, Rank, TensorKey, prepared::{ - GGLWEAutomorphismKeyPrepared, GGLWECiphertextPrepared, GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared, - GGSWCiphertextPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared, + AutomorphismKeyPrepared, GGLWEPrepared, GGSWPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared, + GLWESwitchingKeyPrepared, TensorKeyPrepared, }, }, };

@@ -34,31 +34,31 @@ A: GLWEInfos;

} pub trait TakeGGLWE { - fn take_gglwe<A>(&mut self, infos: &A) -> (GGLWECiphertext<&mut [u8]>, &mut Self) + fn take_gglwe<A>(&mut self, infos: &A) -> (GGLWE<&mut [u8]>, &mut Self) where A: GGLWEInfos; } pub trait TakeGGLWEPrepared<B: Backend> { - fn take_gglwe_prepared<A>(&mut self, infos: &A) -> (GGLWECiphertextPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_prepared<A>(&mut self, infos: &A) -> (GGLWEPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos; } pub trait TakeGGSW { - fn take_ggsw<A>(&mut self, infos: &A) -> (GGSWCiphertext<&mut [u8]>, &mut Self) + fn take_ggsw<A>(&mut self, infos: &A) -> (GGSW<&mut [u8]>, &mut Self) where A: GGSWInfos; } pub trait TakeGGSWPrepared<B: Backend> { - fn take_ggsw_prepared<A>(&mut self, infos: &A) -> (GGSWCiphertextPrepared<&mut [u8], B>, &mut Self) + fn take_ggsw_prepared<A>(&mut self, infos: &A) -> (GGSWPrepared<&mut [u8], B>, &mut Self) where A: GGSWInfos; } pub trait TakeGGSWPreparedSlice<B: Backend> { - fn take_ggsw_prepared_slice<A>(&mut self, size: usize, infos: &A) -> (Vec<GGSWCiphertextPrepared<&mut [u8], B>>, &mut Self) + fn take_ggsw_prepared_slice<A>(&mut self, size: usize, infos: &A) -> (Vec<GGSWPrepared<&mut [u8], B>>, &mut Self) where A: GGSWInfos; }

@@ -84,37 +84,37 @@ A: GLWEInfos;

} pub trait TakeGLWESwitchingKey { - fn take_glwe_switching_key<A>(&mut self, infos: &A) -> (GGLWESwitchingKey<&mut [u8]>, &mut Self) + fn take_glwe_switching_key<A>(&mut self, infos: &A) -> (GLWESwitchingKey<&mut [u8]>, &mut Self) where A: GGLWEInfos; } pub trait TakeGGLWESwitchingKeyPrepared<B: Backend> { - fn take_gglwe_switching_key_prepared<A>(&mut self, infos: &A) -> (GGLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_switching_key_prepared<A>(&mut self, infos: &A) -> (GLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos; } pub trait TakeTensorKey { - fn take_tensor_key<A>(&mut self, infos: &A) -> (GGLWETensorKey<&mut [u8]>, &mut Self) + fn take_tensor_key<A>(&mut self, infos: &A) -> (TensorKey<&mut [u8]>, &mut Self) where A: GGLWEInfos; } pub trait TakeGGLWETensorKeyPrepared<B: Backend> { - fn take_gglwe_tensor_key_prepared<A>(&mut self, infos: &A) -> (GGLWETensorKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_tensor_key_prepared<A>(&mut self, infos: &A) -> (TensorKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos; } pub trait TakeGGLWEAutomorphismKey { - fn take_gglwe_automorphism_key<A>(&mut self, infos: &A) -> (GGLWEAutomorphismKey<&mut [u8]>, &mut Self) + fn take_gglwe_automorphism_key<A>(&mut self, infos: &A) -> (AutomorphismKey<&mut [u8]>, &mut Self) where A: GGLWEInfos; } pub trait TakeGGLWEAutomorphismKeyPrepared<B: Backend> { - fn take_gglwe_automorphism_key_prepared<A>(&mut self, infos: &A) -> (GGLWEAutomorphismKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_automorphism_key_prepared<A>(&mut self, infos: &A) -> (AutomorphismKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos; }

@@ -184,7 +184,7 @@ impl<B: Backend> TakeGGLWE for Scratch<B>

where Scratch<B>: TakeMatZnx, { - fn take_gglwe<A>(&mut self, infos: &A) -> (GGLWECiphertext<&mut [u8]>, &mut Self) + fn take_gglwe<A>(&mut self, infos: &A) -> (GGLWE<&mut [u8]>, &mut Self) where A: GGLWEInfos, {

@@ -196,7 +196,7 @@ (infos.rank_out() + 1).into(),

infos.size(), ); ( - GGLWECiphertext::builder() + GGLWE::builder() .base2k(infos.base2k()) .k(infos.k()) .dsize(infos.dsize())

@@ -212,7 +212,7 @@ impl<B: Backend> TakeGGLWEPrepared<B> for Scratch<B>

where Scratch<B>: TakeVmpPMat<B>, { - fn take_gglwe_prepared<A>(&mut self, infos: &A) -> (GGLWECiphertextPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_prepared<A>(&mut self, infos: &A) -> (GGLWEPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, {

@@ -224,7 +224,7 @@ (infos.rank_out() + 1).into(),

infos.size(), ); ( - GGLWECiphertextPrepared::builder() + GGLWEPrepared::builder() .base2k(infos.base2k()) .dsize(infos.dsize()) .k(infos.k())

@@ -240,7 +240,7 @@ impl<B: Backend> TakeGGSW for Scratch<B>

where Scratch<B>: TakeMatZnx, { - fn take_ggsw<A>(&mut self, infos: &A) -> (GGSWCiphertext<&mut [u8]>, &mut Self) + fn take_ggsw<A>(&mut self, infos: &A) -> (GGSW<&mut [u8]>, &mut Self) where A: GGSWInfos, {

@@ -252,7 +252,7 @@ (infos.rank() + 1).into(),

infos.size(), ); ( - GGSWCiphertext::builder() + GGSW::builder() .base2k(infos.base2k()) .dsize(infos.dsize()) .k(infos.k())

@@ -268,7 +268,7 @@ impl<B: Backend> TakeGGSWPrepared<B> for Scratch<B>

where Scratch<B>: TakeVmpPMat<B>, { - fn take_ggsw_prepared<A>(&mut self, infos: &A) -> (GGSWCiphertextPrepared<&mut [u8], B>, &mut Self) + fn take_ggsw_prepared<A>(&mut self, infos: &A) -> (GGSWPrepared<&mut [u8], B>, &mut Self) where A: GGSWInfos, {

@@ -280,7 +280,7 @@ (infos.rank() + 1).into(),

infos.size(), ); ( - GGSWCiphertextPrepared::builder() + GGSWPrepared::builder() .base2k(infos.base2k()) .dsize(infos.dsize()) .k(infos.k())

@@ -296,12 +296,12 @@ impl<B: Backend> TakeGGSWPreparedSlice<B> for Scratch<B>

where Scratch<B>: TakeGGSWPrepared<B>, { - fn take_ggsw_prepared_slice<A>(&mut self, size: usize, infos: &A) -> (Vec<GGSWCiphertextPrepared<&mut [u8], B>>, &mut Self) + fn take_ggsw_prepared_slice<A>(&mut self, size: usize, infos: &A) -> (Vec<GGSWPrepared<&mut [u8], B>>, &mut Self) where A: GGSWInfos, { let mut scratch: &mut Scratch<B> = self; - let mut cts: Vec<GGSWCiphertextPrepared<&mut [u8], B>> = Vec::with_capacity(size); + let mut cts: Vec<GGSWPrepared<&mut [u8], B>> = Vec::with_capacity(size); for _ in 0..size { let (ct, new_scratch) = scratch.take_ggsw_prepared(infos); scratch = new_scratch;

@@ -390,13 +390,13 @@ impl<B: Backend> TakeGLWESwitchingKey for Scratch<B>

where Scratch<B>: TakeMatZnx, { - fn take_glwe_switching_key<A>(&mut self, infos: &A) -> (GGLWESwitchingKey<&mut [u8]>, &mut Self) + fn take_glwe_switching_key<A>(&mut self, infos: &A) -> (GLWESwitchingKey<&mut [u8]>, &mut Self) where A: GGLWEInfos, { let (data, scratch) = self.take_gglwe(infos); ( - GGLWESwitchingKey { + GLWESwitchingKey { key: data, sk_in_n: 0, sk_out_n: 0,

@@ -410,13 +410,13 @@ impl<B: Backend> TakeGGLWESwitchingKeyPrepared<B> for Scratch<B>

where Scratch<B>: TakeGGLWEPrepared<B>, { - fn take_gglwe_switching_key_prepared<A>(&mut self, infos: &A) -> (GGLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_switching_key_prepared<A>(&mut self, infos: &A) -> (GLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, { let (data, scratch) = self.take_gglwe_prepared(infos); ( - GGLWESwitchingKeyPrepared { + GLWESwitchingKeyPrepared { key: data, sk_in_n: 0, sk_out_n: 0,

@@ -430,12 +430,12 @@ impl<B: Backend> TakeGGLWEAutomorphismKey for Scratch<B>

where Scratch<B>: TakeMatZnx, { - fn take_gglwe_automorphism_key<A>(&mut self, infos: &A) -> (GGLWEAutomorphismKey<&mut [u8]>, &mut Self) + fn take_gglwe_automorphism_key<A>(&mut self, infos: &A) -> (AutomorphismKey<&mut [u8]>, &mut Self) where A: GGLWEInfos, { let (data, scratch) = self.take_glwe_switching_key(infos); - (GGLWEAutomorphismKey { key: data, p: 0 }, scratch) + (AutomorphismKey { key: data, p: 0 }, scratch) } }

@@ -443,12 +443,12 @@ impl<B: Backend> TakeGGLWEAutomorphismKeyPrepared<B> for Scratch<B>

where Scratch<B>: TakeGGLWESwitchingKeyPrepared<B>, { - fn take_gglwe_automorphism_key_prepared<A>(&mut self, infos: &A) -> (GGLWEAutomorphismKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_automorphism_key_prepared<A>(&mut self, infos: &A) -> (AutomorphismKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, { let (data, scratch) = self.take_gglwe_switching_key_prepared(infos); - (GGLWEAutomorphismKeyPrepared { key: data, p: 0 }, scratch) + (AutomorphismKeyPrepared { key: data, p: 0 }, scratch) } }

@@ -456,7 +456,7 @@ impl<B: Backend> TakeTensorKey for Scratch<B>

where Scratch<B>: TakeMatZnx, { - fn take_tensor_key<A>(&mut self, infos: &A) -> (GGLWETensorKey<&mut [u8]>, &mut Self) + fn take_tensor_key<A>(&mut self, infos: &A) -> (TensorKey<&mut [u8]>, &mut Self) where A: GGLWEInfos, {

@@ -465,7 +465,7 @@ infos.rank_in(),

infos.rank_out(), "rank_in != rank_out is not supported for GGLWETensorKey" ); - let mut keys: Vec<GGLWESwitchingKey<&mut [u8]>> = Vec::new(); + let mut keys: Vec<GLWESwitchingKey<&mut [u8]>> = Vec::new(); let pairs: usize = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1) as usize; let mut scratch: &mut Scratch<B> = self;

@@ -483,7 +483,7 @@ let (gglwe, s) = scratch.take_glwe_switching_key(&ksk_infos);

scratch = s; keys.push(gglwe); } - (GGLWETensorKey { keys }, scratch) + (TensorKey { keys }, scratch) } }

@@ -491,7 +491,7 @@ impl<B: Backend> TakeGGLWETensorKeyPrepared<B> for Scratch<B>

where Scratch<B>: TakeVmpPMat<B>, { - fn take_gglwe_tensor_key_prepared<A>(&mut self, infos: &A) -> (GGLWETensorKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_tensor_key_prepared<A>(&mut self, infos: &A) -> (TensorKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, {

@@ -501,7 +501,7 @@ infos.rank_out(),

"rank_in != rank_out is not supported for GGLWETensorKeyPrepared" ); - let mut keys: Vec<GGLWESwitchingKeyPrepared<&mut [u8], B>> = Vec::new(); + let mut keys: Vec<GLWESwitchingKeyPrepared<&mut [u8], B>> = Vec::new(); let pairs: usize = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1) as usize; let mut scratch: &mut Scratch<B> = self;

@@ -519,6 +519,6 @@ let (gglwe, s) = scratch.take_gglwe_switching_key_prepared(&ksk_infos);

scratch = s; keys.push(gglwe); } - (GGLWETensorKeyPrepared { keys }, scratch) + (TensorKeyPrepared { keys }, scratch) } }
M poulpy-core/src/tests/serialization.rs → poulpy-core/src/tests/serialization.rs

@@ -1,12 +1,12 @@

use poulpy_hal::test_suite::serialization::test_reader_writer_interface; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKey, GGLWECiphertext, GGLWESwitchingKey, GGLWETensorKey, GGSWCiphertext, - GLWECiphertext, GLWEToLWEKey, LWECiphertext, LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TorusPrecision, + AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWECiphertext, GLWESwitchingKey, GLWEToLWESwitchingKey, + LWECiphertext, LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision, compressed::{ - GGLWEAutomorphismKeyCompressed, GGLWECiphertextCompressed, GGLWEKeyCompressed, GGLWETensorKeyCompressed, - GGSWCiphertextCompressed, GLWECiphertextCompressed, GLWEToLWESwitchingKeyCompressed, LWECiphertextCompressed, - LWESwitchingKeyCompressed, LWEToGLWESwitchingKeyCompressed, + AutomorphismKeyCompressed, GGLWECiphertextCompressed, GGSWCiphertextCompressed, GLWECiphertextCompressed, + GLWESwitchingKeyCompressed, GLWEToLWESwitchingKeyCompressed, LWECiphertextCompressed, LWESwitchingKeyCompressed, + LWEToGLWESwitchingKeyCompressed, TensorKeyCompressed, }, };

@@ -44,7 +44,7 @@ }

#[test] fn test_gglwe_serialization() { - let original: GGLWECiphertext<Vec<u8>> = GGLWECiphertext::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); + let original: GGLWE<Vec<u8>> = GGLWE::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); test_reader_writer_interface(original); }

@@ -57,44 +57,45 @@ }

#[test] fn test_glwe_switching_key_serialization() { - let original: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); + let original: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_glwe_switching_key_compressed_serialization() { - let original: GGLWEKeyCompressed<Vec<u8>> = GGLWEKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); + let original: GLWESwitchingKeyCompressed<Vec<u8>> = + GLWESwitchingKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_automorphism_key_serialization() { - let original: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let original: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_automorphism_key_compressed_serialization() { - let original: GGLWEAutomorphismKeyCompressed<Vec<u8>> = - GGLWEAutomorphismKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let original: AutomorphismKeyCompressed<Vec<u8>> = + AutomorphismKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_tensor_key_serialization() { - let original: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let original: TensorKey<Vec<u8>> = TensorKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_tensor_key_compressed_serialization() { - let original: GGLWETensorKeyCompressed<Vec<u8>> = GGLWETensorKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let original: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn glwe_to_lwe_switching_key_serialization() { - let original: GLWEToLWEKey<Vec<u8>> = GLWEToLWEKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM); + let original: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM); test_reader_writer_interface(original); }

@@ -132,7 +133,7 @@ }

#[test] fn ggsw_serialization() { - let original: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let original: GGSW<Vec<u8>> = GGSW::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); }
M poulpy-core/src/tests/test_suite/automorphism/gglwe_atk.rs → poulpy-core/src/tests/test_suite/automorphism/gglwe_atk.rs

@@ -18,8 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GGLWEInfos, GLWEPlaintext, GLWESecret, - prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, + AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GLWEPlaintext, GLWESecret, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, };

@@ -84,7 +84,7 @@ let dnum_in: usize = k_in / (base2k * di);

let dnum_out: usize = k_out / (base2k * di); let dnum_apply: usize = k_in.div_ceil(base2k * di); - let auto_key_in_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let auto_key_in_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_in.into(),

@@ -93,7 +93,7 @@ dsize: dsize_in.into(),

rank: rank.into(), }; - let auto_key_out_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let auto_key_out_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_out.into(),

@@ -102,7 +102,7 @@ dsize: dsize_in.into(),

rank: rank.into(), }; - let auto_key_apply_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let auto_key_apply_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_apply.into(),

@@ -111,18 +111,18 @@ dsize: di.into(),

rank: rank.into(), }; - let mut auto_key_in: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_in_infos); - let mut auto_key_out: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_out_infos); - let mut auto_key_apply: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_apply_infos); + let mut auto_key_in: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_in_infos); + let mut auto_key_out: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_out_infos); + let mut auto_key_apply: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_apply_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_in_infos) - | GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply_infos) - | GGLWEAutomorphismKey::automorphism_scratch_space( + AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_in_infos) + | AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply_infos) + | AutomorphismKey::automorphism_scratch_space( module, &auto_key_out_infos, &auto_key_in_infos,

@@ -153,8 +153,8 @@ &mut source_xe,

scratch.borrow(), ); - let mut auto_key_apply_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = - GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_apply_infos); + let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = + AutomorphismKeyPrepared::alloc(module, &auto_key_apply_infos); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());

@@ -293,7 +293,7 @@

let dnum_in: usize = k_in / (base2k * di); let dnum_apply: usize = k_in.div_ceil(base2k * di); - let auto_key_layout: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let auto_key_layout: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_in.into(),

@@ -302,7 +302,7 @@ dsize: dsize_in.into(),

rank: rank.into(), }; - let auto_key_apply_layout: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let auto_key_apply_layout: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_apply.into(),

@@ -311,17 +311,17 @@ dsize: di.into(),

rank: rank.into(), }; - let mut auto_key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_layout); - let mut auto_key_apply: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_apply_layout); + let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_layout); + let mut auto_key_apply: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_apply_layout); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key) - | GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply) - | GGLWEAutomorphismKey::automorphism_inplace_scratch_space(module, &auto_key, &auto_key_apply), + AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key) + | AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key_apply) + | AutomorphismKey::automorphism_inplace_scratch_space(module, &auto_key, &auto_key_apply), ); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(&auto_key);

@@ -347,8 +347,8 @@ &mut source_xe,

scratch.borrow(), ); - let mut auto_key_apply_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = - GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_apply_layout); + let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = + AutomorphismKeyPrepared::alloc(module, &auto_key_apply_layout); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
M poulpy-core/src/tests/test_suite/automorphism/ggsw_ct.rs → poulpy-core/src/tests/test_suite/automorphism/ggsw_ct.rs

@@ -19,8 +19,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWEAutomorphismKey, GGLWETensorKey, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWESecret, - prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, + AutomorphismKey, GGSW, GGSWCiphertextLayout, GLWESecret, TensorKey, TensorKeyLayout, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc, TensorKeyPrepared}, }, noise::noise_ggsw_keyswitch, };

@@ -110,7 +110,7 @@ dsize: dsize_in.into(),

rank: rank.into(), }; - let tensor_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout { + let tensor_key_layout: TensorKeyLayout = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k_tsk.into(),

@@ -119,7 +119,7 @@ dsize: di.into(),

rank: rank.into(), }; - let auto_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout { + let auto_key_layout: TensorKeyLayout = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -128,10 +128,10 @@ dsize: di.into(),

rank: rank.into(), }; - let mut ct_in: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_in_layout); - let mut ct_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_layout); - let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_layout); - let mut auto_key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_layout); + let mut ct_in: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_in_layout); + let mut ct_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_layout); + let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&tensor_key_layout); + let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_layout); let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); let mut source_xs: Source = Source::new([0u8; 32]);

@@ -139,10 +139,10 @@ let mut source_xe: Source = Source::new([0u8; 32]);

let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ct_in) - | GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key) - | GGLWETensorKey::encrypt_sk_scratch_space(module, &tensor_key) - | GGSWCiphertext::automorphism_scratch_space(module, &ct_out, &ct_in, &auto_key, &tensor_key), + GGSW::encrypt_sk_scratch_space(module, &ct_in) + | AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key) + | TensorKey::encrypt_sk_scratch_space(module, &tensor_key) + | GGSW::automorphism_scratch_space(module, &ct_out, &ct_in, &auto_key, &tensor_key), ); let var_xs: f64 = 0.5;

@@ -178,11 +178,11 @@ &mut source_xe,

scratch.borrow(), ); - let mut auto_key_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = - GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_layout); + let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = + AutomorphismKeyPrepared::alloc(module, &auto_key_layout); auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); - let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = GGLWETensorKeyPrepared::alloc(module, &tensor_key_layout); + let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = TensorKeyPrepared::alloc(module, &tensor_key_layout); tsk_prepared.prepare(module, &tensor_key, scratch.borrow()); ct_out.automorphism(

@@ -291,7 +291,7 @@ dsize: dsize_in.into(),

rank: rank.into(), }; - let tensor_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout { + let tensor_key_layout: TensorKeyLayout = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k_tsk.into(),

@@ -300,7 +300,7 @@ dsize: di.into(),

rank: rank.into(), }; - let auto_key_layout: GGLWETensorKeyLayout = GGLWETensorKeyLayout { + let auto_key_layout: TensorKeyLayout = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -309,9 +309,9 @@ dsize: di.into(),

rank: rank.into(), }; - let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_layout); - let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_layout); - let mut auto_key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&auto_key_layout); + let mut ct: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_layout); + let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&tensor_key_layout); + let mut auto_key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&auto_key_layout); let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); let mut source_xs: Source = Source::new([0u8; 32]);

@@ -319,10 +319,10 @@ let mut source_xe: Source = Source::new([0u8; 32]);

let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ct) - | GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &auto_key) - | GGLWETensorKey::encrypt_sk_scratch_space(module, &tensor_key) - | GGSWCiphertext::automorphism_inplace_scratch_space(module, &ct, &auto_key, &tensor_key), + GGSW::encrypt_sk_scratch_space(module, &ct) + | AutomorphismKey::encrypt_sk_scratch_space(module, &auto_key) + | TensorKey::encrypt_sk_scratch_space(module, &tensor_key) + | GGSW::automorphism_inplace_scratch_space(module, &ct, &auto_key, &tensor_key), ); let var_xs: f64 = 0.5;

@@ -358,11 +358,11 @@ &mut source_xe,

scratch.borrow(), ); - let mut auto_key_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = - GGLWEAutomorphismKeyPrepared::alloc(module, &auto_key_layout); + let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = + AutomorphismKeyPrepared::alloc(module, &auto_key_layout); auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); - let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = GGLWETensorKeyPrepared::alloc(module, &tensor_key_layout); + let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = TensorKeyPrepared::alloc(module, &tensor_key_layout); tsk_prepared.prepare(module, &tensor_key, scratch.borrow()); ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow());
M poulpy-core/src/tests/test_suite/automorphism/glwe_ct.rs → poulpy-core/src/tests/test_suite/automorphism/glwe_ct.rs

@@ -18,8 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, - prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, + AutomorphismKey, AutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, };

@@ -91,7 +91,7 @@ k: k_out.into(),

rank: rank.into(), }; - let autokey_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_out.into(),

@@ -100,7 +100,7 @@ dnum: dnum.into(),

dsize: di.into(), }; - let mut autokey: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&autokey_infos); + let mut autokey: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&autokey_infos); let mut ct_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&ct_in_infos); let mut ct_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&ct_out_infos); let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&ct_out_infos);

@@ -112,7 +112,7 @@

module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &autokey) + AutomorphismKey::encrypt_sk_scratch_space(module, &autokey) | GLWECiphertext::decrypt_scratch_space(module, &ct_out) | GLWECiphertext::encrypt_sk_scratch_space(module, &ct_in) | GLWECiphertext::automorphism_scratch_space(module, &ct_out, &ct_in, &autokey),

@@ -140,8 +140,8 @@ &mut source_xe,

scratch.borrow(), ); - let mut autokey_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = - GGLWEAutomorphismKeyPrepared::alloc(module, &autokey_infos); + let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = + AutomorphismKeyPrepared::alloc(module, &autokey_infos); autokey_prepared.prepare(module, &autokey, scratch.borrow()); ct_out.automorphism(module, &ct_in, &autokey_prepared, scratch.borrow());

@@ -226,7 +226,7 @@ k: k_out.into(),

rank: rank.into(), }; - let autokey_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let autokey_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -235,7 +235,7 @@ dnum: dnum.into(),

dsize: di.into(), }; - let mut autokey: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&autokey_infos); + let mut autokey: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&autokey_infos); let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&ct_out_infos); let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&ct_out_infos);

@@ -246,7 +246,7 @@

module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &autokey) + AutomorphismKey::encrypt_sk_scratch_space(module, &autokey) | GLWECiphertext::decrypt_scratch_space(module, &ct) | GLWECiphertext::encrypt_sk_scratch_space(module, &ct) | GLWECiphertext::automorphism_inplace_scratch_space(module, &ct, &autokey),

@@ -274,8 +274,7 @@ &mut source_xe,

scratch.borrow(), ); - let mut autokey_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = - GGLWEAutomorphismKeyPrepared::alloc(module, &autokey); + let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = AutomorphismKeyPrepared::alloc(module, &autokey); autokey_prepared.prepare(module, &autokey, scratch.borrow()); ct.automorphism_inplace(module, &autokey_prepared, scratch.borrow());
M poulpy-core/src/tests/test_suite/conversion.rs → poulpy-core/src/tests/test_suite/conversion.rs

@@ -16,9 +16,9 @@ source::Source,

}; use crate::layouts::{ - Base2K, Degree, Dnum, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, GLWEToLWEKey, GLWEToLWEKeyLayout, - LWECiphertext, LWECiphertextLayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, Rank, - TorusPrecision, + Base2K, Degree, Dnum, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, GLWEToLWEKeyLayout, + GLWEToLWESwitchingKey, LWECiphertext, LWECiphertextLayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey, + LWEToGLWESwitchingKeyLayout, Rank, TorusPrecision, prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc}, };

@@ -214,7 +214,7 @@ let mut source_xa: Source = Source::new([0u8; 32]);

let mut source_xe: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GLWEToLWEKey::encrypt_sk_scratch_space(module, &glwe_to_lwe_infos) + GLWEToLWESwitchingKey::encrypt_sk_scratch_space(module, &glwe_to_lwe_infos) | LWECiphertext::from_glwe_scratch_space(module, &lwe_infos, &glwe_infos, &glwe_to_lwe_infos) | GLWECiphertext::decrypt_scratch_space(module, &glwe_infos), );

@@ -241,7 +241,7 @@ &mut source_xe,

scratch.borrow(), ); - let mut ksk: GLWEToLWEKey<Vec<u8>> = GLWEToLWEKey::alloc(&glwe_to_lwe_infos); + let mut ksk: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(&glwe_to_lwe_infos); ksk.encrypt_sk( module,
M poulpy-core/src/tests/test_suite/encryption/gglwe_atk.rs → poulpy-core/src/tests/test_suite/encryption/gglwe_atk.rs

@@ -18,8 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWEInfos, GLWESecret, - compressed::{Decompress, GGLWEAutomorphismKeyCompressed}, + AutomorphismKey, AutomorphismKeyLayout, GLWEInfos, GLWESecret, + compressed::{AutomorphismKeyCompressed, Decompress}, prepared::{GLWESecretPrepared, PrepareAlloc}, }, };

@@ -75,7 +75,7 @@ for di in 1..dsize + 1 {

let n: usize = module.n(); let dnum: usize = (k_ksk - di * base2k) / (di * base2k); - let atk_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -84,13 +84,13 @@ dsize: di.into(),

rank: rank.into(), }; - let mut atk: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&atk_infos); + let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&atk_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xa: Source = Source::new([0u8; 32]); - let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWEAutomorphismKey::encrypt_sk_scratch_space( + let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_scratch_space( module, &atk_infos, ));

@@ -178,7 +178,7 @@ for di in 1..dsize + 1 {

let n: usize = module.n(); let dnum: usize = (k_ksk - di * base2k) / (di * base2k); - let atk_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let atk_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -187,12 +187,12 @@ dsize: di.into(),

rank: rank.into(), }; - let mut atk_compressed: GGLWEAutomorphismKeyCompressed<Vec<u8>> = GGLWEAutomorphismKeyCompressed::alloc(&atk_infos); + let mut atk_compressed: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc(&atk_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); - let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWEAutomorphismKey::encrypt_sk_scratch_space( + let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_scratch_space( module, &atk_infos, ));

@@ -217,7 +217,7 @@ );

}); let sk_out_prepared = sk_out.prepare_alloc(module, scratch.borrow()); - let mut atk: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&atk_infos); + let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&atk_infos); atk.decompress(module, &atk_compressed); atk.key
M poulpy-core/src/tests/test_suite/encryption/gglwe_ct.rs → poulpy-core/src/tests/test_suite/encryption/gglwe_ct.rs

@@ -17,8 +17,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWECiphertextLayout, GGLWESwitchingKey, GLWESecret, - compressed::{Decompress, GGLWEKeyCompressed}, + GGLWECiphertextLayout, GLWESecret, GLWESwitchingKey, + compressed::{Decompress, GLWESwitchingKeyCompressed}, prepared::{GLWESecretPrepared, PrepareAlloc}, }, };

@@ -81,13 +81,13 @@ rank_in: rank_in.into(),

rank_out: rank_out.into(), }; - let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_infos); + let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xa: Source = Source::new([0u8; 32]); - let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::encrypt_sk_scratch_space( + let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKey::encrypt_sk_scratch_space( module, &gglwe_infos, ));

@@ -173,12 +173,12 @@ rank_in: rank_in.into(),

rank_out: rank_out.into(), }; - let mut ksk_compressed: GGLWEKeyCompressed<Vec<u8>> = GGLWEKeyCompressed::alloc(&gglwe_infos); + let mut ksk_compressed: GLWESwitchingKeyCompressed<Vec<u8>> = GLWESwitchingKeyCompressed::alloc(&gglwe_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); - let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWEKeyCompressed::encrypt_sk_scratch_space( + let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKeyCompressed::encrypt_sk_scratch_space( module, &gglwe_infos, ));

@@ -201,7 +201,7 @@ &mut source_xe,

scratch.borrow(), ); - let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_infos); + let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_infos); ksk.decompress(module, &ksk_compressed); ksk.key
M poulpy-core/src/tests/test_suite/encryption/ggsw_ct.rs → poulpy-core/src/tests/test_suite/encryption/ggsw_ct.rs

@@ -17,53 +17,16 @@

use crate::{ encryption::SIGMA, layouts::{ - GGSWCiphertext, GGSWCiphertextLayout, GLWESecret, + GGSW, GGSWCiphertextLayout, GLWESecret, compressed::{Decompress, GGSWCiphertextCompressed}, prepared::{GLWESecretPrepared, PrepareAlloc}, }, }; -pub fn test_ggsw_encrypt_sk<B>(module: &Module<B>) +pub fn test_ggsw_encrypt_sk<B: Backend>(module: &Module<B>) where - Module<B>: VecZnxDftAllocBytes - + VecZnxBigNormalize<B> - + VecZnxDftApply<B> - + SvpApplyDftToDftInplace<B> - + VecZnxIdftApplyConsume<B> - + VecZnxNormalizeTmpBytes - + VecZnxFillUniform - + VecZnxSubInplace - + VecZnxAddInplace - + VecZnxNormalizeInplace<B> - + VecZnxAddNormal - + VecZnxNormalize<B> - + VecZnxSub - + SvpPrepare<B> - + SvpPPolAllocBytes - + SvpPPolAlloc<B> - + VecZnxBigAddSmallInplace<B> - + VecZnxAddScalarInplace - + VecZnxBigAllocBytes - + VecZnxBigAddInplace<B> - + VecZnxCopy - + VmpPMatAlloc<B> - + VmpPrepare<B> - + VecZnxBigAlloc<B> - + VecZnxDftAlloc<B> - + VecZnxBigNormalizeTmpBytes - + VecZnxIdftApplyTmpA<B>, - B: Backend - + TakeVecZnxDftImpl<B> - + TakeVecZnxBigImpl<B> - + TakeSvpPPolImpl<B> - + ScratchOwnedAllocImpl<B> - + ScratchOwnedBorrowImpl<B> - + ScratchAvailableImpl<B> - + TakeScalarZnxImpl<B> - + TakeVecZnxImpl<B> - + VecZnxDftAllocBytesImpl<B> - + VecZnxBigAllocBytesImpl<B> - + TakeSvpPPolImpl<B>, + ScratchOwned<B>: ScratchOwnedAlloc<B>, + Module<B>: SvpPrepare<B>, { let base2k: usize = 12; let k: usize = 54;

@@ -82,7 +45,7 @@ dsize: di.into(),

rank: rank.into(), }; - let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos); + let mut ct: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos); let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);

@@ -92,10 +55,7 @@ let mut source_xa: Source = Source::new([0u8; 32]);

pt_scalar.fill_ternary_hw(0, n, &mut source_xs); - let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGSWCiphertext::encrypt_sk_scratch_space( - module, - &ggsw_infos, - )); + let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGSW::encrypt_sk_scratch_space(module, &ggsw_infos)); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(&ggsw_infos); sk.fill_ternary_prob(0.5, &mut source_xs);

@@ -206,7 +166,7 @@ );

let noise_f = |_col_i: usize| -(k as f64) + SIGMA.log2() + 0.5; - let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos); + let mut ct: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos); ct.decompress(module, &ct_compressed); ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f);
M poulpy-core/src/tests/test_suite/encryption/glwe_tsk.rs → poulpy-core/src/tests/test_suite/encryption/glwe_tsk.rs

@@ -17,8 +17,8 @@

use crate::{ encryption::SIGMA, layouts::{ - Dsize, GGLWETensorKey, GGLWETensorKeyLayout, GLWEPlaintext, GLWESecret, - compressed::{Decompress, GGLWETensorKeyCompressed}, + Dsize, GLWEPlaintext, GLWESecret, TensorKey, TensorKeyLayout, + compressed::{Decompress, TensorKeyCompressed}, prepared::{GLWESecretPrepared, PrepareAlloc}, }, };

@@ -71,7 +71,7 @@ for rank in 1_usize..3 {

let n: usize = module.n(); let dnum: usize = k / base2k; - let tensor_key_infos = GGLWETensorKeyLayout { + let tensor_key_infos = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k.into(),

@@ -80,13 +80,13 @@ dsize: Dsize(1),

rank: rank.into(), }; - let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_infos); + let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&tensor_key_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xa: Source = Source::new([0u8; 32]); - let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWETensorKey::encrypt_sk_scratch_space( + let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(TensorKey::encrypt_sk_scratch_space( module, &tensor_key_infos, ));

@@ -190,7 +190,7 @@ for rank in 1_usize..3 {

let n: usize = module.n(); let dnum: usize = k / base2k; - let tensor_key_infos: GGLWETensorKeyLayout = GGLWETensorKeyLayout { + let tensor_key_infos: TensorKeyLayout = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k.into(),

@@ -199,12 +199,12 @@ dsize: Dsize(1),

rank: rank.into(), }; - let mut tensor_key_compressed: GGLWETensorKeyCompressed<Vec<u8>> = GGLWETensorKeyCompressed::alloc(&tensor_key_infos); + let mut tensor_key_compressed: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc(&tensor_key_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); - let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWETensorKeyCompressed::encrypt_sk_scratch_space( + let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(TensorKeyCompressed::encrypt_sk_scratch_space( module, &tensor_key_infos, ));

@@ -217,7 +217,7 @@ let seed_xa: [u8; 32] = [1u8; 32];

tensor_key_compressed.encrypt_sk(module, &sk, seed_xa, &mut source_xe, scratch.borrow()); - let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tensor_key_infos); + let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc(&tensor_key_infos); tensor_key.decompress(module, &tensor_key_compressed); let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&tensor_key_infos);
M poulpy-core/src/tests/test_suite/external_product/gglwe_ksk.rs → poulpy-core/src/tests/test_suite/external_product/gglwe_ksk.rs

@@ -18,8 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWESwitchingKey, GGLWESwitchingKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWESecret, - prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, + GGSW, GGSWCiphertextLayout, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout, + prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::noise_ggsw_product, };

@@ -81,7 +81,7 @@ let n: usize = module.n();

let dnum: usize = k_in.div_ceil(base2k * di); let dsize_in: usize = 1; - let gglwe_in_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_in_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_in.into(),

@@ -91,7 +91,7 @@ rank_in: rank_in.into(),

rank_out: rank_out.into(), }; - let gglwe_out_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_out_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_out.into(),

@@ -110,9 +110,9 @@ dsize: di.into(),

rank: rank_out.into(), }; - let mut ct_gglwe_in: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_in_infos); - let mut ct_gglwe_out: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_out_infos); - let mut ct_rgsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos); + let mut ct_gglwe_in: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_in_infos); + let mut ct_gglwe_out: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_out_infos); + let mut ct_rgsw: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos); let mut pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);

@@ -121,14 +121,14 @@ let mut source_xe: Source = Source::new([0u8; 32]);

let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_in_infos) - | GGLWESwitchingKey::external_product_scratch_space( + GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_in_infos) + | GLWESwitchingKey::external_product_scratch_space( module, &gglwe_out_infos, &gglwe_in_infos, &ggsw_infos, ) - | GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_infos), + | GGSW::encrypt_sk_scratch_space(module, &ggsw_infos), ); let r: usize = 1;

@@ -163,7 +163,7 @@ &mut source_xe,

scratch.borrow(), ); - let ct_rgsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow()); + let ct_rgsw_prepared: GGSWPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow()); // gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k) ct_gglwe_out.external_product(module, &ct_gglwe_in, &ct_rgsw_prepared, scratch.borrow());

@@ -263,7 +263,7 @@ let dnum: usize = k_out.div_ceil(base2k * di);

let dsize_in: usize = 1; - let gglwe_out_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_out_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_out.into(),

@@ -282,8 +282,8 @@ dsize: di.into(),

rank: rank_out.into(), }; - let mut ct_gglwe: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_out_infos); - let mut ct_rgsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos); + let mut ct_gglwe: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_out_infos); + let mut ct_rgsw: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos); let mut pt_rgsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);

@@ -292,9 +292,9 @@ let mut source_xe: Source = Source::new([0u8; 32]);

let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_out_infos) - | GGLWESwitchingKey::external_product_inplace_scratch_space(module, &gglwe_out_infos, &ggsw_infos) - | GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_infos), + GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_out_infos) + | GLWESwitchingKey::external_product_inplace_scratch_space(module, &gglwe_out_infos, &ggsw_infos) + | GGSW::encrypt_sk_scratch_space(module, &ggsw_infos), ); let r: usize = 1;

@@ -329,7 +329,7 @@ &mut source_xe,

scratch.borrow(), ); - let ct_rgsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow()); + let ct_rgsw_prepared: GGSWPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow()); // gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k) ct_gglwe.external_product_inplace(module, &ct_rgsw_prepared, scratch.borrow());
M poulpy-core/src/tests/test_suite/external_product/ggsw_ct.rs → poulpy-core/src/tests/test_suite/external_product/ggsw_ct.rs

@@ -18,8 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGSWCiphertext, GGSWCiphertextLayout, GLWESecret, - prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, + GGSW, GGSWCiphertextLayout, GLWESecret, + prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::noise_ggsw_product, };

@@ -111,9 +111,9 @@ dsize: di.into(),

rank: rank.into(), }; - let mut ggsw_in: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_in_infos); - let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos); - let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos); + let mut ggsw_in: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_in_infos); + let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos); + let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos); let mut pt_in: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); let mut pt_apply: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);

@@ -128,9 +128,9 @@

pt_apply.to_mut().raw_mut()[k] = 1; //X^{k} let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos) - | GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_in_infos) - | GGSWCiphertext::external_product_scratch_space(module, &ggsw_out_infos, &ggsw_in_infos, &ggsw_apply_infos), + GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos) + | GGSW::encrypt_sk_scratch_space(module, &ggsw_in_infos) + | GGSW::external_product_scratch_space(module, &ggsw_out_infos, &ggsw_in_infos, &ggsw_apply_infos), ); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_with(n.into(), rank.into());

@@ -155,7 +155,7 @@ &mut source_xe,

scratch.borrow(), ); - let ct_rhs_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); + let ct_rhs_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); ggsw_out.external_product(module, &ggsw_in, &ct_rhs_prepared, scratch.borrow());

@@ -265,8 +265,8 @@ dsize: di.into(),

rank: rank.into(), }; - let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos); - let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos); + let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos); + let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos); let mut pt_in: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); let mut pt_apply: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);

@@ -282,9 +282,9 @@

pt_apply.to_mut().raw_mut()[k] = 1; //X^{k} let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos) - | GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_out_infos) - | GGSWCiphertext::external_product_inplace_scratch_space(module, &ggsw_out_infos, &ggsw_apply_infos), + GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos) + | GGSW::encrypt_sk_scratch_space(module, &ggsw_out_infos) + | GGSW::external_product_inplace_scratch_space(module, &ggsw_out_infos, &ggsw_apply_infos), ); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_with(n.into(), rank.into());

@@ -309,7 +309,7 @@ &mut source_xe,

scratch.borrow(), ); - let ct_rhs_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); + let ct_rhs_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); ggsw_out.external_product_inplace(module, &ct_rhs_prepared, scratch.borrow());
M poulpy-core/src/tests/test_suite/external_product/glwe_ct.rs → poulpy-core/src/tests/test_suite/external_product/glwe_ct.rs

@@ -17,8 +17,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGSWCiphertext, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, - prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, + GGSW, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, + prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::noise_ggsw_product, };

@@ -96,7 +96,7 @@ dsize: di.into(),

rank: rank.into(), }; - let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos); + let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos); let mut glwe_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_in_infos); let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos); let mut pt_ggsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1);

@@ -116,7 +116,7 @@

pt_ggsw.raw_mut()[k] = 1; // X^{k} let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos) + GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos) | GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_in_infos) | GLWECiphertext::external_product_scratch_space(module, &glwe_out_infos, &glwe_in_infos, &ggsw_apply_infos), );

@@ -143,7 +143,7 @@ &mut source_xe,

scratch.borrow(), ); - let ct_ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); + let ct_ggsw_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); glwe_out.external_product(module, &glwe_in, &ct_ggsw_prepared, scratch.borrow());

@@ -240,7 +240,7 @@ dsize: di.into(),

rank: rank.into(), }; - let mut ggsw_apply: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_apply_infos); + let mut ggsw_apply: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_apply_infos); let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos); let mut pt_ggsw: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&glwe_out_infos);

@@ -259,7 +259,7 @@

pt_ggsw.raw_mut()[k] = 1; // X^{k} let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_apply_infos) + GGSW::encrypt_sk_scratch_space(module, &ggsw_apply_infos) | GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos) | GLWECiphertext::external_product_inplace_scratch_space(module, &glwe_out_infos, &ggsw_apply_infos), );

@@ -286,7 +286,7 @@ &mut source_xe,

scratch.borrow(), ); - let ct_ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); + let ct_ggsw_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow()); glwe_out.external_product_inplace(module, &ct_ggsw_prepared, scratch.borrow());
M poulpy-core/src/tests/test_suite/keyswitch/gglwe_ct.rs → poulpy-core/src/tests/test_suite/keyswitch/gglwe_ct.rs

@@ -18,8 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWESwitchingKey, GGLWESwitchingKeyLayout, GLWESecret, - prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc}, + GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout, + prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, };

@@ -80,7 +80,7 @@ let dnum: usize = k_in / base2k;

let dnum_apply: usize = k_in.div_ceil(base2k * di); let dsize_in: usize = 1; - let gglwe_s0s1_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_s0s1_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_in.into(),

@@ -90,7 +90,7 @@ rank_in: rank_in_s0s1.into(),

rank_out: rank_out_s0s1.into(), }; - let gglwe_s1s2_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_s1s2_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -100,7 +100,7 @@ rank_in: rank_out_s0s1.into(),

rank_out: rank_out_s1s2.into(), }; - let gglwe_s0s2_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_s0s2_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_out.into(),

@@ -110,20 +110,20 @@ rank_in: rank_in_s0s1.into(),

rank_out: rank_out_s1s2.into(), }; - let mut gglwe_s0s1: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s0s1_infos); - let mut gglwe_s1s2: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s1s2_infos); - let mut gglwe_s0s2: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s0s2_infos); + let mut gglwe_s0s1: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s0s1_infos); + let mut gglwe_s1s2: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s1s2_infos); + let mut gglwe_s0s2: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s0s2_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch_enc: ScratchOwned<B> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos) - | GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos) - | GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s2_infos), + GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos) + | GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos) + | GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s2_infos), ); - let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::keyswitch_scratch_space( + let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKey::keyswitch_scratch_space( module, &gglwe_s0s1_infos, &gglwe_s0s2_infos,

@@ -160,7 +160,7 @@ &mut source_xe,

scratch_enc.borrow(), ); - let gglwe_s1s2_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = + let gglwe_s1s2_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = gglwe_s1s2.prepare_alloc(module, scratch_apply.borrow()); // gglwe_{s1}(s0) (x) gglwe_{s2}(s1) = gglwe_{s2}(s0)

@@ -246,7 +246,7 @@ let n: usize = module.n();

let dnum: usize = k_out.div_ceil(base2k * di); let dsize_in: usize = 1; - let gglwe_s0s1_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_s0s1_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_out.into(),

@@ -256,7 +256,7 @@ rank_in: rank_in.into(),

rank_out: rank_out.into(), }; - let gglwe_s1s2_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let gglwe_s1s2_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -266,18 +266,18 @@ rank_in: rank_out.into(),

rank_out: rank_out.into(), }; - let mut gglwe_s0s1: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s0s1_infos); - let mut gglwe_s1s2: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&gglwe_s1s2_infos); + let mut gglwe_s0s1: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s0s1_infos); + let mut gglwe_s1s2: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&gglwe_s1s2_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch_enc: ScratchOwned<B> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos) - | GGLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos), + GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s0s1_infos) + | GLWESwitchingKey::encrypt_sk_scratch_space(module, &gglwe_s1s2_infos), ); - let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::keyswitch_inplace_scratch_space( + let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKey::keyswitch_inplace_scratch_space( module, &gglwe_s0s1_infos, &gglwe_s1s2_infos,

@@ -315,13 +315,13 @@ &mut source_xe,

scratch_enc.borrow(), ); - let gglwe_s1s2_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = + let gglwe_s1s2_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = gglwe_s1s2.prepare_alloc(module, scratch_apply.borrow()); // gglwe_{s1}(s0) (x) gglwe_{s2}(s1) = gglwe_{s2}(s0) gglwe_s0s1.keyswitch_inplace(module, &gglwe_s1s2_prepared, scratch_apply.borrow()); - let gglwe_s0s2: GGLWESwitchingKey<Vec<u8>> = gglwe_s0s1; + let gglwe_s0s2: GLWESwitchingKey<Vec<u8>> = gglwe_s0s1; let max_noise: f64 = log2_std_noise_gglwe_product( n as f64,
M poulpy-core/src/tests/test_suite/keyswitch/ggsw_ct.rs → poulpy-core/src/tests/test_suite/keyswitch/ggsw_ct.rs

@@ -18,9 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWESwitchingKey, GGLWESwitchingKeyLayout, GGLWETensorKey, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, - GLWESecret, - prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc}, + GGSW, GGSWCiphertextLayout, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout, TensorKey, TensorKeyLayout, + prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc, TensorKeyPrepared}, }, noise::noise_ggsw_keyswitch, };

@@ -103,7 +102,7 @@ dsize: dsize_in.into(),

rank: rank.into(), }; - let tsk_infos: GGLWETensorKeyLayout = GGLWETensorKeyLayout { + let tsk_infos: TensorKeyLayout = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k_tsk.into(),

@@ -112,7 +111,7 @@ dsize: di.into(),

rank: rank.into(), }; - let ksk_apply_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let ksk_apply_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -122,10 +121,10 @@ rank_in: rank.into(),

rank_out: rank.into(), }; - let mut ggsw_in: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_in_infos); - let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos); - let mut tsk: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tsk_infos); - let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&ksk_apply_infos); + let mut ggsw_in: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_in_infos); + let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos); + let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc(&tsk_infos); + let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&ksk_apply_infos); let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); let mut source_xs: Source = Source::new([0u8; 32]);

@@ -133,10 +132,10 @@ let mut source_xe: Source = Source::new([0u8; 32]);

let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_in_infos) - | GGLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos) - | GGLWETensorKey::encrypt_sk_scratch_space(module, &tsk_infos) - | GGSWCiphertext::keyswitch_scratch_space( + GGSW::encrypt_sk_scratch_space(module, &ggsw_in_infos) + | GLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos) + | TensorKey::encrypt_sk_scratch_space(module, &tsk_infos) + | GGSW::keyswitch_scratch_space( module, &ggsw_out_infos, &ggsw_in_infos,

@@ -182,8 +181,8 @@ &mut source_xe,

scratch.borrow(), ); - let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow()); - let tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow()); + let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow()); + let tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow()); ggsw_out.keyswitch( module,

@@ -282,7 +281,7 @@ dsize: dsize_in.into(),

rank: rank.into(), }; - let tsk_infos: GGLWETensorKeyLayout = GGLWETensorKeyLayout { + let tsk_infos: TensorKeyLayout = TensorKeyLayout { n: n.into(), base2k: base2k.into(), k: k_tsk.into(),

@@ -291,7 +290,7 @@ dsize: di.into(),

rank: rank.into(), }; - let ksk_apply_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let ksk_apply_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -301,9 +300,9 @@ rank_in: rank.into(),

rank_out: rank.into(), }; - let mut ggsw_out: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_out_infos); - let mut tsk: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&tsk_infos); - let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&ksk_apply_infos); + let mut ggsw_out: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_out_infos); + let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc(&tsk_infos); + let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&ksk_apply_infos); let mut pt_scalar: ScalarZnx<Vec<u8>> = ScalarZnx::alloc(n, 1); let mut source_xs: Source = Source::new([0u8; 32]);

@@ -311,10 +310,10 @@ let mut source_xe: Source = Source::new([0u8; 32]);

let mut source_xa: Source = Source::new([0u8; 32]); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGSWCiphertext::encrypt_sk_scratch_space(module, &ggsw_out_infos) - | GGLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos) - | GGLWETensorKey::encrypt_sk_scratch_space(module, &tsk_infos) - | GGSWCiphertext::keyswitch_inplace_scratch_space(module, &ggsw_out_infos, &ksk_apply_infos, &tsk_infos), + GGSW::encrypt_sk_scratch_space(module, &ggsw_out_infos) + | GLWESwitchingKey::encrypt_sk_scratch_space(module, &ksk_apply_infos) + | TensorKey::encrypt_sk_scratch_space(module, &tsk_infos) + | GGSW::keyswitch_inplace_scratch_space(module, &ggsw_out_infos, &ksk_apply_infos, &tsk_infos), ); let var_xs: f64 = 0.5;

@@ -354,8 +353,8 @@ &mut source_xe,

scratch.borrow(), ); - let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow()); - let tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow()); + let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow()); + let tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = tsk.prepare_alloc(module, scratch.borrow()); ggsw_out.keyswitch_inplace(module, &ksk_prepared, &tsk_prepared, scratch.borrow());
M poulpy-core/src/tests/test_suite/keyswitch/glwe_ct.rs → poulpy-core/src/tests/test_suite/keyswitch/glwe_ct.rs

@@ -18,8 +18,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWESwitchingKey, GGLWESwitchingKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, - prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc}, + GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout, + prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, };

@@ -91,7 +91,7 @@ k: k_out.into(),

rank: rank_out.into(), }; - let key_apply: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let key_apply: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -101,7 +101,7 @@ rank_in: rank_in.into(),

rank_out: rank_out.into(), }; - let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&key_apply); + let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&key_apply); let mut glwe_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_in_infos); let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos); let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&glwe_in_infos);

@@ -113,7 +113,7 @@

module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply) + GLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply) | GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_in_infos) | GLWECiphertext::keyswitch_scratch_space(module, &glwe_out_infos, &glwe_in_infos, &key_apply), );

@@ -144,7 +144,7 @@ &mut source_xe,

scratch.borrow(), ); - let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow()); + let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow()); glwe_out.keyswitch(module, &glwe_in, &ksk_prepared, scratch.borrow());

@@ -224,7 +224,7 @@ k: k_out.into(),

rank: rank.into(), }; - let key_apply_infos: GGLWESwitchingKeyLayout = GGLWESwitchingKeyLayout { + let key_apply_infos: GLWESwitchingKeyLayout = GLWESwitchingKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -234,7 +234,7 @@ rank_in: rank.into(),

rank_out: rank.into(), }; - let mut key_apply: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(&key_apply_infos); + let mut key_apply: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&key_apply_infos); let mut glwe_out: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(&glwe_out_infos); let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&glwe_out_infos);

@@ -245,7 +245,7 @@

module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( - GGLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply_infos) + GLWESwitchingKey::encrypt_sk_scratch_space(module, &key_apply_infos) | GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos) | GLWECiphertext::keyswitch_inplace_scratch_space(module, &glwe_out_infos, &key_apply_infos), );

@@ -276,7 +276,7 @@ &mut source_xe,

scratch.borrow(), ); - let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = key_apply.prepare_alloc(module, scratch.borrow()); + let ksk_prepared: GLWESwitchingKeyPrepared<Vec<u8>, B> = key_apply.prepare_alloc(module, scratch.borrow()); glwe_out.keyswitch_inplace(module, &ksk_prepared, scratch.borrow());
M poulpy-core/src/tests/test_suite/packing.rs → poulpy-core/src/tests/test_suite/packing.rs

@@ -21,8 +21,8 @@

use crate::{ GLWEOperations, GLWEPacker, layouts::{ - GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, - prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc}, + AutomorphismKey, AutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, };

@@ -95,7 +95,7 @@ k: k_ct.into(),

rank: rank.into(), }; - let key_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_ksk.into(),

@@ -106,7 +106,7 @@ };

let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos) - | GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &key_infos) + | AutomorphismKey::encrypt_sk_scratch_space(module, &key_infos) | GLWEPacker::scratch_space(module, &glwe_out_infos, &key_infos), );

@@ -124,8 +124,8 @@ pt.encode_vec_i64(&data, pt_k.into());

let gal_els: Vec<i64> = GLWEPacker::galois_elements(module); - let mut auto_keys: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); - let mut tmp: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&key_infos); + let mut auto_keys: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); + let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&key_infos); gal_els.iter().for_each(|gal_el| { tmp.encrypt_sk( module,

@@ -135,7 +135,7 @@ &mut source_xa,

&mut source_xe, scratch.borrow(), ); - let atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow()); + let atk_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow()); auto_keys.insert(*gal_el, atk_prepared); });
M poulpy-core/src/tests/test_suite/trace.rs → poulpy-core/src/tests/test_suite/trace.rs

@@ -21,9 +21,8 @@

use crate::{ encryption::SIGMA, layouts::{ - GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, - LWEInfos, - prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc}, + AutomorphismKey, AutomorphismKeyLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, LWEInfos, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::var_noise_gglwe_product, };

@@ -90,7 +89,7 @@ k: k.into(),

rank: rank.into(), }; - let key_infos: GGLWEAutomorphismKeyLayout = GGLWEAutomorphismKeyLayout { + let key_infos: AutomorphismKeyLayout = AutomorphismKeyLayout { n: n.into(), base2k: base2k.into(), k: k_autokey.into(),

@@ -110,7 +109,7 @@

let mut scratch: ScratchOwned<B> = ScratchOwned::alloc( GLWECiphertext::encrypt_sk_scratch_space(module, &glwe_out_infos) | GLWECiphertext::decrypt_scratch_space(module, &glwe_out_infos) - | GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, &key_infos) + | AutomorphismKey::encrypt_sk_scratch_space(module, &key_infos) | GLWECiphertext::trace_inplace_scratch_space(module, &glwe_out_infos, &key_infos), );

@@ -135,9 +134,9 @@ &mut source_xe,

scratch.borrow(), ); - let mut auto_keys: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); + let mut auto_keys: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(module); - let mut tmp: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&key_infos); + let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&key_infos); gal_els.iter().for_each(|gal_el| { tmp.encrypt_sk( module,

@@ -147,7 +146,7 @@ &mut source_xa,

&mut source_xe, scratch.borrow(), ); - let atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow()); + let atk_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow()); auto_keys.insert(*gal_el, atk_prepared); });
M poulpy-schemes/benches/circuit_bootstrapping.rs → poulpy-schemes/benches/circuit_bootstrapping.rs

@@ -3,8 +3,8 @@

use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; use poulpy_backend::{FFT64Avx, FFT64Ref, FFT64Spqlios}; use poulpy_core::layouts::{ - Dsize, GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWESecret, LWECiphertext, - LWECiphertextLayout, LWESecret, prepared::PrepareAlloc, + AutomorphismKeyLayout, Dsize, GGSW, GGSWCiphertextLayout, GLWESecret, LWECiphertext, LWECiphertextLayout, LWESecret, + TensorKeyLayout, prepared::PrepareAlloc, }; use poulpy_hal::{ api::{

@@ -218,7 +218,7 @@ &mut source_xe,

scratch.borrow(), ); - let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&params.ggsw_infos); + let mut res: GGSW<Vec<u8>> = GGSW::alloc(&params.ggsw_infos); let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> = cbt_key.prepare_alloc(&module, scratch.borrow()); move || {

@@ -261,7 +261,7 @@ k: 52_u32.into(),

dnum: 3_u32.into(), rank: 2_u32.into(), }, - layout_atk: GGLWEAutomorphismKeyLayout { + layout_atk: AutomorphismKeyLayout { n: 1024_u32.into(), base2k: 13_u32.into(), k: 52_u32.into(),

@@ -269,7 +269,7 @@ dnum: 3_u32.into(),

dsize: Dsize(1), rank: 2_u32.into(), }, - layout_tsk: GGLWETensorKeyLayout { + layout_tsk: TensorKeyLayout { n: 1024_u32.into(), base2k: 13_u32.into(), k: 52_u32.into(),
M poulpy-schemes/examples/circuit_bootstrapping.rs → poulpy-schemes/examples/circuit_bootstrapping.rs

@@ -1,9 +1,9 @@

use poulpy_core::{ GLWEOperations, layouts::{ - GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertext, GGSWCiphertextLayout, GLWECiphertext, - GLWECiphertextLayout, GLWEPlaintext, GLWESecret, LWECiphertext, LWECiphertextLayout, LWEInfos, LWEPlaintext, LWESecret, - prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, + AutomorphismKeyLayout, GGSW, GGSWCiphertextLayout, GLWECiphertext, GLWECiphertextLayout, GLWEPlaintext, GLWESecret, + LWECiphertext, LWECiphertextLayout, LWEInfos, LWEPlaintext, LWESecret, TensorKeyLayout, + prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, }, }; use std::time::Instant;

@@ -89,7 +89,7 @@ k: k_brk.into(),

dnum: rows_brk.into(), rank: rank.into(), }, - layout_atk: GGLWEAutomorphismKeyLayout { + layout_atk: AutomorphismKeyLayout { n: n_glwe.into(), base2k: base2k.into(), k: k_trace.into(),

@@ -97,7 +97,7 @@ dnum: rows_trace.into(),

dsize: 1_u32.into(), rank: rank.into(), }, - layout_tsk: GGLWETensorKeyLayout { + layout_tsk: TensorKeyLayout { n: n_glwe.into(), base2k: base2k.into(), k: k_tsk.into(),

@@ -187,7 +187,7 @@ );

println!("CBT-KGEN: {} ms", now.elapsed().as_millis()); // Output GGSW - let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos); + let mut res: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos); // Circuit bootstrapping key prepared (opaque backend dependant write only struct) let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, CGGI, BackendImpl> =

@@ -249,7 +249,7 @@ scratch.borrow(),

); // Prepare GGSW output of circuit bootstrapping (opaque backend dependant write only struct) - let res_prepared: GGSWCiphertextPrepared<Vec<u8>, BackendImpl> = res.prepare_alloc(&module, scratch.borrow()); + let res_prepared: GGSWPrepared<Vec<u8>, BackendImpl> = res.prepare_alloc(&module, scratch.borrow()); // Apply GLWE x GGSW ct_glwe.external_product_inplace(&module, &res_prepared, scratch.borrow());
M poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs → poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs

@@ -1,12 +1,10 @@

use std::marker::PhantomData; -use poulpy_core::layouts::{ - Base2K, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWCiphertextPrepared, -}; +use poulpy_core::layouts::{Base2K, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared}; #[cfg(test)] use poulpy_core::{ TakeGGSW, - layouts::{GGSWCiphertext, prepared::GLWESecretPrepared}, + layouts::{GGSW, prepared::GLWESecretPrepared}, }; use poulpy_hal::{ api::VmpPMatAlloc,

@@ -29,7 +27,7 @@ use crate::tfhe::bdd_arithmetic::{FheUintBlocks, FheUintPrepare, ToBits, UnsignedInteger};

#[cfg(test)] pub(crate) struct FheUintBlocksPrepDebug<D: Data, T: UnsignedInteger> { - pub(crate) blocks: Vec<GGSWCiphertext<D>>, + pub(crate) blocks: Vec<GGSW<D>>, pub(crate) _base: u8, pub(crate) _phantom: PhantomData<T>, }

@@ -62,7 +60,7 @@ rank: Rank,

) -> Self { Self { blocks: (0..T::WORD_SIZE) - .map(|_| GGSWCiphertext::alloc_with(module.n().into(), base2k, k, rank, dnum, dsize)) + .map(|_| GGSW::alloc_with(module.n().into(), base2k, k, rank, dnum, dsize)) .collect(), _base: 1, _phantom: PhantomData,

@@ -72,7 +70,7 @@ }

/// A prepared FHE ciphertext encrypting the bits of an [UnsignedInteger]. pub struct FheUintBlocksPrep<D: Data, B: Backend, T: UnsignedInteger> { - pub(crate) blocks: Vec<GGSWCiphertextPrepared<D, B>>, + pub(crate) blocks: Vec<GGSWPrepared<D, B>>, pub(crate) _base: u8, pub(crate) _phantom: PhantomData<T>, }

@@ -103,7 +101,7 @@ Module<BE>: VmpPMatAlloc<BE>,

{ Self { blocks: (0..T::WORD_SIZE) - .map(|_| GGSWCiphertextPrepared::alloc_with(module, base2k, k, dnum, dsize, rank)) + .map(|_| GGSWPrepared::alloc_with(module, base2k, k, dnum, dsize, rank)) .collect(), _base: 1, _phantom: PhantomData,
M poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs → poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs

@@ -3,7 +3,7 @@ use poulpy_core::{

GLWEOperations, TakeGLWECtSlice, TakeGLWEPt, glwe_packing, layouts::{ GLWECiphertext, GLWEInfos, GLWEPlaintextLayout, LWEInfos, TorusPrecision, - prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared}, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, }, }; use poulpy_hal::{

@@ -32,7 +32,7 @@ fn post_process<ATK, BE: Backend>(

&mut self, module: &Module<BE>, mut tmp_res: Vec<GLWECiphertext<&mut [u8]>>, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<ATK, BE>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<ATK, BE>>, scratch: &mut Scratch<BE>, ) where ATK: DataRef,
M poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs → poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs

@@ -3,7 +3,7 @@ use poulpy_core::{

GLWEExternalProductInplace, GLWEOperations, TakeGLWECtSlice, layouts::{ GLWECiphertext, GLWECiphertextToMut, LWEInfos, - prepared::{GGSWCiphertextPrepared, GGSWCiphertextPreparedToRef}, + prepared::{GGSWCiphertextPreparedToRef, GGSWPrepared}, }, }; use poulpy_hal::{

@@ -164,7 +164,7 @@ &self,

out: &mut GLWECiphertext<O>, t: &GLWECiphertext<T>, f: &GLWECiphertext<F>, - s: &GGSWCiphertextPrepared<S, BE>, + s: &GGSWPrepared<S, BE>, scratch: &mut Scratch<BE>, ) where O: DataMut,

@@ -182,7 +182,7 @@ &self,

out: &mut GLWECiphertext<O>, t: &GLWECiphertext<T>, f: &GLWECiphertext<F>, - s: &GGSWCiphertextPrepared<S, BE>, + s: &GGSWPrepared<S, BE>, scratch: &mut Scratch<BE>, ) where O: DataMut,
M poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs → poulpy-schemes/src/tfhe/bdd_arithmetic/key.rs

@@ -11,7 +11,7 @@ };

use poulpy_core::{ TakeGGSW, TakeGLWECt, layouts::{ - GLWESecret, GLWEToLWEKey, GLWEToLWEKeyLayout, LWECiphertext, LWESecret, + GLWESecret, GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, LWECiphertext, LWESecret, prepared::{GLWEToLWESwitchingKeyPrepared, Prepare, PrepareAlloc}, }, };

@@ -56,7 +56,7 @@ LWE: Data,

BRA: BlindRotationAlgo, { cbt: CircuitBootstrappingKey<CBT, BRA>, - ks: GLWEToLWEKey<LWE>, + ks: GLWEToLWESwitchingKey<LWE>, } impl<BRA: BlindRotationAlgo> BDDKey<Vec<u8>, Vec<u8>, BRA> {

@@ -98,7 +98,7 @@ + VecZnxAutomorphism

+ VecZnxAutomorphismInplace<BE>, Scratch<BE>: TakeVecZnxDft<BE> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeSvpPPol<BE> + TakeVecZnxBig<BE>, { - let mut ks: GLWEToLWEKey<Vec<u8>> = GLWEToLWEKey::alloc(&infos.ks_infos()); + let mut ks: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(&infos.ks_infos()); ks.encrypt_sk(module, sk_lwe, sk_glwe, source_xa, source_xe, scratch); Self {

@@ -131,7 +131,7 @@ impl<CBT: DataMut, LWE: DataMut, BRA: BlindRotationAlgo, BE: Backend> PrepareAlloc<BE, BDDKeyPrepared<CBT, LWE, BRA, BE>>

for BDDKey<CBT, LWE, BRA> where CircuitBootstrappingKey<CBT, BRA>: PrepareAlloc<BE, CircuitBootstrappingKeyPrepared<CBT, BRA, BE>>, - GLWEToLWEKey<LWE>: PrepareAlloc<BE, GLWEToLWESwitchingKeyPrepared<LWE, BE>>, + GLWEToLWESwitchingKey<LWE>: PrepareAlloc<BE, GLWEToLWESwitchingKeyPrepared<LWE, BE>>, { fn prepare_alloc(&self, module: &Module<BE>, scratch: &mut Scratch<BE>) -> BDDKeyPrepared<CBT, LWE, BRA, BE> { BDDKeyPrepared {
M poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs → poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs

@@ -1,7 +1,7 @@

#[cfg(test)] use poulpy_core::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertextLayout, GLWECiphertextLayout, - GLWEToLWEKeyLayout, Rank, TorusPrecision, + AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GGSWCiphertextLayout, GLWECiphertextLayout, GLWEToLWEKeyLayout, Rank, + TensorKeyLayout, TorusPrecision, }; #[cfg(test)]

@@ -53,7 +53,7 @@ k: TorusPrecision(52),

dnum: Dnum(3), rank: Rank(TEST_RANK), }, - layout_atk: GGLWEAutomorphismKeyLayout { + layout_atk: AutomorphismKeyLayout { n: Degree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(52),

@@ -61,7 +61,7 @@ rank: Rank(TEST_RANK),

dnum: Dnum(3), dsize: Dsize(1), }, - layout_tsk: GGLWETensorKeyLayout { + layout_tsk: TensorKeyLayout { n: Degree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(52),
M poulpy-schemes/src/tfhe/blind_rotation/cggi_key.rs → poulpy-schemes/src/tfhe/blind_rotation/cggi_key.rs

@@ -14,9 +14,9 @@

use poulpy_core::{ Distribution, layouts::{ - GGSWCiphertext, GGSWInfos, LWESecret, + GGSW, GGSWInfos, LWESecret, compressed::GGSWCiphertextCompressed, - prepared::{GGSWCiphertextPrepared, GLWESecretPrepared}, + prepared::{GGSWPrepared, GLWESecretPrepared}, }, };

@@ -30,9 +30,9 @@ fn alloc<A>(infos: &A) -> Self

where A: BlindRotationKeyInfos, { - let mut data: Vec<GGSWCiphertext<Vec<u8>>> = Vec::with_capacity(infos.n_lwe().into()); + let mut data: Vec<GGSW<Vec<u8>>> = Vec::with_capacity(infos.n_lwe().into()); for _ in 0..infos.n_lwe().as_usize() { - data.push(GGSWCiphertext::alloc(infos)); + data.push(GGSW::alloc(infos)); } Self {

@@ -49,7 +49,7 @@ where

A: GGSWInfos, Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { - GGSWCiphertext::encrypt_sk_scratch_space(module, infos) + GGSW::encrypt_sk_scratch_space(module, infos) } }

@@ -121,8 +121,8 @@ fn alloc<A>(module: &Module<B>, infos: &A) -> Self

where A: BlindRotationKeyInfos, { - let mut data: Vec<GGSWCiphertextPrepared<Vec<u8>, B>> = Vec::with_capacity(infos.n_lwe().into()); - (0..infos.n_lwe().as_usize()).for_each(|_| data.push(GGSWCiphertextPrepared::alloc(module, infos))); + let mut data: Vec<GGSWPrepared<Vec<u8>, B>> = Vec::with_capacity(infos.n_lwe().into()); + (0..infos.n_lwe().as_usize()).for_each(|_| data.push(GGSWPrepared::alloc(module, infos))); Self { data, dist: Distribution::NONE,
M poulpy-schemes/src/tfhe/blind_rotation/key.rs → poulpy-schemes/src/tfhe/blind_rotation/key.rs

@@ -8,7 +8,7 @@

use poulpy_core::{ Distribution, layouts::{ - Base2K, Degree, Dnum, Dsize, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, TorusPrecision, prepared::GLWESecretPrepared, }, };

@@ -98,7 +98,7 @@ }

#[derive(Clone)] pub struct BlindRotationKey<D: Data, BRT: BlindRotationAlgo> { - pub(crate) keys: Vec<GGSWCiphertext<D>>, + pub(crate) keys: Vec<GGSW<D>>, pub(crate) dist: Distribution, pub(crate) _phantom: PhantomData<BRT>, }
M poulpy-schemes/src/tfhe/blind_rotation/key_prepared.rs → poulpy-schemes/src/tfhe/blind_rotation/key_prepared.rs

@@ -9,7 +9,7 @@ use poulpy_core::{

Distribution, layouts::{ Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{GGSWCiphertextPrepared, Prepare, PrepareAlloc}, + prepared::{GGSWPrepared, Prepare, PrepareAlloc}, }, };

@@ -23,7 +23,7 @@ }

#[derive(PartialEq, Eq)] pub struct BlindRotationKeyPrepared<D: Data, BRT: BlindRotationAlgo, B: Backend> { - pub(crate) data: Vec<GGSWCiphertextPrepared<D, B>>, + pub(crate) data: Vec<GGSWPrepared<D, B>>, pub(crate) dist: Distribution, pub(crate) x_pow_a: Option<Vec<SvpPPol<Vec<u8>, B>>>, pub(crate) _phantom: PhantomData<BRT>,
M poulpy-schemes/src/tfhe/circuit_bootstrapping/circuit.rs → poulpy-schemes/src/tfhe/circuit_bootstrapping/circuit.rs

@@ -20,7 +20,7 @@ layouts::{Dsize, GGLWECiphertextLayout, GGSWInfos, GLWEInfos, LWEInfos},

}; use poulpy_core::glwe_packing; -use poulpy_core::layouts::{GGSWCiphertext, GLWECiphertext, LWECiphertext, prepared::GGLWEAutomorphismKeyPrepared}; +use poulpy_core::layouts::{GGSW, GLWECiphertext, LWECiphertext, prepared::AutomorphismKeyPrepared}; use crate::tfhe::{ blind_rotation::{

@@ -74,7 +74,7 @@ {

fn execute_to_constant<DM: DataMut, DR: DataRef>( &self, module: &Module<B>, - res: &mut GGSWCiphertext<DM>, + res: &mut GGSW<DM>, lwe: &LWECiphertext<DR>, log_domain: usize, extension_factor: usize,

@@ -97,7 +97,7 @@ fn execute_to_exponent<DM: DataMut, DR: DataRef>(

&self, module: &Module<B>, log_gap_out: usize, - res: &mut GGSWCiphertext<DM>, + res: &mut GGSW<DM>, lwe: &LWECiphertext<DR>, log_domain: usize, extension_factor: usize,

@@ -122,7 +122,7 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B>(

to_exponent: bool, module: &Module<B>, log_gap_out: usize, - res: &mut GGSWCiphertext<DRes>, + res: &mut GGSW<DRes>, lwe: &LWECiphertext<DLwe>, log_domain: usize, extension_factor: usize,

@@ -268,7 +268,7 @@ a: &GLWECiphertext<DataA>,

log_gap_in: usize, log_gap_out: usize, log_domain: usize, - auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>, + auto_keys: &HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>>, scratch: &mut Scratch<B>, ) where DataRes: DataMut,
M poulpy-schemes/src/tfhe/circuit_bootstrapping/key.rs → poulpy-schemes/src/tfhe/circuit_bootstrapping/key.rs

@@ -1,7 +1,7 @@

use poulpy_core::layouts::{ - GGLWEAutomorphismKey, GGLWEAutomorphismKeyLayout, GGLWEInfos, GGLWETensorKey, GGLWETensorKeyLayout, GGSWInfos, - GLWECiphertext, GLWEInfos, GLWESecret, LWEInfos, LWESecret, - prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc}, + AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GGSWInfos, GLWECiphertext, GLWEInfos, GLWESecret, LWEInfos, LWESecret, + TensorKey, TensorKeyLayout, + prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc, TensorKeyPrepared}, }; use std::collections::HashMap;

@@ -24,19 +24,19 @@ };

pub trait CircuitBootstrappingKeyInfos { fn brk_infos(&self) -> BlindRotationKeyLayout; - fn atk_infos(&self) -> GGLWEAutomorphismKeyLayout; - fn tsk_infos(&self) -> GGLWETensorKeyLayout; + fn atk_infos(&self) -> AutomorphismKeyLayout; + fn tsk_infos(&self) -> TensorKeyLayout; } #[derive(Debug, Clone, Copy)] pub struct CircuitBootstrappingKeyLayout { pub layout_brk: BlindRotationKeyLayout, - pub layout_atk: GGLWEAutomorphismKeyLayout, - pub layout_tsk: GGLWETensorKeyLayout, + pub layout_atk: AutomorphismKeyLayout, + pub layout_tsk: TensorKeyLayout, } impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout { - fn atk_infos(&self) -> GGLWEAutomorphismKeyLayout { + fn atk_infos(&self) -> AutomorphismKeyLayout { self.layout_atk }

@@ -44,7 +44,7 @@ fn brk_infos(&self) -> BlindRotationKeyLayout {

self.layout_brk } - fn tsk_infos(&self) -> GGLWETensorKeyLayout { + fn tsk_infos(&self) -> TensorKeyLayout { self.layout_tsk } }

@@ -68,8 +68,8 @@ }

pub struct CircuitBootstrappingKey<D: Data, BRA: BlindRotationAlgo> { pub(crate) brk: BlindRotationKey<D, BRA>, - pub(crate) tsk: GGLWETensorKey<Vec<u8>>, - pub(crate) atk: HashMap<i64, GGLWEAutomorphismKey<Vec<u8>>>, + pub(crate) tsk: TensorKey<Vec<u8>>, + pub(crate) atk: HashMap<i64, AutomorphismKey<Vec<u8>>>, } impl<BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyEncryptSk<B> for CircuitBootstrappingKey<Vec<u8>, BRA>

@@ -117,14 +117,14 @@ assert_eq!(sk_glwe.n(), cbt_infos.brk_infos().n_glwe());

assert_eq!(sk_glwe.n(), cbt_infos.atk_infos().n()); assert_eq!(sk_glwe.n(), cbt_infos.tsk_infos().n()); - let atk_infos: GGLWEAutomorphismKeyLayout = cbt_infos.atk_infos(); + let atk_infos: AutomorphismKeyLayout = cbt_infos.atk_infos(); let brk_infos: BlindRotationKeyLayout = cbt_infos.brk_infos(); - let trk_infos: GGLWETensorKeyLayout = cbt_infos.tsk_infos(); + let trk_infos: TensorKeyLayout = cbt_infos.tsk_infos(); - let mut auto_keys: HashMap<i64, GGLWEAutomorphismKey<Vec<u8>>> = HashMap::new(); + let mut auto_keys: HashMap<i64, AutomorphismKey<Vec<u8>>> = HashMap::new(); let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(module); gal_els.iter().for_each(|gal_el| { - let mut key: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(&atk_infos); + let mut key: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc(&atk_infos); key.encrypt_sk(module, *gal_el, sk_glwe, source_xa, source_xe, scratch); auto_keys.insert(*gal_el, key); });

@@ -141,7 +141,7 @@ source_xe,

scratch, ); - let mut tsk: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(&trk_infos); + let mut tsk: TensorKey<Vec<u8>> = TensorKey::alloc(&trk_infos); tsk.encrypt_sk(module, sk_glwe, source_xa, source_xe, scratch); Self {

@@ -154,14 +154,14 @@ }

pub struct CircuitBootstrappingKeyPrepared<D: Data, BRA: BlindRotationAlgo, B: Backend> { pub(crate) brk: BlindRotationKeyPrepared<D, BRA, B>, - pub(crate) tsk: GGLWETensorKeyPrepared<Vec<u8>, B>, - pub(crate) atk: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>, + pub(crate) tsk: TensorKeyPrepared<Vec<u8>, B>, + pub(crate) atk: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>>, } impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyPrepared<D, BRA, B> { - fn atk_infos(&self) -> GGLWEAutomorphismKeyLayout { + fn atk_infos(&self) -> AutomorphismKeyLayout { let (_, atk) = self.atk.iter().next().expect("atk is empty"); - GGLWEAutomorphismKeyLayout { + AutomorphismKeyLayout { n: atk.n(), base2k: atk.base2k(), k: atk.k(),

@@ -182,8 +182,8 @@ rank: self.brk.rank(),

} } - fn tsk_infos(&self) -> GGLWETensorKeyLayout { - GGLWETensorKeyLayout { + fn tsk_infos(&self) -> TensorKeyLayout { + TensorKeyLayout { n: self.tsk.n(), base2k: self.tsk.base2k(), k: self.tsk.k(),

@@ -199,13 +199,13 @@ for CircuitBootstrappingKey<D, BRA>

where Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>, BlindRotationKey<D, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>, - GGLWETensorKey<D>: PrepareAlloc<B, GGLWETensorKeyPrepared<Vec<u8>, B>>, - GGLWEAutomorphismKey<D>: PrepareAlloc<B, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>, + TensorKey<D>: PrepareAlloc<B, TensorKeyPrepared<Vec<u8>, B>>, + AutomorphismKey<D>: PrepareAlloc<B, AutomorphismKeyPrepared<Vec<u8>, B>>, { fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> { let brk: BlindRotationKeyPrepared<Vec<u8>, BRA, B> = self.brk.prepare_alloc(module, scratch); - let tsk: GGLWETensorKeyPrepared<Vec<u8>, B> = self.tsk.prepare_alloc(module, scratch); - let mut atk: HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); + let tsk: TensorKeyPrepared<Vec<u8>, B> = self.tsk.prepare_alloc(module, scratch); + let mut atk: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); for (key, value) in &self.atk { atk.insert(*key, value.prepare_alloc(module, scratch)); }
M poulpy-schemes/src/tfhe/circuit_bootstrapping/mod.rs → poulpy-schemes/src/tfhe/circuit_bootstrapping/mod.rs

@@ -5,7 +5,7 @@

pub use circuit::*; pub use key::*; -use poulpy_core::layouts::{GGSWCiphertext, LWECiphertext}; +use poulpy_core::layouts::{GGSW, LWECiphertext}; use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch};

@@ -13,7 +13,7 @@ pub trait CirtuitBootstrappingExecute<B: Backend> {

fn execute_to_constant<DM: DataMut, DR: DataRef>( &self, module: &Module<B>, - res: &mut GGSWCiphertext<DM>, + res: &mut GGSW<DM>, lwe: &LWECiphertext<DR>, log_domain: usize, extension_factor: usize,

@@ -25,7 +25,7 @@ fn execute_to_exponent<DM: DataMut, DR: DataRef>(

&self, module: &Module<B>, log_gap_out: usize, - res: &mut GGSWCiphertext<DM>, + res: &mut GGSW<DM>, lwe: &LWECiphertext<DR>, log_domain: usize, extension_factor: usize,
M poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs → poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs

@@ -32,12 +32,12 @@ },

}; use poulpy_core::layouts::{ - Dsize, GGLWEAutomorphismKeyLayout, GGLWETensorKeyLayout, GGSWCiphertextLayout, LWECiphertextLayout, prepared::PrepareAlloc, + AutomorphismKeyLayout, Dsize, GGSWCiphertextLayout, LWECiphertextLayout, TensorKeyLayout, prepared::PrepareAlloc, }; use poulpy_core::layouts::{ - GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret, - prepared::{GGSWCiphertextPrepared, GLWESecretPrepared}, + GGSW, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret, + prepared::{GGSWPrepared, GLWESecretPrepared}, }; pub fn test_circuit_bootstrapping_to_exponent<B, BRA: BlindRotationAlgo>(module: &Module<B>)

@@ -143,7 +143,7 @@ k: k_brk.into(),

dnum: rows_brk.into(), rank: rank.into(), }, - layout_atk: GGLWEAutomorphismKeyLayout { + layout_atk: AutomorphismKeyLayout { n: n_glwe.into(), base2k: base2k.into(), k: k_atk.into(),

@@ -151,7 +151,7 @@ dnum: rows_atk.into(),

rank: rank.into(), dsize: Dsize(1), }, - layout_tsk: GGLWETensorKeyLayout { + layout_tsk: TensorKeyLayout { n: n_glwe.into(), base2k: base2k.into(), k: k_tsk.into(),

@@ -206,7 +206,7 @@ scratch.borrow(),

); println!("CBT-KGEN: {} ms", now.elapsed().as_millis()); - let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos); + let mut res: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos); let log_gap_out = 1;

@@ -249,7 +249,7 @@ &mut source_xe,

scratch.borrow(), ); - let res_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow()); + let res_prepared: GGSWPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow()); ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());

@@ -365,7 +365,7 @@ k: k_brk.into(),

dnum: rows_brk.into(), rank: rank.into(), }, - layout_atk: GGLWEAutomorphismKeyLayout { + layout_atk: AutomorphismKeyLayout { n: n_glwe.into(), base2k: base2k.into(), k: k_atk.into(),

@@ -373,7 +373,7 @@ dnum: rows_atk.into(),

rank: rank.into(), dsize: Dsize(1), }, - layout_tsk: GGLWETensorKeyLayout { + layout_tsk: TensorKeyLayout { n: n_glwe.into(), base2k: base2k.into(), k: k_tsk.into(),

@@ -428,7 +428,7 @@ scratch.borrow(),

); println!("CBT-KGEN: {} ms", now.elapsed().as_millis()); - let mut res: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(&ggsw_infos); + let mut res: GGSW<Vec<u8>> = GGSW::alloc(&ggsw_infos); let cbt_prepared: CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B> = cbt_key.prepare_alloc(module, scratch.borrow());

@@ -462,7 +462,7 @@ &mut source_xe,

scratch.borrow(), ); - let res_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow()); + let res_prepared: GGSWPrepared<Vec<u8>, B> = res.prepare_alloc(module, scratch.borrow()); ct_glwe.external_product_inplace(module, &res_prepared, scratch.borrow());