From 2ea59310fbefca5cc899bd7e449ba2aebdb78397 Mon Sep 17 00:00:00 2001 From: Pro7ech Date: Wed, 15 Oct 2025 18:26:32 +0200 Subject: [PATCH] wip --- .../benches/external_product_glwe_fft64.rs | 6 +- poulpy-core/benches/keyswitch_glwe_fft64.rs | 8 +- poulpy-core/examples/encryption.rs | 4 +- .../src/encryption/compressed/gglwe_ksk.rs | 4 +- poulpy-core/src/encryption/gglwe_ksk.rs | 4 +- poulpy-core/src/encryption/gglwe_tsk.rs | 6 +- poulpy-core/src/encryption/lwe_ksk.rs | 5 +- poulpy-core/src/encryption/lwe_to_glwe_ksk.rs | 5 +- poulpy-core/src/keyswitching/lwe_ct.rs | 113 +++++++++++------- .../src/layouts/compressed/gglwe_atk.rs | 5 +- .../src/layouts/compressed/gglwe_ct.rs | 18 +-- .../src/layouts/compressed/gglwe_ksk.rs | 6 +- .../src/layouts/compressed/gglwe_tsk.rs | 4 +- poulpy-core/src/layouts/compressed/ggsw_ct.rs | 12 +- poulpy-core/src/layouts/compressed/glwe_ct.rs | 36 ++++-- .../src/layouts/compressed/glwe_to_lwe_ksk.rs | 4 +- poulpy-core/src/layouts/compressed/lwe_ct.rs | 6 +- poulpy-core/src/layouts/compressed/lwe_ksk.rs | 5 +- .../src/layouts/compressed/lwe_to_glwe_ksk.rs | 4 +- poulpy-core/src/layouts/gglwe_atk.rs | 10 +- poulpy-core/src/layouts/gglwe_ct.rs | 20 ++-- poulpy-core/src/layouts/gglwe_ksk.rs | 8 +- poulpy-core/src/layouts/gglwe_tsk.rs | 10 +- poulpy-core/src/layouts/ggsw_ct.rs | 18 +-- poulpy-core/src/layouts/glwe_ct.rs | 18 +-- poulpy-core/src/layouts/glwe_pk.rs | 18 +-- poulpy-core/src/layouts/glwe_pt.rs | 26 ++-- poulpy-core/src/layouts/glwe_sk.rs | 18 +-- poulpy-core/src/layouts/glwe_to_lwe_ksk.rs | 10 +- poulpy-core/src/layouts/lwe_ct.rs | 20 ++-- poulpy-core/src/layouts/lwe_ksk.rs | 10 +- poulpy-core/src/layouts/lwe_pt.rs | 10 +- poulpy-core/src/layouts/lwe_sk.rs | 10 +- poulpy-core/src/layouts/lwe_to_glwe_ksk.rs | 10 +- poulpy-core/src/layouts/mod.rs | 12 +- poulpy-core/src/layouts/prepared/gglwe_atk.rs | 4 +- poulpy-core/src/layouts/prepared/gglwe_ct.rs | 22 ++-- poulpy-core/src/layouts/prepared/gglwe_ksk.rs | 6 +- poulpy-core/src/layouts/prepared/gglwe_tsk.rs | 4 +- poulpy-core/src/layouts/prepared/ggsw_ct.rs | 24 ++-- poulpy-core/src/layouts/prepared/glwe_pk.rs | 18 +-- poulpy-core/src/layouts/prepared/glwe_sk.rs | 18 +-- .../src/layouts/prepared/glwe_to_lwe_ksk.rs | 4 +- poulpy-core/src/layouts/prepared/lwe_ksk.rs | 4 +- .../src/layouts/prepared/lwe_to_glwe_ksk.rs | 4 +- .../benches/circuit_bootstrapping.rs | 4 +- .../examples/circuit_bootstrapping.rs | 4 +- .../tfhe/bdd_arithmetic/ciphertexts/block.rs | 2 +- .../ciphertexts/block_prepared.rs | 4 +- .../tfhe/bdd_arithmetic/ciphertexts/word.rs | 2 +- .../src/tfhe/bdd_arithmetic/parameters.rs | 18 +-- .../src/tfhe/blind_rotation/cggi_algo.rs | 2 +- poulpy-schemes/src/tfhe/blind_rotation/key.rs | 24 ++-- .../src/tfhe/blind_rotation/key_compressed.rs | 10 +- .../src/tfhe/blind_rotation/key_prepared.rs | 10 +- .../tests/generic_blind_rotation.rs | 2 +- .../tests/circuit_bootstrapping.rs | 4 +- 57 files changed, 363 insertions(+), 314 deletions(-) diff --git a/poulpy-core/benches/external_product_glwe_fft64.rs b/poulpy-core/benches/external_product_glwe_fft64.rs index fad8523..2849e3d 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, Degree, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, RingDegree, TorusPrecision, prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, }; 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: Degree = Degree(module.n() as u32); + let n: RingDegree = RingDegree(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; @@ -137,7 +137,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: Degree = Degree(module.n() as u32); + let n: RingDegree = RingDegree(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 736b53c..fc1dc69 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, Degree, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, - GLWESwitchingKeyLayout, Rank, TorusPrecision, + AutomorphismKey, AutomorphismKeyLayout, Base2K, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, + GLWESwitchingKeyLayout, Rank, RingDegree, TorusPrecision, prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, GLWESwitchingKeyPrepared, PrepareAlloc}, }; 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: Degree = Degree(module.n() as u32); + let n: RingDegree = RingDegree(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; @@ -148,7 +148,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: Degree = Degree(module.n() as u32); + let n: RingDegree = RingDegree(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 d4b17b9..efd838e 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::{ GLWEOperations, SIGMA, layouts::{ - Base2K, Degree, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, TorusPrecision, + Base2K, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, RingDegree, TorusPrecision, prepared::{GLWESecretPrepared, PrepareAlloc}, }, }; @@ -16,7 +16,7 @@ fn main() { // Ring degree let log_n: usize = 10; - let n: Degree = Degree(1 << log_n); + let n: RingDegree = RingDegree(1 << log_n); // Base-2-k (implicit digit decomposition) let base2k: Base2K = Base2K(14); diff --git a/poulpy-core/src/encryption/compressed/gglwe_ksk.rs b/poulpy-core/src/encryption/compressed/gglwe_ksk.rs index 5c2c8c2..93519b9 100644 --- a/poulpy-core/src/encryption/compressed/gglwe_ksk.rs +++ b/poulpy-core/src/encryption/compressed/gglwe_ksk.rs @@ -7,7 +7,7 @@ use poulpy_hal::{ use crate::{ encryption::compressed::gglwe_ct::GGLWECompressedEncryptSk, layouts::{ - Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, + GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, RingDegree, compressed::{GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedToMut}, prepared::GLWESecretPrepared, }, @@ -110,7 +110,7 @@ where ); }); - let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(Degree(n as u32), sk_out.rank()); + let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(RingDegree(n as u32), sk_out.rank()); { let (mut tmp, _) = scratch_2.take_scalar_znx(n, 1); (0..sk_out.rank().into()).for_each(|i| { diff --git a/poulpy-core/src/encryption/gglwe_ksk.rs b/poulpy-core/src/encryption/gglwe_ksk.rs index 8c3a70f..ef9b5bf 100644 --- a/poulpy-core/src/encryption/gglwe_ksk.rs +++ b/poulpy-core/src/encryption/gglwe_ksk.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, prepared::GLWESecretPrepared, + GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, RingDegree, prepared::GLWESecretPrepared, }; impl GLWESwitchingKey> { @@ -85,7 +85,7 @@ impl GLWESwitchingKey { ); }); - let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(Degree(n as u32), sk_out.rank()); + let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(RingDegree(n as u32), sk_out.rank()); { let (mut tmp, _) = scratch_2.take_scalar_znx(n, 1); (0..sk_out.rank().into()).for_each(|i| { diff --git a/poulpy-core/src/encryption/gglwe_tsk.rs b/poulpy-core/src/encryption/gglwe_tsk.rs index 672808b..62d1a15 100644 --- a/poulpy-core/src/encryption/gglwe_tsk.rs +++ b/poulpy-core/src/encryption/gglwe_tsk.rs @@ -10,7 +10,7 @@ use poulpy_hal::{ }; use crate::layouts::{ - Degree, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, TensorKey, prepared::GLWESecretPrepared, + GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, RingDegree, TensorKey, prepared::GLWESecretPrepared, }; impl TensorKey> { @@ -23,7 +23,7 @@ impl TensorKey> { + module.bytes_of_vec_znx_dft(infos.rank_out().into(), 1) + module.bytes_of_vec_znx_big(1, 1) + module.bytes_of_vec_znx_dft(1, 1) - + GLWESecret::bytes_of(Degree(module.n() as u32), Rank(1)) + + GLWESecret::bytes_of(RingDegree(module.n() as u32), Rank(1)) + GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos) } } @@ -64,7 +64,7 @@ impl TensorKey { assert_eq!(self.n(), sk.n()); } - let n: Degree = sk.n(); + let n: RingDegree = sk.n(); let rank: Rank = self.rank_out(); let (mut sk_dft_prep, scratch_1) = scratch.take_glwe_secret_prepared(n, rank); diff --git a/poulpy-core/src/encryption/lwe_ksk.rs b/poulpy-core/src/encryption/lwe_ksk.rs index 1f1820a..2fd60ff 100644 --- a/poulpy-core/src/encryption/lwe_ksk.rs +++ b/poulpy-core/src/encryption/lwe_ksk.rs @@ -10,7 +10,8 @@ use poulpy_hal::{ }; use crate::layouts::{ - Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank, prepared::GLWESecretPrepared, + GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank, RingDegree, + prepared::GLWESecretPrepared, }; impl LWESwitchingKey> { @@ -34,7 +35,7 @@ impl LWESwitchingKey> { 1, "rank_out > 1 is not supported for LWESwitchingKey" ); - GLWESecret::bytes_of(Degree(module.n() as u32), Rank(1)) + GLWESecret::bytes_of(RingDegree(module.n() as u32), Rank(1)) + GLWESecretPrepared::bytes_of(module, Rank(1)) + GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos) } diff --git a/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs b/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs index 56a6701..041c7c4 100644 --- a/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs @@ -9,7 +9,7 @@ use poulpy_hal::{ source::Source, }; -use crate::layouts::{Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank}; +use crate::layouts::{GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank, RingDegree}; impl LWEToGLWESwitchingKey> { pub fn encrypt_sk_tmp_bytes(module: &Module, infos: &A) -> usize @@ -22,7 +22,8 @@ impl LWEToGLWESwitchingKey> { Rank(1), "rank_in != 1 is not supported for LWEToGLWESwitchingKey" ); - GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos) + GLWESecret::bytes_of(Degree(module.n() as u32), infos.rank_in()) + GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos) + + GLWESecret::bytes_of(RingDegree(module.n() as u32), infos.rank_in()) } } diff --git a/poulpy-core/src/keyswitching/lwe_ct.rs b/poulpy-core/src/keyswitching/lwe_ct.rs index 3ee7b75..8546ccb 100644 --- a/poulpy-core/src/keyswitching/lwe_ct.rs +++ b/poulpy-core/src/keyswitching/lwe_ct.rs @@ -1,22 +1,48 @@ use poulpy_hal::{ - api::{ - ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftApply, - VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, - VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, - }, - layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxView, ZnxViewMut, ZnxZero}, + api::ScratchAvailable, + layouts::{Backend, DataMut, Module, Scratch, ZnxView, ZnxViewMut, ZnxZero}, }; use crate::{ + ScratchTakeCore, keyswitching::glwe_ct::GLWEKeySwitch, - layouts::{prepared::LWESwitchingKeyPrepared, GGLWEInfos, GLWEAlloc, GLWELayout, GetDegree, LWEToRef, LWEInfos, Rank, TorusPrecision, GLWE, LWE}, + layouts::{ + GGLWEInfos, GLWE, GLWEAlloc, GLWELayout, LWE, LWEInfos, LWEToMut, LWEToRef, Rank, TorusPrecision, + prepared::{LWESwitchingKeyPrepared, LWESwitchingKeyPreparedToRef}, + }, }; +impl LWE> { + pub fn keyswitch_tmp_bytes(module: &M, res_infos: &R, a_infos: &A, key_infos: &K) -> usize + where + R: LWEInfos, + A: LWEInfos, + K: GGLWEInfos, + M: LWEKeySwitch, + { + module.lwe_keyswitch_tmp_bytes(res_infos, a_infos, key_infos) + } +} + +impl LWE { + pub fn keyswitch(&mut self, module: &M, a: &A, ksk: &K, scratch: &mut Scratch) + where + A: LWEToRef, + K: LWESwitchingKeyPreparedToRef, + Scratch: ScratchTakeCore, + M: LWEKeySwitch, + { + module.lwe_keyswitch(self, a, ksk, scratch); + } +} + +impl LWEKeySwitch for Module where Self: LWEKeySwitch {} + pub trait LWEKeySwitch where Self: GLWEKeySwitch + GLWEAlloc, { - fn keyswitch_tmp_bytes(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize + fn lwe_keyswitch_tmp_bytes(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize where R: LWEInfos, A: LWEInfos, @@ -25,14 +51,14 @@ where let max_k: TorusPrecision = a_infos.k().max(res_infos.k()); let glwe_a_infos: GLWELayout = GLWELayout { - n: GetDegree::n(self), + n: self.ring_degree(), base2k: a_infos.base2k(), k: max_k, rank: Rank(1), }; let glwe_res_infos: GLWELayout = GLWELayout { - n: GetDegree::n(self), + n: self.ring_degree(), base2k: res_infos.base2k(), k: max_k, rank: Rank(1), @@ -45,39 +71,46 @@ where glwe_in + glwe_out + ks } - fn keyswitch( - &mut self, - module: &Module, - a: &A, - ksk: &K, - scratch: &mut Scratch, - ) where + fn lwe_keyswitch(&self, res: &mut R, a: &A, ksk: &K, scratch: &mut Scratch) + where + R: LWEToMut, A: LWEToRef, - DKs: DataRef, - Scratch: ScratchAvailable, + K: LWESwitchingKeyPreparedToRef, + Scratch: ScratchTakeCore, { - assert!(self.n() <= module.n() as u32); - assert!(a.n() <= module.n() as u32); - assert!(scratch.available() >= LWE::keyswitch_tmp_bytes(module, self, a, ksk)); + let res: &mut LWE<&mut [u8]> = &mut res.to_mut(); + let a: &LWE<&[u8]> = &a.to_ref(); + let ksk: &LWESwitchingKeyPrepared<&[u8], BE> = &ksk.to_ref(); - let max_k: TorusPrecision = self.k().max(a.k()); + assert!(res.n().as_usize() <= self.n()); + assert!(a.n().as_usize() <= self.n()); + assert_eq!(ksk.n(), self.n() as u32); + assert!(scratch.available() >= self.lwe_keyswitch_tmp_bytes(res, a, ksk)); + + let max_k: TorusPrecision = res.k().max(a.k()); let a_size: usize = a.k().div_ceil(ksk.base2k()) as usize; - let (mut glwe_in, scratch_1) = scratch.take_glwe_ct(&GLWELayout { - n: ksk.n(), - base2k: a.base2k(), - k: max_k, - rank: Rank(1), - }); + let (mut glwe_in, scratch_1) = scratch.take_glwe_ct( + self, + &GLWELayout { + n: ksk.n(), + base2k: a.base2k(), + k: max_k, + rank: Rank(1), + }, + ); glwe_in.data.zero(); - let (mut glwe_out, scratch_1) = scratch_1.take_glwe_ct(&GLWELayout { - n: ksk.n(), - base2k: self.base2k(), - k: max_k, - rank: Rank(1), - }); + let (mut glwe_out, scratch_1) = scratch_1.take_glwe_ct( + self, + &GLWELayout { + n: ksk.n(), + base2k: res.base2k(), + k: max_k, + rank: Rank(1), + }, + ); let n_lwe: usize = a.n().into(); @@ -87,13 +120,7 @@ where glwe_in.data.at_mut(1, i)[..n_lwe].copy_from_slice(&data_lwe[1..]); } - glwe_out.keyswitch(module, &glwe_in, &ksk.0, scratch_1); - self.sample_extract(&glwe_out); + self.glwe_keyswitch(&mut glwe_out, &glwe_in, &ksk.0, scratch_1); + res.sample_extract(&glwe_out); } } - -impl LWE> {} - -impl LWE { - -} diff --git a/poulpy-core/src/layouts/compressed/gglwe_atk.rs b/poulpy-core/src/layouts/compressed/gglwe_atk.rs index 629e3f3..61ba79a 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_atk.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_atk.rs @@ -4,7 +4,8 @@ use poulpy_hal::{ }; use crate::layouts::{ - AutomorphismKey, AutomorphismKeyToMut, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, + AutomorphismKey, AutomorphismKeyToMut, Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, + TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress, @@ -21,7 +22,7 @@ pub struct AutomorphismKeyCompressed { } impl LWEInfos for AutomorphismKeyCompressed { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.key.n() } diff --git a/poulpy-core/src/layouts/compressed/gglwe_ct.rs b/poulpy-core/src/layouts/compressed/gglwe_ct.rs index f54f759..9216ec4 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, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, compressed::{GLWECompressed, GLWEDecompress}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -24,8 +24,8 @@ pub struct GGLWECompressed { } impl LWEInfos for GGLWECompressed { - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -88,7 +88,7 @@ impl fmt::Display for GGLWECompressed { pub trait GGLWECompressedAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_gglwe_compressed( &self, @@ -115,7 +115,7 @@ where GGLWECompressed { data: MatZnx::alloc( - self.n().into(), + self.ring_degree().into(), dnum.into(), rank_in.into(), 1, @@ -133,7 +133,7 @@ where where A: GGLWEInfos, { - assert_eq!(infos.n(), self.n()); + assert_eq!(infos.n(), self.ring_degree()); self.alloc_gglwe_compressed( infos.base2k(), infos.k(), @@ -160,7 +160,7 @@ where ); MatZnx::bytes_of( - self.n().into(), + self.ring_degree().into(), dnum.into(), rank_in.into(), 1, @@ -172,7 +172,7 @@ where where A: GGLWEInfos, { - assert_eq!(infos.n(), self.n()); + assert_eq!(infos.n(), self.ring_degree()); self.bytes_of_gglwe_compressed( infos.base2k(), infos.k(), @@ -183,7 +183,7 @@ where } } -impl GGLWECompressedAlloc for Module where Self: GetDegree {} +impl GGLWECompressedAlloc for Module where Self: GetRingDegree {} 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 f59587b..fb963c5 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToMut, - LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToMut, LWEInfos, + Rank, RingDegree, 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) -> Degree { + fn n(&self) -> RingDegree { self.key.n() } diff --git a/poulpy-core/src/layouts/compressed/gglwe_tsk.rs b/poulpy-core/src/layouts/compressed/gglwe_tsk.rs index 7c20bba..ff2b8b8 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToMut, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TensorKey, TensorKeyToMut, TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress, @@ -19,7 +19,7 @@ pub struct TensorKeyCompressed { } impl LWEInfos for TensorKeyCompressed { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.keys[0].n() } diff --git a/poulpy-core/src/layouts/compressed/ggsw_ct.rs b/poulpy-core/src/layouts/compressed/ggsw_ct.rs index fa1c46b..adad621 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, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, compressed::{GLWECompressed, GLWEDecompress}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -23,8 +23,8 @@ pub struct GGSWCompressed { } impl LWEInfos for GGSWCompressed { - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -78,7 +78,7 @@ impl FillUniform for GGSWCompressed { pub trait GGSWCompressedAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_ggsw_compressed( &self, @@ -104,7 +104,7 @@ where GGSWCompressed { data: MatZnx::alloc( - self.n().into(), + self.ring_degree().into(), dnum.into(), (rank + 1).into(), 1, @@ -147,7 +147,7 @@ where ); MatZnx::bytes_of( - self.n().into(), + self.ring_degree().into(), dnum.into(), (rank + 1).into(), 1, diff --git a/poulpy-core/src/layouts/compressed/glwe_ct.rs b/poulpy-core/src/layouts/compressed/glwe_ct.rs index 8a5193f..e558cf7 100644 --- a/poulpy-core/src/layouts/compressed/glwe_ct.rs +++ b/poulpy-core/src/layouts/compressed/glwe_ct.rs @@ -6,7 +6,9 @@ use poulpy_hal::{ source::Source, }; -use crate::layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GetDegree, LWEInfos, Rank, SetGLWEInfos, TorusPrecision}; +use crate::layouts::{ + Base2K, GLWE, GLWEInfos, GLWEToMut, GetRingDegree, LWEInfos, Rank, RingDegree, SetGLWEInfos, TorusPrecision, +}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; @@ -32,8 +34,8 @@ impl LWEInfos for GLWECompressed { self.data.size() } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } } impl GLWEInfos for GLWECompressed { @@ -70,11 +72,15 @@ impl FillUniform for GLWECompressed { pub trait GLWECompressedAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_glwe_compressed(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWECompressed> { GLWECompressed { - data: VecZnx::alloc(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize), + data: VecZnx::alloc( + self.ring_degree().into(), + 1, + k.0.div_ceil(base2k.0) as usize, + ), base2k, k, rank, @@ -86,24 +92,28 @@ where where A: GLWEInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.alloc_glwe_compressed(infos.base2k(), infos.k(), infos.rank()) } fn bytes_of_glwe_compressed(&self, base2k: Base2K, k: TorusPrecision) -> usize { - VecZnx::bytes_of(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize) + VecZnx::bytes_of( + self.ring_degree().into(), + 1, + k.0.div_ceil(base2k.0) as usize, + ) } fn bytes_of_glwe_compressed_from_infos(&self, infos: &A) -> usize where A: GLWEInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.bytes_of_glwe_compressed(infos.base2k(), infos.k()) } } -impl GLWECompressedAlloc for Module where Self: GetDegree {} +impl GLWECompressedAlloc for Module where Self: GetRingDegree {} impl GLWECompressed> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self @@ -159,7 +169,7 @@ impl WriterTo for GLWECompressed { pub trait GLWEDecompress where - Self: GetDegree + VecZnxFillUniform + VecZnxCopy, + Self: GetRingDegree + VecZnxFillUniform + VecZnxCopy, { fn decompress_glwe(&self, res: &mut R, other: &O) where @@ -171,10 +181,10 @@ where let other: &GLWECompressed<&[u8]> = &other.to_ref(); assert_eq!( res.n(), - self.n(), + self.ring_degree(), "invalid receiver: res.n()={} != other.n()={}", res.n(), - self.n() + self.ring_degree() ); assert_eq!(res.lwe_layout(), other.lwe_layout()); @@ -193,7 +203,7 @@ where } } -impl GLWEDecompress for Module where Self: GetDegree + VecZnxFillUniform + VecZnxCopy {} +impl GLWEDecompress for Module where Self: GetRingDegree + 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 afdb493..5bfa3eb 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyToMut, LWEInfos, Rank, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyToMut, LWEInfos, Rank, RingDegree, TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, @@ -26,7 +26,7 @@ impl LWEInfos for GLWEToLWESwitchingKeyCompressed { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { 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 c21a6dd..0393758 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, Degree, LWE, LWEInfos, LWEToMut, TorusPrecision}; +use crate::layouts::{Base2K, LWE, LWEInfos, LWEToMut, RingDegree, TorusPrecision}; #[derive(PartialEq, Eq, Clone)] pub struct LWECompressed { @@ -28,8 +28,8 @@ impl LWEInfos for LWECompressed { self.k } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(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 7e1b0cf..cf6ae9a 100644 --- a/poulpy-core/src/layouts/compressed/lwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/lwe_ksk.rs @@ -4,7 +4,8 @@ use poulpy_hal::{ }; use crate::layouts::{ - Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, LWESwitchingKeyToMut, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, LWESwitchingKeyToMut, Rank, RingDegree, + TorusPrecision, compressed::{ GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut, GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress, @@ -24,7 +25,7 @@ impl LWEInfos for LWESwitchingKeyCompressed { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { 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 5545518..33fcf49 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyToMut, Rank, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyToMut, Rank, RingDegree, 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) -> Degree { + fn n(&self) -> RingDegree { self.0.n() } diff --git a/poulpy-core/src/layouts/gglwe_atk.rs b/poulpy-core/src/layouts/gglwe_atk.rs index 2c99bd2..eb93bf4 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, Degree, Dnum, Dsize, GGLWEInfos, GLWE, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWE, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -13,7 +13,7 @@ use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct AutomorphismKeyLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -34,7 +34,7 @@ impl AutomorphismKey { } impl LWEInfos for AutomorphismKey { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.key.n() } @@ -84,7 +84,7 @@ impl LWEInfos for AutomorphismKeyLayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } } diff --git a/poulpy-core/src/layouts/gglwe_ct.rs b/poulpy-core/src/layouts/gglwe_ct.rs index 532a65a..3b95d63 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, Degree, Dnum, Dsize, GLWE, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision}; +use crate::layouts::{Base2K, Dnum, Dsize, GLWE, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, 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: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_in: Rank, @@ -55,7 +55,7 @@ impl LWEInfos for GGLWELayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } } @@ -101,8 +101,8 @@ impl LWEInfos for GGLWE { self.k } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn size(&self) -> usize { @@ -162,7 +162,7 @@ impl fmt::Display for GGLWE { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "(GGLWECiphertext: k={} base2k={} dsize={}) {}", + "(GGLWE: k={} base2k={} dsize={}) {}", self.k().0, self.base2k().0, self.dsize().0, @@ -193,7 +193,7 @@ impl GGLWE { pub trait GGLWEAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_gglwe( &self, @@ -220,7 +220,7 @@ where GGLWE { data: MatZnx::alloc( - self.n().into(), + self.ring_degree().into(), dnum.into(), rank_in.into(), (rank_out + 1).into(), @@ -270,7 +270,7 @@ where ); MatZnx::bytes_of( - self.n().into(), + self.ring_degree().into(), dnum.into(), rank_in.into(), (rank_out + 1).into(), @@ -293,7 +293,7 @@ where } } -impl GGLWEAlloc for Module where Self: GetDegree {} +impl GGLWEAlloc for Module where Self: GetRingDegree {} 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 b261230..ddb4de7 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, Degree, Dnum, Dsize, GGLWE, GGLWEAlloc, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, + Base2K, Dnum, Dsize, GGLWE, GGLWEAlloc, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, RingDegree, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -13,7 +13,7 @@ use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWESwitchingKeyLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_in: Rank, @@ -23,7 +23,7 @@ pub struct GLWESwitchingKeyLayout { } impl LWEInfos for GLWESwitchingKeyLayout { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } @@ -98,7 +98,7 @@ impl GLWESwtichingKeyGetMetaData for GLWESwitchingKey { } impl LWEInfos for GLWESwitchingKey { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.key.n() } diff --git a/poulpy-core/src/layouts/gglwe_tsk.rs b/poulpy-core/src/layouts/gglwe_tsk.rs index 10523b1..6ef67b8 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -13,7 +13,7 @@ use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct TensorKeyLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -27,7 +27,7 @@ pub struct TensorKey { } impl LWEInfos for TensorKey { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.keys[0].n() } @@ -69,7 +69,7 @@ impl GGLWEInfos for TensorKey { } impl LWEInfos for TensorKeyLayout { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } diff --git a/poulpy-core/src/layouts/ggsw_ct.rs b/poulpy-core/src/layouts/ggsw_ct.rs index 494d06a..aac4a20 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, Degree, Dnum, Dsize, GLWE, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision}; +use crate::layouts::{Base2K, Dnum, Dsize, GLWE, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}; pub trait GGSWInfos where @@ -28,7 +28,7 @@ where #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GGSWLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -45,7 +45,7 @@ impl LWEInfos for GGSWLayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } } @@ -74,8 +74,8 @@ pub struct GGSW { } impl LWEInfos for GGSW { - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -152,11 +152,11 @@ impl GGSW { } } -impl GGSWAlloc for Module where Self: GetDegree {} +impl GGSWAlloc for Module where Self: GetRingDegree {} pub trait GGSWAlloc where - Self: GetDegree, + Self: GetRingDegree, { 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; @@ -175,7 +175,7 @@ where GGSW { data: MatZnx::alloc( - self.n().into(), + self.ring_degree().into(), dnum.into(), (rank + 1).into(), (rank + 1).into(), @@ -216,7 +216,7 @@ where ); MatZnx::bytes_of( - self.n().into(), + self.ring_degree().into(), dnum.into(), (rank + 1).into(), (rank + 1).into(), diff --git a/poulpy-core/src/layouts/glwe_ct.rs b/poulpy-core/src/layouts/glwe_ct.rs index 328b1ff..2361e3c 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, Degree, GetDegree, LWEInfos, Rank, TorusPrecision}; +use crate::layouts::{Base2K, GetRingDegree, LWEInfos, Rank, RingDegree, 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: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, } impl LWEInfos for GLWELayout { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } @@ -96,8 +96,8 @@ impl LWEInfos for GLWE { self.k } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn size(&self) -> usize { @@ -148,12 +148,12 @@ impl FillUniform for GLWE { pub trait GLWEAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_glwe(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWE> { GLWE { data: VecZnx::alloc( - self.n().into(), + self.ring_degree().into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize, ), @@ -171,7 +171,7 @@ where fn bytes_of_glwe(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize { VecZnx::bytes_of( - self.n().into(), + self.ring_degree().into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize, ) @@ -185,7 +185,7 @@ where } } -impl GLWEAlloc for Module where Self: GetDegree {} +impl GLWEAlloc for Module where Self: GetRingDegree {} 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 0b0d058..16fc6ea 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, Degree, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision}, + layouts::{Base2K, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; @@ -18,7 +18,7 @@ pub struct GLWEPublicKey { #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWEPublicKeyLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank: Rank, @@ -43,8 +43,8 @@ impl LWEInfos for GLWEPublicKey { self.k } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn size(&self) -> usize { @@ -67,7 +67,7 @@ impl LWEInfos for GLWEPublicKeyLayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } @@ -84,12 +84,12 @@ impl GLWEInfos for GLWEPublicKeyLayout { pub trait GLWEPublicKeyAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_glwe_public_key(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKey> { GLWEPublicKey { data: VecZnx::alloc( - self.n().into(), + self.ring_degree().into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize, ), @@ -108,7 +108,7 @@ where fn bytes_of_glwe_public_key(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize { VecZnx::bytes_of( - self.n().into(), + self.ring_degree().into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize, ) @@ -122,7 +122,7 @@ where } } -impl GLWEPublicKeyAlloc for Module where Self: GetDegree {} +impl GLWEPublicKeyAlloc for Module where Self: GetRingDegree {} 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 e7ae403..3d5ce86 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, Degree, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetDegree, LWEInfos, Rank, SetGLWEInfos, TorusPrecision, + Base2K, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetRingDegree, LWEInfos, Rank, RingDegree, SetGLWEInfos, TorusPrecision, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWEPlaintextLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, } @@ -22,7 +22,7 @@ impl LWEInfos for GLWEPlaintextLayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } } @@ -62,8 +62,8 @@ impl LWEInfos for GLWEPlaintext { self.data.size() } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } } @@ -87,11 +87,15 @@ impl fmt::Display for GLWEPlaintext { pub trait GLWEPlaintextAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_glwe_plaintext(&self, base2k: Base2K, k: TorusPrecision) -> GLWEPlaintext> { GLWEPlaintext { - data: VecZnx::alloc(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize), + data: VecZnx::alloc( + self.ring_degree().into(), + 1, + k.0.div_ceil(base2k.0) as usize, + ), base2k, k, } @@ -105,7 +109,11 @@ where } fn bytes_of_glwe_plaintext(&self, base2k: Base2K, k: TorusPrecision) -> usize { - VecZnx::bytes_of(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize) + VecZnx::bytes_of( + self.ring_degree().into(), + 1, + k.0.div_ceil(base2k.0) as usize, + ) } fn bytes_of_glwe_plaintext_from_infos(&self, infos: &A) -> usize @@ -116,7 +124,7 @@ where } } -impl GLWEPlaintextAlloc for Module where Self: GetDegree {} +impl GLWEPlaintextAlloc for Module where Self: GetRingDegree {} 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 65caa70..9166388 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, Degree, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision}, + layouts::{Base2K, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWESecretLayout { - pub n: Degree, + pub n: RingDegree, pub rank: Rank, } @@ -26,7 +26,7 @@ impl LWEInfos for GLWESecretLayout { TorusPrecision(0) } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } @@ -55,8 +55,8 @@ impl LWEInfos for GLWESecret { TorusPrecision(0) } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn size(&self) -> usize { @@ -72,11 +72,11 @@ impl GLWEInfos for GLWESecret { pub trait GLWESecretAlloc where - Self: GetDegree, + Self: GetRingDegree, { fn alloc_glwe_secret(&self, rank: Rank) -> GLWESecret> { GLWESecret { - data: ScalarZnx::alloc(self.n().into(), rank.into()), + data: ScalarZnx::alloc(self.ring_degree().into(), rank.into()), dist: Distribution::NONE, } } @@ -89,7 +89,7 @@ where } fn bytes_of_glwe_secret(&self, rank: Rank) -> usize { - ScalarZnx::bytes_of(self.n().into(), rank.into()) + ScalarZnx::bytes_of(self.ring_degree().into(), rank.into()) } fn bytes_of_glwe_secret_from_infos(&self, infos: &A) -> usize @@ -100,7 +100,7 @@ where } } -impl GLWESecretAlloc for Module where Self: GetDegree {} +impl GLWESecretAlloc for Module where Self: GetRingDegree {} 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 3aea241..671f018 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, }; use std::fmt; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct GLWEToLWEKeyLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_in: Rank, @@ -20,7 +20,7 @@ pub struct GLWEToLWEKeyLayout { } impl LWEInfos for GLWEToLWEKeyLayout { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } @@ -70,7 +70,7 @@ impl LWEInfos for GLWEToLWESwitchingKey { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.0.n() } diff --git a/poulpy-core/src/layouts/lwe_ct.rs b/poulpy-core/src/layouts/lwe_ct.rs index aed2807..0c8831f 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, Degree, TorusPrecision}; +use crate::layouts::{Base2K, RingDegree, TorusPrecision}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; pub trait LWEInfos { - fn n(&self) -> Degree; + fn n(&self) -> RingDegree; 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: Degree, + pub n: RingDegree, pub k: TorusPrecision, pub base2k: Base2K, } @@ -48,7 +48,7 @@ impl LWEInfos for LWELayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } } @@ -67,8 +67,8 @@ impl LWEInfos for LWE { fn k(&self) -> TorusPrecision { self.k } - fn n(&self) -> Degree { - Degree(self.data.n() as u32 - 1) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32 - 1) } fn size(&self) -> usize { @@ -126,7 +126,7 @@ where } pub trait LWEAlloc { - fn alloc_lwe(&self, n: Degree, base2k: Base2K, k: TorusPrecision) -> LWE> { + fn alloc_lwe(&self, n: RingDegree, 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: Degree, base2k: Base2K, k: TorusPrecision) -> usize { + fn bytes_of_lwe(&self, n: RingDegree, 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: Degree, base2k: Base2K, k: TorusPrecision) -> Self + pub fn alloc(module: &M, n: RingDegree, 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: Degree, base2k: Base2K, k: TorusPrecision) -> usize + pub fn bytes_of(module: &M, n: RingDegree, 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 e449da6..2ff0391 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWESwitchingKeyLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub dnum: Dnum, } impl LWEInfos for LWESwitchingKeyLayout { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } @@ -68,7 +68,7 @@ impl LWEInfos for LWESwitchingKey { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.0.n() } diff --git a/poulpy-core/src/layouts/lwe_pt.rs b/poulpy-core/src/layouts/lwe_pt.rs index 01ae19b..6ffd650 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, Degree, LWEInfos, TorusPrecision}; +use crate::layouts::{Base2K, LWEInfos, RingDegree, TorusPrecision}; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWEPlaintextLayout { @@ -19,8 +19,8 @@ impl LWEInfos for LWEPlaintextLayout { self.k } - fn n(&self) -> Degree { - Degree(0) + fn n(&self) -> RingDegree { + RingDegree(0) } fn size(&self) -> usize { @@ -43,8 +43,8 @@ impl LWEInfos for LWEPlaintext { self.k } - fn n(&self) -> Degree { - Degree(self.data.n() as u32 - 1) + fn n(&self) -> RingDegree { + RingDegree(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 b5f019f..d593ad5 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, Degree, LWEInfos, TorusPrecision}, + layouts::{Base2K, LWEInfos, RingDegree, TorusPrecision}, }; pub struct LWESecret { @@ -14,7 +14,7 @@ pub struct LWESecret { } pub trait LWESecretAlloc { - fn alloc_lwe_secret(&self, n: Degree) -> LWESecret> { + fn alloc_lwe_secret(&self, n: RingDegree) -> 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: Degree) -> Self + pub fn alloc(module: &M, n: RingDegree) -> Self where M: LWESecretAlloc, { @@ -55,8 +55,8 @@ impl LWEInfos for LWESecret { TorusPrecision(0) } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(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 1427447..72b7514 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, - GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut, + GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, }; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct LWEToGLWESwitchingKeyLayout { - pub n: Degree, + pub n: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub rank_out: Rank, @@ -28,7 +28,7 @@ impl LWEInfos for LWEToGLWESwitchingKeyLayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n } } @@ -69,7 +69,7 @@ impl LWEInfos for LWEToGLWESwitchingKey { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.0.n() } diff --git a/poulpy-core/src/layouts/mod.rs b/poulpy-core/src/layouts/mod.rs index 1d8e30d..09064f3 100644 --- a/poulpy-core/src/layouts/mod.rs +++ b/poulpy-core/src/layouts/mod.rs @@ -35,12 +35,12 @@ pub use lwe_to_glwe_ksk::*; use poulpy_hal::layouts::{Backend, Module}; -pub trait GetDegree { - fn n(&self) -> Degree; +pub trait GetRingDegree { + fn ring_degree(&self) -> RingDegree; } -impl GetDegree for Module { - fn n(&self) -> Degree { +impl GetRingDegree for Module { + fn ring_degree(&self) -> RingDegree { Self::n(&self).into() } } @@ -202,14 +202,14 @@ macro_rules! newtype_u32 { }; } -newtype_u32!(Degree); +newtype_u32!(RingDegree); newtype_u32!(TorusPrecision); newtype_u32!(Base2K); newtype_u32!(Dnum); newtype_u32!(Rank); newtype_u32!(Dsize); -impl Degree { +impl RingDegree { 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 d09b2e6..7c8d0b9 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, + AutomorphismKeyToRef, Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -15,7 +15,7 @@ pub struct AutomorphismKeyPrepared { } impl LWEInfos for AutomorphismKeyPrepared { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.key.n() } diff --git a/poulpy-core/src/layouts/prepared/gglwe_ct.rs b/poulpy-core/src/layouts/prepared/gglwe_ct.rs index 180393a..fd6033a 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, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToRef, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToRef, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, }; #[derive(PartialEq, Eq)] @@ -16,8 +16,8 @@ pub struct GGLWEPrepared { } impl LWEInfos for GGLWEPrepared { - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -59,7 +59,7 @@ impl GGLWEInfos for GGLWEPrepared { pub trait GGLWEPreparedAlloc where - Self: GetDegree + VmpPMatAlloc + VmpPMatBytesOf, + Self: GetRingDegree + VmpPMatAlloc + VmpPMatBytesOf, { fn alloc_gglwe_prepared( &self, @@ -96,7 +96,7 @@ where where A: GGLWEInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.alloc_gglwe_prepared( infos.base2k(), infos.k(), @@ -137,7 +137,7 @@ where where A: GGLWEInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.bytes_of_gglwe_prepared( infos.base2k(), infos.k(), @@ -149,7 +149,7 @@ where } } -impl GGLWEPreparedAlloc for Module where Module: GetDegree + VmpPMatAlloc + VmpPMatBytesOf {} +impl GGLWEPreparedAlloc for Module where Module: GetRingDegree + 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: GetDegree + VmpPrepareTmpBytes + VmpPrepare, + Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare, { fn prepare_gglwe_tmp_bytes(&self, infos: &A) -> usize where @@ -223,8 +223,8 @@ where let mut res: GGLWEPrepared<&mut [u8], B> = res.to_mut(); let other: GGLWE<&[u8]> = other.to_ref(); - assert_eq!(res.n(), self.n()); - assert_eq!(other.n(), self.n()); + 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); @@ -233,7 +233,7 @@ where } } -impl GGLWEPrepare for Module where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare {} +impl GGLWEPrepare for Module where Self: GetRingDegree + 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 d8ab0ca..2154b3e 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToRef, - GLWESwtichingKeyGetMetaData, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToRef, GLWESwtichingKeyGetMetaData, + LWEInfos, Rank, RingDegree, TorusPrecision, prepared::{GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef}, }; @@ -34,7 +34,7 @@ impl GLWESwtichingKeyGetMetaData for GLWESwitchingKeyPre } impl LWEInfos for GLWESwitchingKeyPrepared { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.key.n() } diff --git a/poulpy-core/src/layouts/prepared/gglwe_tsk.rs b/poulpy-core/src/layouts/prepared/gglwe_tsk.rs index 8357e40..2d054c1 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TensorKey, TensorKeyToRef, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -14,7 +14,7 @@ pub struct TensorKeyPrepared { } impl LWEInfos for TensorKeyPrepared { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { 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 f8f85c9..6365818 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, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, }; #[derive(PartialEq, Eq)] @@ -16,8 +16,8 @@ pub struct GGSWPrepared { } impl LWEInfos for GGSWPrepared { - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn base2k(&self) -> Base2K { @@ -51,7 +51,7 @@ impl GGSWInfos for GGSWPrepared { pub trait GGSWPreparedAlloc where - Self: GetDegree + VmpPMatAlloc + VmpPMatBytesOf, + Self: GetRingDegree + VmpPMatAlloc + VmpPMatBytesOf, { fn alloc_ggsw_prepared( &self, @@ -92,7 +92,7 @@ where where A: GGSWInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.alloc_ggsw_prepared( infos.base2k(), infos.k(), @@ -124,7 +124,7 @@ where where A: GGSWInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.bytes_of_ggsw_prepared( infos.base2k(), infos.k(), @@ -135,7 +135,7 @@ where } } -impl GGSWPreparedAlloc for Module where Self: GetDegree + VmpPMatAlloc + VmpPMatBytesOf {} +impl GGSWPreparedAlloc for Module where Self: GetRingDegree + VmpPMatAlloc + VmpPMatBytesOf {} impl GGSWPrepared, B> { pub fn alloc_from_infos(module: &M, infos: &A) -> Self @@ -177,13 +177,13 @@ impl GGSWPrepared { pub trait GGSWPrepare where - Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare, + Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare, { fn ggsw_prepare_tmp_bytes(&self, infos: &A) -> usize where A: GGSWInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.vmp_prepare_tmp_bytes( infos.dnum().into(), (infos.rank() + 1).into(), @@ -198,8 +198,8 @@ where { let mut res: GGSWPrepared<&mut [u8], B> = res.to_mut(); let other: GGSW<&[u8]> = other.to_ref(); - assert_eq!(res.n(), self.n()); - assert_eq!(other.n(), self.n()); + 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); @@ -207,7 +207,7 @@ where } } -impl GGSWPrepare for Module where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare {} +impl GGSWPrepare for Module where Self: GetRingDegree + 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 8aa0a59..bca1826 100644 --- a/poulpy-core/src/layouts/prepared/glwe_pk.rs +++ b/poulpy-core/src/layouts/prepared/glwe_pk.rs @@ -5,7 +5,9 @@ use poulpy_hal::{ use crate::{ dist::Distribution, - layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision}, + layouts::{ + Base2K, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, + }, }; #[derive(PartialEq, Eq)] @@ -39,8 +41,8 @@ impl LWEInfos for GLWEPublicKeyPrepared { self.data.size() } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } } @@ -52,7 +54,7 @@ impl GLWEInfos for GLWEPublicKeyPrepared { pub trait GLWEPublicKeyPreparedAlloc where - Self: GetDegree + VecZnxDftAlloc + VecZnxDftBytesOf, + Self: GetRingDegree + VecZnxDftAlloc + VecZnxDftBytesOf, { fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared, B> { GLWEPublicKeyPrepared { @@ -118,7 +120,7 @@ impl GLWEPublicKeyPrepared, B> { pub trait GLWEPublicKeyPrepare where - Self: GetDegree + VecZnxDftApply, + Self: GetRingDegree + VecZnxDftApply, { fn prepare_glwe_public_key(&self, res: &mut R, other: &O) where @@ -129,8 +131,8 @@ where let mut res: GLWEPublicKeyPrepared<&mut [u8], B> = res.to_mut(); let other: GLWEPublicKey<&[u8]> = other.to_ref(); - assert_eq!(res.n(), self.n()); - assert_eq!(other.n(), self.n()); + 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()); @@ -144,7 +146,7 @@ where } } -impl GLWEPublicKeyPrepare for Module where Self: GetDegree + VecZnxDftApply {} +impl GLWEPublicKeyPrepare for Module where Self: GetRingDegree + 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 9e3f2ef..ac7e11f 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, Degree, GLWEInfos, GLWESecret, GLWESecretToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision, + Base2K, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, prepared::SetDist, }, }; @@ -31,8 +31,8 @@ impl LWEInfos for GLWESecretPrepared { TorusPrecision(0) } - fn n(&self) -> Degree { - Degree(self.data.n() as u32) + fn n(&self) -> RingDegree { + RingDegree(self.data.n() as u32) } fn size(&self) -> usize { @@ -47,7 +47,7 @@ impl GLWEInfos for GLWESecretPrepared { pub trait GLWESecretPreparedAlloc where - Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc, + Self: GetRingDegree + SvpPPolBytesOf + SvpPPolAlloc, { fn alloc_glwe_secret_prepared(&self, rank: Rank) -> GLWESecretPrepared, B> { GLWESecretPrepared { @@ -59,7 +59,7 @@ where where A: GLWEInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.alloc_glwe_secret_prepared(infos.rank()) } @@ -70,12 +70,12 @@ where where A: GLWEInfos, { - assert_eq!(self.n(), infos.n()); + assert_eq!(self.ring_degree(), infos.n()); self.bytes_of_glwe_secret(infos.rank()) } } -impl GLWESecretPreparedAlloc for Module where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc {} +impl GLWESecretPreparedAlloc for Module where Self: GetRingDegree + 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) -> Degree { - Degree(self.data.n() as u32) + pub fn n(&self) -> RingDegree { + RingDegree(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 63dec0b..55a7bf9 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -20,7 +20,7 @@ impl LWEInfos for GLWEToLWESwitchingKeyPrepared { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.0.n() } diff --git a/poulpy-core/src/layouts/prepared/lwe_ksk.rs b/poulpy-core/src/layouts/prepared/lwe_ksk.rs index 49914f2..a857bf9 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKeyToRef, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKeyToRef, Rank, RingDegree, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -20,7 +20,7 @@ impl LWEInfos for LWESwitchingKeyPrepared { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { 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 8a2242d..5df692e 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, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKeyToRef, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKeyToRef, Rank, RingDegree, TorusPrecision, prepared::{ GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut, GLWESwitchingKeyPreparedToRef, @@ -21,7 +21,7 @@ impl LWEInfos for LWEToGLWESwitchingKeyPrepared { self.0.k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.0.n() } diff --git a/poulpy-schemes/benches/circuit_bootstrapping.rs b/poulpy-schemes/benches/circuit_bootstrapping.rs index a1f39c6..c2ce4ad 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::Degree = params.cbt_infos.layout_brk.n_glwe(); - let n_lwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_lwe(); + 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 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/examples/circuit_bootstrapping.rs b/poulpy-schemes/examples/circuit_bootstrapping.rs index 3fd8c6e..3383114 100644 --- a/poulpy-schemes/examples/circuit_bootstrapping.rs +++ b/poulpy-schemes/examples/circuit_bootstrapping.rs @@ -1,8 +1,8 @@ use poulpy_core::{ GLWEOperations, layouts::{ - AutomorphismKeyLayout, GGSW, GGSWLayout, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, LWE, LWELayout, - LWEInfos, LWEPlaintext, LWESecret, TensorKeyLayout, + AutomorphismKeyLayout, GGSW, GGSWLayout, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, LWE, LWEInfos, LWELayout, + LWEPlaintext, LWESecret, TensorKeyLayout, prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc}, }, }; diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/ciphertexts/block.rs index 70bd910..de4e30d 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::Degree { + fn n(&self) -> poulpy_core::layouts::RingDegree { 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 c0cd09f..2f4bc44 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::Degree { + fn n(&self) -> poulpy_core::layouts::RingDegree { self.blocks[0].n() } } @@ -256,7 +256,7 @@ impl LWEInfos for FheUintBlocksPrepDebug { self.blocks[0].k() } - fn n(&self) -> poulpy_core::layouts::Degree { + fn n(&self) -> poulpy_core::layouts::RingDegree { 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 a3a779a..38ea57d 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::Degree { + fn n(&self) -> poulpy_core::layouts::RingDegree { self.0.n() } } diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs index 17851cc..924d53a 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/parameters.rs @@ -1,7 +1,7 @@ #[cfg(test)] use poulpy_core::layouts::{ - AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GGSWLayout, GLWELayout, GLWEToLWEKeyLayout, Rank, - TensorKeyLayout, TorusPrecision, + AutomorphismKeyLayout, Base2K, Dnum, Dsize, GGSWLayout, GLWELayout, GLWEToLWEKeyLayout, Rank, RingDegree, TensorKeyLayout, + TorusPrecision, }; #[cfg(test)] @@ -26,7 +26,7 @@ pub(crate) const TEST_RANK: u32 = 2; #[cfg(test)] pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout { - n: Degree(TEST_N_GLWE), + n: RingDegree(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: Degree(TEST_N_GLWE), + n: RingDegree(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: Degree(TEST_N_GLWE), - n_lwe: Degree(TEST_N_LWE), + n_glwe: RingDegree(TEST_N_GLWE), + n_lwe: RingDegree(TEST_N_LWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(52), dnum: Dnum(3), rank: Rank(TEST_RANK), }, layout_atk: AutomorphismKeyLayout { - n: Degree(TEST_N_GLWE), + n: RingDegree(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: Degree(TEST_N_GLWE), + n: RingDegree(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: Degree(TEST_N_GLWE), + n: RingDegree(TEST_N_GLWE), base2k: Base2K(TEST_BASE2K), k: TorusPrecision(39), rank_in: Rank(TEST_RANK), diff --git a/poulpy-schemes/src/tfhe/blind_rotation/cggi_algo.rs b/poulpy-schemes/src/tfhe/blind_rotation/cggi_algo.rs index 7aad6b9..8bf0a9e 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/cggi_algo.rs +++ b/poulpy-schemes/src/tfhe/blind_rotation/cggi_algo.rs @@ -13,7 +13,7 @@ use poulpy_hal::{ use poulpy_core::{ Distribution, GLWEOperations, TakeGLWE, - layouts::{GGSWInfos, GLWE, GLWEInfos, GLWEToMut, LWE, LWEToRef, LWEInfos}, + layouts::{GGSWInfos, GLWE, GLWEInfos, GLWEToMut, LWE, LWEInfos, LWEToRef}, }; use crate::tfhe::blind_rotation::{ diff --git a/poulpy-schemes/src/tfhe/blind_rotation/key.rs b/poulpy-schemes/src/tfhe/blind_rotation/key.rs index d9bb0a9..276539f 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, Degree, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, RingDegree, 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: Degree, - pub n_lwe: Degree, + pub n_glwe: RingDegree, + pub n_lwe: RingDegree, pub base2k: Base2K, pub k: TorusPrecision, pub dnum: Dnum, @@ -28,11 +28,11 @@ pub struct BlindRotationKeyLayout { } impl BlindRotationKeyInfos for BlindRotationKeyLayout { - fn n_glwe(&self) -> Degree { + fn n_glwe(&self) -> RingDegree { self.n_glwe } - fn n_lwe(&self) -> Degree { + fn n_lwe(&self) -> RingDegree { self.n_lwe } } @@ -62,7 +62,7 @@ impl LWEInfos for BlindRotationKeyLayout { self.k } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.n_glwe } } @@ -71,8 +71,8 @@ pub trait BlindRotationKeyInfos where Self: GGSWInfos, { - fn n_glwe(&self) -> Degree; - fn n_lwe(&self) -> Degree; + fn n_glwe(&self) -> RingDegree; + fn n_lwe(&self) -> RingDegree; } pub trait BlindRotationKeyAlloc { @@ -178,12 +178,12 @@ impl WriterTo for BlindRotationKey { } impl BlindRotationKeyInfos for BlindRotationKey { - fn n_glwe(&self) -> Degree { + fn n_glwe(&self) -> RingDegree { self.n() } - fn n_lwe(&self) -> Degree { - Degree(self.keys.len() as u32) + fn n_lwe(&self) -> RingDegree { + RingDegree(self.keys.len() as u32) } } @@ -206,7 +206,7 @@ impl LWEInfos for BlindRotationKey { self.keys[0].k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { 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 784d332..af7e40a 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, Degree, Dsize, GGSWInfos, GLWEInfos, LWEInfos, TorusPrecision, compressed::GGSWCompressed}, + layouts::{Base2K, Dsize, GGSWInfos, GLWEInfos, LWEInfos, RingDegree, 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) -> Degree { + fn n_glwe(&self) -> RingDegree { self.n() } - fn n_lwe(&self) -> Degree { - Degree(self.keys.len() as u32) + fn n_lwe(&self) -> RingDegree { + RingDegree(self.keys.len() as u32) } } impl LWEInfos for BlindRotationKeyCompressed { - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { 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 2001083..1f99ef5 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, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, + Base2K, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TorusPrecision, prepared::{GGSWPrepared, Prepare, PrepareAlloc}, }, }; @@ -30,12 +30,12 @@ pub struct BlindRotationKeyPrepared } impl BlindRotationKeyInfos for BlindRotationKeyPrepared { - fn n_glwe(&self) -> Degree { + fn n_glwe(&self) -> RingDegree { self.n() } - fn n_lwe(&self) -> Degree { - Degree(self.data.len() as u32) + fn n_lwe(&self) -> RingDegree { + RingDegree(self.data.len() as u32) } } @@ -48,7 +48,7 @@ impl LWEInfos for BlindRotationKeyP self.data[0].k() } - fn n(&self) -> Degree { + fn n(&self) -> RingDegree { self.data[0].n() } diff --git a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs b/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs index 409b685..4b8131a 100644 --- a/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs +++ b/poulpy-schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs @@ -23,7 +23,7 @@ use crate::tfhe::blind_rotation::{ }; use poulpy_core::layouts::{ - GLWE, GLWELayout, GLWEPlaintext, GLWESecret, LWE, LWELayout, LWEToRef, LWEInfos, LWEPlaintext, LWESecret, + GLWE, GLWELayout, GLWEPlaintext, GLWESecret, LWE, LWEInfos, LWELayout, LWEPlaintext, LWESecret, LWEToRef, prepared::{GLWESecretPrepared, PrepareAlloc}, }; diff --git a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs b/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs index 9d5f898..cfe238f 100644 --- a/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs +++ b/poulpy-schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs @@ -31,9 +31,7 @@ use crate::tfhe::{ }, }; -use poulpy_core::layouts::{ - AutomorphismKeyLayout, Dsize, GGSWLayout, LWELayout, TensorKeyLayout, prepared::PrepareAlloc, -}; +use poulpy_core::layouts::{AutomorphismKeyLayout, Dsize, GGSWLayout, LWELayout, TensorKeyLayout, prepared::PrepareAlloc}; use poulpy_core::layouts::{ GGSW, GLWE, GLWEPlaintext, GLWESecret, LWE, LWEPlaintext, LWESecret,