Traits reduction, file + structs renaming

This commit is contained in:
Pro7ech
2025-10-21 10:17:52 +02:00
parent 77b49ea530
commit db3b20b8f6
106 changed files with 1026 additions and 1108 deletions

View File

@@ -1,7 +1,7 @@
use poulpy_core::layouts::{ use poulpy_core::layouts::{
AutomorphismKey, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, AutomorphismKey, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey,
GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, TorusPrecision, GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, TorusPrecision,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
}; };
use std::{hint::black_box, time::Duration}; use std::{hint::black_box, time::Duration};
@@ -104,7 +104,8 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
scratch.borrow(), 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()); ksk_prepared.prepare(&module, &ksk, scratch.borrow());
move || { move || {

View File

@@ -7,8 +7,7 @@ use crate::{
ScratchTakeCore, ScratchTakeCore,
automorphism::glwe_ct::GLWEAutomorphism, automorphism::glwe_ct::GLWEAutomorphism,
layouts::{ layouts::{
AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWE, AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWE, GetGaloisElement, SetGaloisElement,
prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement},
}, },
}; };
@@ -18,7 +17,7 @@ impl AutomorphismKey<Vec<u8>> {
R: GGLWEInfos, R: GGLWEInfos,
A: GGLWEInfos, A: GGLWEInfos,
K: GGLWEInfos, K: GGLWEInfos,
M: AutomorphismKeyAutomorphism<BE>, M: GLWEAutomorphismKeyAutomorphism<BE>,
{ {
module.automorphism_key_automorphism_tmp_bytes(res_infos, a_infos, key_infos) module.automorphism_key_automorphism_tmp_bytes(res_infos, a_infos, key_infos)
} }
@@ -27,30 +26,30 @@ impl AutomorphismKey<Vec<u8>> {
impl<DataSelf: DataMut> AutomorphismKey<DataSelf> { 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>) pub fn automorphism<A, K, M, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
where where
A: GGLWEToRef + GetAutomorphismGaloisElement + GGLWEInfos, A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
M: AutomorphismKeyAutomorphism<BE>, M: GLWEAutomorphismKeyAutomorphism<BE>,
{ {
module.automorphism_key_automorphism(self, a, key, scratch); 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>) pub fn automorphism_inplace<K, M, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>)
where where
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
M: AutomorphismKeyAutomorphism<BE>, M: GLWEAutomorphismKeyAutomorphism<BE>,
{ {
module.automorphism_key_automorphism_inplace(self, key, scratch); 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 Self: GaloisElement + GLWEAutomorphism<BE> + VecZnxAutomorphism
{ {
} }
pub trait AutomorphismKeyAutomorphism<BE: Backend> pub trait GLWEAutomorphismKeyAutomorphism<BE: Backend>
where where
Self: GaloisElement + GLWEAutomorphism<BE> + VecZnxAutomorphism, Self: GaloisElement + GLWEAutomorphism<BE> + VecZnxAutomorphism,
{ {
@@ -65,9 +64,9 @@ where
fn automorphism_key_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>) fn automorphism_key_automorphism<R, A, K>(&self, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
where where
R: GGLWEToMut + SetAutomorphismGaloisElement + GGLWEInfos, R: GGLWEToMut + SetGaloisElement + GGLWEInfos,
A: GGLWEToRef + GetAutomorphismGaloisElement + GGLWEInfos, A: GGLWEToRef + GetGaloisElement + GGLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
assert!( assert!(
@@ -121,8 +120,8 @@ where
fn automorphism_key_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) fn automorphism_key_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
where where
R: GGLWEToMut + SetAutomorphismGaloisElement + GetAutomorphismGaloisElement + GGLWEInfos, R: GGLWEToMut + SetGaloisElement + GetGaloisElement + GGLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
assert_eq!( assert_eq!(

View File

@@ -7,7 +7,7 @@ use crate::{
GGSWExpandRows, ScratchTakeCore, GGSWExpandRows, ScratchTakeCore,
automorphism::glwe_ct::GLWEAutomorphism, automorphism::glwe_ct::GLWEAutomorphism,
layouts::{ layouts::{
GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GetAutomorphismGaloisElement, GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GetGaloisElement,
prepared::{TensorKeyPrepared, TensorKeyPreparedToRef}, 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>) pub fn automorphism<A, K, T, M, BE: Backend>(&mut self, module: &M, a: &A, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
where where
A: GGSWToRef, A: GGSWToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
T: TensorKeyPreparedToRef<BE>, T: TensorKeyPreparedToRef<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
M: GGSWAutomorphism<BE>, M: GGSWAutomorphism<BE>,
@@ -45,7 +45,7 @@ impl<D: DataMut> GGSW<D> {
pub fn automorphism_inplace<K, T, M, BE: Backend>(&mut self, module: &M, key: &K, tsk: &T, scratch: &mut Scratch<BE>) pub fn automorphism_inplace<K, T, M, BE: Backend>(&mut self, module: &M, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
where where
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
T: TensorKeyPreparedToRef<BE>, T: TensorKeyPreparedToRef<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
M: GGSWAutomorphism<BE>, M: GGSWAutomorphism<BE>,
@@ -78,7 +78,7 @@ where
where where
R: GGSWToMut, R: GGSWToMut,
A: GGSWToRef, A: GGSWToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
T: TensorKeyPreparedToRef<BE>, T: TensorKeyPreparedToRef<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
@@ -103,7 +103,7 @@ where
fn ggsw_automorphism_inplace<R, K, T>(&self, res: &mut R, key: &K, tsk: &T, scratch: &mut Scratch<BE>) fn ggsw_automorphism_inplace<R, K, T>(&self, res: &mut R, key: &K, tsk: &T, scratch: &mut Scratch<BE>)
where where
R: GGSWToMut, R: GGSWToMut,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
T: TensorKeyPreparedToRef<BE>, T: TensorKeyPreparedToRef<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {

View File

@@ -8,9 +8,7 @@ use poulpy_hal::{
use crate::{ use crate::{
GLWEKeyswitch, ScratchTakeCore, keyswitch_internal, GLWEKeyswitch, ScratchTakeCore, keyswitch_internal,
layouts::{ layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos},
GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, prepared::GetAutomorphismGaloisElement,
},
}; };
impl GLWE<Vec<u8>> { impl GLWE<Vec<u8>> {
@@ -30,7 +28,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism(self, a, key, scratch); module.glwe_automorphism(self, a, key, scratch);
@@ -40,7 +38,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism_add(self, a, key, scratch); module.glwe_automorphism_add(self, a, key, scratch);
@@ -50,7 +48,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism_sub(self, a, key, scratch); module.glwe_automorphism_sub(self, a, key, scratch);
@@ -60,7 +58,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism_sub_negate(self, a, key, scratch); module.glwe_automorphism_sub_negate(self, a, key, scratch);
@@ -69,7 +67,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
pub fn automorphism_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) pub fn automorphism_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>)
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism_inplace(self, key, scratch); module.glwe_automorphism_inplace(self, key, scratch);
@@ -78,7 +76,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
pub fn automorphism_add_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) pub fn automorphism_add_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>)
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism_add_inplace(self, key, scratch); module.glwe_automorphism_add_inplace(self, key, scratch);
@@ -87,7 +85,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
pub fn automorphism_sub_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) pub fn automorphism_sub_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>)
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism_sub_inplace(self, key, scratch); module.glwe_automorphism_sub_inplace(self, key, scratch);
@@ -96,7 +94,7 @@ impl<DataSelf: DataMut> GLWE<DataSelf> {
pub fn automorphism_sub_negate_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>) pub fn automorphism_sub_negate_inplace<M, K, BE: Backend>(&mut self, module: &M, key: &K, scratch: &mut Scratch<BE>)
where where
M: GLWEAutomorphism<BE>, M: GLWEAutomorphism<BE>,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
module.glwe_automorphism_sub_negate_inplace(self, key, scratch); module.glwe_automorphism_sub_negate_inplace(self, key, scratch);
@@ -124,7 +122,7 @@ where
where where
R: GLWEToMut, R: GLWEToMut,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
self.glwe_keyswitch(res, a, key, scratch); self.glwe_keyswitch(res, a, key, scratch);
@@ -139,7 +137,7 @@ where
fn glwe_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) fn glwe_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
where where
R: GLWEToMut, R: GLWEToMut,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
self.glwe_keyswitch_inplace(res, key, scratch); self.glwe_keyswitch_inplace(res, key, scratch);
@@ -155,7 +153,7 @@ where
where where
R: GLWEToMut, R: GLWEToMut,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
@@ -182,7 +180,7 @@ where
fn glwe_automorphism_add_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) fn glwe_automorphism_add_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
where where
R: GLWEToMut, R: GLWEToMut,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
@@ -209,7 +207,7 @@ where
where where
R: GLWEToMut, R: GLWEToMut,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
@@ -237,7 +235,7 @@ where
where where
R: GLWEToMut, R: GLWEToMut,
A: GLWEToRef, A: GLWEToRef,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
@@ -264,7 +262,7 @@ where
fn glwe_automorphism_sub_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) fn glwe_automorphism_sub_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
where where
R: GLWEToMut, R: GLWEToMut,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
@@ -290,7 +288,7 @@ where
fn glwe_automorphism_sub_negate_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>) fn glwe_automorphism_sub_negate_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
where where
R: GLWEToMut, R: GLWEToMut,
K: GetAutomorphismGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos, K: GetGaloisElement + GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();

View File

@@ -85,7 +85,7 @@ where
rank: Rank(1), 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.glwe_keyswitch(&mut tmp_glwe, a, key, scratch_1);
self.lwe_sample_extract(res, &tmp_glwe); self.lwe_sample_extract(res, &tmp_glwe);
} }

View File

@@ -50,7 +50,7 @@ where
assert_eq!(ksk.n(), self.n() as u32); assert_eq!(ksk.n(), self.n() as u32);
assert!(lwe.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, self,
&GLWELayout { &GLWELayout {
n: ksk.n(), n: ksk.n(),

View File

@@ -1,5 +1,5 @@
mod glwe_ct; mod glwe;
mod lwe_ct; mod lwe;
pub use glwe_ct::*; pub use glwe::*;
pub use lwe_ct::*; pub use lwe::*;

View File

@@ -6,10 +6,7 @@ use poulpy_hal::{
use crate::{ use crate::{
ScratchTakeCore, ScratchTakeCore,
encryption::{ encryption::{GLWEEncryptSk, GLWEEncryptSkInternal, SIGMA},
SIGMA,
glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal},
},
layouts::{ layouts::{
GGLWECompressedSeedMut, GGLWEInfos, GLWEPlaintext, GLWESecretPrepared, LWEInfos, GGLWECompressedSeedMut, GGLWEInfos, GLWEPlaintext, GLWESecretPrepared, LWEInfos,
compressed::{GGLWECompressed, GGLWECompressedToMut}, compressed::{GGLWECompressed, GGLWECompressedToMut},
@@ -145,7 +142,7 @@ where
let mut source_xa = Source::new(seed); 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 col_i in 0..rank_in {
for d_i in 0..dnum { for d_i in 0..dnum {
// Adds the scalar_znx_pt to the i-th limb of the vec_znx_pt // Adds the scalar_znx_pt to the i-th limb of the vec_znx_pt

View File

@@ -6,7 +6,7 @@ use poulpy_hal::{
use crate::{ use crate::{
ScratchTakeCore, ScratchTakeCore,
encryption::{SIGMA, ggsw_ct::GGSWEncryptSk, glwe_ct::GLWEEncryptSkInternal}, encryption::{GGSWEncryptSk, GLWEEncryptSkInternal, SIGMA},
layouts::{ layouts::{
GGSWCompressedSeedMut, GGSWInfos, GLWEInfos, LWEInfos, GGSWCompressedSeedMut, GGSWInfos, GLWEInfos, LWEInfos,
compressed::{GGSWCompressed, GGSWCompressedToMut}, compressed::{GGSWCompressed, GGSWCompressedToMut},
@@ -107,7 +107,7 @@ where
println!("res.seed: {:?}", res.seed); 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); let mut source = Source::new(seed_xa);

View File

@@ -7,12 +7,12 @@ use poulpy_hal::{
use crate::{ use crate::{
GGLWECompressedEncryptSk, ScratchTakeCore, GGLWECompressedEncryptSk, ScratchTakeCore,
layouts::{ layouts::{
GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepare, GLWESecretPrepared, GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared,
GLWESecretPreparedAlloc, GLWESecretToRef, LWEInfos, SetAutomorphismGaloisElement, compressed::AutomorphismKeyCompressed, 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 pub fn encrypt_sk_tmp_bytes<M, BE: Backend, A>(module: &M, infos: &A) -> usize
where where
A: GGLWEInfos, A: GGLWEInfos,
@@ -22,7 +22,7 @@ impl AutomorphismKeyCompressed<Vec<u8>> {
} }
} }
impl<DataSelf: DataMut> AutomorphismKeyCompressed<DataSelf> { impl<DataSelf: DataMut> GLWEAutomorphismKeyCompressed<DataSelf> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<M, S, BE: Backend>( pub fn encrypt_sk<M, S, BE: Backend>(
&mut self, &mut self,
@@ -54,18 +54,13 @@ pub trait AutomorphismKeyCompressedEncryptSk<BE: Backend> {
source_xe: &mut Source, source_xe: &mut Source,
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetAutomorphismGaloisElement + GGLWEInfos, R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos,
S: GLWESecretToRef + GLWEInfos; S: GLWESecretToRef + GLWEInfos;
} }
impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE> impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
where where
Self: ModuleN Self: ModuleN + GaloisElement + VecZnxAutomorphism + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedApi<BE>,
+ GaloisElement
+ VecZnxAutomorphism
+ GGLWECompressedEncryptSk<BE>
+ GLWESecretPreparedAlloc<BE>
+ GLWESecretPrepare<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -87,7 +82,7 @@ where
source_xe: &mut Source, source_xe: &mut Source,
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetAutomorphismGaloisElement + GGLWEInfos, R: GGLWECompressedToMut + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos,
S: GLWESecretToRef + GLWEInfos, S: GLWESecretToRef + GLWEInfos,
{ {
let sk: &GLWESecret<&[u8]> = &sk.to_ref(); let sk: &GLWESecret<&[u8]> = &sk.to_ref();
@@ -95,10 +90,10 @@ where
assert_eq!(res.rank_out(), res.rank_in()); assert_eq!(res.rank_out(), res.rank_in());
assert_eq!(sk.rank(), res.rank_out()); assert_eq!(sk.rank(), res.rank_out());
assert!( 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(): {} < AutomorphismKey::encrypt_sk_tmp_bytes: {}",
scratch.available(), 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()); let (mut sk_out_prepared, scratch_1) = scratch.take_glwe_secret_prepared(self, sk.rank());

View File

@@ -4,10 +4,7 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
encryption::{ encryption::{GLWEEncryptSk, GLWEEncryptSkInternal, SIGMA},
SIGMA,
glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal},
},
layouts::{ layouts::{
GLWECompressedSeedMut, GLWEInfos, GLWEPlaintextToRef, LWEInfos, GLWECompressedSeedMut, GLWEInfos, GLWEPlaintextToRef, LWEInfos,
compressed::{GLWECompressed, GLWECompressedToMut}, compressed::{GLWECompressed, GLWECompressedToMut},

View File

@@ -5,13 +5,12 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
ScratchTakeCore, GGLWECompressedEncryptSk, ScratchTakeCore,
encryption::compressed::gglwe_ct::GGLWECompressedEncryptSk,
layouts::{ layouts::{
GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GGLWECompressedSeedMut, GGLWECompressedToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef,
GLWESwitchingKeyDegreesMut, LWEInfos, GLWESwitchingKeyDegreesMut, LWEInfos,
compressed::GLWESwitchingKeyCompressed, compressed::GLWESwitchingKeyCompressed,
prepared::{GLWESecretPrepare, GLWESecretPrepared, GLWESecretPreparedAlloc}, prepared::{GLWESecretPrepared, GLWESecretPreparedApi},
}, },
}; };
@@ -65,7 +64,7 @@ pub trait GLWESwitchingKeyCompressedEncryptSk<BE: Backend> {
impl<BE: Backend> GLWESwitchingKeyCompressedEncryptSk<BE> for Module<BE> impl<BE: Backend> GLWESwitchingKeyCompressedEncryptSk<BE> for Module<BE>
where where
Self: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing, Self: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedApi<BE> + VecZnxSwitchRing,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize

View File

@@ -8,15 +8,14 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
GGLWECompressedEncryptSk, GetDistribution, ScratchTakeCore, GGLWECompressedEncryptSk, GetDistribution, ScratchTakeCore, TensorKeyEncryptSk,
encryption::gglwe_tsk::TensorKeyEncryptSk,
layouts::{ layouts::{
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedAlloc, GLWESecretToRef, LWEInfos, Rank, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedApi, GLWESecretToRef, LWEInfos, Rank,
TensorKeyCompressedAtMut, compressed::TensorKeyCompressed, 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 pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
where where
A: GGLWEInfos, A: GGLWEInfos,
@@ -26,7 +25,7 @@ impl TensorKeyCompressed<Vec<u8>> {
} }
} }
impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> { impl<DataSelf: DataMut> GLWETensorKeyCompressed<DataSelf> {
pub fn encrypt_sk<S, M, BE: Backend>( pub fn encrypt_sk<S, M, BE: Backend>(
&mut self, &mut self,
module: &M, module: &M,
@@ -73,7 +72,7 @@ where
+ SvpPPolBytesOf + SvpPPolBytesOf
+ VecZnxDftBytesOf + VecZnxDftBytesOf
+ VecZnxBigBytesOf + VecZnxBigBytesOf
+ GLWESecretPreparedAlloc<BE>, + GLWESecretPreparedApi<BE>,
Scratch<BE>: ScratchTakeBasic + ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeBasic + ScratchTakeCore<BE>,
{ {
fn tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize fn tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize

View File

@@ -1,13 +1,13 @@
mod gglwe_atk; mod gglwe;
mod gglwe_ct; mod ggsw;
mod gglwe_ksk; mod glwe_automorphism_key;
mod gglwe_tsk;
mod ggsw_ct;
mod glwe_ct; mod glwe_ct;
mod glwe_switching_key;
mod glwe_tensor_key;
pub use gglwe_atk::*; pub use gglwe::*;
pub use gglwe_ct::*; pub use ggsw::*;
pub use gglwe_ksk::*; pub use glwe_automorphism_key::*;
pub use gglwe_tsk::*;
pub use ggsw_ct::*;
pub use glwe_ct::*; pub use glwe_ct::*;
pub use glwe_switching_key::*;
pub use glwe_tensor_key::*;

View File

@@ -5,8 +5,7 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
ScratchTakeCore, GLWEEncryptSk, ScratchTakeCore,
encryption::glwe_ct::GLWEEncryptSk,
layouts::GLWEInfos, layouts::GLWEInfos,
layouts::{ layouts::{
GGLWE, GGLWEInfos, GGLWEToMut, GLWEPlaintext, LWEInfos, GGLWE, GGLWEInfos, GGLWEToMut, GLWEPlaintext, LWEInfos,
@@ -144,7 +143,7 @@ where
let base2k: usize = res.base2k().into(); let base2k: usize = res.base2k().into();
let rank_in: usize = res.rank_in().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 // For each input column (i.e. rank) produces a GGLWE of rank_out+1 columns
// //
// Example for ksk rank 2 to rank 3: // Example for ksk rank 2 to rank 3:

View File

@@ -5,8 +5,7 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
SIGMA, ScratchTakeCore, GLWEEncryptSk, GLWEEncryptSkInternal, SIGMA, ScratchTakeCore,
encryption::glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal},
layouts::{ layouts::{
GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GLWEPlaintext, LWEInfos, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GLWEPlaintext, LWEInfos,
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
@@ -110,7 +109,7 @@ where
let dsize: usize = res.dsize().into(); let dsize: usize = res.dsize().into();
let cols: usize = (rank + 1).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() { for row_i in 0..res.dnum().into() {
tmp_pt.data.zero(); tmp_pt.data.zero();

View File

@@ -10,12 +10,12 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
ScratchTakeCore, GetDistribution, ScratchTakeCore,
dist::Distribution, dist::Distribution,
encryption::{SIGMA, SIGMA_BOUND}, encryption::{SIGMA, SIGMA_BOUND},
layouts::{ layouts::{
GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, GLWEToMut, LWEInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, GLWEPrepared, GLWEPreparedToRef, GLWEToMut, LWEInfos,
prepared::{GLWEPublicKeyPrepared, GLWEPublicKeyPreparedToRef, GLWESecretPrepared, GLWESecretPreparedToRef}, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
}, },
}; };
@@ -80,7 +80,7 @@ impl<D: DataMut> GLWE<D> {
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
P: GLWEPlaintextToRef + GLWEInfos, P: GLWEPlaintextToRef + GLWEInfos,
K: GLWEPublicKeyPreparedToRef<BE>, K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos,
M: GLWEEncryptPk<BE>, M: GLWEEncryptPk<BE>,
{ {
module.glwe_encrypt_pk(self, pt, pk, source_xu, source_xe, scratch); module.glwe_encrypt_pk(self, pt, pk, source_xu, source_xe, scratch);
@@ -94,7 +94,7 @@ impl<D: DataMut> GLWE<D> {
source_xe: &mut Source, source_xe: &mut Source,
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
K: GLWEPublicKeyPreparedToRef<BE>, K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos,
M: GLWEEncryptPk<BE>, M: GLWEEncryptPk<BE>,
{ {
module.glwe_encrypt_zero_pk(self, pk, source_xu, source_xe, scratch); module.glwe_encrypt_zero_pk(self, pk, source_xu, source_xe, scratch);
@@ -246,7 +246,7 @@ pub trait GLWEEncryptPk<BE: Backend> {
) where ) where
R: GLWEToMut, R: GLWEToMut,
P: GLWEPlaintextToRef + GLWEInfos, P: GLWEPlaintextToRef + GLWEInfos,
K: GLWEPublicKeyPreparedToRef<BE>; K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos;
fn glwe_encrypt_zero_pk<R, K>( fn glwe_encrypt_zero_pk<R, K>(
&self, &self,
@@ -257,7 +257,7 @@ pub trait GLWEEncryptPk<BE: Backend> {
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
R: GLWEToMut, R: GLWEToMut,
K: GLWEPublicKeyPreparedToRef<BE>; K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos;
} }
impl<BE: Backend> GLWEEncryptPk<BE> for Module<BE> impl<BE: Backend> GLWEEncryptPk<BE> for Module<BE>
@@ -286,7 +286,7 @@ where
) where ) where
R: GLWEToMut, R: GLWEToMut,
P: GLWEPlaintextToRef + GLWEInfos, 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); self.glwe_encrypt_pk_internal(res, Some((pt, 0)), pk, source_xu, source_xe, scratch);
} }
@@ -300,7 +300,7 @@ where
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
R: GLWEToMut, R: GLWEToMut,
K: GLWEPublicKeyPreparedToRef<BE>, K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos,
{ {
self.glwe_encrypt_pk_internal( self.glwe_encrypt_pk_internal(
res, res,
@@ -325,7 +325,7 @@ pub(crate) trait GLWEEncryptPkInternal<BE: Backend> {
) where ) where
R: GLWEToMut, R: GLWEToMut,
P: GLWEPlaintextToRef + GLWEInfos, P: GLWEPlaintextToRef + GLWEInfos,
K: GLWEPublicKeyPreparedToRef<BE>; K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos;
} }
impl<BE: Backend> GLWEEncryptPkInternal<BE> for Module<BE> impl<BE: Backend> GLWEEncryptPkInternal<BE> for Module<BE>
@@ -352,10 +352,9 @@ where
) where ) where
R: GLWEToMut, R: GLWEToMut,
P: GLWEPlaintextToRef + GLWEInfos, P: GLWEPlaintextToRef + GLWEInfos,
K: GLWEPublicKeyPreparedToRef<BE>, K: GLWEPreparedToRef<BE> + GetDistribution + GLWEInfos,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); 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.base2k(), pk.base2k());
assert_eq!(res.n(), pk.n()); assert_eq!(res.n(), pk.n());
@@ -374,24 +373,27 @@ where
{ {
let (mut u, _) = scratch_1.take_scalar_znx(self, 1); let (mut u, _) = scratch_1.take_scalar_znx(self, 1);
match pk.dist { match pk.dist() {
Distribution::NONE => panic!( Distribution::NONE => panic!(
"invalid public key: SecretDistribution::NONE, ensure it has been correctly intialized through \ "invalid public key: SecretDistribution::NONE, ensure it has been correctly intialized through \
Self::generate" Self::generate"
), ),
Distribution::TernaryFixed(hw) => u.fill_ternary_hw(0, hw, 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::TernaryProb(prob) => u.fill_ternary_prob(0, *prob, source_xu),
Distribution::BinaryFixed(hw) => u.fill_binary_hw(0, hw, 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::BinaryProb(prob) => u.fill_binary_prob(0, *prob, source_xu),
Distribution::BinaryBlock(block_size) => u.fill_binary_block(0, block_size, source_xu), Distribution::BinaryBlock(block_size) => u.fill_binary_block(0, *block_size, source_xu),
Distribution::ZERO => {} Distribution::ZERO => {}
} }
self.svp_prepare(&mut u_dft, 0, &u, 0); self.svp_prepare(&mut u_dft, 0, &u, 0);
} }
{
let pk: &GLWEPrepared<&[u8], BE> = &pk.to_ref();
// ct[i] = pk[i] * u + ei (+ m if col = i) // ct[i] = pk[i] * u + ei (+ m if col = i)
(0..cols).for_each(|i| { for i in 0..cols {
let (mut ci_dft, scratch_2) = scratch_1.take_vec_znx_dft(self, 1, size_pk); let (mut ci_dft, scratch_2) = scratch_1.take_vec_znx_dft(self, 1, size_pk);
// ci_dft = DFT(u) * DFT(pk[i]) // ci_dft = DFT(u) * DFT(pk[i])
self.svp_apply_dft_to_dft(&mut ci_dft, 0, &u_dft, 0, &pk.data, i); self.svp_apply_dft_to_dft(&mut ci_dft, 0, &u_dft, 0, &pk.data, i);
@@ -419,7 +421,8 @@ where
// ct[i] = norm(ci_big) // ct[i] = norm(ci_big)
self.vec_znx_big_normalize(base2k, &mut res.data, i, base2k, &ci_big, 0, scratch_2); self.vec_znx_big_normalize(base2k, &mut res.data, i, base2k, &ci_big, 0, scratch_2);
}); }
}
} }
} }

View File

@@ -7,8 +7,8 @@ use poulpy_hal::{
use crate::{ use crate::{
GGLWEEncryptSk, ScratchTakeCore, GGLWEEncryptSk, ScratchTakeCore,
layouts::{ layouts::{
AutomorphismKey, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESecret, GLWESecretPrepare, GLWESecretPrepared, AutomorphismKey, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESecret, GLWESecretPrepared, GLWESecretPreparedApi,
GLWESecretPreparedAlloc, GLWESecretToRef, LWEInfos, SetAutomorphismGaloisElement, GLWESecretToRef, LWEInfos, SetGaloisElement,
}, },
}; };
@@ -64,18 +64,13 @@ pub trait AutomorphismKeyEncryptSk<BE: Backend> {
source_xe: &mut Source, source_xe: &mut Source,
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
R: GGLWEToMut + SetAutomorphismGaloisElement + GGLWEInfos, R: GGLWEToMut + SetGaloisElement + GGLWEInfos,
S: GLWESecretToRef; S: GLWESecretToRef;
} }
impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE> impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE>
where where
Self: GGLWEEncryptSk<BE> Self: GGLWEEncryptSk<BE> + VecZnxAutomorphism + GaloisElement + SvpPPolBytesOf + GLWESecretPreparedApi<BE>,
+ VecZnxAutomorphism
+ GaloisElement
+ SvpPPolBytesOf
+ GLWESecretPrepare<BE>
+ GLWESecretPreparedAlloc<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -102,7 +97,7 @@ where
source_xe: &mut Source, source_xe: &mut Source,
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
R: GGLWEToMut + SetAutomorphismGaloisElement + GGLWEInfos, R: GGLWEToMut + SetGaloisElement + GGLWEInfos,
S: GLWESecretToRef, S: GLWESecretToRef,
{ {
let sk: &GLWESecret<&[u8]> = &sk.to_ref(); let sk: &GLWESecret<&[u8]> = &sk.to_ref();

View File

@@ -5,10 +5,9 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
Distribution, GetDistribution, GetDistributionMut, ScratchTakeCore, Distribution, GLWEEncryptSk, GetDistribution, GetDistributionMut, ScratchTakeCore,
encryption::glwe_ct::GLWEEncryptSk,
layouts::{ layouts::{
GLWE, GLWEPublicKey, GLWEPublicKeyToMut, LWEInfos, GLWE, GLWEInfos, GLWEPublicKey, GLWEToMut,
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
}, },
}; };
@@ -26,7 +25,7 @@ impl<D: DataMut> GLWEPublicKey<D> {
pub trait GLWEPublicKeyGenerate<BE: Backend> { 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) fn glwe_public_key_generate<R, S>(&self, res: &mut R, sk: &S, source_xa: &mut Source, source_xe: &mut Source)
where where
R: GLWEPublicKeyToMut + GetDistributionMut, R: GLWEToMut + GetDistributionMut + GLWEInfos,
S: GLWESecretPreparedToRef<BE> + GetDistribution; S: GLWESecretPreparedToRef<BE> + GetDistribution;
} }
@@ -38,11 +37,10 @@ where
{ {
fn glwe_public_key_generate<R, S>(&self, res: &mut R, sk: &S, source_xa: &mut Source, source_xe: &mut Source) fn glwe_public_key_generate<R, S>(&self, res: &mut R, sk: &S, source_xa: &mut Source, source_xe: &mut Source)
where where
R: GLWEPublicKeyToMut + GetDistributionMut, R: GLWEToMut + GetDistributionMut + GLWEInfos,
S: GLWESecretPreparedToRef<BE> + GetDistribution, S: GLWESecretPreparedToRef<BE> + GetDistribution,
{ {
{ {
let res: &mut GLWEPublicKey<&mut [u8]> = &mut res.to_mut();
let sk: &GLWESecretPrepared<&[u8], BE> = &sk.to_ref(); let sk: &GLWESecretPrepared<&[u8], BE> = &sk.to_ref();
assert_eq!(res.n(), self.n() as u32); assert_eq!(res.n(), self.n() as u32);

View File

@@ -6,10 +6,10 @@ use poulpy_hal::{
use crate::{ use crate::{
ScratchTakeCore, ScratchTakeCore,
encryption::gglwe_ct::GGLWEEncryptSk, encryption::gglwe::GGLWEEncryptSk,
layouts::{ layouts::{
GGLWEInfos, GGLWEToMut, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, GLWESwitchingKeyDegreesMut, LWEInfos, GGLWEInfos, GGLWEToMut, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, GLWESwitchingKeyDegreesMut, LWEInfos,
prepared::GLWESecretPreparedAlloc, prepared::GLWESecretPreparedApi,
}, },
}; };
@@ -71,7 +71,7 @@ pub trait GLWESwitchingKeyEncryptSk<BE: Backend> {
impl<BE: Backend> GLWESwitchingKeyEncryptSk<BE> for Module<BE> impl<BE: Backend> GLWESwitchingKeyEncryptSk<BE> for Module<BE>
where where
Self: ModuleN + GGLWEEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxSwitchRing + SvpPrepare<BE>, Self: ModuleN + GGLWEEncryptSk<BE> + GLWESecretPreparedApi<BE> + VecZnxSwitchRing + SvpPrepare<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
fn glwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize fn glwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize

View File

@@ -11,7 +11,7 @@ use crate::{
GGLWEEncryptSk, GetDistribution, ScratchTakeCore, GGLWEEncryptSk, GetDistribution, ScratchTakeCore,
layouts::{ layouts::{
GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey, TensorKeyToMut, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey, TensorKeyToMut,
prepared::{GLWESecretPrepare, GLWESecretPrepared, GLWESecretPreparedAlloc}, prepared::{GLWESecretPrepared, GLWESecretPreparedApi},
}, },
}; };
@@ -65,8 +65,7 @@ where
+ GGLWEEncryptSk<BE> + GGLWEEncryptSk<BE>
+ VecZnxDftBytesOf + VecZnxDftBytesOf
+ VecZnxBigBytesOf + VecZnxBigBytesOf
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ VecZnxDftApply<BE> + VecZnxDftApply<BE>
+ SvpApplyDftToDft<BE> + SvpApplyDftToDft<BE>
+ VecZnxIdftApplyTmpA<BE> + VecZnxIdftApplyTmpA<BE>

View File

@@ -7,9 +7,9 @@ use poulpy_hal::{
use crate::{ use crate::{
GGLWEEncryptSk, ScratchTakeCore, GGLWEEncryptSk, ScratchTakeCore,
layouts::{ layouts::{
GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretPrepare, GLWESecretToRef, GLWEToLWESwitchingKey, LWEInfos, GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretToRef, GLWEToLWESwitchingKey, LWEInfos, LWESecret, LWESecretToRef,
LWESecret, LWESecretToRef, Rank, Rank,
prepared::{GLWESecretPrepared, GLWESecretPreparedAlloc}, prepared::{GLWESecretPrepared, GLWESecretPreparedApi},
}, },
}; };
@@ -65,10 +65,9 @@ impl<BE: Backend> GLWEToLWESwitchingKeyEncryptSk<BE> for Module<BE>
where where
Self: ModuleN Self: ModuleN
+ GGLWEEncryptSk<BE> + GGLWEEncryptSk<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ VecZnxAutomorphismInplace<BE> + VecZnxAutomorphismInplace<BE>
+ VecZnxAutomorphismInplaceTmpBytes + VecZnxAutomorphismInplaceTmpBytes,
+ GLWESecretPrepare<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize

View File

@@ -6,11 +6,11 @@ use poulpy_hal::{
use crate::{ use crate::{
ScratchTakeCore, ScratchTakeCore,
encryption::gglwe_ksk::GLWESwitchingKeyEncryptSk, encryption::glwe_switching_key::GLWESwitchingKeyEncryptSk,
layouts::{ layouts::{
GGLWEInfos, GGLWEToMut, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyDegreesMut, LWEInfos, LWESecret, LWESecretToRef, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyDegreesMut, LWEInfos, LWESecret, LWESecretToRef,
LWESwitchingKey, Rank, LWESwitchingKey, Rank,
prepared::{GLWESecretPrepared, GLWESecretPreparedAlloc}, prepared::{GLWESecretPrepared, GLWESecretPreparedApi},
}, },
}; };
@@ -63,7 +63,7 @@ pub trait LWESwitchingKeyEncrypt<BE: Backend> {
impl<BE: Backend> LWESwitchingKeyEncrypt<BE> for Module<BE> impl<BE: Backend> LWESwitchingKeyEncrypt<BE> for Module<BE>
where where
Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>, Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedApi<BE> + VecZnxAutomorphismInplace<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
fn lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize fn lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize

View File

@@ -7,7 +7,7 @@ use poulpy_hal::{
use crate::{ use crate::{
GGLWEEncryptSk, ScratchTakeCore, GGLWEEncryptSk, ScratchTakeCore,
layouts::{ layouts::{
GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretPreparedAlloc, GLWESecretPreparedToRef, LWEInfos, LWESecret, GGLWE, GGLWEInfos, GGLWEToMut, GLWESecret, GLWESecretPreparedApi, GLWESecretPreparedToRef, LWEInfos, LWESecret,
LWESecretToRef, LWEToGLWESwitchingKey, Rank, LWESecretToRef, LWEToGLWESwitchingKey, Rank,
}, },
}; };
@@ -65,7 +65,7 @@ where
Self: ModuleN Self: ModuleN
+ GGLWEEncryptSk<BE> + GGLWEEncryptSk<BE>
+ VecZnxAutomorphismInplace<BE> + VecZnxAutomorphismInplace<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ VecZnxAutomorphismInplaceTmpBytes, + VecZnxAutomorphismInplaceTmpBytes,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {

View File

@@ -1,28 +1,28 @@
mod compressed; mod compressed;
mod gglwe_atk; mod gglwe;
mod gglwe_ct; mod ggsw;
mod gglwe_ksk; mod glwe;
mod gglwe_tsk; mod glwe_automorphism_key;
mod ggsw_ct; mod glwe_public_key;
mod glwe_ct; mod glwe_switching_key;
mod glwe_pk; mod glwe_tensor_key;
mod glwe_to_lwe_ksk; mod glwe_to_lwe_switching_key;
mod lwe_ct; mod lwe;
mod lwe_ksk; mod lwe_switching_key;
mod lwe_to_glwe_ksk; mod lwe_to_glwe_switching_key;
pub use compressed::*; pub use compressed::*;
pub use gglwe_atk::*; pub use gglwe::*;
pub use gglwe_ct::*; pub use ggsw::*;
pub use gglwe_ksk::*; pub use glwe::*;
pub use gglwe_tsk::*; pub use glwe_automorphism_key::*;
pub use ggsw_ct::*; pub use glwe_public_key::*;
pub use glwe_ct::*; pub use glwe_switching_key::*;
pub use glwe_pk::*; pub use glwe_tensor_key::*;
pub use glwe_to_lwe_ksk::*; pub use glwe_to_lwe_switching_key::*;
pub use lwe_ct::*; pub use lwe::*;
pub use lwe_ksk::*; pub use lwe_switching_key::*;
pub use lwe_to_glwe_ksk::*; pub use lwe_to_glwe_switching_key::*;
pub const SIGMA: f64 = 3.2; pub const SIGMA: f64 = 3.2;
pub(crate) const SIGMA_BOUND: f64 = 6.0 * SIGMA; pub(crate) const SIGMA_BOUND: f64 = 6.0 * SIGMA;

View File

@@ -3,11 +3,50 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, ZnxZero};
use crate::{ use crate::{
GLWEExternalProduct, ScratchTakeCore, GLWEExternalProduct, ScratchTakeCore,
layouts::{ layouts::{
GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GLWEInfos, GLWESwitchingKey, AutomorphismKey, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GGSWInfos, GGSWPrepared, GLWEInfos, GLWESwitchingKey,
prepared::{GGSWPrepared, GGSWPreparedToRef}, 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> pub trait GGLWEExternalProduct<BE: Backend>
where where
Self: GLWEExternalProduct<BE>, Self: GLWEExternalProduct<BE>,

View File

@@ -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);
}
}

View File

@@ -1,8 +1,7 @@
mod gglwe_atk; mod gglwe;
mod gglwe_ksk; mod ggsw;
mod ggsw_ct; mod glwe;
mod glwe_ct;
pub use gglwe_ksk::*; pub use gglwe::*;
pub use ggsw_ct::*; pub use ggsw::*;
pub use glwe_ct::*; pub use glwe::*;

View File

@@ -8,9 +8,7 @@ use poulpy_hal::{
use crate::{ use crate::{
GLWEAdd, GLWEAutomorphism, GLWECopy, GLWENormalize, GLWERotate, GLWEShift, GLWESub, ScratchTakeCore, GLWEAdd, GLWEAutomorphism, GLWECopy, GLWENormalize, GLWERotate, GLWEShift, GLWESub, ScratchTakeCore,
glwe_trace::GLWETrace, glwe_trace::GLWETrace,
layouts::{ layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos},
GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, prepared::GetAutomorphismGaloisElement,
},
}; };
/// [GLWEPacker] enables only the fly GLWE packing /// [GLWEPacker] enables only the fly GLWE packing
@@ -117,7 +115,7 @@ impl GLWEPacker {
pub fn add<A, K, M, BE: Backend>(&mut self, module: &M, a: Option<&A>, auto_keys: &HashMap<i64, K>, scratch: &mut Scratch<BE>) 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 where
A: GLWEToRef + GLWEInfos, A: GLWEToRef + GLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
M: GLWEPacking<BE>, M: GLWEPacking<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
@@ -190,7 +188,7 @@ where
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
R: GLWEToMut + GLWEToRef + GLWEInfos, R: GLWEToMut + GLWEToRef + GLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
@@ -234,7 +232,7 @@ fn pack_core<A, K, M, BE: Backend>(
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
A: GLWEToRef + GLWEInfos, A: GLWEToRef + GLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
M: ModuleLogN M: ModuleLogN
+ GLWEAutomorphism<BE> + GLWEAutomorphism<BE>
+ GaloisElement + GaloisElement
@@ -307,7 +305,7 @@ fn combine<B, M, K, BE: Backend>(
B: GLWEToRef + GLWEInfos, B: GLWEToRef + GLWEInfos,
M: GLWEAutomorphism<BE> + GaloisElement + GLWERotate<BE> + GLWESub + GLWEShift<BE> + GLWEAdd + GLWENormalize<BE>, M: GLWEAutomorphism<BE> + GaloisElement + GLWERotate<BE> + GLWESub + GLWEShift<BE> + GLWEAdd + GLWENormalize<BE>,
B: GLWEToRef + GLWEInfos, B: GLWEToRef + GLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let log_n: usize = acc.data.n().log2(); let log_n: usize = acc.data.n().log2();
@@ -333,7 +331,7 @@ fn combine<B, M, K, BE: Backend>(
// since 2*(I(X) * Q/2) = I(X) * Q = 0 mod Q. // since 2*(I(X) * Q/2) = I(X) * Q = 0 mod Q.
if acc.value { if acc.value {
if let Some(b) = b { 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 // a = a * X^-t
module.glwe_rotate_inplace(-t, a, scratch_1); module.glwe_rotate_inplace(-t, a, scratch_1);
@@ -373,7 +371,7 @@ fn combine<B, M, K, BE: Backend>(
} }
} }
} else if let Some(b) = b { } 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_rotate(t, &mut tmp_b, b);
module.glwe_rsh(1, &mut tmp_b, scratch_1); module.glwe_rsh(1, &mut tmp_b, scratch_1);
@@ -400,7 +398,7 @@ fn pack_internal<M, A, B, K, BE: Backend>(
M: GLWEAutomorphism<BE> + GLWERotate<BE> + GLWESub + GLWEShift<BE> + GLWEAdd + GLWENormalize<BE>, M: GLWEAutomorphism<BE> + GLWERotate<BE> + GLWESub + GLWEShift<BE> + GLWEAdd + GLWENormalize<BE>,
A: GLWEToMut + GLWEToRef + GLWEInfos, A: GLWEToMut + GLWEToRef + GLWEInfos,
B: GLWEToMut + GLWEToRef + GLWEInfos, B: GLWEToMut + GLWEToRef + GLWEInfos,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
// Goal is to evaluate: a = a + b*X^t + phi(a - b*X^t)) // Goal is to evaluate: a = a + b*X^t + phi(a - b*X^t))
@@ -417,7 +415,7 @@ fn pack_internal<M, A, B, K, BE: Backend>(
let t: i64 = 1 << (a.n().log2() - i - 1); let t: i64 = 1 << (a.n().log2() - i - 1);
if let Some(b) = b.as_deref_mut() { 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 // a = a * X^-t
module.glwe_rotate_inplace(-t, a, scratch_1); module.glwe_rotate_inplace(-t, a, scratch_1);
@@ -451,7 +449,7 @@ fn pack_internal<M, A, B, K, BE: Backend>(
} else if let Some(b) = b.as_deref_mut() { } else if let Some(b) = b.as_deref_mut() {
let t: i64 = 1 << (b.n().log2() - i - 1); 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_rotate(t, &mut tmp_b, b);
module.glwe_rsh(1, &mut tmp_b, scratch_1); module.glwe_rsh(1, &mut tmp_b, scratch_1);

View File

@@ -8,8 +8,7 @@ use poulpy_hal::{
use crate::{ use crate::{
GLWEAutomorphism, GLWECopy, GLWEShift, ScratchTakeCore, GLWEAutomorphism, GLWECopy, GLWEShift, ScratchTakeCore,
layouts::{ layouts::{
Base2K, GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWELayout, GLWEToMut, GLWEToRef, LWEInfos, Base2K, GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWELayout, GLWEToMut, GLWEToRef, GetGaloisElement, LWEInfos,
prepared::GetAutomorphismGaloisElement,
}, },
}; };
@@ -43,7 +42,7 @@ impl<D: DataMut> GLWE<D> {
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
A: GLWEToRef, A: GLWEToRef,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
M: GLWETrace<BE>, M: GLWETrace<BE>,
{ {
@@ -58,7 +57,7 @@ impl<D: DataMut> GLWE<D> {
keys: &HashMap<i64, K>, keys: &HashMap<i64, K>,
scratch: &mut Scratch<BE>, scratch: &mut Scratch<BE>,
) where ) where
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
M: GLWETrace<BE>, M: GLWETrace<BE>,
{ {
@@ -110,7 +109,7 @@ where
where where
R: GLWEToMut, R: GLWEToMut,
A: GLWEToRef, A: GLWEToRef,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
self.glwe_copy(res, a); self.glwe_copy(res, a);
@@ -120,7 +119,7 @@ where
fn glwe_trace_inplace<R, K>(&self, res: &mut R, start: usize, end: usize, keys: &HashMap<i64, K>, scratch: &mut Scratch<BE>) fn glwe_trace_inplace<R, K>(&self, res: &mut R, start: usize, end: usize, keys: &HashMap<i64, K>, scratch: &mut Scratch<BE>)
where where
R: GLWEToMut, R: GLWEToMut,
K: GGLWEPreparedToRef<BE> + GetAutomorphismGaloisElement + GGLWEInfos, K: GGLWEPreparedToRef<BE> + GetGaloisElement + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
@@ -141,7 +140,7 @@ where
} }
if res.base2k() != basek_ksk { 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, self,
&GLWELayout { &GLWELayout {
n: self.n().into(), n: self.n().into(),

View File

@@ -2,7 +2,7 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch};
use crate::{ use crate::{
ScratchTakeCore, ScratchTakeCore,
keyswitching::glwe_ct::GLWEKeyswitch, keyswitching::GLWEKeyswitch,
layouts::{AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWESwitchingKey}, layouts::{AutomorphismKey, GGLWE, GGLWEInfos, GGLWEPreparedToRef, GGLWEToMut, GGLWEToRef, GLWESwitchingKey},
}; };

View File

@@ -2,7 +2,7 @@ use poulpy_hal::layouts::{Backend, DataMut, Module, Scratch, VecZnx};
use crate::{ use crate::{
GGSWExpandRows, ScratchTakeCore, GGSWExpandRows, ScratchTakeCore,
keyswitching::glwe_ct::GLWEKeyswitch, keyswitching::GLWEKeyswitch,
layouts::{GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, prepared::TensorKeyPreparedToRef}, layouts::{GGLWEInfos, GGLWEPreparedToRef, GGSW, GGSWInfos, GGSWToMut, GGSWToRef, prepared::TensorKeyPreparedToRef},
}; };

View File

@@ -5,7 +5,7 @@ use poulpy_hal::{
use crate::{ use crate::{
LWESampleExtract, ScratchTakeCore, LWESampleExtract, ScratchTakeCore,
keyswitching::glwe_ct::GLWEKeyswitch, keyswitching::GLWEKeyswitch,
layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWELayout, LWE, LWEInfos, LWEToMut, LWEToRef, Rank, TorusPrecision}, layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWELayout, LWE, LWEInfos, LWEToMut, LWEToRef, Rank, TorusPrecision},
}; };
@@ -87,7 +87,7 @@ where
let a_size: usize = a.k().div_ceil(ksk.base2k()) as usize; 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, self,
&GLWELayout { &GLWELayout {
n: ksk.n(), n: ksk.n(),
@@ -98,7 +98,7 @@ where
); );
glwe_in.data.zero(); 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, self,
&GLWELayout { &GLWELayout {
n: ksk.n(), n: ksk.n(),

View File

@@ -1,9 +1,9 @@
mod gglwe_ct; mod gglwe;
mod ggsw_ct; mod ggsw;
mod glwe_ct; mod glwe;
mod lwe_ct; mod lwe;
pub use gglwe_ct::*; pub use gglwe::*;
pub use ggsw_ct::*; pub use ggsw::*;
pub use glwe_ct::*; pub use glwe::*;
pub use lwe_ct::*; pub use lwe::*;

View File

@@ -5,26 +5,25 @@ use poulpy_hal::{
use crate::layouts::{ use crate::layouts::{
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut, AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut,
GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWECompressed, GLWECompressedToMut, GLWECompressedToRef, GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWEDecompress, GLWEInfos, GetGaloisElement, LWEInfos, Rank,
GLWEDecompress, GLWEInfos, LWEInfos, Rank, TorusPrecision, SetGaloisElement, TorusPrecision,
prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement},
}; };
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt; use std::fmt;
#[derive(PartialEq, Eq, Clone)] #[derive(PartialEq, Eq, Clone)]
pub struct AutomorphismKeyCompressed<D: Data> { pub struct GLWEAutomorphismKeyCompressed<D: Data> {
pub(crate) key: GGLWECompressed<D>, pub(crate) key: GGLWECompressed<D>,
pub(crate) p: i64, pub(crate) p: i64,
} }
impl<D: Data> GetAutomorphismGaloisElement for AutomorphismKeyCompressed<D> { impl<D: DataRef> GetGaloisElement for GLWEAutomorphismKeyCompressed<D> {
fn p(&self) -> i64 { fn p(&self) -> i64 {
self.p self.p
} }
} }
impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> { impl<D: Data> LWEInfos for GLWEAutomorphismKeyCompressed<D> {
fn n(&self) -> Degree { fn n(&self) -> Degree {
self.key.n() self.key.n()
} }
@@ -42,13 +41,13 @@ impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> {
} }
} }
impl<D: Data> GLWEInfos for AutomorphismKeyCompressed<D> { impl<D: Data> GLWEInfos for GLWEAutomorphismKeyCompressed<D> {
fn rank(&self) -> Rank { fn rank(&self) -> Rank {
self.rank_out() self.rank_out()
} }
} }
impl<D: Data> GGLWEInfos for AutomorphismKeyCompressed<D> { impl<D: Data> GGLWEInfos for GLWEAutomorphismKeyCompressed<D> {
fn rank_in(&self) -> Rank { fn rank_in(&self) -> Rank {
self.key.rank_in() self.key.rank_in()
} }
@@ -66,25 +65,25 @@ impl<D: Data> GGLWEInfos for AutomorphismKeyCompressed<D> {
} }
} }
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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{self}") 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) { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.key.fill_uniform(log_bound, 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 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "(AutomorphismKeyCompressed: p={}) {}", self.p, self.key) 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 pub fn alloc_from_infos<A>(infos: &A) -> Self
where where
A: GGLWEInfos, A: GGLWEInfos,
@@ -100,7 +99,7 @@ impl AutomorphismKeyCompressed<Vec<u8>> {
} }
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { 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), key: GGLWECompressed::alloc(n, base2k, k, rank, rank, dnum, dsize),
p: 0, p: 0,
} }
@@ -125,14 +124,14 @@ impl AutomorphismKeyCompressed<Vec<u8>> {
} }
} }
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<()> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
self.p = reader.read_u64::<LittleEndian>()? as i64; self.p = reader.read_u64::<LittleEndian>()? as i64;
self.key.read_from(reader) 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<()> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
writer.write_u64::<LittleEndian>(self.p as u64)?; writer.write_u64::<LittleEndian>(self.p as u64)?;
self.key.write_to(writer) self.key.write_to(writer)
@@ -145,8 +144,8 @@ where
{ {
fn decompress_automorphism_key<R, O>(&self, res: &mut R, other: &O) fn decompress_automorphism_key<R, O>(&self, res: &mut R, other: &O)
where where
R: GGLWEToMut + SetAutomorphismGaloisElement, R: GGLWEToMut + SetGaloisElement,
O: GGLWECompressedToRef + GetAutomorphismGaloisElement, O: GGLWECompressedToRef + GetGaloisElement,
{ {
self.decompress_gglwe(res, other); self.decompress_gglwe(res, other);
res.set_p(other.p()); res.set_p(other.p());
@@ -157,68 +156,36 @@ impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: GLWEDecompr
impl<D: DataMut> AutomorphismKey<D> impl<D: DataMut> AutomorphismKey<D>
where where
Self: SetAutomorphismGaloisElement, Self: SetGaloisElement,
{ {
pub fn decompress<O, M>(&mut self, module: &M, other: &O) pub fn decompress<O, M>(&mut self, module: &M, other: &O)
where where
O: GGLWECompressedToRef + GetAutomorphismGaloisElement, O: GGLWECompressedToRef + GetGaloisElement,
M: AutomorphismKeyDecompress, M: AutomorphismKeyDecompress,
{ {
module.decompress_automorphism_key(self, other); 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]> { fn to_ref(&self) -> GGLWECompressed<&[u8]> {
self.key.to_ref() 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]> { fn to_mut(&mut self) -> GGLWECompressed<&mut [u8]> {
self.key.to_mut() self.key.to_mut()
} }
} }
pub trait AutomorphismKeyCompressedToRef { impl<D: DataMut> GGLWECompressedSeedMut for GLWEAutomorphismKeyCompressed<D> {
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> {
fn seed_mut(&mut self) -> &mut Vec<[u8; 32]> { fn seed_mut(&mut self) -> &mut Vec<[u8; 32]> {
&mut self.key.seed &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) { fn set_p(&mut self, p: i64) {
self.p = p self.p = p
} }

View File

@@ -11,11 +11,11 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt; use std::fmt;
#[derive(PartialEq, Eq, Clone)] #[derive(PartialEq, Eq, Clone)]
pub struct TensorKeyCompressed<D: Data> { pub struct GLWETensorKeyCompressed<D: Data> {
pub(crate) keys: Vec<GGLWECompressed<D>>, pub(crate) keys: Vec<GGLWECompressed<D>>,
} }
impl<D: Data> LWEInfos for TensorKeyCompressed<D> { impl<D: Data> LWEInfos for GLWETensorKeyCompressed<D> {
fn n(&self) -> Degree { fn n(&self) -> Degree {
self.keys[0].n() self.keys[0].n()
} }
@@ -31,13 +31,13 @@ impl<D: Data> LWEInfos for TensorKeyCompressed<D> {
self.keys[0].size() self.keys[0].size()
} }
} }
impl<D: Data> GLWEInfos for TensorKeyCompressed<D> { impl<D: Data> GLWEInfos for GLWETensorKeyCompressed<D> {
fn rank(&self) -> Rank { fn rank(&self) -> Rank {
self.rank_out() self.rank_out()
} }
} }
impl<D: Data> GGLWEInfos for TensorKeyCompressed<D> { impl<D: Data> GGLWEInfos for GLWETensorKeyCompressed<D> {
fn rank_in(&self) -> Rank { fn rank_in(&self) -> Rank {
self.rank_out() self.rank_out()
} }
@@ -55,13 +55,13 @@ impl<D: Data> GGLWEInfos for TensorKeyCompressed<D> {
} }
} }
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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{self}") 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) { fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.keys self.keys
.iter_mut() .iter_mut()
@@ -69,7 +69,7 @@ impl<D: DataMut> FillUniform for TensorKeyCompressed<D> {
} }
} }
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 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "(GLWETensorKeyCompressed)",)?; writeln!(f, "(GLWETensorKeyCompressed)",)?;
for (i, key) in self.keys.iter().enumerate() { for (i, key) in self.keys.iter().enumerate() {
@@ -79,7 +79,7 @@ impl<D: DataRef> fmt::Display for TensorKeyCompressed<D> {
} }
} }
impl TensorKeyCompressed<Vec<u8>> { impl GLWETensorKeyCompressed<Vec<u8>> {
pub fn alloc_from_infos<A>(infos: &A) -> Self pub fn alloc_from_infos<A>(infos: &A) -> Self
where where
A: GGLWEInfos, A: GGLWEInfos,
@@ -96,7 +96,7 @@ impl TensorKeyCompressed<Vec<u8>> {
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self { 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); let pairs: u32 = (((rank.as_u32() + 1) * rank.as_u32()) >> 1).max(1);
TensorKeyCompressed { GLWETensorKeyCompressed {
keys: (0..pairs) keys: (0..pairs)
.map(|_| GGLWECompressed::alloc(n, base2k, k, Rank(1), rank, dnum, dsize)) .map(|_| GGLWECompressed::alloc(n, base2k, k, Rank(1), rank, dnum, dsize))
.collect(), .collect(),
@@ -123,7 +123,7 @@ impl TensorKeyCompressed<Vec<u8>> {
} }
} }
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<()> { fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
let len: usize = reader.read_u64::<LittleEndian>()? as usize; let len: usize = reader.read_u64::<LittleEndian>()? as usize;
if self.keys.len() != len { if self.keys.len() != len {
@@ -139,7 +139,7 @@ impl<D: DataMut> ReaderFrom for TensorKeyCompressed<D> {
} }
} }
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<()> { fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
writer.write_u64::<LittleEndian>(self.keys.len() as u64)?; writer.write_u64::<LittleEndian>(self.keys.len() as u64)?;
for key in &self.keys { for key in &self.keys {
@@ -153,7 +153,7 @@ pub trait TensorKeyCompressedAtRef<D: DataRef> {
fn at(&self, i: usize, j: usize) -> &GGLWECompressed<D>; 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> { fn at(&self, mut i: usize, mut j: usize) -> &GGLWECompressed<D> {
if i > j { if i > j {
std::mem::swap(&mut i, &mut 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>; 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> { fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWECompressed<D> {
if i > j { if i > j {
std::mem::swap(&mut i, &mut j); std::mem::swap(&mut i, &mut j);
@@ -187,7 +187,7 @@ where
O: TensorKeyCompressedToRef, O: TensorKeyCompressedToRef,
{ {
let res: &mut TensorKey<&mut [u8]> = &mut res.to_mut(); 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!( assert_eq!(
res.keys.len(), res.keys.len(),
@@ -216,30 +216,30 @@ impl<D: DataMut> TensorKey<D> {
} }
pub trait TensorKeyCompressedToMut { 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 where
GGLWECompressed<D>: GGLWECompressedToMut, GGLWECompressed<D>: GGLWECompressedToMut,
{ {
fn to_mut(&mut self) -> TensorKeyCompressed<&mut [u8]> { fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]> {
TensorKeyCompressed { GLWETensorKeyCompressed {
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(), keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
} }
} }
} }
pub trait TensorKeyCompressedToRef { 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 where
GGLWECompressed<D>: GGLWECompressedToRef, GGLWECompressed<D>: GGLWECompressedToRef,
{ {
fn to_ref(&self) -> TensorKeyCompressed<&[u8]> { fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]> {
TensorKeyCompressed { GLWETensorKeyCompressed {
keys: self.keys.iter().map(|c| c.to_ref()).collect(), keys: self.keys.iter().map(|c| c.to_ref()).collect(),
} }
} }

View File

@@ -1,21 +1,21 @@
mod gglwe_atk; mod gglwe;
mod gglwe_ct; mod ggsw;
mod gglwe_ksk; mod glwe;
mod gglwe_tsk; mod glwe_automorphism_key;
mod ggsw_ct; mod glwe_switching_key;
mod glwe_ct; mod glwe_tensor_key;
mod glwe_to_lwe_ksk; mod glwe_to_lwe_switching_key;
mod lwe_ct; mod lwe;
mod lwe_ksk; mod lwe_switching_key;
mod lwe_to_glwe_ksk; mod lwe_to_glwe_switching_key;
pub use gglwe_atk::*; pub use gglwe::*;
pub use gglwe_ct::*; pub use ggsw::*;
pub use gglwe_ksk::*; pub use glwe::*;
pub use gglwe_tsk::*; pub use glwe_automorphism_key::*;
pub use ggsw_ct::*; pub use glwe_switching_key::*;
pub use glwe_ct::*; pub use glwe_tensor_key::*;
pub use glwe_to_lwe_ksk::*; pub use glwe_to_lwe_switching_key::*;
pub use lwe_ct::*; pub use lwe::*;
pub use lwe_ksk::*; pub use lwe_switching_key::*;
pub use lwe_to_glwe_ksk::*; pub use lwe_to_glwe_switching_key::*;

View File

@@ -5,7 +5,6 @@ use poulpy_hal::{
use crate::layouts::{ use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, TorusPrecision, Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, TorusPrecision,
prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement},
}; };
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -27,13 +26,21 @@ pub struct AutomorphismKey<D: Data> {
pub(crate) p: i64, 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) { fn set_p(&mut self, p: i64) {
self.p = p self.p = p
} }
} }
impl<D: DataRef> GetAutomorphismGaloisElement for AutomorphismKey<D> { impl<D: DataRef> GetGaloisElement for AutomorphismKey<D> {
fn p(&self) -> i64 { fn p(&self) -> i64 {
self.p self.p
} }

View File

@@ -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::{ use crate::{
GetDistribution, GetDistributionMut, GetDistribution, GetDistributionMut,
dist::Distribution, 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)] #[derive(PartialEq, Eq)]
pub struct GLWEPublicKey<D: Data> { pub struct GLWEPublicKey<D: Data> {
pub(crate) data: VecZnx<D>, pub(crate) key: GLWE<D>,
pub(crate) base2k: Base2K,
pub(crate) k: TorusPrecision,
pub(crate) dist: Distribution, pub(crate) dist: Distribution,
} }
@@ -37,25 +34,25 @@ pub struct GLWEPublicKeyLayout {
impl<D: Data> LWEInfos for GLWEPublicKey<D> { impl<D: Data> LWEInfos for GLWEPublicKey<D> {
fn base2k(&self) -> Base2K { fn base2k(&self) -> Base2K {
self.base2k self.key.base2k()
} }
fn k(&self) -> TorusPrecision { fn k(&self) -> TorusPrecision {
self.k self.key.k()
} }
fn n(&self) -> Degree { fn n(&self) -> Degree {
Degree(self.data.n() as u32) self.key.n()
} }
fn size(&self) -> usize { fn size(&self) -> usize {
self.data.size() self.key.size()
} }
} }
impl<D: Data> GLWEInfos for GLWEPublicKey<D> { impl<D: Data> GLWEInfos for GLWEPublicKey<D> {
fn rank(&self) -> Rank { fn rank(&self) -> Rank {
Rank(self.data.cols() as u32 - 1) self.key.rank()
} }
} }
@@ -93,9 +90,7 @@ impl GLWEPublicKey<Vec<u8>> {
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self { pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
GLWEPublicKey { GLWEPublicKey {
data: VecZnx::alloc(n.into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize), key: GLWE::alloc(n, base2k, k, rank),
base2k,
k,
dist: Distribution::NONE, dist: Distribution::NONE,
} }
} }
@@ -114,54 +109,32 @@ impl GLWEPublicKey<Vec<u8>> {
impl<D: DataMut> ReaderFrom for GLWEPublicKey<D> { impl<D: DataMut> ReaderFrom for GLWEPublicKey<D> {
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> { 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) { match Distribution::read_from(reader) {
Ok(dist) => self.dist = dist, Ok(dist) => self.dist = dist,
Err(e) => return Err(e), Err(e) => return Err(e),
} }
self.data.read_from(reader) self.key.read_from(reader)
} }
} }
impl<D: DataRef> WriterTo for GLWEPublicKey<D> { impl<D: DataRef> WriterTo for GLWEPublicKey<D> {
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> { 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) { match self.dist.write_to(writer) {
Ok(()) => {} Ok(()) => {}
Err(e) => return Err(e), Err(e) => return Err(e),
} }
self.data.write_to(writer) self.key.write_to(writer)
} }
} }
pub trait GLWEPublicKeyToRef { impl<D: DataRef> GLWEToRef for GLWEPublicKey<D> {
fn to_ref(&self) -> GLWEPublicKey<&[u8]>; fn to_ref(&self) -> GLWE<&[u8]> {
} self.key.to_ref()
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,
}
} }
} }
pub trait GLWEPublicKeyToMut { impl<D: DataMut> GLWEToMut for GLWEPublicKey<D> {
fn to_mut(&mut self) -> GLWEPublicKey<&mut [u8]>; fn to_mut(&mut self) -> GLWE<&mut [u8]> {
} self.key.to_mut()
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(),
}
} }
} }

View File

@@ -1,38 +1,38 @@
mod gglwe_atk; mod gglwe;
mod gglwe_ct; mod ggsw;
mod gglwe_ksk; mod glwe;
mod gglwe_tsk; mod glwe_automorphism_key;
mod ggsw_ct; mod glwe_plaintext;
mod glwe_ct; mod glwe_public_key;
mod glwe_pk; mod glwe_secret;
mod glwe_pt; mod glwe_switching_key;
mod glwe_sk; mod glwe_tensor_key;
mod glwe_to_lwe_ksk; mod glwe_to_lwe_switching_key;
mod lwe_ct; mod lwe;
mod lwe_ksk; mod lwe_plaintext;
mod lwe_pt; mod lwe_secret;
mod lwe_sk; mod lwe_switching_key;
mod lwe_to_glwe_ksk; mod lwe_to_glwe_switching_key;
pub mod compressed; pub mod compressed;
pub mod prepared; pub mod prepared;
pub use compressed::*; pub use compressed::*;
pub use gglwe_atk::*; pub use gglwe::*;
pub use gglwe_ct::*; pub use ggsw::*;
pub use gglwe_ksk::*; pub use glwe::*;
pub use gglwe_tsk::*; pub use glwe_automorphism_key::*;
pub use ggsw_ct::*; pub use glwe_plaintext::*;
pub use glwe_ct::*; pub use glwe_public_key::*;
pub use glwe_pk::*; pub use glwe_secret::*;
pub use glwe_pt::*; pub use glwe_switching_key::*;
pub use glwe_sk::*; pub use glwe_tensor_key::*;
pub use glwe_to_lwe_ksk::*; pub use glwe_to_lwe_switching_key::*;
pub use lwe_ct::*; pub use lwe::*;
pub use lwe_ksk::*; pub use lwe_plaintext::*;
pub use lwe_pt::*; pub use lwe_secret::*;
pub use lwe_sk::*; pub use lwe_switching_key::*;
pub use lwe_to_glwe_ksk::*; pub use lwe_to_glwe_switching_key::*;
pub use prepared::*; pub use prepared::*;
use poulpy_hal::layouts::{Backend, Module}; use poulpy_hal::layouts::{Backend, Module};

View File

@@ -57,9 +57,9 @@ impl<D: Data, B: Backend> GGLWEInfos for GGLWEPrepared<D, B> {
} }
} }
pub trait GGLWEPreparedAlloc<B: Backend> pub trait GGLWEPreparedAlloc<BE: Backend>
where where
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf, Self: GetDegree + VmpPMatAlloc<BE> + VmpPMatBytesOf + VmpPrepare<BE> + VmpPrepareTmpBytes,
{ {
fn alloc_gglwe_prepared( fn alloc_gglwe_prepared(
&self, &self,
@@ -69,7 +69,7 @@ where
rank_out: Rank, rank_out: Rank,
dnum: Dnum, dnum: Dnum,
dsize: Dsize, dsize: Dsize,
) -> GGLWEPrepared<Vec<u8>, B> { ) -> GGLWEPrepared<Vec<u8>, BE> {
let size: usize = k.0.div_ceil(base2k.0) as usize; let size: usize = k.0.div_ceil(base2k.0) as usize;
debug_assert!( debug_assert!(
size as u32 > dsize.0, size as u32 > dsize.0,
@@ -92,7 +92,7 @@ where
} }
} }
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 where
A: GGLWEInfos, A: GGLWEInfos,
{ {
@@ -147,9 +147,41 @@ where
infos.dsize(), 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(),
)
} }
impl<B: Backend> GGLWEPreparedAlloc<B> for Module<B> where Module<B>: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {} 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<BE: Backend> GGLWEPreparedAlloc<BE> for Module<BE> where
Module<BE>: GetDegree + VmpPMatAlloc<BE> + VmpPMatBytesOf + VmpPrepare<BE> + VmpPrepareTmpBytes
{
}
impl<B: Backend> GGLWEPrepared<Vec<u8>, B> { impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -199,47 +231,11 @@ impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
} }
} }
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> { impl<D: DataMut, B: Backend> GGLWEPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGLWEToRef, O: GGLWEToRef,
M: GGLWEPrepare<B>, M: GGLWEPreparedAlloc<B>,
{ {
module.prepare_gglwe(self, other, scratch); module.prepare_gglwe(self, other, scratch);
} }
@@ -248,7 +244,7 @@ impl<D: DataMut, B: Backend> GGLWEPrepared<D, B> {
impl<B: Backend> GGLWEPrepared<Vec<u8>, B> { impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
where where
M: GGLWEPrepare<B>, M: GGLWEPreparedAlloc<B>,
{ {
module.prepare_gglwe_tmp_bytes(self) module.prepare_gglwe_tmp_bytes(self)
} }

View File

@@ -51,7 +51,7 @@ impl<D: Data, B: Backend> GGSWInfos for GGSWPrepared<D, B> {
pub trait GGSWPreparedAlloc<B: Backend> pub trait GGSWPreparedAlloc<B: Backend>
where where
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf, Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf + VmpPrepareTmpBytes + VmpPrepare<B>,
{ {
fn alloc_ggsw_prepared( fn alloc_ggsw_prepared(
&self, &self,
@@ -133,9 +133,39 @@ where
infos.rank(), 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> { impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -175,45 +205,11 @@ impl<D: DataRef, B: Backend> GGSWPrepared<D, B> {
} }
} }
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> { impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
where where
A: GGSWInfos, A: GGSWInfos,
M: GGSWPrepare<B>, M: GGSWPreparedAlloc<B>,
{ {
module.ggsw_prepare_tmp_bytes(infos) 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>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGSWToRef, O: GGSWToRef,
M: GGSWPrepare<B>, M: GGSWPreparedAlloc<B>,
{ {
module.ggsw_prepare(self, other, scratch); module.ggsw_prepare(self, other, scratch);
} }

View File

@@ -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,
}
}
}

View File

@@ -1,17 +1,17 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{ use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef,
GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, LWEInfos, Rank, TorusPrecision, GGLWEToRef, GLWEInfos, GetGaloisElement, LWEInfos, Rank, SetGaloisElement, TorusPrecision,
}; };
#[derive(PartialEq, Eq)] #[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) key: GGLWEPrepared<D, B>,
pub(crate) p: i64, 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 { fn n(&self) -> Degree {
self.key.n() self.key.n()
} }
@@ -29,33 +29,25 @@ impl<D: Data, B: Backend> LWEInfos for AutomorphismKeyPrepared<D, B> {
} }
} }
pub trait GetAutomorphismGaloisElement { impl<D: Data, B: Backend> GetGaloisElement for GLWEAutomorphismKeyPrepared<D, B> {
fn p(&self) -> i64;
}
impl<D: Data, B: Backend> GetAutomorphismGaloisElement for AutomorphismKeyPrepared<D, B> {
fn p(&self) -> i64 { fn p(&self) -> i64 {
self.p self.p
} }
} }
pub trait SetAutomorphismGaloisElement { impl<D: Data, B: Backend> SetGaloisElement for GLWEAutomorphismKeyPrepared<D, B> {
fn set_p(&mut self, p: i64);
}
impl<D: Data, B: Backend> SetAutomorphismGaloisElement for AutomorphismKeyPrepared<D, B> {
fn set_p(&mut self, p: i64) { fn set_p(&mut self, p: i64) {
self.p = p 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 { fn rank(&self) -> Rank {
self.rank_out() 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 { fn rank_in(&self) -> Rank {
self.key.rank_in() self.key.rank_in()
} }
@@ -73,7 +65,7 @@ impl<D: Data, B: Backend> GGLWEInfos for AutomorphismKeyPrepared<D, B> {
} }
} }
pub trait AutomorphismKeyPreparedAlloc<B: Backend> pub trait GLWEAutomorphismKeyPreparedApi<B: Backend>
where where
Self: GGLWEPreparedAlloc<B>, Self: GGLWEPreparedAlloc<B>,
{ {
@@ -84,14 +76,14 @@ where
rank: Rank, rank: Rank,
dnum: Dnum, dnum: Dnum,
dsize: Dsize, dsize: Dsize,
) -> AutomorphismKeyPrepared<Vec<u8>, B> { ) -> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
AutomorphismKeyPrepared::<Vec<u8>, B> { GLWEAutomorphismKeyPrepared::<Vec<u8>, B> {
key: self.alloc_gglwe_prepared(base2k, k, rank, rank, dnum, dsize), key: self.alloc_gglwe_prepared(base2k, k, rank, rank, dnum, dsize),
p: 0, 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 where
A: GGLWEInfos, A: GGLWEInfos,
{ {
@@ -137,46 +129,7 @@ where
infos.dsize(), infos.dsize(),
) )
} }
}
impl<B: Backend> AutomorphismKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}
impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
where
A: GGLWEInfos,
M: AutomorphismKeyPreparedAlloc<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>,
{
module.alloc_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
}
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
where
A: GGLWEInfos,
M: AutomorphismKeyPreparedAlloc<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>,
{
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 fn prepare_automorphism_key_tmp_bytes<A>(&self, infos: &A) -> usize
where where
A: GGLWEInfos, A: GGLWEInfos,
@@ -186,42 +139,74 @@ where
fn prepare_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>) fn prepare_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
where where
R: GGLWEPreparedToMut<B> + SetAutomorphismGaloisElement, R: GGLWEPreparedToMut<B> + SetGaloisElement,
O: GGLWEToRef + GetAutomorphismGaloisElement, O: GGLWEToRef + GetGaloisElement,
{ {
self.prepare_gglwe(res, other, scratch); self.prepare_gglwe(res, other, scratch);
res.set_p(other.p()); res.set_p(other.p());
} }
} }
impl<B: Backend> AutomorphismKeyPrepare<B> for Module<B> where Module<B>: GGLWEPrepare<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: 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: GLWEAutomorphismKeyPreparedApi<B>,
{
module.alloc_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
}
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
where
A: GGLWEInfos,
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: GLWEAutomorphismKeyPreparedApi<B>,
{
module.bytes_of_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
}
}
impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
where where
M: AutomorphismKeyPrepare<B>, M: GLWEAutomorphismKeyPreparedApi<B>,
{ {
module.prepare_automorphism_key_tmp_bytes(self) 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>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGLWEToRef + GetAutomorphismGaloisElement, O: GGLWEToRef + GetGaloisElement,
M: AutomorphismKeyPrepare<B>, M: GLWEAutomorphismKeyPreparedApi<B>,
{ {
module.prepare_automorphism_key(self, other, scratch); 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> { fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> {
self.key.to_mut() 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> { fn to_ref(&self) -> GGLWEPrepared<&[u8], BE> {
self.key.to_ref() self.key.to_ref()
} }

View File

@@ -1,19 +1,20 @@
use poulpy_hal::{ use poulpy_hal::{
api::{VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf}, api::{VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf},
layouts::{Backend, Data, DataMut, DataRef, Module, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, ZnxInfos}, layouts::{Backend, Data, DataMut, DataRef, Module},
}; };
use crate::{ use crate::{
GetDistribution, GetDistributionMut, GetDistribution, GetDistributionMut,
dist::Distribution, dist::Distribution,
layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, LWEInfos, Rank, TorusPrecision}, layouts::{
Base2K, Degree, GLWEInfos, GLWEPrepared, GLWEPreparedAlloc, GLWEPreparedToMut, GLWEPreparedToRef, GLWEToRef, GetDegree,
LWEInfos, Rank, TorusPrecision,
},
}; };
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
pub struct GLWEPublicKeyPrepared<D: Data, B: Backend> { pub struct GLWEPublicKeyPrepared<D: Data, B: Backend> {
pub(crate) data: VecZnxDft<D, B>, pub(crate) key: GLWEPrepared<D, B>,
pub(crate) base2k: Base2K,
pub(crate) k: TorusPrecision,
pub(crate) dist: Distribution, pub(crate) dist: Distribution,
} }
@@ -31,37 +32,35 @@ impl<D: DataMut, BE: Backend> GetDistributionMut for GLWEPublicKeyPrepared<D, BE
impl<D: Data, B: Backend> LWEInfos for GLWEPublicKeyPrepared<D, B> { impl<D: Data, B: Backend> LWEInfos for GLWEPublicKeyPrepared<D, B> {
fn base2k(&self) -> Base2K { fn base2k(&self) -> Base2K {
self.base2k self.key.base2k()
} }
fn k(&self) -> TorusPrecision { fn k(&self) -> TorusPrecision {
self.k self.key.k()
} }
fn size(&self) -> usize { fn size(&self) -> usize {
self.data.size() self.key.size()
} }
fn n(&self) -> Degree { fn n(&self) -> Degree {
Degree(self.data.n() as u32) self.key.n()
} }
} }
impl<D: Data, B: Backend> GLWEInfos for GLWEPublicKeyPrepared<D, B> { impl<D: Data, B: Backend> GLWEInfos for GLWEPublicKeyPrepared<D, B> {
fn rank(&self) -> Rank { fn rank(&self) -> Rank {
Rank(self.data.cols() as u32 - 1) self.key.rank()
} }
} }
pub trait GLWEPublicKeyPreparedAlloc<B: Backend> pub trait GLWEPublicKeyPreparedAlloc<B: Backend>
where where
Self: GetDegree + VecZnxDftAlloc<B> + VecZnxDftBytesOf, Self: GetDegree + GLWEPreparedAlloc<B>,
{ {
fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared<Vec<u8>, B> { fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared<Vec<u8>, B> {
GLWEPublicKeyPrepared { GLWEPublicKeyPrepared {
data: self.vec_znx_dft_alloc((rank + 1).into(), k.0.div_ceil(base2k.0) as usize), key: self.alloc_glwe_prepared(base2k, k, rank),
base2k,
k,
dist: Distribution::NONE, dist: Distribution::NONE,
} }
} }
@@ -74,7 +73,7 @@ where
} }
fn bytes_of_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize { 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) self.bytes_of_glwe_prepared(base2k, k, rank)
} }
fn bytes_of_glwe_public_key_prepared_from_infos<A>(&self, infos: &A) -> usize fn bytes_of_glwe_public_key_prepared_from_infos<A>(&self, infos: &A) -> usize
@@ -83,9 +82,18 @@ where
{ {
self.bytes_of_glwe_public_key_prepared(infos.base2k(), infos.k(), infos.rank()) 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 {} impl<B: Backend> GLWEPublicKeyPreparedAlloc<B> for Module<B> where Self: VecZnxDftAlloc<B> + VecZnxDftBytesOf + VecZnxDftApply<B> {}
impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> { impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -119,72 +127,30 @@ impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> {
} }
} }
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> { impl<D: DataMut, B: Backend> GLWEPublicKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O) pub fn prepare<O, M>(&mut self, module: &M, other: &O)
where where
O: GLWEPublicKeyToRef + GetDistribution, O: GLWEToRef + GetDistribution,
M: GLWEPublicKeyPrepare<B>, M: GLWEPublicKeyPreparedAlloc<B>,
{ {
module.prepare_glwe_public_key(self, other); module.prepare_glwe_public_key(self, other);
} }
} }
pub trait GLWEPublicKeyPreparedToMut<B: Backend> { impl<D: DataMut, B: Backend> GLWEPreparedToMut<B> for GLWEPublicKeyPrepared<D, B>
fn to_mut(&mut self) -> GLWEPublicKeyPrepared<&mut [u8], B>; where
} GLWEPrepared<D, B>: GLWEPreparedToMut<B>,
{
impl<D: DataMut, B: Backend> GLWEPublicKeyPreparedToMut<B> for GLWEPublicKeyPrepared<D, B> { fn to_mut(&mut self) -> GLWEPrepared<&mut [u8], B> {
fn to_mut(&mut self) -> GLWEPublicKeyPrepared<&mut [u8], B> { self.key.to_mut()
GLWEPublicKeyPrepared {
dist: self.dist,
k: self.k,
base2k: self.base2k,
data: self.data.to_mut(),
}
} }
} }
pub trait GLWEPublicKeyPreparedToRef<B: Backend> { impl<D: DataRef, B: Backend> GLWEPreparedToRef<B> for GLWEPublicKeyPrepared<D, B>
fn to_ref(&self) -> GLWEPublicKeyPrepared<&[u8], B>; where
} GLWEPrepared<D, B>: GLWEPreparedToRef<B>,
{
impl<D: DataRef, B: Backend> GLWEPublicKeyPreparedToRef<B> for GLWEPublicKeyPrepared<D, B> { fn to_ref(&self) -> GLWEPrepared<&[u8], B> {
fn to_ref(&self) -> GLWEPublicKeyPrepared<&[u8], B> { self.key.to_ref()
GLWEPublicKeyPrepared {
data: self.data.to_ref(),
dist: self.dist,
k: self.k,
base2k: self.base2k,
}
} }
} }

View File

@@ -49,9 +49,9 @@ impl<D: Data, B: Backend> GLWEInfos for GLWESecretPrepared<D, B> {
} }
} }
pub trait GLWESecretPreparedAlloc<B: Backend> pub trait GLWESecretPreparedApi<B: Backend>
where 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> { fn alloc_glwe_secret_prepared(&self, rank: Rank) -> GLWESecretPrepared<Vec<u8>, B> {
GLWESecretPrepared { GLWESecretPrepared {
@@ -77,56 +77,7 @@ where
assert_eq!(self.ring_degree(), infos.n()); assert_eq!(self.ring_degree(), infos.n());
self.bytes_of_glwe_secret_prepared(infos.rank()) self.bytes_of_glwe_secret_prepared(infos.rank())
} }
}
impl<B: Backend> GLWESecretPreparedAlloc<B> for Module<B> where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<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>,
{
module.alloc_glwe_secret_prepared_from_infos(infos)
}
pub fn alloc<M>(module: &M, rank: Rank) -> Self
where
M: GLWESecretPreparedAlloc<B>,
{
module.alloc_glwe_secret_prepared(rank)
}
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
where
A: GLWEInfos,
M: GLWESecretPreparedAlloc<B>,
{
module.bytes_of_glwe_secret_prepared_from_infos(infos)
}
pub fn bytes_of<M>(module: &M, rank: Rank) -> usize
where
M: GLWESecretPreparedAlloc<B>,
{
module.bytes_of_glwe_secret_prepared(rank)
}
}
impl<D: Data, B: Backend> GLWESecretPrepared<D, B> {
pub fn n(&self) -> Degree {
Degree(self.data.n() as u32)
}
pub fn rank(&self) -> Rank {
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) fn prepare_glwe_secret<R, O>(&self, res: &mut R, other: &O)
where where
R: GLWESecretPreparedToMut<B> + GetDistributionMut, R: GLWESecretPreparedToMut<B> + GetDistributionMut,
@@ -145,12 +96,54 @@ where
} }
} }
impl<B: Backend> GLWESecretPrepare<B> for Module<B> where Self: SvpPrepare<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: GLWESecretPreparedApi<B>,
{
module.alloc_glwe_secret_prepared_from_infos(infos)
}
pub fn alloc<M>(module: &M, rank: Rank) -> Self
where
M: GLWESecretPreparedApi<B>,
{
module.alloc_glwe_secret_prepared(rank)
}
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
where
A: GLWEInfos,
M: GLWESecretPreparedApi<B>,
{
module.bytes_of_glwe_secret_prepared_from_infos(infos)
}
pub fn bytes_of<M>(module: &M, rank: Rank) -> usize
where
M: GLWESecretPreparedApi<B>,
{
module.bytes_of_glwe_secret_prepared(rank)
}
}
impl<D: Data, B: Backend> GLWESecretPrepared<D, B> {
pub fn n(&self) -> Degree {
Degree(self.data.n() as u32)
}
pub fn rank(&self) -> Rank {
Rank(self.data.cols() as u32)
}
}
impl<D: DataMut, B: Backend> GLWESecretPrepared<D, B> { impl<D: DataMut, B: Backend> GLWESecretPrepared<D, B> {
pub fn prepare<M, O>(&mut self, module: &M, other: &O) pub fn prepare<M, O>(&mut self, module: &M, other: &O)
where where
M: GLWESecretPrepare<B>, M: GLWESecretPreparedApi<B>,
O: GLWESecretToRef + GetDistribution, O: GLWESecretToRef + GetDistribution,
{ {
module.prepare_glwe_secret(self, other); module.prepare_glwe_secret(self, other);

View File

@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{ use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut,
LWEInfos, Rank, TorusPrecision, LWEInfos, Rank, TorusPrecision,
prepared::{GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef}, prepared::{GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef},
}; };
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@@ -134,6 +134,23 @@ where
infos.dsize(), 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> {} impl<B: Backend> GLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GGLWEPreparedAlloc<B> {}
@@ -186,35 +203,11 @@ impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> {
} }
} }
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> { impl<D: DataMut, B: Backend> GLWESwitchingKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGLWEToRef + GLWESwitchingKeyDegrees, O: GGLWEToRef + GLWESwitchingKeyDegrees,
M: GLWESwitchingKeyPrepare<B>, M: GLWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_glwe_switching(self, other, scratch); module.prepare_glwe_switching(self, other, scratch);
} }
@@ -223,7 +216,7 @@ impl<D: DataMut, B: Backend> GLWESwitchingKeyPrepared<D, B> {
impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> { impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
where where
M: GLWESwitchingKeyPrepare<B>, M: GLWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_glwe_switching_key_tmp_bytes(self) module.prepare_glwe_switching_key_tmp_bytes(self)
} }

View File

@@ -1,8 +1,8 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{ use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef,
GGLWEPreparedToRef, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
}; };
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@@ -107,6 +107,28 @@ where
infos.dsize(), 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> {} impl<B: Backend> TensorKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}
@@ -165,40 +187,11 @@ impl<D: DataRef, B: Backend> TensorKeyPrepared<D, B> {
} }
} }
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> { impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
where where
A: GGLWEInfos, A: GGLWEInfos,
M: TensorKeyPrepare<B>, M: TensorKeyPreparedAlloc<B>,
{ {
module.prepare_tensor_key_tmp_bytes(infos) 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>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: TensorKeyToRef, O: TensorKeyToRef,
M: TensorKeyPrepare<B>, M: TensorKeyPreparedAlloc<B>,
{ {
module.prepare_tensor_key(self, other, scratch); module.prepare_tensor_key(self, other, scratch);
} }

View File

@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{ use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
}; };
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@@ -101,6 +101,21 @@ where
); );
self.bytes_of_glwe_to_lwe_switching_key_prepared(infos.base2k(), infos.k(), infos.rank_in(), infos.dnum()) 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> {} impl<B: Backend> GLWEToLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}
@@ -137,33 +152,11 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
} }
} }
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> { impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A)
where where
A: GGLWEInfos, A: GGLWEInfos,
M: GLWEToLWESwitchingKeyPrepare<B>, M: GLWEToLWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_glwe_to_lwe_switching_key_tmp_bytes(infos); 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>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGLWEToRef + GLWESwitchingKeyDegrees, O: GGLWEToRef + GLWESwitchingKeyDegrees,
M: GLWEToLWESwitchingKeyPrepare<B>, M: GLWEToLWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_glwe_to_lwe_switching_key(self, other, scratch); module.prepare_glwe_to_lwe_switching_key(self, other, scratch);
} }

View File

@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{ use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
}; };
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@@ -110,6 +110,20 @@ where
); );
self.bytes_of_lwe_switching_key_prepared(infos.base2k(), infos.k(), infos.dnum()) 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> {} impl<B: Backend> LWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}
@@ -146,32 +160,11 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
} }
} }
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> { impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A)
where where
A: GGLWEInfos, A: GGLWEInfos,
M: LWESwitchingKeyPrepare<B>, M: LWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_lwe_switching_key_tmp_bytes(infos); 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>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGLWEToRef + GLWESwitchingKeyDegrees, O: GGLWEToRef + GLWESwitchingKeyDegrees,
M: LWESwitchingKeyPrepare<B>, M: LWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_lwe_switching_key(self, other, scratch); module.prepare_lwe_switching_key(self, other, scratch);
} }

View File

@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{ use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc}, prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
}; };
/// A special [GLWESwitchingKey] required to for the conversion from [LWE] to [GLWE]. /// A special [GLWESwitchingKey] required to for the conversion from [LWE] to [GLWE].
@@ -108,6 +108,21 @@ where
); );
self.bytes_of_lwe_to_glwe_switching_key_prepared(infos.base2k(), infos.k(), infos.rank_out(), infos.dnum()) 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> {} impl<B: Backend> LWEToGLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}
@@ -144,33 +159,11 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
} }
} }
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> { impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A)
where where
A: GGLWEInfos, A: GGLWEInfos,
M: LWEToGLWESwitchingKeyPrepare<B>, M: LWEToGLWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_lwe_to_glwe_switching_key_tmp_bytes(infos); 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>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGLWEToRef + GLWESwitchingKeyDegrees, O: GGLWEToRef + GLWESwitchingKeyDegrees,
M: LWEToGLWESwitchingKeyPrepare<B>, M: LWEToGLWESwitchingKeyPreparedAlloc<B>,
{ {
module.prepare_lwe_to_glwe_switching_key(self, other, scratch); module.prepare_lwe_to_glwe_switching_key(self, other, scratch);
} }

View File

@@ -1,21 +1,23 @@
mod gglwe_atk; mod gglwe;
mod gglwe_ct; mod ggsw;
mod gglwe_ksk; mod glwe;
mod gglwe_tsk; mod glwe_automorphism_key;
mod ggsw_ct; mod glwe_public_key;
mod glwe_pk; mod glwe_secret;
mod glwe_sk; mod glwe_switching_key;
mod glwe_to_lwe_ksk; mod glwe_tensor_key;
mod lwe_ksk; mod glwe_to_lwe_switching_key;
mod lwe_to_glwe_ksk; mod lwe_switching_key;
mod lwe_to_glwe_switching_key;
pub use gglwe_atk::*; pub use gglwe::*;
pub use gglwe_ct::*; pub use ggsw::*;
pub use gglwe_ksk::*; pub use glwe::*;
pub use gglwe_tsk::*; pub use glwe_automorphism_key::*;
pub use ggsw_ct::*; pub use glwe_public_key::*;
pub use glwe_pk::*; pub use glwe_secret::*;
pub use glwe_sk::*; pub use glwe_switching_key::*;
pub use glwe_to_lwe_ksk::*; pub use glwe_tensor_key::*;
pub use lwe_ksk::*; pub use glwe_to_lwe_switching_key::*;
pub use lwe_to_glwe_ksk::*; pub use lwe_switching_key::*;
pub use lwe_to_glwe_switching_key::*;

View File

@@ -1,10 +1,10 @@
mod gglwe_ct; mod gglwe;
mod ggsw_ct; mod ggsw;
mod glwe_ct; mod glwe;
pub use gglwe_ct::*; pub use gglwe::*;
pub use ggsw_ct::*; pub use ggsw::*;
pub use glwe_ct::*; pub use glwe::*;
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
#[allow(dead_code)] #[allow(dead_code)]

View File

@@ -6,10 +6,10 @@ use poulpy_hal::{
use crate::{ use crate::{
dist::Distribution, dist::Distribution,
layouts::{ layouts::{
AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPublicKey, AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGLWELayout, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPrepared,
GLWESecret, GLWESwitchingKey, Rank, TensorKey, GLWEPublicKey, GLWESecret, GLWESwitchingKey, Rank, TensorKey,
prepared::{ prepared::{
AutomorphismKeyPrepared, GGLWEPrepared, GGSWPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared, GGLWEPrepared, GGSWPrepared, GLWEAutomorphismKeyPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared,
GLWESwitchingKeyPrepared, TensorKeyPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared,
}, },
}, },
@@ -19,7 +19,7 @@ pub trait ScratchTakeCore<B: Backend>
where where
Self: ScratchTakeBasic + ScratchAvailable, 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 where
A: GLWEInfos, A: GLWEInfos,
M: ModuleN, M: ModuleN,
@@ -36,7 +36,7 @@ where
) )
} }
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 where
A: GLWEInfos, A: GLWEInfos,
M: ModuleN, M: ModuleN,
@@ -44,14 +44,14 @@ where
let mut scratch: &mut Self = self; let mut scratch: &mut Self = self;
let mut cts: Vec<GLWE<&mut [u8]>> = Vec::with_capacity(size); let mut cts: Vec<GLWE<&mut [u8]>> = Vec::with_capacity(size);
for _ in 0..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; scratch = new_scratch;
cts.push(ct); cts.push(ct);
} }
(cts, scratch) (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 where
A: GLWEInfos, A: GLWEInfos,
M: ModuleN, M: ModuleN,
@@ -184,25 +184,38 @@ where
(cts, scratch) (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 where
A: GLWEInfos, A: GLWEInfos,
M: ModuleN, M: ModuleN,
{ {
assert_eq!(module.n() as u32, infos.n()); 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 { GLWEPublicKey {
k: infos.k(),
dist: Distribution::NONE, dist: Distribution::NONE,
base2k: infos.base2k(), key: data,
data,
}, },
scratch, 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 where
A: GLWEInfos, A: GLWEInfos,
M: ModuleN + VecZnxDftBytesOf, M: ModuleN + VecZnxDftBytesOf,
@@ -210,9 +223,8 @@ where
assert_eq!(module.n() as u32, infos.n()); assert_eq!(module.n() as u32, infos.n());
let (data, scratch) = self.take_vec_znx_dft(module, (infos.rank() + 1).into(), infos.size()); let (data, scratch) = self.take_vec_znx_dft(module, (infos.rank() + 1).into(), infos.size());
( (
GLWEPublicKeyPrepared { GLWEPrepared {
k: infos.k(), k: infos.k(),
dist: Distribution::NONE,
base2k: infos.base2k(), base2k: infos.base2k(),
data, data,
}, },
@@ -265,7 +277,7 @@ where
) )
} }
fn take_gglwe_switching_key_prepared<A, M>( fn take_glwe_switching_key_prepared<A, M>(
&mut self, &mut self,
module: &M, module: &M,
infos: &A, infos: &A,
@@ -300,14 +312,14 @@ where
&mut self, &mut self,
module: &M, module: &M,
infos: &A, infos: &A,
) -> (AutomorphismKeyPrepared<&mut [u8], B>, &mut Self) ) -> (GLWEAutomorphismKeyPrepared<&mut [u8], B>, &mut Self)
where where
A: GGLWEInfos, A: GGLWEInfos,
M: ModuleN + VmpPMatBytesOf, M: ModuleN + VmpPMatBytesOf,
{ {
assert_eq!(module.n() as u32, infos.n()); assert_eq!(module.n() as u32, infos.n());
let (data, scratch) = self.take_gglwe_prepared(module, infos); 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) fn take_tensor_key<A, M>(&mut self, module: &M, infos: &A) -> (TensorKey<&mut [u8]>, &mut Self)

View File

@@ -4,9 +4,9 @@ use crate::layouts::{
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE, AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE,
LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision, LWESwitchingKey, LWEToGLWESwitchingKey, Rank, TensorKey, TorusPrecision,
compressed::{ compressed::{
AutomorphismKeyCompressed, GGLWECompressed, GGSWCompressed, GLWECompressed, GLWESwitchingKeyCompressed, GGLWECompressed, GGSWCompressed, GLWEAutomorphismKeyCompressed, GLWECompressed, GLWESwitchingKeyCompressed,
GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed, LWEToGLWESwitchingKeyCompressed, GLWETensorKeyCompressed, GLWEToLWESwitchingKeyCompressed, LWECompressed, LWESwitchingKeyCompressed,
TensorKeyCompressed, LWEToGLWESwitchingKeyCompressed,
}, },
}; };
@@ -75,7 +75,8 @@ fn test_automorphism_key_serialization() {
#[test] #[test]
fn test_automorphism_key_compressed_serialization() { 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); test_reader_writer_interface(original);
} }
@@ -87,7 +88,7 @@ fn test_tensor_key_serialization() {
#[test] #[test]
fn test_tensor_key_compressed_serialization() { 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); test_reader_writer_interface(original);
} }

View File

@@ -5,12 +5,12 @@ use poulpy_hal::{
}; };
use crate::{ use crate::{
AutomorphismKeyAutomorphism, AutomorphismKeyEncryptSk, GLWEDecrypt, ScratchTakeCore, AutomorphismKeyEncryptSk, GLWEAutomorphismKeyAutomorphism, GLWEDecrypt, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GGLWEInfos, GLWEPlaintext, AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GLWEAutomorphismKeyPreparedApi, GLWEPlaintext, GLWESecret,
GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESecretPreparedApi,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
}, },
noise::log2_std_noise_gglwe_product, noise::log2_std_noise_gglwe_product,
}; };
@@ -19,14 +19,12 @@ use crate::{
pub fn test_gglwe_automorphism_key_automorphism<BE: Backend>(module: &Module<BE>) pub fn test_gglwe_automorphism_key_automorphism<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: AutomorphismKeyEncryptSk<BE> Module<BE>: AutomorphismKeyEncryptSk<BE>
+ AutomorphismKeyPreparedAlloc<BE> + GLWEAutomorphismKeyPreparedApi<BE>
+ AutomorphismKeyPrepare<BE> + GLWEAutomorphismKeyAutomorphism<BE>
+ AutomorphismKeyAutomorphism<BE>
+ VecZnxAutomorphism + VecZnxAutomorphism
+ GaloisElement + GaloisElement
+ VecZnxSubScalarInplace + VecZnxSubScalarInplace
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GLWEDecrypt<BE>, + GLWEDecrypt<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
@@ -117,8 +115,8 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = let mut auto_key_apply_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_infos); GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_infos);
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow()); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
@@ -190,14 +188,12 @@ where
pub fn test_gglwe_automorphism_key_automorphism_inplace<BE: Backend>(module: &Module<BE>) pub fn test_gglwe_automorphism_key_automorphism_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: AutomorphismKeyEncryptSk<BE> Module<BE>: AutomorphismKeyEncryptSk<BE>
+ AutomorphismKeyPreparedAlloc<BE> + GLWEAutomorphismKeyPreparedApi<BE>
+ AutomorphismKeyPrepare<BE> + GLWEAutomorphismKeyAutomorphism<BE>
+ AutomorphismKeyAutomorphism<BE>
+ VecZnxAutomorphism + VecZnxAutomorphism
+ GaloisElement + GaloisElement
+ VecZnxSubScalarInplace + VecZnxSubScalarInplace
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GLWEDecrypt<BE>, + GLWEDecrypt<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
@@ -271,8 +267,8 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = let mut auto_key_apply_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_layout); GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_layout);
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow()); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());

View File

@@ -8,9 +8,9 @@ use crate::{
AutomorphismKeyEncryptSk, GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, TensorKeyEncryptSk, AutomorphismKeyEncryptSk, GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, TensorKeyEncryptSk,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
AutomorphismKey, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GGSW, GGSWLayout, GLWESecret, GLWESecretPrepare, AutomorphismKey, GGSW, GGSWLayout, GLWEAutomorphismKeyPreparedApi, GLWESecret, GLWESecretPreparedApi, TensorKey,
GLWESecretPreparedAlloc, TensorKey, TensorKeyLayout, TensorKeyPrepare, TensorKeyPreparedAlloc, TensorKeyLayout, TensorKeyPreparedAlloc,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared}, prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared},
}, },
noise::noise_ggsw_keyswitch, noise::noise_ggsw_keyswitch,
}; };
@@ -19,14 +19,11 @@ pub fn test_ggsw_automorphism<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGSWEncryptSk<BE> Module<BE>: GGSWEncryptSk<BE>
+ AutomorphismKeyEncryptSk<BE> + AutomorphismKeyEncryptSk<BE>
+ AutomorphismKeyPreparedAlloc<BE> + GLWEAutomorphismKeyPreparedApi<BE>
+ AutomorphismKeyPrepare<BE>
+ GGSWAutomorphism<BE> + GGSWAutomorphism<BE>
+ TensorKeyPrepare<BE>
+ TensorKeyPreparedAlloc<BE> + TensorKeyPreparedAlloc<BE>
+ TensorKeyEncryptSk<BE> + TensorKeyEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ VecZnxAutomorphismInplace<BE> + VecZnxAutomorphismInplace<BE>
+ GGSWNoise<BE>, + GGSWNoise<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -137,8 +134,8 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = let mut auto_key_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> = let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
@@ -181,14 +178,11 @@ pub fn test_ggsw_automorphism_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGSWEncryptSk<BE> Module<BE>: GGSWEncryptSk<BE>
+ AutomorphismKeyEncryptSk<BE> + AutomorphismKeyEncryptSk<BE>
+ AutomorphismKeyPreparedAlloc<BE> + GLWEAutomorphismKeyPreparedApi<BE>
+ AutomorphismKeyPrepare<BE>
+ GGSWAutomorphism<BE> + GGSWAutomorphism<BE>
+ TensorKeyPrepare<BE>
+ TensorKeyPreparedAlloc<BE> + TensorKeyPreparedAlloc<BE>
+ TensorKeyEncryptSk<BE> + TensorKeyEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ VecZnxAutomorphismInplace<BE> + VecZnxAutomorphismInplace<BE>
+ GGSWNoise<BE>, + GGSWNoise<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -286,8 +280,8 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = let mut auto_key_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> = let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =

