gglwe atk key
Rasoul Akhavan Mahdavi rasoul.akhavan.mahdavi@uwaterloo.ca
Sun, 19 Oct 2025 22:57:00 -0400
5 files changed,
59 insertions(+),
110 deletions(-)
M
poulpy-core/src/layouts/compressed/gglwe_atk.rs
→
poulpy-core/src/layouts/compressed/gglwe_atk.rs
@@ -20,6 +20,12 @@ pub(crate) key: GLWESwitchingKeyCompressed<D>,
pub(crate) p: i64, } +impl<D: Data> GetAutomorphismGaloisElement for AutomorphismKeyCompressed<D> { + fn p(&self) -> i64 { + self.p + } +} + impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> { fn n(&self) -> Degree { self.key.n()@@ -37,6 +43,7 @@ fn size(&self) -> usize {
self.key.size() } } + impl<D: Data> GLWEInfos for AutomorphismKeyCompressed<D> { fn rank(&self) -> Rank { self.rank_out()@@ -199,7 +206,7 @@ res.set_p(other.p());
} } -impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: AutomorphismKeyDecompress {} +impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: GLWESwitchingKeyDecompress {} impl<D: DataMut> AutomorphismKey<D> where
M
poulpy-core/src/noise/mod.rs
→
poulpy-core/src/noise/mod.rs
@@ -3,8 +3,8 @@ mod ggsw_ct;
mod glwe_ct; pub use gglwe_ct::*; -pub use ggsw_ct::*; -pub use glwe_ct::*; +// pub use ggsw_ct::*; +// pub use glwe_ct::*; #[allow(clippy::too_many_arguments)] #[allow(dead_code)]
M
poulpy-core/src/tests/mod.rs
→
poulpy-core/src/tests/mod.rs
@@ -32,8 +32,8 @@ // glwe_packing => crate::tests::test_suite::test_glwe_packing,
// GGLWE Encryption gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, -// gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, -// gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, +gglwe_automorphism_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_encrypt_sk, +gglwe_automorphism_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphism_key_compressed_encrypt_sk, // gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, // gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, // GGLWE Keyswitching
M
poulpy-core/src/tests/test_suite/encryption/gglwe_atk.rs
→
poulpy-core/src/tests/test_suite/encryption/gglwe_atk.rs
@@ -1,71 +1,38 @@
use poulpy_hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare, - VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, - VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, - VecZnxCopy, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, - VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSubScalarInplace, VecZnxSwitchRing, - VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare, + ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, + VecZnxAutomorphism,VecZnxFillUniform, }, - layouts::{Backend, Module, ScratchOwned}, - oep::{ - ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl, - TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, - }, + layouts::{Backend, Module, Scratch, ScratchOwned, GaloisElement}, source::Source, }; use crate::{ encryption::SIGMA, layouts::{ - AutomorphismKey, AutomorphismKeyLayout, GLWEInfos, GLWESecret, - compressed::{AutomorphismKeyCompressed, Decompress}, - prepared::{GLWESecretPrepared, PrepareAlloc}, + compressed::AutomorphismKeyCompressed, prepared::GLWESecretPrepared, + AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, + GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKeyAlloc, GLWESwitchingKeyDecompress }, + noise::GGLWENoise, + GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore }; -pub fn test_gglwe_automorphisk_key_encrypt_sk<B>(module: &Module<B>) +pub fn test_gglwe_automorphism_key_encrypt_sk<BE: Backend>(module: &Module<BE>) where - Module<B>: VecZnxDftBytesOf - + VecZnxBigNormalize<B> - + VecZnxDftApply<B> - + SvpApplyDftToDftInplace<B> - + VecZnxIdftApplyConsume<B> - + VecZnxNormalizeTmpBytes + Module<BE>: GGLWEEncryptSk<BE> + + GGLWEKeyswitch<BE> + + GLWESecretPreparedAlloc<BE> + + GLWESecretPrepare<BE> + + GLWESwitchingKeyAlloc + + GLWESwitchingKeyEncryptSk<BE> + + GLWESwitchingKeyCompressedEncryptSk<BE> + + GLWESwitchingKeyDecompress + + GGLWENoise<BE> + VecZnxFillUniform - + VecZnxSubInplace - + VecZnxAddInplace - + VecZnxNormalizeInplace<B> - + VecZnxAddNormal - + VecZnxNormalize<B> - + VecZnxSub - + SvpPrepare<B> - + SvpPPolBytesOf - + SvpPPolAlloc<B> - + VmpApplyDftToDftTmpBytes - + VecZnxBigNormalizeTmpBytes - + VmpApplyDftToDft<B> - + VmpApplyDftToDftAdd<B> - + VecZnxBigAddSmallInplace<B> - + VecZnxAutomorphism - + VecZnxSwitchRing - + VecZnxAddScalarInplace - + VecZnxAutomorphismInplace<B> - + VecZnxBigBytesOf - + VecZnxBigAddInplace<B> - + VecZnxSubScalarInplace - + VecZnxCopy - + VmpPMatAlloc<B> - + VmpPrepare<B>, - B: Backend - + ScratchOwnedAllocImpl<B> - + ScratchOwnedBorrowImpl<B> - + ScratchAvailableImpl<B> - + TakeScalarZnxImpl<B> - + TakeVecZnxDftImpl<B> - + TakeVecZnxImpl<B> - + TakeSvpPPolImpl<B> - + TakeVecZnxBigImpl<B>, + + VecZnxAutomorphism, + ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, + Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, { let base2k: usize = 12; let k_ksk: usize = 60;@@ -84,17 +51,17 @@ dsize: di.into(),
rank: rank.into(), }; - let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&atk_infos); + let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(module, &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(AutomorphismKey::encrypt_sk_tmp_bytes( + let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_tmp_bytes( module, &atk_infos, )); - let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&atk_infos); + let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &atk_infos); sk.fill_ternary_prob(0.5, &mut source_xs); let p = -5;@@ -118,7 +85,8 @@ &sk.data.as_vec_znx(),
i, ); }); - let sk_out_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_out.prepare_alloc(module, scratch.borrow()); + let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank().into()); + sk_out_prepared.prepare(module, &sk_out); atk.key .key@@ -127,48 +95,21 @@ }
} } -pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>(module: &Module<B>) +pub fn test_gglwe_automorphism_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>) where - Module<B>: VecZnxDftBytesOf - + VecZnxBigNormalize<B> - + VecZnxDftApply<B> - + SvpApplyDftToDftInplace<B> - + VecZnxIdftApplyConsume<B> - + VecZnxNormalizeTmpBytes - + VecZnxFillUniform - + VecZnxSubInplace - + VecZnxAddInplace - + VecZnxNormalizeInplace<B> - + VecZnxAddNormal - + VecZnxNormalize<B> - + VecZnxSub - + SvpPrepare<B> - + SvpPPolBytesOf - + SvpPPolAlloc<B> - + VmpApplyDftToDftTmpBytes - + VecZnxBigNormalizeTmpBytes - + VmpApplyDftToDft<B> - + VmpApplyDftToDftAdd<B> - + VecZnxBigAddSmallInplace<B> + Module<BE>: GGLWEEncryptSk<BE> + + GGLWEKeyswitch<BE> + + GLWESecretPreparedAlloc<BE> + + GLWESecretPrepare<BE> + + GLWESwitchingKeyAlloc + + GLWESwitchingKeyEncryptSk<BE> + + GLWESwitchingKeyCompressedEncryptSk<BE> + + AutomorphismKeyDecompress + VecZnxAutomorphism - + VecZnxSwitchRing - + VecZnxAddScalarInplace - + VecZnxAutomorphismInplace<B> - + VecZnxBigBytesOf - + VecZnxBigAddInplace<B> - + VecZnxSubScalarInplace - + VecZnxCopy - + VmpPMatAlloc<B> - + VmpPrepare<B>, - B: Backend - + ScratchOwnedAllocImpl<B> - + ScratchOwnedBorrowImpl<B> - + ScratchAvailableImpl<B> - + TakeScalarZnxImpl<B> - + TakeVecZnxDftImpl<B> - + TakeVecZnxImpl<B> - + TakeSvpPPolImpl<B> - + TakeVecZnxBigImpl<B>, + + VecZnxFillUniform + + GGLWENoise<BE>, + ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, + Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, { let base2k: usize = 12; let k_ksk: usize = 60;@@ -187,16 +128,16 @@ dsize: di.into(),
rank: rank.into(), }; - let mut atk_compressed: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc_from_infos(&atk_infos); + let mut atk_compressed: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc_from_infos(module, &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(AutomorphismKey::encrypt_sk_tmp_bytes( + let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_tmp_bytes( module, &atk_infos, )); - let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&atk_infos); + let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &atk_infos); sk.fill_ternary_prob(0.5, &mut source_xs); let p = -5;@@ -215,9 +156,10 @@ &sk.data.as_vec_znx(),
i, ); }); - let sk_out_prepared = sk_out.prepare_alloc(module, scratch.borrow()); + let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank().into()); + sk_out_prepared.prepare(module, &sk_out); - let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&atk_infos); + let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(module, &atk_infos); atk.decompress(module, &atk_compressed); atk.key
M
poulpy-core/src/tests/test_suite/encryption/mod.rs
→
poulpy-core/src/tests/test_suite/encryption/mod.rs
@@ -1,10 +1,10 @@
-// mod gglwe_atk; +mod gglwe_atk; mod gglwe_ct; // mod ggsw_ct; mod glwe_ct; // mod glwe_tsk; -// pub use gglwe_atk::*; +pub use gglwe_atk::*; pub use gglwe_ct::*; // pub use ggsw_ct::*; pub use glwe_ct::*;