From 3a828740ccbdc33993a427df911ed23bd39a7866 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bossuat Date: Sat, 16 Aug 2025 18:23:22 +0200 Subject: [PATCH] Traits cleaning, CBT example & bug fixes (#72) * Some cleaning, CBT example, fix mod switch and add LUT correctness test to BR test * finished trait cleaning * removed trait aliastoutside of backend --- Cargo.lock | 77 +------ Cargo.toml | 2 +- backend/Cargo.toml | 3 - backend/src/hal/api/vmp_pmat.rs | 2 +- backend/src/hal/delegates/vmp_pmat.rs | 4 +- core/src/automorphism/gglwe_atk.rs | 43 +++- core/src/automorphism/ggsw_ct.rs | 71 ++++-- core/src/automorphism/glwe_ct.rs | 106 +++++++-- core/src/conversion/glwe_to_lwe.rs | 22 +- core/src/conversion/lwe_to_glwe.rs | 22 +- core/src/decryption/glwe_ct.rs | 14 +- core/src/encryption/compressed/gglwe_atk.rs | 37 ++- core/src/encryption/compressed/gglwe_ct.rs | 25 +- core/src/encryption/compressed/gglwe_ksk.rs | 40 +++- core/src/encryption/compressed/gglwe_tsk.rs | 44 +++- core/src/encryption/compressed/ggsw_ct.rs | 25 +- core/src/encryption/compressed/glwe_ct.rs | 38 ++- core/src/encryption/gglwe_atk.rs | 37 ++- core/src/encryption/gglwe_ct.rs | 24 +- core/src/encryption/gglwe_ksk.rs | 37 ++- core/src/encryption/gglwe_tsk.rs | 35 ++- core/src/encryption/ggsw_ct.rs | 27 ++- core/src/encryption/glwe_ct.rs | 92 ++++++-- core/src/encryption/glwe_pk.rs | 30 ++- core/src/encryption/glwe_to_lwe_ksk.rs | 34 ++- core/src/encryption/lwe_ksk.rs | 33 ++- core/src/encryption/lwe_to_glwe_ksk.rs | 33 ++- core/src/external_product/gglwe_atk.rs | 32 ++- core/src/external_product/gglwe_ksk.rs | 32 ++- core/src/external_product/ggsw_ct.rs | 34 ++- core/src/external_product/glwe_ct.rs | 27 ++- core/src/glwe_packing.rs | 82 ++++++- core/src/glwe_trace.rs | 44 +++- core/src/keyswitching/gglwe_ct.rs | 66 ++++-- core/src/keyswitching/ggsw_ct.rs | 92 ++++++-- core/src/keyswitching/glwe_ct.rs | 49 +++- core/src/keyswitching/lwe_ct.rs | 29 ++- core/src/layouts/compressed/gglwe_atk.rs | 7 +- core/src/layouts/compressed/gglwe_ct.rs | 7 +- core/src/layouts/compressed/gglwe_ksk.rs | 6 +- core/src/layouts/compressed/gglwe_tsk.rs | 7 +- core/src/layouts/compressed/ggsw_ct.rs | 6 +- core/src/layouts/compressed/glwe_ct.rs | 18 +- .../src/layouts/compressed/glwe_to_lwe_ksk.rs | 24 +- core/src/layouts/compressed/lwe_ct.rs | 5 +- core/src/layouts/compressed/lwe_ksk.rs | 32 ++- .../src/layouts/compressed/lwe_to_glwe_ksk.rs | 32 ++- core/src/layouts/compressed/mod.rs | 11 + core/src/layouts/lwe_pt.rs | 6 + core/src/layouts/prepared/gglwe_atk.rs | 6 +- core/src/layouts/prepared/gglwe_ct.rs | 6 +- core/src/layouts/prepared/gglwe_ksk.rs | 6 +- core/src/layouts/prepared/gglwe_tsk.rs | 6 +- core/src/layouts/prepared/ggsw_ct.rs | 6 +- core/src/layouts/prepared/glwe_sk.rs | 7 +- core/src/layouts/prepared/glwe_to_lwe_ksk.rs | 6 +- core/src/layouts/prepared/lwe_ksk.rs | 6 +- core/src/layouts/prepared/lwe_to_glwe_ksk.rs | 6 +- core/src/lib.rs | 2 - core/src/noise/gglwe_ct.rs | 22 +- core/src/noise/ggsw_ct.rs | 45 +++- core/src/noise/glwe_ct.rs | 19 +- core/src/scratch.rs | 36 +-- .../tests/generics/automorphism/gglwe_atk.rs | 89 +++++-- .../tests/generics/automorphism/ggsw_ct.rs | 89 +++++-- .../tests/generics/automorphism/glwe_ct.rs | 69 ++++-- core/src/tests/generics/conversion.rs | 96 +++++--- .../tests/generics/encryption/gglwe_atk.rs | 81 +++++-- .../src/tests/generics/encryption/gglwe_ct.rs | 70 ++++-- core/src/tests/generics/encryption/ggsw_ct.rs | 79 +++++-- core/src/tests/generics/encryption/glwe_ct.rs | 150 ++++++++++-- .../src/tests/generics/encryption/glwe_tsk.rs | 95 +++++--- .../generics/external_product/gglwe_ksk.rs | 77 +++++-- .../generics/external_product/ggsw_ct.rs | 92 +++++--- .../generics/external_product/glwe_ct.rs | 65 ++++-- core/src/tests/generics/keyswitch/gglwe_ct.rs | 94 +++++--- core/src/tests/generics/keyswitch/ggsw_ct.rs | 113 +++++---- core/src/tests/generics/keyswitch/glwe_ct.rs | 72 ++++-- core/src/tests/generics/keyswitch/lwe_ct.rs | 53 +++-- core/src/tests/generics/packing.rs | 80 ++++--- core/src/tests/generics/trace.rs | 80 ++++--- core/src/trait_families.rs | 104 --------- poulpy/Cargo.toml | 10 + poulpy/README.md | 171 ++++++++++++++ poulpy/examples/circuit_bootstrapping.rs | 218 ++++++++++++++++++ poulpy/poulpy.png | Bin 0 -> 23087 bytes poulpy/src/lib.rs | 15 ++ schemes/src/lib.rs | 1 - schemes/src/tfhe/blind_rotation/cggi_algo.rs | 144 +++++++++--- schemes/src/tfhe/blind_rotation/cggi_key.rs | 42 +++- .../src/tfhe/blind_rotation/key_prepared.rs | 4 +- schemes/src/tfhe/blind_rotation/lut.rs | 1 + .../tests/generic_blind_rotation.rs | 85 +++++-- .../circuit_bootstrapping.rs | 184 +++++++++++---- schemes/src/tfhe/circuit_bootstrapping/key.rs | 38 ++- .../tests/circuit_bootstrapping.rs | 112 ++++++--- utils/Cargo.toml | 8 - utils/src/lib.rs | 1 - utils/src/map.rs | 21 -- 99 files changed, 3267 insertions(+), 1220 deletions(-) delete mode 100644 core/src/trait_families.rs create mode 100644 poulpy/Cargo.toml create mode 100644 poulpy/README.md create mode 100644 poulpy/examples/circuit_bootstrapping.rs create mode 100644 poulpy/poulpy.png create mode 100644 poulpy/src/lib.rs delete mode 100644 utils/Cargo.toml delete mode 100644 utils/src/lib.rs delete mode 100644 utils/src/map.rs diff --git a/Cargo.lock b/Cargo.lock index bbb23d2..e4516a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,14 +43,11 @@ dependencies = [ "cmake", "criterion", "itertools 0.14.0", - "paste", "rand", "rand_core", "rand_distr", "rug", "sampling", - "utils", - "zstd", ] [[package]] @@ -83,8 +80,6 @@ version = "1.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" dependencies = [ - "jobserver", - "libc", "shlex", ] @@ -239,12 +234,6 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "getrandom" version = "0.3.2" @@ -301,15 +290,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" -[[package]] -name = "jobserver" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.76" @@ -366,18 +346,6 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - -[[package]] -name = "pkg-config" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" - [[package]] name = "plotters" version = "0.3.7" @@ -406,6 +374,16 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "poulpy" +version = "0.1.0" +dependencies = [ + "backend", + "core", + "sampling", + "schemes", +] + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -639,13 +617,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" -[[package]] -name = "utils" -version = "0.1.0" -dependencies = [ - "fnv", -] - [[package]] name = "walkdir" version = "2.5.0" @@ -849,31 +820,3 @@ dependencies = [ "quote", "syn", ] - -[[package]] -name = "zstd" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" -dependencies = [ - "zstd-safe", -] - -[[package]] -name = "zstd-safe" -version = "7.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" -dependencies = [ - "zstd-sys", -] - -[[package]] -name = "zstd-sys" -version = "2.0.15+zstd.1.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb81183ddd97d0c74cedf1d50d85c8d08c1b8b68ee863bdee9e706eedba1a237" -dependencies = [ - "cc", - "pkg-config", -] diff --git a/Cargo.toml b/Cargo.toml index b7117c5..b0e3d5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["backend", "core", "sampling", "utils", "schemes"] +members = ["backend", "core", "sampling", "schemes", "poulpy"] resolver = "3" [workspace.dependencies] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 15e4cde..e447821 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -12,10 +12,7 @@ rand = {workspace = true} rand_distr = {workspace = true} rand_core = {workspace = true} sampling = { path = "../sampling" } -utils = { path = "../utils" } -paste = "1.0.15" byteorder = {workspace = true} -zstd = {workspace = true} [build-dependencies] cmake = "0.1.54" diff --git a/backend/src/hal/api/vmp_pmat.rs b/backend/src/hal/api/vmp_pmat.rs index 64fd8a5..bdead9c 100644 --- a/backend/src/hal/api/vmp_pmat.rs +++ b/backend/src/hal/api/vmp_pmat.rs @@ -26,7 +26,7 @@ pub trait VmpPrepareTmpBytes { fn vmp_prepare_tmp_bytes(&self, n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize; } -pub trait VmpPMatPrepare { +pub trait VmpPrepare { fn vmp_prepare(&self, res: &mut R, a: &A, scratch: &mut Scratch) where R: VmpPMatToMut, diff --git a/backend/src/hal/delegates/vmp_pmat.rs b/backend/src/hal/delegates/vmp_pmat.rs index 0d9a501..10343eb 100644 --- a/backend/src/hal/delegates/vmp_pmat.rs +++ b/backend/src/hal/delegates/vmp_pmat.rs @@ -1,7 +1,7 @@ use crate::hal::{ api::{ VmpApply, VmpApplyAdd, VmpApplyAddTmpBytes, VmpApplyTmpBytes, VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatFromBytes, - VmpPMatPrepare, VmpPrepareTmpBytes, + VmpPrepare, VmpPrepareTmpBytes, }, layouts::{Backend, MatZnxToRef, Module, Scratch, VecZnxDftToMut, VecZnxDftToRef, VmpPMatOwned, VmpPMatToMut, VmpPMatToRef}, oep::{ @@ -54,7 +54,7 @@ where } } -impl VmpPMatPrepare for Module +impl VmpPrepare for Module where B: Backend + VmpPMatPrepareImpl, { diff --git a/core/src/automorphism/gglwe_atk.rs b/core/src/automorphism/gglwe_atk.rs index 3fcf6db..d66b335 100644 --- a/core/src/automorphism/gglwe_atk.rs +++ b/core/src/automorphism/gglwe_atk.rs @@ -1,12 +1,13 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnxDft, VecZnxAutomorphism, VecZnxAutomorphismInplace, ZnxZero}, + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::{ - layouts::{GGLWEAutomorphismKey, GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared}, - trait_families::GLWEKeyswitchFamily, -}; +use crate::layouts::{GGLWEAutomorphismKey, GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared}; impl GGLWEAutomorphismKey> { pub fn automorphism_scratch_space( @@ -20,7 +21,7 @@ impl GGLWEAutomorphismKey> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank) } @@ -35,7 +36,7 @@ impl GGLWEAutomorphismKey> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GGLWEAutomorphismKey::automorphism_scratch_space(module, n, basek, k_out, k_out, k_ksk, digits, rank) } @@ -49,8 +50,18 @@ impl GGLWEAutomorphismKey { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxAutomorphism + VecZnxAutomorphismInplace, - Scratch: TakeVecZnxDft + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphism + + VecZnxAutomorphismInplace, + Scratch: ScratchAvailable + TakeVecZnxDft, { #[cfg(debug_assertions)] { @@ -123,8 +134,18 @@ impl GGLWEAutomorphismKey { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxAutomorphism + VecZnxAutomorphismInplace, - Scratch: TakeVecZnxDft + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphism + + VecZnxAutomorphismInplace, + Scratch: ScratchAvailable + TakeVecZnxDft, { unsafe { let self_ptr: *mut GGLWEAutomorphismKey = self as *mut GGLWEAutomorphismKey; diff --git a/core/src/automorphism/ggsw_ct.rs b/core/src/automorphism/ggsw_ct.rs index 77c14ff..73e6b59 100644 --- a/core/src/automorphism/ggsw_ct.rs +++ b/core/src/automorphism/ggsw_ct.rs @@ -1,14 +1,16 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnxBig, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxNormalizeTmpBytes}, + api::{ + ScratchAvailable, TakeVecZnxBig, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAddInplace, VecZnxDftAllocBytes, VecZnxDftCopy, + VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxNormalizeTmpBytes, VmpApply, + VmpApplyAdd, VmpApplyTmpBytes, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::{ - layouts::{ - GGSWCiphertext, GLWECiphertext, Infos, - prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared}, - }, - trait_families::{GGSWKeySwitchFamily, GLWEKeyswitchFamily}, +use crate::layouts::{ + GGSWCiphertext, GLWECiphertext, Infos, + prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared}, }; impl GGSWCiphertext> { @@ -25,7 +27,8 @@ impl GGSWCiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, + Module: + VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes, { let out_size: usize = k_out.div_ceil(basek); let ci_dft: usize = module.vec_znx_dft_alloc_bytes(n, rank + 1, out_size); @@ -47,7 +50,8 @@ impl GGSWCiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, + Module: + VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes, { GGSWCiphertext::automorphism_scratch_space( module, n, basek, k_out, k_out, k_ksk, digits_ksk, k_tsk, digits_tsk, rank, @@ -64,8 +68,22 @@ impl GGSWCiphertext { tensor_key: &GGLWETensorKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxAutomorphismInplace + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace + + VecZnxBigAllocBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxDftToVecZnxBigTmpA, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnxBig, { #[cfg(debug_assertions)] { @@ -121,8 +139,22 @@ impl GGSWCiphertext { tensor_key: &GGLWETensorKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxAutomorphismInplace + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace + + VecZnxBigAllocBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxDftToVecZnxBigTmpA, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnxBig, { unsafe { let self_ptr: *mut GGSWCiphertext = self as *mut GGSWCiphertext; @@ -137,8 +169,17 @@ impl GGSWCiphertext { auto_key: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxAutomorphismInplace + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace, + Scratch: TakeVecZnxDft + ScratchAvailable, { // Keyswitch the j-th row of the col 0 (0..lhs.rows()).for_each(|row_i| { diff --git a/core/src/automorphism/glwe_ct.rs b/core/src/automorphism/glwe_ct.rs index 3f399b6..69e5a38 100644 --- a/core/src/automorphism/glwe_ct.rs +++ b/core/src/automorphism/glwe_ct.rs @@ -1,15 +1,13 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxBigAutomorphismInplace, VecZnxBigSubSmallAInplace, - VecZnxBigSubSmallBInplace, + ScratchAvailable, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallAInplace, VecZnxBigSubSmallBInplace, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig}, }; -use crate::{ - layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared}, - trait_families::GLWEKeyswitchFamily, -}; +use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared}; impl GLWECiphertext> { pub fn automorphism_scratch_space( @@ -23,7 +21,7 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { Self::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank) } @@ -38,7 +36,7 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { Self::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank) } @@ -52,7 +50,16 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxAutomorphismInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { self.keyswitch(module, lhs, &rhs.key, scratch); @@ -67,7 +74,16 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxAutomorphismInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { self.keyswitch_inplace(module, &rhs.key, scratch); @@ -83,7 +99,16 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxBigAutomorphismInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { #[cfg(debug_assertions)] @@ -105,7 +130,16 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxBigAutomorphismInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { unsafe { @@ -121,7 +155,17 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxBigAutomorphismInplace + VecZnxBigSubSmallAInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace + + VecZnxBigSubSmallAInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { #[cfg(debug_assertions)] @@ -143,7 +187,17 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxBigAutomorphismInplace + VecZnxBigSubSmallAInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace + + VecZnxBigSubSmallAInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { unsafe { @@ -159,7 +213,17 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxBigAutomorphismInplace + VecZnxBigSubSmallBInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace + + VecZnxBigSubSmallBInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { #[cfg(debug_assertions)] @@ -181,7 +245,17 @@ impl GLWECiphertext { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + VecZnxBigAutomorphismInplace + VecZnxBigSubSmallBInplace, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace + + VecZnxBigSubSmallBInplace, Scratch: TakeVecZnxDft + ScratchAvailable, { unsafe { diff --git a/core/src/conversion/glwe_to_lwe.rs b/core/src/conversion/glwe_to_lwe.rs index 4da48b1..189c2df 100644 --- a/core/src/conversion/glwe_to_lwe.rs +++ b/core/src/conversion/glwe_to_lwe.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft, ZnxView, ZnxViewMut, ZnxZero}, + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxView, + ZnxViewMut, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -8,8 +12,6 @@ use crate::{ layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::GLWEToLWESwitchingKeyPrepared}, }; -use crate::trait_families::GLWEKeyswitchFamily; - impl LWECiphertext> { pub fn from_glwe_scratch_space( module: &Module, @@ -21,7 +23,7 @@ impl LWECiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GLWECiphertext::bytes_of(n, basek, k_lwe, 1) + GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_lwe, k_glwe, k_ksk, 1, rank, 1) @@ -55,8 +57,16 @@ impl LWECiphertext { ) where DGlwe: DataRef, DKs: DataRef, - Module: GLWEKeyswitchFamily, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: ScratchAvailable + TakeVecZnxDft + TakeGLWECt, { #[cfg(debug_assertions)] { diff --git a/core/src/conversion/lwe_to_glwe.rs b/core/src/conversion/lwe_to_glwe.rs index 9e65291..5f023fb 100644 --- a/core/src/conversion/lwe_to_glwe.rs +++ b/core/src/conversion/lwe_to_glwe.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft, ZnxView, ZnxViewMut, ZnxZero}, + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxView, + ZnxViewMut, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -8,8 +12,6 @@ use crate::{ layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::LWEToGLWESwitchingKeyPrepared}, }; -use crate::trait_families::GLWEKeyswitchFamily; - impl GLWECiphertext> { pub fn from_lwe_scratch_space( module: &Module, @@ -21,7 +23,7 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_glwe, k_lwe, k_ksk, 1, 1, rank) + GLWECiphertext::bytes_of(n, basek, k_lwe, 1) @@ -38,8 +40,16 @@ impl GLWECiphertext { ) where DLwe: DataRef, DKsk: DataRef, - Module: GLWEKeyswitchFamily, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: ScratchAvailable + TakeVecZnxDft + TakeGLWECt, { #[cfg(debug_assertions)] { diff --git a/core/src/decryption/glwe_ct.rs b/core/src/decryption/glwe_ct.rs index 1e1ed1c..732ca25 100644 --- a/core/src/decryption/glwe_ct.rs +++ b/core/src/decryption/glwe_ct.rs @@ -6,15 +6,12 @@ use backend::hal::{ layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::{ - layouts::{GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}, - trait_families::GLWEDecryptFamily, -}; +use crate::layouts::{GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}; impl GLWECiphertext> { pub fn decrypt_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GLWEDecryptFamily, + Module: VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { let size: usize = k.div_ceil(basek); (module.vec_znx_normalize_tmp_bytes(n) | module.vec_znx_dft_alloc_bytes(n, 1, size)) @@ -30,7 +27,12 @@ impl GLWECiphertext { sk: &GLWESecretPrepared, scratch: &mut Scratch, ) where - Module: GLWEDecryptFamily, + Module: VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + TakeVecZnxBig, { #[cfg(debug_assertions)] diff --git a/core/src/encryption/compressed/gglwe_atk.rs b/core/src/encryption/compressed/gglwe_atk.rs index 2efc7f9..e055953 100644 --- a/core/src/encryption/compressed/gglwe_atk.rs +++ b/core/src/encryption/compressed/gglwe_atk.rs @@ -1,7 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphism, - VecZnxSwithcDegree, + ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigNormalize, VecZnxDftAllocBytes, + VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -10,17 +12,15 @@ use sampling::source::Source; use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, layouts::{ - GLWESecret, Infos, + GLWESecret, compressed::{GGLWEAutomorphismKeyCompressed, GGLWESwitchingKeyCompressed}, }, }; -use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl GGLWEAutomorphismKeyCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGLWEAutomorphismKeyEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes, { GGLWESwitchingKeyCompressed::encrypt_sk_scratch_space(module, n, basek, k, rank, rank) + GLWESecret::bytes_of(n, rank) } @@ -37,15 +37,30 @@ impl GGLWEAutomorphismKeyCompressed { sigma: f64, scratch: &mut Scratch, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily + Module: VecZnxAutomorphism + + SvpPrepare + + SvpPPolAllocBytes + VecZnxSwithcDegree - + VecZnxAutomorphism - + VecZnxAddScalarInplace - + GLWESecretPreparedModuleFamily, - Scratch: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft + TakeGLWESecretPrepared + TakeVecZnx, + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + VecZnxAddScalarInplace, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, { #[cfg(debug_assertions)] { + use crate::layouts::Infos; + assert_eq!(self.n(), sk.n()); assert_eq!(self.rank_out(), self.rank_in()); assert_eq!(sk.rank(), self.rank()); diff --git a/core/src/encryption/compressed/gglwe_ct.rs b/core/src/encryption/compressed/gglwe_ct.rs index 4d0ffe9..e98739b 100644 --- a/core/src/encryption/compressed/gglwe_ct.rs +++ b/core/src/encryption/compressed/gglwe_ct.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxNormalizeInplace, ZnxZero}, + api::{ + ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch}, }; use sampling::source::Source; @@ -10,12 +14,10 @@ use crate::{ layouts::{GGLWECiphertext, Infos, compressed::GGLWECiphertextCompressed, prepared::GLWESecretPrepared}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily}; - impl GGLWECiphertextCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GGLWESwitchingKeyEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) } @@ -32,7 +34,20 @@ impl GGLWECiphertextCompressed { sigma: f64, scratch: &mut Scratch, ) where - Module: GGLWEEncryptSkFamily + VecZnxAddScalarInplace, + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] diff --git a/core/src/encryption/compressed/gglwe_ksk.rs b/core/src/encryption/compressed/gglwe_ksk.rs index e529fce..21cacd8 100644 --- a/core/src/encryption/compressed/gglwe_ksk.rs +++ b/core/src/encryption/compressed/gglwe_ksk.rs @@ -1,19 +1,19 @@ use backend::hal::{ - api::{ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxSwithcDegree}, + api::{ + ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, + VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, + }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch}, }; use sampling::source::Source; use crate::{ TakeGLWESecretPrepared, - layouts::{ - GGLWECiphertext, GGLWESwitchingKey, GLWESecret, Infos, compressed::GGLWESwitchingKeyCompressed, - prepared::GLWESecretPrepared, - }, + layouts::{GGLWECiphertext, GLWESecret, compressed::GGLWESwitchingKeyCompressed, prepared::GLWESecretPrepared}, }; -use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl GGLWESwitchingKeyCompressed> { pub fn encrypt_sk_scratch_space( module: &Module, @@ -24,7 +24,7 @@ impl GGLWESwitchingKeyCompressed> { rank_out: usize, ) -> usize where - Module: GGLWESwitchingKeyEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes, { (GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) | ScalarZnx::alloc_bytes(n, 1)) + ScalarZnx::alloc_bytes(n, rank_in) @@ -43,13 +43,29 @@ impl GGLWESwitchingKeyCompressed { sigma: f64, scratch: &mut Scratch, ) where - Module: - GGLWESwitchingKeyEncryptSkFamily + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily, - Scratch: - ScratchAvailable + TakeScalarZnx + TakeVecZnxDft + TakeGLWESecretPrepared + ScratchAvailable + TakeVecZnx, + Module: SvpPrepare + + SvpPPolAllocBytes + + VecZnxSwithcDegree + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + VecZnxAddScalarInplace, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, { #[cfg(debug_assertions)] { + use crate::layouts::{GGLWESwitchingKey, Infos}; + assert!(sk_in.n() <= module.n()); assert!(sk_out.n() <= module.n()); assert!( diff --git a/core/src/encryption/compressed/gglwe_tsk.rs b/core/src/encryption/compressed/gglwe_tsk.rs index 5ebb402..10681bc 100644 --- a/core/src/encryption/compressed/gglwe_tsk.rs +++ b/core/src/encryption/compressed/gglwe_tsk.rs @@ -1,7 +1,10 @@ use backend::hal::{ api::{ - ScratchAvailable, SvpApply, TakeScalarZnx, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAddScalarInplace, - VecZnxDftToVecZnxBigTmpA, VecZnxSwithcDegree, + ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, + TakeVecZnxBig, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, + VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + VecZnxSwithcDegree, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -10,15 +13,13 @@ use sampling::source::Source; use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, layouts::{GGLWETensorKey, GLWESecret, Infos, compressed::GGLWETensorKeyCompressed, prepared::Prepare}, - trait_families::GLWEDecryptFamily, }; -use crate::trait_families::{GGLWETensorKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl GGLWETensorKeyCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGLWETensorKeyEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: + SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigAllocBytes, { GGLWETensorKey::encrypt_sk_scratch_space(module, n, basek, k, rank) } @@ -34,10 +35,33 @@ impl GGLWETensorKeyCompressed { sigma: f64, scratch: &mut Scratch, ) where - Module: - GGLWETensorKeyEncryptSkFamily + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily, - Scratch: - ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig + TakeGLWESecretPrepared + TakeScalarZnx + TakeVecZnx, + Module: SvpApply + + VecZnxDftToVecZnxBigTmpA + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + VecZnxSwithcDegree + + VecZnxAddScalarInplace + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc, + Scratch: ScratchAvailable + + TakeScalarZnx + + TakeVecZnxDft + + TakeGLWESecretPrepared + + ScratchAvailable + + TakeVecZnx + + TakeVecZnxBig, { #[cfg(debug_assertions)] { diff --git a/core/src/encryption/compressed/ggsw_ct.rs b/core/src/encryption/compressed/ggsw_ct.rs index 3925464..6842768 100644 --- a/core/src/encryption/compressed/ggsw_ct.rs +++ b/core/src/encryption/compressed/ggsw_ct.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxNormalizeInplace, ZnxZero}, + api::{ + ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch}, }; use sampling::source::Source; @@ -10,12 +14,10 @@ use crate::{ layouts::{GGSWCiphertext, Infos, compressed::GGSWCiphertextCompressed, prepared::GLWESecretPrepared}, }; -use crate::trait_families::GGSWEncryptSkFamily; - impl GGSWCiphertextCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGSWEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k, rank) } @@ -32,7 +34,20 @@ impl GGSWCiphertextCompressed { sigma: f64, scratch: &mut Scratch, ) where - Module: GGSWEncryptSkFamily + VecZnxAddScalarInplace, + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] diff --git a/core/src/encryption/compressed/glwe_ct.rs b/core/src/encryption/compressed/glwe_ct.rs index 270d4af..543eb81 100644 --- a/core/src/encryption/compressed/glwe_ct.rs +++ b/core/src/encryption/compressed/glwe_ct.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft}, + api::{ + ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigNormalize, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; use sampling::source::Source; @@ -9,12 +13,10 @@ use crate::{ layouts::{GLWECiphertext, GLWEPlaintext, Infos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared}, }; -use crate::trait_families::GLWEEncryptSkFamily; - impl GLWECiphertextCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GLWEEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) } @@ -31,7 +33,19 @@ impl GLWECiphertextCompressed { sigma: f64, scratch: &mut Scratch, ) where - Module: GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { self.encrypt_sk_internal( @@ -55,7 +69,19 @@ impl GLWECiphertextCompressed { sigma: f64, scratch: &mut Scratch, ) where - Module: GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { let mut source_xa = Source::new(seed_xa); diff --git a/core/src/encryption/gglwe_atk.rs b/core/src/encryption/gglwe_atk.rs index b7ce5e5..ea1a323 100644 --- a/core/src/encryption/gglwe_atk.rs +++ b/core/src/encryption/gglwe_atk.rs @@ -1,7 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphism, - VecZnxSwithcDegree, + ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigNormalize, VecZnxDftAllocBytes, + VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -9,15 +11,13 @@ use sampling::source::Source; use crate::{ TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, GLWESecret, Infos}, + layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, GLWESecret}, }; -use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl GGLWEAutomorphismKey> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGLWEAutomorphismKeyEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank, rank) + GLWESecret::bytes_of(n, rank) } @@ -38,15 +38,30 @@ impl GGLWEAutomorphismKey { sigma: f64, scratch: &mut Scratch, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily - + VecZnxAutomorphism + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + VecZnxSwithcDegree - + VecZnxAddScalarInplace - + GLWESecretPreparedModuleFamily, - Scratch: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft + TakeGLWESecretPrepared + TakeVecZnx, + + SvpPPolAllocBytes + + VecZnxAutomorphism, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, { #[cfg(debug_assertions)] { + use crate::layouts::Infos; + assert_eq!(self.n(), sk.n()); assert_eq!(self.rank_out(), self.rank_in()); assert_eq!(sk.rank(), self.rank()); diff --git a/core/src/encryption/gglwe_ct.rs b/core/src/encryption/gglwe_ct.rs index 5e22b4e..7fa8d53 100644 --- a/core/src/encryption/gglwe_ct.rs +++ b/core/src/encryption/gglwe_ct.rs @@ -1,7 +1,8 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, - ZnxZero, + ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, ZnxZero, }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch}, }; @@ -12,12 +13,10 @@ use crate::{ layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}, }; -use crate::trait_families::GGLWEEncryptSkFamily; - impl GGLWECiphertext> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GGLWEEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) + (GLWEPlaintext::byte_of(n, basek, k) | module.vec_znx_normalize_tmp_bytes(n)) @@ -39,7 +38,20 @@ impl GGLWECiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: GGLWEEncryptSkFamily + VecZnxAddScalarInplace, + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] diff --git a/core/src/encryption/gglwe_ksk.rs b/core/src/encryption/gglwe_ksk.rs index ff698f5..3c5b155 100644 --- a/core/src/encryption/gglwe_ksk.rs +++ b/core/src/encryption/gglwe_ksk.rs @@ -1,16 +1,19 @@ use backend::hal::{ - api::{ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxSwithcDegree}, + api::{ + ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, + VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, + }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch}, }; use sampling::source::Source; use crate::{ TakeGLWESecretPrepared, - layouts::{GGLWECiphertext, GGLWESwitchingKey, GLWESecret, Infos, prepared::GLWESecretPrepared}, + layouts::{GGLWECiphertext, GGLWESwitchingKey, GLWESecret, prepared::GLWESecretPrepared}, }; -use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl GGLWESwitchingKey> { pub fn encrypt_sk_scratch_space( module: &Module, @@ -21,7 +24,7 @@ impl GGLWESwitchingKey> { rank_out: usize, ) -> usize where - Module: GGLWESwitchingKeyEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { (GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) | ScalarZnx::alloc_bytes(n, 1)) + ScalarZnx::alloc_bytes(n, rank_in) @@ -51,13 +54,29 @@ impl GGLWESwitchingKey { sigma: f64, scratch: &mut Scratch, ) where - Module: - GGLWESwitchingKeyEncryptSkFamily + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily, - Scratch: - ScratchAvailable + TakeScalarZnx + TakeVecZnxDft + TakeGLWESecretPrepared + ScratchAvailable + TakeVecZnx, + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + VecZnxSwithcDegree + + SvpPPolAllocBytes, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, { #[cfg(debug_assertions)] { + use crate::layouts::Infos; + assert!(sk_in.n() <= module.n()); assert!(sk_out.n() <= module.n()); assert!( diff --git a/core/src/encryption/gglwe_tsk.rs b/core/src/encryption/gglwe_tsk.rs index 4b5b590..d425fd6 100644 --- a/core/src/encryption/gglwe_tsk.rs +++ b/core/src/encryption/gglwe_tsk.rs @@ -1,7 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, SvpApply, TakeScalarZnx, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAddScalarInplace, - VecZnxBigAllocBytes, VecZnxDftToVecZnxBigTmpA, VecZnxSwithcDegree, + ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxBig, + TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAllocBytes, VecZnxBigNormalize, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -13,15 +15,13 @@ use crate::{ GGLWESwitchingKey, GGLWETensorKey, GLWESecret, Infos, prepared::{GLWESecretPrepared, Prepare}, }, - trait_families::GLWEDecryptFamily, }; -use crate::trait_families::{GGLWETensorKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl GGLWETensorKey> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGLWETensorKeyEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: + SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigAllocBytes, { GLWESecretPrepared::bytes_of(module, n, rank) + module.vec_znx_dft_alloc_bytes(n, rank, 1) @@ -42,10 +42,27 @@ impl GGLWETensorKey { sigma: f64, scratch: &mut Scratch, ) where - Module: - GGLWETensorKeyEncryptSkFamily + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily, + Module: SvpApply + + VecZnxDftToVecZnxBigTmpA + + VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + VecZnxSwithcDegree + + SvpPPolAllocBytes, Scratch: - ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig + TakeGLWESecretPrepared + TakeScalarZnx + TakeVecZnx, + TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared + TakeVecZnxBig, { #[cfg(debug_assertions)] { diff --git a/core/src/encryption/ggsw_ct.rs b/core/src/encryption/ggsw_ct.rs index e09fd65..3b8282f 100644 --- a/core/src/encryption/ggsw_ct.rs +++ b/core/src/encryption/ggsw_ct.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxNormalizeInplace, ZnxZero}, + api::{ + ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch, VecZnx}, }; use sampling::source::Source; @@ -9,14 +13,10 @@ use crate::{ layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GLWESecretPrepared}, }; -use crate::trait_families::GLWEEncryptSkFamily; - -pub trait GGSWEncryptSkFamily = GLWEEncryptSkFamily; - impl GGSWCiphertext> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGSWEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { let size = k.div_ceil(basek); GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) @@ -37,7 +37,20 @@ impl GGSWCiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: GGSWEncryptSkFamily + VecZnxAddScalarInplace, + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] diff --git a/core/src/encryption/glwe_ct.rs b/core/src/encryption/glwe_ct.rs index b82402b..a23e568 100644 --- a/core/src/encryption/glwe_ct.rs +++ b/core/src/encryption/glwe_ct.rs @@ -1,8 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, SvpApply, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeSvpPPol, TakeVecZnx, TakeVecZnxDft, - VecZnxBigAddNormal, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftToVecZnxBigConsume, - ZnxInfos, ZnxZero, + ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeSvpPPol, TakeVecZnx, + TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigAddNormal, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, ZnxInfos, ZnxZero, }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch, VecZnx, VecZnxBig}, }; @@ -15,20 +16,19 @@ use crate::{ GLWECiphertext, GLWEPlaintext, Infos, prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared}, }, - trait_families::{GLWEEncryptPkFamily, GLWEEncryptSkFamily}, }; impl GLWECiphertext> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GLWEEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { let size: usize = k.div_ceil(basek); module.vec_znx_normalize_tmp_bytes(n) + 2 * VecZnx::alloc_bytes(n, 1, size) + module.vec_znx_dft_alloc_bytes(n, 1, size) } pub fn encrypt_pk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GLWEEncryptPkFamily, + Module: VecZnxDftAllocBytes + SvpPPolAllocBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes, { let size: usize = k.div_ceil(basek); ((module.vec_znx_dft_alloc_bytes(n, 1, size) + module.vec_znx_big_alloc_bytes(n, 1, size)) | ScalarZnx::alloc_bytes(n, 1)) @@ -48,7 +48,19 @@ impl GLWECiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] @@ -84,7 +96,19 @@ impl GLWECiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] @@ -119,7 +143,19 @@ impl GLWECiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { let cols: usize = self.rank() + 1; @@ -149,8 +185,13 @@ impl GLWECiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: GLWEEncryptPkFamily, - Scratch: TakeVecZnxDft + TakeSvpPPol + TakeScalarZnx, + Module: SvpPrepare + + SvpApply + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddNormal + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: TakeSvpPPol + TakeScalarZnx + TakeVecZnxDft, { self.encrypt_pk_internal::( module, @@ -172,8 +213,13 @@ impl GLWECiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: GLWEEncryptPkFamily, - Scratch: TakeVecZnxDft + TakeSvpPPol + TakeScalarZnx, + Module: SvpPrepare + + SvpApply + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddNormal + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: TakeSvpPPol + TakeScalarZnx + TakeVecZnxDft, { self.encrypt_pk_internal::, DataPk, B>( module, @@ -196,15 +242,13 @@ impl GLWECiphertext { sigma: f64, scratch: &mut Scratch, ) where - Module: VecZnxDftAllocBytes - + SvpPPolAllocBytes - + SvpPrepare + Module: SvpPrepare + SvpApply + VecZnxDftToVecZnxBigConsume + VecZnxBigAddNormal + VecZnxBigAddSmallInplace + VecZnxBigNormalize, - Scratch: TakeVecZnxDft + TakeSvpPPol + TakeScalarZnx, + Scratch: TakeSvpPPol + TakeScalarZnx + TakeVecZnxDft, { #[cfg(debug_assertions)] { @@ -289,7 +333,19 @@ pub(crate) fn glwe_encrypt_sk_internal, ) where - Module: GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] diff --git a/core/src/encryption/glwe_pk.rs b/core/src/encryption/glwe_pk.rs index 2442824..16b0e6f 100644 --- a/core/src/encryption/glwe_pk.rs +++ b/core/src/encryption/glwe_pk.rs @@ -1,16 +1,15 @@ use backend::hal::{ - api::{ScratchOwnedAlloc, ScratchOwnedBorrow}, + api::{ + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigNormalize, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + }, layouts::{Backend, DataMut, DataRef, Module, ScratchOwned}, oep::{ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxDftImpl, TakeVecZnxImpl}, }; use sampling::source::Source; -use crate::{ - dist::Distribution, - layouts::{GLWECiphertext, GLWEPublicKey, Infos, prepared::GLWESecretPrepared}, -}; - -use crate::trait_families::GLWEEncryptSkFamily; +use crate::layouts::{GLWECiphertext, GLWEPublicKey, Infos, prepared::GLWESecretPrepared}; impl GLWEPublicKey { pub fn generate_from_sk( @@ -21,7 +20,20 @@ impl GLWEPublicKey { source_xe: &mut Source, sigma: f64, ) where - Module: GLWEEncryptSkFamily, + Module:, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + TakeVecZnxDftImpl @@ -30,6 +42,8 @@ impl GLWEPublicKey { { #[cfg(debug_assertions)] { + use crate::Distribution; + assert_eq!(self.n(), sk.n()); match sk.dist { diff --git a/core/src/encryption/glwe_to_lwe_ksk.rs b/core/src/encryption/glwe_to_lwe_ksk.rs index be4f618..d68662f 100644 --- a/core/src/encryption/glwe_to_lwe_ksk.rs +++ b/core/src/encryption/glwe_to_lwe_ksk.rs @@ -1,7 +1,10 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, - VecZnxSwithcDegree, ZnxView, ZnxViewMut, ZnxZero, + ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, ZnxView, ZnxViewMut, + ZnxZero, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -12,12 +15,10 @@ use crate::{ layouts::{GGLWESwitchingKey, GLWESecret, GLWEToLWESwitchingKey, LWESecret, prepared::GLWESecretPrepared}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl GLWEToLWESwitchingKey> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank_in: usize) -> usize where - Module: GGLWEEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { GLWESecretPrepared::bytes_of(module, n, rank_in) + (GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_in, 1) | GLWESecret::bytes_of(n, rank_in)) @@ -37,12 +38,25 @@ impl GLWEToLWESwitchingKey { ) where DLwe: DataRef, DGlwe: DataRef, - Module: GGLWESwitchingKeyEncryptSkFamily - + VecZnxAutomorphismInplace - + VecZnxSwithcDegree + Module: VecZnxAutomorphismInplace + VecZnxAddScalarInplace - + GLWESecretPreparedModuleFamily, - Scratch: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft + TakeGLWESecretPrepared + TakeVecZnx, + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + VecZnxSwithcDegree + + SvpPPolAllocBytes, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, { #[cfg(debug_assertions)] { diff --git a/core/src/encryption/lwe_ksk.rs b/core/src/encryption/lwe_ksk.rs index b9b5058..5894347 100644 --- a/core/src/encryption/lwe_ksk.rs +++ b/core/src/encryption/lwe_ksk.rs @@ -1,7 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, - VecZnxSwithcDegree, ZnxView, ZnxViewMut, + ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, ZnxView, ZnxViewMut, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -12,12 +14,10 @@ use crate::{ layouts::{GGLWESwitchingKey, GLWESecret, Infos, LWESecret, LWESwitchingKey, prepared::GLWESecretPrepared}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl LWESwitchingKey> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GGLWEEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { GLWESecret::bytes_of(n, 1) + GLWESecretPrepared::bytes_of(module, n, 1) @@ -38,12 +38,25 @@ impl LWESwitchingKey { ) where DIn: DataRef, DOut: DataRef, - Module: GGLWESwitchingKeyEncryptSkFamily - + VecZnxAutomorphismInplace - + VecZnxSwithcDegree + Module: VecZnxAutomorphismInplace + VecZnxAddScalarInplace - + GLWESecretPreparedModuleFamily, - Scratch: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft + TakeGLWESecretPrepared + TakeVecZnx, + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + VecZnxSwithcDegree + + SvpPPolAllocBytes, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, { #[cfg(debug_assertions)] { diff --git a/core/src/encryption/lwe_to_glwe_ksk.rs b/core/src/encryption/lwe_to_glwe_ksk.rs index d76ceeb..1fbb16e 100644 --- a/core/src/encryption/lwe_to_glwe_ksk.rs +++ b/core/src/encryption/lwe_to_glwe_ksk.rs @@ -1,7 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, - VecZnxSwithcDegree, ZnxView, ZnxViewMut, + ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, ZnxView, ZnxViewMut, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -12,12 +14,10 @@ use crate::{ layouts::{GGLWESwitchingKey, GLWESecret, LWESecret, LWEToGLWESwitchingKey}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - impl LWEToGLWESwitchingKey> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank_out: usize) -> usize where - Module: GGLWEEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes, { GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, 1, rank_out) + GLWESecret::bytes_of(n, 1) } @@ -36,12 +36,25 @@ impl LWEToGLWESwitchingKey { ) where DLwe: DataRef, DGlwe: DataRef, - Module: GGLWESwitchingKeyEncryptSkFamily - + VecZnxAutomorphismInplace - + VecZnxSwithcDegree + Module: VecZnxAutomorphismInplace + VecZnxAddScalarInplace - + GLWESecretPreparedModuleFamily, - Scratch: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft + TakeGLWESecretPrepared + TakeVecZnx, + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + VecZnxSwithcDegree + + SvpPPolAllocBytes, + Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, { #[cfg(debug_assertions)] { diff --git a/core/src/external_product/gglwe_atk.rs b/core/src/external_product/gglwe_atk.rs index 3e711de..7b5dd4b 100644 --- a/core/src/external_product/gglwe_atk.rs +++ b/core/src/external_product/gglwe_atk.rs @@ -1,12 +1,12 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnxDft}, + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxNormalizeTmpBytes, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::{ - layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, prepared::GGSWCiphertextPrepared}, - trait_families::GLWEExternalProductFamily, -}; +use crate::layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, prepared::GGSWCiphertextPrepared}; impl GGLWEAutomorphismKey> { pub fn external_product_scratch_space( @@ -20,7 +20,7 @@ impl GGLWEAutomorphismKey> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { GGLWESwitchingKey::external_product_scratch_space(module, n, basek, k_out, k_in, ggsw_k, digits, rank) } @@ -35,7 +35,7 @@ impl GGLWEAutomorphismKey> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { GGLWESwitchingKey::external_product_inplace_scratch_space(module, n, basek, k_out, ggsw_k, digits, rank) } @@ -49,7 +49,14 @@ impl GGLWEAutomorphismKey { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { self.key.external_product(module, &lhs.key, rhs, scratch); @@ -61,7 +68,14 @@ impl GGLWEAutomorphismKey { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { self.key.external_product_inplace(module, rhs, scratch); diff --git a/core/src/external_product/gglwe_ksk.rs b/core/src/external_product/gglwe_ksk.rs index 9728cee..c68a4c4 100644 --- a/core/src/external_product/gglwe_ksk.rs +++ b/core/src/external_product/gglwe_ksk.rs @@ -1,12 +1,12 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnxDft, ZnxZero}, + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxNormalizeTmpBytes, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::{ - layouts::{GGLWESwitchingKey, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}, - trait_families::GLWEExternalProductFamily, -}; +use crate::layouts::{GGLWESwitchingKey, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}; impl GGLWESwitchingKey> { pub fn external_product_scratch_space( @@ -20,7 +20,7 @@ impl GGLWESwitchingKey> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { GLWECiphertext::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank) } @@ -35,7 +35,7 @@ impl GGLWESwitchingKey> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { GLWECiphertext::external_product_inplace_scratch_space(module, n, basek, k_out, k_ggsw, digits, rank) } @@ -49,7 +49,14 @@ impl GGLWESwitchingKey { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { #[cfg(debug_assertions)] @@ -97,7 +104,14 @@ impl GGLWESwitchingKey { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { #[cfg(debug_assertions)] diff --git a/core/src/external_product/ggsw_ct.rs b/core/src/external_product/ggsw_ct.rs index ee17aa6..bdc5845 100644 --- a/core/src/external_product/ggsw_ct.rs +++ b/core/src/external_product/ggsw_ct.rs @@ -1,12 +1,12 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnxDft, ZnxZero}, + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxNormalizeTmpBytes, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::{ - layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}, - trait_families::GLWEExternalProductFamily, -}; +use crate::layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}; impl GGSWCiphertext> { pub fn external_product_scratch_space( @@ -20,7 +20,7 @@ impl GGSWCiphertext> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { GLWECiphertext::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank) } @@ -35,7 +35,7 @@ impl GGSWCiphertext> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { GLWECiphertext::external_product_inplace_scratch_space(module, n, basek, k_out, k_ggsw, digits, rank) } @@ -49,8 +49,15 @@ impl GGSWCiphertext { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, - Scratch: ScratchAvailable + TakeVecZnxDft, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, + Scratch: TakeVecZnxDft + ScratchAvailable, { #[cfg(debug_assertions)] { @@ -108,7 +115,14 @@ impl GGSWCiphertext { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { #[cfg(debug_assertions)] diff --git a/core/src/external_product/glwe_ct.rs b/core/src/external_product/glwe_ct.rs index b5ab132..9ab438b 100644 --- a/core/src/external_product/glwe_ct.rs +++ b/core/src/external_product/glwe_ct.rs @@ -6,10 +6,7 @@ use backend::hal::{ layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig}, }; -use crate::{ - layouts::{GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}, - trait_families::GLWEExternalProductFamily, -}; +use crate::layouts::{GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared}; impl GLWECiphertext> { pub fn external_product_scratch_space( @@ -23,7 +20,7 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { let in_size: usize = k_in.div_ceil(basek).div_ceil(digits); let out_size: usize = k_out.div_ceil(basek); @@ -53,7 +50,7 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes, { Self::external_product_scratch_space(module, n, basek, k_out, k_out, k_ggsw, digits, rank) } @@ -67,7 +64,14 @@ impl GLWECiphertext { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { let basek: usize = self.basek(); @@ -144,7 +148,14 @@ impl GLWECiphertext { rhs: &GGSWCiphertextPrepared, scratch: &mut Scratch, ) where - Module: GLWEExternalProductFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { unsafe { diff --git a/core/src/glwe_packing.rs b/core/src/glwe_packing.rs index 481bdb0..020fb23 100644 --- a/core/src/glwe_packing.rs +++ b/core/src/glwe_packing.rs @@ -1,7 +1,13 @@ use std::collections::HashMap; use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxCopy}, + api::{ + ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, + VecZnxBigAutomorphismInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallBInplace, VecZnxCopy, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxNegateInplace, VecZnxNormalizeInplace, + VecZnxRotate, VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VmpApply, VmpApplyAdd, + VmpApplyTmpBytes, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -10,8 +16,6 @@ use crate::{ layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared}, }; -use crate::trait_families::{GLWEKeyswitchFamily, GLWEPackingFamily}; - /// [GLWEPacker] enables only the fly GLWE packing /// with constant memory of Log(N) ciphertexts. /// Main difference with usual GLWE packing is that @@ -93,7 +97,7 @@ impl GLWEPacker { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { pack_core_scratch_space(module, n, basek, ct_k, k_ksk, digits, rank) } @@ -118,7 +122,27 @@ impl GLWEPacker { auto_keys: &HashMap>, scratch: &mut Scratch, ) where - Module: GLWEPackingFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxCopy + + VecZnxRotateInplace + + VecZnxSub + + VecZnxNegateInplace + + VecZnxRshInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxSubABInplace + + VecZnxRotate + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxBigAutomorphismInplace, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { assert!( @@ -164,7 +188,7 @@ fn pack_core_scratch_space( rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { combine_scratch_space(module, n, basek, ct_k, k_ksk, digits, rank) } @@ -177,7 +201,27 @@ fn pack_core( auto_keys: &HashMap>, scratch: &mut Scratch, ) where - Module: GLWEPackingFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxCopy + + VecZnxRotateInplace + + VecZnxSub + + VecZnxNegateInplace + + VecZnxRshInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxSubABInplace + + VecZnxRotate + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxBigAutomorphismInplace, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { let log_n: usize = module.log_n(); @@ -239,7 +283,7 @@ fn combine_scratch_space( rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GLWECiphertext::bytes_of(n, basek, ct_k, rank) + (GLWECiphertext::rsh_scratch_space(n) @@ -255,7 +299,27 @@ fn combine( auto_keys: &HashMap>, scratch: &mut Scratch, ) where - Module: GLWEPackingFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxCopy + + VecZnxRotateInplace + + VecZnxSub + + VecZnxNegateInplace + + VecZnxRshInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxSubABInplace + + VecZnxRotate + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxBigAutomorphismInplace, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { let n: usize = acc.data.n(); diff --git a/core/src/glwe_trace.rs b/core/src/glwe_trace.rs index 12284a1..253f1e3 100644 --- a/core/src/glwe_trace.rs +++ b/core/src/glwe_trace.rs @@ -1,14 +1,19 @@ use std::collections::HashMap; -use backend::hal::layouts::{Backend, DataMut, DataRef, Module, Scratch}; +use backend::hal::{ + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VecZnxRshInplace, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, + }, + layouts::{Backend, DataMut, DataRef, Module, Scratch}, +}; use crate::{ layouts::{GLWECiphertext, prepared::GGLWEAutomorphismKeyPrepared}, operations::GLWEOperations, }; -use crate::trait_families::{GLWETraceModuleFamily, GLWETraceScratchFamily}; - impl GLWECiphertext> { pub fn trace_galois_elements(module: &Module) -> Vec { let mut gal_els: Vec = Vec::new(); @@ -33,7 +38,7 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWETraceModuleFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { Self::automorphism_inplace_scratch_space(module, n, basek, out_k.min(in_k), ksk_k, digits, rank) } @@ -48,7 +53,7 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWETraceModuleFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { Self::automorphism_inplace_scratch_space(module, n, basek, out_k, ksk_k, digits, rank) } @@ -64,8 +69,19 @@ impl GLWECiphertext { auto_keys: &HashMap>, scratch: &mut Scratch, ) where - Module: GLWETraceModuleFamily, - Scratch: GLWETraceScratchFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxCopy, + Scratch: TakeVecZnxDft + ScratchAvailable, { self.copy(module, lhs); self.trace_inplace(module, start, end, auto_keys, scratch); @@ -79,8 +95,18 @@ impl GLWECiphertext { auto_keys: &HashMap>, scratch: &mut Scratch, ) where - Module: GLWETraceModuleFamily, - Scratch: GLWETraceScratchFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace, + Scratch: TakeVecZnxDft + ScratchAvailable, { (start..end).for_each(|i| { self.rsh(module, 1); diff --git a/core/src/keyswitching/gglwe_ct.rs b/core/src/keyswitching/gglwe_ct.rs index b25e0fb..0a66bb6 100644 --- a/core/src/keyswitching/gglwe_ct.rs +++ b/core/src/keyswitching/gglwe_ct.rs @@ -1,14 +1,14 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnxDft, ZnxZero}, + api::{ + ScratchAvailable, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; -use crate::{ - layouts::{ - GGLWEAutomorphismKey, GGLWESwitchingKey, GLWECiphertext, Infos, - prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared}, - }, - trait_families::GLWEKeyswitchFamily, +use crate::layouts::{ + GGLWEAutomorphismKey, GGLWESwitchingKey, GLWECiphertext, Infos, + prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared}, }; impl GGLWEAutomorphismKey> { @@ -23,7 +23,7 @@ impl GGLWEAutomorphismKey> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GGLWESwitchingKey::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank) } @@ -38,7 +38,7 @@ impl GGLWEAutomorphismKey> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GGLWESwitchingKey::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank) } @@ -52,7 +52,15 @@ impl GGLWEAutomorphismKey { rhs: &GGLWESwitchingKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { self.key.keyswitch(module, &lhs.key, rhs, scratch); @@ -64,7 +72,15 @@ impl GGLWEAutomorphismKey { rhs: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable, { self.key.keyswitch_inplace(module, &rhs.key, scratch); @@ -84,7 +100,7 @@ impl GGLWESwitchingKey> { rank_out: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GLWECiphertext::keyswitch_scratch_space( module, n, basek, k_out, k_in, k_ksk, digits, rank_in, rank_out, @@ -101,7 +117,7 @@ impl GGLWESwitchingKey> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { GLWECiphertext::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank) } @@ -115,8 +131,16 @@ impl GGLWESwitchingKey { rhs: &GGLWESwitchingKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily, - Scratch: TakeVecZnxDft + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: ScratchAvailable + TakeVecZnxDft, { #[cfg(debug_assertions)] { @@ -163,8 +187,16 @@ impl GGLWESwitchingKey { rhs: &GGLWESwitchingKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily, - Scratch: TakeVecZnxDft + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: ScratchAvailable + TakeVecZnxDft, { #[cfg(debug_assertions)] { diff --git a/core/src/keyswitching/ggsw_ct.rs b/core/src/keyswitching/ggsw_ct.rs index 10802bc..4c78421 100644 --- a/core/src/keyswitching/ggsw_ct.rs +++ b/core/src/keyswitching/ggsw_ct.rs @@ -1,7 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigAllocBytes, VecZnxCopy, VecZnxDftAddInplace, - VecZnxDftCopy, VecZnxDftToVecZnxBigTmpA, VecZnxNormalizeTmpBytes, ZnxInfos, + ScratchAvailable, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAddInplace, VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxNormalizeTmpBytes, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, + ZnxInfos, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, VmpPMat}, }; @@ -12,7 +14,6 @@ use crate::{ prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared}, }, operations::GLWEOperations, - trait_families::{GGSWKeySwitchFamily, GLWEKeyswitchFamily}, }; impl GGSWCiphertext> { @@ -26,7 +27,7 @@ impl GGSWCiphertext> { rank: usize, ) -> usize where - Module: GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes, { let tsk_size: usize = k_tsk.div_ceil(basek); let self_size_out: usize = self_k.div_ceil(basek); @@ -61,7 +62,8 @@ impl GGSWCiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, + Module: + VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes, { let out_size: usize = k_out.div_ceil(basek); let res_znx: usize = VecZnx::alloc_bytes(n, rank + 1, out_size); @@ -84,7 +86,8 @@ impl GGSWCiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, + Module: + VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes, { GGSWCiphertext::keyswitch_scratch_space( module, n, basek, k_out, k_out, k_ksk, digits_ksk, k_tsk, digits_tsk, rank, @@ -102,8 +105,19 @@ impl GGSWCiphertext { ) where DataA: DataRef, DataTsk: DataRef, - Module: GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes + VecZnxCopy, - Scratch: TakeVecZnxDft + TakeVecZnxBig + ScratchAvailable + TakeVecZnx, + Module: VecZnxCopy + + VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigAllocBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VecZnxDftCopy + + VmpApply + + VmpApplyAdd + + VecZnxDftAddInplace + + VecZnxBigNormalize + + VecZnxDftToVecZnxBigTmpA, + Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig, { #[cfg(debug_assertions)] { @@ -127,8 +141,22 @@ impl GGSWCiphertext { tsk: &GGLWETensorKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + TakeVecZnxBig + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxDftToVecZnxBigTmpA, + Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig, { self.keyswitch_internal(module, lhs, ksk, scratch); self.expand_row(module, tsk, scratch); @@ -141,8 +169,22 @@ impl GGSWCiphertext { tsk: &GGLWETensorKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + TakeVecZnxBig + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxDftToVecZnxBigTmpA, + Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig, { unsafe { let self_ptr: *mut GGSWCiphertext = self as *mut GGSWCiphertext; @@ -156,8 +198,18 @@ impl GGSWCiphertext { tsk: &GGLWETensorKeyPrepared, scratch: &mut Scratch, ) where - Module: GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + TakeVecZnxBig + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigAllocBytes + + VecZnxNormalizeTmpBytes + + VecZnxDftFromVecZnx + + VecZnxDftCopy + + VmpApply + + VmpApplyAdd + + VecZnxDftAddInplace + + VecZnxBigNormalize + + VecZnxDftToVecZnxBigTmpA, + Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig, { assert!( scratch.available() @@ -281,8 +333,16 @@ impl GGSWCiphertext { ksk: &GGLWESwitchingKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily + GGSWKeySwitchFamily + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + TakeVecZnxBig + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: ScratchAvailable + TakeVecZnxDft, { // Keyswitch the j-th row of the col 0 (0..lhs.rows()).for_each(|row_i| { diff --git a/core/src/keyswitching/glwe_ct.rs b/core/src/keyswitching/glwe_ct.rs index 672a2e3..58c4564 100644 --- a/core/src/keyswitching/glwe_ct.rs +++ b/core/src/keyswitching/glwe_ct.rs @@ -6,10 +6,7 @@ use backend::hal::{ layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, VecZnxBig, VecZnxDft, VmpPMat}, }; -use crate::{ - layouts::{GLWECiphertext, Infos, prepared::GGLWESwitchingKeyPrepared}, - trait_families::GLWEKeyswitchFamily, -}; +use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWESwitchingKeyPrepared}; impl GLWECiphertext> { pub fn keyswitch_scratch_space( @@ -24,7 +21,7 @@ impl GLWECiphertext> { rank_out: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { let in_size: usize = k_in.div_ceil(basek).div_ceil(digits); let out_size: usize = k_out.div_ceil(basek); @@ -54,13 +51,14 @@ impl GLWECiphertext> { rank: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, { Self::keyswitch_scratch_space(module, n, basek, k_out, k_out, k_ksk, digits, rank, rank) } } impl GLWECiphertext { + #[allow(dead_code)] pub(crate) fn assert_keyswitch( &self, module: &Module, @@ -70,7 +68,7 @@ impl GLWECiphertext { ) where DataLhs: DataRef, DataRhs: DataRef, - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes, Scratch: ScratchAvailable, { let basek: usize = self.basek(); @@ -139,8 +137,17 @@ impl GLWECiphertext { rhs: &GGLWESwitchingKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily, - Scratch: TakeVecZnxDft + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: ScratchAvailable + TakeVecZnxDft, { #[cfg(debug_assertions)] { @@ -159,8 +166,17 @@ impl GLWECiphertext { rhs: &GGLWESwitchingKeyPrepared, scratch: &mut Scratch, ) where - Module: GLWEKeyswitchFamily, - Scratch: TakeVecZnxDft + ScratchAvailable, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, + Scratch: ScratchAvailable + TakeVecZnxDft, { unsafe { let self_ptr: *mut GLWECiphertext = self as *mut GLWECiphertext; @@ -180,7 +196,16 @@ impl GLWECiphertext { where DataRes: DataMut, DataKey: DataRef, - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, Scratch: TakeVecZnxDft, { if rhs.digits() == 1 { diff --git a/core/src/keyswitching/lwe_ct.rs b/core/src/keyswitching/lwe_ct.rs index 70febf5..deb4697 100644 --- a/core/src/keyswitching/lwe_ct.rs +++ b/core/src/keyswitching/lwe_ct.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchAvailable, TakeVecZnx, TakeVecZnxDft, ZnxView, ZnxViewMut, ZnxZero}, + api::{ + ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxView, + ZnxViewMut, ZnxZero, + }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -8,8 +12,6 @@ use crate::{ layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::LWESwitchingKeyPrepared}, }; -use crate::trait_families::GLWEKeyswitchFamily; - impl LWECiphertext> { pub fn keyswitch_scratch_space( module: &Module, @@ -20,7 +22,16 @@ impl LWECiphertext> { k_ksk: usize, ) -> usize where - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, { GLWECiphertext::bytes_of(n, basek, k_lwe_out.max(k_lwe_in), 1) + GLWECiphertext::keyswitch_inplace_scratch_space(module, n, basek, k_lwe_out, k_ksk, 1, 1) @@ -37,7 +48,15 @@ impl LWECiphertext { ) where A: DataRef, DKs: DataRef, - Module: GLWEKeyswitchFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] diff --git a/core/src/layouts/compressed/gglwe_atk.rs b/core/src/layouts/compressed/gglwe_atk.rs index dcdb303..388da7e 100644 --- a/core/src/layouts/compressed/gglwe_atk.rs +++ b/core/src/layouts/compressed/gglwe_atk.rs @@ -3,12 +3,13 @@ use backend::hal::{ layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; -use crate::layouts::{GGLWEAutomorphismKey, Infos, compressed::GGLWESwitchingKeyCompressed}; +use crate::layouts::{ + GGLWEAutomorphismKey, Infos, + compressed::{Decompress, GGLWESwitchingKeyCompressed}, +}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; -use crate::trait_families::Decompress; - #[derive(PartialEq, Eq, Clone)] pub struct GGLWEAutomorphismKeyCompressed { pub(crate) key: GGLWESwitchingKeyCompressed, diff --git a/core/src/layouts/compressed/gglwe_ct.rs b/core/src/layouts/compressed/gglwe_ct.rs index 59643ce..a617f27 100644 --- a/core/src/layouts/compressed/gglwe_ct.rs +++ b/core/src/layouts/compressed/gglwe_ct.rs @@ -3,12 +3,13 @@ use backend::hal::{ layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; -use crate::layouts::{GGLWECiphertext, Infos, compressed::GLWECiphertextCompressed}; +use crate::layouts::{ + GGLWECiphertext, Infos, + compressed::{Decompress, GLWECiphertextCompressed}, +}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; -use crate::trait_families::Decompress; - #[derive(PartialEq, Eq, Clone)] pub struct GGLWECiphertextCompressed { pub(crate) data: MatZnx, diff --git a/core/src/layouts/compressed/gglwe_ksk.rs b/core/src/layouts/compressed/gglwe_ksk.rs index 02543cf..bc8607e 100644 --- a/core/src/layouts/compressed/gglwe_ksk.rs +++ b/core/src/layouts/compressed/gglwe_ksk.rs @@ -3,9 +3,9 @@ use backend::hal::{ layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; -use crate::{ - layouts::{GGLWESwitchingKey, Infos, compressed::GGLWECiphertextCompressed}, - trait_families::Decompress, +use crate::layouts::{ + GGLWESwitchingKey, Infos, + compressed::{Decompress, GGLWECiphertextCompressed}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; diff --git a/core/src/layouts/compressed/gglwe_tsk.rs b/core/src/layouts/compressed/gglwe_tsk.rs index 6fc913c..784a088 100644 --- a/core/src/layouts/compressed/gglwe_tsk.rs +++ b/core/src/layouts/compressed/gglwe_tsk.rs @@ -3,12 +3,13 @@ use backend::hal::{ layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; -use crate::layouts::{GGLWETensorKey, Infos, compressed::GGLWESwitchingKeyCompressed}; +use crate::layouts::{ + GGLWETensorKey, Infos, + compressed::{Decompress, GGLWESwitchingKeyCompressed}, +}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; -use crate::trait_families::Decompress; - #[derive(PartialEq, Eq, Clone)] pub struct GGLWETensorKeyCompressed { pub(crate) keys: Vec>, diff --git a/core/src/layouts/compressed/ggsw_ct.rs b/core/src/layouts/compressed/ggsw_ct.rs index 4dce213..8e25e58 100644 --- a/core/src/layouts/compressed/ggsw_ct.rs +++ b/core/src/layouts/compressed/ggsw_ct.rs @@ -3,9 +3,9 @@ use backend::hal::{ layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; -use crate::{ - layouts::{GGSWCiphertext, Infos, compressed::GLWECiphertextCompressed}, - trait_families::Decompress, +use crate::layouts::{ + GGSWCiphertext, Infos, + compressed::{Decompress, GLWECiphertextCompressed}, }; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; diff --git a/core/src/layouts/compressed/glwe_ct.rs b/core/src/layouts/compressed/glwe_ct.rs index 3d429b0..65a2057 100644 --- a/core/src/layouts/compressed/glwe_ct.rs +++ b/core/src/layouts/compressed/glwe_ct.rs @@ -1,13 +1,10 @@ use backend::hal::{ - api::{FillUniform, Reset, VecZnxCopy, VecZnxFillUniform, ZnxInfos}, + api::{FillUniform, Reset, VecZnxCopy, VecZnxFillUniform}, layouts::{Backend, Data, DataMut, DataRef, Module, ReaderFrom, VecZnx, WriterTo}, }; use sampling::source::Source; -use crate::{ - layouts::{GLWECiphertext, Infos}, - trait_families::{Decompress, DecompressFamily}, -}; +use crate::layouts::{GLWECiphertext, Infos, compressed::Decompress}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::fmt; @@ -117,10 +114,12 @@ impl WriterTo for GLWECiphertextCompressed { impl Decompress> for GLWECiphertext { fn decompress(&mut self, module: &Module, other: &GLWECiphertextCompressed) where - Module: DecompressFamily, + Module: VecZnxCopy + VecZnxFillUniform, { #[cfg(debug_assertions)] { + use backend::hal::api::ZnxInfos; + assert_eq!( self.n(), other.data.n(), @@ -142,9 +141,10 @@ impl Decompress GLWECiphertext { source: &mut Source, ) where DataOther: DataRef, - Module: DecompressFamily, + Module: VecZnxCopy + VecZnxFillUniform, { #[cfg(debug_assertions)] { diff --git a/core/src/layouts/compressed/glwe_to_lwe_ksk.rs b/core/src/layouts/compressed/glwe_to_lwe_ksk.rs index 3f190d4..3d65027 100644 --- a/core/src/layouts/compressed/glwe_to_lwe_ksk.rs +++ b/core/src/layouts/compressed/glwe_to_lwe_ksk.rs @@ -2,13 +2,16 @@ use std::fmt; use backend::hal::{ api::{FillUniform, Reset}, + api::{ + SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigNormalize, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + }, layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; use crate::layouts::{GLWEToLWESwitchingKey, Infos, compressed::GGLWESwitchingKeyCompressed}; -use crate::trait_families::{GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily}; - #[derive(PartialEq, Eq, Clone)] pub struct GLWEToLWESwitchingKeyCompressed(pub(crate) GGLWESwitchingKeyCompressed); @@ -91,7 +94,22 @@ impl GLWEToLWESwitchingKeyCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank_in: usize) -> usize where - Module: GGLWEEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc, { GLWEToLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_in) } diff --git a/core/src/layouts/compressed/lwe_ct.rs b/core/src/layouts/compressed/lwe_ct.rs index 7871b56..44b153a 100644 --- a/core/src/layouts/compressed/lwe_ct.rs +++ b/core/src/layouts/compressed/lwe_ct.rs @@ -6,10 +6,7 @@ use backend::hal::{ }; use sampling::source::Source; -use crate::{ - layouts::{Infos, LWECiphertext, SetMetaData}, - trait_families::Decompress, -}; +use crate::layouts::{Infos, LWECiphertext, SetMetaData, compressed::Decompress}; #[derive(PartialEq, Eq, Clone)] pub struct LWECiphertextCompressed { diff --git a/core/src/layouts/compressed/lwe_ksk.rs b/core/src/layouts/compressed/lwe_ksk.rs index 312fd2f..bbb304b 100644 --- a/core/src/layouts/compressed/lwe_ksk.rs +++ b/core/src/layouts/compressed/lwe_ksk.rs @@ -1,13 +1,18 @@ use backend::hal::{ - api::{FillUniform, Reset}, + api::{ + FillUniform, Reset, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, + VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + }, layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; -use crate::layouts::{Infos, LWESwitchingKey, compressed::GGLWESwitchingKeyCompressed}; +use crate::layouts::{ + Infos, LWESwitchingKey, + compressed::{Decompress, GGLWESwitchingKeyCompressed}, +}; use std::fmt; -use crate::trait_families::{Decompress, GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily}; - #[derive(PartialEq, Eq, Clone)] pub struct LWESwitchingKeyCompressed(pub(crate) GGLWESwitchingKeyCompressed); @@ -90,7 +95,22 @@ impl LWESwitchingKeyCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where - Module: GGLWEEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc, { LWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k) } @@ -99,7 +119,7 @@ impl LWESwitchingKeyCompressed> { impl Decompress> for LWESwitchingKey { fn decompress(&mut self, module: &Module, other: &LWESwitchingKeyCompressed) where - Module: crate::trait_families::DecompressFamily, + Module: VecZnxCopy + VecZnxFillUniform, { self.0.decompress(module, &other.0); } diff --git a/core/src/layouts/compressed/lwe_to_glwe_ksk.rs b/core/src/layouts/compressed/lwe_to_glwe_ksk.rs index 3c3be1c..ee3b8d0 100644 --- a/core/src/layouts/compressed/lwe_to_glwe_ksk.rs +++ b/core/src/layouts/compressed/lwe_to_glwe_ksk.rs @@ -1,16 +1,19 @@ use backend::hal::{ api::{FillUniform, Reset}, + api::{ + SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigNormalize, + VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + }, layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo}, }; -use crate::{ - layouts::{Infos, LWEToGLWESwitchingKey, compressed::GGLWESwitchingKeyCompressed}, - trait_families::Decompress, +use crate::layouts::{ + Infos, LWEToGLWESwitchingKey, + compressed::{Decompress, GGLWESwitchingKeyCompressed}, }; use std::fmt; -use crate::trait_families::{GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily}; - #[derive(PartialEq, Eq, Clone)] pub struct LWEToGLWESwitchingKeyCompressed(pub(crate) GGLWESwitchingKeyCompressed); @@ -93,7 +96,22 @@ impl LWEToGLWESwitchingKeyCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank_out: usize) -> usize where - Module: GGLWEEncryptSkFamily + GLWESecretPreparedModuleFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc, { LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_out) } @@ -102,7 +120,7 @@ impl LWEToGLWESwitchingKeyCompressed> { impl Decompress> for LWEToGLWESwitchingKey { fn decompress(&mut self, module: &Module, other: &LWEToGLWESwitchingKeyCompressed) where - Module: crate::trait_families::DecompressFamily, + Module: VecZnxCopy + VecZnxFillUniform, { self.0.decompress(module, &other.0); } diff --git a/core/src/layouts/compressed/mod.rs b/core/src/layouts/compressed/mod.rs index cd7c459..16bd4cd 100644 --- a/core/src/layouts/compressed/mod.rs +++ b/core/src/layouts/compressed/mod.rs @@ -19,3 +19,14 @@ pub use glwe_to_lwe_ksk::*; pub use lwe_ct::*; pub use lwe_ksk::*; pub use lwe_to_glwe_ksk::*; + +use backend::hal::{ + api::{VecZnxCopy, VecZnxFillUniform}, + layouts::{Backend, Module}, +}; + +pub trait Decompress { + fn decompress(&mut self, module: &Module, other: &C) + where + Module: VecZnxFillUniform + VecZnxCopy; +} diff --git a/core/src/layouts/lwe_pt.rs b/core/src/layouts/lwe_pt.rs index 957bcac..45807b8 100644 --- a/core/src/layouts/lwe_pt.rs +++ b/core/src/layouts/lwe_pt.rs @@ -87,3 +87,9 @@ impl LWEPlaintextToMut for LWEPlaintext { } } } + +impl LWEPlaintext { + pub fn data_mut(&mut self) -> &mut VecZnx { + &mut self.data + } +} diff --git a/core/src/layouts/prepared/gglwe_atk.rs b/core/src/layouts/prepared/gglwe_atk.rs index 0c60306..e5ff632 100644 --- a/core/src/layouts/prepared/gglwe_atk.rs +++ b/core/src/layouts/prepared/gglwe_atk.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -73,7 +73,7 @@ impl GGLWEAutomorphismKeyPrepared { impl Prepare> for GGLWEAutomorphismKeyPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &GGLWEAutomorphismKey, scratch: &mut Scratch) { self.key.prepare(module, &other.key, scratch); @@ -83,7 +83,7 @@ where impl PrepareAlloc, B>> for GGLWEAutomorphismKey where - Module: VmpPMatAlloc + VmpPMatPrepare, + Module: VmpPMatAlloc + VmpPrepare, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> GGLWEAutomorphismKeyPrepared, B> { let mut atk_prepared: GGLWEAutomorphismKeyPrepared, B> = GGLWEAutomorphismKeyPrepared::alloc( diff --git a/core/src/layouts/prepared/gglwe_ct.rs b/core/src/layouts/prepared/gglwe_ct.rs index 7bbd4e8..4ae2613 100644 --- a/core/src/layouts/prepared/gglwe_ct.rs +++ b/core/src/layouts/prepared/gglwe_ct.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -123,7 +123,7 @@ impl GGLWECiphertextPrepared { impl Prepare> for GGLWECiphertextPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &GGLWECiphertext, scratch: &mut Scratch) { module.vmp_prepare(&mut self.data, &other.data, scratch); @@ -135,7 +135,7 @@ where impl PrepareAlloc, B>> for GGLWECiphertext where - Module: VmpPMatAlloc + VmpPMatPrepare, + Module: VmpPMatAlloc + VmpPrepare, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> GGLWECiphertextPrepared, B> { let mut atk_prepared: GGLWECiphertextPrepared, B> = GGLWECiphertextPrepared::alloc( diff --git a/core/src/layouts/prepared/gglwe_ksk.rs b/core/src/layouts/prepared/gglwe_ksk.rs index 0fb9bc5..a269dbb 100644 --- a/core/src/layouts/prepared/gglwe_ksk.rs +++ b/core/src/layouts/prepared/gglwe_ksk.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -97,7 +97,7 @@ impl GGLWESwitchingKeyPrepared { impl Prepare> for GGLWESwitchingKeyPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &GGLWESwitchingKey, scratch: &mut Scratch) { self.key.prepare(module, &other.key, scratch); @@ -108,7 +108,7 @@ where impl PrepareAlloc, B>> for GGLWESwitchingKey where - Module: VmpPMatAlloc + VmpPMatPrepare, + Module: VmpPMatAlloc + VmpPrepare, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> GGLWESwitchingKeyPrepared, B> { let mut atk_prepared: GGLWESwitchingKeyPrepared, B> = GGLWESwitchingKeyPrepared::alloc( diff --git a/core/src/layouts/prepared/gglwe_tsk.rs b/core/src/layouts/prepared/gglwe_tsk.rs index adbb13e..1b4cdd3 100644 --- a/core/src/layouts/prepared/gglwe_tsk.rs +++ b/core/src/layouts/prepared/gglwe_tsk.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -95,7 +95,7 @@ impl GGLWETensorKeyPrepared { impl Prepare> for GGLWETensorKeyPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &GGLWETensorKey, scratch: &mut Scratch) { #[cfg(debug_assertions)] @@ -113,7 +113,7 @@ where impl PrepareAlloc, B>> for GGLWETensorKey where - Module: VmpPMatAlloc + VmpPMatPrepare, + Module: VmpPMatAlloc + VmpPrepare, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> GGLWETensorKeyPrepared, B> { let mut tsk_prepared: GGLWETensorKeyPrepared, B> = GGLWETensorKeyPrepared::alloc( diff --git a/core/src/layouts/prepared/ggsw_ct.rs b/core/src/layouts/prepared/ggsw_ct.rs index 814145b..3034d5e 100644 --- a/core/src/layouts/prepared/ggsw_ct.rs +++ b/core/src/layouts/prepared/ggsw_ct.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -105,7 +105,7 @@ impl GGSWCiphertextPrepared { impl Prepare> for GGSWCiphertextPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &GGSWCiphertext, scratch: &mut Scratch) { module.vmp_prepare(&mut self.data, &other.data, scratch); @@ -117,7 +117,7 @@ where impl PrepareAlloc, B>> for GGSWCiphertext where - Module: VmpPMatAlloc + VmpPMatPrepare, + Module: VmpPMatAlloc + VmpPrepare, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> GGSWCiphertextPrepared, B> { let mut ggsw_prepared: GGSWCiphertextPrepared, B> = GGSWCiphertextPrepared::alloc( diff --git a/core/src/layouts/prepared/glwe_sk.rs b/core/src/layouts/prepared/glwe_sk.rs index 97faa9b..d7fe23b 100644 --- a/core/src/layouts/prepared/glwe_sk.rs +++ b/core/src/layouts/prepared/glwe_sk.rs @@ -9,7 +9,6 @@ use crate::{ GLWESecret, prepared::{Prepare, PrepareAlloc}, }, - trait_families::GLWESecretPreparedModuleFamily, }; pub struct GLWESecretPrepared { @@ -20,7 +19,7 @@ pub struct GLWESecretPrepared { impl GLWESecretPrepared, B> { pub fn alloc(module: &Module, n: usize, rank: usize) -> Self where - Module: GLWESecretPreparedModuleFamily, + Module: SvpPPolAlloc, { Self { data: module.svp_ppol_alloc(n, rank), @@ -30,7 +29,7 @@ impl GLWESecretPrepared, B> { pub fn bytes_of(module: &Module, n: usize, rank: usize) -> usize where - Module: GLWESecretPreparedModuleFamily, + Module: SvpPPolAllocBytes, { module.svp_ppol_alloc_bytes(n, rank) } @@ -52,7 +51,7 @@ impl GLWESecretPrepared { impl PrepareAlloc, B>> for GLWESecret where - Module: SvpPrepare + SvpPPolAllocBytes + SvpPPolAlloc, + Module: SvpPrepare + SvpPPolAlloc, { fn prepare_alloc( &self, diff --git a/core/src/layouts/prepared/glwe_to_lwe_ksk.rs b/core/src/layouts/prepared/glwe_to_lwe_ksk.rs index 9ee9a1b..4befe50 100644 --- a/core/src/layouts/prepared/glwe_to_lwe_ksk.rs +++ b/core/src/layouts/prepared/glwe_to_lwe_ksk.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -65,7 +65,7 @@ impl GLWEToLWESwitchingKeyPrepared, B> { impl PrepareAlloc, B>> for GLWEToLWESwitchingKey where - Module: VmpPMatPrepare + VmpPMatAlloc, + Module: VmpPrepare + VmpPMatAlloc, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> GLWEToLWESwitchingKeyPrepared, B> { let mut ksk_prepared: GLWEToLWESwitchingKeyPrepared, B> = GLWEToLWESwitchingKeyPrepared::alloc( @@ -83,7 +83,7 @@ where impl Prepare> for GLWEToLWESwitchingKeyPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &GLWEToLWESwitchingKey, scratch: &mut Scratch) { self.0.prepare(module, &other.0, scratch); diff --git a/core/src/layouts/prepared/lwe_ksk.rs b/core/src/layouts/prepared/lwe_ksk.rs index f3676e9..358498f 100644 --- a/core/src/layouts/prepared/lwe_ksk.rs +++ b/core/src/layouts/prepared/lwe_ksk.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -65,7 +65,7 @@ impl LWESwitchingKeyPrepared, B> { impl PrepareAlloc, B>> for LWESwitchingKey where - Module: VmpPMatPrepare + VmpPMatAlloc, + Module: VmpPrepare + VmpPMatAlloc, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> LWESwitchingKeyPrepared, B> { let mut ksk_prepared: LWESwitchingKeyPrepared, B> = LWESwitchingKeyPrepared::alloc( @@ -82,7 +82,7 @@ where impl Prepare> for LWESwitchingKeyPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &LWESwitchingKey, scratch: &mut Scratch) { self.0.prepare(module, &other.0, scratch); diff --git a/core/src/layouts/prepared/lwe_to_glwe_ksk.rs b/core/src/layouts/prepared/lwe_to_glwe_ksk.rs index 40a9356..806f534 100644 --- a/core/src/layouts/prepared/lwe_to_glwe_ksk.rs +++ b/core/src/layouts/prepared/lwe_to_glwe_ksk.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, + api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; @@ -66,7 +66,7 @@ impl LWEToGLWESwitchingKeyPrepared, B> { impl PrepareAlloc, B>> for LWEToGLWESwitchingKey where - Module: VmpPMatPrepare + VmpPMatAlloc, + Module: VmpPrepare + VmpPMatAlloc, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> LWEToGLWESwitchingKeyPrepared, B> { let mut ksk_prepared: LWEToGLWESwitchingKeyPrepared, B> = LWEToGLWESwitchingKeyPrepared::alloc( @@ -84,7 +84,7 @@ where impl Prepare> for LWEToGLWESwitchingKeyPrepared where - Module: VmpPMatPrepare, + Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &LWEToGLWESwitchingKey, scratch: &mut Scratch) { self.0.prepare(module, &other.0, scratch); diff --git a/core/src/lib.rs b/core/src/lib.rs index 53652cd..8c9e78d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(trait_alias)] mod automorphism; mod conversion; mod decryption; @@ -15,7 +14,6 @@ mod utils; pub use operations::*; pub mod layouts; -pub mod trait_families; pub use dist::*; pub use glwe_packing::*; diff --git a/core/src/noise/gglwe_ct.rs b/core/src/noise/gglwe_ct.rs index 77b4122..78c82ca 100644 --- a/core/src/noise/gglwe_ct.rs +++ b/core/src/noise/gglwe_ct.rs @@ -1,13 +1,14 @@ use backend::hal::{ - api::{ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxSubScalarInplace, ZnxZero}, + api::{ + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VecZnxNormalizeTmpBytes, VecZnxSubScalarInplace, ZnxZero, + }, layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, }; -use crate::{ - layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}, - trait_families::GLWEDecryptFamily, -}; +use crate::layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}; impl GGLWECiphertext { pub fn assert_noise( @@ -19,7 +20,16 @@ impl GGLWECiphertext { ) where DataSk: DataRef, DataWant: DataRef, - Module: GLWEDecryptFamily + VecZnxSubScalarInplace, + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxSubScalarInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let digits: usize = self.digits(); diff --git a/core/src/noise/ggsw_ct.rs b/core/src/noise/ggsw_ct.rs index a47ea3c..27cc6a2 100644 --- a/core/src/noise/ggsw_ct.rs +++ b/core/src/noise/ggsw_ct.rs @@ -1,16 +1,15 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxBigAlloc, VecZnxBigNormalize, VecZnxDftAlloc, - VecZnxDftToVecZnxBigTmpA, VecZnxNormalizeTmpBytes, VecZnxSubABInplace, ZnxZero, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, VecZnxAddScalarInplace, VecZnxBigAddInplace, + VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, + VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, + VecZnxNormalizeTmpBytes, VecZnxSubABInplace, ZnxZero, }, layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned, VecZnxBig, VecZnxDft}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, }; -use crate::{ - layouts::{GGSWCiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}, - trait_families::GGSWAssertNoiseFamily, -}; +use crate::layouts::{GGSWCiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared}; impl GGSWCiphertext { pub fn assert_noise( @@ -22,7 +21,21 @@ impl GGSWCiphertext { ) where DataSk: DataRef, DataScalar: DataRef, - Module: GGSWAssertNoiseFamily + VecZnxAddScalarInplace + VecZnxSubABInplace, + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA + + VecZnxAddScalarInplace + + VecZnxSubABInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, F: Fn(usize) -> f64, { @@ -76,7 +89,21 @@ impl GGSWCiphertext { ) where DataSk: DataRef, DataScalar: DataRef, - Module: GGSWAssertNoiseFamily + VecZnxAddScalarInplace + VecZnxSubABInplace, + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA + + VecZnxAddScalarInplace + + VecZnxSubABInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let basek: usize = self.basek(); @@ -110,7 +137,7 @@ impl GGSWCiphertext { module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt.data, 0); let std_pt: f64 = pt_have.data.std(basek, 0).log2(); - println!("{}", std_pt); + println!("col: {} row: {}: {}", col_j, row_i, std_pt); pt.data.zero(); }); }); diff --git a/core/src/noise/glwe_ct.rs b/core/src/noise/glwe_ct.rs index 2a5e9bf..a4e7fb7 100644 --- a/core/src/noise/glwe_ct.rs +++ b/core/src/noise/glwe_ct.rs @@ -1,5 +1,9 @@ use backend::hal::{ - api::{ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxNormalizeInplace, VecZnxSubABInplace}, + api::{ + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSubABInplace, + }, layouts::{Backend, DataRef, Module, ScratchOwned}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, }; @@ -8,7 +12,6 @@ use crate::{ layouts::GLWEPlaintext, layouts::prepared::GLWESecretPrepared, layouts::{GLWECiphertext, Infos}, - trait_families::GLWEDecryptFamily, }; impl GLWECiphertext { @@ -21,7 +24,17 @@ impl GLWECiphertext { ) where DataSk: DataRef, DataPt: DataRef, - Module: GLWEDecryptFamily + VecZnxSubABInplace + VecZnxNormalizeInplace, + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxSubABInplace + + VecZnxNormalizeInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc(self.n(), self.basek(), self.k()); diff --git a/core/src/scratch.rs b/core/src/scratch.rs index 7ba0bd0..39a364f 100644 --- a/core/src/scratch.rs +++ b/core/src/scratch.rs @@ -21,11 +21,11 @@ pub trait TakeLike<'a, B: Backend, T> { fn take_like(&'a mut self, template: &T) -> (Self::Output, &'a mut Self); } -pub trait TakeGLWECt { +pub trait TakeGLWECt { fn take_glwe_ct(&mut self, n: usize, basek: usize, k: usize, rank: usize) -> (GLWECiphertext<&mut [u8]>, &mut Self); } -pub trait TakeGLWECtSlice { +pub trait TakeGLWECtSlice { fn take_glwe_ct_slice( &mut self, size: usize, @@ -40,7 +40,7 @@ pub trait TakeGLWEPt { fn take_glwe_pt(&mut self, n: usize, basek: usize, k: usize) -> (GLWEPlaintext<&mut [u8]>, &mut Self); } -pub trait TakeGGLWE { +pub trait TakeGGLWE { fn take_gglwe( &mut self, n: usize, @@ -66,7 +66,7 @@ pub trait TakeGGLWEPrepared { ) -> (GGLWECiphertextPrepared<&mut [u8], B>, &mut Self); } -pub trait TakeGGSW { +pub trait TakeGGSW { fn take_ggsw( &mut self, n: usize, @@ -90,7 +90,7 @@ pub trait TakeGGSWPrepared { ) -> (GGSWCiphertextPrepared<&mut [u8], B>, &mut Self); } -pub trait TakeGLWESecret { +pub trait TakeGLWESecret { fn take_glwe_secret(&mut self, n: usize, rank: usize) -> (GLWESecret<&mut [u8]>, &mut Self); } @@ -98,7 +98,7 @@ pub trait TakeGLWESecretPrepared { fn take_glwe_secret_prepared(&mut self, n: usize, rank: usize) -> (GLWESecretPrepared<&mut [u8], B>, &mut Self); } -pub trait TakeGLWEPk { +pub trait TakeGLWEPk { fn take_glwe_pk(&mut self, n: usize, basek: usize, k: usize, rank: usize) -> (GLWEPublicKey<&mut [u8]>, &mut Self); } @@ -112,7 +112,7 @@ pub trait TakeGLWEPkPrepared { ) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self); } -pub trait TakeGLWESwitchingKey { +pub trait TakeGLWESwitchingKey { fn take_glwe_switching_key( &mut self, n: usize, @@ -138,7 +138,7 @@ pub trait TakeGLWESwitchingKeyPrepared { ) -> (GGLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self); } -pub trait TakeTensorKey { +pub trait TakeTensorKey { fn take_tensor_key( &mut self, n: usize, @@ -162,7 +162,7 @@ pub trait TakeTensorKeyPrepared { ) -> (GGLWETensorKeyPrepared<&mut [u8], B>, &mut Self); } -pub trait TakeAutomorphismKey { +pub trait TakeAutomorphismKey { fn take_automorphism_key( &mut self, n: usize, @@ -186,7 +186,7 @@ pub trait TakeAutomorphismKeyPrepared { ) -> (GGLWEAutomorphismKeyPrepared<&mut [u8], B>, &mut Self); } -impl TakeGLWECt for Scratch +impl TakeGLWECt for Scratch where Scratch: TakeVecZnx, { @@ -216,7 +216,7 @@ where } } -impl TakeGLWECtSlice for Scratch +impl TakeGLWECtSlice for Scratch where Scratch: TakeVecZnx, { @@ -269,7 +269,7 @@ where } } -impl TakeGGLWE for Scratch +impl TakeGGLWE for Scratch where Scratch: TakeMatZnx, { @@ -391,7 +391,7 @@ where } } -impl TakeGGSW for Scratch +impl TakeGGSW for Scratch where Scratch: TakeMatZnx, { @@ -511,7 +511,7 @@ where } } -impl TakeGLWEPk for Scratch +impl TakeGLWEPk for Scratch where Scratch: TakeVecZnx, { @@ -595,7 +595,7 @@ where } } -impl TakeGLWESecret for Scratch +impl TakeGLWESecret for Scratch where Scratch: TakeScalarZnx, { @@ -665,7 +665,7 @@ where } } -impl TakeGLWESwitchingKey for Scratch +impl TakeGLWESwitchingKey for Scratch where Scratch: TakeMatZnx, { @@ -759,7 +759,7 @@ where } } -impl TakeAutomorphismKey for Scratch +impl TakeAutomorphismKey for Scratch where Scratch: TakeMatZnx, { @@ -823,7 +823,7 @@ where } } -impl TakeTensorKey for Scratch +impl TakeTensorKey for Scratch where Scratch: TakeMatZnx, { diff --git a/core/src/tests/generics/automorphism/gglwe_atk.rs b/core/src/tests/generics/automorphism/gglwe_atk.rs index fb08745..ff72e0d 100644 --- a/core/src/tests/generics/automorphism/gglwe_atk.rs +++ b/core/src/tests/generics/automorphism/gglwe_atk.rs @@ -1,7 +1,11 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxCopy, - VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxBigAddInplace, + VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSubScalarInplace, + VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -17,11 +21,8 @@ use crate::{ prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, - trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily}, }; -use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_gglwe_automorphism_key_automorphism( module: &Module, p0: i64, @@ -34,19 +35,36 @@ pub fn test_gglwe_automorphism_key_automorphism( sigma: f64, rank: usize, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEKeyswitchFamily - + VecZnxAutomorphism - + VecZnxSwithcDegree - + VecZnxAddScalarInplace + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + VecZnxAutomorphism + VecZnxAutomorphismInplace - + GLWEDecryptFamily - + VecZnxSubScalarInplace - + VecZnxCopy + + SvpPPolAllocBytes + + VecZnxDftAllocBytes + + VecZnxNormalizeTmpBytes + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + SvpPrepare + + SvpApplyInplace + + VecZnxAddScalarInplace + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + VecZnxSwithcDegree + + SvpPPolAlloc + + VecZnxBigAddInplace + + VecZnxSubScalarInplace, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl @@ -179,19 +197,50 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace( sigma: f64, rank: usize, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEKeyswitchFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + VecZnxAutomorphism + VecZnxSwithcDegree + VecZnxAddScalarInplace + VecZnxAutomorphism + VecZnxAutomorphismInplace - + GLWEDecryptFamily + + VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + VecZnxSubScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/automorphism/ggsw_ct.rs b/core/src/tests/generics/automorphism/ggsw_ct.rs index 61967f6..dd56e2b 100644 --- a/core/src/tests/generics/automorphism/ggsw_ct.rs +++ b/core/src/tests/generics/automorphism/ggsw_ct.rs @@ -1,7 +1,12 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxCopy, - VecZnxSubABInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, + VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAllocBytes, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAddInplace, VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftCopy, + VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, + VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScalarZnx, ScratchOwned}, oep::{ @@ -17,11 +22,6 @@ use crate::{ prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, }, noise::noise_ggsw_keyswitch, - trait_families::GGSWAssertNoiseFamily, -}; - -use crate::trait_families::{ - GGLWESwitchingKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWKeySwitchFamily, GLWESecretPreparedModuleFamily, }; pub fn test_ggsw_automorphism( @@ -36,23 +36,44 @@ pub fn test_ggsw_automorphism( rank: usize, sigma: f64, ) where - Module: GGSWAssertNoiseFamily - + GLWESecretPreparedModuleFamily + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + VecZnxAddScalarInplace + VecZnxCopy + VecZnxSubABInplace + VmpPMatAlloc - + VmpPMatPrepare - + GGSWKeySwitchFamily - + GGLWESwitchingKeyEncryptSkFamily - + GGLWETensorKeyEncryptSkFamily + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxFillUniform + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpApply + VecZnxSwithcDegree + VecZnxAutomorphismInplace - + VecZnxAutomorphismInplace + VecZnxAutomorphism, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl @@ -171,23 +192,45 @@ pub fn test_ggsw_automorphism_inplace( rank: usize, sigma: f64, ) where - Module: GGSWAssertNoiseFamily - + GLWESecretPreparedModuleFamily + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + VecZnxAddScalarInplace + VecZnxCopy + VecZnxSubABInplace + VmpPMatAlloc - + VmpPMatPrepare - + GGSWKeySwitchFamily - + GGLWESwitchingKeyEncryptSkFamily - + GGLWETensorKeyEncryptSkFamily + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigAddSmallInplace + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + VecZnxFillUniform + + SvpApply + VecZnxSwithcDegree + VecZnxAutomorphismInplace - + VecZnxAutomorphismInplace + VecZnxAutomorphism, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/automorphism/glwe_ct.rs b/core/src/tests/generics/automorphism/glwe_ct.rs index 0977171..1bd5821 100644 --- a/core/src/tests/generics/automorphism/glwe_ct.rs +++ b/core/src/tests/generics/automorphism/glwe_ct.rs @@ -1,7 +1,11 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, - VecZnxFillUniform, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxBigAddInplace, + VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, + VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, + VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -17,11 +21,8 @@ use crate::{ prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, - trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily}, }; -use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_glwe_automorphism( module: &Module, basek: usize, @@ -33,16 +34,35 @@ pub fn test_glwe_automorphism( rank: usize, sigma: f64, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + GLWEKeyswitchFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + VecZnxAutomorphism + VecZnxSwithcDegree + VecZnxAddScalarInplace + VecZnxAutomorphismInplace + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -140,16 +160,35 @@ pub fn test_glwe_automorphism_inplace( rank: usize, sigma: f64, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + GLWEKeyswitchFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + VecZnxAutomorphism + VecZnxSwithcDegree + VecZnxAddScalarInplace + VecZnxAutomorphismInplace + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl diff --git a/core/src/tests/generics/conversion.rs b/core/src/tests/generics/conversion.rs index a593805..e2c702c 100644 --- a/core/src/tests/generics/conversion.rs +++ b/core/src/tests/generics/conversion.rs @@ -1,7 +1,11 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxSwithcDegree, - VmpPMatAlloc, VmpPMatPrepare, ZnxView, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, + VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, + ZnxView, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -17,27 +21,44 @@ use crate::layouts::{ prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GLWEDecryptFamily, GLWEKeyswitchFamily, GLWESecretPreparedModuleFamily}; - pub fn test_lwe_to_glwe(module: &Module) where - Module: GGLWEEncryptSkFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace - + GLWEKeyswitchFamily - + VecZnxAutomorphismInplace + VmpPMatAlloc - + VmpPMatPrepare - + GLWESecretPreparedModuleFamily, - B: TakeScalarZnxImpl - + TakeVecZnxDftImpl - + ScratchAvailableImpl - + TakeVecZnxImpl + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxAutomorphismInplace, + B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl + ScratchOwnedAllocImpl - + ScratchOwnedBorrowImpl, + + ScratchOwnedBorrowImpl + + ScratchAvailableImpl + + TakeScalarZnxImpl + + TakeVecZnxImpl, { let n: usize = module.n(); let basek: usize = 17; @@ -112,23 +133,42 @@ where pub fn test_glwe_to_lwe(module: &Module) where - Module: GGLWEEncryptSkFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace - + GLWEKeyswitchFamily - + VecZnxAutomorphismInplace + VmpPMatAlloc - + VmpPMatPrepare - + GLWESecretPreparedModuleFamily, - B: TakeScalarZnxImpl - + TakeVecZnxDftImpl - + ScratchAvailableImpl - + TakeVecZnxImpl + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxAutomorphismInplace, + B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl + ScratchOwnedAllocImpl - + ScratchOwnedBorrowImpl, + + ScratchOwnedBorrowImpl + + ScratchAvailableImpl + + TakeScalarZnxImpl + + TakeVecZnxImpl, { let n: usize = module.n(); let basek: usize = 17; diff --git a/core/src/tests/generics/encryption/gglwe_atk.rs b/core/src/tests/generics/encryption/gglwe_atk.rs index 72fb304..ce58e8c 100644 --- a/core/src/tests/generics/encryption/gglwe_atk.rs +++ b/core/src/tests/generics/encryption/gglwe_atk.rs @@ -1,7 +1,11 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxCopy, - VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxBigAddInplace, + VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSubScalarInplace, + VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -11,17 +15,12 @@ use backend::hal::{ }; use sampling::source::Source; -use crate::{ - layouts::{ - GGLWEAutomorphismKey, GLWESecret, - compressed::GGLWEAutomorphismKeyCompressed, - prepared::{GLWESecretPrepared, PrepareAlloc}, - }, - trait_families::{Decompress, GLWEDecryptFamily, GLWEKeyswitchFamily}, +use crate::layouts::{ + GGLWEAutomorphismKey, GLWESecret, + compressed::{Decompress, GGLWEAutomorphismKeyCompressed}, + prepared::{GLWESecretPrepared, PrepareAlloc}, }; -use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_gglwe_automorphisk_key_encrypt_sk( module: &Module, basek: usize, @@ -30,19 +29,37 @@ pub fn test_gglwe_automorphisk_key_encrypt_sk( rank: usize, sigma: f64, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEKeyswitchFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigAddSmallInplace + VecZnxAutomorphism + VecZnxSwithcDegree + VecZnxAddScalarInplace - + VecZnxAutomorphism + VecZnxAutomorphismInplace - + GLWEDecryptFamily + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + VecZnxSubScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl @@ -105,19 +122,37 @@ pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk( rank: usize, sigma: f64, ) where - Module: GGLWEAutomorphismKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEKeyswitchFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigAddSmallInplace + VecZnxAutomorphism + VecZnxSwithcDegree + VecZnxAddScalarInplace - + VecZnxAutomorphism + VecZnxAutomorphismInplace - + GLWEDecryptFamily + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + VecZnxSubScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/encryption/gglwe_ct.rs b/core/src/tests/generics/encryption/gglwe_ct.rs index 855eb56..d51949d 100644 --- a/core/src/tests/generics/encryption/gglwe_ct.rs +++ b/core/src/tests/generics/encryption/gglwe_ct.rs @@ -1,7 +1,10 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubScalarInplace, VecZnxSwithcDegree, - VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSubScalarInplace, + VecZnxSwithcDegree, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -11,17 +14,12 @@ use backend::hal::{ }; use sampling::source::Source; -use crate::{ - layouts::{ - GGLWESwitchingKey, GLWESecret, - compressed::GGLWESwitchingKeyCompressed, - prepared::{GLWESecretPrepared, PrepareAlloc}, - }, - trait_families::{Decompress, GLWEDecryptFamily}, +use crate::layouts::{ + GGLWESwitchingKey, GLWESecret, + compressed::{Decompress, GGLWESwitchingKeyCompressed}, + prepared::{GLWESecretPrepared, PrepareAlloc}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_gglwe_switching_key_encrypt_sk( module: &Module, basek: usize, @@ -31,18 +29,33 @@ pub fn test_gglwe_switching_key_encrypt_sk( rank_out: usize, sigma: f64, ) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAddSmallInplace + VecZnxSwithcDegree + VecZnxAddScalarInplace + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + VecZnxSubScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl @@ -95,18 +108,33 @@ pub fn test_gglwe_switching_key_compressed_encrypt_sk( rank_out: usize, sigma: f64, ) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAddSmallInplace + VecZnxSwithcDegree + VecZnxAddScalarInplace + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + VecZnxSubScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/encryption/ggsw_ct.rs b/core/src/tests/generics/encryption/ggsw_ct.rs index d2c5e6f..2a1ec82 100644 --- a/core/src/tests/generics/encryption/ggsw_ct.rs +++ b/core/src/tests/generics/encryption/ggsw_ct.rs @@ -1,7 +1,10 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubABInplace, VmpPMatAlloc, - VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAlloc, VecZnxDftAllocBytes, + VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScalarZnx, ScratchOwned}, oep::{ @@ -11,27 +14,41 @@ use backend::hal::{ }; use sampling::source::Source; -use crate::{ - layouts::{ - GGSWCiphertext, GLWESecret, - compressed::GGSWCiphertextCompressed, - prepared::{GLWESecretPrepared, PrepareAlloc}, - }, - trait_families::{Decompress, GGSWAssertNoiseFamily}, +use crate::layouts::{ + GGSWCiphertext, GLWESecret, + compressed::{Decompress, GGSWCiphertextCompressed}, + prepared::{GLWESecretPrepared, PrepareAlloc}, }; -use crate::trait_families::{GGSWEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_ggsw_encrypt_sk(module: &Module, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64) where - Module: GLWESecretPreparedModuleFamily - + GGSWEncryptSkFamily - + GGSWAssertNoiseFamily - + VecZnxAddScalarInplace + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAddSmallInplace + + VecZnxAddScalarInplace + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -88,17 +105,35 @@ pub fn test_ggsw_compressed_encrypt_sk( rank: usize, sigma: f64, ) where - Module: GLWESecretPreparedModuleFamily - + GGSWEncryptSkFamily - + GGSWAssertNoiseFamily - + VecZnxAddScalarInplace + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAddSmallInplace + + VecZnxAddScalarInplace + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/encryption/glwe_ct.rs b/core/src/tests/generics/encryption/glwe_ct.rs index 9aeebe9..43bbe24 100644 --- a/core/src/tests/generics/encryption/glwe_ct.rs +++ b/core/src/tests/generics/encryption/glwe_ct.rs @@ -1,5 +1,11 @@ use backend::hal::{ - api::{ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxCopy, VecZnxDftAlloc, VecZnxFillUniform, VecZnxSubABInplace}, + api::{ + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, + VecZnxAddInplace, VecZnxAddNormal, VecZnxBigAddInplace, VecZnxBigAddNormal, VecZnxBigAddSmallInplace, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxCopy, VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, + VecZnxSub, VecZnxSubABInplace, + }, layouts::{Backend, Module, ScratchOwned}, oep::{ ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl, @@ -11,21 +17,49 @@ use sampling::source::Source; use crate::{ layouts::{ GLWECiphertext, GLWEPlaintext, GLWEPublicKey, GLWESecret, Infos, - compressed::GLWECiphertextCompressed, + compressed::{Decompress, GLWECiphertextCompressed}, prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, operations::GLWEOperations, - trait_families::Decompress, }; -use crate::trait_families::{GLWEDecryptFamily, GLWEEncryptPkFamily, GLWEEncryptSkFamily, GLWESecretPreparedModuleFamily}; - -pub trait EncryptionTestModuleFamily = - GLWEDecryptFamily + GLWESecretPreparedModuleFamily + GLWEEncryptPkFamily; - pub fn test_glwe_encrypt_sk(module: &Module, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize) where - Module: EncryptionTestModuleFamily + GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + SvpPPolAllocBytes + + SvpPrepare + + SvpApply + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddNormal + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -83,7 +117,42 @@ pub fn test_glwe_compressed_encrypt_sk( sigma: f64, rank: usize, ) where - Module: EncryptionTestModuleFamily + GLWEEncryptSkFamily + VecZnxCopy, + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + SvpPPolAllocBytes + + SvpPrepare + + SvpApply + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddNormal + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + VecZnxCopy, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -146,7 +215,41 @@ pub fn test_glwe_compressed_encrypt_sk( pub fn test_glwe_encrypt_zero_sk(module: &Module, basek: usize, k_ct: usize, sigma: f64, rank: usize) where - Module: EncryptionTestModuleFamily + GLWEEncryptSkFamily, + Module: VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxDftAllocBytes + + VecZnxBigAllocBytes + + SvpPPolAllocBytes + + SvpPrepare + + SvpApply + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddNormal + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -189,8 +292,29 @@ where pub fn test_glwe_encrypt_pk(module: &Module, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize) where - Module: - EncryptionTestModuleFamily + GLWEEncryptSkFamily + VecZnxDftAlloc + VecZnxFillUniform + VecZnxSubABInplace, + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAddSmallInplace + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxCopy + + VecZnxDftAlloc + + SvpApply + + VecZnxBigAddNormal, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl diff --git a/core/src/tests/generics/encryption/glwe_tsk.rs b/core/src/tests/generics/encryption/glwe_tsk.rs index df20016..d4504f4 100644 --- a/core/src/tests/generics/encryption/glwe_tsk.rs +++ b/core/src/tests/generics/encryption/glwe_tsk.rs @@ -1,7 +1,10 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxBigAlloc, VecZnxCopy, VecZnxDftAlloc, - VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxCopy, VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSubScalarInplace, VecZnxSwithcDegree, }, layouts::{Backend, Module, ScratchOwned, VecZnxDft}, oep::{ @@ -11,34 +14,43 @@ use backend::hal::{ }; use sampling::source::Source; -use crate::{ - layouts::{ - GGLWETensorKey, GLWEPlaintext, GLWESecret, Infos, - compressed::GGLWETensorKeyCompressed, - prepared::{GLWESecretPrepared, PrepareAlloc}, - }, - trait_families::{Decompress, GLWEDecryptFamily}, +use crate::layouts::{ + GGLWETensorKey, GLWEPlaintext, GLWESecret, Infos, + compressed::{Decompress, GGLWETensorKeyCompressed}, + prepared::{GLWESecretPrepared, PrepareAlloc}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_glwe_tensor_key_encrypt_sk(module: &Module, basek: usize, k: usize, sigma: f64, rank: usize) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree - + VecZnxAddScalarInplace - + VecZnxSubScalarInplace - + VmpPMatAlloc - + VmpPMatPrepare - + GGLWETensorKeyEncryptSkFamily - + GLWEDecryptFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAddSmallInplace + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxCopy + VecZnxDftAlloc - + VecZnxBigAlloc, + + SvpApply + + VecZnxBigAlloc + + VecZnxDftToVecZnxBigTmpA + + VecZnxAddScalarInplace + + VecZnxSwithcDegree + + VecZnxSubScalarInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl @@ -120,22 +132,35 @@ where pub fn test_glwe_tensor_key_compressed_encrypt_sk(module: &Module, basek: usize, k: usize, sigma: f64, rank: usize) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree - + VecZnxAddScalarInplace - + VecZnxSubScalarInplace - + VmpPMatAlloc - + VmpPMatPrepare - + GGLWETensorKeyEncryptSkFamily - + GLWEDecryptFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAddSmallInplace + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxCopy + VecZnxDftAlloc + + SvpApply + VecZnxBigAlloc - + VecZnxCopy, + + VecZnxDftToVecZnxBigTmpA + + VecZnxAddScalarInplace + + VecZnxSwithcDegree + + VecZnxSubScalarInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/external_product/gglwe_ksk.rs b/core/src/tests/generics/external_product/gglwe_ksk.rs index d85729e..36762dd 100644 --- a/core/src/tests/generics/external_product/gglwe_ksk.rs +++ b/core/src/tests/generics/external_product/gglwe_ksk.rs @@ -1,7 +1,11 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxRotateInplace, VecZnxSubScalarInplace, - VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, ZnxViewMut, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotateInplace, VecZnxSub, VecZnxSubABInplace, + VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, + ZnxViewMut, }, layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, ScratchOwned}, oep::{ @@ -17,11 +21,8 @@ use crate::{ prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::noise_ggsw_product, - trait_families::{GLWEDecryptFamily, GLWEExternalProductFamily}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_gglwe_switching_key_external_product( module: &Module, basek: usize, @@ -33,22 +34,37 @@ pub fn test_gglwe_switching_key_external_product( rank_out: usize, sigma: f64, ) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + VecZnxSwithcDegree + VecZnxAddScalarInplace + VecZnxSubScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare - + GGLWESwitchingKeyEncryptSkFamily - + GLWEExternalProductFamily - + GLWEDecryptFamily - + VecZnxRotateInplace, + + VecZnxRotateInplace + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VmpPrepare, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl @@ -159,22 +175,37 @@ pub fn test_gglwe_switching_key_external_product_inplace( rank_out: usize, sigma: f64, ) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + VecZnxSwithcDegree + VecZnxAddScalarInplace + VecZnxSubScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare - + GGLWESwitchingKeyEncryptSkFamily - + GLWEExternalProductFamily - + GLWEDecryptFamily - + VecZnxRotateInplace, + + VecZnxRotateInplace + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VmpPrepare, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/external_product/ggsw_ct.rs b/core/src/tests/generics/external_product/ggsw_ct.rs index 8d627cf..a6d32e7 100644 --- a/core/src/tests/generics/external_product/ggsw_ct.rs +++ b/core/src/tests/generics/external_product/ggsw_ct.rs @@ -1,7 +1,11 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxRotateInplace, VecZnxSubABInplace, - VmpPMatAlloc, VmpPMatPrepare, ZnxViewMut, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAlloc, VecZnxDftAllocBytes, + VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotateInplace, VecZnxSub, VecZnxSubABInplace, VmpApply, + VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, ZnxViewMut, }, layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, ScratchOwned}, oep::{ @@ -17,12 +21,6 @@ use crate::{ prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::noise_ggsw_product, - trait_families::GGSWAssertNoiseFamily, -}; - -use crate::trait_families::{ - GGLWESwitchingKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWEncryptSkFamily, GGSWKeySwitchFamily, - GLWESecretPreparedModuleFamily, }; pub fn test_ggsw_external_product( @@ -35,22 +33,39 @@ pub fn test_ggsw_external_product( rank: usize, sigma: f64, ) where - Module: GLWESecretPreparedModuleFamily - + GGSWEncryptSkFamily - + GGSWAssertNoiseFamily - + VecZnxAddScalarInplace + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxAddScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare - + GGSWAssertNoiseFamily - + GGSWKeySwitchFamily - + GGLWESwitchingKeyEncryptSkFamily - + GGLWETensorKeyEncryptSkFamily - + VecZnxRotateInplace, + + VecZnxRotateInplace + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VmpPrepare + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl @@ -151,22 +166,39 @@ pub fn test_ggsw_external_product_inplace( rank: usize, sigma: f64, ) where - Module: GLWESecretPreparedModuleFamily - + GGSWEncryptSkFamily - + GGSWAssertNoiseFamily - + VecZnxAddScalarInplace + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxAddScalarInplace + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare - + GGSWAssertNoiseFamily - + GGSWKeySwitchFamily - + GGLWESwitchingKeyEncryptSkFamily - + GGLWETensorKeyEncryptSkFamily - + VecZnxRotateInplace, + + VecZnxRotateInplace + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VmpPrepare + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpA, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl - + TakeSvpPPolImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + ScratchAvailableImpl diff --git a/core/src/tests/generics/external_product/glwe_ct.rs b/core/src/tests/generics/external_product/glwe_ct.rs index 644495d..69d0345 100644 --- a/core/src/tests/generics/external_product/glwe_ct.rs +++ b/core/src/tests/generics/external_product/glwe_ct.rs @@ -1,7 +1,10 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxFillUniform, VecZnxRotateInplace, VmpPMatAlloc, - VmpPMatPrepare, ZnxViewMut, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotateInplace, VecZnxSub, VecZnxSubABInplace, + VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, ZnxViewMut, }, layouts::{Backend, Module, ScalarZnx, ScratchOwned}, oep::{ @@ -19,8 +22,6 @@ use crate::{ noise::noise_ggsw_product, }; -use crate::trait_families::{GLWEDecryptFamily, GLWEEncryptSkFamily, GLWEExternalProductFamily, GLWESecretPreparedModuleFamily}; - pub fn test_glwe_external_product( module: &Module, basek: usize, @@ -31,14 +32,32 @@ pub fn test_glwe_external_product( rank: usize, sigma: f64, ) where - Module: GLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + GLWEExternalProductFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace + VecZnxRotateInplace + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -148,14 +167,32 @@ pub fn test_glwe_external_product_inplace( rank: usize, sigma: f64, ) where - Module: GLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + GLWEExternalProductFamily + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace + VecZnxRotateInplace + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl diff --git a/core/src/tests/generics/keyswitch/gglwe_ct.rs b/core/src/tests/generics/keyswitch/gglwe_ct.rs index fcfc01b..c0aef14 100644 --- a/core/src/tests/generics/keyswitch/gglwe_ct.rs +++ b/core/src/tests/generics/keyswitch/gglwe_ct.rs @@ -1,12 +1,15 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubScalarInplace, VecZnxSwithcDegree, - VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScratchOwned}, oep::{ ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl, - TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl, + TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, }, }; use sampling::source::Source; @@ -17,11 +20,8 @@ use crate::{ prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, - trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_gglwe_switching_key_keyswitch( module: &Module, basek: usize, @@ -34,18 +34,34 @@ pub fn test_gglwe_switching_key_keyswitch( rank_out_s1s2: usize, sigma: f64, ) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace - + VecZnxSubScalarInplace - + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare - + GGLWEEncryptSkFamily - + GLWEDecryptFamily - + GLWEKeyswitchFamily, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxSubScalarInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -53,10 +69,7 @@ pub fn test_gglwe_switching_key_keyswitch( + ScratchOwnedBorrowImpl + ScratchAvailableImpl + TakeScalarZnxImpl - + TakeVecZnxImpl - + VecZnxDftAllocBytesImpl - + VecZnxBigAllocBytesImpl - + TakeSvpPPolImpl, + + TakeVecZnxImpl, { let n: usize = module.n(); let rows: usize = k_in.div_ceil(basek * digits); @@ -171,18 +184,34 @@ pub fn test_gglwe_switching_key_keyswitch_inplace( rank_out: usize, sigma: f64, ) where - Module: GGLWEEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace - + VecZnxSubScalarInplace - + VecZnxCopy + VmpPMatAlloc - + VmpPMatPrepare - + GGLWESwitchingKeyEncryptSkFamily - + GLWEKeyswitchFamily - + GLWEDecryptFamily, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxSubScalarInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -190,10 +219,7 @@ pub fn test_gglwe_switching_key_keyswitch_inplace( + ScratchOwnedBorrowImpl + ScratchAvailableImpl + TakeScalarZnxImpl - + TakeVecZnxImpl - + VecZnxDftAllocBytesImpl - + VecZnxBigAllocBytesImpl - + TakeSvpPPolImpl, + + TakeVecZnxImpl, { let n: usize = module.n(); let rows: usize = k_ct.div_ceil(basek * digits); diff --git a/core/src/tests/generics/keyswitch/ggsw_ct.rs b/core/src/tests/generics/keyswitch/ggsw_ct.rs index ea5bf2a..8261463 100644 --- a/core/src/tests/generics/keyswitch/ggsw_ct.rs +++ b/core/src/tests/generics/keyswitch/ggsw_ct.rs @@ -1,12 +1,16 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubABInplace, VecZnxSwithcDegree, - VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAddInplace, VecZnxDftAlloc, + VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, + VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScalarZnx, ScratchOwned}, oep::{ ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl, - TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl, + TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, }, }; use sampling::source::Source; @@ -17,12 +21,6 @@ use crate::{ prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::noise_ggsw_keyswitch, - trait_families::GGSWAssertNoiseFamily, -}; - -use crate::trait_families::{ - GGLWESwitchingKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWEncryptSkFamily, GGSWKeySwitchFamily, - GLWESecretPreparedModuleFamily, }; pub fn test_ggsw_keyswitch( @@ -36,19 +34,39 @@ pub fn test_ggsw_keyswitch( rank: usize, sigma: f64, ) where - Module: GLWESecretPreparedModuleFamily - + GGSWEncryptSkFamily - + GGSWAssertNoiseFamily - + VecZnxAddScalarInplace + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + VecZnxSubABInplace - + VecZnxCopy + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + + VecZnxAddScalarInplace + VmpPMatAlloc - + VmpPMatPrepare - + GGSWAssertNoiseFamily - + GGSWKeySwitchFamily - + GGLWESwitchingKeyEncryptSkFamily - + GGLWETensorKeyEncryptSkFamily - + VecZnxSwithcDegree, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + SvpApply + + VecZnxDftToVecZnxBigTmpA + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxBigAlloc + + VecZnxDftAlloc, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -56,13 +74,7 @@ pub fn test_ggsw_keyswitch( + ScratchOwnedBorrowImpl + ScratchAvailableImpl + TakeScalarZnxImpl - + TakeVecZnxImpl - + VecZnxDftAllocBytesImpl - + VecZnxBigAllocBytesImpl - + TakeSvpPPolImpl - + VecZnxDftAllocBytesImpl - + VecZnxBigAllocBytesImpl - + TakeSvpPPolImpl, + + TakeVecZnxImpl, { let n: usize = module.n(); let rows: usize = k_in.div_ceil(digits * basek); @@ -168,19 +180,39 @@ pub fn test_ggsw_keyswitch_inplace( rank: usize, sigma: f64, ) where - Module: GLWESecretPreparedModuleFamily - + GGSWEncryptSkFamily - + GGSWAssertNoiseFamily - + VecZnxAddScalarInplace + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + VecZnxSubABInplace - + VecZnxCopy + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + + VecZnxAddScalarInplace + VmpPMatAlloc - + VmpPMatPrepare - + GGSWAssertNoiseFamily - + GGSWKeySwitchFamily - + GGLWESwitchingKeyEncryptSkFamily - + GGLWETensorKeyEncryptSkFamily - + VecZnxSwithcDegree, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + SvpApply + + VecZnxDftToVecZnxBigTmpA + + VecZnxDftCopy + + VecZnxDftAddInplace + + VecZnxBigAlloc + + VecZnxDftAlloc, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -188,10 +220,7 @@ pub fn test_ggsw_keyswitch_inplace( + ScratchOwnedBorrowImpl + ScratchAvailableImpl + TakeScalarZnxImpl - + TakeVecZnxImpl - + VecZnxDftAllocBytesImpl - + VecZnxBigAllocBytesImpl - + TakeSvpPPolImpl, + + TakeVecZnxImpl, { let n: usize = module.n(); let rows: usize = k_ct.div_ceil(digits * basek); diff --git a/core/src/tests/generics/keyswitch/glwe_ct.rs b/core/src/tests/generics/keyswitch/glwe_ct.rs index 1d74416..f8ebe6f 100644 --- a/core/src/tests/generics/keyswitch/glwe_ct.rs +++ b/core/src/tests/generics/keyswitch/glwe_ct.rs @@ -1,7 +1,10 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxFillUniform, VecZnxSwithcDegree, VmpPMatAlloc, - VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -17,11 +20,8 @@ use crate::{ prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::log2_std_noise_gglwe_product, - trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily}, }; -use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - pub fn test_glwe_keyswitch( module: &Module, basek: usize, @@ -33,14 +33,33 @@ pub fn test_glwe_keyswitch( rank_out: usize, sigma: f64, ) where - Module: GGLWESwitchingKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEKeyswitchFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl @@ -137,14 +156,33 @@ pub fn test_glwe_keyswitch_inplace( rank: usize, sigma: f64, ) where - Module: GGLWESwitchingKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEKeyswitchFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl diff --git a/core/src/tests/generics/keyswitch/lwe_ct.rs b/core/src/tests/generics/keyswitch/lwe_ct.rs index e565fa9..416e7ca 100644 --- a/core/src/tests/generics/keyswitch/lwe_ct.rs +++ b/core/src/tests/generics/keyswitch/lwe_ct.rs @@ -1,7 +1,11 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxSwithcDegree, - VmpPMatAlloc, VmpPMatPrepare, ZnxView, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, + VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, + ZnxView, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -16,27 +20,44 @@ use crate::layouts::{ prepared::{LWESwitchingKeyPrepared, PrepareAlloc}, }; -use crate::trait_families::{GGLWEEncryptSkFamily, GLWEDecryptFamily, GLWEKeyswitchFamily, GLWESecretPreparedModuleFamily}; - pub fn test_lwe_keyswitch(module: &Module) where - Module: GGLWEEncryptSkFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree + Module: VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + VecZnxAddScalarInplace - + GLWEKeyswitchFamily - + VecZnxAutomorphismInplace + VmpPMatAlloc - + VmpPMatPrepare - + GLWESecretPreparedModuleFamily, - B: TakeScalarZnxImpl - + TakeVecZnxDftImpl - + ScratchAvailableImpl - + TakeVecZnxImpl + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxAutomorphismInplace, + B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + TakeSvpPPolImpl + ScratchOwnedAllocImpl - + ScratchOwnedBorrowImpl, + + ScratchOwnedBorrowImpl + + ScratchAvailableImpl + + TakeScalarZnxImpl + + TakeVecZnxImpl, { let n: usize = module.n(); let basek: usize = 17; diff --git a/core/src/tests/generics/packing.rs b/core/src/tests/generics/packing.rs index 7fd45b1..db57cb9 100644 --- a/core/src/tests/generics/packing.rs +++ b/core/src/tests/generics/packing.rs @@ -2,8 +2,13 @@ use std::collections::HashMap; use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigSubSmallBInplace, - VecZnxRotateInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxBigAddInplace, + VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigAutomorphismInplace, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, + VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNegateInplace, VecZnxNormalize, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, + VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -19,37 +24,54 @@ use crate::{ GGLWEAutomorphismKey, GLWECiphertext, GLWEPlaintext, GLWESecret, prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, - trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily, GLWEPackingFamily}, }; -use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - -pub trait PackingTestModuleFamily = GLWEPackingFamily - + GLWESecretPreparedModuleFamily - + GGLWESwitchingKeyEncryptSkFamily - + GLWEKeyswitchFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree - + VecZnxAddScalarInplace - + VecZnxRotateInplace - + VecZnxAutomorphism - + VecZnxBigSubSmallBInplace - + VmpPMatAlloc - + VmpPMatPrepare; - -pub trait PackingTestScratchFamily = TakeVecZnxDftImpl - + TakeVecZnxBigImpl - + TakeSvpPPolImpl - + ScratchOwnedAllocImpl - + ScratchOwnedBorrowImpl - + ScratchAvailableImpl - + TakeScalarZnxImpl - + TakeVecZnxImpl; - pub fn test_glwe_packing(module: &Module) where - Module: PackingTestModuleFamily, - B: PackingTestScratchFamily, + Module: VecZnxDftAllocBytes + + VecZnxAutomorphism + + VecZnxBigAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxNegateInplace + + VecZnxRshInplace + + VecZnxRotateInplace + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + VecZnxRotate + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + + VecZnxAddScalarInplace + + VmpPMatAlloc + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxAutomorphismInplace + + VecZnxCopy, + B: TakeVecZnxDftImpl + + TakeVecZnxBigImpl + + TakeSvpPPolImpl + + ScratchOwnedAllocImpl + + ScratchOwnedBorrowImpl + + ScratchAvailableImpl + + TakeScalarZnxImpl + + TakeVecZnxImpl, { let mut source_xs: Source = Source::new([0u8; 32]); let mut source_xe: Source = Source::new([0u8; 32]); diff --git a/core/src/tests/generics/trace.rs b/core/src/tests/generics/trace.rs index 2e08206..30803e4 100644 --- a/core/src/tests/generics/trace.rs +++ b/core/src/tests/generics/trace.rs @@ -2,9 +2,13 @@ use std::collections::HashMap; use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigAutomorphismInplace, - VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxFillUniform, VecZnxNormalizeInplace, VecZnxRotateInplace, VecZnxRshInplace, - VecZnxSubABInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, ZnxView, ZnxViewMut, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, + VecZnxBigAllocBytes, VecZnxBigAutomorphismInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, + VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotateInplace, + VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, + VmpPMatAlloc, VmpPrepare, ZnxView, ZnxViewMut, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -20,39 +24,51 @@ use crate::{ prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc}, }, noise::var_noise_gglwe_product, - trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily}, }; -use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily}; - -pub trait TraceTestModuleFamily = GGLWESwitchingKeyEncryptSkFamily - + GLWESecretPreparedModuleFamily - + GLWEKeyswitchFamily - + GLWEDecryptFamily - + VecZnxSwithcDegree - + VecZnxAddScalarInplace - + VecZnxRotateInplace - + VecZnxBigSubSmallBInplace - + VecZnxBigAutomorphismInplace - + VecZnxCopy - + VecZnxAutomorphism - + VecZnxRshInplace - + VmpPMatAlloc - + VmpPMatPrepare; - -pub trait TraceTestScratchFamily = TakeVecZnxDftImpl - + TakeVecZnxBigImpl - + TakeSvpPPolImpl - + ScratchOwnedAllocImpl - + ScratchOwnedBorrowImpl - + ScratchAvailableImpl - + TakeScalarZnxImpl - + TakeVecZnxImpl; - pub fn test_glwe_trace_inplace(module: &Module, basek: usize, k: usize, sigma: f64, rank: usize) where - Module: TraceTestModuleFamily, - B: TraceTestScratchFamily, + Module: VecZnxDftAllocBytes + + VecZnxAutomorphism + + VecZnxBigAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxRshInplace + + VecZnxRotateInplace + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxBigAllocBytes + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxNormalizeTmpBytes + + VecZnxAddScalarInplace + + VmpPMatAlloc + + VmpPrepare + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxBigNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxCopy, + B: TakeVecZnxDftImpl + + TakeVecZnxBigImpl + + TakeSvpPPolImpl + + ScratchOwnedAllocImpl + + ScratchOwnedBorrowImpl + + ScratchAvailableImpl + + TakeScalarZnxImpl + + TakeVecZnxImpl, { let n: usize = module.n(); let k_autokey: usize = k + basek; diff --git a/core/src/trait_families.rs b/core/src/trait_families.rs deleted file mode 100644 index 8efb654..0000000 --- a/core/src/trait_families.rs +++ /dev/null @@ -1,104 +0,0 @@ -use backend::hal::{ - api::{ - ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, TakeVecZnxDft, - VecZnxAddInplace, VecZnxAddNormal, VecZnxAutomorphismInplace, VecZnxBigAddInplace, VecZnxBigAddNormal, - VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAllocBytes, VecZnxBigAutomorphismInplace, VecZnxBigNormalize, - VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxDftAddInplace, VecZnxDftAlloc, - VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, - VecZnxFillUniform, VecZnxNegateInplace, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, - VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, - VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare, - }, - layouts::{Backend, Module}, -}; - -pub trait GGSWKeySwitchFamily = - GLWEKeyswitchFamily + VecZnxBigAllocBytes + VecZnxDftCopy + VecZnxDftAddInplace + VecZnxDftToVecZnxBigTmpA; -pub trait GGLWEEncryptSkFamily = GLWEEncryptSkFamily; -pub trait GGLWESwitchingKeyEncryptSkFamily = GGLWEEncryptSkFamily; -pub trait GGLWEAutomorphismKeyEncryptSkFamily = GGLWEEncryptSkFamily; -pub trait GGLWETensorKeyEncryptSkFamily = - GGLWEEncryptSkFamily + VecZnxBigAllocBytes + VecZnxDftToVecZnxBigTmpA + SvpApply; -pub trait GGSWEncryptSkFamily = GLWEEncryptSkFamily; -pub trait GGSWAssertNoiseFamily = GLWEDecryptFamily - + VecZnxBigAlloc - + VecZnxDftAlloc - + VecZnxBigNormalizeTmpBytes - + VecZnxBigNormalize - + VecZnxDftToVecZnxBigTmpA; -pub trait GLWEDecryptFamily = VecZnxDftAllocBytes - + VecZnxBigAllocBytes - + VecZnxDftFromVecZnx - + SvpApplyInplace - + VecZnxDftToVecZnxBigConsume - + VecZnxBigAddInplace - + VecZnxBigAddSmallInplace - + VecZnxBigNormalize - + VecZnxNormalizeTmpBytes; -pub trait GLWEEncryptSkFamily = VecZnxDftAllocBytes - + VecZnxBigNormalize - + VecZnxDftFromVecZnx - + SvpApplyInplace - + VecZnxDftToVecZnxBigConsume - + VecZnxNormalizeTmpBytes - + VecZnxFillUniform - + VecZnxSubABInplace - + VecZnxAddInplace - + VecZnxNormalizeInplace - + VecZnxAddNormal - + VecZnxNormalize - + VecZnxSub; -pub trait GLWEEncryptPkFamily = VecZnxDftAllocBytes - + VecZnxBigAllocBytes - + SvpPPolAllocBytes - + SvpPrepare - + SvpApply - + VecZnxDftToVecZnxBigConsume - + VecZnxBigAddNormal - + VecZnxBigAddSmallInplace - + VecZnxBigNormalize - + VecZnxNormalizeTmpBytes; -pub trait GLWEExternalProductFamily = VecZnxDftAllocBytes - + VmpApplyTmpBytes - + VmpApply - + VmpApplyAdd - + VecZnxDftFromVecZnx - + VecZnxDftToVecZnxBigConsume - + VecZnxBigNormalize - + VecZnxNormalizeTmpBytes; -pub trait GLWEKeyswitchFamily = VecZnxDftAllocBytes - + VmpApplyTmpBytes - + VecZnxBigNormalizeTmpBytes - + VmpApplyTmpBytes - + VmpApply - + VmpApplyAdd - + VecZnxDftFromVecZnx - + VecZnxDftToVecZnxBigConsume - + VecZnxBigAddSmallInplace - + VecZnxBigNormalize; -pub trait GLWEPackingFamily = GLWEKeyswitchFamily - + VecZnxCopy - + VecZnxRotateInplace - + VecZnxSub - + VecZnxNegateInplace - + VecZnxRshInplace - + VecZnxAddInplace - + VecZnxNormalizeInplace - + VecZnxSubABInplace - + VecZnxRotate - + VecZnxAutomorphismInplace - + VecZnxBigSubSmallBInplace - + VecZnxBigAutomorphismInplace; -pub trait GLWESecretPreparedModuleFamily = SvpPrepare + SvpPPolAllocBytes + SvpPPolAlloc; -pub trait GGLWEPreparedLayoutFamily = VmpPMatAlloc + VmpPMatAllocBytes + VmpPMatPrepare; -pub trait GLWETraceModuleFamily = - GLWEKeyswitchFamily + VecZnxCopy + VecZnxRshInplace + VecZnxBigAutomorphismInplace; -pub trait GLWETraceScratchFamily = TakeVecZnxDft + ScratchAvailable; -pub trait GGSWLayoutFamily = VmpPMatAlloc + VmpPMatAllocBytes + VmpPMatPrepare; - -pub trait DecompressFamily = VecZnxFillUniform + VecZnxCopy; -pub trait Decompress { - fn decompress(&mut self, module: &Module, other: &C) - where - Module: DecompressFamily; -} diff --git a/poulpy/Cargo.toml b/poulpy/Cargo.toml new file mode 100644 index 0000000..8889a9a --- /dev/null +++ b/poulpy/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "poulpy" +version = "0.1.0" +edition = "2024" + +[dependencies] +backend = {path="../backend"} +core = {path="../core"} +schemes = {path="../schemes"} +sampling = {path="../sampling"} \ No newline at end of file diff --git a/poulpy/README.md b/poulpy/README.md new file mode 100644 index 0000000..402f551 --- /dev/null +++ b/poulpy/README.md @@ -0,0 +1,171 @@ +# 🐙 Poulpy + +

+ +

+ +[![CI](https://github.com/phantomzone-org/poulpy/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/phantomzone-org/poulpy/actions/workflows/ci.yml) + +**Poulpy** is a fast & modular FHE library that implements Ring-Learning-With-Errors based homomorphic encryption. It adopts the bivariate polynomial representation proposed in [Revisiting Key Decomposition Techniques for FHE: Simpler, Faster and More Generic](https://eprint.iacr.org/2023/771). In addition to simpler and more efficient arithmetic than the residue number system (RNS), this representation provides a common plaintext space for all schemes and allows easy switching between any two schemes. Poulpy also decouples the schemes implementations from the polynomial arithmetic backend by being built around a hardware abstraction layer (HAL). This enables user to easily provide or use a custom backend. + +### Bivariate Polynomial Representation + +Existing FHE implementations (such as [Lattigo](https://github.com/tuneinsight/lattigo) or [OpenFHE](https://github.com/openfheorg/openfhe-development)) use the [residue-number-system](https://en.wikipedia.org/wiki/Residue_number_system) (RNS) to represent large integers. Although the parallelism and carry-less arithmetic provided by the RNS representation provides a very efficient modular arithmetic over large-integers, it suffers from various drawbacks when used in the context of FHE. The main idea behind the bivariate representation is to decouple the cyclotomic arithmetic from the large number arithmetic. Instead of using the RNS representation for large integer, integers are decomposed in base $2^{-K}$ over the Torus $\mathbb{T}_{N}[X]$. + +This provides the following benefits: + +- **Intuitive, efficient and reusable parameterization & instances:** Only the bit-size of the modulus is required from the user (i.e. Torus precision). As such, parameterization is natural and generic, and instances can be reused for any circuit consuming the same homomorphic capacity, without loss of efficiency. With the RNS representation, individual NTT friendly primes needs to be specified for each level, making the parameterization not user friendly and circuit-specific. + +- **Optimal and granular rescaling:** Ciphertext rescaling is carried out with bit-shifting, enabling a bit-level granular rescaling and optimal noise/homomorphic capacity management. In the RNS representation, ciphertext division can only be done by one of the primes composing the modulus, leading to difficult scaling management and frequent inefficient noise/homomorphic capacity management. + +- **Linear number of DFT in the half external product:** The bivariate representation of the coefficients implicitly provides the digit decomposition, as such the number of DFT is linear in the number of limbs, contrary to the RNS representation where it is quadratic due to the RNS basis conversion. This enables a much more efficient key-switching, which is the **most used and expensive** FHE operation. + +- **Unified plaintext space:** The bivariate polynomial representation is by essence a high precision discretized representation of the Torus $\mathbb{T}_{N}[X]$. Using the Torus as the common plaintext space for all schemes achieves the vision of [CHIMERA: Combining Ring-LWE-based Fully Homomorphic Encryption Schemes](https://eprint.iacr.org/2018/758) which is to unify all RLWE-based FHE schemes (TFHE, FHEW, BGV, BFV, CLPX, GBFV, CKKS, ...) under a single scheme with different encodings, enabling native and efficient scheme-switching functionalities. + +- **Simpler implementation**: Since the cyclotomic arithmetic is decoupled from the coefficient representation, the same pipeline (including DFT) can be reused for all limbs (unlike in the RNS representation), making this representation a prime target for hardware acceleration. + +- **Deterministic computation**: Although being defined on the Torus, bivariate arithmetic remains integer polynomial arithmetic, ensuring all computations are deterministic, the contract being that output should be reproducible and identical, regardless of the backend or hardware. + +### Hardware Abstraction Layer + +In addition to providing a general purpose FHE library over a unified plaintext space, Poulpy is also designed from the ground up around a **hardware abstraction layer** that closely matches the API of [spqlios-arithmetic](https://github.com/tfhe/spqlios-arithmetic). The bivariate representation is by itself hardware friendly as it uses flat, aligned & vectorized memory layout. Finally, generic opaque write only structs (prepared versions) are provided, making it easy for developers to provide hardware focused/optimized operations. This makes possible for anyone to provide or use a custom backend. + +## Library Overview + +- **`backend/hal`**: hardware abstraction layer. This layer targets users that want to provide their own backend or use a third party backend. + + - **`api`**: fixed public low-level polynomial level arithmetic API closely matching spqlios-arithmetic. The goal is to eventually freeze this API, in order to decouple it from the OEP traits, ensuring that changes to implementations do not affect the front end API. + + ```rust + pub trait SvpPrepare { + fn svp_prepare(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) + where + R: SvpPPolToMut, + A: ScalarZnxToRef; + } + ```` + + - **`delegates`**: link between the user facing API and implementation OEP. Each trait of `api` is implemented by calling its corresponding trait on the `oep`. + + ```rust + impl SvpPrepare for Module + where + B: Backend + SvpPrepareImpl, + { + fn svp_prepare(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) + where + R: SvpPPolToMut, + A: ScalarZnxToRef, + { + B::svp_prepare_impl(self, res, res_col, a, a_col); + } + } + ``` + + - **`layouts`**: defines the layouts of the front-end algebraic structs matching spqlios-arithmetic definitions, such as `ScalarZnx`, `VecZnx` or opaque backend prepared struct such as `SvpPPol` and `VmpPMat`. + + ```rust + pub struct SvpPPol { + data: D, + n: usize, + cols: usize, + _phantom: PhantomData, + } + ``` + + - **`oep`**: open extension points, which can be implemented by the user to provide a custom backend. + + ```rust + pub unsafe trait SvpPrepareImpl { + fn svp_prepare_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) + where + R: SvpPPolToMut, + A: ScalarZnxToRef; + } + ``` + + - **`tests`**: exported generic tests for the OEP/structs. Their goal is to enable a user to automatically be able to test its backend implementation, without having to re-implement any tests. + +- **`backend/implementation`**: + - **`cpu_spqlios`**: concrete cpu implementation of the hal through the oep using bindings on spqlios-arithmetic. This implementation currently supports the `FFT64` backend and will be extended to support the `NTT120` backend once it is available in spqlios-arithmetic. + + ```rust + unsafe impl SvpPrepareImpl for FFT64 { + fn svp_prepare_impl(module: &Module, res: &mut R, res_col: usize, a: &A, a_col: usize) + where + R: SvpPPolToMut, + A: ScalarZnxToRef, + { + unsafe { + svp::svp_prepare( + module.ptr(), + res.to_mut().at_mut_ptr(res_col, 0) as *mut svp::svp_ppol_t, + a.to_ref().at_ptr(a_col, 0), + ) + } + } + } + ``` + +- **`core`**: core of the FHE library, implementing scheme agnostic RLWE arithmetic for LWE, GLWE, GGLWE and GGSW ciphertexts. It notably includes all possible cross-ciphertext operations, for example applying an external product on a GGLWE or an automorphism on a GGSW, as well as blind rotation. This crate is entirely implemented using the hardware abstraction layer API, and is thus solely defined over generic and traits (including tests). As such it will work over any backend, as long as it implements the necessary traits defined in the OEP. + + ```rust + pub struct GLWESecret { + pub(crate) data: ScalarZnx, + pub(crate) dist: Distribution, + } + + pub struct GLWESecrecPrepared { + pub(crate) data: SvpPPol, + pub(crate) dist: Distribution, + } + + impl GLWESecretPrepared { + pub fn prepare(&mut self, module: &Module, sk: &GLWESecret) + where + O: DataRef, + Module: SvpPrepare, + { + (0..self.rank()).for_each(|i| { + module.svp_prepare(&mut self.data, i, &sk.data, i); + }); + self.dist = sk.dist + } + } + ``` + +## Installation + +TBD — currently not published on crates.io. Clone the repository and use via path-based dependencies. + +## Documentation + +* Full `cargo doc` documentation is coming soon. +* Architecture diagrams and design notes will be added in the [`/doc`](./doc) folder. + +## Contributing + +We welcome external contributions, please see [CONTRIBUTING](./CONTRIBUTING.md). + +## Security + +Please see [SECURITY](./SECURITY.md). + +## License + +Poulpy is licensed under the Apache 2.0 License. See [NOTICE](./NOTICE) & [LICENSE](./LICENSE). + +## Acknowledgement + +**Poulpy** is inspired by the modular architecture of [Lattigo](https://github.com/tuneinsight/lattigo) and [TFHE-go](https://github.com/sp301415/tfhe-go), and its development is lead by Lattigo’s co-author and main contributor [@Pro7ech](https://github.com/Pro7ech). Poulpy reflects the experience gained from over five years of designing and maintaining Lattigo, and represents the next evolution in architecture, performance, and backend philosophy. + +## Citing +Please use the following BibTex entry for citing Lattigo + + @misc{poulpy, + title = {Poulpy v0.1.0}, + howpublished = {Online: \url{https://github.com/phantomzone-org/poulpy}}, + month = Aug, + year = 2025, + note = {Phantom Zone} + } diff --git a/poulpy/examples/circuit_bootstrapping.rs b/poulpy/examples/circuit_bootstrapping.rs new file mode 100644 index 0000000..4ec2c9d --- /dev/null +++ b/poulpy/examples/circuit_bootstrapping.rs @@ -0,0 +1,218 @@ +use core::{ + GLWEOperations, + layouts::{ + GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, Infos, LWECiphertext, LWEPlaintext, LWESecret, + prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc}, + }, +}; +use std::time::Instant; + +use backend::{ + hal::{ + api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxNormalizeInplace, ZnxView, ZnxViewMut}, + layouts::{Module, ScalarZnx, ScratchOwned}, + }, + implementation::cpu_spqlios::FFT64, +}; + +use sampling::source::Source; +use schemes::tfhe::{ + blind_rotation::CGGI, + circuit_bootstrapping::{ + CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute, + }, +}; + +fn main() { + // GLWE ring degree + let n_glwe: usize = 1024; + + // Module provides access to the backend arithmetic + let module: Module = Module::::new(n_glwe as u64); + + // Base 2 loga + let basek: usize = 13; + + // Lookup table extension factor + let extension_factor: usize = 1; + + // GLWE rank + let rank: usize = 1; + + // Noise (discrete) standard deviation + let sigma: f64 = 3.2; + + // LWE degree + let n_lwe: usize = 574; + + // LWE plaintext modulus + let k_lwe_pt: usize = 1; + + // LWE ciphertext modulus + let k_lwe_ct: usize = 13; + + // LWE block binary key block size + let block_size: usize = 7; + + // GGSW output number of rows + let rows_ggsw_res: usize = 2; + + // GGSW output modulus + let k_ggsw_res: usize = (rows_ggsw_res + 1) * basek; + + // Blind rotation key GGSW number of rows + let rows_brk: usize = rows_ggsw_res + 1; + + // Blind rotation key GGSW modulus + let k_brk: usize = (rows_brk + 1) * basek; + + // GGLWE automorphism keys number of rows + let rows_trace: usize = rows_ggsw_res + 1; + + // GGLWE automorphism keys modulus + let k_trace: usize = (rows_trace + 1) * basek; + + // GGLWE tensor key number of rows + let rows_tsk: usize = rows_ggsw_res + 1; + + // GGLWE tensor key modulus + let k_tsk: usize = (rows_tsk + 1) * basek; + + // Scratch space (4MB) + let mut scratch: ScratchOwned = ScratchOwned::alloc(1 << 22); + + // Secret key sampling source + let mut source_xs: Source = Source::new([1u8; 32]); + + // Public randomness sampling source + let mut source_xa: Source = Source::new([1u8; 32]); + + // Noise sampling source + let mut source_xe: Source = Source::new([1u8; 32]); + + // LWE secret + let mut sk_lwe: LWESecret> = LWESecret::alloc(n_lwe); + sk_lwe.fill_binary_block(block_size, &mut source_xs); + sk_lwe.fill_zero(); + + // GLWE secret + let mut sk_glwe: GLWESecret> = GLWESecret::alloc(n_glwe, rank); + sk_glwe.fill_ternary_prob(0.5, &mut source_xs); + // sk_glwe.fill_zero(); + + // GLWE secret prepared (opaque backend dependant write only struct) + let sk_glwe_prepared: GLWESecretPrepared, FFT64> = sk_glwe.prepare_alloc(&module, scratch.borrow()); + + // Plaintext value to circuit bootstrap + let data: i64 = 1 % (1 << k_lwe_pt); + + // LWE plaintext + let mut pt_lwe: LWEPlaintext> = LWEPlaintext::alloc(basek, k_lwe_pt); + + // LWE plaintext(data * 2^{- (k_lwe_pt - 1)}) + pt_lwe.encode_i64(data, k_lwe_pt + 1); // +1 for padding bit + module.vec_znx_normalize_inplace(basek, pt_lwe.data_mut(), 0, scratch.borrow()); + + println!("pt_lwe: {}", pt_lwe); + + // LWE ciphertext + let mut ct_lwe: LWECiphertext> = LWECiphertext::alloc(n_lwe, basek, k_lwe_ct); + + // Encrypt LWE Plaintext + ct_lwe.encrypt_sk( + &module, + &pt_lwe, + &sk_lwe, + &mut source_xa, + &mut source_xe, + sigma, + ); + + let now: Instant = Instant::now(); + + // Circuit bootstrapping evaluation key + let cbt_key: CircuitBootstrappingKey, CGGI> = CircuitBootstrappingKey::encrypt_sk( + &module, + basek, + &sk_lwe, + &sk_glwe, + k_brk, + rows_brk, + k_trace, + rows_trace, + k_tsk, + rows_tsk, + &mut source_xa, + &mut source_xe, + sigma, + scratch.borrow(), + ); + println!("CBT-KGEN: {} ms", now.elapsed().as_millis()); + + // Output GGSW + let mut res: GGSWCiphertext> = GGSWCiphertext::alloc(n_glwe, basek, k_ggsw_res, rows_ggsw_res, 1, rank); + + // Circuit bootstrapping key prepared (opaque backend dependant write only struct) + let cbt_prepared: CircuitBootstrappingKeyPrepared, CGGI, FFT64> = cbt_key.prepare_alloc(&module, scratch.borrow()); + + // Apply circuit bootstrapping: LWE(data * 2^{- (k_lwe_pt + 2)}) -> GGSW(data) + let now: Instant = Instant::now(); + cbt_prepared.execute_to_constant( + &module, + &mut res, + &ct_lwe, + k_lwe_pt, + extension_factor, + scratch.borrow(), + ); + println!("CBT: {} ms", now.elapsed().as_millis()); + + // Allocate "ideal" GGSW(data) plaintext + let mut pt_ggsw: ScalarZnx> = ScalarZnx::alloc(n_glwe, 1); + pt_ggsw.at_mut(0, 0)[0] = data; + + // Prints noise of GGSW(data) + res.print_noise(&module, &sk_glwe_prepared, &pt_ggsw); + + // Tests RLWE(1) * GGSW(data) + + // GLWE ciphertext modulus + let mut ct_glwe: GLWECiphertext> = GLWECiphertext::alloc(n_glwe, basek, k_ggsw_res - basek, rank); + + // Some GLWE plaintext with signed data + let k_glwe_pt: usize = 3; + let mut pt_glwe: GLWEPlaintext> = GLWEPlaintext::alloc(n_glwe, basek, basek); + let mut data_vec: Vec = vec![0i64; n_glwe]; + data_vec + .iter_mut() + .enumerate() + .for_each(|(x, y)| *y = (x % (1 << (k_glwe_pt - 1))) as i64 - (1 << (k_glwe_pt - 2))); + + pt_glwe.encode_vec_i64(&data_vec, k_lwe_pt + 2); + pt_glwe.normalize_inplace(&module, scratch.borrow()); + + println!("{}", pt_glwe); + + // Encrypt + ct_glwe.encrypt_sk( + &module, + &pt_glwe, + &sk_glwe_prepared, + &mut source_xa, + &mut source_xe, + sigma, + scratch.borrow(), + ); + + // Prepare GGSW output of circuit bootstrapping (opaque backend dependant write only struct) + let res_prepared: GGSWCiphertextPrepared, FFT64> = res.prepare_alloc(&module, scratch.borrow()); + + // Apply GLWE x GGSW + ct_glwe.external_product_inplace(&module, &res_prepared, scratch.borrow()); + + // Decrypt + let mut pt_res: GLWEPlaintext> = GLWEPlaintext::alloc(n_glwe, basek, ct_glwe.k()); + ct_glwe.decrypt(&module, &mut pt_res, &sk_glwe_prepared, scratch.borrow()); + + println!("pt_res: {:?}", &pt_res.data.at(0, 0)[..64]); +} diff --git a/poulpy/poulpy.png b/poulpy/poulpy.png new file mode 100644 index 0000000000000000000000000000000000000000..23b4935e05db80a09cf7207b20b271933659b718 GIT binary patch literal 23087 zcmY&1!)8+Y}5=lSlvKlZa1_MU65 zF$drA&Im<$NhElDcn}DL^i@hs8TkGHfxtkp(7=&TM_vQ)1?H?QDFUjQCj1MWK$;87 z34=iOaR{%5P{28ygOsK-2m~Sc?*rz-!}tlfi02}%;quMi%*EZ%$rR-7?#^UsXYFik z=wQlZ?_{2J&W{g_8fK}Y;i4fY%WG_J%VcO`Z)D2kVe0_=8wBDP^l&gVwl;MkH8M4~ zwEIGR(a}RqYH9L?TAfplMb1Ig)WTBA%gOYcm%NIxm$fmE3ALaA5d)m1edNA5KQ~Y-TF;iz_CrbwxOM5%ge*+pC*}J-YA$N7PG~qQf zG~+ZfG2vu1GGsSlWMwrmWHdBkXJs^DXE)*EWaVZvV>KfG@8ex8&HnH6?VSHB20$Rp z|L!oeGO_%d^1owV1t&{WU>5%#DZtAApZovcHGbxQ6ZwB8Ch$L3fOiFs{#P>p#Pq+? zHMIjo>JG?`AvqlZ1kynKDkiMrp?8+!?(xl(VE7_wu1gzUw+U)Ik!+NhO)M4BbSAY0 zmN7EVKd&qtHZm}m+XBtPl9oXDbGQv8rpd*k973_T*^i4j4$JFTLZqU#@XvyM{-;31IhS zH(qTzYH=byP~;F15*CWp{={Jieyac$!)~0$q)SH~#$yFD{b-$0o__+ZnAgK`ftO=z zfrn(14C@iqZYz4$hv$ccfsenaCvS))ghV=W%v#KG#JponuATrvSQ5nkj&Go~vdV(L zpa3#eh;?LXP#3x?wg2;Ihs@L4N1T0?6&_!A^qV7wgchFPDS7~8@yvjtW^80U&^Stl zyt@^hD_#;>Lo{6I!3VaIXiPXPI=`Z)wf8yXhP)2K{8a)SyQNP_LMAq#;AfICAysfm z>Bx|T-6vDzx9#YjOj!hduGEshIYrY-1GA5{ZFO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E2)rCB3knXF zzZsw|AUVl!GyxNnb;LZc>X>(Cgkrx!^{XOZ}1#}jWB#Qg{^+BjK8GjUP zZKa9_HMd~x!)EV_k(>c$!n^Q5dHB?h0Nq049fH2B+?O5C5R6`{6Ey9ohP)MY~t0LE;Wo!B#ii!wZv@#j7syPn-L#( z0(7p(v|L|Q@pMn+V_>#9;2IW6nR)vxYuL2M_GmL~=9j2IA%bg9%wk`IN3WM==F}=I z8PHVBKt(Jz-?LknWHxvnfM?PgN8HBdK{ch6qVZqbZN_DP6)I;4DbSWD{)i`X^JC~taPpXN zr}(v0vvZG=TxZvGvy$x_*tA2V#Hb(?P0vKr6bf54{YQxn2k@pxd$4aQL0{;AkGg|e z;fn1v+^=o3UWxjVeCu{BhWuF@8GLe$J-;@J^whyNcV4&IGnytL4^|iguxOdZc|JUX zj~_qRAnB|APE08g`=uJeUVYtGq1|3*37n*BSr6)Q@Fetd5KmA<$f>(7?B;67lX%-A ze>lWsdS$^jihae`8u$xUFDHSB`XeNSVw8j{!u4@wi4tmbng~|F35%SExRB z!9oOyo|$UN^Ru&O<$q`wiD`*JH;_3kL;$t*Ju(LxKnkX{2XS5uj`iLIrO7>ov(nRM zz8ar!Ln?kjNyLBImQPDwj*j$}O~CuYk_WDdl; = VecZnxBigAllocBytes - + VecZnxDftAllocBytes - + SvpPPolAllocBytes - + VmpApplyTmpBytes - + VecZnxBigNormalizeTmpBytes - + VecZnxDftToVecZnxBigTmpBytes - + VecZnxDftToVecZnxBig - + VecZnxDftAdd - + VecZnxDftAddInplace - + VecZnxDftFromVecZnx - + VecZnxDftZero - + SvpApply - + VecZnxDftSubABInplace - + VecZnxBigAddSmallInplace - + GLWEExternalProductFamily - + VecZnxRotate - + VecZnxAddInplace - + VecZnxSubABInplace - + VecZnxNormalize - + VecZnxNormalizeInplace - + VecZnxCopy - + VecZnxMulXpMinusOneInplace; - pub fn cggi_blind_rotate_scratch_space( module: &Module, n: usize, @@ -55,7 +32,12 @@ pub fn cggi_blind_rotate_scratch_space( rank: usize, ) -> usize where - Module: CCGIBlindRotationFamily, + Module: VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxNormalizeTmpBytes + + VecZnxBigAllocBytes + + VecZnxDftToVecZnxBigTmpBytes + + VecZnxBigNormalizeTmpBytes, { let brk_size: usize = k_brk.div_ceil(basek); @@ -89,7 +71,32 @@ where impl BlincRotationExecute for BlindRotationKeyPrepared where - Module: CCGIBlindRotationFamily, + Module: VecZnxBigAllocBytes + + VecZnxDftAllocBytes + + SvpPPolAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpBytes + + VecZnxDftToVecZnxBig + + VecZnxDftAdd + + VecZnxDftAddInplace + + VecZnxDftFromVecZnx + + VecZnxDftZero + + SvpApply + + VecZnxDftSubABInplace + + VecZnxBigAddSmallInplace + + VecZnxRotate + + VecZnxAddInplace + + VecZnxSubABInplace + + VecZnxNormalize + + VecZnxNormalizeInplace + + VecZnxCopy + + VecZnxMulXpMinusOneInplace + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes, Scratch: TakeVecZnxDftSlice + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnxSlice + TakeVecZnx + ScratchAvailable, { fn execute( @@ -126,7 +133,29 @@ fn execute_block_binary_extended( DataRes: DataMut, DataIn: DataRef, DataBrk: DataRef, - Module: CCGIBlindRotationFamily, + Module: VecZnxBigAllocBytes + + VecZnxDftAllocBytes + + SvpPPolAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpBytes + + VecZnxDftToVecZnxBig + + VecZnxDftAdd + + VecZnxDftAddInplace + + VecZnxDftFromVecZnx + + VecZnxDftZero + + SvpApply + + VecZnxDftSubABInplace + + VecZnxBigAddSmallInplace + + VecZnxRotate + + VecZnxAddInplace + + VecZnxSubABInplace + + VecZnxNormalize + + VecZnxNormalizeInplace + + VecZnxCopy + + VecZnxMulXpMinusOneInplace + + VecZnxBigNormalize + + VmpApply, Scratch: TakeVecZnxDftSlice + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx, { let n_glwe: usize = brk.n(); @@ -271,7 +300,29 @@ fn execute_block_binary( DataRes: DataMut, DataIn: DataRef, DataBrk: DataRef, - Module: CCGIBlindRotationFamily, + Module: VecZnxBigAllocBytes + + VecZnxDftAllocBytes + + SvpPPolAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpBytes + + VecZnxDftToVecZnxBig + + VecZnxDftAdd + + VecZnxDftAddInplace + + VecZnxDftFromVecZnx + + VecZnxDftZero + + SvpApply + + VecZnxDftSubABInplace + + VecZnxBigAddSmallInplace + + VecZnxRotate + + VecZnxAddInplace + + VecZnxSubABInplace + + VecZnxNormalize + + VecZnxNormalizeInplace + + VecZnxCopy + + VecZnxMulXpMinusOneInplace + + VmpApply + + VecZnxBigNormalize, Scratch: TakeVecZnxDftSlice + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx, { let n_glwe: usize = brk.n(); @@ -363,7 +414,32 @@ fn execute_standard( DataRes: DataMut, DataIn: DataRef, DataBrk: DataRef, - Module: CCGIBlindRotationFamily, + Module: VecZnxBigAllocBytes + + VecZnxDftAllocBytes + + SvpPPolAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpBytes + + VecZnxDftToVecZnxBig + + VecZnxDftAdd + + VecZnxDftAddInplace + + VecZnxDftFromVecZnx + + VecZnxDftZero + + SvpApply + + VecZnxDftSubABInplace + + VecZnxBigAddSmallInplace + + VecZnxRotate + + VecZnxAddInplace + + VecZnxSubABInplace + + VecZnxNormalize + + VecZnxNormalizeInplace + + VecZnxCopy + + VecZnxMulXpMinusOneInplace + + VmpApply + + VmpApplyAdd + + VecZnxDftToVecZnxBigConsume + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes, Scratch: TakeVecZnxDftSlice + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] @@ -454,7 +530,7 @@ pub(crate) fn mod_switch_2n(n: usize, res: &mut [i64], lwe: &LWECiphertext<&[u8] } if basek > log2n { - let diff: usize = basek - log2n; + let diff: usize = basek - (log2n - 1); // additional -1 because we map to [-N/2, N/2) instead of [0, N) res.iter_mut().for_each(|x| { *x = div_round_by_pow2(x, diff); }) diff --git a/schemes/src/tfhe/blind_rotation/cggi_key.rs b/schemes/src/tfhe/blind_rotation/cggi_key.rs index f63c070..77e8665 100644 --- a/schemes/src/tfhe/blind_rotation/cggi_key.rs +++ b/schemes/src/tfhe/blind_rotation/cggi_key.rs @@ -1,6 +1,9 @@ use backend::hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VmpPMatAlloc, VmpPMatPrepare, ZnxView, ZnxViewMut, + ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VmpPMatAlloc, + VmpPrepare, ZnxView, ZnxViewMut, }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch}, }; @@ -15,7 +18,6 @@ use core::{ compressed::GGSWCiphertextCompressed, prepared::{GGSWCiphertextPrepared, GLWESecretPrepared}, }, - trait_families::GGSWEncryptSkFamily, }; use crate::tfhe::blind_rotation::{ @@ -38,7 +40,7 @@ impl BlindRotationKeyAlloc for BlindRotationKey, CGGI> { impl BlindRotationKey, CGGI> { pub fn generate_from_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGSWEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k, rank) } @@ -46,7 +48,20 @@ impl BlindRotationKey, CGGI> { impl BlindRotationKeyEncryptSk for BlindRotationKey where - Module: GGSWEncryptSkFamily + VecZnxAddScalarInplace, + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { fn encrypt_sk( @@ -92,7 +107,7 @@ where impl BlindRotationKeyPreparedAlloc for BlindRotationKeyPrepared, CGGI, B> where - Module: VmpPMatAlloc + VmpPMatPrepare, + Module: VmpPMatAlloc + VmpPrepare, { fn alloc(module: &Module, n_glwe: usize, n_lwe: usize, basek: usize, k: usize, rows: usize, rank: usize) -> Self { let mut data: Vec, B>> = Vec::with_capacity(n_lwe); @@ -127,7 +142,7 @@ impl BlindRotationKeyCompressed, CGGI> { pub fn generate_from_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize, rank: usize) -> usize where - Module: GGSWEncryptSkFamily, + Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { GGSWCiphertextCompressed::encrypt_sk_scratch_space(module, n, basek, k, rank) } @@ -146,7 +161,20 @@ impl BlindRotationKeyCompressed { ) where DataSkGLWE: DataRef, DataSkLWE: DataRef, - Module: GGSWEncryptSkFamily + VecZnxAddScalarInplace, + Module: VecZnxAddScalarInplace + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { #[cfg(debug_assertions)] diff --git a/schemes/src/tfhe/blind_rotation/key_prepared.rs b/schemes/src/tfhe/blind_rotation/key_prepared.rs index 887716f..0d72bab 100644 --- a/schemes/src/tfhe/blind_rotation/key_prepared.rs +++ b/schemes/src/tfhe/blind_rotation/key_prepared.rs @@ -1,5 +1,5 @@ use backend::hal::{ - api::{SvpPPolAlloc, SvpPrepare, VmpPMatAlloc, VmpPMatPrepare}, + api::{SvpPPolAlloc, SvpPrepare, VmpPMatAlloc, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, ScalarZnx, Scratch, SvpPPol}, }; @@ -89,7 +89,7 @@ where impl Prepare> for BlindRotationKeyPrepared where - Module: VmpPMatAlloc + VmpPMatPrepare + SvpPPolAlloc + SvpPrepare, + Module: VmpPMatAlloc + VmpPrepare + SvpPPolAlloc + SvpPrepare, { fn prepare(&mut self, module: &Module, other: &BlindRotationKey, scratch: &mut Scratch) { #[cfg(debug_assertions)] diff --git a/schemes/src/tfhe/blind_rotation/lut.rs b/schemes/src/tfhe/blind_rotation/lut.rs index 6ec093e..3e405a3 100644 --- a/schemes/src/tfhe/blind_rotation/lut.rs +++ b/schemes/src/tfhe/blind_rotation/lut.rs @@ -183,6 +183,7 @@ impl DivRound for usize { } } +#[allow(dead_code)] fn max_bit_size(vec: &[i64]) -> u32 { vec.iter() .map(|&v| { diff --git a/schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs b/schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs index 832d3c1..53d752e 100644 --- a/schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs +++ b/schemes/src/tfhe/blind_rotation/tests/generic_blind_rotation.rs @@ -1,7 +1,12 @@ use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxFillUniform, VecZnxRotateInplace, - VecZnxSub, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, ZnxView, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, + VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAdd, VecZnxDftAddInplace, + VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftSubABInplace, VecZnxDftToVecZnxBig, VecZnxDftToVecZnxBigConsume, + VecZnxDftToVecZnxBigTmpBytes, VecZnxDftZero, VecZnxFillUniform, VecZnxMulXpMinusOneInplace, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxSub, VecZnxSubABInplace, + VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, ZnxView, }, layouts::{Backend, Module, ScratchOwned}, oep::{ @@ -12,23 +17,45 @@ use backend::hal::{ use sampling::source::Source; use crate::tfhe::blind_rotation::{ - BlincRotationExecute, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared, - CCGIBlindRotationFamily, CGGI, LookUpTable, cggi_blind_rotate_scratch_space, mod_switch_2n, + BlincRotationExecute, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared, CGGI, + LookUpTable, cggi_blind_rotate_scratch_space, mod_switch_2n, }; -use core::{ - layouts::{ - GLWECiphertext, GLWEPlaintext, GLWESecret, Infos, LWECiphertext, LWECiphertextToRef, LWEPlaintext, LWESecret, - prepared::{GLWESecretPrepared, PrepareAlloc}, - }, - trait_families::{GLWEDecryptFamily, GLWESecretPreparedModuleFamily}, +use core::layouts::{ + GLWECiphertext, GLWEPlaintext, GLWESecret, Infos, LWECiphertext, LWECiphertextToRef, LWEPlaintext, LWESecret, + prepared::{GLWESecretPrepared, PrepareAlloc}, }; pub fn test_blind_rotation(module: &Module, n_lwe: usize, block_size: usize, extension_factor: usize) where - Module: CCGIBlindRotationFamily - + GLWESecretPreparedModuleFamily - + GLWEDecryptFamily + Module: VecZnxBigAllocBytes + + VecZnxDftAllocBytes + + SvpPPolAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VecZnxDftToVecZnxBigTmpBytes + + VecZnxDftToVecZnxBig + + VecZnxDftAdd + + VecZnxDftAddInplace + + VecZnxDftFromVecZnx + + VecZnxDftZero + + SvpApply + + VecZnxDftSubABInplace + + VecZnxBigAddSmallInplace + + VecZnxRotate + + VecZnxAddInplace + + VecZnxSubABInplace + + VecZnxNormalize + + VecZnxNormalizeInplace + + VecZnxCopy + + VecZnxMulXpMinusOneInplace + + SvpPrepare + + SvpPPolAlloc + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddInplace + + VecZnxBigNormalize + + VecZnxNormalizeTmpBytes + VecZnxFillUniform + VecZnxAddNormal + VecZnxAddScalarInplace @@ -36,7 +63,9 @@ where + VecZnxSwithcDegree + VecZnxSub + VmpPMatAlloc - + VmpPMatPrepare, + + VmpPrepare + + VmpApply + + VmpApplyAdd, B: VecZnxDftAllocBytesImpl + VecZnxBigAllocBytesImpl + ScratchOwnedAllocImpl @@ -57,7 +86,9 @@ where let k_res: usize = 2 * basek; let rank: usize = 1; - let message_modulus: usize = 1 << 4; + let log_message_modulus = 4; + + let message_modulus: usize = 1 << log_message_modulus; let mut source_xs: Source = Source::new([2u8; 32]); let mut source_xe: Source = Source::new([2u8; 32]); @@ -103,10 +134,9 @@ where let mut pt_lwe: LWEPlaintext> = LWEPlaintext::alloc(basek, k_lwe); - let x: i64 = 2; - let bits: usize = 8; + let x: i64 = 15 % (message_modulus as i64); - pt_lwe.encode_i64(x, bits); + pt_lwe.encode_i64(x, log_message_modulus + 1); lwe.encrypt_sk( module, @@ -117,13 +147,16 @@ where 3.2, ); - let mut f: Vec = vec![0i64; message_modulus]; - f.iter_mut() + let f = |x: i64| -> i64 { 2 * x + 1 }; + + let mut f_vec: Vec = vec![0i64; message_modulus]; + f_vec + .iter_mut() .enumerate() - .for_each(|(i, x)| *x = 2 * (i as i64) + 1); + .for_each(|(i, x)| *x = f(i as i64)); let mut lut: LookUpTable = LookUpTable::alloc(n, basek, k_lut, extension_factor); - lut.set(module, &f, message_modulus); + lut.set(module, &f_vec, log_message_modulus + 1); let mut res: GLWECiphertext> = GLWECiphertext::alloc(n, basek, k_res, rank); @@ -157,4 +190,12 @@ where // First limb should be exactly equal (test are parameterized such that the noise does not reach // the first limb) assert_eq!(pt_have.data.at(0, 0), lut.data[0].at(0, 0)); + + // Verify that it effectively compute f(x) + let mut have: i64 = pt_have.decode_coeff_i64(log_message_modulus + 1, 0); + + // Get positive representative and assert equality + have = (have + message_modulus as i64) % (message_modulus as i64); + + assert_eq!(have, f(x) % (message_modulus as i64)); } diff --git a/schemes/src/tfhe/circuit_bootstrapping/circuit_bootstrapping.rs b/schemes/src/tfhe/circuit_bootstrapping/circuit_bootstrapping.rs index 7589729..f0990df 100644 --- a/schemes/src/tfhe/circuit_bootstrapping/circuit_bootstrapping.rs +++ b/schemes/src/tfhe/circuit_bootstrapping/circuit_bootstrapping.rs @@ -1,50 +1,58 @@ -use std::{collections::HashMap, time::Instant, usize}; +use std::{collections::HashMap, usize}; use backend::hal::{ api::{ ScratchAvailable, TakeMatZnx, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice, TakeVecZnxSlice, - VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAutomorphismInplace, VecZnxBigSubSmallBInplace, VecZnxCopy, - VecZnxDftCopy, VecZnxDftToVecZnxBigTmpA, VecZnxNegateInplace, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, - VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, + VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigAutomorphismInplace, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxDftAddInplace, + VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, + VecZnxNegateInplace, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, + VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl}, }; -use core::{GLWEOperations, TakeGGLWE, TakeGLWECt, layouts::Infos, trait_families::GLWETraceModuleFamily}; +use core::{GLWEOperations, TakeGGLWE, TakeGLWECt, layouts::Infos}; use core::layouts::{GGSWCiphertext, GLWECiphertext, LWECiphertext, prepared::GGLWEAutomorphismKeyPrepared}; use crate::tfhe::{ blind_rotation::{ - BlincRotationExecute, BlindRotationAlgo, BlindRotationKeyPrepared, CCGIBlindRotationFamily, LookUpTable, - LookUpTableRotationDirection, + BlincRotationExecute, BlindRotationAlgo, BlindRotationKeyPrepared, LookUpTable, LookUpTableRotationDirection, }, circuit_bootstrapping::{CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute}, }; -pub trait CircuitBootstrapFamily = VecZnxRotateInplace - + VecZnxNormalizeInplace - + VecZnxNormalizeTmpBytes - + CCGIBlindRotationFamily - + VecZnxSwithcDegree - + VecZnxBigAutomorphismInplace - + VecZnxRshInplace - + VecZnxDftCopy - + VecZnxDftToVecZnxBigTmpA - + VecZnxSub - + VecZnxAddInplace - + VecZnxNegateInplace - + VecZnxCopy - + VecZnxSubABInplace - + GLWETraceModuleFamily - + VecZnxRotateInplace - + VecZnxAutomorphismInplace - + VecZnxBigSubSmallBInplace; - impl CirtuitBootstrappingExecute for CircuitBootstrappingKeyPrepared where - Module: CircuitBootstrapFamily, + Module: VecZnxRotateInplace + + VecZnxNormalizeInplace + + VecZnxNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxDftCopy + + VecZnxDftToVecZnxBigTmpA + + VecZnxSub + + VecZnxAddInplace + + VecZnxNegateInplace + + VecZnxCopy + + VecZnxSubABInplace + + VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxBigAllocBytes + + VecZnxDftAddInplace + + VecZnxRotate, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, Scratch: TakeVecZnx + TakeVecZnxDftSlice @@ -115,7 +123,33 @@ pub fn circuit_bootstrap_core: CircuitBootstrapFamily, + Module: VecZnxRotateInplace + + VecZnxNormalizeInplace + + VecZnxNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxDftCopy + + VecZnxDftToVecZnxBigTmpA + + VecZnxSub + + VecZnxAddInplace + + VecZnxNegateInplace + + VecZnxCopy + + VecZnxSubABInplace + + VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxBigAllocBytes + + VecZnxDftAddInplace + + VecZnxRotate, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, Scratch: TakeVecZnxDftSlice + TakeVecZnxBig @@ -165,14 +199,10 @@ pub fn circuit_bootstrap_core = tmp_gglwe.at_mut(i, 0); if to_exponent { - let now: Instant = Instant::now(); - // Isolates i-th LUT and moves coefficients according to requested gap. post_process( module, @@ -194,7 +222,6 @@ pub fn circuit_bootstrap_core( ) where DataRes: DataMut, DataA: DataRef, - Module: CircuitBootstrapFamily, + Module: VecZnxRotateInplace + + VecZnxNormalizeInplace + + VecZnxNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxDftCopy + + VecZnxDftToVecZnxBigTmpA + + VecZnxSub + + VecZnxAddInplace + + VecZnxNegateInplace + + VecZnxCopy + + VecZnxSubABInplace + + VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxRotate, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { let log_n: usize = module.log_n(); @@ -248,10 +299,7 @@ fn post_process( } cts.insert(i as usize * (1 << log_gap_out), res.clone()); }); - - let now: Instant = Instant::now(); pack(module, &mut cts, log_gap_out, auto_keys, scratch); - println!("pack: {} ms", now.elapsed().as_millis()); let packed: GLWECiphertext> = cts.remove(&0).unwrap(); res.trace( module, @@ -271,7 +319,31 @@ pub fn pack( auto_keys: &HashMap, B>>, scratch: &mut Scratch, ) where - Module: CircuitBootstrapFamily, + Module: VecZnxRotateInplace + + VecZnxNormalizeInplace + + VecZnxNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxDftCopy + + VecZnxDftToVecZnxBigTmpA + + VecZnxSub + + VecZnxAddInplace + + VecZnxNegateInplace + + VecZnxCopy + + VecZnxSubABInplace + + VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxRotate, Scratch: TakeVecZnx + TakeVecZnxDft + ScratchAvailable, { let log_n: usize = module.log_n(); @@ -281,8 +353,6 @@ pub fn pack( let rank: usize = cts.get(&0).unwrap().rank(); (0..log_n - log_gap_out).for_each(|i| { - let now: Instant = Instant::now(); - let t = 16.min(1 << (log_n - 1 - i)); let auto_key: &GGLWEAutomorphismKeyPrepared, B>; @@ -314,8 +384,6 @@ pub fn pack( cts.insert(j, b); } }); - - println!("combine: {} us", now.elapsed().as_micros()); }); } @@ -330,7 +398,31 @@ fn combine( auto_key: &GGLWEAutomorphismKeyPrepared, scratch: &mut Scratch, ) where - Module: CircuitBootstrapFamily, + Module: VecZnxRotateInplace + + VecZnxNormalizeInplace + + VecZnxNormalizeTmpBytes + + VecZnxSwithcDegree + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxDftCopy + + VecZnxDftToVecZnxBigTmpA + + VecZnxSub + + VecZnxAddInplace + + VecZnxNegateInplace + + VecZnxCopy + + VecZnxSubABInplace + + VecZnxDftAllocBytes + + VmpApplyTmpBytes + + VecZnxBigNormalizeTmpBytes + + VmpApply + + VmpApplyAdd + + VecZnxDftFromVecZnx + + VecZnxDftToVecZnxBigConsume + + VecZnxBigAddSmallInplace + + VecZnxBigNormalize + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxRotate, Scratch: TakeVecZnx + TakeVecZnxDft + ScratchAvailable, { // Goal is to evaluate: a = a + b*X^t + phi(a - b*X^t)) diff --git a/schemes/src/tfhe/circuit_bootstrapping/key.rs b/schemes/src/tfhe/circuit_bootstrapping/key.rs index aeb58bb..4600aa3 100644 --- a/schemes/src/tfhe/circuit_bootstrapping/key.rs +++ b/schemes/src/tfhe/circuit_bootstrapping/key.rs @@ -6,17 +6,16 @@ use std::{collections::HashMap, usize}; use backend::hal::{ api::{ - ScratchAvailable, TakeScalarZnx, TakeSvpPPol, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAddScalarInplace, - VecZnxAutomorphism, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, + ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeSvpPPol, + TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, + VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, + VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, + VecZnxSwithcDegree, VmpPMatAlloc, VmpPrepare, }, layouts::{Backend, Data, DataRef, Module, Scratch}, }; use sampling::source::Source; -use core::trait_families::{ - GGLWEAutomorphismKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWEncryptSkFamily, GLWESecretPreparedModuleFamily, -}; - use crate::tfhe::blind_rotation::{ BlindRotationAlgo, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared, }; @@ -52,13 +51,27 @@ pub struct CircuitBootstrappingKey { impl CircuitBootstrappingKeyEncryptSk for CircuitBootstrappingKey, BRA> where BlindRotationKey, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk, - Module: GGSWEncryptSkFamily - + GLWESecretPreparedModuleFamily + Module: SvpApply + + VecZnxDftToVecZnxBigTmpA + VecZnxAddScalarInplace - + GGLWEAutomorphismKeyEncryptSkFamily - + VecZnxAutomorphism + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxFillUniform + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalizeInplace + + VecZnxAddNormal + + VecZnxNormalize + + VecZnxSub + + SvpPrepare + VecZnxSwithcDegree - + GGLWETensorKeyEncryptSkFamily, + + SvpPPolAllocBytes + + SvpPPolAlloc + + VecZnxAutomorphism, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeSvpPPol + TakeVecZnxBig, { fn encrypt_sk( @@ -80,6 +93,7 @@ where where DLwe: DataRef, DGlwe: DataRef, + Module:, { let mut auto_keys: HashMap>> = HashMap::new(); let gal_els: Vec = GLWECiphertext::trace_galois_elements(&module); @@ -133,7 +147,7 @@ pub struct CircuitBootstrappingKeyPrepared PrepareAlloc, BRA, B>> for CircuitBootstrappingKey where - Module: VmpPMatAlloc + VmpPMatPrepare, + Module: VmpPMatAlloc + VmpPrepare, BlindRotationKey: PrepareAlloc, BRA, B>>, GGLWETensorKey: PrepareAlloc, B>>, GGLWEAutomorphismKey: PrepareAlloc, B>>, diff --git a/schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs b/schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs index 349ba2c..eb04845 100644 --- a/schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs +++ b/schemes/src/tfhe/circuit_bootstrapping/tests/circuit_bootstrapping.rs @@ -2,9 +2,14 @@ use std::time::Instant; use backend::hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal, VecZnxAddScalarInplace, - VecZnxAutomorphism, VecZnxFillUniform, VecZnxNormalizeInplace, VecZnxRotateInplace, VecZnxSwithcDegree, VmpPMatAlloc, - VmpPMatPrepare, ZnxView, ZnxViewMut, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, + VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, + VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAllocBytes, VecZnxBigAutomorphismInplace, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxDftAddInplace, + VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, + VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform, VecZnxNegateInplace, VecZnxNormalize, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, + VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare, ZnxView, ZnxViewMut, }, layouts::{Backend, Module, ScalarZnx, ScratchOwned}, oep::{ @@ -20,18 +25,11 @@ use crate::tfhe::{ BlindRotationKeyPrepared, }, circuit_bootstrapping::{ - CircuitBootstrapFamily, CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyPrepared, - CirtuitBootstrappingExecute, + CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute, }, }; -use core::{ - layouts::prepared::PrepareAlloc, - trait_families::{ - GGLWEAutomorphismKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWAssertNoiseFamily, GGSWEncryptSkFamily, - GLWEDecryptFamily, - }, -}; +use core::layouts::prepared::PrepareAlloc; use core::layouts::{ GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret, @@ -43,19 +41,46 @@ where Module: VecZnxFillUniform + VecZnxAddNormal + VecZnxNormalizeInplace - + GGSWEncryptSkFamily + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalize + + VecZnxSub + VecZnxAddScalarInplace - + GGLWEAutomorphismKeyEncryptSkFamily + VecZnxAutomorphism + VecZnxSwithcDegree - + GGLWETensorKeyEncryptSkFamily - + CircuitBootstrapFamily - + GLWEDecryptFamily - + GGSWAssertNoiseFamily + + VecZnxBigAllocBytes + + VecZnxDftToVecZnxBigTmpA + + SvpApply + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + VmpPMatAlloc - + VmpPMatPrepare + + VmpPrepare + SvpPrepare - + SvpPPolAlloc, + + SvpPPolAlloc + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + SvpPPolAllocBytes + + VecZnxRotateInplace + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxDftCopy + + VecZnxNegateInplace + + VecZnxCopy + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxBigAllocBytes + + VecZnxDftAddInplace + + VecZnxRotate, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + TakeVecZnxDftImpl @@ -108,7 +133,7 @@ where let data: i64 = 1; let mut pt_lwe: LWEPlaintext> = LWEPlaintext::alloc(basek, k_lwe_pt); - pt_lwe.encode_i64(data, k_lwe_pt + 2); + pt_lwe.encode_i64(data, k_lwe_pt + 1); println!("pt_lwe: {}", pt_lwe); @@ -203,19 +228,46 @@ where Module: VecZnxFillUniform + VecZnxAddNormal + VecZnxNormalizeInplace - + GGSWEncryptSkFamily + + VecZnxDftAllocBytes + + VecZnxBigNormalize + + VecZnxDftFromVecZnx + + SvpApplyInplace + + VecZnxDftToVecZnxBigConsume + + VecZnxNormalizeTmpBytes + + VecZnxSubABInplace + + VecZnxAddInplace + + VecZnxNormalize + + VecZnxSub + VecZnxAddScalarInplace - + GGLWEAutomorphismKeyEncryptSkFamily + VecZnxAutomorphism + VecZnxSwithcDegree - + GGLWETensorKeyEncryptSkFamily - + CircuitBootstrapFamily - + GLWEDecryptFamily - + GGSWAssertNoiseFamily + + VecZnxBigAllocBytes + + VecZnxDftToVecZnxBigTmpA + + SvpApply + + VecZnxBigAddInplace + + VecZnxBigAddSmallInplace + + VecZnxBigAlloc + + VecZnxDftAlloc + + VecZnxBigNormalizeTmpBytes + VmpPMatAlloc - + VmpPMatPrepare + + VmpPrepare + SvpPrepare - + SvpPPolAlloc, + + SvpPPolAlloc + + VmpApplyTmpBytes + + VmpApply + + VmpApplyAdd + + SvpPPolAllocBytes + + VecZnxRotateInplace + + VecZnxBigAutomorphismInplace + + VecZnxRshInplace + + VecZnxDftCopy + + VecZnxNegateInplace + + VecZnxCopy + + VecZnxAutomorphismInplace + + VecZnxBigSubSmallBInplace + + VecZnxBigAllocBytes + + VecZnxDftAddInplace + + VecZnxRotate, B: ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl + TakeVecZnxDftImpl @@ -268,7 +320,7 @@ where let data: i64 = 1; let mut pt_lwe: LWEPlaintext> = LWEPlaintext::alloc(basek, k_lwe_pt); - pt_lwe.encode_i64(data, k_lwe_pt + 2); + pt_lwe.encode_i64(data, k_lwe_pt + 1); println!("pt_lwe: {}", pt_lwe); diff --git a/utils/Cargo.toml b/utils/Cargo.toml deleted file mode 100644 index 56760fb..0000000 --- a/utils/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "utils" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" - -[dependencies] -fnv = "1.0.7" \ No newline at end of file diff --git a/utils/src/lib.rs b/utils/src/lib.rs deleted file mode 100644 index 1d7f53b..0000000 --- a/utils/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod map; diff --git a/utils/src/map.rs b/utils/src/map.rs deleted file mode 100644 index 94b824f..0000000 --- a/utils/src/map.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::hash::Hash; - -use fnv::FnvHashMap; - -pub struct Map(pub FnvHashMap); - -impl Map { - pub fn new() -> Self { - Self { - 0: FnvHashMap::::default(), - } - } - - pub fn insert(&mut self, k: K, data: V) -> Option { - self.0.insert(k, data) - } - - pub fn get(&self, k: &K) -> Option<&V> { - self.0.get(k) - } -}