View File

@@ -8,9 +8,9 @@ use crate::{
AutomorphismKeyEncryptSk, GLWEAutomorphism, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore, AutomorphismKeyEncryptSk, GLWEAutomorphism, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GLWE, GLWELayout, AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWEAutomorphismKeyPreparedApi, GLWELayout, GLWEPlaintext, GLWESecret,
GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESecretPreparedApi,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, prepared::{GLWEAutomorphismKeyPrepared, GLWESecretPrepared},
}, },
noise::log2_std_noise_gglwe_product, noise::log2_std_noise_gglwe_product,
}; };
@@ -18,14 +18,12 @@ use crate::{
pub fn test_glwe_automorphism<BE: Backend>(module: &Module<BE>) pub fn test_glwe_automorphism<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GLWEEncryptSk<BE> Module<BE>: GLWEEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ VecZnxFillUniform + VecZnxFillUniform
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ GLWEAutomorphism<BE> + GLWEAutomorphism<BE>
+ AutomorphismKeyEncryptSk<BE> + AutomorphismKeyEncryptSk<BE>
+ AutomorphismKeyPrepare<BE> + GLWEAutomorphismKeyPreparedApi<BE>
+ AutomorphismKeyPreparedAlloc<BE>
+ GLWENoise<BE> + GLWENoise<BE>
+ VecZnxAutomorphismInplace<BE>, + VecZnxAutomorphismInplace<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -108,8 +106,8 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = let mut autokey_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &autokey_infos); GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &autokey_infos);
autokey_prepared.prepare(module, &autokey, scratch.borrow()); autokey_prepared.prepare(module, &autokey, scratch.borrow());
ct_out.automorphism(module, &ct_in, &autokey_prepared, scratch.borrow()); ct_out.automorphism(module, &ct_in, &autokey_prepared, scratch.borrow());
@@ -138,14 +136,12 @@ where
pub fn test_glwe_automorphism_inplace<BE: Backend>(module: &Module<BE>) pub fn test_glwe_automorphism_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GLWEEncryptSk<BE> Module<BE>: GLWEEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ VecZnxFillUniform + VecZnxFillUniform
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ GLWEAutomorphism<BE> + GLWEAutomorphism<BE>
+ AutomorphismKeyEncryptSk<BE> + AutomorphismKeyEncryptSk<BE>
+ AutomorphismKeyPrepare<BE> + GLWEAutomorphismKeyPreparedApi<BE>
+ AutomorphismKeyPreparedAlloc<BE>
+ GLWENoise<BE> + GLWENoise<BE>
+ VecZnxAutomorphismInplace<BE>, + VecZnxAutomorphismInplace<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -219,8 +215,8 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> = let mut autokey_prepared: GLWEAutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &autokey); GLWEAutomorphismKeyPrepared::alloc_from_infos(module, &autokey);
autokey_prepared.prepare(module, &autokey, scratch.borrow()); autokey_prepared.prepare(module, &autokey, scratch.borrow());
ct.automorphism_inplace(module, &autokey_prepared, scratch.borrow()); ct.automorphism_inplace(module, &autokey_prepared, scratch.borrow());

