diff --git a/poulpy-core/benches/external_product_glwe_fft64.rs b/poulpy-core/benches/external_product_glwe_fft64.rs index db78656..47b98ea 100644 --- a/poulpy-core/benches/external_product_glwe_fft64.rs +++ b/poulpy-core/benches/external_product_glwe_fft64.rs @@ -1,5 +1,5 @@ use poulpy_core::layouts::{ - Base2K, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, TorusPrecision, prepared::{GGSWPrepared, GLWESecretPrepared}, }; use std::hint::black_box; @@ -28,7 +28,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) { fn runner(p: Params) -> impl FnMut() { let module: Module = Module::::new(1 << p.log_n); - let n: RingDegree = RingDegree(module.n() as u32); + let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; let k_ct_in: TorusPrecision = p.k_ct_in; let k_ct_out: TorusPrecision = p.k_ct_out; @@ -140,7 +140,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) { fn runner(p: Params) -> impl FnMut() { let module: Module = Module::::new(1 << p.log_n); - let n: RingDegree = RingDegree(module.n() as u32); + let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; let k_glwe: TorusPrecision = p.k_ct; let k_ggsw: TorusPrecision = p.k_ggsw; diff --git a/poulpy-core/benches/keyswitch_glwe_fft64.rs b/poulpy-core/benches/keyswitch_glwe_fft64.rs index 5806b16..d603b60 100644 --- a/poulpy-core/benches/keyswitch_glwe_fft64.rs +++ b/poulpy-core/benches/keyswitch_glwe_fft64.rs @@ -1,6 +1,6 @@ use poulpy_core::layouts::{ - AutomorphismKey, AutomorphismKeyLayout, Base2K, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, - GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, RingDegree, TorusPrecision, + AutomorphismKey, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, + GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, TorusPrecision, prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, }; use std::{hint::black_box, time::Duration}; @@ -29,7 +29,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) { fn runner(p: Params) -> impl FnMut() { let module: Module = Module::::new(1 << p.log_n); - let n: RingDegree = RingDegree(module.n() as u32); + let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; let k_glwe_in: TorusPrecision = p.k_ct_in; let k_glwe_out: TorusPrecision = p.k_ct_out; @@ -151,7 +151,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) { fn runner(p: Params) -> impl FnMut() { let module: Module = Module::::new(1 << p.log_n); - let n: RingDegree = RingDegree(module.n() as u32); + let n: Degree = Degree(module.n() as u32); let base2k: Base2K = p.base2k; let k_ct: TorusPrecision = p.k_ct; let k_ksk: TorusPrecision = p.k_ksk; diff --git a/poulpy-core/examples/encryption.rs b/poulpy-core/examples/encryption.rs index aae1204..43a2b0e 100644 --- a/poulpy-core/examples/encryption.rs +++ b/poulpy-core/examples/encryption.rs @@ -2,7 +2,7 @@ use poulpy_backend::cpu_spqlios::FFT64Spqlios; use poulpy_core::{ GLWESub, SIGMA, layouts::{ - Base2K, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, TorusPrecision, prepared::GLWESecretPrepared, }, }; @@ -16,7 +16,7 @@ fn main() { // Ring degree let log_n: usize = 10; - let n: RingDegree = RingDegree(1 << log_n); + let n: Degree = Degree(1 << log_n); // Base-2-k (implicit digit decomposition) let base2k: Base2K = Base2K(14); diff --git a/poulpy-core/src/layouts/compressed/gglwe_atk.rs b/poulpy-core/src/layouts/compressed/gglwe_atk.rs index 61ba79a..276b695 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_atk.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_atk.rs @@ -4,8 +4,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - AutomorphismKey, AutomorphismKeyToMut, Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, - TorusPrecision, + AutomorphismKey, AutomorphismKeyToMut, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress, @@ -22,7 +21,7 @@ pub struct AutomorphismKeyCompressed { } impl LWEInfos for AutomorphismKeyCompressed { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.key.n() } @@ -80,6 +79,8 @@ impl fmt::Display for AutomorphismKeyCompressed { } } +impl AutomorphismKeyCompressedAlloc for Module where Self: GLWESwitchingKeyCompressedAlloc {} + pub trait AutomorphismKeyCompressedAlloc where Self: GLWESwitchingKeyCompressedAlloc, diff --git a/poulpy-core/src/layouts/compressed/gglwe_ct.rs b/poulpy-core/src/layouts/compressed/gglwe_ct.rs index 9216ec4..235cc4d 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_ct.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_ct.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, compressed::{GLWECompressed, GLWEDecompress}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -24,8 +24,8 @@ pub struct GGLWECompressed { } impl LWEInfos for GGLWECompressed { - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -88,7 +88,7 @@ impl fmt::Display for GGLWECompressed { pub trait GGLWECompressedAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_gglwe_compressed( &self, @@ -183,7 +183,7 @@ where } } -impl GGLWECompressedAlloc for Module where Self: GetRingDegree {} +impl GGLWECompressedAlloc for Module where Self: GetDegree {} impl GGLWECompressed> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self diff --git a/poulpy-core/src/layouts/compressed/gglwe_ksk.rs b/poulpy-core/src/layouts/compressed/gglwe_ksk.rs index fb963c5..d9574c4 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_ksk.rs @@ -4,8 +4,8 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToMut, LWEInfos, - Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToMut, + LWEInfos, Rank, TorusPrecision, compressed::{GGLWECompressed, GGLWECompressedAlloc, GGLWECompressedToMut, GGLWECompressedToRef, GGLWEDecompress}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -19,7 +19,7 @@ pub struct GLWESwitchingKeyCompressed { } impl LWEInfos for GLWESwitchingKeyCompressed { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.key.n() } @@ -81,6 +81,8 @@ impl fmt::Display for GLWESwitchingKeyCompressed { } } +impl GLWESwitchingKeyCompressedAlloc for Module where Self: GGLWECompressedAlloc {} + pub trait GLWESwitchingKeyCompressedAlloc where Self: GGLWECompressedAlloc, diff --git a/poulpy-core/src/layouts/compressed/gglwe_tsk.rs b/poulpy-core/src/layouts/compressed/gglwe_tsk.rs index ff2b8b8..d0202cc 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_tsk.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_tsk.rs @@ -4,7 +4,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TensorKey, TensorKeyToMut, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToMut, TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress, @@ -19,7 +19,7 @@ pub struct TensorKeyCompressed { } impl LWEInfos for TensorKeyCompressed { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.keys[0].n() } @@ -82,6 +82,8 @@ impl fmt::Display for TensorKeyCompressed { } } +impl TensorKeyCompressedAlloc for Module where Self: GLWESwitchingKeyCompressedAlloc {} + pub trait TensorKeyCompressedAlloc where Self: GLWESwitchingKeyCompressedAlloc, diff --git a/poulpy-core/src/layouts/compressed/ggsw_ct.rs b/poulpy-core/src/layouts/compressed/ggsw_ct.rs index adad621..454dae3 100644 --- a/poulpy-core/src/layouts/compressed/ggsw_ct.rs +++ b/poulpy-core/src/layouts/compressed/ggsw_ct.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, compressed::{GLWECompressed, GLWEDecompress}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -23,8 +23,8 @@ pub struct GGSWCompressed { } impl LWEInfos for GGSWCompressed { - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -76,9 +76,11 @@ impl FillUniform for GGSWCompressed { } } +impl GGSWCompressedAlloc for Module where Self: GetDegree {} + pub trait GGSWCompressedAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_ggsw_compressed( &self, diff --git a/poulpy-core/src/layouts/compressed/glwe_ct.rs b/poulpy-core/src/layouts/compressed/glwe_ct.rs index e558cf7..00f125a 100644 --- a/poulpy-core/src/layouts/compressed/glwe_ct.rs +++ b/poulpy-core/src/layouts/compressed/glwe_ct.rs @@ -6,9 +6,7 @@ use poulpy_hal::{ source::Source, }; -use crate::layouts::{ - Base2K, GLWE, GLWEInfos, GLWEToMut, GetRingDegree, LWEInfos, Rank, RingDegree, SetGLWEInfos, TorusPrecision, -}; +use crate::layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GetDegree, LWEInfos, Rank, SetGLWEInfos, TorusPrecision}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; @@ -34,8 +32,8 @@ impl LWEInfos for GLWECompressed { self.data.size() } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } } impl GLWEInfos for GLWECompressed { @@ -72,7 +70,7 @@ impl FillUniform for GLWECompressed { pub trait GLWECompressedAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_glwe_compressed(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWECompressed> { GLWECompressed { @@ -113,7 +111,7 @@ where } } -impl GLWECompressedAlloc for Module where Self: GetRingDegree {} +impl GLWECompressedAlloc for Module where Self: GetDegree {} impl GLWECompressed> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self @@ -169,7 +167,7 @@ impl WriterTo for GLWECompressed { pub trait GLWEDecompress where - Self: GetRingDegree + VecZnxFillUniform + VecZnxCopy, + Self: GetDegree + VecZnxFillUniform + VecZnxCopy, { fn decompress_glwe(&self, res: &mut R, other: &O) where @@ -203,7 +201,7 @@ where } } -impl GLWEDecompress for Module where Self: GetRingDegree + VecZnxFillUniform + VecZnxCopy {} +impl GLWEDecompress for Module where Self: GetDegree + VecZnxFillUniform + VecZnxCopy {} impl GLWE { pub fn decompress(&mut self, module: &M, other: &O) diff --git a/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs b/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs index 5bfa3eb..afdb493 100644 --- a/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyToMut, LWEInfos, Rank, RingDegree, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyToMut, LWEInfos, Rank, TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, @@ -26,7 +26,7 @@ impl LWEInfos for GLWEToLWESwitchingKeyCompressed { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } fn size(&self) -> usize { diff --git a/poulpy-core/src/layouts/compressed/lwe_ct.rs b/poulpy-core/src/layouts/compressed/lwe_ct.rs index 0393758..c21a6dd 100644 --- a/poulpy-core/src/layouts/compressed/lwe_ct.rs +++ b/poulpy-core/src/layouts/compressed/lwe_ct.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ source::Source, }; -use crate::layouts::{Base2K, LWE, LWEInfos, LWEToMut, RingDegree, TorusPrecision}; +use crate::layouts::{Base2K, Degree, LWE, LWEInfos, LWEToMut, TorusPrecision}; #[derive(PartialEq, Eq, Clone)] pub struct LWECompressed { @@ -28,8 +28,8 @@ impl LWEInfos for LWECompressed { self.k } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn size(&self) -> usize { diff --git a/poulpy-core/src/layouts/compressed/lwe_ksk.rs b/poulpy-core/src/layouts/compressed/lwe_ksk.rs index cf6ae9a..7e1b0cf 100644 --- a/poulpy-core/src/layouts/compressed/lwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/lwe_ksk.rs @@ -4,8 +4,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, LWESwitchingKeyToMut, Rank, RingDegree, - TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, LWESwitchingKeyToMut, Rank, TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress, @@ -25,7 +24,7 @@ impl LWEInfos for LWESwitchingKeyCompressed { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } fn size(&self) -> usize { diff --git a/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs b/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs index 33fcf49..545f126 100644 --- a/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs @@ -4,7 +4,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyToMut, Rank, RingDegree, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyToMut, Rank, TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, @@ -17,7 +17,7 @@ use std::fmt; pub struct LWEToGLWESwitchingKeyCompressed(pub(crate) GLWESwitchingKeyCompressed); impl LWEInfos for LWEToGLWESwitchingKeyCompressed { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } @@ -86,6 +86,8 @@ impl WriterTo for LWEToGLWESwitchingKeyCompressed { } } +impl LWEToGLWESwitchingKeyCompressedAlloc for Module where Self: GLWESwitchingKeyCompressedAlloc {} + pub trait LWEToGLWESwitchingKeyCompressedAlloc where Self: GLWESwitchingKeyCompressedAlloc, diff --git a/poulpy-core/src/layouts/gglwe_atk.rs b/poulpy-core/src/layouts/gglwe_atk.rs index 3c0afc1..b4b61c6 100644 --- a/poulpy-core/src/layouts/gglwe_atk.rs +++ b/poulpy-core/src/layouts/gglwe_atk.rs @@ -4,8 +4,8 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWE, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWE, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -14,7 +14,7 @@ use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct AutomorphismKeyLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -47,7 +47,7 @@ impl AutomorphismKey { } impl LWEInfos for AutomorphismKey { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.key.n() } @@ -97,7 +97,7 @@ impl LWEInfos for AutomorphismKeyLayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } } diff --git a/poulpy-core/src/layouts/gglwe_ct.rs b/poulpy-core/src/layouts/gglwe_ct.rs index 3b95d63..666293a 100644 --- a/poulpy-core/src/layouts/gglwe_ct.rs +++ b/poulpy-core/src/layouts/gglwe_ct.rs @@ -5,7 +5,7 @@ use poulpy_hal::{ source::Source, }; -use crate::layouts::{Base2K, Dnum, Dsize, GLWE, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}; +use crate::layouts::{Base2K, Degree, Dnum, Dsize, GLWE, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; @@ -37,7 +37,7 @@ pub trait SetGGLWEInfos { #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GGLWELayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_in: Rank, @@ -55,7 +55,7 @@ impl LWEInfos for GGLWELayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } } @@ -101,8 +101,8 @@ impl LWEInfos for GGLWE { self.k } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn size(&self) -> usize { @@ -193,7 +193,7 @@ impl GGLWE { pub trait GGLWEAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_gglwe( &self, @@ -293,7 +293,7 @@ where } } -impl GGLWEAlloc for Module where Self: GetRingDegree {} +impl GGLWEAlloc for Module where Self: GetDegree {} impl GGLWE> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self diff --git a/poulpy-core/src/layouts/gglwe_ksk.rs b/poulpy-core/src/layouts/gglwe_ksk.rs index e18648b..466f8ac 100644 --- a/poulpy-core/src/layouts/gglwe_ksk.rs +++ b/poulpy-core/src/layouts/gglwe_ksk.rs @@ -4,7 +4,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWE, GGLWEAlloc, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, RingDegree, + Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEAlloc, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -13,7 +13,7 @@ use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWESwitchingKeyLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_in: Rank, @@ -23,7 +23,7 @@ pub struct GLWESwitchingKeyLayout { } impl LWEInfos for GLWESwitchingKeyLayout { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } @@ -98,7 +98,7 @@ impl GLWESwtichingKeyGetMetaData for GLWESwitchingKey { } impl LWEInfos for GLWESwitchingKey { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.key.n() } diff --git a/poulpy-core/src/layouts/gglwe_tsk.rs b/poulpy-core/src/layouts/gglwe_tsk.rs index 6ef67b8..10523b1 100644 --- a/poulpy-core/src/layouts/gglwe_tsk.rs +++ b/poulpy-core/src/layouts/gglwe_tsk.rs @@ -4,8 +4,8 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -13,7 +13,7 @@ use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct TensorKeyLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -27,7 +27,7 @@ pub struct TensorKey { } impl LWEInfos for TensorKey { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.keys[0].n() } @@ -69,7 +69,7 @@ impl GGLWEInfos for TensorKey { } impl LWEInfos for TensorKeyLayout { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } diff --git a/poulpy-core/src/layouts/ggsw_ct.rs b/poulpy-core/src/layouts/ggsw_ct.rs index aac4a20..a4d091d 100644 --- a/poulpy-core/src/layouts/ggsw_ct.rs +++ b/poulpy-core/src/layouts/ggsw_ct.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ }; use std::fmt; -use crate::layouts::{Base2K, Dnum, Dsize, GLWE, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}; +use crate::layouts::{Base2K, Degree, Dnum, Dsize, GLWE, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision}; pub trait GGSWInfos where @@ -28,7 +28,7 @@ where #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GGSWLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -45,7 +45,7 @@ impl LWEInfos for GGSWLayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } } @@ -74,8 +74,8 @@ pub struct GGSW { } impl LWEInfos for GGSW { - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -152,11 +152,11 @@ impl GGSW { } } -impl GGSWAlloc for Module where Self: GetRingDegree {} +impl GGSWAlloc for Module where Self: GetDegree {} pub trait GGSWAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_ggsw(&self, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> GGSW> { let size: usize = k.0.div_ceil(base2k.0) as usize; diff --git a/poulpy-core/src/layouts/glwe_ct.rs b/poulpy-core/src/layouts/glwe_ct.rs index 2361e3c..edf7b4c 100644 --- a/poulpy-core/src/layouts/glwe_ct.rs +++ b/poulpy-core/src/layouts/glwe_ct.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ source::Source, }; -use crate::layouts::{Base2K, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}; +use crate::layouts::{Base2K, Degree, GetDegree, LWEInfos, Rank, TorusPrecision}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; @@ -32,14 +32,14 @@ pub trait SetGLWEInfos { #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWELayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, } impl LWEInfos for GLWELayout { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } @@ -96,8 +96,8 @@ impl LWEInfos for GLWE { self.k } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn size(&self) -> usize { @@ -148,7 +148,7 @@ impl FillUniform for GLWE { pub trait GLWEAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_glwe(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWE> { GLWE { @@ -185,7 +185,7 @@ where } } -impl GLWEAlloc for Module where Self: GetRingDegree {} +impl GLWEAlloc for Module where Self: GetDegree {} impl GLWE> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self diff --git a/poulpy-core/src/layouts/glwe_pk.rs b/poulpy-core/src/layouts/glwe_pk.rs index 16fc6ea..80b0a9d 100644 --- a/poulpy-core/src/layouts/glwe_pk.rs +++ b/poulpy-core/src/layouts/glwe_pk.rs @@ -4,7 +4,7 @@ use poulpy_hal::layouts::{ use crate::{ dist::Distribution, - layouts::{Base2K, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}, + layouts::{Base2K, Degree, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -18,7 +18,7 @@ pub struct GLWEPublicKey { #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWEPublicKeyLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -43,8 +43,8 @@ impl LWEInfos for GLWEPublicKey { self.k } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn size(&self) -> usize { @@ -67,7 +67,7 @@ impl LWEInfos for GLWEPublicKeyLayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } @@ -84,7 +84,7 @@ impl GLWEInfos for GLWEPublicKeyLayout { pub trait GLWEPublicKeyAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_glwe_public_key(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKey> { GLWEPublicKey { @@ -122,7 +122,7 @@ where } } -impl GLWEPublicKeyAlloc for Module where Self: GetRingDegree {} +impl GLWEPublicKeyAlloc for Module where Self: GetDegree {} impl GLWEPublicKey> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self diff --git a/poulpy-core/src/layouts/glwe_pt.rs b/poulpy-core/src/layouts/glwe_pt.rs index 3d5ce86..e3d7290 100644 --- a/poulpy-core/src/layouts/glwe_pt.rs +++ b/poulpy-core/src/layouts/glwe_pt.rs @@ -3,12 +3,12 @@ use std::fmt; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, VecZnx, VecZnxToMut, VecZnxToRef, ZnxInfos}; use crate::layouts::{ - Base2K, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetRingDegree, LWEInfos, Rank, RingDegree, SetGLWEInfos, TorusPrecision, + Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetDegree, LWEInfos, Rank, SetGLWEInfos, TorusPrecision, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWEPlaintextLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, } @@ -22,7 +22,7 @@ impl LWEInfos for GLWEPlaintextLayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } } @@ -62,8 +62,8 @@ impl LWEInfos for GLWEPlaintext { self.data.size() } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } } @@ -87,7 +87,7 @@ impl fmt::Display for GLWEPlaintext { pub trait GLWEPlaintextAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_glwe_plaintext(&self, base2k: Base2K, k: TorusPrecision) -> GLWEPlaintext> { GLWEPlaintext { @@ -124,7 +124,7 @@ where } } -impl GLWEPlaintextAlloc for Module where Self: GetRingDegree {} +impl GLWEPlaintextAlloc for Module where Self: GetDegree {} impl GLWEPlaintext> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self diff --git a/poulpy-core/src/layouts/glwe_sk.rs b/poulpy-core/src/layouts/glwe_sk.rs index 72ecd95..51b2f0d 100644 --- a/poulpy-core/src/layouts/glwe_sk.rs +++ b/poulpy-core/src/layouts/glwe_sk.rs @@ -8,12 +8,12 @@ use poulpy_hal::{ use crate::{ dist::Distribution, - layouts::{Base2K, GLWEInfos, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}, + layouts::{Base2K, Degree, GLWEInfos, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision}, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWESecretLayout { - pub n: RingDegree, + pub n: Degree, pub rank: Rank, } @@ -26,7 +26,7 @@ impl LWEInfos for GLWESecretLayout { TorusPrecision(0) } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } @@ -55,8 +55,8 @@ impl LWEInfos for GLWESecret { TorusPrecision(0) } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn size(&self) -> usize { @@ -78,7 +78,7 @@ impl GLWEInfos for GLWESecret { pub trait GLWESecretAlloc where - Self: GetRingDegree, + Self: GetDegree, { fn alloc_glwe_secret(&self, rank: Rank) -> GLWESecret> { GLWESecret { @@ -106,7 +106,7 @@ where } } -impl GLWESecretAlloc for Module where Self: GetRingDegree {} +impl GLWESecretAlloc for Module where Self: GetDegree {} impl GLWESecret> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self diff --git a/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs b/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs index 671f018..3aea241 100644 --- a/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs +++ b/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs @@ -4,15 +4,15 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, }; use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWEToLWEKeyLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_in: Rank, @@ -20,7 +20,7 @@ pub struct GLWEToLWEKeyLayout { } impl LWEInfos for GLWEToLWEKeyLayout { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } @@ -70,7 +70,7 @@ impl LWEInfos for GLWEToLWESwitchingKey { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } diff --git a/poulpy-core/src/layouts/lwe_ct.rs b/poulpy-core/src/layouts/lwe_ct.rs index 0c8831f..aed2807 100644 --- a/poulpy-core/src/layouts/lwe_ct.rs +++ b/poulpy-core/src/layouts/lwe_ct.rs @@ -5,11 +5,11 @@ use poulpy_hal::{ source::Source, }; -use crate::layouts::{Base2K, RingDegree, TorusPrecision}; +use crate::layouts::{Base2K, Degree, TorusPrecision}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; pub trait LWEInfos { - fn n(&self) -> RingDegree; + fn n(&self) -> Degree; fn k(&self) -> TorusPrecision; fn max_k(&self) -> TorusPrecision { TorusPrecision(self.k().0 * self.size() as u32) @@ -34,7 +34,7 @@ pub trait SetLWEInfos { #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWELayout { - pub n: RingDegree, + pub n: Degree, pub k: TorusPrecision, pub base2k: Base2K, } @@ -48,7 +48,7 @@ impl LWEInfos for LWELayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } } @@ -67,8 +67,8 @@ impl LWEInfos for LWE { fn k(&self) -> TorusPrecision { self.k } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32 - 1) + fn n(&self) -> Degree { + Degree(self.data.n() as u32 - 1) } fn size(&self) -> usize { @@ -126,7 +126,7 @@ where } pub trait LWEAlloc { - fn alloc_lwe(&self, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> LWE> { + fn alloc_lwe(&self, n: Degree, base2k: Base2K, k: TorusPrecision) -> LWE> { LWE { data: Zn::alloc((n + 1).into(), 1, k.0.div_ceil(base2k.0) as usize), k, @@ -141,7 +141,7 @@ pub trait LWEAlloc { self.alloc_lwe(infos.n(), infos.base2k(), infos.k()) } - fn bytes_of_lwe(&self, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> usize { + fn bytes_of_lwe(&self, n: Degree, base2k: Base2K, k: TorusPrecision) -> usize { Zn::bytes_of((n + 1).into(), 1, k.0.div_ceil(base2k.0) as usize) } @@ -164,7 +164,7 @@ impl LWE> { module.alloc_lwe_from_infos(infos) } - pub fn alloc(module: &M, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> Self + pub fn alloc(module: &M, n: Degree, base2k: Base2K, k: TorusPrecision) -> Self where M: LWEAlloc, { @@ -179,7 +179,7 @@ impl LWE> { module.bytes_of_lwe_from_infos(infos) } - pub fn bytes_of(module: &M, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> usize + pub fn bytes_of(module: &M, n: Degree, base2k: Base2K, k: TorusPrecision) -> usize where M: LWEAlloc, { diff --git a/poulpy-core/src/layouts/lwe_ksk.rs b/poulpy-core/src/layouts/lwe_ksk.rs index 2ff0391..e449da6 100644 --- a/poulpy-core/src/layouts/lwe_ksk.rs +++ b/poulpy-core/src/layouts/lwe_ksk.rs @@ -6,20 +6,20 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWESwitchingKeyLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub dnum: Dnum, } impl LWEInfos for LWESwitchingKeyLayout { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } @@ -68,7 +68,7 @@ impl LWEInfos for LWESwitchingKey { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } diff --git a/poulpy-core/src/layouts/lwe_pt.rs b/poulpy-core/src/layouts/lwe_pt.rs index 6ffd650..01ae19b 100644 --- a/poulpy-core/src/layouts/lwe_pt.rs +++ b/poulpy-core/src/layouts/lwe_pt.rs @@ -2,7 +2,7 @@ use std::fmt; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Zn, ZnToMut, ZnToRef, ZnxInfos}; -use crate::layouts::{Base2K, LWEInfos, RingDegree, TorusPrecision}; +use crate::layouts::{Base2K, Degree, LWEInfos, TorusPrecision}; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWEPlaintextLayout { @@ -19,8 +19,8 @@ impl LWEInfos for LWEPlaintextLayout { self.k } - fn n(&self) -> RingDegree { - RingDegree(0) + fn n(&self) -> Degree { + Degree(0) } fn size(&self) -> usize { @@ -43,8 +43,8 @@ impl LWEInfos for LWEPlaintext { self.k } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32 - 1) + fn n(&self) -> Degree { + Degree(self.data.n() as u32 - 1) } fn size(&self) -> usize { diff --git a/poulpy-core/src/layouts/lwe_sk.rs b/poulpy-core/src/layouts/lwe_sk.rs index d593ad5..b5f019f 100644 --- a/poulpy-core/src/layouts/lwe_sk.rs +++ b/poulpy-core/src/layouts/lwe_sk.rs @@ -5,7 +5,7 @@ use poulpy_hal::{ use crate::{ dist::Distribution, - layouts::{Base2K, LWEInfos, RingDegree, TorusPrecision}, + layouts::{Base2K, Degree, LWEInfos, TorusPrecision}, }; pub struct LWESecret { @@ -14,7 +14,7 @@ pub struct LWESecret { } pub trait LWESecretAlloc { - fn alloc_lwe_secret(&self, n: RingDegree) -> LWESecret> { + fn alloc_lwe_secret(&self, n: Degree) -> LWESecret> { LWESecret { data: ScalarZnx::alloc(n.into(), 1), dist: Distribution::NONE, @@ -25,7 +25,7 @@ pub trait LWESecretAlloc { impl LWESecretAlloc for Module {} impl LWESecret> { - pub fn alloc(module: &M, n: RingDegree) -> Self + pub fn alloc(module: &M, n: Degree) -> Self where M: LWESecretAlloc, { @@ -55,8 +55,8 @@ impl LWEInfos for LWESecret { TorusPrecision(0) } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn size(&self) -> usize { diff --git a/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs b/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs index 72b7514..1427447 100644 --- a/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs @@ -6,13 +6,13 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWEToGLWESwitchingKeyLayout { - pub n: RingDegree, + pub n: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_out: Rank, @@ -28,7 +28,7 @@ impl LWEInfos for LWEToGLWESwitchingKeyLayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n } } @@ -69,7 +69,7 @@ impl LWEInfos for LWEToGLWESwitchingKey { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } diff --git a/poulpy-core/src/layouts/mod.rs b/poulpy-core/src/layouts/mod.rs index 0d53307..abafe7e 100644 --- a/poulpy-core/src/layouts/mod.rs +++ b/poulpy-core/src/layouts/mod.rs @@ -37,12 +37,12 @@ pub use prepared::*; use poulpy_hal::layouts::{Backend, Module}; -pub trait GetRingDegree { - fn ring_degree(&self) -> RingDegree; +pub trait GetDegree { + fn ring_degree(&self) -> Degree; } -impl GetRingDegree for Module { - fn ring_degree(&self) -> RingDegree { +impl GetDegree for Module { + fn ring_degree(&self) -> Degree { Self::n(&self).into() } } @@ -204,14 +204,14 @@ macro_rules! newtype_u32 { }; } -newtype_u32!(RingDegree); +newtype_u32!(Degree); newtype_u32!(TorusPrecision); newtype_u32!(Base2K); newtype_u32!(Dnum); newtype_u32!(Rank); newtype_u32!(Dsize); -impl RingDegree { +impl Degree { pub fn log2(&self) -> usize { let n: usize = self.0 as usize; (usize::BITS - (n - 1).leading_zeros()) as _ diff --git a/poulpy-core/src/layouts/prepared/gglwe_atk.rs b/poulpy-core/src/layouts/prepared/gglwe_atk.rs index 7c8d0b9..d09b2e6 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_atk.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_atk.rs @@ -1,7 +1,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - AutomorphismKeyToRef, Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TorusPrecision, + AutomorphismKeyToRef, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -15,7 +15,7 @@ pub struct AutomorphismKeyPrepared { } impl LWEInfos for AutomorphismKeyPrepared { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.key.n() } diff --git a/poulpy-core/src/layouts/prepared/gglwe_ct.rs b/poulpy-core/src/layouts/prepared/gglwe_ct.rs index fd6033a..98d45b5 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_ct.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_ct.rs @@ -4,7 +4,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToRef, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToRef, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, }; #[derive(PartialEq, Eq)] @@ -16,8 +16,8 @@ pub struct GGLWEPrepared { } impl LWEInfos for GGLWEPrepared { - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -59,7 +59,7 @@ impl GGLWEInfos for GGLWEPrepared { pub trait GGLWEPreparedAlloc where - Self: GetRingDegree + VmpPMatAlloc + VmpPMatBytesOf, + Self: GetDegree + VmpPMatAlloc + VmpPMatBytesOf, { fn alloc_gglwe_prepared( &self, @@ -149,7 +149,7 @@ where } } -impl GGLWEPreparedAlloc for Module where Module: GetRingDegree + VmpPMatAlloc + VmpPMatBytesOf {} +impl GGLWEPreparedAlloc for Module where Module: GetDegree + VmpPMatAlloc + VmpPMatBytesOf {} impl GGLWEPrepared, B> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self @@ -201,7 +201,7 @@ impl GGLWEPrepared, B> { pub trait GGLWEPrepare where - Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare, + Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare, { fn prepare_gglwe_tmp_bytes(&self, infos: &A) -> usize where @@ -233,7 +233,7 @@ where } } -impl GGLWEPrepare for Module where Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare {} +impl GGLWEPrepare for Module where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare {} impl GGLWEPrepared { pub fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) diff --git a/poulpy-core/src/layouts/prepared/gglwe_ksk.rs b/poulpy-core/src/layouts/prepared/gglwe_ksk.rs index 2154b3e..d8ab0ca 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_ksk.rs @@ -1,8 +1,8 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToRef, GLWESwtichingKeyGetMetaData, - LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToRef, + GLWESwtichingKeyGetMetaData, LWEInfos, Rank, TorusPrecision, prepared::{GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef}, }; @@ -34,7 +34,7 @@ impl GLWESwtichingKeyGetMetaData for GLWESwitchingKeyPre } impl LWEInfos for GLWESwitchingKeyPrepared { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.key.n() } diff --git a/poulpy-core/src/layouts/prepared/gglwe_tsk.rs b/poulpy-core/src/layouts/prepared/gglwe_tsk.rs index 1ff5759..29f6e28 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_tsk.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_tsk.rs @@ -1,7 +1,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TensorKey, TensorKeyToRef, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -14,7 +14,7 @@ pub struct TensorKeyPrepared { } impl LWEInfos for TensorKeyPrepared { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.keys[0].n() } diff --git a/poulpy-core/src/layouts/prepared/ggsw_ct.rs b/poulpy-core/src/layouts/prepared/ggsw_ct.rs index 6365818..551660b 100644 --- a/poulpy-core/src/layouts/prepared/ggsw_ct.rs +++ b/poulpy-core/src/layouts/prepared/ggsw_ct.rs @@ -4,7 +4,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, }; #[derive(PartialEq, Eq)] @@ -16,8 +16,8 @@ pub struct GGSWPrepared { } impl LWEInfos for GGSWPrepared { - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -51,7 +51,7 @@ impl GGSWInfos for GGSWPrepared { pub trait GGSWPreparedAlloc where - Self: GetRingDegree + VmpPMatAlloc + VmpPMatBytesOf, + Self: GetDegree + VmpPMatAlloc + VmpPMatBytesOf, { fn alloc_ggsw_prepared( &self, @@ -135,7 +135,7 @@ where } } -impl GGSWPreparedAlloc for Module where Self: GetRingDegree + VmpPMatAlloc + VmpPMatBytesOf {} +impl GGSWPreparedAlloc for Module where Self: GetDegree + VmpPMatAlloc + VmpPMatBytesOf {} impl GGSWPrepared, B> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self @@ -177,7 +177,7 @@ impl GGSWPrepared { pub trait GGSWPrepare where - Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare, + Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare, { fn ggsw_prepare_tmp_bytes(&self, infos: &A) -> usize where @@ -207,7 +207,7 @@ where } } -impl GGSWPrepare for Module where Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare {} +impl GGSWPrepare for Module where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare {} impl GGSWPrepared, B> { pub fn prepare_tmp_bytes(&self, module: &M, infos: &A) -> usize diff --git a/poulpy-core/src/layouts/prepared/glwe_pk.rs b/poulpy-core/src/layouts/prepared/glwe_pk.rs index 62165c8..5212a11 100644 --- a/poulpy-core/src/layouts/prepared/glwe_pk.rs +++ b/poulpy-core/src/layouts/prepared/glwe_pk.rs @@ -5,9 +5,7 @@ use poulpy_hal::{ use crate::{ dist::Distribution, - layouts::{ - Base2K, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, - }, + layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision}, }; #[derive(PartialEq, Eq)] @@ -41,8 +39,8 @@ impl LWEInfos for GLWEPublicKeyPrepared { self.data.size() } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } } @@ -54,7 +52,7 @@ impl GLWEInfos for GLWEPublicKeyPrepared { pub trait GLWEPublicKeyPreparedAlloc where - Self: GetRingDegree + VecZnxDftAlloc + VecZnxDftBytesOf, + Self: GetDegree + VecZnxDftAlloc + VecZnxDftBytesOf, { fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared, B> { GLWEPublicKeyPrepared { @@ -120,7 +118,7 @@ impl GLWEPublicKeyPrepared, B> { pub trait GLWEPublicKeyPrepare where - Self: GetRingDegree + VecZnxDftApply, + Self: GetDegree + VecZnxDftApply, { fn prepare_glwe_public_key(&self, res: &mut R, other: &O) where @@ -146,7 +144,7 @@ where } } -impl GLWEPublicKeyPrepare for Module where Self: GetRingDegree + VecZnxDftApply {} +impl GLWEPublicKeyPrepare for Module where Self: GetDegree + VecZnxDftApply {} impl GLWEPublicKeyPrepared { pub fn prepare(&mut self, module: &M, other: &O) diff --git a/poulpy-core/src/layouts/prepared/glwe_sk.rs b/poulpy-core/src/layouts/prepared/glwe_sk.rs index f50f2dc..5eb9e07 100644 --- a/poulpy-core/src/layouts/prepared/glwe_sk.rs +++ b/poulpy-core/src/layouts/prepared/glwe_sk.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ use crate::{ dist::Distribution, layouts::{ - Base2K, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, GLWEInfos, GLWESecret, GLWESecretToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision, prepared::SetDist, }, }; @@ -31,8 +31,8 @@ impl LWEInfos for GLWESecretPrepared { TorusPrecision(0) } - fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + fn n(&self) -> Degree { + Degree(self.data.n() as u32) } fn size(&self) -> usize { @@ -47,7 +47,7 @@ impl GLWEInfos for GLWESecretPrepared { pub trait GLWESecretPreparedAlloc where - Self: GetRingDegree + SvpPPolBytesOf + SvpPPolAlloc, + Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc, { fn alloc_glwe_secret_prepared(&self, rank: Rank) -> GLWESecretPrepared, B> { GLWESecretPrepared { @@ -75,7 +75,7 @@ where } } -impl GLWESecretPreparedAlloc for Module where Self: GetRingDegree + SvpPPolBytesOf + SvpPPolAlloc {} +impl GLWESecretPreparedAlloc for Module where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc {} impl GLWESecretPrepared, B> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self @@ -110,8 +110,8 @@ impl GLWESecretPrepared, B> { } impl GLWESecretPrepared { - pub fn n(&self) -> RingDegree { - RingDegree(self.data.n() as u32) + pub fn n(&self) -> Degree { + Degree(self.data.n() as u32) } pub fn rank(&self) -> Rank { diff --git a/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs b/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs index 4c7f65e..cf1d875 100644 --- a/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs @@ -1,7 +1,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -20,7 +20,7 @@ impl LWEInfos for GLWEToLWESwitchingKeyPrepared { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } diff --git a/poulpy-core/src/layouts/prepared/lwe_ksk.rs b/poulpy-core/src/layouts/prepared/lwe_ksk.rs index 7e0b1da..83508d0 100644 --- a/poulpy-core/src/layouts/prepared/lwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/lwe_ksk.rs @@ -1,7 +1,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKeyToRef, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKeyToRef, Rank, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -20,7 +20,7 @@ impl LWEInfos for LWESwitchingKeyPrepared { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } diff --git a/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs b/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs index 6afb32a..43b006c 100644 --- a/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs @@ -1,7 +1,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch}; use crate::layouts::{ - Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKeyToRef, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKeyToRef, Rank, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -21,7 +21,7 @@ impl LWEInfos for LWEToGLWESwitchingKeyPrepared { self.0.k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.0.n() } diff --git a/poulpy-core/src/lib.rs b/poulpy-core/src/lib.rs index 2dcc77a..88a0ac5 100644 --- a/poulpy-core/src/lib.rs +++ b/poulpy-core/src/lib.rs @@ -25,4 +25,4 @@ pub use encryption::SIGMA; pub use scratch::*; -// pub mod tests; +pub mod tests; diff --git a/poulpy-core/src/tests/mod.rs b/poulpy-core/src/tests/mod.rs index 23b489b..5dcd276 100644 --- a/poulpy-core/src/tests/mod.rs +++ b/poulpy-core/src/tests/mod.rs @@ -1,182 +1,182 @@ -pub mod test_suite; +// pub mod test_suite; #[cfg(test)] mod serialization; -#[allow(unused_imports)] -use poulpy_hal::backend_test_suite; +//#[allow(unused_imports)] +// use poulpy_hal::backend_test_suite; -#[cfg(test)] -backend_test_suite!( - mod cpu_spqlios, - backend = poulpy_backend::cpu_spqlios::FFT64Spqlios, - size = 1<<8, - tests = { - // GLWE Encryption - glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, - glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, - glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, - glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, - // GLWE Keyswitch - glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, - glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, - // GLWE Automorphism - glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, - glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, - // GLWE External Product - glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, - glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, - // GLWE Trace - glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, - glwe_packing => crate::tests::test_suite::test_glwe_packing, - // GGLWE Encryption - gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, - gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, - gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, - gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, - gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, - gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, - // GGLWE Keyswitching - gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, - gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, - // GGLWE External Product - gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, - gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, - // GGLWE Automorphism - gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, - gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, - // GGSW Encryption - ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, - ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, - // GGSW Keyswitching - ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, - ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, - // GGSW External Product - ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, - ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, - // GGSW Automorphism - ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, - ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, - // LWE - lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, - glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, - lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, - } -); - -#[cfg(test)] -backend_test_suite!( - mod cpu_ref, - backend = poulpy_backend::cpu_fft64_ref::FFT64Ref, - size = 1<<8, - tests = { - // GLWE Encryption - glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, - glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, - glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, - glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, - // GLWE Keyswitch - glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, - glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, - // GLWE Automorphism - glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, - glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, - // GLWE External Product - glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, - glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, - // GLWE Trace - glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, - glwe_packing => crate::tests::test_suite::test_glwe_packing, - // GGLWE Encryption - gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, - gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, - gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, - gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, - gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, - gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, - // GGLWE Keyswitching - gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, - gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, - // GGLWE External Product - gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, - gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, - // GGLWE Automorphism - gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, - gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, - // GGSW Encryption - ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, - ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, - // GGSW Keyswitching - ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, - ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, - // GGSW External Product - ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, - ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, - // GGSW Automorphism - ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, - ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, - // LWE - lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, - glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, - lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, - } -); - -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] -#[cfg(test)] -backend_test_suite!( - mod cpu_avx, - backend = poulpy_backend::cpu_fft64_avx::FFT64Avx, - size = 1<<8, - tests = { - // GLWE Encryption - glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, - glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, - glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, - glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, - // GLWE Keyswitch - glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, - glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, - // GLWE Automorphism - glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, - glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, - // GLWE External Product - glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, - glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, - // GLWE Trace - glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, - glwe_packing => crate::tests::test_suite::test_glwe_packing, - // GGLWE Encryption - gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, - gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, - gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, - gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, - gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, - gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, - // GGLWE Keyswitching - gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, - gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, - // GGLWE External Product - gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, - gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, - // GGLWE Automorphism - gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, - gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, - // GGSW Encryption - ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, - ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, - // GGSW Keyswitching - ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, - ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, - // GGSW External Product - ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, - ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, - // GGSW Automorphism - ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, - ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, - // LWE - lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, - glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, - lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, - } -); +// #[cfg(test)] +// backend_test_suite!( +// mod cpu_spqlios, +// backend = poulpy_backend::cpu_spqlios::FFT64Spqlios, +// size = 1<<8, +// tests = { +// GLWE Encryption +// glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, +// glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, +// glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, +// glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, +// GLWE Keyswitch +// glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, +// glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, +// GLWE Automorphism +// glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, +// glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, +// GLWE External Product +// glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, +// glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, +// GLWE Trace +// glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, +// glwe_packing => crate::tests::test_suite::test_glwe_packing, +// GGLWE Encryption +// gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, +// gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, +// gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, +// gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, +// gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, +// gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, +// GGLWE Keyswitching +// gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, +// gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, +// GGLWE External Product +// gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, +// gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, +// GGLWE Automorphism +// gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, +// gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, +// GGSW Encryption +// ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, +// ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, +// GGSW Keyswitching +// ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, +// ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, +// GGSW External Product +// ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, +// ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, +// GGSW Automorphism +// ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, +// ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, +// LWE +// lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, +// glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, +// lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, +// } +// ); +// +// #[cfg(test)] +// backend_test_suite!( +// mod cpu_ref, +// backend = poulpy_backend::cpu_fft64_ref::FFT64Ref, +// size = 1<<8, +// tests = { +// GLWE Encryption +// glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, +// glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, +// glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, +// glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, +// GLWE Keyswitch +// glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, +// glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, +// GLWE Automorphism +// glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, +// glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, +// GLWE External Product +// glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, +// glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, +// GLWE Trace +// glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, +// glwe_packing => crate::tests::test_suite::test_glwe_packing, +// GGLWE Encryption +// gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, +// gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, +// gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, +// gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, +// gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, +// gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, +// GGLWE Keyswitching +// gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, +// gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, +// GGLWE External Product +// gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, +// gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, +// GGLWE Automorphism +// gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, +// gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, +// GGSW Encryption +// ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, +// ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, +// GGSW Keyswitching +// ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, +// ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, +// GGSW External Product +// ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, +// ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, +// GGSW Automorphism +// ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, +// ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, +// LWE +// lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, +// glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, +// lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, +// } +// ); +// +// #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] +// #[cfg(test)] +// backend_test_suite!( +// mod cpu_avx, +// backend = poulpy_backend::cpu_fft64_avx::FFT64Avx, +// size = 1<<8, +// tests = { +// GLWE Encryption +// glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, +// glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, +// glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, +// glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, +// GLWE Keyswitch +// glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, +// glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, +// GLWE Automorphism +// glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, +// glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, +// GLWE External Product +// glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, +// glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, +// GLWE Trace +// glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, +// glwe_packing => crate::tests::test_suite::test_glwe_packing, +// GGLWE Encryption +// gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, +// gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, +// gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, +// gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, +// gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, +// gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, +// GGLWE Keyswitching +// gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, +// gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, +// GGLWE External Product +// gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, +// gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, +// GGLWE Automorphism +// gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, +// gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, +// GGSW Encryption +// ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, +// ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, +// GGSW Keyswitching +// ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, +// ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, +// GGSW External Product +// ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, +// ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, +// GGSW Automorphism +// ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, +// ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, +// LWE +// lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, +// glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, +// lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, +// } +// ); diff --git a/poulpy-core/src/tests/serialization.rs b/poulpy-core/src/tests/serialization.rs index 3c4e564..c770311 100644 --- a/poulpy-core/src/tests/serialization.rs +++ b/poulpy-core/src/tests/serialization.rs @@ -1,4 +1,5 @@ -use poulpy_hal::test_suite::serialization::test_reader_writer_interface; +use poulpy_backend::FFT64Ref; +use poulpy_hal::{api::ModuleNew, layouts::Module, test_suite::serialization::test_reader_writer_interface}; use crate::layouts::{ AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE, @@ -20,123 +21,143 @@ const DSIZE: Dsize = Dsize(1); #[test] fn glwe_serialization() { - let original: GLWE> = GLWE::alloc(N_GLWE, BASE2K, K, RANK); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GLWE> = GLWE::alloc(&module, BASE2K, K, RANK); poulpy_hal::test_suite::serialization::test_reader_writer_interface(original); } #[test] fn glwe_compressed_serialization() { - let original: GLWECompressed> = GLWECompressed::alloc(N_GLWE, BASE2K, K, RANK); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GLWECompressed> = GLWECompressed::alloc(&module, BASE2K, K, RANK); test_reader_writer_interface(original); } #[test] fn lwe_serialization() { - let original: LWE> = LWE::alloc(N_LWE, BASE2K, K); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: LWE> = LWE::alloc(&module, N_LWE, BASE2K, K); test_reader_writer_interface(original); } #[test] fn lwe_compressed_serialization() { - let original: LWECompressed> = LWECompressed::alloc(BASE2K, K); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: LWECompressed> = LWECompressed::alloc(&module, BASE2K, K); test_reader_writer_interface(original); } #[test] fn test_gglwe_serialization() { - let original: GGLWE> = GGLWE::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GGLWE> = GGLWE::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_gglwe_compressed_serialization() { - let original: GGLWECompressed> = GGLWECompressed::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GGLWECompressed> = GGLWECompressed::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_glwe_switching_key_serialization() { - let original: GLWESwitchingKey> = GLWESwitchingKey::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GLWESwitchingKey> = GLWESwitchingKey::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_glwe_switching_key_compressed_serialization() { + let module: Module = Module::::new(N_GLWE.as_u32() as u64); let original: GLWESwitchingKeyCompressed> = - GLWESwitchingKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); + GLWESwitchingKeyCompressed::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_automorphism_key_serialization() { - let original: AutomorphismKey> = AutomorphismKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: AutomorphismKey> = AutomorphismKey::alloc_with(&module, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_automorphism_key_compressed_serialization() { - let original: AutomorphismKeyCompressed> = AutomorphismKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: AutomorphismKeyCompressed> = AutomorphismKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_tensor_key_serialization() { - let original: TensorKey> = TensorKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: TensorKey> = TensorKey::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn test_tensor_key_compressed_serialization() { - let original: TensorKeyCompressed> = TensorKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: TensorKeyCompressed> = TensorKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn glwe_to_lwe_switching_key_serialization() { - let original: GLWEToLWESwitchingKey> = GLWEToLWESwitchingKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GLWEToLWESwitchingKey> = GLWEToLWESwitchingKey::alloc(&module, BASE2K, K, RANK, DNUM); test_reader_writer_interface(original); } #[test] fn glwe_to_lwe_switching_key_compressed_serialization() { + let module: Module = Module::::new(N_GLWE.as_u32() as u64); let original: GLWEToLWESwitchingKeyCompressed> = - GLWEToLWESwitchingKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM); + GLWEToLWESwitchingKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM); test_reader_writer_interface(original); } #[test] fn lwe_to_glwe_switching_key_serialization() { - let original: LWEToGLWESwitchingKey> = LWEToGLWESwitchingKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: LWEToGLWESwitchingKey> = LWEToGLWESwitchingKey::alloc(&module, BASE2K, K, RANK, DNUM); test_reader_writer_interface(original); } #[test] fn lwe_to_glwe_switching_key_compressed_serialization() { + let module: Module = Module::::new(N_GLWE.as_u32() as u64); let original: LWEToGLWESwitchingKeyCompressed> = - LWEToGLWESwitchingKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM); + LWEToGLWESwitchingKeyCompressed::alloc_with(&module, BASE2K, K, RANK, DNUM); test_reader_writer_interface(original); } #[test] fn lwe_switching_key_serialization() { - let original: LWESwitchingKey> = LWESwitchingKey::alloc(N_GLWE, BASE2K, K, DNUM); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: LWESwitchingKey> = LWESwitchingKey::alloc(&module, BASE2K, K, DNUM); test_reader_writer_interface(original); } #[test] fn lwe_switching_key_compressed_serialization() { - let original: LWESwitchingKeyCompressed> = LWESwitchingKeyCompressed::alloc(N_GLWE, BASE2K, K, DNUM); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: LWESwitchingKeyCompressed> = LWESwitchingKeyCompressed::alloc(&module, BASE2K, K, DNUM); test_reader_writer_interface(original); } #[test] fn ggsw_serialization() { - let original: GGSW> = GGSW::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GGSW> = GGSW::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } #[test] fn ggsw_compressed_serialization() { - let original: GGSWCompressed> = GGSWCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); + let module: Module = Module::::new(N_GLWE.as_u32() as u64); + let original: GGSWCompressed> = GGSWCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE); test_reader_writer_interface(original); } diff --git a/poulpy-schemes/benches/circuit_bootstrapping.rs b/poulpy-schemes/benches/circuit_bootstrapping.rs index c2ce4ad..a1f39c6 100644 --- a/poulpy-schemes/benches/circuit_bootstrapping.rs +++ b/poulpy-schemes/benches/circuit_bootstrapping.rs @@ -188,8 +188,8 @@ where // Scratch space (4MB) let mut scratch: ScratchOwned = ScratchOwned::alloc(1 << 22); - let n_glwe: poulpy_core::layouts::RingDegree = params.cbt_infos.layout_brk.n_glwe(); - let n_lwe: poulpy_core::layouts::RingDegree = params.cbt_infos.layout_brk.n_lwe(); + let n_glwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_glwe(); + let n_lwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_lwe(); let rank: poulpy_core::layouts::Rank = params.cbt_infos.layout_brk.rank; let module: Module = Module::::new(n_glwe.as_u32() as u64); diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs index de4e30d..70bd910 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs @@ -38,7 +38,7 @@ impl LWEInfos for FheUintBlocks { self.blocks[0].k() } - fn n(&self) -> poulpy_core::layouts::RingDegree { + fn n(&self) -> poulpy_core::layouts::Degree { self.blocks[0].n() } } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs index 2f4bc44..c0cd09f 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block_prepared.rs @@ -225,7 +225,7 @@ impl LWEInfos for FheUintBlocksPrep< self.blocks[0].k() } - fn n(&self) -> poulpy_core::layouts::RingDegree { + fn n(&self) -> poulpy_core::layouts::Degree { self.blocks[0].n() } } @@ -256,7 +256,7 @@ impl LWEInfos for FheUintBlocksPrepDebug { self.blocks[0].k() } - fn n(&self) -> poulpy_core::layouts::RingDegree { + fn n(&self) -> poulpy_core::layouts::Degree { self.blocks[0].n() } } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs index 38ea57d..a3a779a 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/word.rs @@ -87,7 +87,7 @@ impl LWEInfos for FheUintWord { self.0.k() } - fn n(&self) -> poulpy_core::layouts::RingDegree { + fn n(&self) -> poulpy_core::layouts::Degree { self.0.n() } } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs index 924d53a..90175fb 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs @@ -1,6 +1,6 @@ #[cfg(test)] use poulpy_core::layouts::{ - AutomorphismKeyLayout, Base2K, Dnum, Dsize, GGSWLayout, GLWELayout, GLWEToLWEKeyLayout, Rank, RingDegree, TensorKeyLayout, + AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GGSWLayout, GLWELayout, GLWEToLWEKeyLayout, Rank, TensorKeyLayout, TorusPrecision, }; @@ -26,7 +26,7 @@ pub(crate) const TEST_RANK: u32 = 2; #[cfg(test)] pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout { - n: RingDegree(TEST_N_GLWE), + n: Degree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(TEST_K_GLWE), rank: Rank(TEST_RANK), @@ -34,7 +34,7 @@ pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout { #[cfg(test)] pub(crate) static TEST_GGSW_INFOS: GGSWLayout = GGSWLayout { - n: RingDegree(TEST_N_GLWE), + n: Degree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(TEST_K_GGSW), rank: Rank(TEST_RANK), @@ -46,15 +46,15 @@ pub(crate) static TEST_GGSW_INFOS: GGSWLayout = GGSWLayout { pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout { cbt: CircuitBootstrappingKeyLayout { layout_brk: BlindRotationKeyLayout { - n_glwe: RingDegree(TEST_N_GLWE), - n_lwe: RingDegree(TEST_N_LWE), + n_glwe: Degree(TEST_N_GLWE), + n_lwe: Degree(TEST_N_LWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(52), dnum: Dnum(3), rank: Rank(TEST_RANK), }, layout_atk: AutomorphismKeyLayout { - n: RingDegree(TEST_N_GLWE), + n: Degree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(52), rank: Rank(TEST_RANK), @@ -62,7 +62,7 @@ pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout { dsize: Dsize(1), }, layout_tsk: TensorKeyLayout { - n: RingDegree(TEST_N_GLWE), + n: Degree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(52), rank: Rank(TEST_RANK), @@ -71,7 +71,7 @@ pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout { }, }, ks: GLWEToLWEKeyLayout { - n: RingDegree(TEST_N_GLWE), + n: Degree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(39), rank_in: Rank(TEST_RANK), diff --git a/poulpy-schemes/src/tfhe/blind_rotation/key.rs b/poulpy-schemes/src/tfhe/blind_rotation/key.rs index 276539f..d9bb0a9 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/key.rs +++ b/poulpy-schemes/src/tfhe/blind_rotation/key.rs @@ -8,7 +8,7 @@ use std::{fmt, marker::PhantomData}; use poulpy_core::{ Distribution, layouts::{ - Base2K, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, TorusPrecision, prepared::GLWESecretPrepared, }, }; @@ -19,8 +19,8 @@ use crate::tfhe::blind_rotation::BlindRotationAlgo; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct BlindRotationKeyLayout { - pub n_glwe: RingDegree, - pub n_lwe: RingDegree, + pub n_glwe: Degree, + pub n_lwe: Degree, pub base2k: Base2K, pub k: TorusPrecision, pub dnum: Dnum, @@ -28,11 +28,11 @@ pub struct BlindRotationKeyLayout { } impl BlindRotationKeyInfos for BlindRotationKeyLayout { - fn n_glwe(&self) -> RingDegree { + fn n_glwe(&self) -> Degree { self.n_glwe } - fn n_lwe(&self) -> RingDegree { + fn n_lwe(&self) -> Degree { self.n_lwe } } @@ -62,7 +62,7 @@ impl LWEInfos for BlindRotationKeyLayout { self.k } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.n_glwe } } @@ -71,8 +71,8 @@ pub trait BlindRotationKeyInfos where Self: GGSWInfos, { - fn n_glwe(&self) -> RingDegree; - fn n_lwe(&self) -> RingDegree; + fn n_glwe(&self) -> Degree; + fn n_lwe(&self) -> Degree; } pub trait BlindRotationKeyAlloc { @@ -178,12 +178,12 @@ impl WriterTo for BlindRotationKey { } impl BlindRotationKeyInfos for BlindRotationKey { - fn n_glwe(&self) -> RingDegree { + fn n_glwe(&self) -> Degree { self.n() } - fn n_lwe(&self) -> RingDegree { - RingDegree(self.keys.len() as u32) + fn n_lwe(&self) -> Degree { + Degree(self.keys.len() as u32) } } @@ -206,7 +206,7 @@ impl LWEInfos for BlindRotationKey { self.keys[0].k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.keys[0].n() } diff --git a/poulpy-schemes/src/tfhe/blind_rotation/key_compressed.rs b/poulpy-schemes/src/tfhe/blind_rotation/key_compressed.rs index af7e40a..784d332 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/key_compressed.rs +++ b/poulpy-schemes/src/tfhe/blind_rotation/key_compressed.rs @@ -8,7 +8,7 @@ use std::{fmt, marker::PhantomData}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use poulpy_core::{ Distribution, - layouts::{Base2K, Dsize, GGSWInfos, GLWEInfos, LWEInfos, RingDegree, TorusPrecision, compressed::GGSWCompressed}, + layouts::{Base2K, Degree, Dsize, GGSWInfos, GLWEInfos, LWEInfos, TorusPrecision, compressed::GGSWCompressed}, }; use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyInfos}; @@ -94,17 +94,17 @@ impl WriterTo for BlindRotationKeyCompressed } impl BlindRotationKeyInfos for BlindRotationKeyCompressed { - fn n_glwe(&self) -> RingDegree { + fn n_glwe(&self) -> Degree { self.n() } - fn n_lwe(&self) -> RingDegree { - RingDegree(self.keys.len() as u32) + fn n_lwe(&self) -> Degree { + Degree(self.keys.len() as u32) } } impl LWEInfos for BlindRotationKeyCompressed { - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.keys[0].n() } diff --git a/poulpy-schemes/src/tfhe/blind_rotation/key_prepared.rs b/poulpy-schemes/src/tfhe/blind_rotation/key_prepared.rs index 1f99ef5..2001083 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/key_prepared.rs +++ b/poulpy-schemes/src/tfhe/blind_rotation/key_prepared.rs @@ -8,7 +8,7 @@ use std::marker::PhantomData; use poulpy_core::{ Distribution, layouts::{ - Base2K, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TorusPrecision, + Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::{GGSWPrepared, Prepare, PrepareAlloc}, }, }; @@ -30,12 +30,12 @@ pub struct BlindRotationKeyPrepared } impl BlindRotationKeyInfos for BlindRotationKeyPrepared { - fn n_glwe(&self) -> RingDegree { + fn n_glwe(&self) -> Degree { self.n() } - fn n_lwe(&self) -> RingDegree { - RingDegree(self.data.len() as u32) + fn n_lwe(&self) -> Degree { + Degree(self.data.len() as u32) } } @@ -48,7 +48,7 @@ impl LWEInfos for BlindRotationKeyP self.data[0].k() } - fn n(&self) -> RingDegree { + fn n(&self) -> Degree { self.data[0].n() }