Traits reduction, file + structs renaming
jump to
@@ -1,7 +1,7 @@
use poulpy_core::layouts::{ AutomorphismKey, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, TorusPrecision, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared}, }; use std::{hint::black_box, time::Duration};@@ -104,7 +104,8 @@ &mut source_xe,
scratch.borrow(), ); - let mut ksk_prepared: AutomorphismKeyPrepared<Vec<u8>, _> = AutomorphismKeyPrepared::alloc_from_infos(&module, &ksk); + let mut ksk_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, _> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(&module, &ksk); ksk_prepared.prepare(&module, &ksk, scratch.borrow()); move || {
@@ -7,8 +7,7 @@ use crate::{
ScratchTakeCore, automorphism::glwe_ct::GLWEAutomorphism, layouts::{ - AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWE, - prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement}, + AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWE, GetGaloisElement, SetGaloisElement, }, };@@ -18,7 +17,7 @@ where
R: GGLWEInfos, A: GGLWEInfos, K: GGLWEInfos, - M: AutomorphismKeyAutomorphism<BE>, + M: GLWEAutomorphismKeyAutomorphism<BE>, { module.automorphism_key_automorphism_tmp_bytes(res_infos, a_infos, key_infos) }@@ -27,30 +26,30 @@
impl<DataSelf: DataMut> AutomorphismKey<DataSelf> { pub fn automorphism<A, K, M, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>) where - A: GGLWEToRef + GetAutomorphismGaloisElement + GGLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + A: GGLWEToRef + GetGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, - M: AutomorphismKeyAutomorphism<BE>, + M: GLWEAutomorphismKeyAutomorphism<BE>, { module.automorphism_key_automorphism(self, a, key, scratch); } pub fn automorphism_inplace<K, M, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) where - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, - M: AutomorphismKeyAutomorphism<BE>, + M: GLWEAutomorphismKeyAutomorphism<BE>, { module.automorphism_key_automorphism_inplace(self, key, scratch); } } -impl<BE: Backend> AutomorphismKeyAutomorphism<BE> for Module<BE> where +impl<BE: Backend> GLWEAutomorphismKeyAutomorphism<BE> for Module<BE> where Self: GaloisElement + GLWEAutomorphism<BE> + VecZnxAutomorphism { } -pub trait AutomorphismKeyAutomorphism<BE: Backend> +pub trait GLWEAutomorphismKeyAutomorphism<BE: Backend> where Self: GaloisElement + GLWEAutomorphism<BE> + VecZnxAutomorphism, {@@ -65,9 +64,9 @@ }
fn automorphism_key_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>) where - R: GGLWEToMut + SetAutomorphismGaloisElement + GGLWEInfos, - A: GGLWEToRef + GetAutomorphismGaloisElement + GGLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + R: GGLWEToMut + SetGaloisElement + GGLWEInfos, + A: GGLWEToRef + GetGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { assert!(@@ -121,8 +120,8 @@ }
fn automorphism_key_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) where - R: GGLWEToMut + SetAutomorphismGaloisElement + GetAutomorphismGaloisElement + GGLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + R: GGLWEToMut + SetGaloisElement + GetGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { assert_eq!(
@@ -7,7 +7,7 @@ use crate::{
GGSWExpandRows, ScratchTakeCore, automorphism::glwe_ct::GLWEAutomorphism, layouts::{ - GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GetAutomorphismGaloisElement, + GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GetGaloisElement, prepared::{TensorKeyPrepared, TensorKeyPreparedToRef}, }, };@@ -35,7 +35,7 @@ impl<D: DataMut> GGSW<D> {
pub fn automorphism<A, K, T, M, BE: Backend>(&mut self, module: &M, a: &A, key: &K, tsk: &T, scratch: &mut Scratch<BE>) where A: GGSWToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, T: TensorKeyPreparedToRef<BE>, Scratch<BE>: ScratchTakeCore<BE>, M: GGSWAutomorphism<BE>,@@ -45,7 +45,7 @@ }
pub fn automorphism_inplace<K, T, M, BE: Backend>(&mut self, module: &M, key: &K, tsk: &T, scratch: &mut Scratch<BE>) where - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, T: TensorKeyPreparedToRef<BE>, Scratch<BE>: ScratchTakeCore<BE>, M: GGSWAutomorphism<BE>,@@ -78,7 +78,7 @@ fn ggsw_automorphism<R, A, K, T>(&self, res: &mut R, a: &A, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
where R: GGSWToMut, A: GGSWToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, T: TensorKeyPreparedToRef<BE>, Scratch<BE>: ScratchTakeCore<BE>, {@@ -103,7 +103,7 @@
fn ggsw_automorphism_inplace<R, K, T>(&self, res: &mut R, key: &K, tsk: &T, scratch: &mut Scratch<BE>) where R: GGSWToMut, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, T: TensorKeyPreparedToRef<BE>, Scratch<BE>: ScratchTakeCore<BE>, {
@@ -8,9 +8,7 @@ };
use crate::{ GLWEKeyswitch, ScratchTakeCore, keyswitch_internal, - layouts::{ - GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, prepared::GetAutomorphismGaloisElement, - }, + layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos}, }; impl GLWE<Vec<u8>> {@@ -30,7 +28,7 @@ pub fn automorphism<M, A, K, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
where M: GLWEAutomorphism<BE>, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism(self, a, key, scratch);@@ -40,7 +38,7 @@ pub fn automorphism_add<M, A, K, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
where M: GLWEAutomorphism<BE>, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism_add(self, a, key, scratch);@@ -50,7 +48,7 @@ pub fn automorphism_sub<M, A, K, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
where M: GLWEAutomorphism<BE>, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism_sub(self, a, key, scratch);@@ -60,7 +58,7 @@ pub fn glwe_automorphism_sub_negate<M, A, K, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
where M: GLWEAutomorphism<BE>, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism_sub_negate(self, a, key, scratch);@@ -69,7 +67,7 @@
pub fn automorphism_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) where M: GLWEAutomorphism<BE>, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism_inplace(self, key, scratch);@@ -78,7 +76,7 @@
pub fn automorphism_add_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) where M: GLWEAutomorphism<BE>, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism_add_inplace(self, key, scratch);@@ -87,7 +85,7 @@
pub fn automorphism_sub_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) where M: GLWEAutomorphism<BE>, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism_sub_inplace(self, key, scratch);@@ -96,7 +94,7 @@
pub fn automorphism_sub_negate_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) where M: GLWEAutomorphism<BE>, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { module.glwe_automorphism_sub_negate_inplace(self, key, scratch);@@ -124,7 +122,7 @@ fn glwe_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
where R: GLWEToMut, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { self.glwe_keyswitch(res, a, key, scratch);@@ -139,7 +137,7 @@
fn glwe_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) where R: GLWEToMut, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { self.glwe_keyswitch_inplace(res, key, scratch);@@ -155,7 +153,7 @@ fn glwe_automorphism_add<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
where R: GLWEToMut, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();@@ -182,7 +180,7 @@
fn glwe_automorphism_add_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) where R: GLWEToMut, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();@@ -209,7 +207,7 @@ fn glwe_automorphism_sub<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
where R: GLWEToMut, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();@@ -237,7 +235,7 @@ fn glwe_automorphism_sub_negate<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
where R: GLWEToMut, A: GLWEToRef, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();@@ -264,7 +262,7 @@
fn glwe_automorphism_sub_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) where R: GLWEToMut, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();@@ -290,7 +288,7 @@
fn glwe_automorphism_sub_negate_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) where R: GLWEToMut, - K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, + K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
@@ -85,7 +85,7 @@ k: res.k(),
rank: Rank(1), }; - let (mut tmp_glwe, scratch_1) = scratch.take_glwe_ct(self, &glwe_layout); + let (mut tmp_glwe, scratch_1) = scratch.take_glwe(self, &glwe_layout); self.glwe_keyswitch(&mut tmp_glwe, a, key, scratch_1); self.lwe_sample_extract(res, &tmp_glwe); }
@@ -50,7 +50,7 @@ assert_eq!(res.n(), self.n() as u32);
assert_eq!(ksk.n(), self.n() as u32); assert!(lwe.n() <= self.n() as u32); - let (mut glwe, scratch_1) = scratch.take_glwe_ct( + let (mut glwe, scratch_1) = scratch.take_glwe( self, &GLWELayout { n: ksk.n(),
@@ -1,5 +1,5 @@
-mod glwe_ct; -mod lwe_ct; +mod glwe; +mod lwe; -pub use glwe_ct::*; -pub use lwe_ct::*; +pub use glwe::*; +pub use lwe::*;
@@ -7,12 +7,12 @@
use crate::{ GGLWECompressedEncryptSk, ScratchTakeCore, layouts::{ - GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepare, GLWESecretPrepared, - GLWESecretPreparedAlloc, GLWESecretToRef, LWEInfos, SetAutomorphismGaloisElement, compressed::AutomorphismKeyCompressed, + GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, + GLWESecretPreparedApi, GLWESecretToRef, LWEInfos, SetGaloisElement, compressed::GLWEAutomorphismKeyCompressed, }, }; -impl AutomorphismKeyCompressed<Vec<u8>> { +impl GLWEAutomorphismKeyCompressed<Vec<u8>> { pub fn encrypt_sk_tmp_bytes<M, BE: Backend, A>(module: &M, infos: &A) -> usize where A: GGLWEInfos,@@ -22,7 +22,7 @@ module.automorphism_key_compressed_encrypt_sk_tmp_bytes(infos)
} } -impl<DataSelf: DataMut> AutomorphismKeyCompressed<DataSelf> { +impl<DataSelf: DataMut> GLWEAutomorphismKeyCompressed<DataSelf> { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk<M, S, BE: Backend>( &mut self,@@ -54,18 +54,13 @@ seed_xa: [u8; 32],
source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetAutomorphismGaloisElement + GGLWEInfos, + R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos, S: GLWESecretToRef + GLWEInfos; } impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE> where - Self: ModuleN - + GaloisElement - + VecZnxAutomorphism - + GGLWECompressedEncryptSk<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE>, + Self: ModuleN + GaloisElement + VecZnxAutomorphism + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedApi<BE>, Scratch<BE>: ScratchTakeCore<BE>, { fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize@@ -87,7 +82,7 @@ seed_xa: [u8; 32],
source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetAutomorphismGaloisElement + GGLWEInfos, + R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos, S: GLWESecretToRef + GLWEInfos, { let sk: &GLWESecret<&[u8]> = &sk.to_ref();@@ -95,10 +90,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() >= AutomorphismKeyCompressed::encrypt_sk_tmp_bytes(self, res), + scratch.available() >= GLWEAutomorphismKeyCompressed::encrypt_sk_tmp_bytes(self, res), "scratch.available(): {} < AutomorphismKey::encrypt_sk_tmp_bytes: {}", scratch.available(), - AutomorphismKeyCompressed::encrypt_sk_tmp_bytes(self, res) + GLWEAutomorphismKeyCompressed::encrypt_sk_tmp_bytes(self, res) ); let (mut sk_out_prepared, scratch_1) = scratch.take_glwe_secret_prepared(self, sk.rank());
@@ -6,10 +6,7 @@ };
use crate::{ ScratchTakeCore, - encryption::{ - SIGMA, - glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal}, - }, + encryption::{GLWEEncryptSk, GLWEEncryptSkInternal, SIGMA}, layouts::{ GGLWECompressedSeedMut, GGLWEInfos, GLWEPlaintext, GLWESecretPrepared, LWEInfos, compressed::{GGLWECompressed, GGLWECompressedToMut},@@ -145,7 +142,7 @@ let cols: usize = (res.rank_out() + 1).into();
let mut source_xa = Source::new(seed); - let (mut tmp_pt, scrach_1) = scratch.take_glwe_pt(self, res); + let (mut tmp_pt, scrach_1) = scratch.take_glwe_plaintext(self, res); for col_i in 0..rank_in { for d_i in 0..dnum { // Adds the scalar_znx_pt to the i-th limb of the vec_znx_pt
@@ -5,13 +5,12 @@ source::Source,
}; use crate::{ - ScratchTakeCore, - encryption::compressed::gglwe_ct::GGLWECompressedEncryptSk, + GGLWECompressedEncryptSk, ScratchTakeCore, layouts::{ GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKeyDegreesMut, LWEInfos, compressed::GLWESwitchingKeyCompressed, - prepared::{GLWESecretPrepare, GLWESecretPrepared, GLWESecretPreparedAlloc}, + prepared::{GLWESecretPrepared, GLWESecretPreparedApi}, }, };@@ -65,7 +64,7 @@ }
impl<BE: Backend> GLWESwitchingKeyCompressedEncryptSk<BE> for Module<BE> where - Self: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing, + Self: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedApi<BE> + VecZnxSwitchRing, Scratch<BE>: ScratchTakeCore<BE>, { fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -8,15 +8,14 @@ source::Source,
}; use crate::{ - GGLWECompressedEncryptSk, GetDistribution, ScratchTakeCore, - encryption::gglwe_tsk::TensorKeyEncryptSk, + GGLWECompressedEncryptSk, GetDistribution, ScratchTakeCore, TensorKeyEncryptSk, layouts::{ - GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedAlloc, GLWESecretToRef, LWEInfos, Rank, - TensorKeyCompressedAtMut, compressed::TensorKeyCompressed, + GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedApi, GLWESecretToRef, LWEInfos, Rank, + TensorKeyCompressedAtMut, compressed::GLWETensorKeyCompressed, }, }; -impl TensorKeyCompressed<Vec<u8>> { +impl GLWETensorKeyCompressed<Vec<u8>> { pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize where A: GGLWEInfos,@@ -26,7 +25,7 @@ module.tensor_key_compressed_encrypt_sk_tmp_bytes(infos)
} } -impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> { +impl<DataSelf: DataMut> GLWETensorKeyCompressed<DataSelf> { pub fn encrypt_sk<S, M, BE: Backend>( &mut self, module: &M,@@ -73,7 +72,7 @@ + SvpPrepare<BE>
+ SvpPPolBytesOf + VecZnxDftBytesOf + VecZnxBigBytesOf - + GLWESecretPreparedAlloc<BE>, + + GLWESecretPreparedApi<BE>, Scratch<BE>: ScratchTakeBasic + ScratchTakeCore<BE>, { fn tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -6,7 +6,7 @@ };
use crate::{ ScratchTakeCore, - encryption::{SIGMA, ggsw_ct::GGSWEncryptSk, glwe_ct::GLWEEncryptSkInternal}, + encryption::{GGSWEncryptSk, GLWEEncryptSkInternal, SIGMA}, layouts::{ GGSWCompressedSeedMut, GGSWInfos, GLWEInfos, LWEInfos, compressed::{GGSWCompressed, GGSWCompressedToMut},@@ -107,7 +107,7 @@ let res: &mut GGSWCompressed<&mut [u8]> = &mut res.to_mut();
println!("res.seed: {:?}", res.seed); - let (mut tmp_pt, scratch_1) = scratch.take_glwe_pt(self, &res.glwe_layout()); + let (mut tmp_pt, scratch_1) = scratch.take_glwe_plaintext(self, &res.glwe_layout()); let mut source = Source::new(seed_xa);
@@ -4,10 +4,7 @@ source::Source,
}; use crate::{ - encryption::{ - SIGMA, - glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal}, - }, + encryption::{GLWEEncryptSk, GLWEEncryptSkInternal, SIGMA}, layouts::{ GLWECompressedSeedMut, GLWEInfos, GLWEPlaintextToRef, LWEInfos, compressed::{GLWECompressed, GLWECompressedToMut},
@@ -1,13 +1,13 @@
-mod gglwe_atk; -mod gglwe_ct; -mod gglwe_ksk; -mod gglwe_tsk; -mod ggsw_ct; +mod gglwe; +mod ggsw; +mod glwe_automorphism_key; mod glwe_ct; +mod glwe_switching_key; +mod glwe_tensor_key; -pub use gglwe_atk::*; -pub use gglwe_ct::*; -pub use gglwe_ksk::*; -pub use gglwe_tsk::*; -pub use ggsw_ct::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe_automorphism_key::*; pub use glwe_ct::*; +pub use glwe_switching_key::*; +pub use glwe_tensor_key::*;
@@ -7,8 +7,8 @@
use crate::{ GGLWEEncryptSk, ScratchTakeCore, layouts::{ - AutomorphismKey, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESecret, GLWESecretPrepare, GLWESecretPrepared, - GLWESecretPreparedAlloc, GLWESecretToRef, LWEInfos, SetAutomorphismGaloisElement, + AutomorphismKey, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedApi, + GLWESecretToRef, LWEInfos, SetGaloisElement, }, };@@ -64,18 +64,13 @@ source_xa: &mut Source,
source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - R: GGLWEToMut + SetAutomorphismGaloisElement + GGLWEInfos, + R: GGLWEToMut + SetGaloisElement + GGLWEInfos, S: GLWESecretToRef; } impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE> where - Self: GGLWEEncryptSk<BE> - + VecZnxAutomorphism - + GaloisElement - + SvpPPolBytesOf - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE>, + Self: GGLWEEncryptSk<BE> + VecZnxAutomorphism + GaloisElement + SvpPPolBytesOf + GLWESecretPreparedApi<BE>, Scratch<BE>: ScratchTakeCore<BE>, { fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize@@ -102,7 +97,7 @@ source_xa: &mut Source,
source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - R: GGLWEToMut + SetAutomorphismGaloisElement + GGLWEInfos, + R: GGLWEToMut + SetGaloisElement + GGLWEInfos, S: GLWESecretToRef, { let sk: &GLWESecret<&[u8]> = &sk.to_ref();
@@ -5,8 +5,7 @@ source::Source,
}; use crate::{ - ScratchTakeCore, - encryption::glwe_ct::GLWEEncryptSk, + GLWEEncryptSk, ScratchTakeCore, layouts::GLWEInfos, layouts::{ GGLWE, GGLWEInfos, GGLWEToMut, GLWEPlaintext, LWEInfos,@@ -144,7 +143,7 @@ let dsize: usize = res.dsize().into();
let base2k: usize = res.base2k().into(); let rank_in: usize = res.rank_in().into(); - let (mut tmp_pt, scrach_1) = scratch.take_glwe_pt(self, &res.glwe_layout()); + let (mut tmp_pt, scrach_1) = scratch.take_glwe_plaintext(self, &res.glwe_layout()); // For each input column (i.e. rank) produces a GGLWE of rank_out+1 columns // // Example for ksk rank 2 to rank 3:
@@ -6,10 +6,10 @@ };
use crate::{ ScratchTakeCore, - encryption::gglwe_ct::GGLWEEncryptSk, + encryption::gglwe::GGLWEEncryptSk, layouts::{ GGLWEInfos, GGLWEToMut, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, GLWESwitchingKeyDegreesMut, LWEInfos, - prepared::GLWESecretPreparedAlloc, + prepared::GLWESecretPreparedApi, }, };@@ -71,7 +71,7 @@ }
impl<BE: Backend> GLWESwitchingKeyEncryptSk<BE> for Module<BE> where - Self: ModuleN + GGLWEEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxSwitchRing + SvpPrepare<BE>, + Self: ModuleN + GGLWEEncryptSk<BE> + GLWESecretPreparedApi<BE> + VecZnxSwitchRing + SvpPrepare<BE>, Scratch<BE>: ScratchTakeCore<BE>, { fn glwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -11,7 +11,7 @@ use crate::{
GGLWEEncryptSk, GetDistribution, ScratchTakeCore, layouts::{ GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey, TensorKeyToMut, - prepared::{GLWESecretPrepare, GLWESecretPrepared, GLWESecretPreparedAlloc}, + prepared::{GLWESecretPrepared, GLWESecretPreparedApi}, }, };@@ -65,8 +65,7 @@ Self: ModuleN
+ GGLWEEncryptSk<BE> + VecZnxDftBytesOf + VecZnxBigBytesOf - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + VecZnxDftApply<BE> + SvpApplyDftToDft<BE> + VecZnxIdftApplyTmpA<BE>
@@ -5,8 +5,7 @@ source::Source,
}; use crate::{ - SIGMA, ScratchTakeCore, - encryption::glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal}, + GLWEEncryptSk, GLWEEncryptSkInternal, SIGMA, ScratchTakeCore, layouts::{ GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},@@ -110,7 +109,7 @@ let rank: usize = res.rank().into();
let dsize: usize = res.dsize().into(); let cols: usize = (rank + 1).into(); - let (mut tmp_pt, scratch_1) = scratch.take_glwe_pt(self, res); + let (mut tmp_pt, scratch_1) = scratch.take_glwe_plaintext(self, res); for row_i in 0..res.dnum().into() { tmp_pt.data.zero();
@@ -10,12 +10,12 @@ source::Source,
}; use crate::{ - ScratchTakeCore, + GetDistribution, ScratchTakeCore, dist::Distribution, encryption::{SIGMA, SIGMA_BOUND}, layouts::{ - GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, GLWEToMut, LWEInfos, - prepared::{GLWEPublicKeyPrepared, GLWEPublicKeyPreparedToRef, GLWESecretPrepared, GLWESecretPreparedToRef}, + GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, GLWEPrepared, GLWEPreparedToRef, GLWEToMut, LWEInfos, + prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, }, };@@ -80,7 +80,7 @@ source_xe: &mut Source,
scratch: &mut Scratch<BE>, ) where P: GLWEPlaintextToRef + GLWEInfos, - K: GLWEPublicKeyPreparedToRef<BE>, + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos, M: GLWEEncryptPk<BE>, { module.glwe_encrypt_pk(self, pt, pk, source_xu, source_xe, scratch);@@ -94,7 +94,7 @@ source_xu: &mut Source,
source_xe: &mut Source, scratch: &mut Scratch<BE>, ) where - K: GLWEPublicKeyPreparedToRef<BE>, + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos, M: GLWEEncryptPk<BE>, { module.glwe_encrypt_zero_pk(self, pk, source_xu, source_xe, scratch);@@ -246,7 +246,7 @@ scratch: &mut Scratch<BE>,
) where R: GLWEToMut, P: GLWEPlaintextToRef + GLWEInfos, - K: GLWEPublicKeyPreparedToRef<BE>; + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos; fn glwe_encrypt_zero_pk<R, K>( &self,@@ -257,7 +257,7 @@ source_xe: &mut Source,
scratch: &mut Scratch<BE>, ) where R: GLWEToMut, - K: GLWEPublicKeyPreparedToRef<BE>; + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos; } impl<BE: Backend> GLWEEncryptPk<BE> for Module<BE>@@ -286,7 +286,7 @@ scratch: &mut Scratch<BE>,
) where R: GLWEToMut, P: GLWEPlaintextToRef + GLWEInfos, - K: GLWEPublicKeyPreparedToRef<BE>, + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos, { self.glwe_encrypt_pk_internal(res, Some((pt, 0)), pk, source_xu, source_xe, scratch); }@@ -300,7 +300,7 @@ source_xe: &mut Source,
scratch: &mut Scratch<BE>, ) where R: GLWEToMut, - K: GLWEPublicKeyPreparedToRef<BE>, + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos, { self.glwe_encrypt_pk_internal( res,@@ -325,7 +325,7 @@ scratch: &mut Scratch<BE>,
) where R: GLWEToMut, P: GLWEPlaintextToRef + GLWEInfos, - K: GLWEPublicKeyPreparedToRef<BE>; + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos; } impl<BE: Backend> GLWEEncryptPkInternal<BE> for Module<BE>@@ -352,10 +352,9 @@ scratch: &mut Scratch<BE>,
) where R: GLWEToMut, P: GLWEPlaintextToRef + GLWEInfos, - K: GLWEPublicKeyPreparedToRef<BE>, + K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); - let pk: &GLWEPublicKeyPrepared<&[u8], BE> = &pk.to_ref(); assert_eq!(res.base2k(), pk.base2k()); assert_eq!(res.n(), pk.n());@@ -374,52 +373,56 @@ let (mut u_dft, scratch_1) = scratch.take_svp_ppol(self, 1);
{ let (mut u, _) = scratch_1.take_scalar_znx(self, 1); - match pk.dist { + match pk.dist() { Distribution::NONE => panic!( "invalid public key: SecretDistribution::NONE, ensure it has been correctly intialized through \ Self::generate" ), - Distribution::TernaryFixed(hw) => u.fill_ternary_hw(0, hw, source_xu), - Distribution::TernaryProb(prob) => u.fill_ternary_prob(0, prob, source_xu), - Distribution::BinaryFixed(hw) => u.fill_binary_hw(0, hw, source_xu), - Distribution::BinaryProb(prob) => u.fill_binary_prob(0, prob, source_xu), - Distribution::BinaryBlock(block_size) => u.fill_binary_block(0, block_size, source_xu), + Distribution::TernaryFixed(hw) => u.fill_ternary_hw(0, *hw, source_xu), + Distribution::TernaryProb(prob) => u.fill_ternary_prob(0, *prob, source_xu), + Distribution::BinaryFixed(hw) => u.fill_binary_hw(0, *hw, source_xu), + Distribution::BinaryProb(prob) => u.fill_binary_prob(0, *prob, source_xu), + Distribution::BinaryBlock(block_size) => u.fill_binary_block(0, *block_size, source_xu), Distribution::ZERO => {} } self.svp_prepare(&mut u_dft, 0, &u, 0); } - // ct[i] = pk[i] * u + ei (+ m if col = i) - (0..cols).for_each(|i| { - let (mut ci_dft, scratch_2) = scratch_1.take_vec_znx_dft(self, 1, size_pk); - // ci_dft = DFT(u) * DFT(pk[i]) - self.svp_apply_dft_to_dft(&mut ci_dft, 0, &u_dft, 0, &pk.data, i); + { + let pk: &GLWEPrepared<&[u8], BE> = &pk.to_ref(); + + // ct[i] = pk[i] * u + ei (+ m if col = i) + for i in 0..cols { + let (mut ci_dft, scratch_2) = scratch_1.take_vec_znx_dft(self, 1, size_pk); + // ci_dft = DFT(u) * DFT(pk[i]) + self.svp_apply_dft_to_dft(&mut ci_dft, 0, &u_dft, 0, &pk.data, i); + + // ci_big = u * p[i] + let mut ci_big = self.vec_znx_idft_apply_consume(ci_dft); - // ci_big = u * p[i] - let mut ci_big = self.vec_znx_idft_apply_consume(ci_dft); + // ci_big = u * pk[i] + e + self.vec_znx_big_add_normal( + base2k, + &mut ci_big, + 0, + pk.k().into(), + source_xe, + SIGMA, + SIGMA_BOUND, + ); - // ci_big = u * pk[i] + e - self.vec_znx_big_add_normal( - base2k, - &mut ci_big, - 0, - pk.k().into(), - source_xe, - SIGMA, - SIGMA_BOUND, - ); + // ci_big = u * pk[i] + e + m (if col = i) + if let Some((pt, col)) = pt + && col == i + { + self.vec_znx_big_add_small_inplace(&mut ci_big, 0, &pt.to_ref().data, 0); + } - // ci_big = u * pk[i] + e + m (if col = i) - if let Some((pt, col)) = pt - && col == i - { - self.vec_znx_big_add_small_inplace(&mut ci_big, 0, &pt.to_ref().data, 0); + // ct[i] = norm(ci_big) + self.vec_znx_big_normalize(base2k, &mut res.data, i, base2k, &ci_big, 0, scratch_2); } - - // ct[i] = norm(ci_big) - self.vec_znx_big_normalize(base2k, &mut res.data, i, base2k, &ci_big, 0, scratch_2); - }); + } } }
@@ -5,10 +5,9 @@ source::Source,
}; use crate::{ - Distribution, GetDistribution, GetDistributionMut, ScratchTakeCore, - encryption::glwe_ct::GLWEEncryptSk, + Distribution, GLWEEncryptSk, GetDistribution, GetDistributionMut, ScratchTakeCore, layouts::{ - GLWE, GLWEPublicKey, GLWEPublicKeyToMut, LWEInfos, + GLWE, GLWEInfos, GLWEPublicKey, GLWEToMut, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, }, };@@ -26,7 +25,7 @@
pub trait GLWEPublicKeyGenerate<BE: Backend> { fn glwe_public_key_generate<R, S>(&self, res: &mut R, sk: &S, source_xa: &mut Source, source_xe: &mut Source) where - R: GLWEPublicKeyToMut + GetDistributionMut, + R: GLWEToMut + GetDistributionMut + GLWEInfos, S: GLWESecretPreparedToRef<BE> + GetDistribution; }@@ -38,11 +37,10 @@ Scratch<BE>: ScratchTakeCore<BE>,
{ fn glwe_public_key_generate<R, S>(&self, res: &mut R, sk: &S, source_xa: &mut Source, source_xe: &mut Source) where - R: GLWEPublicKeyToMut + GetDistributionMut, + R: GLWEToMut + GetDistributionMut + GLWEInfos, S: GLWESecretPreparedToRef<BE> + GetDistribution, { { - let res: &mut GLWEPublicKey<&mut [u8]> = &mut res.to_mut(); let sk: &GLWESecretPrepared<&[u8], BE> = &sk.to_ref(); assert_eq!(res.n(), self.n() as u32);
@@ -7,9 +7,9 @@
use crate::{ GGLWEEncryptSk, ScratchTakeCore, layouts::{ - GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretPrepare, GLWESecretToRef, GLWEToLWESwitchingKey, LWEInfos, - LWESecret, LWESecretToRef, Rank, - prepared::{GLWESecretPrepared, GLWESecretPreparedAlloc}, + GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretToRef, GLWEToLWESwitchingKey, LWEInfos, LWESecret, LWESecretToRef, + Rank, + prepared::{GLWESecretPrepared, GLWESecretPreparedApi}, }, };@@ -65,10 +65,9 @@ impl<BE: Backend> GLWEToLWESwitchingKeyEncryptSk<BE> for Module<BE>
where Self: ModuleN + GGLWEEncryptSk<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxAutomorphismInplace<BE> - + VecZnxAutomorphismInplaceTmpBytes - + GLWESecretPrepare<BE>, + + VecZnxAutomorphismInplaceTmpBytes, Scratch<BE>: ScratchTakeCore<BE>, { fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -6,11 +6,11 @@ };
use crate::{ ScratchTakeCore, - encryption::gglwe_ksk::GLWESwitchingKeyEncryptSk, + encryption::glwe_switching_key::GLWESwitchingKeyEncryptSk, layouts::{ GGLWEInfos, GGLWEToMut, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyDegreesMut, LWEInfos, LWESecret, LWESecretToRef, LWESwitchingKey, Rank, - prepared::{GLWESecretPrepared, GLWESecretPreparedAlloc}, + prepared::{GLWESecretPrepared, GLWESecretPreparedApi}, }, };@@ -63,7 +63,7 @@ }
impl<BE: Backend> LWESwitchingKeyEncrypt<BE> for Module<BE> where - Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>, + Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedApi<BE> + VecZnxAutomorphismInplace<BE>, Scratch<BE>: ScratchTakeCore<BE>, { fn lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -7,7 +7,7 @@
use crate::{ GGLWEEncryptSk, ScratchTakeCore, layouts::{ - GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretPreparedAlloc, GLWESecretPreparedToRef, LWEInfos, LWESecret, + GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretPreparedApi, GLWESecretPreparedToRef, LWEInfos, LWESecret, LWESecretToRef, LWEToGLWESwitchingKey, Rank, }, };@@ -65,7 +65,7 @@ where
Self: ModuleN + GGLWEEncryptSk<BE> + VecZnxAutomorphismInplace<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxAutomorphismInplaceTmpBytes, Scratch<BE>: ScratchTakeCore<BE>, {
@@ -1,28 +1,28 @@
mod compressed; -mod gglwe_atk; -mod gglwe_ct; -mod gglwe_ksk; -mod gglwe_tsk; -mod ggsw_ct; -mod glwe_ct; -mod glwe_pk; -mod glwe_to_lwe_ksk; -mod lwe_ct; -mod lwe_ksk; -mod lwe_to_glwe_ksk; +mod gglwe; +mod ggsw; +mod glwe; +mod glwe_automorphism_key; +mod glwe_public_key; +mod glwe_switching_key; +mod glwe_tensor_key; +mod glwe_to_lwe_switching_key; +mod lwe; +mod lwe_switching_key; +mod lwe_to_glwe_switching_key; pub use compressed::*; -pub use gglwe_atk::*; -pub use gglwe_ct::*; -pub use gglwe_ksk::*; -pub use gglwe_tsk::*; -pub use ggsw_ct::*; -pub use glwe_ct::*; -pub use glwe_pk::*; -pub use glwe_to_lwe_ksk::*; -pub use lwe_ct::*; -pub use lwe_ksk::*; -pub use lwe_to_glwe_ksk::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe::*; +pub use glwe_automorphism_key::*; +pub use glwe_public_key::*; +pub use glwe_switching_key::*; +pub use glwe_tensor_key::*; +pub use glwe_to_lwe_switching_key::*; +pub use lwe::*; +pub use lwe_switching_key::*; +pub use lwe_to_glwe_switching_key::*; pub const SIGMA: f64 = 3.2; pub(crate) const SIGMA_BOUND: f64 = 6.0 * SIGMA;
@@ -1,46 +0,0 @@
-use poulpy_hal::layouts::{Backend, DataMut, Scratch}; - -use crate::{ - ScratchTakeCore, - external_product::gglwe_ksk::GGLWEExternalProduct, - layouts::{AutomorphismKey, GGLWEInfos, GGLWEToRef, GGSWInfos, prepared::GGSWPreparedToRef}, -}; - -impl AutomorphismKey<Vec<u8>> { - pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>( - &self, - module: &M, - res_infos: &R, - a_infos: &A, - b_infos: &B, - ) -> usize - where - R: GGLWEInfos, - A: GGLWEInfos, - B: GGSWInfos, - M: GGLWEExternalProduct<BE>, - { - module.gglwe_external_product_tmp_bytes(res_infos, a_infos, b_infos) - } -} - -impl<DataSelf: DataMut> AutomorphismKey<DataSelf> { - pub fn external_product<A, B, M, BE: Backend>(&mut self, module: &M, a: &A, b: &B, scratch: &mut Scratch<BE>) - where - M: GGLWEExternalProduct<BE>, - A: GGLWEToRef, - B: GGSWPreparedToRef<BE>, - Scratch<BE>: ScratchTakeCore<BE>, - { - module.gglwe_external_product(self, a, b, scratch); - } - - pub fn external_product_inplace<A, M, BE: Backend>(&mut self, module: &M, a: &A, scratch: &mut Scratch<BE>) - where - M: GGLWEExternalProduct<BE>, - A: GGSWPreparedToRef<BE>, - Scratch<BE>: ScratchTakeCore<BE>, - { - module.gglwe_external_product_inplace(self, a, scratch); - } -}
@@ -3,10 +3,49 @@
use crate::{ GLWEExternalProduct, ScratchTakeCore, layouts::{ - GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GLWEInfos, GLWESwitchingKey, - prepared::{GGSWPrepared, GGSWPreparedToRef}, + AutomorphismKey, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GGSWPrepared, GLWEInfos, GLWESwitchingKey, + prepared::GGSWPreparedToRef, }, }; + +impl AutomorphismKey<Vec<u8>> { + pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>( + &self, + module: &M, + res_infos: &R, + a_infos: &A, + b_infos: &B, + ) -> usize + where + R: GGLWEInfos, + A: GGLWEInfos, + B: GGSWInfos, + M: GGLWEExternalProduct<BE>, + { + module.gglwe_external_product_tmp_bytes(res_infos, a_infos, b_infos) + } +} + +impl<DataSelf: DataMut> AutomorphismKey<DataSelf> { + pub fn external_product<A, B, M, BE: Backend>(&mut self, module: &M, a: &A, b: &B, scratch: &mut Scratch<BE>) + where + M: GGLWEExternalProduct<BE>, + A: GGLWEToRef, + B: GGSWPreparedToRef<BE>, + Scratch<BE>: ScratchTakeCore<BE>, + { + module.gglwe_external_product(self, a, b, scratch); + } + + pub fn external_product_inplace<A, M, BE: Backend>(&mut self, module: &M, a: &A, scratch: &mut Scratch<BE>) + where + M: GGLWEExternalProduct<BE>, + A: GGSWPreparedToRef<BE>, + Scratch<BE>: ScratchTakeCore<BE>, + { + module.gglwe_external_product_inplace(self, a, scratch); + } +} pub trait GGLWEExternalProduct<BE: Backend> where
@@ -1,8 +1,7 @@
-mod gglwe_atk; -mod gglwe_ksk; -mod ggsw_ct; -mod glwe_ct; +mod gglwe; +mod ggsw; +mod glwe; -pub use gglwe_ksk::*; -pub use ggsw_ct::*; -pub use glwe_ct::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe::*;
@@ -8,9 +8,7 @@
use crate::{ GLWEAdd, GLWEAutomorphism, GLWECopy, GLWENormalize, GLWERotate, GLWEShift, GLWESub, ScratchTakeCore, glwe_trace::GLWETrace, - layouts::{ - GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, prepared::GetAutomorphismGaloisElement, - }, + layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos}, }; /// [GLWEPacker] enables only the fly GLWE packing@@ -117,7 +115,7 @@ /// * `scratch`: scratch space of size at least [Self::tmp_bytes].
pub fn add<A, K, M, BE: Backend>(&mut self, module: &M, a: Option<&A>, auto_keys: &HashMap<i64, K>, scratch: &mut Scratch<BE>) where A: GLWEToRef + GLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, M: GLWEPacking<BE>, Scratch<BE>: ScratchTakeCore<BE>, {@@ -190,7 +188,7 @@ keys: &HashMap<i64, K>,
scratch: &mut Scratch<BE>, ) where R: GLWEToMut + GLWEToRef + GLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { #[cfg(debug_assertions)]@@ -234,7 +232,7 @@ auto_keys: &HashMap<i64, K>,
scratch: &mut Scratch<BE>, ) where A: GLWEToRef + GLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, M: ModuleLogN + GLWEAutomorphism<BE> + GaloisElement@@ -307,7 +305,7 @@ ) where
B: GLWEToRef + GLWEInfos, M: GLWEAutomorphism<BE> + GaloisElement + GLWERotate<BE> + GLWESub + GLWEShift<BE> + GLWEAdd + GLWENormalize<BE>, B: GLWEToRef + GLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let log_n: usize = acc.data.n().log2();@@ -333,7 +331,7 @@ // either mapped to garbage or twice their value which vanishes I(X)
// since 2*(I(X) * Q/2) = I(X) * Q = 0 mod Q. if acc.value { if let Some(b) = b { - let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(module, a); + let (mut tmp_b, scratch_1) = scratch.take_glwe(module, a); // a = a * X^-t module.glwe_rotate_inplace(-t, a, scratch_1);@@ -373,7 +371,7 @@ panic!("auto_key[{gal_el}] not found");
} } } else if let Some(b) = b { - let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(module, a); + let (mut tmp_b, scratch_1) = scratch.take_glwe(module, a); module.glwe_rotate(t, &mut tmp_b, b); module.glwe_rsh(1, &mut tmp_b, scratch_1);@@ -400,7 +398,7 @@ ) where
M: GLWEAutomorphism<BE> + GLWERotate<BE> + GLWESub + GLWEShift<BE> + GLWEAdd + GLWENormalize<BE>, A: GLWEToMut + GLWEToRef + GLWEInfos, B: GLWEToMut + GLWEToRef + GLWEInfos, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { // Goal is to evaluate: a = a + b*X^t + phi(a - b*X^t))@@ -417,7 +415,7 @@ if let Some(a) = a.as_deref_mut() {
let t: i64 = 1 << (a.n().log2() - i - 1); if let Some(b) = b.as_deref_mut() { - let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(module, a); + let (mut tmp_b, scratch_1) = scratch.take_glwe(module, a); // a = a * X^-t module.glwe_rotate_inplace(-t, a, scratch_1);@@ -451,7 +449,7 @@ }
} else if let Some(b) = b.as_deref_mut() { let t: i64 = 1 << (b.n().log2() - i - 1); - let (mut tmp_b, scratch_1) = scratch.take_glwe_ct(module, b); + let (mut tmp_b, scratch_1) = scratch.take_glwe(module, b); module.glwe_rotate(t, &mut tmp_b, b); module.glwe_rsh(1, &mut tmp_b, scratch_1);
@@ -8,8 +8,7 @@
use crate::{ GLWEAutomorphism, GLWECopy, GLWEShift, ScratchTakeCore, layouts::{ - Base2K, GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWELayout, GLWEToMut, GLWEToRef, LWEInfos, - prepared::GetAutomorphismGaloisElement, + Base2K, GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWELayout, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos, }, };@@ -43,7 +42,7 @@ keys: &HashMap<i64, K>,
scratch: &mut Scratch<BE>, ) where A: GLWEToRef, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, M: GLWETrace<BE>, {@@ -58,7 +57,7 @@ end: usize,
keys: &HashMap<i64, K>, scratch: &mut Scratch<BE>, ) where - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, M: GLWETrace<BE>, {@@ -110,7 +109,7 @@ fn glwe_trace<R, A, K>(&self, res: &mut R, start: usize, end: usize, a: &A, keys: &HashMap<i64, K>, scratch: &mut Scratch<BE>)
where R: GLWEToMut, A: GLWEToRef, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { self.glwe_copy(res, a);@@ -120,7 +119,7 @@
fn glwe_trace_inplace<R, K>(&self, res: &mut R, start: usize, end: usize, keys: &HashMap<i64, K>, scratch: &mut Scratch<BE>) where R: GLWEToMut, - K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, + K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos, Scratch<BE>: ScratchTakeCore<BE>, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();@@ -141,7 +140,7 @@ }
} if res.base2k() != basek_ksk { - let (mut self_conv, scratch_1) = scratch.take_glwe_ct( + let (mut self_conv, scratch_1) = scratch.take_glwe( self, &GLWELayout { n: self.n().into(),
@@ -2,7 +2,7 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch};
use crate::{ ScratchTakeCore, - keyswitching::glwe_ct::GLWEKeyswitch, + keyswitching::GLWEKeyswitch, layouts::{AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWESwitchingKey}, };
@@ -2,7 +2,7 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, VecZnx};
use crate::{ GGSWExpandRows, ScratchTakeCore, - keyswitching::glwe_ct::GLWEKeyswitch, + keyswitching::GLWEKeyswitch, layouts::{GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, prepared::TensorKeyPreparedToRef}, };
@@ -5,7 +5,7 @@ };
use crate::{ LWESampleExtract, ScratchTakeCore, - keyswitching::glwe_ct::GLWEKeyswitch, + keyswitching::GLWEKeyswitch, layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWELayout, LWE, LWEInfos, LWEToMut, LWEToRef, Rank, TorusPrecision}, };@@ -87,7 +87,7 @@ let max_k: TorusPrecision = res.k().max(a.k());
let a_size: usize = a.k().div_ceil(ksk.base2k()) as usize; - let (mut glwe_in, scratch_1) = scratch.take_glwe_ct( + let (mut glwe_in, scratch_1) = scratch.take_glwe( self, &GLWELayout { n: ksk.n(),@@ -98,7 +98,7 @@ },
); glwe_in.data.zero(); - let (mut glwe_out, scratch_1) = scratch_1.take_glwe_ct( + let (mut glwe_out, scratch_1) = scratch_1.take_glwe( self, &GLWELayout { n: ksk.n(),
@@ -1,9 +1,9 @@
-mod gglwe_ct; -mod ggsw_ct; -mod glwe_ct; -mod lwe_ct; +mod gglwe; +mod ggsw; +mod glwe; +mod lwe; -pub use gglwe_ct::*; -pub use ggsw_ct::*; -pub use glwe_ct::*; -pub use lwe_ct::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe::*; +pub use lwe::*;
@@ -5,26 +5,25 @@ };
use crate::layouts::{ AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut, - GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWECompressed, GLWECompressedToMut, GLWECompressedToRef, - GLWEDecompress, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement}, + GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWEDecompress, GLWEInfos, GetGaloisElement, LWEInfos, Rank, + SetGaloisElement, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; #[derive(PartialEq, Eq, Clone)] -pub struct AutomorphismKeyCompressed<D: Data> { +pub struct GLWEAutomorphismKeyCompressed<D: Data> { pub(crate) key: GGLWECompressed<D>, pub(crate) p: i64, } -impl<D: Data> GetAutomorphismGaloisElement for AutomorphismKeyCompressed<D> { +impl<D: DataRef> GetGaloisElement for GLWEAutomorphismKeyCompressed<D> { fn p(&self) -> i64 { self.p } } -impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> { +impl<D: Data> LWEInfos for GLWEAutomorphismKeyCompressed<D> { fn n(&self) -> Degree { self.key.n() }@@ -42,13 +41,13 @@ self.key.size()
} } -impl<D: Data> GLWEInfos for AutomorphismKeyCompressed<D> { +impl<D: Data> GLWEInfos for GLWEAutomorphismKeyCompressed<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for AutomorphismKeyCompressed<D> { +impl<D: Data> GGLWEInfos for GLWEAutomorphismKeyCompressed<D> { fn rank_in(&self) -> Rank { self.key.rank_in() }@@ -66,25 +65,25 @@ self.key.dnum()
} } -impl<D: DataRef> fmt::Debug for AutomorphismKeyCompressed<D> { +impl<D: DataRef> fmt::Debug for GLWEAutomorphismKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for AutomorphismKeyCompressed<D> { +impl<D: DataMut> FillUniform for GLWEAutomorphismKeyCompressed<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 AutomorphismKeyCompressed<D> { +impl<D: DataRef> fmt::Display for GLWEAutomorphismKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "(AutomorphismKeyCompressed: p={}) {}", self.p, self.key) } } -impl AutomorphismKeyCompressed<Vec<u8>> { +impl GLWEAutomorphismKeyCompressed<Vec<u8>> { pub fn alloc_from_infos<A>(infos: &A) -> Self where A: GGLWEInfos,@@ -100,7 +99,7 @@ )
} pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { - AutomorphismKeyCompressed { + GLWEAutomorphismKeyCompressed { key: GGLWECompressed::alloc(n, base2k, k, rank, rank, dnum, dsize), p: 0, }@@ -125,14 +124,14 @@ GGLWECompressed::bytes_of(n, base2k, k, rank, dnum, dsize)
} } -impl<D: DataMut> ReaderFrom for AutomorphismKeyCompressed<D> { +impl<D: DataMut> ReaderFrom for GLWEAutomorphismKeyCompressed<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 AutomorphismKeyCompressed<D> { +impl<D: DataRef> WriterTo for GLWEAutomorphismKeyCompressed<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)@@ -145,8 +144,8 @@ Self: GGLWEDecompress,
{ fn decompress_automorphism_key<R, O>(&self, res: &mut R, other: &O) where - R: GGLWEToMut + SetAutomorphismGaloisElement, - O: GGLWECompressedToRef + GetAutomorphismGaloisElement, + R: GGLWEToMut + SetGaloisElement, + O: GGLWECompressedToRef + GetGaloisElement, { self.decompress_gglwe(res, other); res.set_p(other.p());@@ -157,68 +156,36 @@ impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: GLWEDecompress {}
impl<D: DataMut> AutomorphismKey<D> where - Self: SetAutomorphismGaloisElement, + Self: SetGaloisElement, { pub fn decompress<O, M>(&mut self, module: &M, other: &O) where - O: GGLWECompressedToRef + GetAutomorphismGaloisElement, + O: GGLWECompressedToRef + GetGaloisElement, M: AutomorphismKeyDecompress, { module.decompress_automorphism_key(self, other); } } -impl<D: DataRef> GGLWECompressedToRef for AutomorphismKeyCompressed<D> { +impl<D: DataRef> GGLWECompressedToRef for GLWEAutomorphismKeyCompressed<D> { fn to_ref(&self) -> GGLWECompressed<&[u8]> { self.key.to_ref() } } -impl<D: DataMut> GGLWECompressedToMut for AutomorphismKeyCompressed<D> { +impl<D: DataMut> GGLWECompressedToMut for GLWEAutomorphismKeyCompressed<D> { fn to_mut(&mut self) -> GGLWECompressed<&mut [u8]> { self.key.to_mut() } } -pub trait AutomorphismKeyCompressedToRef { - fn to_ref(&self) -> AutomorphismKeyCompressed<&[u8]>; -} - -impl<D: DataRef> AutomorphismKeyCompressedToRef for AutomorphismKeyCompressed<D> -where - GLWECompressed<D>: GLWECompressedToRef, -{ - fn to_ref(&self) -> AutomorphismKeyCompressed<&[u8]> { - AutomorphismKeyCompressed { - key: self.key.to_ref(), - p: self.p, - } - } -} - -pub trait AutomorphismKeyCompressedToMut { - fn to_mut(&mut self) -> AutomorphismKeyCompressed<&mut [u8]>; -} - -impl<D: DataMut> AutomorphismKeyCompressedToMut for AutomorphismKeyCompressed<D> -where - GLWECompressed<D>: GLWECompressedToMut, -{ - fn to_mut(&mut self) -> AutomorphismKeyCompressed<&mut [u8]> { - AutomorphismKeyCompressed { - p: self.p, - key: self.key.to_mut(), - } - } -} - -impl<D: DataMut> GGLWECompressedSeedMut for AutomorphismKeyCompressed<D> { +impl<D: DataMut> GGLWECompressedSeedMut for GLWEAutomorphismKeyCompressed<D> { fn seed_mut(&mut self) -> &mut Vec<[u8; 32]> { &mut self.key.seed } } -impl<D: DataMut> SetAutomorphismGaloisElement for AutomorphismKeyCompressed<D> { +impl<D: DataMut> SetGaloisElement for GLWEAutomorphismKeyCompressed<D> { fn set_p(&mut self, p: i64) { self.p = p }
@@ -11,11 +11,11 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt; #[derive(PartialEq, Eq, Clone)] -pub struct TensorKeyCompressed<D: Data> { +pub struct GLWETensorKeyCompressed<D: Data> { pub(crate) keys: Vec<GGLWECompressed<D>>, } -impl<D: Data> LWEInfos for TensorKeyCompressed<D> { +impl<D: Data> LWEInfos for GLWETensorKeyCompressed<D> { fn n(&self) -> Degree { self.keys[0].n() }@@ -31,13 +31,13 @@ fn size(&self) -> usize {
self.keys[0].size() } } -impl<D: Data> GLWEInfos for TensorKeyCompressed<D> { +impl<D: Data> GLWEInfos for GLWETensorKeyCompressed<D> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data> GGLWEInfos for TensorKeyCompressed<D> { +impl<D: Data> GGLWEInfos for GLWETensorKeyCompressed<D> { fn rank_in(&self) -> Rank { self.rank_out() }@@ -55,13 +55,13 @@ self.keys[0].dnum()
} } -impl<D: DataRef> fmt::Debug for TensorKeyCompressed<D> { +impl<D: DataRef> fmt::Debug for GLWETensorKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{self}") } } -impl<D: DataMut> FillUniform for TensorKeyCompressed<D> { +impl<D: DataMut> FillUniform for GLWETensorKeyCompressed<D> { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) { self.keys .iter_mut()@@ -69,7 +69,7 @@ .for_each(|key: &mut GGLWECompressed<D>| key.fill_uniform(log_bound, source))
} } -impl<D: DataRef> fmt::Display for TensorKeyCompressed<D> { +impl<D: DataRef> fmt::Display for GLWETensorKeyCompressed<D> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "(GLWETensorKeyCompressed)",)?; for (i, key) in self.keys.iter().enumerate() {@@ -79,7 +79,7 @@ Ok(())
} } -impl TensorKeyCompressed<Vec<u8>> { +impl GLWETensorKeyCompressed<Vec<u8>> { pub fn alloc_from_infos<A>(infos: &A) -> Self where A: GGLWEInfos,@@ -96,7 +96,7 @@ }
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { let pairs: u32 = (((rank.as_u32() + 1) * rank.as_u32()) >> 1).max(1); - TensorKeyCompressed { + GLWETensorKeyCompressed { keys: (0..pairs) .map(|_| GGLWECompressed::alloc(n, base2k, k, Rank(1), rank, dnum, dsize)) .collect(),@@ -123,7 +123,7 @@ pairs * GGLWECompressed::bytes_of(n, base2k, k, Rank(1), dnum, dsize)
} } -impl<D: DataMut> ReaderFrom for TensorKeyCompressed<D> { +impl<D: DataMut> ReaderFrom for GLWETensorKeyCompressed<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 {@@ -139,7 +139,7 @@ Ok(())
} } -impl<D: DataRef> WriterTo for TensorKeyCompressed<D> { +impl<D: DataRef> WriterTo for GLWETensorKeyCompressed<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 {@@ -153,7 +153,7 @@ pub trait TensorKeyCompressedAtRef<D: DataRef> {
fn at(&self, i: usize, j: usize) -> &GGLWECompressed<D>; } -impl<D: DataRef> TensorKeyCompressedAtRef<D> for TensorKeyCompressed<D> { +impl<D: DataRef> TensorKeyCompressedAtRef<D> for GLWETensorKeyCompressed<D> { fn at(&self, mut i: usize, mut j: usize) -> &GGLWECompressed<D> { if i > j { std::mem::swap(&mut i, &mut j);@@ -167,7 +167,7 @@ pub trait TensorKeyCompressedAtMut<D: DataMut> {
fn at_mut(&mut self, i: usize, j: usize) -> &mut GGLWECompressed<D>; } -impl<D: DataMut> TensorKeyCompressedAtMut<D> for TensorKeyCompressed<D> { +impl<D: DataMut> TensorKeyCompressedAtMut<D> for GLWETensorKeyCompressed<D> { fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWECompressed<D> { if i > j { std::mem::swap(&mut i, &mut j);@@ -187,7 +187,7 @@ R: TensorKeyToMut,
O: TensorKeyCompressedToRef, { let res: &mut TensorKey<&mut [u8]> = &mut res.to_mut(); - let other: &TensorKeyCompressed<&[u8]> = &other.to_ref(); + let other: &GLWETensorKeyCompressed<&[u8]> = &other.to_ref(); assert_eq!( res.keys.len(),@@ -216,30 +216,30 @@ }
} pub trait TensorKeyCompressedToMut { - fn to_mut(&mut self) -> TensorKeyCompressed<&mut [u8]>; + fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]>; } -impl<D: DataMut> TensorKeyCompressedToMut for TensorKeyCompressed<D> +impl<D: DataMut> TensorKeyCompressedToMut for GLWETensorKeyCompressed<D> where GGLWECompressed<D>: GGLWECompressedToMut, { - fn to_mut(&mut self) -> TensorKeyCompressed<&mut [u8]> { - TensorKeyCompressed { + fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]> { + GLWETensorKeyCompressed { keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(), } } } pub trait TensorKeyCompressedToRef { - fn to_ref(&self) -> TensorKeyCompressed<&[u8]>; + fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]>; } -impl<D: DataRef> TensorKeyCompressedToRef for TensorKeyCompressed<D> +impl<D: DataRef> TensorKeyCompressedToRef for GLWETensorKeyCompressed<D> where GGLWECompressed<D>: GGLWECompressedToRef, { - fn to_ref(&self) -> TensorKeyCompressed<&[u8]> { - TensorKeyCompressed { + fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]> { + GLWETensorKeyCompressed { keys: self.keys.iter().map(|c| c.to_ref()).collect(), } }
@@ -1,21 +1,21 @@
-mod gglwe_atk; -mod gglwe_ct; -mod gglwe_ksk; -mod gglwe_tsk; -mod ggsw_ct; -mod glwe_ct; -mod glwe_to_lwe_ksk; -mod lwe_ct; -mod lwe_ksk; -mod lwe_to_glwe_ksk; +mod gglwe; +mod ggsw; +mod glwe; +mod glwe_automorphism_key; +mod glwe_switching_key; +mod glwe_tensor_key; +mod glwe_to_lwe_switching_key; +mod lwe; +mod lwe_switching_key; +mod lwe_to_glwe_switching_key; -pub use gglwe_atk::*; -pub use gglwe_ct::*; -pub use gglwe_ksk::*; -pub use gglwe_tsk::*; -pub use ggsw_ct::*; -pub use glwe_ct::*; -pub use glwe_to_lwe_ksk::*; -pub use lwe_ct::*; -pub use lwe_ksk::*; -pub use lwe_to_glwe_ksk::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe::*; +pub use glwe_automorphism_key::*; +pub use glwe_switching_key::*; +pub use glwe_tensor_key::*; +pub use glwe_to_lwe_switching_key::*; +pub use lwe::*; +pub use lwe_switching_key::*; +pub use lwe_to_glwe_switching_key::*;
@@ -5,7 +5,6 @@ };
use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, TorusPrecision, - prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};@@ -27,13 +26,21 @@ pub(crate) key: GGLWE<D>,
pub(crate) p: i64, } -impl<D: DataMut> SetAutomorphismGaloisElement for AutomorphismKey<D> { +pub trait GetGaloisElement { + fn p(&self) -> i64; +} + +pub trait SetGaloisElement { + fn set_p(&mut self, p: i64); +} + +impl<D: DataMut> SetGaloisElement for AutomorphismKey<D> { fn set_p(&mut self, p: i64) { self.p = p } } -impl<D: DataRef> GetAutomorphismGaloisElement for AutomorphismKey<D> { +impl<D: DataRef> GetGaloisElement for AutomorphismKey<D> { fn p(&self) -> i64 { self.p }
@@ -1,17 +1,14 @@
-use poulpy_hal::layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, VecZnxToMut, VecZnxToRef, WriterTo, ZnxInfos}; +use poulpy_hal::layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, WriterTo}; use crate::{ GetDistribution, GetDistributionMut, dist::Distribution, - layouts::{Base2K, Degree, GLWEInfos, LWEInfos, Rank, TorusPrecision}, + layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, Rank, TorusPrecision}, }; -use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; #[derive(PartialEq, Eq)] pub struct GLWEPublicKey<D: Data> { - pub(crate) data: VecZnx<D>, - pub(crate) base2k: Base2K, - pub(crate) k: TorusPrecision, + pub(crate) key: GLWE<D>, pub(crate) dist: Distribution, }@@ -37,25 +34,25 @@ }
impl<D: Data> LWEInfos for GLWEPublicKey<D> { fn base2k(&self) -> Base2K { - self.base2k + self.key.base2k() } fn k(&self) -> TorusPrecision { - self.k + self.key.k() } fn n(&self) -> Degree { - Degree(self.data.n() as u32) + self.key.n() } fn size(&self) -> usize { - self.data.size() + self.key.size() } } impl<D: Data> GLWEInfos for GLWEPublicKey<D> { fn rank(&self) -> Rank { - Rank(self.data.cols() as u32 - 1) + self.key.rank() } }@@ -93,9 +90,7 @@ }
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self { GLWEPublicKey { - data: VecZnx::alloc(n.into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize), - base2k, - k, + key: GLWE::alloc(n, base2k, k, rank), dist: Distribution::NONE, } }@@ -114,54 +109,32 @@ }
impl<D: DataMut> ReaderFrom for GLWEPublicKey<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>()?); match Distribution::read_from(reader) { Ok(dist) => self.dist = dist, Err(e) => return Err(e), } - self.data.read_from(reader) + self.key.read_from(reader) } } impl<D: DataRef> WriterTo for GLWEPublicKey<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)?; match self.dist.write_to(writer) { Ok(()) => {} Err(e) => return Err(e), } - self.data.write_to(writer) + self.key.write_to(writer) } } -pub trait GLWEPublicKeyToRef { - fn to_ref(&self) -> GLWEPublicKey<&[u8]>; -} - -impl<D: DataRef> GLWEPublicKeyToRef for GLWEPublicKey<D> { - fn to_ref(&self) -> GLWEPublicKey<&[u8]> { - GLWEPublicKey { - data: self.data.to_ref(), - base2k: self.base2k, - k: self.k, - dist: self.dist, - } +impl<D: DataRef> GLWEToRef for GLWEPublicKey<D> { + fn to_ref(&self) -> GLWE<&[u8]> { + self.key.to_ref() } } -pub trait GLWEPublicKeyToMut { - fn to_mut(&mut self) -> GLWEPublicKey<&mut [u8]>; -} - -impl<D: DataMut> GLWEPublicKeyToMut for GLWEPublicKey<D> { - fn to_mut(&mut self) -> GLWEPublicKey<&mut [u8]> { - GLWEPublicKey { - base2k: self.base2k, - k: self.k, - dist: self.dist, - data: self.data.to_mut(), - } +impl<D: DataMut> GLWEToMut for GLWEPublicKey<D> { + fn to_mut(&mut self) -> GLWE<&mut [u8]> { + self.key.to_mut() } }
@@ -1,38 +1,38 @@
-mod gglwe_atk; -mod gglwe_ct; -mod gglwe_ksk; -mod gglwe_tsk; -mod ggsw_ct; -mod glwe_ct; -mod glwe_pk; -mod glwe_pt; -mod glwe_sk; -mod glwe_to_lwe_ksk; -mod lwe_ct; -mod lwe_ksk; -mod lwe_pt; -mod lwe_sk; -mod lwe_to_glwe_ksk; +mod gglwe; +mod ggsw; +mod glwe; +mod glwe_automorphism_key; +mod glwe_plaintext; +mod glwe_public_key; +mod glwe_secret; +mod glwe_switching_key; +mod glwe_tensor_key; +mod glwe_to_lwe_switching_key; +mod lwe; +mod lwe_plaintext; +mod lwe_secret; +mod lwe_switching_key; +mod lwe_to_glwe_switching_key; pub mod compressed; pub mod prepared; pub use compressed::*; -pub use gglwe_atk::*; -pub use gglwe_ct::*; -pub use gglwe_ksk::*; -pub use gglwe_tsk::*; -pub use ggsw_ct::*; -pub use glwe_ct::*; -pub use glwe_pk::*; -pub use glwe_pt::*; -pub use glwe_sk::*; -pub use glwe_to_lwe_ksk::*; -pub use lwe_ct::*; -pub use lwe_ksk::*; -pub use lwe_pt::*; -pub use lwe_sk::*; -pub use lwe_to_glwe_ksk::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe::*; +pub use glwe_automorphism_key::*; +pub use glwe_plaintext::*; +pub use glwe_public_key::*; +pub use glwe_secret::*; +pub use glwe_switching_key::*; +pub use glwe_tensor_key::*; +pub use glwe_to_lwe_switching_key::*; +pub use lwe::*; +pub use lwe_plaintext::*; +pub use lwe_secret::*; +pub use lwe_switching_key::*; +pub use lwe_to_glwe_switching_key::*; pub use prepared::*; use poulpy_hal::layouts::{Backend, Module};
@@ -1,17 +1,17 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, - GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, LWEInfos, Rank, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef, + GGLWEToRef, GLWEInfos, GetGaloisElement, LWEInfos, Rank, SetGaloisElement, TorusPrecision, }; #[derive(PartialEq, Eq)] -pub struct AutomorphismKeyPrepared<D: Data, B: Backend> { +pub struct GLWEAutomorphismKeyPrepared<D: Data, B: Backend> { pub(crate) key: GGLWEPrepared<D, B>, pub(crate) p: i64, } -impl<D: Data, B: Backend> LWEInfos for AutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> LWEInfos for GLWEAutomorphismKeyPrepared<D, B> { fn n(&self) -> Degree { self.key.n() }@@ -29,33 +29,25 @@ self.key.size()
} } -pub trait GetAutomorphismGaloisElement { - fn p(&self) -> i64; -} - -impl<D: Data, B: Backend> GetAutomorphismGaloisElement for AutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> GetGaloisElement for GLWEAutomorphismKeyPrepared<D, B> { fn p(&self) -> i64 { self.p } } -pub trait SetAutomorphismGaloisElement { - fn set_p(&mut self, p: i64); -} - -impl<D: Data, B: Backend> SetAutomorphismGaloisElement for AutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> SetGaloisElement for GLWEAutomorphismKeyPrepared<D, B> { fn set_p(&mut self, p: i64) { self.p = p } } -impl<D: Data, B: Backend> GLWEInfos for AutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> GLWEInfos for GLWEAutomorphismKeyPrepared<D, B> { fn rank(&self) -> Rank { self.rank_out() } } -impl<D: Data, B: Backend> GGLWEInfos for AutomorphismKeyPrepared<D, B> { +impl<D: Data, B: Backend> GGLWEInfos for GLWEAutomorphismKeyPrepared<D, B> { fn rank_in(&self) -> Rank { self.key.rank_in() }@@ -73,7 +65,7 @@ self.key.dnum()
} } -pub trait AutomorphismKeyPreparedAlloc<B: Backend> +pub trait GLWEAutomorphismKeyPreparedApi<B: Backend> where Self: GGLWEPreparedAlloc<B>, {@@ -84,14 +76,14 @@ k: TorusPrecision,
rank: Rank, dnum: Dnum, dsize: Dsize, - ) -> AutomorphismKeyPrepared<Vec<u8>, B> { - AutomorphismKeyPrepared::<Vec<u8>, B> { + ) -> GLWEAutomorphismKeyPrepared<Vec<u8>, B> { + GLWEAutomorphismKeyPrepared::<Vec<u8>, B> { key: self.alloc_gglwe_prepared(base2k, k, rank, rank, dnum, dsize), p: 0, } } - fn alloc_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> AutomorphismKeyPrepared<Vec<u8>, B> + fn alloc_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> GLWEAutomorphismKeyPrepared<Vec<u8>, B> where A: GGLWEInfos, {@@ -137,22 +129,38 @@ infos.dnum(),
infos.dsize(), ) } + + fn prepare_automorphism_key_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGLWEInfos, + { + self.prepare_gglwe_tmp_bytes(infos) + } + + fn prepare_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGLWEPreparedToMut<B> + SetGaloisElement, + O: GGLWEToRef + GetGaloisElement, + { + self.prepare_gglwe(res, other, scratch); + res.set_p(other.p()); + } } -impl<B: Backend> AutomorphismKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {} +impl<B: Backend> GLWEAutomorphismKeyPreparedApi<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {} -impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> { +impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> { pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self where A: GGLWEInfos, - M: AutomorphismKeyPreparedAlloc<B>, + M: GLWEAutomorphismKeyPreparedApi<B>, { module.alloc_automorphism_key_prepared_from_infos(infos) } pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - M: AutomorphismKeyPreparedAlloc<B>, + M: GLWEAutomorphismKeyPreparedApi<B>, { module.alloc_automorphism_key_prepared(base2k, k, rank, dnum, dsize) }@@ -160,68 +168,45 @@
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize where A: GGLWEInfos, - M: AutomorphismKeyPreparedAlloc<B>, + M: GLWEAutomorphismKeyPreparedApi<B>, { module.bytes_of_automorphism_key_prepared_from_infos(infos) } pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize where - M: AutomorphismKeyPreparedAlloc<B>, + M: GLWEAutomorphismKeyPreparedApi<B>, { module.bytes_of_automorphism_key_prepared(base2k, k, rank, dnum, dsize) } } -pub trait AutomorphismKeyPrepare<B: Backend> -where - Self: GGLWEPrepare<B>, -{ - fn prepare_automorphism_key_tmp_bytes<A>(&self, infos: &A) -> usize - where - A: GGLWEInfos, - { - self.prepare_gglwe_tmp_bytes(infos) - } - - fn prepare_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) - where - R: GGLWEPreparedToMut<B> + SetAutomorphismGaloisElement, - O: GGLWEToRef + GetAutomorphismGaloisElement, - { - self.prepare_gglwe(res, other, scratch); - res.set_p(other.p()); - } -} - -impl<B: Backend> AutomorphismKeyPrepare<B> for Module<B> where Module<B>: GGLWEPrepare<B> {} - -impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> { +impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize where - M: AutomorphismKeyPrepare<B>, + M: GLWEAutomorphismKeyPreparedApi<B>, { module.prepare_automorphism_key_tmp_bytes(self) } } -impl<D: DataMut, B: Backend> AutomorphismKeyPrepared<D, B> { +impl<D: DataMut, B: Backend> GLWEAutomorphismKeyPrepared<D, B> { pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where - O: GGLWEToRef + GetAutomorphismGaloisElement, - M: AutomorphismKeyPrepare<B>, + O: GGLWEToRef + GetGaloisElement, + M: GLWEAutomorphismKeyPreparedApi<B>, { module.prepare_automorphism_key(self, other, scratch); } } -impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for AutomorphismKeyPrepared<D, B> { +impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for GLWEAutomorphismKeyPrepared<D, B> { fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> { self.key.to_mut() } } -impl<D: DataRef, BE: Backend> GGLWEPreparedToRef<BE> for AutomorphismKeyPrepared<D, BE> { +impl<D: DataRef, BE: Backend> GGLWEPreparedToRef<BE> for GLWEAutomorphismKeyPrepared<D, BE> { fn to_ref(&self) -> GGLWEPrepared<&[u8], BE> { self.key.to_ref() }
@@ -57,9 +57,9 @@ Dnum(self.data.rows() as u32)
} } -pub trait GGLWEPreparedAlloc<B: Backend> +pub trait GGLWEPreparedAlloc<BE: Backend> where - Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf, + Self: GetDegree + VmpPMatAlloc<BE> + VmpPMatBytesOf + VmpPrepare<BE> + VmpPrepareTmpBytes, { fn alloc_gglwe_prepared( &self,@@ -69,7 +69,7 @@ rank_in: Rank,
rank_out: Rank, dnum: Dnum, dsize: Dsize, - ) -> GGLWEPrepared<Vec<u8>, B> { + ) -> GGLWEPrepared<Vec<u8>, BE> { let size: usize = k.0.div_ceil(base2k.0) as usize; debug_assert!( size as u32 > dsize.0,@@ -92,7 +92,7 @@ dsize,
} } - fn alloc_gglwe_prepared_from_infos<A>(&self, infos: &A) -> GGLWEPrepared<Vec<u8>, B> + fn alloc_gglwe_prepared_from_infos<A>(&self, infos: &A) -> GGLWEPrepared<Vec<u8>, BE> where A: GGLWEInfos, {@@ -147,9 +147,41 @@ infos.dnum(),
infos.dsize(), ) } + + fn prepare_gglwe_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(), + infos.size(), + ) + } + + fn prepare_gglwe<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<BE>) + where + R: GGLWEPreparedToMut<BE>, + O: GGLWEToRef, + { + let mut res: GGLWEPrepared<&mut [u8], BE> = res.to_mut(); + let other: GGLWE<&[u8]> = other.to_ref(); + + assert_eq!(res.n(), self.ring_degree()); + assert_eq!(other.n(), self.ring_degree()); + 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<B: Backend> GGLWEPreparedAlloc<B> for Module<B> where Module<B>: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {} +impl<BE: Backend> GGLWEPreparedAlloc<BE> for Module<BE> where + Module<BE>: GetDegree + VmpPMatAlloc<BE> + VmpPMatBytesOf + VmpPrepare<BE> + VmpPrepareTmpBytes +{ +} impl<B: Backend> GGLWEPrepared<Vec<u8>, B> { pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self@@ -199,47 +231,11 @@ module.bytes_of_gglwe_prepared(base2k, k, rank_in, rank_out, dnum, dsize)
} } -pub trait GGLWEPrepare<B: Backend> -where - Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B>, -{ - fn prepare_gglwe_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(), - infos.size(), - ) - } - - fn prepare_gglwe<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> = res.to_mut(); - let other: GGLWE<&[u8]> = other.to_ref(); - - assert_eq!(res.n(), self.ring_degree()); - assert_eq!(other.n(), self.ring_degree()); - 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<B: Backend> GGLWEPrepare<B> for Module<B> where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B> {} - impl<D: DataMut, B: Backend> GGLWEPrepared<D, B> { pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where O: GGLWEToRef, - M: GGLWEPrepare<B>, + M: GGLWEPreparedAlloc<B>, { module.prepare_gglwe(self, other, scratch); }@@ -248,7 +244,7 @@
impl<B: Backend> GGLWEPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize where - M: GGLWEPrepare<B>, + M: GGLWEPreparedAlloc<B>, { module.prepare_gglwe_tmp_bytes(self) }
@@ -3,7 +3,7 @@
use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision, - prepared::{GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef}, + prepared::{GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef}, }; #[derive(PartialEq, Eq)]@@ -134,6 +134,23 @@ infos.dnum(),
infos.dsize(), ) } + + fn prepare_glwe_switching_key_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGLWEInfos, + { + self.prepare_gglwe_tmp_bytes(infos) + } + + fn prepare_glwe_switching<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, + O: GGLWEToRef + GLWESwitchingKeyDegrees, + { + self.prepare_gglwe(res, other, scratch); + *res.input_degree() = *other.input_degree(); + *res.output_degree() = *other.output_degree(); + } } impl<B: Backend> GLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GGLWEPreparedAlloc<B> {}@@ -186,35 +203,11 @@ module.bytes_of_glwe_switching_key_prepared(base2k, k, rank_in, rank_out, dnum, dsize)
} } -pub trait GLWESwitchingKeyPrepare<B: Backend> -where - Self: GGLWEPrepare<B>, -{ - fn prepare_glwe_switching_key_tmp_bytes<A>(&self, infos: &A) -> usize - where - A: GGLWEInfos, - { - self.prepare_gglwe_tmp_bytes(infos) - } - - fn prepare_glwe_switching<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) - where - R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, - O: GGLWEToRef + GLWESwitchingKeyDegrees, - { - self.prepare_gglwe(res, other, scratch); - *res.input_degree() = *other.input_degree(); - *res.output_degree() = *other.output_degree(); - } -} - -impl<B: Backend> GLWESwitchingKeyPrepare<B> for Module<B> where Self: GGLWEPrepare<B> {} - impl<D: DataMut, B: Backend> GLWESwitchingKeyPrepared<D, B> { pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where O: GGLWEToRef + GLWESwitchingKeyDegrees, - M: GLWESwitchingKeyPrepare<B>, + M: GLWESwitchingKeyPreparedAlloc<B>, { module.prepare_glwe_switching(self, other, scratch); }@@ -223,7 +216,7 @@
impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize where - M: GLWESwitchingKeyPrepare<B>, + M: GLWESwitchingKeyPreparedAlloc<B>, { module.prepare_glwe_switching_key_tmp_bytes(self) }
@@ -1,8 +1,8 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, - GGLWEPreparedToRef, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef, + GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision, }; #[derive(PartialEq, Eq)]@@ -107,6 +107,28 @@ infos.dnum(),
infos.dsize(), ) } + + fn prepare_tensor_key_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGLWEInfos, + { + self.prepare_gglwe_tmp_bytes(infos) + } + + fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: TensorKeyPreparedToMut<B>, + O: TensorKeyToRef, + { + let mut res: TensorKeyPrepared<&mut [u8], B> = res.to_mut(); + let other: TensorKey<&[u8]> = other.to_ref(); + + assert_eq!(res.keys.len(), other.keys.len()); + + for (a, b) in res.keys.iter_mut().zip(other.keys.iter()) { + self.prepare_gglwe(a, b, scratch); + } + } } impl<B: Backend> TensorKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}@@ -165,40 +187,11 @@ &self.keys[i * rank + j - (i * (i + 1) / 2)]
} } -pub trait TensorKeyPrepare<B: Backend> -where - Self: GGLWEPrepare<B>, -{ - fn prepare_tensor_key_tmp_bytes<A>(&self, infos: &A) -> usize - where - A: GGLWEInfos, - { - self.prepare_gglwe_tmp_bytes(infos) - } - - fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) - where - R: TensorKeyPreparedToMut<B>, - O: TensorKeyToRef, - { - let mut res: TensorKeyPrepared<&mut [u8], B> = res.to_mut(); - let other: TensorKey<&[u8]> = other.to_ref(); - - assert_eq!(res.keys.len(), other.keys.len()); - - for (a, b) in res.keys.iter_mut().zip(other.keys.iter()) { - self.prepare_gglwe(a, b, scratch); - } - } -} - -impl<B: Backend> TensorKeyPrepare<B> for Module<B> where Self: GGLWEPrepare<B> {} - impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize where A: GGLWEInfos, - M: TensorKeyPrepare<B>, + M: TensorKeyPreparedAlloc<B>, { module.prepare_tensor_key_tmp_bytes(infos) }@@ -208,7 +201,7 @@ impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where O: TensorKeyToRef, - M: TensorKeyPrepare<B>, + M: TensorKeyPreparedAlloc<B>, { module.prepare_tensor_key(self, other, scratch); }
@@ -51,7 +51,7 @@ }
pub trait GGSWPreparedAlloc<B: Backend> where - Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf, + Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf + VmpPrepareTmpBytes + VmpPrepare<B>, { fn alloc_ggsw_prepared( &self,@@ -133,9 +133,39 @@ infos.dsize(),
infos.rank(), ) } + + fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize + where + A: GGSWInfos, + { + assert_eq!(self.ring_degree(), infos.n()); + self.vmp_prepare_tmp_bytes( + infos.dnum().into(), + (infos.rank() + 1).into(), + (infos.rank() + 1).into(), + infos.size(), + ) + } + 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.n(), self.ring_degree()); + assert_eq!(other.n(), self.ring_degree()); + 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<B: Backend> GGSWPreparedAlloc<B> for Module<B> where Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {} +impl<B: Backend> GGSWPreparedAlloc<B> for Module<B> where + Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf + VmpPrepareTmpBytes + VmpPrepare<B> +{ +} impl<B: Backend> GGSWPrepared<Vec<u8>, B> { pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self@@ -175,45 +205,11 @@ &self.data
} } -pub trait GGSWPrepare<B: Backend> -where - Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B>, -{ - fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize - where - A: GGSWInfos, - { - assert_eq!(self.ring_degree(), infos.n()); - self.vmp_prepare_tmp_bytes( - infos.dnum().into(), - (infos.rank() + 1).into(), - (infos.rank() + 1).into(), - infos.size(), - ) - } - 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.n(), self.ring_degree()); - assert_eq!(other.n(), self.ring_degree()); - 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<B: Backend> GGSWPrepare<B> for Module<B> where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B> {} - impl<B: Backend> GGSWPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize where A: GGSWInfos, - M: GGSWPrepare<B>, + M: GGSWPreparedAlloc<B>, { module.ggsw_prepare_tmp_bytes(infos) }@@ -223,7 +219,7 @@ impl<D: DataMut, B: Backend> GGSWPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where O: GGSWToRef, - M: GGSWPrepare<B>, + M: GGSWPreparedAlloc<B>, { module.ggsw_prepare(self, other, scratch); }
@@ -0,0 +1,161 @@
+use poulpy_hal::{ + api::{VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf}, + layouts::{Backend, Data, DataMut, DataRef, Module, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, ZnxInfos}, +}; + +use crate::layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToRef, GetDegree, LWEInfos, Rank, TorusPrecision}; + +#[derive(PartialEq, Eq)] +pub struct GLWEPrepared<D: Data, B: Backend> { + pub(crate) data: VecZnxDft<D, B>, + pub(crate) base2k: Base2K, + pub(crate) k: TorusPrecision, +} + +impl<D: Data, B: Backend> LWEInfos for GLWEPrepared<D, B> { + fn base2k(&self) -> Base2K { + self.base2k + } + + fn k(&self) -> TorusPrecision { + self.k + } + + fn size(&self) -> usize { + self.data.size() + } + + fn n(&self) -> Degree { + Degree(self.data.n() as u32) + } +} + +impl<D: Data, B: Backend> GLWEInfos for GLWEPrepared<D, B> { + fn rank(&self) -> Rank { + Rank(self.data.cols() as u32 - 1) + } +} + +pub trait GLWEPreparedAlloc<B: Backend> +where + Self: GetDegree + VecZnxDftAlloc<B> + VecZnxDftBytesOf + VecZnxDftApply<B>, +{ + fn alloc_glwe_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPrepared<Vec<u8>, B> { + GLWEPrepared { + data: self.vec_znx_dft_alloc((rank + 1).into(), k.0.div_ceil(base2k.0) as usize), + base2k, + k, + } + } + + fn alloc_glwe_prepared_from_infos<A>(&self, infos: &A) -> GLWEPrepared<Vec<u8>, B> + where + A: GLWEInfos, + { + self.alloc_glwe_prepared(infos.base2k(), infos.k(), infos.rank()) + } + + fn bytes_of_glwe_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize { + self.bytes_of_vec_znx_dft((rank + 1).into(), k.0.div_ceil(base2k.0) as usize) + } + + fn bytes_of_glwe_prepared_from_infos<A>(&self, infos: &A) -> usize + where + A: GLWEInfos, + { + self.bytes_of_glwe_prepared(infos.base2k(), infos.k(), infos.rank()) + } + + fn prepare_glwe<R, O>(&self, res: &mut R, other: &O) + where + R: GLWEPreparedToMut<B>, + O: GLWEToRef, + { + { + let mut res: GLWEPrepared<&mut [u8], B> = res.to_mut(); + let other: GLWE<&[u8]> = other.to_ref(); + + assert_eq!(res.n(), self.ring_degree()); + assert_eq!(other.n(), self.ring_degree()); + assert_eq!(res.size(), other.size()); + assert_eq!(res.k(), other.k()); + assert_eq!(res.base2k(), other.base2k()); + + for i in 0..(res.rank() + 1).into() { + self.vec_znx_dft_apply(1, 0, &mut res.data, i, &other.data, i); + } + } + } +} + +impl<B: Backend> GLWEPreparedAlloc<B> for Module<B> where Self: VecZnxDftAlloc<B> + VecZnxDftBytesOf + VecZnxDftApply<B> {} + +impl<B: Backend> GLWEPrepared<Vec<u8>, B> { + pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self + where + A: GLWEInfos, + M: GLWEPreparedAlloc<B>, + { + module.alloc_glwe_prepared_from_infos(infos) + } + + pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self + where + M: GLWEPreparedAlloc<B>, + { + module.alloc_glwe_prepared(base2k, k, rank) + } + + pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize + where + A: GLWEInfos, + M: GLWEPreparedAlloc<B>, + { + module.bytes_of_glwe_prepared_from_infos(infos) + } + + pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize + where + M: GLWEPreparedAlloc<B>, + { + module.bytes_of_glwe_prepared(base2k, k, rank) + } +} + +impl<D: DataMut, B: Backend> GLWEPrepared<D, B> { + pub fn prepare<O, M>(&mut self, module: &M, other: &O) + where + O: GLWEToRef, + M: GLWEPreparedAlloc<B>, + { + module.prepare_glwe(self, other); + } +} + +pub trait GLWEPreparedToMut<B: Backend> { + fn to_mut(&mut self) -> GLWEPrepared<&mut [u8], B>; +} + +impl<D: DataMut, B: Backend> GLWEPreparedToMut<B> for GLWEPrepared<D, B> { + fn to_mut(&mut self) -> GLWEPrepared<&mut [u8], B> { + GLWEPrepared { + k: self.k, + base2k: self.base2k, + data: self.data.to_mut(), + } + } +} + +pub trait GLWEPreparedToRef<B: Backend> { + fn to_ref(&self) -> GLWEPrepared<&[u8], B>; +} + +impl<D: DataRef, B: Backend> GLWEPreparedToRef<B> for GLWEPrepared<D, B> { + fn to_ref(&self) -> GLWEPrepared<&[u8], B> { + GLWEPrepared { + data: self.data.to_ref(), + k: self.k, + base2k: self.base2k, + } + } +}
@@ -1,190 +0,0 @@
-use poulpy_hal::{ - api::{VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf}, - layouts::{Backend, Data, DataMut, DataRef, Module, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, ZnxInfos}, -}; - -use crate::{ - GetDistribution, GetDistributionMut, - dist::Distribution, - layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, LWEInfos, Rank, TorusPrecision}, -}; - -#[derive(PartialEq, Eq)] -pub struct GLWEPublicKeyPrepared<D: Data, B: Backend> { - pub(crate) data: VecZnxDft<D, B>, - pub(crate) base2k: Base2K, - pub(crate) k: TorusPrecision, - pub(crate) dist: Distribution, -} - -impl<D: DataRef, BE: Backend> GetDistribution for GLWEPublicKeyPrepared<D, BE> { - fn dist(&self) -> &Distribution { - &self.dist - } -} - -impl<D: DataMut, BE: Backend> GetDistributionMut for GLWEPublicKeyPrepared<D, BE> { - fn dist_mut(&mut self) -> &mut Distribution { - &mut self.dist - } -} - -impl<D: Data, B: Backend> LWEInfos for GLWEPublicKeyPrepared<D, B> { - fn base2k(&self) -> Base2K { - self.base2k - } - - fn k(&self) -> TorusPrecision { - self.k - } - - fn size(&self) -> usize { - self.data.size() - } - - fn n(&self) -> Degree { - Degree(self.data.n() as u32) - } -} - -impl<D: Data, B: Backend> GLWEInfos for GLWEPublicKeyPrepared<D, B> { - fn rank(&self) -> Rank { - Rank(self.data.cols() as u32 - 1) - } -} - -pub trait GLWEPublicKeyPreparedAlloc<B: Backend> -where - Self: GetDegree + VecZnxDftAlloc<B> + VecZnxDftBytesOf, -{ - fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared<Vec<u8>, B> { - GLWEPublicKeyPrepared { - data: self.vec_znx_dft_alloc((rank + 1).into(), k.0.div_ceil(base2k.0) as usize), - base2k, - k, - dist: Distribution::NONE, - } - } - - fn alloc_glwe_public_key_prepared_from_infos<A>(&self, infos: &A) -> GLWEPublicKeyPrepared<Vec<u8>, B> - where - A: GLWEInfos, - { - self.alloc_glwe_public_key_prepared(infos.base2k(), infos.k(), infos.rank()) - } - - fn bytes_of_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize { - self.bytes_of_vec_znx_dft((rank + 1).into(), k.0.div_ceil(base2k.0) as usize) - } - - fn bytes_of_glwe_public_key_prepared_from_infos<A>(&self, infos: &A) -> usize - where - A: GLWEInfos, - { - self.bytes_of_glwe_public_key_prepared(infos.base2k(), infos.k(), infos.rank()) - } -} - -impl<B: Backend> GLWEPublicKeyPreparedAlloc<B> for Module<B> where Self: VecZnxDftAlloc<B> + VecZnxDftBytesOf {} - -impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> { - pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self - where - A: GLWEInfos, - M: GLWEPublicKeyPreparedAlloc<B>, - { - module.alloc_glwe_public_key_prepared_from_infos(infos) - } - - pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self - where - M: GLWEPublicKeyPreparedAlloc<B>, - { - module.alloc_glwe_public_key_prepared(base2k, k, rank) - } - - pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize - where - A: GLWEInfos, - M: GLWEPublicKeyPreparedAlloc<B>, - { - module.bytes_of_glwe_public_key_prepared_from_infos(infos) - } - - pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize - where - M: GLWEPublicKeyPreparedAlloc<B>, - { - module.bytes_of_glwe_public_key_prepared(base2k, k, rank) - } -} - -pub trait GLWEPublicKeyPrepare<B: Backend> -where - Self: GetDegree + VecZnxDftApply<B>, -{ - fn prepare_glwe_public_key<R, O>(&self, res: &mut R, other: &O) - where - R: GLWEPublicKeyPreparedToMut<B> + GetDistributionMut, - O: GLWEPublicKeyToRef + GetDistribution, - { - { - let mut res: GLWEPublicKeyPrepared<&mut [u8], B> = res.to_mut(); - let other: GLWEPublicKey<&[u8]> = other.to_ref(); - - assert_eq!(res.n(), self.ring_degree()); - assert_eq!(other.n(), self.ring_degree()); - assert_eq!(res.size(), other.size()); - assert_eq!(res.k(), other.k()); - assert_eq!(res.base2k(), other.base2k()); - - for i in 0..(res.rank() + 1).into() { - self.vec_znx_dft_apply(1, 0, &mut res.data, i, &other.data, i); - } - } - - *res.dist_mut() = *other.dist(); - } -} - -impl<B: Backend> GLWEPublicKeyPrepare<B> for Module<B> where Self: GetDegree + VecZnxDftApply<B> {} - -impl<D: DataMut, B: Backend> GLWEPublicKeyPrepared<D, B> { - pub fn prepare<O, M>(&mut self, module: &M, other: &O) - where - O: GLWEPublicKeyToRef + GetDistribution, - M: GLWEPublicKeyPrepare<B>, - { - module.prepare_glwe_public_key(self, other); - } -} - -pub trait GLWEPublicKeyPreparedToMut<B: Backend> { - fn to_mut(&mut self) -> GLWEPublicKeyPrepared<&mut [u8], B>; -} - -impl<D: DataMut, B: Backend> GLWEPublicKeyPreparedToMut<B> for GLWEPublicKeyPrepared<D, B> { - fn to_mut(&mut self) -> GLWEPublicKeyPrepared<&mut [u8], B> { - GLWEPublicKeyPrepared { - dist: self.dist, - k: self.k, - base2k: self.base2k, - data: self.data.to_mut(), - } - } -} - -pub trait GLWEPublicKeyPreparedToRef<B: Backend> { - fn to_ref(&self) -> GLWEPublicKeyPrepared<&[u8], B>; -} - -impl<D: DataRef, B: Backend> GLWEPublicKeyPreparedToRef<B> for GLWEPublicKeyPrepared<D, B> { - fn to_ref(&self) -> GLWEPublicKeyPrepared<&[u8], B> { - GLWEPublicKeyPrepared { - data: self.data.to_ref(), - dist: self.dist, - k: self.k, - base2k: self.base2k, - } - } -}
@@ -0,0 +1,156 @@
+use poulpy_hal::{ + api::{VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf}, + layouts::{Backend, Data, DataMut, DataRef, Module}, +}; + +use crate::{ + GetDistribution, GetDistributionMut, + dist::Distribution, + layouts::{ + Base2K, Degree, GLWEInfos, GLWEPrepared, GLWEPreparedAlloc, GLWEPreparedToMut, GLWEPreparedToRef, GLWEToRef, GetDegree, + LWEInfos, Rank, TorusPrecision, + }, +}; + +#[derive(PartialEq, Eq)] +pub struct GLWEPublicKeyPrepared<D: Data, B: Backend> { + pub(crate) key: GLWEPrepared<D, B>, + pub(crate) dist: Distribution, +} + +impl<D: DataRef, BE: Backend> GetDistribution for GLWEPublicKeyPrepared<D, BE> { + fn dist(&self) -> &Distribution { + &self.dist + } +} + +impl<D: DataMut, BE: Backend> GetDistributionMut for GLWEPublicKeyPrepared<D, BE> { + fn dist_mut(&mut self) -> &mut Distribution { + &mut self.dist + } +} + +impl<D: Data, B: Backend> LWEInfos for GLWEPublicKeyPrepared<D, B> { + fn base2k(&self) -> Base2K { + self.key.base2k() + } + + fn k(&self) -> TorusPrecision { + self.key.k() + } + + fn size(&self) -> usize { + self.key.size() + } + + fn n(&self) -> Degree { + self.key.n() + } +} + +impl<D: Data, B: Backend> GLWEInfos for GLWEPublicKeyPrepared<D, B> { + fn rank(&self) -> Rank { + self.key.rank() + } +} + +pub trait GLWEPublicKeyPreparedAlloc<B: Backend> +where + Self: GetDegree + GLWEPreparedAlloc<B>, +{ + fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared<Vec<u8>, B> { + GLWEPublicKeyPrepared { + key: self.alloc_glwe_prepared(base2k, k, rank), + dist: Distribution::NONE, + } + } + + fn alloc_glwe_public_key_prepared_from_infos<A>(&self, infos: &A) -> GLWEPublicKeyPrepared<Vec<u8>, B> + where + A: GLWEInfos, + { + self.alloc_glwe_public_key_prepared(infos.base2k(), infos.k(), infos.rank()) + } + + fn bytes_of_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize { + self.bytes_of_glwe_prepared(base2k, k, rank) + } + + fn bytes_of_glwe_public_key_prepared_from_infos<A>(&self, infos: &A) -> usize + where + A: GLWEInfos, + { + self.bytes_of_glwe_public_key_prepared(infos.base2k(), infos.k(), infos.rank()) + } + + fn prepare_glwe_public_key<R, O>(&self, res: &mut R, other: &O) + where + R: GLWEPreparedToMut<B> + GetDistributionMut, + O: GLWEToRef + GetDistribution, + { + self.prepare_glwe(res, other); + *res.dist_mut() = *other.dist(); + } +} + +impl<B: Backend> GLWEPublicKeyPreparedAlloc<B> for Module<B> where Self: VecZnxDftAlloc<B> + VecZnxDftBytesOf + VecZnxDftApply<B> {} + +impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> { + pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self + where + A: GLWEInfos, + M: GLWEPublicKeyPreparedAlloc<B>, + { + module.alloc_glwe_public_key_prepared_from_infos(infos) + } + + pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self + where + M: GLWEPublicKeyPreparedAlloc<B>, + { + module.alloc_glwe_public_key_prepared(base2k, k, rank) + } + + pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize + where + A: GLWEInfos, + M: GLWEPublicKeyPreparedAlloc<B>, + { + module.bytes_of_glwe_public_key_prepared_from_infos(infos) + } + + pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize + where + M: GLWEPublicKeyPreparedAlloc<B>, + { + module.bytes_of_glwe_public_key_prepared(base2k, k, rank) + } +} + +impl<D: DataMut, B: Backend> GLWEPublicKeyPrepared<D, B> { + pub fn prepare<O, M>(&mut self, module: &M, other: &O) + where + O: GLWEToRef + GetDistribution, + M: GLWEPublicKeyPreparedAlloc<B>, + { + module.prepare_glwe_public_key(self, other); + } +} + +impl<D: DataMut, B: Backend> GLWEPreparedToMut<B> for GLWEPublicKeyPrepared<D, B> +where + GLWEPrepared<D, B>: GLWEPreparedToMut<B>, +{ + fn to_mut(&mut self) -> GLWEPrepared<&mut [u8], B> { + self.key.to_mut() + } +} + +impl<D: DataRef, B: Backend> GLWEPreparedToRef<B> for GLWEPublicKeyPrepared<D, B> +where + GLWEPrepared<D, B>: GLWEPreparedToRef<B>, +{ + fn to_ref(&self) -> GLWEPrepared<&[u8], B> { + self.key.to_ref() + } +}
@@ -49,9 +49,9 @@ Rank(self.data.cols() as u32)
} } -pub trait GLWESecretPreparedAlloc<B: Backend> +pub trait GLWESecretPreparedApi<B: Backend> where - Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B>, + Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B> + SvpPrepare<B>, { fn alloc_glwe_secret_prepared(&self, rank: Rank) -> GLWESecretPrepared<Vec<u8>, B> { GLWESecretPrepared {@@ -77,22 +77,39 @@ {
assert_eq!(self.ring_degree(), infos.n()); self.bytes_of_glwe_secret_prepared(infos.rank()) } + + fn prepare_glwe_secret<R, O>(&self, res: &mut R, other: &O) + where + R: GLWESecretPreparedToMut<B> + GetDistributionMut, + O: GLWESecretToRef + GetDistribution, + { + { + let mut res: GLWESecretPrepared<&mut [u8], _> = res.to_mut(); + let other: GLWESecret<&[u8]> = other.to_ref(); + + for i in 0..res.rank().into() { + self.svp_prepare(&mut res.data, i, &other.data, i); + } + } + + *res.dist_mut() = *other.dist(); + } } -impl<B: Backend> GLWESecretPreparedAlloc<B> for Module<B> where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B> {} +impl<B: Backend> GLWESecretPreparedApi<B> for Module<B> where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B> + SvpPrepare<B> {} impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> { pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self where A: GLWEInfos, - M: GLWESecretPreparedAlloc<B>, + M: GLWESecretPreparedApi<B>, { module.alloc_glwe_secret_prepared_from_infos(infos) } pub fn alloc<M>(module: &M, rank: Rank) -> Self where - M: GLWESecretPreparedAlloc<B>, + M: GLWESecretPreparedApi<B>, { module.alloc_glwe_secret_prepared(rank) }@@ -100,14 +117,14 @@
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize where A: GLWEInfos, - M: GLWESecretPreparedAlloc<B>, + M: GLWESecretPreparedApi<B>, { module.bytes_of_glwe_secret_prepared_from_infos(infos) } pub fn bytes_of<M>(module: &M, rank: Rank) -> usize where - M: GLWESecretPreparedAlloc<B>, + M: GLWESecretPreparedApi<B>, { module.bytes_of_glwe_secret_prepared(rank) }@@ -123,34 +140,10 @@ Rank(self.data.cols() as u32)
} } -pub trait GLWESecretPrepare<B: Backend> -where - Self: SvpPrepare<B>, -{ - fn prepare_glwe_secret<R, O>(&self, res: &mut R, other: &O) - where - R: GLWESecretPreparedToMut<B> + GetDistributionMut, - O: GLWESecretToRef + GetDistribution, - { - { - let mut res: GLWESecretPrepared<&mut [u8], _> = res.to_mut(); - let other: GLWESecret<&[u8]> = other.to_ref(); - - for i in 0..res.rank().into() { - self.svp_prepare(&mut res.data, i, &other.data, i); - } - } - - *res.dist_mut() = *other.dist(); - } -} - -impl<B: Backend> GLWESecretPrepare<B> for Module<B> where Self: SvpPrepare<B> {} - impl<D: DataMut, B: Backend> GLWESecretPrepared<D, B> { pub fn prepare<M, O>(&mut self, module: &M, other: &O) where - M: GLWESecretPrepare<B>, + M: GLWESecretPreparedApi<B>, O: GLWESecretToRef + GetDistribution, { module.prepare_glwe_secret(self, other);
@@ -3,7 +3,7 @@
use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision, - prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, + prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, }; #[derive(PartialEq, Eq)]@@ -101,6 +101,21 @@ "dsize > 1 is not supported for GLWEToLWESwitchingKeyPrepared"
); self.bytes_of_glwe_to_lwe_switching_key_prepared(infos.base2k(), infos.k(), infos.rank_in(), infos.dnum()) } + + fn prepare_glwe_to_lwe_switching_key_tmp_bytes<A>(&self, infos: &A) + where + A: GGLWEInfos, + { + self.prepare_glwe_switching_key_tmp_bytes(infos); + } + + fn prepare_glwe_to_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, + O: GGLWEToRef + GLWESwitchingKeyDegrees, + { + self.prepare_glwe_switching(res, other, scratch); + } } impl<B: Backend> GLWEToLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}@@ -137,33 +152,11 @@ module.bytes_of_glwe_to_lwe_switching_key_prepared(base2k, k, rank_in, dnum)
} } -pub trait GLWEToLWESwitchingKeyPrepare<B: Backend> -where - Self: GLWESwitchingKeyPrepare<B>, -{ - fn prepare_glwe_to_lwe_switching_key_tmp_bytes<A>(&self, infos: &A) - where - A: GGLWEInfos, - { - self.prepare_glwe_switching_key_tmp_bytes(infos); - } - - fn prepare_glwe_to_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) - where - R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, - O: GGLWEToRef + GLWESwitchingKeyDegrees, - { - self.prepare_glwe_switching(res, other, scratch); - } -} - -impl<B: Backend> GLWEToLWESwitchingKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {} - impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) where A: GGLWEInfos, - M: GLWEToLWESwitchingKeyPrepare<B>, + M: GLWEToLWESwitchingKeyPreparedAlloc<B>, { module.prepare_glwe_to_lwe_switching_key_tmp_bytes(infos); }@@ -173,7 +166,7 @@ impl<D: DataMut, B: Backend> GLWEToLWESwitchingKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where O: GGLWEToRef + GLWESwitchingKeyDegrees, - M: GLWEToLWESwitchingKeyPrepare<B>, + M: GLWEToLWESwitchingKeyPreparedAlloc<B>, { module.prepare_glwe_to_lwe_switching_key(self, other, scratch); }
@@ -3,7 +3,7 @@
use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision, - prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, + prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, }; #[derive(PartialEq, Eq)]@@ -110,6 +110,20 @@ "rank_out > 1 is not supported for LWESwitchingKey"
); self.bytes_of_lwe_switching_key_prepared(infos.base2k(), infos.k(), infos.dnum()) } + + fn prepare_lwe_switching_key_tmp_bytes<A>(&self, infos: &A) + where + A: GGLWEInfos, + { + self.prepare_glwe_switching_key_tmp_bytes(infos); + } + fn prepare_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, + O: GGLWEToRef + GLWESwitchingKeyDegrees, + { + self.prepare_glwe_switching(res, other, scratch); + } } impl<B: Backend> LWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}@@ -146,32 +160,11 @@ module.bytes_of_lwe_switching_key_prepared(base2k, k, dnum)
} } -pub trait LWESwitchingKeyPrepare<B: Backend> -where - Self: GLWESwitchingKeyPrepare<B>, -{ - fn prepare_lwe_switching_key_tmp_bytes<A>(&self, infos: &A) - where - A: GGLWEInfos, - { - self.prepare_glwe_switching_key_tmp_bytes(infos); - } - fn prepare_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) - where - R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, - O: GGLWEToRef + GLWESwitchingKeyDegrees, - { - self.prepare_glwe_switching(res, other, scratch); - } -} - -impl<B: Backend> LWESwitchingKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {} - impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) where A: GGLWEInfos, - M: LWESwitchingKeyPrepare<B>, + M: LWESwitchingKeyPreparedAlloc<B>, { module.prepare_lwe_switching_key_tmp_bytes(infos); }@@ -181,7 +174,7 @@ impl<D: DataMut, B: Backend> LWESwitchingKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where O: GGLWEToRef + GLWESwitchingKeyDegrees, - M: LWESwitchingKeyPrepare<B>, + M: LWESwitchingKeyPreparedAlloc<B>, { module.prepare_lwe_switching_key(self, other, scratch); }
@@ -3,7 +3,7 @@
use crate::layouts::{ Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision, - prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, + prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, }; /// A special [GLWESwitchingKey] required to for the conversion from [LWE] to [GLWE].@@ -108,6 +108,21 @@ "dsize > 1 is not supported for LWEToGLWESwitchingKey"
); self.bytes_of_lwe_to_glwe_switching_key_prepared(infos.base2k(), infos.k(), infos.rank_out(), infos.dnum()) } + + fn prepare_lwe_to_glwe_switching_key_tmp_bytes<A>(&self, infos: &A) + where + A: GGLWEInfos, + { + self.prepare_glwe_switching_key_tmp_bytes(infos); + } + + fn prepare_lwe_to_glwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) + where + R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, + O: GGLWEToRef + GLWESwitchingKeyDegrees, + { + self.prepare_glwe_switching(res, other, scratch); + } } impl<B: Backend> LWEToGLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}@@ -144,33 +159,11 @@ module.bytes_of_lwe_to_glwe_switching_key_prepared(base2k, k, rank_out, dnum)
} } -pub trait LWEToGLWESwitchingKeyPrepare<B: Backend> -where - Self: GLWESwitchingKeyPrepare<B>, -{ - fn prepare_lwe_to_glwe_switching_key_tmp_bytes<A>(&self, infos: &A) - where - A: GGLWEInfos, - { - self.prepare_glwe_switching_key_tmp_bytes(infos); - } - - fn prepare_lwe_to_glwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) - where - R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut, - O: GGLWEToRef + GLWESwitchingKeyDegrees, - { - self.prepare_glwe_switching(res, other, scratch); - } -} - -impl<B: Backend> LWEToGLWESwitchingKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {} - impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> { pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) where A: GGLWEInfos, - M: LWEToGLWESwitchingKeyPrepare<B>, + M: LWEToGLWESwitchingKeyPreparedAlloc<B>, { module.prepare_lwe_to_glwe_switching_key_tmp_bytes(infos); }@@ -180,7 +173,7 @@ impl<D: DataMut, B: Backend> LWEToGLWESwitchingKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) where O: GGLWEToRef + GLWESwitchingKeyDegrees, - M: LWEToGLWESwitchingKeyPrepare<B>, + M: LWEToGLWESwitchingKeyPreparedAlloc<B>, { module.prepare_lwe_to_glwe_switching_key(self, other, scratch); }
@@ -1,21 +1,23 @@
-mod gglwe_atk; -mod gglwe_ct; -mod gglwe_ksk; -mod gglwe_tsk; -mod ggsw_ct; -mod glwe_pk; -mod glwe_sk; -mod glwe_to_lwe_ksk; -mod lwe_ksk; -mod lwe_to_glwe_ksk; +mod gglwe; +mod ggsw; +mod glwe; +mod glwe_automorphism_key; +mod glwe_public_key; +mod glwe_secret; +mod glwe_switching_key; +mod glwe_tensor_key; +mod glwe_to_lwe_switching_key; +mod lwe_switching_key; +mod lwe_to_glwe_switching_key; -pub use gglwe_atk::*; -pub use gglwe_ct::*; -pub use gglwe_ksk::*; -pub use gglwe_tsk::*; -pub use ggsw_ct::*; -pub use glwe_pk::*; -pub use glwe_sk::*; -pub use glwe_to_lwe_ksk::*; -pub use lwe_ksk::*; -pub use lwe_to_glwe_ksk::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe::*; +pub use glwe_automorphism_key::*; +pub use glwe_public_key::*; +pub use glwe_secret::*; +pub use glwe_switching_key::*; +pub use glwe_tensor_key::*; +pub use glwe_to_lwe_switching_key::*; +pub use lwe_switching_key::*; +pub use lwe_to_glwe_switching_key::*;
@@ -1,10 +1,10 @@
-mod gglwe_ct; -mod ggsw_ct; -mod glwe_ct; +mod gglwe; +mod ggsw; +mod glwe; -pub use gglwe_ct::*; -pub use ggsw_ct::*; -pub use glwe_ct::*; +pub use gglwe::*; +pub use ggsw::*; +pub use glwe::*; #[allow(clippy::too_many_arguments)] #[allow(dead_code)]
@@ -6,10 +6,10 @@
use crate::{ dist::Distribution, layouts::{ - AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPublicKey, - GLWESecret, GLWESwitchingKey, Rank, TensorKey, + AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPrepared, + GLWEPublicKey, GLWESecret, GLWESwitchingKey, Rank, TensorKey, prepared::{ - AutomorphismKeyPrepared, GGLWEPrepared, GGSWPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared, + GGLWEPrepared, GGSWPrepared, GLWEAutomorphismKeyPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared, }, },@@ -19,7 +19,7 @@ pub trait ScratchTakeCore<B: Backend>
where Self: ScratchTakeBasic + ScratchAvailable, { - fn take_glwe_ct<A, M>(&mut self, module: &M, infos: &A) -> (GLWE<&mut [u8]>, &mut Self) + fn take_glwe<A, M>(&mut self, module: &M, infos: &A) -> (GLWE<&mut [u8]>, &mut Self) where A: GLWEInfos, M: ModuleN,@@ -36,7 +36,7 @@ scratch,
) } - fn take_glwe_ct_slice<A, M>(&mut self, module: &M, size: usize, infos: &A) -> (Vec<GLWE<&mut [u8]>>, &mut Self) + fn take_glwe_slice<A, M>(&mut self, module: &M, size: usize, infos: &A) -> (Vec<GLWE<&mut [u8]>>, &mut Self) where A: GLWEInfos, M: ModuleN,@@ -44,14 +44,14 @@ {
let mut scratch: &mut Self = self; let mut cts: Vec<GLWE<&mut [u8]>> = Vec::with_capacity(size); for _ in 0..size { - let (ct, new_scratch) = scratch.take_glwe_ct(module, infos); + let (ct, new_scratch) = scratch.take_glwe(module, infos); scratch = new_scratch; cts.push(ct); } (cts, scratch) } - fn take_glwe_pt<A, M>(&mut self, module: &M, infos: &A) -> (GLWEPlaintext<&mut [u8]>, &mut Self) + fn take_glwe_plaintext<A, M>(&mut self, module: &M, infos: &A) -> (GLWEPlaintext<&mut [u8]>, &mut Self) where A: GLWEInfos, M: ModuleN,@@ -184,25 +184,38 @@ }
(cts, scratch) } - fn take_glwe_pk<A, M>(&mut self, module: &M, infos: &A) -> (GLWEPublicKey<&mut [u8]>, &mut Self) + fn take_glwe_public_key<A, M>(&mut self, module: &M, infos: &A) -> (GLWEPublicKey<&mut [u8]>, &mut Self) where A: GLWEInfos, M: ModuleN, { assert_eq!(module.n() as u32, infos.n()); - let (data, scratch) = self.take_vec_znx(module, (infos.rank() + 1).into(), infos.size()); + let (data, scratch) = self.take_glwe(module, infos); ( GLWEPublicKey { - k: infos.k(), dist: Distribution::NONE, - base2k: infos.base2k(), - data, + key: data, }, scratch, ) } - fn take_glwe_pk_prepared<A, M>(&mut self, module: &M, infos: &A) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self) + fn take_glwe_public_key_prepared<A, M>(&mut self, module: &M, infos: &A) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self) + where + A: GLWEInfos, + M: ModuleN + VecZnxDftBytesOf, + { + let (data, scratch) = self.take_glwe_prepared(module, infos); + ( + GLWEPublicKeyPrepared { + dist: Distribution::NONE, + key: data, + }, + scratch, + ) + } + + fn take_glwe_prepared<A, M>(&mut self, module: &M, infos: &A) -> (GLWEPrepared<&mut [u8], B>, &mut Self) where A: GLWEInfos, M: ModuleN + VecZnxDftBytesOf,@@ -210,9 +223,8 @@ {
assert_eq!(module.n() as u32, infos.n()); let (data, scratch) = self.take_vec_znx_dft(module, (infos.rank() + 1).into(), infos.size()); ( - GLWEPublicKeyPrepared { + GLWEPrepared { k: infos.k(), - dist: Distribution::NONE, base2k: infos.base2k(), data, },@@ -265,7 +277,7 @@ scratch,
) } - fn take_gglwe_switching_key_prepared<A, M>( + fn take_glwe_switching_key_prepared<A, M>( &mut self, module: &M, infos: &A,@@ -300,14 +312,14 @@ fn take_gglwe_automorphism_key_prepared<A, M>(
&mut self, module: &M, infos: &A, - ) -> (AutomorphismKeyPrepared<&mut [u8], B>, &mut Self) + ) -> (GLWEAutomorphismKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, M: ModuleN + VmpPMatBytesOf, { assert_eq!(module.n() as u32, infos.n()); let (data, scratch) = self.take_gglwe_prepared(module, infos); - (AutomorphismKeyPrepared { key: data, p: 0 }, scratch) + (GLWEAutomorphismKeyPrepared { key: data, p: 0 }, scratch) } fn take_tensor_key<A, M>(&mut self, module: &M, infos: &A) -> (TensorKey<&mut [u8]>, &mut Self)
@@ -4,9 +4,9 @@ use crate::layouts::{
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE, LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision, compressed::{ - AutomorphismKeyCompressed, GGLWECompressed, GGSWCompressed, GLWECompressed, GLWESwitchingKeyCompressed, - GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed, LWEToGLWESwitchingKeyCompressed, - TensorKeyCompressed, + GGLWECompressed, GGSWCompressed, GLWEAutomorphismKeyCompressed, GLWECompressed, GLWESwitchingKeyCompressed, + GLWETensorKeyCompressed, GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed, + LWEToGLWESwitchingKeyCompressed, }, };@@ -75,7 +75,8 @@ }
#[test] fn test_automorphism_key_compressed_serialization() { - let original: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let original: GLWEAutomorphismKeyCompressed<Vec<u8>> = + GLWEAutomorphismKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); }@@ -87,7 +88,7 @@ }
#[test] fn test_tensor_key_compressed_serialization() { - let original: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let original: GLWETensorKeyCompressed<Vec<u8>> = GLWETensorKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); }
@@ -5,12 +5,12 @@ source::Source,
}; use crate::{ - AutomorphismKeyAutomorphism, AutomorphismKeyEncryptSk, GLWEDecrypt, ScratchTakeCore, + AutomorphismKeyEncryptSk, GLWEAutomorphismKeyAutomorphism, GLWEDecrypt, ScratchTakeCore, encryption::SIGMA, layouts::{ - AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GGLWEInfos, GLWEPlaintext, - GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, + AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GLWEAutomorphismKeyPreparedApi, GLWEPlaintext, GLWESecret, + GLWESecretPreparedApi, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared}, }, noise::log2_std_noise_gglwe_product, };@@ -19,14 +19,12 @@ #[allow(clippy::too_many_arguments)]
pub fn test_gglwe_automorphism_key_automorphism<BE: Backend>(module: &Module<BE>) where Module<BE>: AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPreparedAlloc<BE> - + AutomorphismKeyPrepare<BE> - + AutomorphismKeyAutomorphism<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + + GLWEAutomorphismKeyAutomorphism<BE> + VecZnxAutomorphism + GaloisElement + VecZnxSubScalarInplace - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + GLWEDecrypt<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,@@ -117,8 +115,8 @@ &mut source_xe,
scratch.borrow(), ); - let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = - AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_infos); + let mut auto_key_apply_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_infos); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());@@ -190,14 +188,12 @@ #[allow(clippy::too_many_arguments)]
pub fn test_gglwe_automorphism_key_automorphism_inplace<BE: Backend>(module: &Module<BE>) where Module<BE>: AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPreparedAlloc<BE> - + AutomorphismKeyPrepare<BE> - + AutomorphismKeyAutomorphism<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + + GLWEAutomorphismKeyAutomorphism<BE> + VecZnxAutomorphism + GaloisElement + VecZnxSubScalarInplace - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + GLWEDecrypt<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,@@ -271,8 +267,8 @@ &mut source_xe,
scratch.borrow(), ); - let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = - AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_layout); + let mut auto_key_apply_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_layout); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
@@ -8,9 +8,9 @@ use crate::{
AutomorphismKeyEncryptSk, GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, TensorKeyEncryptSk, encryption::SIGMA, layouts::{ - AutomorphismKey, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GGSW, GGSWLayout, GLWESecret, GLWESecretPrepare, - GLWESecretPreparedAlloc, TensorKey, TensorKeyLayout, TensorKeyPrepare, TensorKeyPreparedAlloc, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared}, + AutomorphismKey, GGSW, GGSWLayout, GLWEAutomorphismKeyPreparedApi, GLWESecret, GLWESecretPreparedApi, TensorKey, + TensorKeyLayout, TensorKeyPreparedAlloc, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared}, }, noise::noise_ggsw_keyswitch, };@@ -19,14 +19,11 @@ pub fn test_ggsw_automorphism<BE: Backend>(module: &Module<BE>)
where Module<BE>: GGSWEncryptSk<BE> + AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPreparedAlloc<BE> - + AutomorphismKeyPrepare<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + GGSWAutomorphism<BE> - + TensorKeyPrepare<BE> + TensorKeyPreparedAlloc<BE> + TensorKeyEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxAutomorphismInplace<BE> + GGSWNoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,@@ -137,8 +134,8 @@ &mut source_xe,
scratch.borrow(), ); - let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = - AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); + let mut auto_key_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =@@ -181,14 +178,11 @@ pub fn test_ggsw_automorphism_inplace<BE: Backend>(module: &Module<BE>)
where Module<BE>: GGSWEncryptSk<BE> + AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPreparedAlloc<BE> - + AutomorphismKeyPrepare<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + GGSWAutomorphism<BE> - + TensorKeyPrepare<BE> + TensorKeyPreparedAlloc<BE> + TensorKeyEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxAutomorphismInplace<BE> + GGSWNoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,@@ -286,8 +280,8 @@ &mut source_xe,
scratch.borrow(), ); - let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = - AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); + let mut auto_key_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
@@ -8,9 +8,9 @@ use crate::{
AutomorphismKeyEncryptSk, GLWEAutomorphism, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore, encryption::SIGMA, layouts::{ - AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GLWE, GLWELayout, - GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, + AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedApi, GLWELayout, GLWEPlaintext, GLWESecret, + GLWESecretPreparedApi, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared}, }, noise::log2_std_noise_gglwe_product, };@@ -18,14 +18,12 @@
pub fn test_glwe_automorphism<BE: Backend>(module: &Module<BE>) where Module<BE>: GLWEEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWEDecrypt<BE> + GLWEAutomorphism<BE> + AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPrepare<BE> - + AutomorphismKeyPreparedAlloc<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + GLWENoise<BE> + VecZnxAutomorphismInplace<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,@@ -108,8 +106,8 @@ &mut source_xe,
scratch.borrow(), ); - let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = - AutomorphismKeyPrepared::alloc_from_infos(module, &autokey_infos); + let mut autokey_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &autokey_infos); autokey_prepared.prepare(module, &autokey, scratch.borrow()); ct_out.automorphism(module, &ct_in, &autokey_prepared, scratch.borrow());@@ -138,14 +136,12 @@ #[allow(clippy::too_many_arguments)]
pub fn test_glwe_automorphism_inplace<BE: Backend>(module: &Module<BE>) where Module<BE>: GLWEEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWEDecrypt<BE> + GLWEAutomorphism<BE> + AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPrepare<BE> - + AutomorphismKeyPreparedAlloc<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + GLWENoise<BE> + VecZnxAutomorphismInplace<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,@@ -219,8 +215,8 @@ &mut source_xe,
scratch.borrow(), ); - let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = - AutomorphismKeyPrepared::alloc_from_infos(module, &autokey); + let mut autokey_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &autokey); autokey_prepared.prepare(module, &autokey, scratch.borrow()); ct.automorphism_inplace(module, &autokey_prepared, scratch.borrow());
@@ -8,10 +8,9 @@ use crate::{
GLWEDecrypt, GLWEEncryptSk, GLWEFromLWE, GLWEToLWESwitchingKeyEncryptSk, LWEDecrypt, LWEEncryptSk, LWEToGLWESwitchingKeyEncryptSk, ScratchTakeCore, layouts::{ - Base2K, Degree, Dnum, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, - GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyPrepare, GLWEToLWESwitchingKeyPreparedAlloc, LWE, - LWELayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, LWEToGLWESwitchingKeyPrepare, - LWEToGLWESwitchingKeyPreparedAlloc, Rank, TorusPrecision, + Base2K, Degree, Dnum, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi, GLWEToLWEKeyLayout, + GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyPreparedAlloc, LWE, LWELayout, LWEPlaintext, LWESecret, + LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, LWEToGLWESwitchingKeyPreparedAlloc, Rank, TorusPrecision, prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared}, }, };@@ -21,11 +20,9 @@ where
Module<BE>: GLWEFromLWE<BE> + LWEToGLWESwitchingKeyEncryptSk<BE> + GLWEDecrypt<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + LWEEncryptSk<BE> - + LWEToGLWESwitchingKeyPreparedAlloc<BE> - + LWEToGLWESwitchingKeyPrepare<BE>, + + LWEToGLWESwitchingKeyPreparedAlloc<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {@@ -115,10 +112,8 @@ + GLWEToLWESwitchingKeyEncryptSk<BE>
+ GLWEEncryptSk<BE> + LWEDecrypt<BE> + GLWEDecrypt<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + GLWEToLWESwitchingKeyEncryptSk<BE> - + GLWEToLWESwitchingKeyPrepare<BE> + GLWEToLWESwitchingKeyPreparedAlloc<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
@@ -9,8 +9,8 @@ AutomorphismKeyCompressedEncryptSk, AutomorphismKeyEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk,
GLWESwitchingKeyEncryptSk, ScratchTakeCore, encryption::SIGMA, layouts::{ - AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, GLWESecret, GLWESecretPrepare, - GLWESecretPreparedAlloc, GLWESwitchingKeyDecompress, compressed::AutomorphismKeyCompressed, prepared::GLWESecretPrepared, + AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, GLWESecret, GLWESecretPreparedApi, + GLWESwitchingKeyDecompress, compressed::GLWEAutomorphismKeyCompressed, prepared::GLWESecretPrepared, }, noise::GGLWENoise, };@@ -19,8 +19,7 @@ pub fn test_gglwe_automorphism_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
where Module<BE>: AutomorphismKeyEncryptSk<BE> + GGLWEKeyswitch<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyCompressedEncryptSk<BE> + GLWESwitchingKeyDecompress@@ -92,8 +91,7 @@ pub fn test_gglwe_automorphism_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
where Module<BE>: AutomorphismKeyCompressedEncryptSk<BE> + GGLWEKeyswitch<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyCompressedEncryptSk<BE> + AutomorphismKeyDecompress@@ -120,12 +118,13 @@ dsize: di.into(),
rank: rank.into(), }; - let mut atk_compressed: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc_from_infos(&atk_infos); + let mut atk_compressed: GLWEAutomorphismKeyCompressed<Vec<u8>> = + GLWEAutomorphismKeyCompressed::alloc_from_infos(&atk_infos); let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); - let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKeyCompressed::encrypt_sk_tmp_bytes( + let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWEAutomorphismKeyCompressed::encrypt_sk_tmp_bytes( module, &atk_infos, ));
@@ -9,9 +9,8 @@ GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
decryption::GLWEDecrypt, encryption::SIGMA, layouts::{ - GGLWELayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyCompressed, - GLWESwitchingKeyDecompress, - prepared::{GGLWEPrepare, GGLWEPreparedAlloc, GLWESecretPrepared}, + GGLWELayout, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyCompressed, GLWESwitchingKeyDecompress, + prepared::{GGLWEPreparedAlloc, GLWESecretPrepared}, }, noise::GGLWENoise, };@@ -19,12 +18,10 @@
pub fn test_gglwe_switching_key_encrypt_sk<BE: Backend>(module: &Module<BE>) where Module<BE>: GGLWEEncryptSk<BE> - + GGLWEPrepare<BE> + GGLWEPreparedAlloc<BE> + GGLWEKeyswitch<BE> + GLWEDecrypt<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + GLWESwitchingKeyEncryptSk<BE> + VecZnxFillUniform + GGLWENoise<BE>,@@ -86,12 +83,10 @@
pub fn test_gglwe_switching_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>) where Module<BE>: GGLWEEncryptSk<BE> - + GGLWEPrepare<BE> + GGLWEPreparedAlloc<BE> + GGLWEKeyswitch<BE> + GLWEDecrypt<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyCompressedEncryptSk<BE> + GLWESwitchingKeyDecompress
@@ -8,7 +8,7 @@ use crate::{
GGSWCompressedEncryptSk, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, encryption::SIGMA, layouts::{ - GGSW, GGSWDecompress, GGSWLayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, compressed::GGSWCompressed, + GGSW, GGSWDecompress, GGSWLayout, GLWESecret, GLWESecretPreparedApi, compressed::GGSWCompressed, prepared::GLWESecretPrepared, }, };@@ -17,7 +17,7 @@ pub fn test_ggsw_encrypt_sk<BE: Backend>(module: &Module<BE>)
where ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchTakeCore<BE>, - Module<BE>: GGSWEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + GGSWNoise<BE>, + Module<BE>: GGSWEncryptSk<BE> + GLWESecretPreparedApi<BE> + GGSWNoise<BE>, { let base2k: usize = 12; let k: usize = 54;@@ -74,8 +74,7 @@ pub fn test_ggsw_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
where ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchTakeCore<BE>, - Module<BE>: - GGSWCompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + GGSWNoise<BE> + GGSWDecompress, + Module<BE>: GGSWCompressedEncryptSk<BE> + GLWESecretPreparedApi<BE> + GGSWNoise<BE> + GGSWDecompress, { let base2k: usize = 12; let k: usize = 54;
@@ -9,8 +9,8 @@ GLWECompressedEncryptSk, GLWEEncryptPk, GLWEEncryptSk, GLWEPublicKeyGenerate, GLWESub, ScratchTakeCore,
decryption::GLWEDecrypt, encryption::SIGMA, layouts::{ - GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWEPublicKey, GLWEPublicKeyPrepare, GLWEPublicKeyPreparedAlloc, - GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, LWEInfos, + GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWEPublicKey, GLWEPublicKeyPreparedAlloc, GLWESecret, + GLWESecretPreparedApi, LWEInfos, compressed::GLWECompressed, prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared}, },@@ -18,8 +18,7 @@ };
pub fn test_glwe_encrypt_sk<BE: Backend>(module: &Module<BE>) where - Module<BE>: - GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxFillUniform + GLWESub, + Module<BE>: GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWESub, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {@@ -84,12 +83,7 @@ }
pub fn test_glwe_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>) where - Module<BE>: GLWECompressedEncryptSk<BE> - + GLWEDecrypt<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> - + VecZnxFillUniform - + GLWESub, + Module<BE>: GLWECompressedEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWESub, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {@@ -166,8 +160,7 @@ }
pub fn test_glwe_encrypt_zero_sk<BE: Backend>(module: &Module<BE>) where - Module<BE>: - GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxFillUniform + GLWESub, + Module<BE>: GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWESub, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {@@ -217,12 +210,10 @@
pub fn test_glwe_encrypt_pk<BE: Backend>(module: &Module<BE>) where Module<BE>: GLWEEncryptPk<BE> - + GLWEPublicKeyPrepare<BE> + GLWEPublicKeyPreparedAlloc<BE> + GLWEPublicKeyGenerate<BE> + GLWEDecrypt<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWESub, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -13,16 +13,15 @@ GGLWETensorKeyCompressedEncryptSk, ScratchTakeCore, TensorKeyEncryptSk,
decryption::GLWEDecrypt, encryption::SIGMA, layouts::{ - Dsize, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, TensorKey, TensorKeyCompressed, - TensorKeyLayout, prepared::GLWESecretPrepared, + Dsize, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi, GLWETensorKeyCompressed, TensorKey, TensorKeyLayout, + prepared::GLWESecretPrepared, }, }; pub fn test_gglwe_tensor_key_encrypt_sk<BE: Backend>(module: &Module<BE>) where Module<BE>: TensorKeyEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + GLWEDecrypt<BE> + VecZnxDftAlloc<BE> + VecZnxBigAlloc<BE>@@ -113,8 +112,7 @@
pub fn test_gglwe_tensor_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>) where Module<BE>: TensorKeyEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + GGLWETensorKeyCompressedEncryptSk<BE> + GLWEDecrypt<BE> + VecZnxDftAlloc<BE>@@ -144,12 +142,13 @@ dsize: Dsize(1),
rank: rank.into(), }; - let mut tensor_key_compressed: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc_from_infos(&tensor_key_infos); + let mut tensor_key_compressed: GLWETensorKeyCompressed<Vec<u8>> = + GLWETensorKeyCompressed::alloc_from_infos(&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<BE> = ScratchOwned::alloc(TensorKeyCompressed::encrypt_sk_tmp_bytes( + let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWETensorKeyCompressed::encrypt_sk_tmp_bytes( module, &tensor_key_infos, ));
@@ -8,8 +8,7 @@ use crate::{
GGLWEExternalProduct, GGLWENoise, GGSWEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore, encryption::SIGMA, layouts::{ - GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, - GLWESwitchingKey, GLWESwitchingKeyLayout, + GGSW, GGSWLayout, GGSWPreparedAlloc, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout, prepared::{GGSWPrepared, GLWESecretPrepared}, }, noise::noise_ggsw_product,@@ -21,10 +20,8 @@ where
Module<BE>: GGLWEExternalProduct<BE> + GGSWEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxRotateInplace<BE> - + GGSWPrepare<BE> + GGSWPreparedAlloc<BE> + GGLWENoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,@@ -172,10 +169,8 @@ where
Module<BE>: GGLWEExternalProduct<BE> + GGSWEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxRotateInplace<BE> - + GGSWPrepare<BE> + GGSWPreparedAlloc<BE> + GGLWENoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -8,7 +8,7 @@ use crate::{
GGSWEncryptSk, GGSWExternalProduct, GGSWNoise, ScratchTakeCore, encryption::SIGMA, layouts::{ - GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, + GGSW, GGSWLayout, GGSWPreparedAlloc, GLWESecret, GLWESecretPreparedApi, prepared::{GGSWPrepared, GLWESecretPrepared}, }, noise::noise_ggsw_product,@@ -19,9 +19,7 @@ pub fn test_ggsw_external_product<BE: Backend>(module: &Module<BE>)
where Module<BE>: GGSWEncryptSk<BE> + GGSWExternalProduct<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> - + GGSWPrepare<BE> + + GLWESecretPreparedApi<BE> + GGSWPreparedAlloc<BE> + VecZnxRotateInplace<BE> + GGSWNoise<BE>,@@ -155,9 +153,7 @@ pub fn test_ggsw_external_product_inplace<BE: Backend>(module: &Module<BE>)
where Module<BE>: GGSWEncryptSk<BE> + GGSWExternalProduct<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> - + GGSWPrepare<BE> + + GLWESecretPreparedApi<BE> + GGSWPreparedAlloc<BE> + VecZnxRotateInplace<BE> + GGSWNoise<BE>,
@@ -8,8 +8,7 @@ use crate::{
GGSWEncryptSk, GLWEEncryptSk, GLWEExternalProduct, GLWENoise, ScratchTakeCore, encryption::SIGMA, layouts::{ - GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare, - GLWESecretPreparedAlloc, + GGSW, GGSWLayout, GGSWPreparedAlloc, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi, prepared::{GGSWPrepared, GLWESecretPrepared}, }, noise::noise_ggsw_product,@@ -19,15 +18,13 @@ #[allow(clippy::too_many_arguments)]
pub fn test_glwe_external_product<BE: Backend>(module: &Module<BE>) where Module<BE>: GGSWEncryptSk<BE> - + GGSWPrepare<BE> + GGSWPreparedAlloc<BE> + VecZnxFillUniform + GLWEExternalProduct<BE> + GLWEEncryptSk<BE> + GLWENoise<BE> + VecZnxRotateInplace<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE>, + + GLWESecretPreparedApi<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {@@ -151,15 +148,13 @@ #[allow(clippy::too_many_arguments)]
pub fn test_glwe_external_product_inplace<BE: Backend>(module: &Module<BE>) where Module<BE>: GGSWEncryptSk<BE> - + GGSWPrepare<BE> + GGSWPreparedAlloc<BE> + VecZnxFillUniform + GLWEExternalProduct<BE> + GLWEEncryptSk<BE> + GLWENoise<BE> + VecZnxRotateInplace<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE>, + + GLWESecretPreparedApi<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {
@@ -8,8 +8,7 @@ use crate::{
GGLWEKeyswitch, GGLWENoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, encryption::SIGMA, layouts::{ - GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyLayout, - GLWESwitchingKeyPrepare, GLWESwitchingKeyPreparedAlloc, + GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout, GLWESwitchingKeyPreparedAlloc, prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared}, }, noise::log2_std_noise_gglwe_product,@@ -19,10 +18,8 @@ pub fn test_gglwe_switching_key_keyswitch<BE: Backend>(module: &Module<BE>)
where Module<BE>: GLWESwitchingKeyEncryptSk<BE> + GGLWEKeyswitch<BE> - + GLWESecretPrepare<BE> + GLWESwitchingKeyPreparedAlloc<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESwitchingKeyPrepare<BE> + + GLWESecretPreparedApi<BE> + GGLWENoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,@@ -165,9 +162,7 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<BE: Backend>(module: &Module<BE>)
where Module<BE>: GLWESwitchingKeyEncryptSk<BE> + GGLWEKeyswitch<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESwitchingKeyPrepare<BE> + + GLWESecretPreparedApi<BE> + GGLWENoise<BE> + GLWESwitchingKeyPreparedAlloc<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -8,9 +8,8 @@ use crate::{
GGSWEncryptSk, GGSWKeyswitch, GGSWNoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, TensorKeyEncryptSk, encryption::SIGMA, layouts::{ - GGSW, GGSWLayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyLayout, - GLWESwitchingKeyPrepare, GLWESwitchingKeyPreparedAlloc, TensorKey, TensorKeyLayout, TensorKeyPrepare, - TensorKeyPreparedAlloc, + GGSW, GGSWLayout, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout, + GLWESwitchingKeyPreparedAlloc, TensorKey, TensorKeyLayout, TensorKeyPreparedAlloc, prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared}, }, noise::noise_ggsw_keyswitch,@@ -23,13 +22,10 @@ Module<BE>: GGSWEncryptSk<BE>
+ GLWESwitchingKeyEncryptSk<BE> + TensorKeyEncryptSk<BE> + GGSWKeyswitch<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + TensorKeyPreparedAlloc<BE> + GLWESwitchingKeyPreparedAlloc<BE> - + GGSWNoise<BE> - + GLWESwitchingKeyPrepare<BE> - + TensorKeyPrepare<BE>, + + GGSWNoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {@@ -191,13 +187,10 @@ Module<BE>: GGSWEncryptSk<BE>
+ GLWESwitchingKeyEncryptSk<BE> + TensorKeyEncryptSk<BE> + GGSWKeyswitch<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> + + GLWESecretPreparedApi<BE> + TensorKeyPreparedAlloc<BE> + GLWESwitchingKeyPreparedAlloc<BE> - + GGSWNoise<BE> - + GLWESwitchingKeyPrepare<BE> - + TensorKeyPrepare<BE>, + + GGSWNoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {
@@ -8,8 +8,8 @@ use crate::{
GLWEEncryptSk, GLWEKeyswitch, GLWENoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, encryption::SIGMA, layouts::{ - GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, - GLWESwitchingKeyLayout, GLWESwitchingKeyPrepare, GLWESwitchingKeyPreparedAlloc, + GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout, + GLWESwitchingKeyPreparedAlloc, prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared}, }, noise::log2_std_noise_gglwe_product,@@ -22,9 +22,7 @@ Module<BE>: VecZnxFillUniform
+ GLWESwitchingKeyEncryptSk<BE> + GLWEEncryptSk<BE> + GLWEKeyswitch<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> - + GLWESwitchingKeyPrepare<BE> + + GLWESecretPreparedApi<BE> + GLWESwitchingKeyPreparedAlloc<BE> + GLWENoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,@@ -145,9 +143,7 @@ Module<BE>: VecZnxFillUniform
+ GLWESwitchingKeyEncryptSk<BE> + GLWEEncryptSk<BE> + GLWEKeyswitch<BE> - + GLWESecretPreparedAlloc<BE> - + GLWESecretPrepare<BE> - + GLWESwitchingKeyPrepare<BE> + + GLWESecretPreparedApi<BE> + GLWESwitchingKeyPreparedAlloc<BE> + GLWENoise<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -7,19 +7,15 @@
use crate::{ LWEDecrypt, LWEEncryptSk, LWEKeySwitch, LWESwitchingKeyEncrypt, ScratchTakeCore, layouts::{ - LWE, LWELayout, LWEPlaintext, LWESecret, LWESwitchingKey, LWESwitchingKeyLayout, LWESwitchingKeyPrepare, - LWESwitchingKeyPreparedAlloc, prepared::LWESwitchingKeyPrepared, + LWE, LWELayout, LWEPlaintext, LWESecret, LWESwitchingKey, LWESwitchingKeyLayout, LWESwitchingKeyPreparedAlloc, + prepared::LWESwitchingKeyPrepared, }, }; pub fn test_lwe_keyswitch<BE: Backend>(module: &Module<BE>) where - Module<BE>: LWEKeySwitch<BE> - + LWESwitchingKeyEncrypt<BE> - + LWEEncryptSk<BE> - + LWESwitchingKeyPreparedAlloc<BE> - + LWEDecrypt<BE> - + LWESwitchingKeyPrepare<BE>, + Module<BE>: + LWEKeySwitch<BE> + LWESwitchingKeyEncrypt<BE> + LWEEncryptSk<BE> + LWESwitchingKeyPreparedAlloc<BE> + LWEDecrypt<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, {
@@ -9,9 +9,9 @@
use crate::{ AutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWEPacker, GLWEPacking, GLWERotate, GLWESub, ScratchTakeCore, layouts::{ - AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GLWE, GLWELayout, - GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, + AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedApi, GLWELayout, GLWEPlaintext, GLWESecret, + GLWESecretPreparedApi, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared}, }, };@@ -19,11 +19,9 @@ pub fn test_glwe_packing<BE: Backend>(module: &Module<BE>)
where Module<BE>: GLWEEncryptSk<BE> + AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPrepare<BE> - + AutomorphismKeyPreparedAlloc<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + GLWEPacking<BE> - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + GLWESub + GLWEDecrypt<BE> + GLWERotate<BE>,@@ -82,7 +80,7 @@ pt.encode_vec_i64(&data, pt_k.into());
let gal_els: Vec<i64> = GLWEPacker::galois_elements(module); - let mut auto_keys: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new(); + let mut auto_keys: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new(); let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&key_infos); gal_els.iter().for_each(|gal_el| { tmp.encrypt_sk(@@ -93,7 +91,8 @@ &mut source_xa,
&mut source_xe, scratch.borrow(), ); - let mut atk_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = AutomorphismKeyPrepared::alloc_from_infos(module, &tmp); + let mut atk_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &tmp); atk_prepared.prepare(module, &tmp, scratch.borrow()); auto_keys.insert(*gal_el, atk_prepared); });
@@ -11,9 +11,9 @@ AutomorphismKeyEncryptSk, GLWEDecrypt, GLWEEncryptSk, ScratchTakeCore,
encryption::SIGMA, glwe_trace::GLWETrace, layouts::{ - AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GLWE, GLWELayout, - GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, LWEInfos, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, + AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedApi, GLWELayout, GLWEPlaintext, GLWESecret, + GLWESecretPreparedApi, LWEInfos, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared}, }, noise::var_noise_gglwe_product, };@@ -24,11 +24,9 @@ Module<BE>: GLWETrace<BE>
+ GLWEEncryptSk<BE> + GLWEDecrypt<BE> + AutomorphismKeyEncryptSk<BE> - + AutomorphismKeyPrepare<BE> - + AutomorphismKeyPreparedAlloc<BE> + + GLWEAutomorphismKeyPreparedApi<BE> + VecZnxFillUniform - + GLWESecretPrepare<BE> - + GLWESecretPreparedAlloc<BE> + + GLWESecretPreparedApi<BE> + VecZnxSubInplace + VecZnxNormalizeInplace<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,@@ -98,7 +96,7 @@ &mut source_xe,
scratch.borrow(), ); - let mut auto_keys: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new(); + let mut auto_keys: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, BE>> = HashMap::new(); let gal_els: Vec<i64> = GLWE::trace_galois_elements(module); let mut tmp: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&key_infos); gal_els.iter().for_each(|gal_el| {@@ -110,7 +108,8 @@ &mut source_xa,
&mut source_xe, scratch.borrow(), ); - let mut atk_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = AutomorphismKeyPrepared::alloc_from_infos(module, &tmp); + let mut atk_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> = + GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &tmp); atk_prepared.prepare(module, &tmp, scratch.borrow()); auto_keys.insert(*gal_el, atk_prepared); });
@@ -3,7 +3,7 @@ use poulpy_core::{
GLWEOperations, TakeGLWEPlaintext, TakeGLWESlice, glwe_packing, layouts::{ GLWE, GLWEInfos, GLWEPlaintextLayout, LWEInfos, TorusPrecision, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared}, }, }; use poulpy_hal::{@@ -32,7 +32,7 @@ fn post_process<ATK, BE: Backend>(
&mut self, module: &Module<BE>, mut tmp_res: Vec<GLWE<&mut [u8]>>, - auto_keys: &HashMap<i64, AutomorphismKeyPrepared<ATK, BE>>, + auto_keys: &HashMap<i64, GLWEAutomorphismKeyPrepared<ATK, BE>>, scratch: &mut Scratch<BE>, ) where ATK: DataRef,
@@ -20,7 +20,7 @@ layouts::{Dsize, GGLWELayout, GGSWInfos, GLWEInfos, LWEInfos},
}; use poulpy_core::glwe_packing; -use poulpy_core::layouts::{GGSW, GLWE, LWE, prepared::AutomorphismKeyPrepared}; +use poulpy_core::layouts::{GGSW, GLWE, LWE, prepared::GLWEAutomorphismKeyPrepared}; use crate::tfhe::{ blind_rotation::{@@ -268,7 +268,7 @@ a: &GLWE<DataA>,
log_gap_in: usize, log_gap_out: usize, log_domain: usize, - auto_keys: &HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>>, + auto_keys: &HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>>, scratch: &mut Scratch<B>, ) where DataRes: DataMut,
@@ -1,7 +1,7 @@
use poulpy_core::layouts::{ AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GGSWInfos, GLWE, GLWEInfos, GLWESecret, LWEInfos, LWESecret, TensorKey, TensorKeyLayout, - prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc, TensorKeyPrepared}, + prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc, TensorKeyPrepared}, }; use std::collections::HashMap;@@ -155,7 +155,7 @@
pub struct CircuitBootstrappingKeyPrepared<D: Data, BRA: BlindRotationAlgo, B: Backend> { pub(crate) brk: BlindRotationKeyPrepared<D, BRA, B>, pub(crate) tsk: TensorKeyPrepared<Vec<u8>, B>, - pub(crate) atk: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>>, + pub(crate) atk: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>>, } impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyPrepared<D, BRA, B> {@@ -200,12 +200,12 @@ where
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>, BlindRotationKey<D, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>, TensorKey<D>: PrepareAlloc<B, TensorKeyPrepared<Vec<u8>, B>>, - AutomorphismKey<D>: PrepareAlloc<B, AutomorphismKeyPrepared<Vec<u8>, B>>, + AutomorphismKey<D>: PrepareAlloc<B, GLWEAutomorphismKeyPrepared<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: TensorKeyPrepared<Vec<u8>, B> = self.tsk.prepare_alloc(module, scratch); - let mut atk: HashMap<i64, AutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); + let mut atk: HashMap<i64, GLWEAutomorphismKeyPrepared<Vec<u8>, B>> = HashMap::new(); for (key, value) in &self.atk { atk.insert(*key, value.prepare_alloc(module, scratch)); }