View File

@@ -8,10 +8,9 @@ use crate::{
GLWEDecrypt, GLWEEncryptSk, GLWEFromLWE, GLWEToLWESwitchingKeyEncryptSk, LWEDecrypt, LWEEncryptSk, GLWEDecrypt, GLWEEncryptSk, GLWEFromLWE, GLWEToLWESwitchingKeyEncryptSk, LWEDecrypt, LWEEncryptSk,
LWEToGLWESwitchingKeyEncryptSk, ScratchTakeCore, LWEToGLWESwitchingKeyEncryptSk, ScratchTakeCore,
layouts::{ layouts::{
Base2K, Degree, Dnum, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, Base2K, Degree, Dnum, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi, GLWEToLWEKeyLayout,
GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyPrepare, GLWEToLWESwitchingKeyPreparedAlloc, LWE, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyPreparedAlloc, LWE, LWELayout, LWEPlaintext, LWESecret,
LWELayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, LWEToGLWESwitchingKeyPrepare, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, LWEToGLWESwitchingKeyPreparedAlloc, Rank, TorusPrecision,
LWEToGLWESwitchingKeyPreparedAlloc, Rank, TorusPrecision,
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared}, prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared},
}, },
}; };
@@ -21,11 +20,9 @@ where
Module<BE>: GLWEFromLWE<BE> Module<BE>: GLWEFromLWE<BE>
+ LWEToGLWESwitchingKeyEncryptSk<BE> + LWEToGLWESwitchingKeyEncryptSk<BE>
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ LWEEncryptSk<BE> + LWEEncryptSk<BE>
+ LWEToGLWESwitchingKeyPreparedAlloc<BE> + LWEToGLWESwitchingKeyPreparedAlloc<BE>,
+ LWEToGLWESwitchingKeyPrepare<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {
@@ -115,10 +112,8 @@ where
+ GLWEEncryptSk<BE> + GLWEEncryptSk<BE>
+ LWEDecrypt<BE> + LWEDecrypt<BE>
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GLWEToLWESwitchingKeyEncryptSk<BE> + GLWEToLWESwitchingKeyEncryptSk<BE>
+ GLWEToLWESwitchingKeyPrepare<BE>
+ GLWEToLWESwitchingKeyPreparedAlloc<BE>, + GLWEToLWESwitchingKeyPreparedAlloc<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,

View File

@@ -9,8 +9,8 @@ use crate::{
GLWESwitchingKeyEncryptSk, ScratchTakeCore, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, GLWESecret, GLWESecretPrepare, AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, GLWESecret, GLWESecretPreparedApi,
GLWESecretPreparedAlloc, GLWESwitchingKeyDecompress, compressed::AutomorphismKeyCompressed, prepared::GLWESecretPrepared, GLWESwitchingKeyDecompress, compressed::GLWEAutomorphismKeyCompressed, prepared::GLWESecretPrepared,
}, },
noise::GGLWENoise, noise::GGLWENoise,
}; };
@@ -19,8 +19,7 @@ pub fn test_gglwe_automorphism_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: AutomorphismKeyEncryptSk<BE> Module<BE>: AutomorphismKeyEncryptSk<BE>
+ GGLWEKeyswitch<BE> + GGLWEKeyswitch<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ GLWESwitchingKeyCompressedEncryptSk<BE> + GLWESwitchingKeyCompressedEncryptSk<BE>
+ GLWESwitchingKeyDecompress + GLWESwitchingKeyDecompress
@@ -92,8 +91,7 @@ pub fn test_gglwe_automorphism_key_compressed_encrypt_sk<BE: Backend>(module: &M
where where
Module<BE>: AutomorphismKeyCompressedEncryptSk<BE> Module<BE>: AutomorphismKeyCompressedEncryptSk<BE>
+ GGLWEKeyswitch<BE> + GGLWEKeyswitch<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ GLWESwitchingKeyCompressedEncryptSk<BE> + GLWESwitchingKeyCompressedEncryptSk<BE>
+ AutomorphismKeyDecompress + AutomorphismKeyDecompress
@@ -120,12 +118,13 @@ where
rank: rank.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_xs: Source = Source::new([0u8; 32]);
let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]);
let mut 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, module, &atk_infos,
)); ));

View File

@@ -9,9 +9,8 @@ use crate::{
decryption::GLWEDecrypt, decryption::GLWEDecrypt,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GGLWELayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyCompressed, GGLWELayout, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyCompressed, GLWESwitchingKeyDecompress,
GLWESwitchingKeyDecompress, prepared::{GGLWEPreparedAlloc, GLWESecretPrepared},
prepared::{GGLWEPrepare, GGLWEPreparedAlloc, GLWESecretPrepared},
}, },
noise::GGLWENoise, noise::GGLWENoise,
}; };
@@ -19,12 +18,10 @@ use crate::{
pub fn test_gglwe_switching_key_encrypt_sk<BE: Backend>(module: &Module<BE>) pub fn test_gglwe_switching_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGLWEEncryptSk<BE> Module<BE>: GGLWEEncryptSk<BE>
+ GGLWEPrepare<BE>
+ GGLWEPreparedAlloc<BE> + GGLWEPreparedAlloc<BE>
+ GGLWEKeyswitch<BE> + GGLWEKeyswitch<BE>
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ VecZnxFillUniform + VecZnxFillUniform
+ GGLWENoise<BE>, + GGLWENoise<BE>,
@@ -86,12 +83,10 @@ where
pub fn test_gglwe_switching_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>) pub fn test_gglwe_switching_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGLWEEncryptSk<BE> Module<BE>: GGLWEEncryptSk<BE>
+ GGLWEPrepare<BE>
+ GGLWEPreparedAlloc<BE> + GGLWEPreparedAlloc<BE>
+ GGLWEKeyswitch<BE> + GGLWEKeyswitch<BE>
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ GLWESwitchingKeyCompressedEncryptSk<BE> + GLWESwitchingKeyCompressedEncryptSk<BE>
+ GLWESwitchingKeyDecompress + GLWESwitchingKeyDecompress

View File

@@ -8,7 +8,7 @@ use crate::{
GGSWCompressedEncryptSk, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, GGSWCompressedEncryptSk, GGSWEncryptSk, GGSWNoise, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GGSW, GGSWDecompress, GGSWLayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, compressed::GGSWCompressed, GGSW, GGSWDecompress, GGSWLayout, GLWESecret, GLWESecretPreparedApi, compressed::GGSWCompressed,
prepared::GLWESecretPrepared, prepared::GLWESecretPrepared,
}, },
}; };
@@ -17,7 +17,7 @@ pub fn test_ggsw_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchTakeCore<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 base2k: usize = 12;
let k: usize = 54; let k: usize = 54;
@@ -74,8 +74,7 @@ pub fn test_ggsw_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
Module<BE>: Module<BE>: GGSWCompressedEncryptSk<BE> + GLWESecretPreparedApi<BE> + GGSWNoise<BE> + GGSWDecompress,
GGSWCompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + GGSWNoise<BE> + GGSWDecompress,
{ {
let base2k: usize = 12; let base2k: usize = 12;
let k: usize = 54; let k: usize = 54;

View File

@@ -9,8 +9,8 @@ use crate::{
decryption::GLWEDecrypt, decryption::GLWEDecrypt,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWEPublicKey, GLWEPublicKeyPrepare, GLWEPublicKeyPreparedAlloc, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWEPublicKey, GLWEPublicKeyPreparedAlloc, GLWESecret,
GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, LWEInfos, GLWESecretPreparedApi, LWEInfos,
compressed::GLWECompressed, compressed::GLWECompressed,
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared}, prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared},
}, },
@@ -18,8 +18,7 @@ use crate::{
pub fn test_glwe_encrypt_sk<BE: Backend>(module: &Module<BE>) pub fn test_glwe_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: Module<BE>: GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWESub,
GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxFillUniform + GLWESub,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {
@@ -84,12 +83,7 @@ where
pub fn test_glwe_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>) pub fn test_glwe_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GLWECompressedEncryptSk<BE> Module<BE>: GLWECompressedEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWESub,
+ GLWEDecrypt<BE>
+ GLWESecretPreparedAlloc<BE>
+ GLWESecretPrepare<BE>
+ VecZnxFillUniform
+ GLWESub,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {
@@ -166,8 +160,7 @@ where
pub fn test_glwe_encrypt_zero_sk<BE: Backend>(module: &Module<BE>) pub fn test_glwe_encrypt_zero_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: Module<BE>: GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedApi<BE> + VecZnxFillUniform + GLWESub,
GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxFillUniform + GLWESub,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {
@@ -217,12 +210,10 @@ where
pub fn test_glwe_encrypt_pk<BE: Backend>(module: &Module<BE>) pub fn test_glwe_encrypt_pk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GLWEEncryptPk<BE> Module<BE>: GLWEEncryptPk<BE>
+ GLWEPublicKeyPrepare<BE>
+ GLWEPublicKeyPreparedAlloc<BE> + GLWEPublicKeyPreparedAlloc<BE>
+ GLWEPublicKeyGenerate<BE> + GLWEPublicKeyGenerate<BE>
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ VecZnxFillUniform + VecZnxFillUniform
+ GLWESub, + GLWESub,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,

View File

@@ -13,16 +13,15 @@ use crate::{
decryption::GLWEDecrypt, decryption::GLWEDecrypt,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
Dsize, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, TensorKey, TensorKeyCompressed, Dsize, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi, GLWETensorKeyCompressed, TensorKey, TensorKeyLayout,
TensorKeyLayout, prepared::GLWESecretPrepared, prepared::GLWESecretPrepared,
}, },
}; };
pub fn test_gglwe_tensor_key_encrypt_sk<BE: Backend>(module: &Module<BE>) pub fn test_gglwe_tensor_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: TensorKeyEncryptSk<BE> Module<BE>: TensorKeyEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ VecZnxDftAlloc<BE> + VecZnxDftAlloc<BE>
+ VecZnxBigAlloc<BE> + VecZnxBigAlloc<BE>
@@ -113,8 +112,7 @@ where
pub fn test_gglwe_tensor_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>) pub fn test_gglwe_tensor_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: TensorKeyEncryptSk<BE> Module<BE>: TensorKeyEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GGLWETensorKeyCompressedEncryptSk<BE> + GGLWETensorKeyCompressedEncryptSk<BE>
+ GLWEDecrypt<BE> + GLWEDecrypt<BE>
+ VecZnxDftAlloc<BE> + VecZnxDftAlloc<BE>
@@ -144,12 +142,13 @@ where
rank: rank.into(), 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_xs: Source = Source::new([0u8; 32]);
let mut source_xe: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(TensorKeyCompressed::encrypt_sk_tmp_bytes( let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWETensorKeyCompressed::encrypt_sk_tmp_bytes(
module, module,
&tensor_key_infos, &tensor_key_infos,
)); ));

View File

@@ -8,8 +8,7 @@ use crate::{
GGLWEExternalProduct, GGLWENoise, GGSWEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore, GGLWEExternalProduct, GGLWENoise, GGSWEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GGSW, GGSWLayout, GGSWPreparedAlloc, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout,
GLWESwitchingKey, GLWESwitchingKeyLayout,
prepared::{GGSWPrepared, GLWESecretPrepared}, prepared::{GGSWPrepared, GLWESecretPrepared},
}, },
noise::noise_ggsw_product, noise::noise_ggsw_product,
@@ -21,10 +20,8 @@ where
Module<BE>: GGLWEExternalProduct<BE> Module<BE>: GGLWEExternalProduct<BE>
+ GGSWEncryptSk<BE> + GGSWEncryptSk<BE>
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ VecZnxRotateInplace<BE> + VecZnxRotateInplace<BE>
+ GGSWPrepare<BE>
+ GGSWPreparedAlloc<BE> + GGSWPreparedAlloc<BE>
+ GGLWENoise<BE>, + GGLWENoise<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -172,10 +169,8 @@ where
Module<BE>: GGLWEExternalProduct<BE> Module<BE>: GGLWEExternalProduct<BE>
+ GGSWEncryptSk<BE> + GGSWEncryptSk<BE>
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ VecZnxRotateInplace<BE> + VecZnxRotateInplace<BE>
+ GGSWPrepare<BE>
+ GGSWPreparedAlloc<BE> + GGSWPreparedAlloc<BE>
+ GGLWENoise<BE>, + GGLWENoise<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,

View File

@@ -8,7 +8,7 @@ use crate::{
GGSWEncryptSk, GGSWExternalProduct, GGSWNoise, ScratchTakeCore, GGSWEncryptSk, GGSWExternalProduct, GGSWNoise, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GGSW, GGSWLayout, GGSWPreparedAlloc, GLWESecret, GLWESecretPreparedApi,
prepared::{GGSWPrepared, GLWESecretPrepared}, prepared::{GGSWPrepared, GLWESecretPrepared},
}, },
noise::noise_ggsw_product, noise::noise_ggsw_product,
@@ -19,9 +19,7 @@ pub fn test_ggsw_external_product<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGSWEncryptSk<BE> Module<BE>: GGSWEncryptSk<BE>
+ GGSWExternalProduct<BE> + GGSWExternalProduct<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GGSWPrepare<BE>
+ GGSWPreparedAlloc<BE> + GGSWPreparedAlloc<BE>
+ VecZnxRotateInplace<BE> + VecZnxRotateInplace<BE>
+ GGSWNoise<BE>, + GGSWNoise<BE>,
@@ -155,9 +153,7 @@ pub fn test_ggsw_external_product_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGSWEncryptSk<BE> Module<BE>: GGSWEncryptSk<BE>
+ GGSWExternalProduct<BE> + GGSWExternalProduct<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GGSWPrepare<BE>
+ GGSWPreparedAlloc<BE> + GGSWPreparedAlloc<BE>
+ VecZnxRotateInplace<BE> + VecZnxRotateInplace<BE>
+ GGSWNoise<BE>, + GGSWNoise<BE>,

View File

@@ -8,8 +8,7 @@ use crate::{
GGSWEncryptSk, GLWEEncryptSk, GLWEExternalProduct, GLWENoise, ScratchTakeCore, GGSWEncryptSk, GLWEEncryptSk, GLWEExternalProduct, GLWENoise, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GGSW, GGSWLayout, GGSWPreparedAlloc, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi,
GLWESecretPreparedAlloc,
prepared::{GGSWPrepared, GLWESecretPrepared}, prepared::{GGSWPrepared, GLWESecretPrepared},
}, },
noise::noise_ggsw_product, noise::noise_ggsw_product,
@@ -19,15 +18,13 @@ use crate::{
pub fn test_glwe_external_product<BE: Backend>(module: &Module<BE>) pub fn test_glwe_external_product<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGSWEncryptSk<BE> Module<BE>: GGSWEncryptSk<BE>
+ GGSWPrepare<BE>
+ GGSWPreparedAlloc<BE> + GGSWPreparedAlloc<BE>
+ VecZnxFillUniform + VecZnxFillUniform
+ GLWEExternalProduct<BE> + GLWEExternalProduct<BE>
+ GLWEEncryptSk<BE> + GLWEEncryptSk<BE>
+ GLWENoise<BE> + GLWENoise<BE>
+ VecZnxRotateInplace<BE> + VecZnxRotateInplace<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>,
+ GLWESecretPreparedAlloc<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {
@@ -151,15 +148,13 @@ where
pub fn test_glwe_external_product_inplace<BE: Backend>(module: &Module<BE>) pub fn test_glwe_external_product_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GGSWEncryptSk<BE> Module<BE>: GGSWEncryptSk<BE>
+ GGSWPrepare<BE>
+ GGSWPreparedAlloc<BE> + GGSWPreparedAlloc<BE>
+ VecZnxFillUniform + VecZnxFillUniform
+ GLWEExternalProduct<BE> + GLWEExternalProduct<BE>
+ GLWEEncryptSk<BE> + GLWEEncryptSk<BE>
+ GLWENoise<BE> + GLWENoise<BE>
+ VecZnxRotateInplace<BE> + VecZnxRotateInplace<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>,
+ GLWESecretPreparedAlloc<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {

View File

@@ -8,8 +8,7 @@ use crate::{
GGLWEKeyswitch, GGLWENoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, GGLWEKeyswitch, GGLWENoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyLayout, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout, GLWESwitchingKeyPreparedAlloc,
GLWESwitchingKeyPrepare, GLWESwitchingKeyPreparedAlloc,
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared}, prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared},
}, },
noise::log2_std_noise_gglwe_product, noise::log2_std_noise_gglwe_product,
@@ -19,10 +18,8 @@ pub fn test_gglwe_switching_key_keyswitch<BE: Backend>(module: &Module<BE>)
where where
Module<BE>: GLWESwitchingKeyEncryptSk<BE> Module<BE>: GLWESwitchingKeyEncryptSk<BE>
+ GGLWEKeyswitch<BE> + GGLWEKeyswitch<BE>
+ GLWESecretPrepare<BE>
+ GLWESwitchingKeyPreparedAlloc<BE> + GLWESwitchingKeyPreparedAlloc<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESwitchingKeyPrepare<BE>
+ GGLWENoise<BE>, + GGLWENoise<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
@@ -165,9 +162,7 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<BE: Backend>(module: &Module<B
where where
Module<BE>: GLWESwitchingKeyEncryptSk<BE> Module<BE>: GLWESwitchingKeyEncryptSk<BE>
+ GGLWEKeyswitch<BE> + GGLWEKeyswitch<BE>
+ GLWESecretPrepare<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPreparedAlloc<BE>
+ GLWESwitchingKeyPrepare<BE>
+ GGLWENoise<BE> + GGLWENoise<BE>
+ GLWESwitchingKeyPreparedAlloc<BE>, + GLWESwitchingKeyPreparedAlloc<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,

View File

@@ -8,9 +8,8 @@ use crate::{
GGSWEncryptSk, GGSWKeyswitch, GGSWNoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, TensorKeyEncryptSk, GGSWEncryptSk, GGSWKeyswitch, GGSWNoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, TensorKeyEncryptSk,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GGSW, GGSWLayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyLayout, GGSW, GGSWLayout, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout,
GLWESwitchingKeyPrepare, GLWESwitchingKeyPreparedAlloc, TensorKey, TensorKeyLayout, TensorKeyPrepare, GLWESwitchingKeyPreparedAlloc, TensorKey, TensorKeyLayout, TensorKeyPreparedAlloc,
TensorKeyPreparedAlloc,
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared}, prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared},
}, },
noise::noise_ggsw_keyswitch, noise::noise_ggsw_keyswitch,
@@ -23,13 +22,10 @@ where
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ TensorKeyEncryptSk<BE> + TensorKeyEncryptSk<BE>
+ GGSWKeyswitch<BE> + GGSWKeyswitch<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ TensorKeyPreparedAlloc<BE> + TensorKeyPreparedAlloc<BE>
+ GLWESwitchingKeyPreparedAlloc<BE> + GLWESwitchingKeyPreparedAlloc<BE>
+ GGSWNoise<BE> + GGSWNoise<BE>,
+ GLWESwitchingKeyPrepare<BE>
+ TensorKeyPrepare<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {
@@ -191,13 +187,10 @@ where
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ TensorKeyEncryptSk<BE> + TensorKeyEncryptSk<BE>
+ GGSWKeyswitch<BE> + GGSWKeyswitch<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ TensorKeyPreparedAlloc<BE> + TensorKeyPreparedAlloc<BE>
+ GLWESwitchingKeyPreparedAlloc<BE> + GLWESwitchingKeyPreparedAlloc<BE>
+ GGSWNoise<BE> + GGSWNoise<BE>,
+ GLWESwitchingKeyPrepare<BE>
+ TensorKeyPrepare<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>, Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{ {

View File

@@ -8,8 +8,8 @@ use crate::{
GLWEEncryptSk, GLWEKeyswitch, GLWENoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore, GLWEEncryptSk, GLWEKeyswitch, GLWENoise, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPreparedApi, GLWESwitchingKey, GLWESwitchingKeyLayout,
GLWESwitchingKeyLayout, GLWESwitchingKeyPrepare, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedAlloc,
prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared}, prepared::{GLWESecretPrepared, GLWESwitchingKeyPrepared},
}, },
noise::log2_std_noise_gglwe_product, noise::log2_std_noise_gglwe_product,
@@ -22,9 +22,7 @@ where
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ GLWEEncryptSk<BE> + GLWEEncryptSk<BE>
+ GLWEKeyswitch<BE> + GLWEKeyswitch<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ GLWESwitchingKeyPrepare<BE>
+ GLWESwitchingKeyPreparedAlloc<BE> + GLWESwitchingKeyPreparedAlloc<BE>
+ GLWENoise<BE>, + GLWENoise<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
@@ -145,9 +143,7 @@ where
+ GLWESwitchingKeyEncryptSk<BE> + GLWESwitchingKeyEncryptSk<BE>
+ GLWEEncryptSk<BE> + GLWEEncryptSk<BE>
+ GLWEKeyswitch<BE> + GLWEKeyswitch<BE>
+ GLWESecretPreparedAlloc<BE> + GLWESecretPreparedApi<BE>
+ GLWESecretPrepare<BE>
+ GLWESwitchingKeyPrepare<BE>
+ GLWESwitchingKeyPreparedAlloc<BE> + GLWESwitchingKeyPreparedAlloc<BE>
+ GLWENoise<BE>, + GLWENoise<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>, ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,

Some files were not shown because too many files have changed in this diff Show More