mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
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
This commit is contained in:
committed by
GitHub
parent
c7219c35e9
commit
3a828740cc
77
Cargo.lock
generated
77
Cargo.lock
generated
@@ -43,14 +43,11 @@ dependencies = [
|
|||||||
"cmake",
|
"cmake",
|
||||||
"criterion",
|
"criterion",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
"paste",
|
|
||||||
"rand",
|
"rand",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
"rand_distr",
|
"rand_distr",
|
||||||
"rug",
|
"rug",
|
||||||
"sampling",
|
"sampling",
|
||||||
"utils",
|
|
||||||
"zstd",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -83,8 +80,6 @@ version = "1.2.31"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2"
|
checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jobserver",
|
|
||||||
"libc",
|
|
||||||
"shlex",
|
"shlex",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -239,12 +234,6 @@ version = "1.13.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fnv"
|
|
||||||
version = "1.0.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -301,15 +290,6 @@ version = "1.0.14"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jobserver"
|
|
||||||
version = "0.1.32"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.76"
|
version = "0.3.76"
|
||||||
@@ -366,18 +346,6 @@ version = "11.1.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9"
|
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]]
|
[[package]]
|
||||||
name = "plotters"
|
name = "plotters"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
@@ -406,6 +374,16 @@ dependencies = [
|
|||||||
"plotters-backend",
|
"plotters-backend",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "poulpy"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"backend",
|
||||||
|
"core",
|
||||||
|
"sampling",
|
||||||
|
"schemes",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.20"
|
version = "0.2.20"
|
||||||
@@ -639,13 +617,6 @@ version = "1.0.14"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "utils"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"fnv",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "walkdir"
|
name = "walkdir"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@@ -849,31 +820,3 @@ dependencies = [
|
|||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"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",
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["backend", "core", "sampling", "utils", "schemes"]
|
members = ["backend", "core", "sampling", "schemes", "poulpy"]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ rand = {workspace = true}
|
|||||||
rand_distr = {workspace = true}
|
rand_distr = {workspace = true}
|
||||||
rand_core = {workspace = true}
|
rand_core = {workspace = true}
|
||||||
sampling = { path = "../sampling" }
|
sampling = { path = "../sampling" }
|
||||||
utils = { path = "../utils" }
|
|
||||||
paste = "1.0.15"
|
|
||||||
byteorder = {workspace = true}
|
byteorder = {workspace = true}
|
||||||
zstd = {workspace = true}
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cmake = "0.1.54"
|
cmake = "0.1.54"
|
||||||
|
|||||||
@@ -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;
|
fn vmp_prepare_tmp_bytes(&self, n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait VmpPMatPrepare<B: Backend> {
|
pub trait VmpPrepare<B: Backend> {
|
||||||
fn vmp_prepare<R, A>(&self, res: &mut R, a: &A, scratch: &mut Scratch<B>)
|
fn vmp_prepare<R, A>(&self, res: &mut R, a: &A, scratch: &mut Scratch<B>)
|
||||||
where
|
where
|
||||||
R: VmpPMatToMut<B>,
|
R: VmpPMatToMut<B>,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::hal::{
|
use crate::hal::{
|
||||||
api::{
|
api::{
|
||||||
VmpApply, VmpApplyAdd, VmpApplyAddTmpBytes, VmpApplyTmpBytes, VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatFromBytes,
|
VmpApply, VmpApplyAdd, VmpApplyAddTmpBytes, VmpApplyTmpBytes, VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatFromBytes,
|
||||||
VmpPMatPrepare, VmpPrepareTmpBytes,
|
VmpPrepare, VmpPrepareTmpBytes,
|
||||||
},
|
},
|
||||||
layouts::{Backend, MatZnxToRef, Module, Scratch, VecZnxDftToMut, VecZnxDftToRef, VmpPMatOwned, VmpPMatToMut, VmpPMatToRef},
|
layouts::{Backend, MatZnxToRef, Module, Scratch, VecZnxDftToMut, VecZnxDftToRef, VmpPMatOwned, VmpPMatToMut, VmpPMatToRef},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -54,7 +54,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B> VmpPMatPrepare<B> for Module<B>
|
impl<B> VmpPrepare<B> for Module<B>
|
||||||
where
|
where
|
||||||
B: Backend + VmpPMatPrepareImpl<B>,
|
B: Backend + VmpPMatPrepareImpl<B>,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GGLWEAutomorphismKey, GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared};
|
||||||
layouts::{GGLWEAutomorphismKey, GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared},
|
|
||||||
trait_families::GLWEKeyswitchFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GGLWEAutomorphismKey<Vec<u8>> {
|
impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn automorphism_scratch_space<B: Backend>(
|
pub fn automorphism_scratch_space<B: Backend>(
|
||||||
@@ -20,7 +21,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank)
|
GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank)
|
||||||
}
|
}
|
||||||
@@ -35,7 +36,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWEAutomorphismKey::automorphism_scratch_space(module, n, basek, k_out, k_out, k_ksk, digits, rank)
|
GGLWEAutomorphismKey::automorphism_scratch_space(module, n, basek, k_out, k_out, k_ksk, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -49,8 +50,18 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxAutomorphism + VecZnxAutomorphismInplace,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphism
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -123,8 +134,18 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxAutomorphism + VecZnxAutomorphismInplace,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphism
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let self_ptr: *mut GGLWEAutomorphismKey<DataSelf> = self as *mut GGLWEAutomorphismKey<DataSelf>;
|
let self_ptr: *mut GGLWEAutomorphismKey<DataSelf> = self as *mut GGLWEAutomorphismKey<DataSelf>;
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{
|
|
||||||
GGSWCiphertext, GLWECiphertext, Infos,
|
GGSWCiphertext, GLWECiphertext, Infos,
|
||||||
prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared},
|
prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared},
|
||||||
},
|
|
||||||
trait_families::{GGSWKeySwitchFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl GGSWCiphertext<Vec<u8>> {
|
impl GGSWCiphertext<Vec<u8>> {
|
||||||
@@ -25,7 +27,8 @@ impl GGSWCiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>:
|
||||||
|
VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
let out_size: usize = k_out.div_ceil(basek);
|
let out_size: usize = k_out.div_ceil(basek);
|
||||||
let ci_dft: usize = module.vec_znx_dft_alloc_bytes(n, rank + 1, out_size);
|
let ci_dft: usize = module.vec_znx_dft_alloc_bytes(n, rank + 1, out_size);
|
||||||
@@ -47,7 +50,8 @@ impl GGSWCiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>:
|
||||||
|
VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGSWCiphertext::automorphism_scratch_space(
|
GGSWCiphertext::automorphism_scratch_space(
|
||||||
module, n, basek, k_out, k_out, k_ksk, digits_ksk, k_tsk, digits_tsk, rank,
|
module, n, basek, k_out, k_out, k_ksk, digits_ksk, k_tsk, digits_tsk, rank,
|
||||||
@@ -64,8 +68,22 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
tensor_key: &GGLWETensorKeyPrepared<DataTsk, B>,
|
tensor_key: &GGLWETensorKeyPrepared<DataTsk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxAutomorphismInplace + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -121,8 +139,22 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
tensor_key: &GGLWETensorKeyPrepared<DataTsk, B>,
|
tensor_key: &GGLWETensorKeyPrepared<DataTsk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxAutomorphismInplace + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let self_ptr: *mut GGSWCiphertext<DataSelf> = self as *mut GGSWCiphertext<DataSelf>;
|
let self_ptr: *mut GGSWCiphertext<DataSelf> = self as *mut GGSWCiphertext<DataSelf>;
|
||||||
@@ -137,8 +169,17 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
auto_key: &GGLWEAutomorphismKeyPrepared<DataAk, B>,
|
auto_key: &GGLWEAutomorphismKeyPrepared<DataAk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxAutomorphismInplace + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
// Keyswitch the j-th row of the col 0
|
// Keyswitch the j-th row of the col 0
|
||||||
(0..lhs.rows()).for_each(|row_i| {
|
(0..lhs.rows()).for_each(|row_i| {
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxBigAutomorphismInplace, VecZnxBigSubSmallAInplace,
|
ScratchAvailable, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace,
|
||||||
VecZnxBigSubSmallBInplace,
|
VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallAInplace, VecZnxBigSubSmallBInplace,
|
||||||
|
VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VmpApply, VmpApplyAdd, VmpApplyTmpBytes,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared};
|
||||||
layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared},
|
|
||||||
trait_families::GLWEKeyswitchFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn automorphism_scratch_space<B: Backend>(
|
pub fn automorphism_scratch_space<B: Backend>(
|
||||||
@@ -23,7 +21,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
Self::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank)
|
Self::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank)
|
||||||
}
|
}
|
||||||
@@ -38,7 +36,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
Self::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank)
|
Self::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -52,7 +50,16 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxAutomorphismInplace,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
self.keyswitch(module, lhs, &rhs.key, scratch);
|
self.keyswitch(module, lhs, &rhs.key, scratch);
|
||||||
@@ -67,7 +74,16 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxAutomorphismInplace,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
self.keyswitch_inplace(module, &rhs.key, scratch);
|
self.keyswitch_inplace(module, &rhs.key, scratch);
|
||||||
@@ -83,7 +99,16 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxBigAutomorphismInplace<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -105,7 +130,16 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxBigAutomorphismInplace<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -121,7 +155,17 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallAInplace<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxBigSubSmallAInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -143,7 +187,17 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallAInplace<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxBigSubSmallAInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -159,7 +213,17 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallBInplace<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -181,7 +245,17 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + VecZnxBigAutomorphismInplace<B> + VecZnxBigSubSmallBInplace<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -8,8 +12,6 @@ use crate::{
|
|||||||
layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::GLWEToLWESwitchingKeyPrepared},
|
layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::GLWEToLWESwitchingKeyPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::GLWEKeyswitchFamily;
|
|
||||||
|
|
||||||
impl LWECiphertext<Vec<u8>> {
|
impl LWECiphertext<Vec<u8>> {
|
||||||
pub fn from_glwe_scratch_space<B: Backend>(
|
pub fn from_glwe_scratch_space<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
@@ -21,7 +23,7 @@ impl LWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::bytes_of(n, basek, k_lwe, 1)
|
GLWECiphertext::bytes_of(n, basek, k_lwe, 1)
|
||||||
+ GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_lwe, k_glwe, k_ksk, 1, rank, 1)
|
+ GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_lwe, k_glwe, k_ksk, 1, rank, 1)
|
||||||
@@ -55,8 +57,16 @@ impl<DLwe: DataMut> LWECiphertext<DLwe> {
|
|||||||
) where
|
) where
|
||||||
DGlwe: DataRef,
|
DGlwe: DataRef,
|
||||||
DKs: DataRef,
|
DKs: DataRef,
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeGLWECt,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -8,8 +12,6 @@ use crate::{
|
|||||||
layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::LWEToGLWESwitchingKeyPrepared},
|
layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::LWEToGLWESwitchingKeyPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::GLWEKeyswitchFamily;
|
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn from_lwe_scratch_space<B: Backend>(
|
pub fn from_lwe_scratch_space<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
@@ -21,7 +23,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_glwe, k_lwe, k_ksk, 1, 1, rank)
|
GLWECiphertext::keyswitch_scratch_space(module, n, basek, k_glwe, k_lwe, k_ksk, 1, 1, rank)
|
||||||
+ GLWECiphertext::bytes_of(n, basek, k_lwe, 1)
|
+ GLWECiphertext::bytes_of(n, basek, k_lwe, 1)
|
||||||
@@ -38,8 +40,16 @@ impl<D: DataMut> GLWECiphertext<D> {
|
|||||||
) where
|
) where
|
||||||
DLwe: DataRef,
|
DLwe: DataRef,
|
||||||
DKsk: DataRef,
|
DKsk: DataRef,
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeGLWECt,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,15 +6,12 @@ use backend::hal::{
|
|||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared};
|
||||||
layouts::{GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared},
|
|
||||||
trait_families::GLWEDecryptFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn decrypt_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn decrypt_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEDecryptFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||||
{
|
{
|
||||||
let size: usize = k.div_ceil(basek);
|
let size: usize = k.div_ceil(basek);
|
||||||
(module.vec_znx_normalize_tmp_bytes(n) | module.vec_znx_dft_alloc_bytes(n, 1, size))
|
(module.vec_znx_normalize_tmp_bytes(n) | module.vec_znx_dft_alloc_bytes(n, 1, size))
|
||||||
@@ -30,7 +27,12 @@ impl<DataSelf: DataRef> GLWECiphertext<DataSelf> {
|
|||||||
sk: &GLWESecretPrepared<DataSk, B>,
|
sk: &GLWESecretPrepared<DataSk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEDecryptFamily<B>,
|
Module<B>: VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphism,
|
ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft,
|
||||||
VecZnxSwithcDegree,
|
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigNormalize, VecZnxDftAllocBytes,
|
||||||
|
VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace,
|
||||||
|
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
@@ -10,17 +12,15 @@ use sampling::source::Source;
|
|||||||
use crate::{
|
use crate::{
|
||||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||||
layouts::{
|
layouts::{
|
||||||
GLWESecret, Infos,
|
GLWESecret,
|
||||||
compressed::{GGLWEAutomorphismKeyCompressed, GGLWESwitchingKeyCompressed},
|
compressed::{GGLWEAutomorphismKeyCompressed, GGLWESwitchingKeyCompressed},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl GGLWEAutomorphismKeyCompressed<Vec<u8>> {
|
impl GGLWEAutomorphismKeyCompressed<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes,
|
||||||
{
|
{
|
||||||
GGLWESwitchingKeyCompressed::encrypt_sk_scratch_space(module, n, basek, k, rank, rank) + GLWESecret::bytes_of(n, rank)
|
GGLWESwitchingKeyCompressed::encrypt_sk_scratch_space(module, n, basek, k, rank, rank) + GLWESecret::bytes_of(n, rank)
|
||||||
}
|
}
|
||||||
@@ -37,15 +37,30 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxAutomorphism
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxDftAllocBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxDftFromVecZnx<B>
|
||||||
Scratch<B>: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft<B> + TakeGLWESecretPrepared<B> + TakeVecZnx,
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxAddScalarInplace,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
use crate::layouts::Infos;
|
||||||
|
|
||||||
assert_eq!(self.n(), sk.n());
|
assert_eq!(self.n(), sk.n());
|
||||||
assert_eq!(self.rank_out(), self.rank_in());
|
assert_eq!(self.rank_out(), self.rank_in());
|
||||||
assert_eq!(sk.rank(), self.rank());
|
assert_eq!(sk.rank(), self.rank());
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
@@ -10,12 +14,10 @@ use crate::{
|
|||||||
layouts::{GGLWECiphertext, Infos, compressed::GGLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
layouts::{GGLWECiphertext, Infos, compressed::GGLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily};
|
|
||||||
|
|
||||||
impl GGLWECiphertextCompressed<Vec<u8>> {
|
impl GGLWECiphertextCompressed<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
||||||
}
|
}
|
||||||
@@ -32,7 +34,20 @@ impl<D: DataMut> GGLWECiphertextCompressed<D> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + VecZnxAddScalarInplace,
|
Module<B>: VecZnxAddScalarInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
TakeGLWESecretPrepared,
|
TakeGLWESecretPrepared,
|
||||||
layouts::{
|
layouts::{GGLWECiphertext, GLWESecret, compressed::GGLWESwitchingKeyCompressed, prepared::GLWESecretPrepared},
|
||||||
GGLWECiphertext, GGLWESwitchingKey, GLWESecret, Infos, compressed::GGLWESwitchingKeyCompressed,
|
|
||||||
prepared::GLWESecretPrepared,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl GGLWESwitchingKeyCompressed<Vec<u8>> {
|
impl GGLWESwitchingKeyCompressed<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(
|
pub fn encrypt_sk_scratch_space<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
@@ -24,7 +24,7 @@ impl GGLWESwitchingKeyCompressed<Vec<u8>> {
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes,
|
||||||
{
|
{
|
||||||
(GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) | ScalarZnx::alloc_bytes(n, 1))
|
(GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) | ScalarZnx::alloc_bytes(n, 1))
|
||||||
+ ScalarZnx::alloc_bytes(n, rank_in)
|
+ ScalarZnx::alloc_bytes(n, rank_in)
|
||||||
@@ -43,13 +43,29 @@ impl<DataSelf: DataMut> GGLWESwitchingKeyCompressed<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>:
|
Module<B>: SvpPrepare<B>
|
||||||
GGLWESwitchingKeyEncryptSkFamily<B> + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily<B>,
|
+ SvpPPolAllocBytes
|
||||||
Scratch<B>:
|
+ VecZnxSwithcDegree
|
||||||
ScratchAvailable + TakeScalarZnx + TakeVecZnxDft<B> + TakeGLWESecretPrepared<B> + ScratchAvailable + TakeVecZnx,
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxAddScalarInplace,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
use crate::layouts::{GGLWESwitchingKey, Infos};
|
||||||
|
|
||||||
assert!(sk_in.n() <= module.n());
|
assert!(sk_in.n() <= module.n());
|
||||||
assert!(sk_out.n() <= module.n());
|
assert!(sk_out.n() <= module.n());
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, SvpApply, TakeScalarZnx, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAddScalarInplace,
|
ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx,
|
||||||
VecZnxDftToVecZnxBigTmpA, VecZnxSwithcDegree,
|
TakeVecZnxBig, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAllocBytes,
|
||||||
|
VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA,
|
||||||
|
VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace,
|
||||||
|
VecZnxSwithcDegree,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
@@ -10,15 +13,13 @@ use sampling::source::Source;
|
|||||||
use crate::{
|
use crate::{
|
||||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||||
layouts::{GGLWETensorKey, GLWESecret, Infos, compressed::GGLWETensorKeyCompressed, prepared::Prepare},
|
layouts::{GGLWETensorKey, GLWESecret, Infos, compressed::GGLWETensorKeyCompressed, prepared::Prepare},
|
||||||
trait_families::GLWEDecryptFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWETensorKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl GGLWETensorKeyCompressed<Vec<u8>> {
|
impl GGLWETensorKeyCompressed<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWETensorKeyEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>:
|
||||||
|
SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigAllocBytes,
|
||||||
{
|
{
|
||||||
GGLWETensorKey::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
GGLWETensorKey::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
||||||
}
|
}
|
||||||
@@ -34,10 +35,33 @@ impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>:
|
Module<B>: SvpApply<B>
|
||||||
GGLWETensorKeyEncryptSkFamily<B> + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
Scratch<B>:
|
+ VecZnxDftAllocBytes
|
||||||
ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeGLWESecretPrepared<B> + TakeScalarZnx + TakeVecZnx,
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>,
|
||||||
|
Scratch<B>: ScratchAvailable
|
||||||
|
+ TakeScalarZnx
|
||||||
|
+ TakeVecZnxDft<B>
|
||||||
|
+ TakeGLWESecretPrepared<B>
|
||||||
|
+ ScratchAvailable
|
||||||
|
+ TakeVecZnx
|
||||||
|
+ TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
@@ -10,12 +14,10 @@ use crate::{
|
|||||||
layouts::{GGSWCiphertext, Infos, compressed::GGSWCiphertextCompressed, prepared::GLWESecretPrepared},
|
layouts::{GGSWCiphertext, Infos, compressed::GGSWCiphertextCompressed, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::GGSWEncryptSkFamily;
|
|
||||||
|
|
||||||
impl GGSWCiphertextCompressed<Vec<u8>> {
|
impl GGSWCiphertextCompressed<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGSWEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||||
{
|
{
|
||||||
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
||||||
}
|
}
|
||||||
@@ -32,7 +34,20 @@ impl<DataSelf: DataMut> GGSWCiphertextCompressed<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGSWEncryptSkFamily<B> + VecZnxAddScalarInplace,
|
Module<B>: VecZnxAddScalarInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
@@ -9,12 +13,10 @@ use crate::{
|
|||||||
layouts::{GLWECiphertext, GLWEPlaintext, Infos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
layouts::{GLWECiphertext, GLWEPlaintext, Infos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::GLWEEncryptSkFamily;
|
|
||||||
|
|
||||||
impl GLWECiphertextCompressed<Vec<u8>> {
|
impl GLWECiphertextCompressed<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
||||||
}
|
}
|
||||||
@@ -31,7 +33,19 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
self.encrypt_sk_internal(
|
self.encrypt_sk_internal(
|
||||||
@@ -55,7 +69,19 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
let mut source_xa = Source::new(seed_xa);
|
let mut source_xa = Source::new(seed_xa);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphism,
|
ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft,
|
||||||
VecZnxSwithcDegree,
|
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigNormalize, VecZnxDftAllocBytes,
|
||||||
|
VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace,
|
||||||
|
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
@@ -9,15 +11,13 @@ use sampling::source::Source;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||||
layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, GLWESecret, Infos},
|
layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, GLWESecret},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl GGLWEAutomorphismKey<Vec<u8>> {
|
impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank, rank) + GLWESecret::bytes_of(n, rank)
|
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank, rank) + GLWESecret::bytes_of(n, rank)
|
||||||
}
|
}
|
||||||
@@ -38,15 +38,30 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxAddScalarInplace
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ SvpPPolAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxAutomorphism,
|
||||||
Scratch<B>: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft<B> + TakeGLWESecretPrepared<B> + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
use crate::layouts::Infos;
|
||||||
|
|
||||||
assert_eq!(self.n(), sk.n());
|
assert_eq!(self.n(), sk.n());
|
||||||
assert_eq!(self.rank_out(), self.rank_in());
|
assert_eq!(self.rank_out(), self.rank_in());
|
||||||
assert_eq!(sk.rank(), self.rank());
|
assert_eq!(sk.rank(), self.rank());
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes,
|
ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace,
|
||||||
ZnxZero,
|
VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform,
|
||||||
|
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, ZnxZero,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch},
|
||||||
};
|
};
|
||||||
@@ -12,12 +13,10 @@ use crate::{
|
|||||||
layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared},
|
layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::GGLWEEncryptSkFamily;
|
|
||||||
|
|
||||||
impl GGLWECiphertext<Vec<u8>> {
|
impl GGLWECiphertext<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
||||||
+ (GLWEPlaintext::byte_of(n, basek, k) | module.vec_znx_normalize_tmp_bytes(n))
|
+ (GLWEPlaintext::byte_of(n, basek, k) | module.vec_znx_normalize_tmp_bytes(n))
|
||||||
@@ -39,7 +38,20 @@ impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + VecZnxAddScalarInplace,
|
Module<B>: VecZnxAddScalarInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
TakeGLWESecretPrepared,
|
TakeGLWESecretPrepared,
|
||||||
layouts::{GGLWECiphertext, GGLWESwitchingKey, GLWESecret, Infos, prepared::GLWESecretPrepared},
|
layouts::{GGLWECiphertext, GGLWESwitchingKey, GLWESecret, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl GGLWESwitchingKey<Vec<u8>> {
|
impl GGLWESwitchingKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(
|
pub fn encrypt_sk_scratch_space<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
@@ -21,7 +24,7 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
(GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) | ScalarZnx::alloc_bytes(n, 1))
|
(GGLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) | ScalarZnx::alloc_bytes(n, 1))
|
||||||
+ ScalarZnx::alloc_bytes(n, rank_in)
|
+ ScalarZnx::alloc_bytes(n, rank_in)
|
||||||
@@ -51,13 +54,29 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>:
|
Module<B>: VecZnxAddScalarInplace
|
||||||
GGLWESwitchingKeyEncryptSkFamily<B> + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxDftAllocBytes
|
||||||
Scratch<B>:
|
+ VecZnxBigNormalize<B>
|
||||||
ScratchAvailable + TakeScalarZnx + TakeVecZnxDft<B> + TakeGLWESecretPrepared<B> + ScratchAvailable + TakeVecZnx,
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpPPolAllocBytes,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
use crate::layouts::Infos;
|
||||||
|
|
||||||
assert!(sk_in.n() <= module.n());
|
assert!(sk_in.n() <= module.n());
|
||||||
assert!(sk_out.n() <= module.n());
|
assert!(sk_out.n() <= module.n());
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, SvpApply, TakeScalarZnx, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAddScalarInplace,
|
ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxBig,
|
||||||
VecZnxBigAllocBytes, VecZnxDftToVecZnxBigTmpA, VecZnxSwithcDegree,
|
TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAllocBytes, VecZnxBigNormalize,
|
||||||
|
VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxFillUniform,
|
||||||
|
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
@@ -13,15 +15,13 @@ use crate::{
|
|||||||
GGLWESwitchingKey, GGLWETensorKey, GLWESecret, Infos,
|
GGLWESwitchingKey, GGLWETensorKey, GLWESecret, Infos,
|
||||||
prepared::{GLWESecretPrepared, Prepare},
|
prepared::{GLWESecretPrepared, Prepare},
|
||||||
},
|
},
|
||||||
trait_families::GLWEDecryptFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWETensorKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl GGLWETensorKey<Vec<u8>> {
|
impl GGLWETensorKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWETensorKeyEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>:
|
||||||
|
SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigAllocBytes,
|
||||||
{
|
{
|
||||||
GLWESecretPrepared::bytes_of(module, n, rank)
|
GLWESecretPrepared::bytes_of(module, n, rank)
|
||||||
+ module.vec_znx_dft_alloc_bytes(n, rank, 1)
|
+ module.vec_znx_dft_alloc_bytes(n, rank, 1)
|
||||||
@@ -42,10 +42,27 @@ impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>:
|
Module<B>: SvpApply<B>
|
||||||
GGLWETensorKeyEncryptSkFamily<B> + VecZnxSwithcDegree + VecZnxAddScalarInplace + GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpPPolAllocBytes,
|
||||||
Scratch<B>:
|
Scratch<B>:
|
||||||
ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeGLWESecretPrepared<B> + TakeScalarZnx + TakeVecZnx,
|
TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B> + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch, VecZnx},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
@@ -9,14 +13,10 @@ use crate::{
|
|||||||
layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GLWESecretPrepared},
|
layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::GLWEEncryptSkFamily;
|
|
||||||
|
|
||||||
pub trait GGSWEncryptSkFamily<B: Backend> = GLWEEncryptSkFamily<B>;
|
|
||||||
|
|
||||||
impl GGSWCiphertext<Vec<u8>> {
|
impl GGSWCiphertext<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGSWEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||||
{
|
{
|
||||||
let size = k.div_ceil(basek);
|
let size = k.div_ceil(basek);
|
||||||
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k)
|
||||||
@@ -37,7 +37,20 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGSWEncryptSkFamily<B> + VecZnxAddScalarInplace,
|
Module<B>: VecZnxAddScalarInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, SvpApply, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeSvpPPol, TakeVecZnx, TakeVecZnxDft,
|
ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeSvpPPol, TakeVecZnx,
|
||||||
VecZnxBigAddNormal, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftToVecZnxBigConsume,
|
TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigAddNormal, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes,
|
||||||
ZnxInfos, ZnxZero,
|
VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform,
|
||||||
|
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, ZnxInfos, ZnxZero,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch, VecZnx, VecZnxBig},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch, VecZnx, VecZnxBig},
|
||||||
};
|
};
|
||||||
@@ -15,20 +16,19 @@ use crate::{
|
|||||||
GLWECiphertext, GLWEPlaintext, Infos,
|
GLWECiphertext, GLWEPlaintext, Infos,
|
||||||
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared},
|
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
trait_families::{GLWEEncryptPkFamily, GLWEEncryptSkFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||||
{
|
{
|
||||||
let size: usize = k.div_ceil(basek);
|
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)
|
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<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn encrypt_pk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEEncryptPkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + SvpPPolAllocBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
let size: usize = k.div_ceil(basek);
|
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))
|
((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<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -84,7 +96,19 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -119,7 +143,19 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
let cols: usize = self.rank() + 1;
|
let cols: usize = self.rank() + 1;
|
||||||
@@ -149,8 +185,13 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptPkFamily<B>,
|
Module<B>: SvpPrepare<B>
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeSvpPPol<B> + TakeScalarZnx,
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddNormal<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: TakeSvpPPol<B> + TakeScalarZnx + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
self.encrypt_pk_internal::<DataPt, DataPk, B>(
|
self.encrypt_pk_internal::<DataPt, DataPk, B>(
|
||||||
module,
|
module,
|
||||||
@@ -172,8 +213,13 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptPkFamily<B>,
|
Module<B>: SvpPrepare<B>
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeSvpPPol<B> + TakeScalarZnx,
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddNormal<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: TakeSvpPPol<B> + TakeScalarZnx + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
self.encrypt_pk_internal::<Vec<u8>, DataPk, B>(
|
self.encrypt_pk_internal::<Vec<u8>, DataPk, B>(
|
||||||
module,
|
module,
|
||||||
@@ -196,15 +242,13 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: VecZnxDftAllocBytes
|
Module<B>: SvpPrepare<B>
|
||||||
+ SvpPPolAllocBytes
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpApply<B>
|
+ SvpApply<B>
|
||||||
+ VecZnxDftToVecZnxBigConsume<B>
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
+ VecZnxBigAddNormal<B>
|
+ VecZnxBigAddNormal<B>
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
+ VecZnxBigNormalize<B>,
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeSvpPPol<B> + TakeScalarZnx,
|
Scratch<B>: TakeSvpPPol<B> + TakeScalarZnx + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -289,7 +333,19 @@ pub(crate) fn glwe_encrypt_sk_internal<DataCt: DataMut, DataPt: DataRef, DataSk:
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, ScratchOwned},
|
||||||
oep::{ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxDftImpl, TakeVecZnxImpl},
|
oep::{ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxDftImpl, TakeVecZnxImpl},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GLWECiphertext, GLWEPublicKey, Infos, prepared::GLWESecretPrepared};
|
||||||
dist::Distribution,
|
|
||||||
layouts::{GLWECiphertext, GLWEPublicKey, Infos, prepared::GLWESecretPrepared},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::trait_families::GLWEEncryptSkFamily;
|
|
||||||
|
|
||||||
impl<D: DataMut> GLWEPublicKey<D> {
|
impl<D: DataMut> GLWEPublicKey<D> {
|
||||||
pub fn generate_from_sk<S: DataRef, B: Backend>(
|
pub fn generate_from_sk<S: DataRef, B: Backend>(
|
||||||
@@ -21,7 +20,20 @@ impl<D: DataMut> GLWEPublicKey<D> {
|
|||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>,
|
Module<B>:,
|
||||||
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
B: ScratchOwnedAllocImpl<B>
|
B: ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ TakeVecZnxDftImpl<B>
|
+ TakeVecZnxDftImpl<B>
|
||||||
@@ -30,6 +42,8 @@ impl<D: DataMut> GLWEPublicKey<D> {
|
|||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
use crate::Distribution;
|
||||||
|
|
||||||
assert_eq!(self.n(), sk.n());
|
assert_eq!(self.n(), sk.n());
|
||||||
|
|
||||||
match sk.dist {
|
match sk.dist {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphismInplace,
|
ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft,
|
||||||
VecZnxSwithcDegree, ZnxView, ZnxViewMut, ZnxZero,
|
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize,
|
||||||
|
VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize,
|
||||||
|
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, ZnxView, ZnxViewMut,
|
||||||
|
ZnxZero,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
@@ -12,12 +15,10 @@ use crate::{
|
|||||||
layouts::{GGLWESwitchingKey, GLWESecret, GLWEToLWESwitchingKey, LWESecret, prepared::GLWESecretPrepared},
|
layouts::{GGLWESwitchingKey, GLWESecret, GLWEToLWESwitchingKey, LWESecret, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl GLWEToLWESwitchingKey<Vec<u8>> {
|
impl GLWEToLWESwitchingKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_in: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_in: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWESecretPrepared::bytes_of(module, n, rank_in)
|
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))
|
+ (GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_in, 1) | GLWESecret::bytes_of(n, rank_in))
|
||||||
@@ -37,12 +38,25 @@ impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
|||||||
) where
|
) where
|
||||||
DLwe: DataRef,
|
DLwe: DataRef,
|
||||||
DGlwe: DataRef,
|
DGlwe: DataRef,
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B>
|
Module<B>: VecZnxAutomorphismInplace
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VecZnxSwithcDegree
|
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxDftAllocBytes
|
||||||
Scratch<B>: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft<B> + TakeGLWESecretPrepared<B> + TakeVecZnx,
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpPPolAllocBytes,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphismInplace,
|
ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft,
|
||||||
VecZnxSwithcDegree, ZnxView, ZnxViewMut,
|
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize,
|
||||||
|
VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize,
|
||||||
|
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, ZnxView, ZnxViewMut,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
@@ -12,12 +14,10 @@ use crate::{
|
|||||||
layouts::{GGLWESwitchingKey, GLWESecret, Infos, LWESecret, LWESwitchingKey, prepared::GLWESecretPrepared},
|
layouts::{GGLWESwitchingKey, GLWESecret, Infos, LWESecret, LWESwitchingKey, prepared::GLWESecretPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl LWESwitchingKey<Vec<u8>> {
|
impl LWESwitchingKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWESecret::bytes_of(n, 1)
|
GLWESecret::bytes_of(n, 1)
|
||||||
+ GLWESecretPrepared::bytes_of(module, n, 1)
|
+ GLWESecretPrepared::bytes_of(module, n, 1)
|
||||||
@@ -38,12 +38,25 @@ impl<D: DataMut> LWESwitchingKey<D> {
|
|||||||
) where
|
) where
|
||||||
DIn: DataRef,
|
DIn: DataRef,
|
||||||
DOut: DataRef,
|
DOut: DataRef,
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B>
|
Module<B>: VecZnxAutomorphismInplace
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VecZnxSwithcDegree
|
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxDftAllocBytes
|
||||||
Scratch<B>: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft<B> + TakeGLWESecretPrepared<B> + TakeVecZnx,
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpPPolAllocBytes,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxAutomorphismInplace,
|
ScratchAvailable, SvpApplyInplace, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft,
|
||||||
VecZnxSwithcDegree, ZnxView, ZnxViewMut,
|
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize,
|
||||||
|
VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize,
|
||||||
|
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, ZnxView, ZnxViewMut,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
@@ -12,12 +14,10 @@ use crate::{
|
|||||||
layouts::{GGLWESwitchingKey, GLWESecret, LWESecret, LWEToGLWESwitchingKey},
|
layouts::{GGLWESwitchingKey, GLWESecret, LWESecret, LWEToGLWESwitchingKey},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
impl LWEToGLWESwitchingKey<Vec<u8>> {
|
impl LWEToGLWESwitchingKey<Vec<u8>> {
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_out: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_out: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, 1, rank_out) + GLWESecret::bytes_of(n, 1)
|
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, 1, rank_out) + GLWESecret::bytes_of(n, 1)
|
||||||
}
|
}
|
||||||
@@ -36,12 +36,25 @@ impl<D: DataMut> LWEToGLWESwitchingKey<D> {
|
|||||||
) where
|
) where
|
||||||
DLwe: DataRef,
|
DLwe: DataRef,
|
||||||
DGlwe: DataRef,
|
DGlwe: DataRef,
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B>
|
Module<B>: VecZnxAutomorphismInplace
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VecZnxSwithcDegree
|
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VecZnxDftAllocBytes
|
||||||
Scratch<B>: ScratchAvailable + TakeScalarZnx + TakeVecZnxDft<B> + TakeGLWESecretPrepared<B> + TakeVecZnx,
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpPPolAllocBytes,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{ScratchAvailable, TakeVecZnxDft},
|
api::{
|
||||||
|
ScratchAvailable, TakeVecZnxDft, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx,
|
||||||
|
VecZnxDftToVecZnxBigConsume, VecZnxNormalizeTmpBytes, VmpApply, VmpApplyAdd, VmpApplyTmpBytes,
|
||||||
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, prepared::GGSWCiphertextPrepared};
|
||||||
layouts::{GGLWEAutomorphismKey, GGLWESwitchingKey, prepared::GGSWCiphertextPrepared},
|
|
||||||
trait_families::GLWEExternalProductFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GGLWEAutomorphismKey<Vec<u8>> {
|
impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||||
pub fn external_product_scratch_space<B: Backend>(
|
pub fn external_product_scratch_space<B: Backend>(
|
||||||
@@ -20,7 +20,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWESwitchingKey::external_product_scratch_space(module, n, basek, k_out, k_in, ggsw_k, digits, rank)
|
GGLWESwitchingKey::external_product_scratch_space(module, n, basek, k_out, k_in, ggsw_k, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWESwitchingKey::external_product_inplace_scratch_space(module, n, basek, k_out, ggsw_k, digits, rank)
|
GGLWESwitchingKey::external_product_inplace_scratch_space(module, n, basek, k_out, ggsw_k, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,14 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
self.key.external_product(module, &lhs.key, rhs, scratch);
|
self.key.external_product(module, &lhs.key, rhs, scratch);
|
||||||
@@ -61,7 +68,14 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
self.key.external_product_inplace(module, rhs, scratch);
|
self.key.external_product_inplace(module, rhs, scratch);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GGLWESwitchingKey, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared};
|
||||||
layouts::{GGLWESwitchingKey, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared},
|
|
||||||
trait_families::GLWEExternalProductFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GGLWESwitchingKey<Vec<u8>> {
|
impl GGLWESwitchingKey<Vec<u8>> {
|
||||||
pub fn external_product_scratch_space<B: Backend>(
|
pub fn external_product_scratch_space<B: Backend>(
|
||||||
@@ -20,7 +20,7 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank)
|
GLWECiphertext::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::external_product_inplace_scratch_space(module, n, basek, k_out, k_ggsw, digits, rank)
|
GLWECiphertext::external_product_inplace_scratch_space(module, n, basek, k_out, k_ggsw, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,14 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -97,7 +104,14 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared};
|
||||||
layouts::{GGSWCiphertext, GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared},
|
|
||||||
trait_families::GLWEExternalProductFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GGSWCiphertext<Vec<u8>> {
|
impl GGSWCiphertext<Vec<u8>> {
|
||||||
pub fn external_product_scratch_space<B: Backend>(
|
pub fn external_product_scratch_space<B: Backend>(
|
||||||
@@ -20,7 +20,7 @@ impl GGSWCiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank)
|
GLWECiphertext::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ impl GGSWCiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::external_product_inplace_scratch_space(module, n, basek, k_out, k_ggsw, digits, rank)
|
GLWECiphertext::external_product_inplace_scratch_space(module, n, basek, k_out, k_ggsw, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,15 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -108,7 +115,14 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ use backend::hal::{
|
|||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared};
|
||||||
layouts::{GLWECiphertext, Infos, prepared::GGSWCiphertextPrepared},
|
|
||||||
trait_families::GLWEExternalProductFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn external_product_scratch_space<B: Backend>(
|
pub fn external_product_scratch_space<B: Backend>(
|
||||||
@@ -23,7 +20,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
let in_size: usize = k_in.div_ceil(basek).div_ceil(digits);
|
let in_size: usize = k_in.div_ceil(basek).div_ceil(digits);
|
||||||
let out_size: usize = k_out.div_ceil(basek);
|
let out_size: usize = k_out.div_ceil(basek);
|
||||||
@@ -53,7 +50,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
Self::external_product_scratch_space(module, n, basek, k_out, k_out, k_ggsw, digits, rank)
|
Self::external_product_scratch_space(module, n, basek, k_out, k_out, k_ggsw, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -67,7 +64,14 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
let basek: usize = self.basek();
|
let basek: usize = self.basek();
|
||||||
@@ -144,7 +148,14 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
rhs: &GGSWCiphertextPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEExternalProductFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -10,8 +16,6 @@ use crate::{
|
|||||||
layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared},
|
layouts::{GLWECiphertext, Infos, prepared::GGLWEAutomorphismKeyPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GLWEKeyswitchFamily, GLWEPackingFamily};
|
|
||||||
|
|
||||||
/// [GLWEPacker] enables only the fly GLWE packing
|
/// [GLWEPacker] enables only the fly GLWE packing
|
||||||
/// with constant memory of Log(N) ciphertexts.
|
/// with constant memory of Log(N) ciphertexts.
|
||||||
/// Main difference with usual GLWE packing is that
|
/// Main difference with usual GLWE packing is that
|
||||||
@@ -93,7 +97,7 @@ impl GLWEPacker {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
pack_core_scratch_space(module, n, basek, ct_k, k_ksk, digits, rank)
|
pack_core_scratch_space(module, n, basek, ct_k, k_ksk, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -118,7 +122,27 @@ impl GLWEPacker {
|
|||||||
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEPackingFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxRotateInplace
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
assert!(
|
assert!(
|
||||||
@@ -164,7 +188,7 @@ fn pack_core_scratch_space<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
combine_scratch_space(module, n, basek, ct_k, k_ksk, digits, rank)
|
combine_scratch_space(module, n, basek, ct_k, k_ksk, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -177,7 +201,27 @@ fn pack_core<D: DataRef, DataAK: DataRef, B: Backend>(
|
|||||||
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEPackingFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxRotateInplace
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
let log_n: usize = module.log_n();
|
let log_n: usize = module.log_n();
|
||||||
@@ -239,7 +283,7 @@ fn combine_scratch_space<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::bytes_of(n, basek, ct_k, rank)
|
GLWECiphertext::bytes_of(n, basek, ct_k, rank)
|
||||||
+ (GLWECiphertext::rsh_scratch_space(n)
|
+ (GLWECiphertext::rsh_scratch_space(n)
|
||||||
@@ -255,7 +299,27 @@ fn combine<D: DataRef, DataAK: DataRef, B: Backend>(
|
|||||||
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEPackingFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxRotateInplace
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
let n: usize = acc.data.n();
|
let n: usize = acc.data.n();
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
use std::collections::HashMap;
|
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::{
|
use crate::{
|
||||||
layouts::{GLWECiphertext, prepared::GGLWEAutomorphismKeyPrepared},
|
layouts::{GLWECiphertext, prepared::GGLWEAutomorphismKeyPrepared},
|
||||||
operations::GLWEOperations,
|
operations::GLWEOperations,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GLWETraceModuleFamily, GLWETraceScratchFamily};
|
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn trace_galois_elements<B: Backend>(module: &Module<B>) -> Vec<i64> {
|
pub fn trace_galois_elements<B: Backend>(module: &Module<B>) -> Vec<i64> {
|
||||||
let mut gal_els: Vec<i64> = Vec::new();
|
let mut gal_els: Vec<i64> = Vec::new();
|
||||||
@@ -33,7 +38,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWETraceModuleFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
Self::automorphism_inplace_scratch_space(module, n, basek, out_k.min(in_k), ksk_k, digits, rank)
|
Self::automorphism_inplace_scratch_space(module, n, basek, out_k.min(in_k), ksk_k, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -48,7 +53,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWETraceModuleFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
Self::automorphism_inplace_scratch_space(module, n, basek, out_k, ksk_k, digits, rank)
|
Self::automorphism_inplace_scratch_space(module, n, basek, out_k, ksk_k, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -64,8 +69,19 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWETraceModuleFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: GLWETraceScratchFamily<B>,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxCopy,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
self.copy(module, lhs);
|
self.copy(module, lhs);
|
||||||
self.trace_inplace(module, start, end, auto_keys, scratch);
|
self.trace_inplace(module, start, end, auto_keys, scratch);
|
||||||
@@ -79,8 +95,18 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<DataAK, B>>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWETraceModuleFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: GLWETraceScratchFamily<B>,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace,
|
||||||
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
(start..end).for_each(|i| {
|
(start..end).for_each(|i| {
|
||||||
self.rsh(module, 1);
|
self.rsh(module, 1);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{
|
|
||||||
GGLWEAutomorphismKey, GGLWESwitchingKey, GLWECiphertext, Infos,
|
GGLWEAutomorphismKey, GGLWESwitchingKey, GLWECiphertext, Infos,
|
||||||
prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared},
|
prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared},
|
||||||
},
|
|
||||||
trait_families::GLWEKeyswitchFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl GGLWEAutomorphismKey<Vec<u8>> {
|
impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||||
@@ -23,7 +23,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWESwitchingKey::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank)
|
GGLWESwitchingKey::keyswitch_scratch_space(module, n, basek, k_out, k_in, k_ksk, digits, rank, rank)
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGLWESwitchingKey::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank)
|
GGLWESwitchingKey::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,15 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
|||||||
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
self.key.keyswitch(module, &lhs.key, rhs, scratch);
|
self.key.keyswitch(module, &lhs.key, rhs, scratch);
|
||||||
@@ -64,7 +72,15 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
|||||||
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
rhs: &GGLWEAutomorphismKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
self.key.keyswitch_inplace(module, &rhs.key, scratch);
|
self.key.keyswitch_inplace(module, &rhs.key, scratch);
|
||||||
@@ -84,7 +100,7 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::keyswitch_scratch_space(
|
GLWECiphertext::keyswitch_scratch_space(
|
||||||
module, n, basek, k_out, k_in, k_ksk, digits, rank_in, rank_out,
|
module, n, basek, k_out, k_in, k_ksk, digits, rank_in, rank_out,
|
||||||
@@ -101,7 +117,7 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GLWECiphertext::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank)
|
GLWECiphertext::keyswitch_inplace_scratch_space(module, n, basek, k_out, k_ksk, digits, rank)
|
||||||
}
|
}
|
||||||
@@ -115,8 +131,16 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
|||||||
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -163,8 +187,16 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
|||||||
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigAllocBytes, VecZnxCopy, VecZnxDftAddInplace,
|
ScratchAvailable, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigNormalize,
|
||||||
VecZnxDftCopy, VecZnxDftToVecZnxBigTmpA, VecZnxNormalizeTmpBytes, ZnxInfos,
|
VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAddInplace, VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx,
|
||||||
|
VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxNormalizeTmpBytes, VmpApply, VmpApplyAdd, VmpApplyTmpBytes,
|
||||||
|
ZnxInfos,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, VmpPMat},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, VmpPMat},
|
||||||
};
|
};
|
||||||
@@ -12,7 +14,6 @@ use crate::{
|
|||||||
prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared},
|
prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared},
|
||||||
},
|
},
|
||||||
operations::GLWEOperations,
|
operations::GLWEOperations,
|
||||||
trait_families::{GGSWKeySwitchFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl GGSWCiphertext<Vec<u8>> {
|
impl GGSWCiphertext<Vec<u8>> {
|
||||||
@@ -26,7 +27,7 @@ impl GGSWCiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
let tsk_size: usize = k_tsk.div_ceil(basek);
|
let tsk_size: usize = k_tsk.div_ceil(basek);
|
||||||
let self_size_out: usize = self_k.div_ceil(basek);
|
let self_size_out: usize = self_k.div_ceil(basek);
|
||||||
@@ -61,7 +62,8 @@ impl GGSWCiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>:
|
||||||
|
VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
let out_size: usize = k_out.div_ceil(basek);
|
let out_size: usize = k_out.div_ceil(basek);
|
||||||
let res_znx: usize = VecZnx::alloc_bytes(n, rank + 1, out_size);
|
let res_znx: usize = VecZnx::alloc_bytes(n, rank + 1, out_size);
|
||||||
@@ -84,7 +86,8 @@ impl GGSWCiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>:
|
||||||
|
VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
GGSWCiphertext::keyswitch_scratch_space(
|
GGSWCiphertext::keyswitch_scratch_space(
|
||||||
module, n, basek, k_out, k_out, k_ksk, digits_ksk, k_tsk, digits_tsk, rank,
|
module, n, basek, k_out, k_out, k_ksk, digits_ksk, k_tsk, digits_tsk, rank,
|
||||||
@@ -102,8 +105,19 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
) where
|
) where
|
||||||
DataA: DataRef,
|
DataA: DataRef,
|
||||||
DataTsk: DataRef,
|
DataTsk: DataRef,
|
||||||
Module<B>: GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes + VecZnxCopy,
|
Module<B>: VecZnxCopy
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B> + ScratchAvailable + TakeVecZnx,
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -127,8 +141,22 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
tsk: &GGLWETensorKeyPrepared<DataTsk, B>,
|
tsk: &GGLWETensorKeyPrepared<DataTsk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
self.keyswitch_internal(module, lhs, ksk, scratch);
|
self.keyswitch_internal(module, lhs, ksk, scratch);
|
||||||
self.expand_row(module, tsk, scratch);
|
self.expand_row(module, tsk, scratch);
|
||||||
@@ -141,8 +169,22 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
tsk: &GGLWETensorKeyPrepared<DataTsk, B>,
|
tsk: &GGLWETensorKeyPrepared<DataTsk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let self_ptr: *mut GGSWCiphertext<DataSelf> = self as *mut GGSWCiphertext<DataSelf>;
|
let self_ptr: *mut GGSWCiphertext<DataSelf> = self as *mut GGSWCiphertext<DataSelf>;
|
||||||
@@ -156,8 +198,18 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
tsk: &GGLWETensorKeyPrepared<DataTsk, B>,
|
tsk: &GGLWETensorKeyPrepared<DataTsk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B> + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
assert!(
|
assert!(
|
||||||
scratch.available()
|
scratch.available()
|
||||||
@@ -281,8 +333,16 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
|||||||
ksk: &GGLWESwitchingKeyPrepared<DataKsk, B>,
|
ksk: &GGLWESwitchingKeyPrepared<DataKsk, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B> + GGSWKeySwitchFamily<B> + VecZnxNormalizeTmpBytes,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + TakeVecZnxBig<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
// Keyswitch the j-th row of the col 0
|
// Keyswitch the j-th row of the col 0
|
||||||
(0..lhs.rows()).for_each(|row_i| {
|
(0..lhs.rows()).for_each(|row_i| {
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ use backend::hal::{
|
|||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, VecZnxBig, VecZnxDft, VmpPMat},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, VecZnxBig, VecZnxDft, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GLWECiphertext, Infos, prepared::GGLWESwitchingKeyPrepared};
|
||||||
layouts::{GLWECiphertext, Infos, prepared::GGLWESwitchingKeyPrepared},
|
|
||||||
trait_families::GLWEKeyswitchFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn keyswitch_scratch_space<B: Backend>(
|
pub fn keyswitch_scratch_space<B: Backend>(
|
||||||
@@ -24,7 +21,7 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
let in_size: usize = k_in.div_ceil(basek).div_ceil(digits);
|
let in_size: usize = k_in.div_ceil(basek).div_ceil(digits);
|
||||||
let out_size: usize = k_out.div_ceil(basek);
|
let out_size: usize = k_out.div_ceil(basek);
|
||||||
@@ -54,13 +51,14 @@ impl GLWECiphertext<Vec<u8>> {
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
Self::keyswitch_scratch_space(module, n, basek, k_out, k_out, k_ksk, digits, rank, rank)
|
Self::keyswitch_scratch_space(module, n, basek, k_out, k_out, k_ksk, digits, rank, rank)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DataSelf: DataRef> GLWECiphertext<DataSelf> {
|
impl<DataSelf: DataRef> GLWECiphertext<DataSelf> {
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) fn assert_keyswitch<B: Backend, DataLhs, DataRhs>(
|
pub(crate) fn assert_keyswitch<B: Backend, DataLhs, DataRhs>(
|
||||||
&self,
|
&self,
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
@@ -70,7 +68,7 @@ impl<DataSelf: DataRef> GLWECiphertext<DataSelf> {
|
|||||||
) where
|
) where
|
||||||
DataLhs: DataRef,
|
DataLhs: DataRef,
|
||||||
DataRhs: DataRef,
|
DataRhs: DataRef,
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes + VmpApplyTmpBytes + VecZnxBigNormalizeTmpBytes,
|
||||||
Scratch<B>: ScratchAvailable,
|
Scratch<B>: ScratchAvailable,
|
||||||
{
|
{
|
||||||
let basek: usize = self.basek();
|
let basek: usize = self.basek();
|
||||||
@@ -139,8 +137,17 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
@@ -159,8 +166,17 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
|||||||
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
rhs: &GGLWESwitchingKeyPrepared<DataRhs, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable,
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
|
Scratch<B>: ScratchAvailable + TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let self_ptr: *mut GLWECiphertext<DataSelf> = self as *mut GLWECiphertext<DataSelf>;
|
let self_ptr: *mut GLWECiphertext<DataSelf> = self as *mut GLWECiphertext<DataSelf>;
|
||||||
@@ -180,7 +196,16 @@ impl<D: DataRef> GLWECiphertext<D> {
|
|||||||
where
|
where
|
||||||
DataRes: DataMut,
|
DataRes: DataMut,
|
||||||
DataKey: DataRef,
|
DataKey: DataRef,
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B>,
|
Scratch<B>: TakeVecZnxDft<B>,
|
||||||
{
|
{
|
||||||
if rhs.digits() == 1 {
|
if rhs.digits() == 1 {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -8,8 +12,6 @@ use crate::{
|
|||||||
layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::LWESwitchingKeyPrepared},
|
layouts::{GLWECiphertext, Infos, LWECiphertext, prepared::LWESwitchingKeyPrepared},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::GLWEKeyswitchFamily;
|
|
||||||
|
|
||||||
impl LWECiphertext<Vec<u8>> {
|
impl LWECiphertext<Vec<u8>> {
|
||||||
pub fn keyswitch_scratch_space<B: Backend>(
|
pub fn keyswitch_scratch_space<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
@@ -20,7 +22,16 @@ impl LWECiphertext<Vec<u8>> {
|
|||||||
k_ksk: usize,
|
k_ksk: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
{
|
{
|
||||||
GLWECiphertext::bytes_of(n, basek, k_lwe_out.max(k_lwe_in), 1)
|
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)
|
+ GLWECiphertext::keyswitch_inplace_scratch_space(module, n, basek, k_lwe_out, k_ksk, 1, 1)
|
||||||
@@ -37,7 +48,15 @@ impl<DLwe: DataMut> LWECiphertext<DLwe> {
|
|||||||
) where
|
) where
|
||||||
A: DataRef,
|
A: DataRef,
|
||||||
DKs: DataRef,
|
DKs: DataRef,
|
||||||
Module<B>: GLWEKeyswitchFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ use backend::hal::{
|
|||||||
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
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 byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::trait_families::Decompress;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct GGLWEAutomorphismKeyCompressed<D: Data> {
|
pub struct GGLWEAutomorphismKeyCompressed<D: Data> {
|
||||||
pub(crate) key: GGLWESwitchingKeyCompressed<D>,
|
pub(crate) key: GGLWESwitchingKeyCompressed<D>,
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ use backend::hal::{
|
|||||||
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
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 byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::trait_families::Decompress;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct GGLWECiphertextCompressed<D: Data> {
|
pub struct GGLWECiphertextCompressed<D: Data> {
|
||||||
pub(crate) data: MatZnx<D>,
|
pub(crate) data: MatZnx<D>,
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ use backend::hal::{
|
|||||||
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{GGLWESwitchingKey, Infos, compressed::GGLWECiphertextCompressed},
|
GGLWESwitchingKey, Infos,
|
||||||
trait_families::Decompress,
|
compressed::{Decompress, GGLWECiphertextCompressed},
|
||||||
};
|
};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ use backend::hal::{
|
|||||||
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
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 byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::trait_families::Decompress;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct GGLWETensorKeyCompressed<D: Data> {
|
pub struct GGLWETensorKeyCompressed<D: Data> {
|
||||||
pub(crate) keys: Vec<GGLWESwitchingKeyCompressed<D>>,
|
pub(crate) keys: Vec<GGLWESwitchingKeyCompressed<D>>,
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ use backend::hal::{
|
|||||||
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{GGSWCiphertext, Infos, compressed::GLWECiphertextCompressed},
|
GGSWCiphertext, Infos,
|
||||||
trait_families::Decompress,
|
compressed::{Decompress, GLWECiphertextCompressed},
|
||||||
};
|
};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{FillUniform, Reset, VecZnxCopy, VecZnxFillUniform, ZnxInfos},
|
api::{FillUniform, Reset, VecZnxCopy, VecZnxFillUniform},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, ReaderFrom, VecZnx, WriterTo},
|
layouts::{Backend, Data, DataMut, DataRef, Module, ReaderFrom, VecZnx, WriterTo},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GLWECiphertext, Infos, compressed::Decompress};
|
||||||
layouts::{GLWECiphertext, Infos},
|
|
||||||
trait_families::{Decompress, DecompressFamily},
|
|
||||||
};
|
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
@@ -117,10 +114,12 @@ impl<D: DataRef> WriterTo for GLWECiphertextCompressed<D> {
|
|||||||
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D> {
|
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D> {
|
||||||
fn decompress(&mut self, module: &Module<B>, other: &GLWECiphertextCompressed<DR>)
|
fn decompress(&mut self, module: &Module<B>, other: &GLWECiphertextCompressed<DR>)
|
||||||
where
|
where
|
||||||
Module<B>: DecompressFamily<B>,
|
Module<B>: VecZnxCopy + VecZnxFillUniform,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
use backend::hal::api::ZnxInfos;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
self.n(),
|
self.n(),
|
||||||
other.data.n(),
|
other.data.n(),
|
||||||
@@ -142,10 +141,11 @@ impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed
|
|||||||
self.rank(),
|
self.rank(),
|
||||||
other.rank()
|
other.rank()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let mut source: Source = Source::new(other.seed);
|
let mut source: Source = Source::new(other.seed);
|
||||||
self.decompress_internal(module, other, &mut source);
|
self.decompress_internal(module, other, &mut source);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: DataMut> GLWECiphertext<D> {
|
impl<D: DataMut> GLWECiphertext<D> {
|
||||||
@@ -156,7 +156,7 @@ impl<D: DataMut> GLWECiphertext<D> {
|
|||||||
source: &mut Source,
|
source: &mut Source,
|
||||||
) where
|
) where
|
||||||
DataOther: DataRef,
|
DataOther: DataRef,
|
||||||
Module<B>: DecompressFamily<B>,
|
Module<B>: VecZnxCopy + VecZnxFillUniform,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ use std::fmt;
|
|||||||
|
|
||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{FillUniform, Reset},
|
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},
|
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::layouts::{GLWEToLWESwitchingKey, Infos, compressed::GGLWESwitchingKeyCompressed};
|
use crate::layouts::{GLWEToLWESwitchingKey, Infos, compressed::GGLWESwitchingKeyCompressed};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct GLWEToLWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWESwitchingKeyCompressed<D>);
|
pub struct GLWEToLWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWESwitchingKeyCompressed<D>);
|
||||||
|
|
||||||
@@ -91,7 +94,22 @@ impl GLWEToLWESwitchingKeyCompressed<Vec<u8>> {
|
|||||||
|
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_in: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_in: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>,
|
||||||
{
|
{
|
||||||
GLWEToLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_in)
|
GLWEToLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_in)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ use backend::hal::{
|
|||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{Infos, LWECiphertext, SetMetaData, compressed::Decompress};
|
||||||
layouts::{Infos, LWECiphertext, SetMetaData},
|
|
||||||
trait_families::Decompress,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct LWECiphertextCompressed<D: Data> {
|
pub struct LWECiphertextCompressed<D: Data> {
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
use backend::hal::{
|
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},
|
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 std::fmt;
|
||||||
|
|
||||||
use crate::trait_families::{Decompress, GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct LWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWESwitchingKeyCompressed<D>);
|
pub struct LWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWESwitchingKeyCompressed<D>);
|
||||||
|
|
||||||
@@ -90,7 +95,22 @@ impl LWESwitchingKeyCompressed<Vec<u8>> {
|
|||||||
|
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>,
|
||||||
{
|
{
|
||||||
LWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k)
|
LWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k)
|
||||||
}
|
}
|
||||||
@@ -99,7 +119,7 @@ impl LWESwitchingKeyCompressed<Vec<u8>> {
|
|||||||
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWESwitchingKeyCompressed<DR>> for LWESwitchingKey<D> {
|
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWESwitchingKeyCompressed<DR>> for LWESwitchingKey<D> {
|
||||||
fn decompress(&mut self, module: &Module<B>, other: &LWESwitchingKeyCompressed<DR>)
|
fn decompress(&mut self, module: &Module<B>, other: &LWESwitchingKeyCompressed<DR>)
|
||||||
where
|
where
|
||||||
Module<B>: crate::trait_families::DecompressFamily<B>,
|
Module<B>: VecZnxCopy + VecZnxFillUniform,
|
||||||
{
|
{
|
||||||
self.0.decompress(module, &other.0);
|
self.0.decompress(module, &other.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{FillUniform, Reset},
|
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},
|
layouts::{Backend, Data, DataMut, DataRef, MatZnx, Module, ReaderFrom, WriterTo},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{Infos, LWEToGLWESwitchingKey, compressed::GGLWESwitchingKeyCompressed},
|
Infos, LWEToGLWESwitchingKey,
|
||||||
trait_families::Decompress,
|
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||||
};
|
};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
pub struct LWEToGLWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWESwitchingKeyCompressed<D>);
|
pub struct LWEToGLWESwitchingKeyCompressed<D: Data>(pub(crate) GGLWESwitchingKeyCompressed<D>);
|
||||||
|
|
||||||
@@ -93,7 +96,22 @@ impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
|
|||||||
|
|
||||||
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_out: usize) -> usize
|
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_out: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B> + GLWESecretPreparedModuleFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>,
|
||||||
{
|
{
|
||||||
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_out)
|
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_out)
|
||||||
}
|
}
|
||||||
@@ -102,7 +120,7 @@ impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
|
|||||||
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWEToGLWESwitchingKeyCompressed<DR>> for LWEToGLWESwitchingKey<D> {
|
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWEToGLWESwitchingKeyCompressed<DR>> for LWEToGLWESwitchingKey<D> {
|
||||||
fn decompress(&mut self, module: &Module<B>, other: &LWEToGLWESwitchingKeyCompressed<DR>)
|
fn decompress(&mut self, module: &Module<B>, other: &LWEToGLWESwitchingKeyCompressed<DR>)
|
||||||
where
|
where
|
||||||
Module<B>: crate::trait_families::DecompressFamily<B>,
|
Module<B>: VecZnxCopy + VecZnxFillUniform,
|
||||||
{
|
{
|
||||||
self.0.decompress(module, &other.0);
|
self.0.decompress(module, &other.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,3 +19,14 @@ pub use glwe_to_lwe_ksk::*;
|
|||||||
pub use lwe_ct::*;
|
pub use lwe_ct::*;
|
||||||
pub use lwe_ksk::*;
|
pub use lwe_ksk::*;
|
||||||
pub use lwe_to_glwe_ksk::*;
|
pub use lwe_to_glwe_ksk::*;
|
||||||
|
|
||||||
|
use backend::hal::{
|
||||||
|
api::{VecZnxCopy, VecZnxFillUniform},
|
||||||
|
layouts::{Backend, Module},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub trait Decompress<B: Backend, C> {
|
||||||
|
fn decompress(&mut self, module: &Module<B>, other: &C)
|
||||||
|
where
|
||||||
|
Module<B>: VecZnxFillUniform + VecZnxCopy;
|
||||||
|
}
|
||||||
|
|||||||
@@ -87,3 +87,9 @@ impl<D: DataMut> LWEPlaintextToMut for LWEPlaintext<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: DataMut> LWEPlaintext<D> {
|
||||||
|
pub fn data_mut(&mut self) -> &mut VecZnx<D> {
|
||||||
|
&mut self.data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ impl<D: Data, B: Backend> GGLWEAutomorphismKeyPrepared<D, B> {
|
|||||||
|
|
||||||
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWEAutomorphismKey<DR>> for GGLWEAutomorphismKeyPrepared<D, B>
|
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWEAutomorphismKey<DR>> for GGLWEAutomorphismKeyPrepared<D, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &GGLWEAutomorphismKey<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &GGLWEAutomorphismKey<DR>, scratch: &mut Scratch<B>) {
|
||||||
self.key.prepare(module, &other.key, scratch);
|
self.key.prepare(module, &other.key, scratch);
|
||||||
@@ -83,7 +83,7 @@ where
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> for GGLWEAutomorphismKey<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>> for GGLWEAutomorphismKey<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
||||||
let mut atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = GGLWEAutomorphismKeyPrepared::alloc(
|
let mut atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = GGLWEAutomorphismKeyPrepared::alloc(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ impl<D: Data, B: Backend> GGLWECiphertextPrepared<D, B> {
|
|||||||
|
|
||||||
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWECiphertext<DR>> for GGLWECiphertextPrepared<D, B>
|
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWECiphertext<DR>> for GGLWECiphertextPrepared<D, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &GGLWECiphertext<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &GGLWECiphertext<DR>, scratch: &mut Scratch<B>) {
|
||||||
module.vmp_prepare(&mut self.data, &other.data, scratch);
|
module.vmp_prepare(&mut self.data, &other.data, scratch);
|
||||||
@@ -135,7 +135,7 @@ where
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWECiphertextPrepared<Vec<u8>, B>> for GGLWECiphertext<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWECiphertextPrepared<Vec<u8>, B>> for GGLWECiphertext<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWECiphertextPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWECiphertextPrepared<Vec<u8>, B> {
|
||||||
let mut atk_prepared: GGLWECiphertextPrepared<Vec<u8>, B> = GGLWECiphertextPrepared::alloc(
|
let mut atk_prepared: GGLWECiphertextPrepared<Vec<u8>, B> = GGLWECiphertextPrepared::alloc(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ impl<D: Data, B: Backend> GGLWESwitchingKeyPrepared<D, B> {
|
|||||||
|
|
||||||
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWESwitchingKey<DR>> for GGLWESwitchingKeyPrepared<D, B>
|
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWESwitchingKey<DR>> for GGLWESwitchingKeyPrepared<D, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &GGLWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &GGLWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
||||||
self.key.prepare(module, &other.key, scratch);
|
self.key.prepare(module, &other.key, scratch);
|
||||||
@@ -108,7 +108,7 @@ where
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWESwitchingKeyPrepared<Vec<u8>, B>> for GGLWESwitchingKey<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWESwitchingKeyPrepared<Vec<u8>, B>> for GGLWESwitchingKey<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||||
let mut atk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = GGLWESwitchingKeyPrepared::alloc(
|
let mut atk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, B> = GGLWESwitchingKeyPrepared::alloc(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ impl<D: DataRef, B: Backend> GGLWETensorKeyPrepared<D, B> {
|
|||||||
|
|
||||||
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWETensorKey<DR>> for GGLWETensorKeyPrepared<D, B>
|
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGLWETensorKey<DR>> for GGLWETensorKeyPrepared<D, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &GGLWETensorKey<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &GGLWETensorKey<DR>, scratch: &mut Scratch<B>) {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -113,7 +113,7 @@ where
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWETensorKeyPrepared<Vec<u8>, B>> for GGLWETensorKey<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGLWETensorKeyPrepared<Vec<u8>, B>> for GGLWETensorKey<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWETensorKeyPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGLWETensorKeyPrepared<Vec<u8>, B> {
|
||||||
let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = GGLWETensorKeyPrepared::alloc(
|
let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> = GGLWETensorKeyPrepared::alloc(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ impl<D: DataRef, B: Backend> GGSWCiphertextPrepared<D, B> {
|
|||||||
|
|
||||||
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGSWCiphertext<DR>> for GGSWCiphertextPrepared<D, B>
|
impl<D: DataMut, DR: DataRef, B: Backend> Prepare<B, GGSWCiphertext<DR>> for GGSWCiphertextPrepared<D, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &GGSWCiphertext<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &GGSWCiphertext<DR>, scratch: &mut Scratch<B>) {
|
||||||
module.vmp_prepare(&mut self.data, &other.data, scratch);
|
module.vmp_prepare(&mut self.data, &other.data, scratch);
|
||||||
@@ -117,7 +117,7 @@ where
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGSWCiphertextPrepared<Vec<u8>, B>> for GGSWCiphertext<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, GGSWCiphertextPrepared<Vec<u8>, B>> for GGSWCiphertext<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGSWCiphertextPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GGSWCiphertextPrepared<Vec<u8>, B> {
|
||||||
let mut ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = GGSWCiphertextPrepared::alloc(
|
let mut ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, B> = GGSWCiphertextPrepared::alloc(
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use crate::{
|
|||||||
GLWESecret,
|
GLWESecret,
|
||||||
prepared::{Prepare, PrepareAlloc},
|
prepared::{Prepare, PrepareAlloc},
|
||||||
},
|
},
|
||||||
trait_families::GLWESecretPreparedModuleFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct GLWESecretPrepared<D: Data, B: Backend> {
|
pub struct GLWESecretPrepared<D: Data, B: Backend> {
|
||||||
@@ -20,7 +19,7 @@ pub struct GLWESecretPrepared<D: Data, B: Backend> {
|
|||||||
impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
|
impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
|
||||||
pub fn alloc(module: &Module<B>, n: usize, rank: usize) -> Self
|
pub fn alloc(module: &Module<B>, n: usize, rank: usize) -> Self
|
||||||
where
|
where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>,
|
Module<B>: SvpPPolAlloc<B>,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
data: module.svp_ppol_alloc(n, rank),
|
data: module.svp_ppol_alloc(n, rank),
|
||||||
@@ -30,7 +29,7 @@ impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
|
|||||||
|
|
||||||
pub fn bytes_of(module: &Module<B>, n: usize, rank: usize) -> usize
|
pub fn bytes_of(module: &Module<B>, n: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>,
|
Module<B>: SvpPPolAllocBytes,
|
||||||
{
|
{
|
||||||
module.svp_ppol_alloc_bytes(n, rank)
|
module.svp_ppol_alloc_bytes(n, rank)
|
||||||
}
|
}
|
||||||
@@ -52,7 +51,7 @@ impl<D: Data, B: Backend> GLWESecretPrepared<D, B> {
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWESecretPrepared<Vec<u8>, B>> for GLWESecret<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWESecretPrepared<Vec<u8>, B>> for GLWESecret<D>
|
||||||
where
|
where
|
||||||
Module<B>: SvpPrepare<B> + SvpPPolAllocBytes + SvpPPolAlloc<B>,
|
Module<B>: SvpPrepare<B> + SvpPPolAlloc<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(
|
fn prepare_alloc(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWEToLWESwitchingKeyPrepared<Vec<u8>, B>> for GLWEToLWESwitchingKey<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWEToLWESwitchingKeyPrepared<Vec<u8>, B>> for GLWEToLWESwitchingKey<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B> + VmpPMatAlloc<B>,
|
Module<B>: VmpPrepare<B> + VmpPMatAlloc<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||||
let mut ksk_prepared: GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> = GLWEToLWESwitchingKeyPrepared::alloc(
|
let mut ksk_prepared: GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> = GLWEToLWESwitchingKeyPrepared::alloc(
|
||||||
@@ -83,7 +83,7 @@ where
|
|||||||
|
|
||||||
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, GLWEToLWESwitchingKey<DR>> for GLWEToLWESwitchingKeyPrepared<DM, B>
|
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, GLWEToLWESwitchingKey<DR>> for GLWEToLWESwitchingKeyPrepared<DM, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &GLWEToLWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &GLWEToLWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
||||||
self.0.prepare(module, &other.0, scratch);
|
self.0.prepare(module, &other.0, scratch);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, LWESwitchingKeyPrepared<Vec<u8>, B>> for LWESwitchingKey<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, LWESwitchingKeyPrepared<Vec<u8>, B>> for LWESwitchingKey<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B> + VmpPMatAlloc<B>,
|
Module<B>: VmpPrepare<B> + VmpPMatAlloc<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||||
let mut ksk_prepared: LWESwitchingKeyPrepared<Vec<u8>, B> = LWESwitchingKeyPrepared::alloc(
|
let mut ksk_prepared: LWESwitchingKeyPrepared<Vec<u8>, B> = LWESwitchingKeyPrepared::alloc(
|
||||||
@@ -82,7 +82,7 @@ where
|
|||||||
|
|
||||||
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, LWESwitchingKey<DR>> for LWESwitchingKeyPrepared<DM, B>
|
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, LWESwitchingKey<DR>> for LWESwitchingKeyPrepared<DM, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &LWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &LWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
||||||
self.0.prepare(module, &other.0, scratch);
|
self.0.prepare(module, &other.0, scratch);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare},
|
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, LWEToGLWESwitchingKeyPrepared<Vec<u8>, B>> for LWEToGLWESwitchingKey<D>
|
impl<D: DataRef, B: Backend> PrepareAlloc<B, LWEToGLWESwitchingKeyPrepared<Vec<u8>, B>> for LWEToGLWESwitchingKey<D>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B> + VmpPMatAlloc<B>,
|
Module<B>: VmpPrepare<B> + VmpPMatAlloc<B>,
|
||||||
{
|
{
|
||||||
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
fn prepare_alloc(&self, module: &Module<B>, scratch: &mut Scratch<B>) -> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||||
let mut ksk_prepared: LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> = LWEToGLWESwitchingKeyPrepared::alloc(
|
let mut ksk_prepared: LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> = LWEToGLWESwitchingKeyPrepared::alloc(
|
||||||
@@ -84,7 +84,7 @@ where
|
|||||||
|
|
||||||
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, LWEToGLWESwitchingKey<DR>> for LWEToGLWESwitchingKeyPrepared<DM, B>
|
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, LWEToGLWESwitchingKey<DR>> for LWEToGLWESwitchingKeyPrepared<DM, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatPrepare<B>,
|
Module<B>: VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &LWEToGLWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &LWEToGLWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
||||||
self.0.prepare(module, &other.0, scratch);
|
self.0.prepare(module, &other.0, scratch);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![feature(trait_alias)]
|
|
||||||
mod automorphism;
|
mod automorphism;
|
||||||
mod conversion;
|
mod conversion;
|
||||||
mod decryption;
|
mod decryption;
|
||||||
@@ -15,7 +14,6 @@ mod utils;
|
|||||||
|
|
||||||
pub use operations::*;
|
pub use operations::*;
|
||||||
pub mod layouts;
|
pub mod layouts;
|
||||||
pub mod trait_families;
|
|
||||||
pub use dist::*;
|
pub use dist::*;
|
||||||
pub use glwe_packing::*;
|
pub use glwe_packing::*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned},
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared};
|
||||||
layouts::{GGLWECiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared},
|
|
||||||
trait_families::GLWEDecryptFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl<D: DataRef> GGLWECiphertext<D> {
|
impl<D: DataRef> GGLWECiphertext<D> {
|
||||||
pub fn assert_noise<B: Backend, DataSk, DataWant>(
|
pub fn assert_noise<B: Backend, DataSk, DataWant>(
|
||||||
@@ -19,7 +20,16 @@ impl<D: DataRef> GGLWECiphertext<D> {
|
|||||||
) where
|
) where
|
||||||
DataSk: DataRef,
|
DataSk: DataRef,
|
||||||
DataWant: DataRef,
|
DataWant: DataRef,
|
||||||
Module<B>: GLWEDecryptFamily<B> + VecZnxSubScalarInplace,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSubScalarInplace,
|
||||||
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||||
{
|
{
|
||||||
let digits: usize = self.digits();
|
let digits: usize = self.digits();
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxBigAlloc, VecZnxBigNormalize, VecZnxDftAlloc,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, VecZnxAddScalarInplace, VecZnxBigAddInplace,
|
||||||
VecZnxDftToVecZnxBigTmpA, VecZnxNormalizeTmpBytes, VecZnxSubABInplace, ZnxZero,
|
VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes,
|
||||||
|
VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA,
|
||||||
|
VecZnxNormalizeTmpBytes, VecZnxSubABInplace, ZnxZero,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned, VecZnxBig, VecZnxDft},
|
layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned, VecZnxBig, VecZnxDft},
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{GGSWCiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared};
|
||||||
layouts::{GGSWCiphertext, GLWECiphertext, GLWEPlaintext, Infos, prepared::GLWESecretPrepared},
|
|
||||||
trait_families::GGSWAssertNoiseFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl<D: DataRef> GGSWCiphertext<D> {
|
impl<D: DataRef> GGSWCiphertext<D> {
|
||||||
pub fn assert_noise<B: Backend, DataSk, DataScalar, F>(
|
pub fn assert_noise<B: Backend, DataSk, DataScalar, F>(
|
||||||
@@ -22,7 +21,21 @@ impl<D: DataRef> GGSWCiphertext<D> {
|
|||||||
) where
|
) where
|
||||||
DataSk: DataRef,
|
DataSk: DataRef,
|
||||||
DataScalar: DataRef,
|
DataScalar: DataRef,
|
||||||
Module<B>: GGSWAssertNoiseFamily<B> + VecZnxAddScalarInplace + VecZnxSubABInplace,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxSubABInplace,
|
||||||
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||||
F: Fn(usize) -> f64,
|
F: Fn(usize) -> f64,
|
||||||
{
|
{
|
||||||
@@ -76,7 +89,21 @@ impl<D: DataRef> GGSWCiphertext<D> {
|
|||||||
) where
|
) where
|
||||||
DataSk: DataRef,
|
DataSk: DataRef,
|
||||||
DataScalar: DataRef,
|
DataScalar: DataRef,
|
||||||
Module<B>: GGSWAssertNoiseFamily<B> + VecZnxAddScalarInplace + VecZnxSubABInplace,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxSubABInplace,
|
||||||
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||||
{
|
{
|
||||||
let basek: usize = self.basek();
|
let basek: usize = self.basek();
|
||||||
@@ -110,7 +137,7 @@ impl<D: DataRef> GGSWCiphertext<D> {
|
|||||||
module.vec_znx_sub_ab_inplace(&mut pt_have.data, 0, &pt.data, 0);
|
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();
|
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();
|
pt.data.zero();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, DataRef, Module, ScratchOwned},
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl},
|
||||||
};
|
};
|
||||||
@@ -8,7 +12,6 @@ use crate::{
|
|||||||
layouts::GLWEPlaintext,
|
layouts::GLWEPlaintext,
|
||||||
layouts::prepared::GLWESecretPrepared,
|
layouts::prepared::GLWESecretPrepared,
|
||||||
layouts::{GLWECiphertext, Infos},
|
layouts::{GLWECiphertext, Infos},
|
||||||
trait_families::GLWEDecryptFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<D: DataRef> GLWECiphertext<D> {
|
impl<D: DataRef> GLWECiphertext<D> {
|
||||||
@@ -21,7 +24,17 @@ impl<D: DataRef> GLWECiphertext<D> {
|
|||||||
) where
|
) where
|
||||||
DataSk: DataRef,
|
DataSk: DataRef,
|
||||||
DataPt: DataRef,
|
DataPt: DataRef,
|
||||||
Module<B>: GLWEDecryptFamily<B> + VecZnxSubABInplace + VecZnxNormalizeInplace<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>,
|
||||||
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
B: TakeVecZnxDftImpl<B> + TakeVecZnxBigImpl<B> + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||||
{
|
{
|
||||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), self.basek(), self.k());
|
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(self.n(), self.basek(), self.k());
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ pub trait TakeLike<'a, B: Backend, T> {
|
|||||||
fn take_like(&'a mut self, template: &T) -> (Self::Output, &'a mut Self);
|
fn take_like(&'a mut self, template: &T) -> (Self::Output, &'a mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeGLWECt<B: Backend> {
|
pub trait TakeGLWECt {
|
||||||
fn take_glwe_ct(&mut self, n: usize, basek: usize, k: usize, rank: usize) -> (GLWECiphertext<&mut [u8]>, &mut Self);
|
fn take_glwe_ct(&mut self, n: usize, basek: usize, k: usize, rank: usize) -> (GLWECiphertext<&mut [u8]>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeGLWECtSlice<B: Backend> {
|
pub trait TakeGLWECtSlice {
|
||||||
fn take_glwe_ct_slice(
|
fn take_glwe_ct_slice(
|
||||||
&mut self,
|
&mut self,
|
||||||
size: usize,
|
size: usize,
|
||||||
@@ -40,7 +40,7 @@ pub trait TakeGLWEPt<B: Backend> {
|
|||||||
fn take_glwe_pt(&mut self, n: usize, basek: usize, k: usize) -> (GLWEPlaintext<&mut [u8]>, &mut Self);
|
fn take_glwe_pt(&mut self, n: usize, basek: usize, k: usize) -> (GLWEPlaintext<&mut [u8]>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeGGLWE<B: Backend> {
|
pub trait TakeGGLWE {
|
||||||
fn take_gglwe(
|
fn take_gglwe(
|
||||||
&mut self,
|
&mut self,
|
||||||
n: usize,
|
n: usize,
|
||||||
@@ -66,7 +66,7 @@ pub trait TakeGGLWEPrepared<B: Backend> {
|
|||||||
) -> (GGLWECiphertextPrepared<&mut [u8], B>, &mut Self);
|
) -> (GGLWECiphertextPrepared<&mut [u8], B>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeGGSW<B: Backend> {
|
pub trait TakeGGSW {
|
||||||
fn take_ggsw(
|
fn take_ggsw(
|
||||||
&mut self,
|
&mut self,
|
||||||
n: usize,
|
n: usize,
|
||||||
@@ -90,7 +90,7 @@ pub trait TakeGGSWPrepared<B: Backend> {
|
|||||||
) -> (GGSWCiphertextPrepared<&mut [u8], B>, &mut Self);
|
) -> (GGSWCiphertextPrepared<&mut [u8], B>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeGLWESecret<B: Backend> {
|
pub trait TakeGLWESecret {
|
||||||
fn take_glwe_secret(&mut self, n: usize, rank: usize) -> (GLWESecret<&mut [u8]>, &mut Self);
|
fn take_glwe_secret(&mut self, n: usize, rank: usize) -> (GLWESecret<&mut [u8]>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ pub trait TakeGLWESecretPrepared<B: Backend> {
|
|||||||
fn take_glwe_secret_prepared(&mut self, n: usize, rank: usize) -> (GLWESecretPrepared<&mut [u8], B>, &mut Self);
|
fn take_glwe_secret_prepared(&mut self, n: usize, rank: usize) -> (GLWESecretPrepared<&mut [u8], B>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeGLWEPk<B: Backend> {
|
pub trait TakeGLWEPk {
|
||||||
fn take_glwe_pk(&mut self, n: usize, basek: usize, k: usize, rank: usize) -> (GLWEPublicKey<&mut [u8]>, &mut Self);
|
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<B: Backend> {
|
|||||||
) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self);
|
) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeGLWESwitchingKey<B: Backend> {
|
pub trait TakeGLWESwitchingKey {
|
||||||
fn take_glwe_switching_key(
|
fn take_glwe_switching_key(
|
||||||
&mut self,
|
&mut self,
|
||||||
n: usize,
|
n: usize,
|
||||||
@@ -138,7 +138,7 @@ pub trait TakeGLWESwitchingKeyPrepared<B: Backend> {
|
|||||||
) -> (GGLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self);
|
) -> (GGLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeTensorKey<B: Backend> {
|
pub trait TakeTensorKey {
|
||||||
fn take_tensor_key(
|
fn take_tensor_key(
|
||||||
&mut self,
|
&mut self,
|
||||||
n: usize,
|
n: usize,
|
||||||
@@ -162,7 +162,7 @@ pub trait TakeTensorKeyPrepared<B: Backend> {
|
|||||||
) -> (GGLWETensorKeyPrepared<&mut [u8], B>, &mut Self);
|
) -> (GGLWETensorKeyPrepared<&mut [u8], B>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TakeAutomorphismKey<B: Backend> {
|
pub trait TakeAutomorphismKey {
|
||||||
fn take_automorphism_key(
|
fn take_automorphism_key(
|
||||||
&mut self,
|
&mut self,
|
||||||
n: usize,
|
n: usize,
|
||||||
@@ -186,7 +186,7 @@ pub trait TakeAutomorphismKeyPrepared<B: Backend> {
|
|||||||
) -> (GGLWEAutomorphismKeyPrepared<&mut [u8], B>, &mut Self);
|
) -> (GGLWEAutomorphismKeyPrepared<&mut [u8], B>, &mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeGLWECt<B> for Scratch<B>
|
impl<B: Backend> TakeGLWECt for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeVecZnx,
|
Scratch<B>: TakeVecZnx,
|
||||||
{
|
{
|
||||||
@@ -216,7 +216,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeGLWECtSlice<B> for Scratch<B>
|
impl<B: Backend> TakeGLWECtSlice for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeVecZnx,
|
Scratch<B>: TakeVecZnx,
|
||||||
{
|
{
|
||||||
@@ -269,7 +269,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeGGLWE<B> for Scratch<B>
|
impl<B: Backend> TakeGGLWE for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeMatZnx,
|
Scratch<B>: TakeMatZnx,
|
||||||
{
|
{
|
||||||
@@ -391,7 +391,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeGGSW<B> for Scratch<B>
|
impl<B: Backend> TakeGGSW for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeMatZnx,
|
Scratch<B>: TakeMatZnx,
|
||||||
{
|
{
|
||||||
@@ -511,7 +511,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeGLWEPk<B> for Scratch<B>
|
impl<B: Backend> TakeGLWEPk for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeVecZnx,
|
Scratch<B>: TakeVecZnx,
|
||||||
{
|
{
|
||||||
@@ -595,7 +595,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeGLWESecret<B> for Scratch<B>
|
impl<B: Backend> TakeGLWESecret for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeScalarZnx,
|
Scratch<B>: TakeScalarZnx,
|
||||||
{
|
{
|
||||||
@@ -665,7 +665,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeGLWESwitchingKey<B> for Scratch<B>
|
impl<B: Backend> TakeGLWESwitchingKey for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeMatZnx,
|
Scratch<B>: TakeMatZnx,
|
||||||
{
|
{
|
||||||
@@ -759,7 +759,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeAutomorphismKey<B> for Scratch<B>
|
impl<B: Backend> TakeAutomorphismKey for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeMatZnx,
|
Scratch<B>: TakeMatZnx,
|
||||||
{
|
{
|
||||||
@@ -823,7 +823,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: Backend> TakeTensorKey<B> for Scratch<B>
|
impl<B: Backend> TakeTensorKey for Scratch<B>
|
||||||
where
|
where
|
||||||
Scratch<B>: TakeMatZnx,
|
Scratch<B>: TakeMatZnx,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxCopy,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -17,11 +21,8 @@ use crate::{
|
|||||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::log2_std_noise_gglwe_product,
|
noise::log2_std_noise_gglwe_product,
|
||||||
trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_gglwe_automorphism_key_automorphism<B: Backend>(
|
pub fn test_gglwe_automorphism_key_automorphism<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
p0: i64,
|
p0: i64,
|
||||||
@@ -34,19 +35,36 @@ pub fn test_gglwe_automorphism_key_automorphism<B: Backend>(
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
rank: usize,
|
rank: usize,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ VecZnxAutomorphism
|
+ VmpApply<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VmpApplyAdd<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ GLWEDecryptFamily<B>
|
+ SvpPPolAllocBytes
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxDftAllocBytes
|
||||||
+ VecZnxCopy
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxSubScalarInplace,
|
||||||
B: ScratchOwnedAllocImpl<B>
|
B: ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
@@ -179,19 +197,50 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B: Backend>(
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
rank: usize,
|
rank: usize,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxSubScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>,
|
||||||
B: ScratchOwnedAllocImpl<B>
|
B: ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxCopy,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare,
|
||||||
VecZnxSubABInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScalarZnx, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -17,11 +22,6 @@ use crate::{
|
|||||||
prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_keyswitch,
|
noise::noise_ggsw_keyswitch,
|
||||||
trait_families::GGSWAssertNoiseFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::trait_families::{
|
|
||||||
GGLWESwitchingKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWKeySwitchFamily, GLWESecretPreparedModuleFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_ggsw_automorphism<B: Backend>(
|
pub fn test_ggsw_automorphism<B: Backend>(
|
||||||
@@ -36,23 +36,44 @@ pub fn test_ggsw_automorphism<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGSWAssertNoiseFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GGSWKeySwitchFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApply<B>
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpApply<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VecZnxAutomorphism,
|
+ VecZnxAutomorphism,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
@@ -171,23 +192,45 @@ pub fn test_ggsw_automorphism_inplace<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGSWAssertNoiseFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GGSWKeySwitchFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApply<B>
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ SvpApply<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VecZnxAutomorphism,
|
+ VecZnxAutomorphism,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VecZnxFillUniform, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -17,11 +21,8 @@ use crate::{
|
|||||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::log2_std_noise_gglwe_product,
|
noise::log2_std_noise_gglwe_product,
|
||||||
trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_glwe_automorphism<B: Backend>(
|
pub fn test_glwe_automorphism<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
basek: usize,
|
basek: usize,
|
||||||
@@ -33,16 +34,35 @@ pub fn test_glwe_automorphism<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -140,16 +160,35 @@ pub fn test_glwe_automorphism_inplace<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxSwithcDegree,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatAlloc, VmpPMatPrepare, ZnxView,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -17,27 +21,44 @@ use crate::layouts::{
|
|||||||
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc},
|
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GLWEDecryptFamily, GLWEKeyswitchFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_lwe_to_glwe<B: Backend>(module: &Module<B>)
|
pub fn test_lwe_to_glwe<B: Backend>(module: &Module<B>)
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GLWEKeyswitchFamily<B>
|
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VmpApplyTmpBytes
|
||||||
B: TakeScalarZnxImpl<B>
|
+ VmpApply<B>
|
||||||
+ TakeVecZnxDftImpl<B>
|
+ VmpApplyAdd<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ TakeVecZnxImpl<B>
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>,
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
|
+ ScratchAvailableImpl<B>
|
||||||
|
+ TakeScalarZnxImpl<B>
|
||||||
|
+ TakeVecZnxImpl<B>,
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let basek: usize = 17;
|
let basek: usize = 17;
|
||||||
@@ -112,23 +133,42 @@ where
|
|||||||
|
|
||||||
pub fn test_glwe_to_lwe<B: Backend>(module: &Module<B>)
|
pub fn test_glwe_to_lwe<B: Backend>(module: &Module<B>)
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GLWEKeyswitchFamily<B>
|
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VmpApplyTmpBytes
|
||||||
B: TakeScalarZnxImpl<B>
|
+ VmpApply<B>
|
||||||
+ TakeVecZnxDftImpl<B>
|
+ VmpApplyAdd<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ TakeVecZnxImpl<B>
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>,
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
|
+ ScratchAvailableImpl<B>
|
||||||
|
+ TakeScalarZnxImpl<B>
|
||||||
|
+ TakeVecZnxImpl<B>,
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let basek: usize = 17;
|
let basek: usize = 17;
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxCopy,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -11,17 +15,12 @@ use backend::hal::{
|
|||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{
|
|
||||||
GGLWEAutomorphismKey, GLWESecret,
|
GGLWEAutomorphismKey, GLWESecret,
|
||||||
compressed::GGLWEAutomorphismKeyCompressed,
|
compressed::{Decompress, GGLWEAutomorphismKeyCompressed},
|
||||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
|
||||||
trait_families::{Decompress, GLWEDecryptFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEAutomorphismKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_gglwe_automorphisk_key_encrypt_sk<B: Backend>(
|
pub fn test_gglwe_automorphisk_key_encrypt_sk<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
basek: usize,
|
basek: usize,
|
||||||
@@ -30,19 +29,37 @@ pub fn test_gglwe_automorphisk_key_encrypt_sk<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxAutomorphism
|
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxSubScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>,
|
||||||
B: ScratchOwnedAllocImpl<B>
|
B: ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
@@ -105,19 +122,37 @@ pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEAutomorphismKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxAutomorphism
|
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxSubScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>,
|
||||||
B: ScratchOwnedAllocImpl<B>
|
B: ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubScalarInplace, VecZnxSwithcDegree,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatAlloc, VmpPMatPrepare,
|
VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes,
|
||||||
|
VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform,
|
||||||
|
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, VecZnxSubScalarInplace,
|
||||||
|
VecZnxSwithcDegree, VmpPMatAlloc, VmpPrepare,
|
||||||
},
|
},
|
||||||
layouts::{Backend, Module, ScratchOwned},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -11,17 +14,12 @@ use backend::hal::{
|
|||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{
|
|
||||||
GGLWESwitchingKey, GLWESecret,
|
GGLWESwitchingKey, GLWESecret,
|
||||||
compressed::GGLWESwitchingKeyCompressed,
|
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
|
||||||
trait_families::{Decompress, GLWEDecryptFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_gglwe_switching_key_encrypt_sk<B: Backend>(
|
pub fn test_gglwe_switching_key_encrypt_sk<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
basek: usize,
|
basek: usize,
|
||||||
@@ -31,18 +29,33 @@ pub fn test_gglwe_switching_key_encrypt_sk<B: Backend>(
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxSubScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
@@ -95,18 +108,33 @@ pub fn test_gglwe_switching_key_compressed_encrypt_sk<B: Backend>(
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxSubScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubABInplace, VmpPMatAlloc,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScalarZnx, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -11,27 +14,41 @@ use backend::hal::{
|
|||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{
|
|
||||||
GGSWCiphertext, GLWESecret,
|
GGSWCiphertext, GLWESecret,
|
||||||
compressed::GGSWCiphertextCompressed,
|
compressed::{Decompress, GGSWCiphertextCompressed},
|
||||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
|
||||||
trait_families::{Decompress, GGSWAssertNoiseFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGSWEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_ggsw_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64)
|
pub fn test_ggsw_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64)
|
||||||
where
|
where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -88,17 +105,35 @@ pub fn test_ggsw_compressed_encrypt_sk<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
use backend::hal::{
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
||||||
@@ -11,21 +17,49 @@ use sampling::source::Source;
|
|||||||
use crate::{
|
use crate::{
|
||||||
layouts::{
|
layouts::{
|
||||||
GLWECiphertext, GLWEPlaintext, GLWEPublicKey, GLWESecret, Infos,
|
GLWECiphertext, GLWEPlaintext, GLWEPublicKey, GLWESecret, Infos,
|
||||||
compressed::GLWECiphertextCompressed,
|
compressed::{Decompress, GLWECiphertextCompressed},
|
||||||
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
operations::GLWEOperations,
|
operations::GLWEOperations,
|
||||||
trait_families::Decompress,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GLWEDecryptFamily, GLWEEncryptPkFamily, GLWEEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub trait EncryptionTestModuleFamily<B: Backend> =
|
|
||||||
GLWEDecryptFamily<B> + GLWESecretPreparedModuleFamily<B> + GLWEEncryptPkFamily<B>;
|
|
||||||
|
|
||||||
pub fn test_glwe_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize)
|
pub fn test_glwe_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize)
|
||||||
where
|
where
|
||||||
Module<B>: EncryptionTestModuleFamily<B> + GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddNormal<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -83,7 +117,42 @@ pub fn test_glwe_compressed_encrypt_sk<B: Backend>(
|
|||||||
sigma: f64,
|
sigma: f64,
|
||||||
rank: usize,
|
rank: usize,
|
||||||
) where
|
) where
|
||||||
Module<B>: EncryptionTestModuleFamily<B> + GLWEEncryptSkFamily<B> + VecZnxCopy,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddNormal<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxCopy,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -146,7 +215,41 @@ pub fn test_glwe_compressed_encrypt_sk<B: Backend>(
|
|||||||
|
|
||||||
pub fn test_glwe_encrypt_zero_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, sigma: f64, rank: usize)
|
pub fn test_glwe_encrypt_zero_sk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, sigma: f64, rank: usize)
|
||||||
where
|
where
|
||||||
Module<B>: EncryptionTestModuleFamily<B> + GLWEEncryptSkFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddNormal<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -189,8 +292,29 @@ where
|
|||||||
|
|
||||||
pub fn test_glwe_encrypt_pk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize)
|
pub fn test_glwe_encrypt_pk<B: Backend>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize)
|
||||||
where
|
where
|
||||||
Module<B>:
|
Module<B>: VecZnxDftAllocBytes
|
||||||
EncryptionTestModuleFamily<B> + GLWEEncryptSkFamily<B> + VecZnxDftAlloc<B> + VecZnxFillUniform + VecZnxSubABInplace,
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxBigAddNormal<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxBigAlloc, VecZnxCopy, VecZnxDftAlloc,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare,
|
||||||
VecZnxSubScalarInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScratchOwned, VecZnxDft},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -11,34 +14,43 @@ use backend::hal::{
|
|||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::{
|
use crate::layouts::{
|
||||||
layouts::{
|
|
||||||
GGLWETensorKey, GLWEPlaintext, GLWESecret, Infos,
|
GGLWETensorKey, GLWEPlaintext, GLWESecret, Infos,
|
||||||
compressed::GGLWETensorKeyCompressed,
|
compressed::{Decompress, GGLWETensorKeyCompressed},
|
||||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
|
||||||
trait_families::{Decompress, GLWEDecryptFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_glwe_tensor_key_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
pub fn test_glwe_tensor_key_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxSwithcDegree
|
+ SvpApplyInplace<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VmpPMatAlloc<B>
|
+ VecZnxFillUniform
|
||||||
+ VmpPMatPrepare<B>
|
+ VecZnxSubABInplace
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VecZnxAddInplace
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
+ VecZnxDftAlloc<B>
|
+ VecZnxDftAlloc<B>
|
||||||
+ VecZnxBigAlloc<B>,
|
+ SvpApply<B>
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxSubScalarInplace,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
@@ -120,22 +132,35 @@ where
|
|||||||
|
|
||||||
pub fn test_glwe_tensor_key_compressed_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
pub fn test_glwe_tensor_key_compressed_encrypt_sk<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxSwithcDegree
|
+ SvpApplyInplace<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VmpPMatAlloc<B>
|
+ VecZnxFillUniform
|
||||||
+ VmpPMatPrepare<B>
|
+ VecZnxSubABInplace
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VecZnxAddInplace
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
+ VecZnxDftAlloc<B>
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ SvpApply<B>
|
||||||
+ VecZnxBigAlloc<B>
|
+ VecZnxBigAlloc<B>
|
||||||
+ VecZnxCopy,
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxSubScalarInplace,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxRotateInplace, VecZnxSubScalarInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, ZnxViewMut,
|
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},
|
layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -17,11 +21,8 @@ use crate::{
|
|||||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_product,
|
noise::noise_ggsw_product,
|
||||||
trait_families::{GLWEDecryptFamily, GLWEExternalProductFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_gglwe_switching_key_external_product<B: Backend>(
|
pub fn test_gglwe_switching_key_external_product<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
basek: usize,
|
basek: usize,
|
||||||
@@ -33,22 +34,37 @@ pub fn test_gglwe_switching_key_external_product<B: Backend>(
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxSubScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VecZnxRotateInplace
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GLWEExternalProductFamily<B>
|
+ VmpApply<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
+ VecZnxRotateInplace,
|
+ VmpPrepare<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
@@ -159,22 +175,37 @@ pub fn test_gglwe_switching_key_external_product_inplace<B: Backend>(
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxSubScalarInplace
|
+ VecZnxSubScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VecZnxRotateInplace
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GLWEExternalProductFamily<B>
|
+ VmpApply<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
+ VecZnxRotateInplace,
|
+ VmpPrepare<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxRotateInplace, VecZnxSubABInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatAlloc, VmpPMatPrepare, ZnxViewMut,
|
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},
|
layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -17,12 +21,6 @@ use crate::{
|
|||||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_product,
|
noise::noise_ggsw_product,
|
||||||
trait_families::GGSWAssertNoiseFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::trait_families::{
|
|
||||||
GGLWESwitchingKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWEncryptSkFamily, GGSWKeySwitchFamily,
|
|
||||||
GLWESecretPreparedModuleFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_ggsw_external_product<B: Backend>(
|
pub fn test_ggsw_external_product<B: Backend>(
|
||||||
@@ -35,22 +33,39 @@ pub fn test_ggsw_external_product<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VecZnxRotateInplace
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GGSWKeySwitchFamily<B>
|
+ VmpApply<B>
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VmpPrepare<B>
|
||||||
+ VecZnxRotateInplace,
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
@@ -151,22 +166,39 @@ pub fn test_ggsw_external_product_inplace<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VecZnxRotateInplace
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GGSWKeySwitchFamily<B>
|
+ VmpApply<B>
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VmpPrepare<B>
|
||||||
+ VecZnxRotateInplace,
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxFillUniform, VecZnxRotateInplace, VmpPMatAlloc,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatPrepare, ZnxViewMut,
|
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},
|
layouts::{Backend, Module, ScalarZnx, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -19,8 +22,6 @@ use crate::{
|
|||||||
noise::noise_ggsw_product,
|
noise::noise_ggsw_product,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GLWEDecryptFamily, GLWEEncryptSkFamily, GLWEExternalProductFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_glwe_external_product<B: Backend>(
|
pub fn test_glwe_external_product<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
basek: usize,
|
basek: usize,
|
||||||
@@ -31,14 +32,32 @@ pub fn test_glwe_external_product<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ GLWEExternalProductFamily<B>
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxRotateInplace
|
+ VecZnxRotateInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -148,14 +167,32 @@ pub fn test_glwe_external_product_inplace<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ GLWEExternalProductFamily<B>
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxRotateInplace
|
+ VecZnxRotateInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubScalarInplace, VecZnxSwithcDegree,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
||||||
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl,
|
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
@@ -17,11 +20,8 @@ use crate::{
|
|||||||
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::log2_std_noise_gglwe_product,
|
noise::log2_std_noise_gglwe_product,
|
||||||
trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_gglwe_switching_key_keyswitch<B: Backend>(
|
pub fn test_gglwe_switching_key_keyswitch<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
basek: usize,
|
basek: usize,
|
||||||
@@ -34,18 +34,34 @@ pub fn test_gglwe_switching_key_keyswitch<B: Backend>(
|
|||||||
rank_out_s1s2: usize,
|
rank_out_s1s2: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxSwithcDegree
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxSubScalarInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GGLWEEncryptSkFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GLWEDecryptFamily<B>
|
+ VmpApply<B>
|
||||||
+ GLWEKeyswitchFamily<B>,
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxSubScalarInplace,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -53,10 +69,7 @@ pub fn test_gglwe_switching_key_keyswitch<B: Backend>(
|
|||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
+ TakeScalarZnxImpl<B>
|
+ TakeScalarZnxImpl<B>
|
||||||
+ TakeVecZnxImpl<B>
|
+ TakeVecZnxImpl<B>,
|
||||||
+ VecZnxDftAllocBytesImpl<B>
|
|
||||||
+ VecZnxBigAllocBytesImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>,
|
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let rows: usize = k_in.div_ceil(basek * digits);
|
let rows: usize = k_in.div_ceil(basek * digits);
|
||||||
@@ -171,18 +184,34 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B: Backend>(
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxSwithcDegree
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VecZnxSubScalarInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ VmpApply<B>
|
||||||
+ GLWEDecryptFamily<B>,
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxSubScalarInplace,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -190,10 +219,7 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B: Backend>(
|
|||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
+ TakeScalarZnxImpl<B>
|
+ TakeScalarZnxImpl<B>
|
||||||
+ TakeVecZnxImpl<B>
|
+ TakeVecZnxImpl<B>,
|
||||||
+ VecZnxDftAllocBytesImpl<B>
|
|
||||||
+ VecZnxBigAllocBytesImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>,
|
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let rows: usize = k_ct.div_ceil(basek * digits);
|
let rows: usize = k_ct.div_ceil(basek * digits);
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxCopy, VecZnxSubABInplace, VecZnxSwithcDegree,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare,
|
||||||
VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScalarZnx, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
||||||
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl,
|
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
@@ -17,12 +21,6 @@ use crate::{
|
|||||||
prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_keyswitch,
|
noise::noise_ggsw_keyswitch,
|
||||||
trait_families::GGSWAssertNoiseFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::trait_families::{
|
|
||||||
GGLWESwitchingKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWEncryptSkFamily, GGSWKeySwitchFamily,
|
|
||||||
GLWESecretPreparedModuleFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_ggsw_keyswitch<B: Backend>(
|
pub fn test_ggsw_keyswitch<B: Backend>(
|
||||||
@@ -36,19 +34,39 @@ pub fn test_ggsw_keyswitch<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GGSWKeySwitchFamily<B>
|
+ VmpApply<B>
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ VecZnxSwithcDegree,
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -56,13 +74,7 @@ pub fn test_ggsw_keyswitch<B: Backend>(
|
|||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
+ TakeScalarZnxImpl<B>
|
+ TakeScalarZnxImpl<B>
|
||||||
+ TakeVecZnxImpl<B>
|
+ TakeVecZnxImpl<B>,
|
||||||
+ VecZnxDftAllocBytesImpl<B>
|
|
||||||
+ VecZnxBigAllocBytesImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ VecZnxDftAllocBytesImpl<B>
|
|
||||||
+ VecZnxBigAllocBytesImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>,
|
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let rows: usize = k_in.div_ceil(digits * basek);
|
let rows: usize = k_in.div_ceil(digits * basek);
|
||||||
@@ -168,19 +180,39 @@ pub fn test_ggsw_keyswitch_inplace<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GLWESecretPreparedModuleFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VmpApplyTmpBytes
|
||||||
+ GGSWKeySwitchFamily<B>
|
+ VmpApply<B>
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
+ VmpApplyAdd<B>
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ VecZnxSwithcDegree,
|
+ VecZnxSwithcDegree
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -188,10 +220,7 @@ pub fn test_ggsw_keyswitch_inplace<B: Backend>(
|
|||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
+ TakeScalarZnxImpl<B>
|
+ TakeScalarZnxImpl<B>
|
||||||
+ TakeVecZnxImpl<B>
|
+ TakeVecZnxImpl<B>,
|
||||||
+ VecZnxDftAllocBytesImpl<B>
|
|
||||||
+ VecZnxBigAllocBytesImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>,
|
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let rows: usize = k_ct.div_ceil(digits * basek);
|
let rows: usize = k_ct.div_ceil(digits * basek);
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxFillUniform, VecZnxSwithcDegree, VmpPMatAlloc,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -17,11 +20,8 @@ use crate::{
|
|||||||
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::log2_std_noise_gglwe_product,
|
noise::log2_std_noise_gglwe_product,
|
||||||
trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_glwe_keyswitch<B: Backend>(
|
pub fn test_glwe_keyswitch<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
basek: usize,
|
basek: usize,
|
||||||
@@ -33,14 +33,33 @@ pub fn test_glwe_keyswitch<B: Backend>(
|
|||||||
rank_out: usize,
|
rank_out: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ SvpApplyInplace<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
@@ -137,14 +156,33 @@ pub fn test_glwe_keyswitch_inplace<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
sigma: f64,
|
sigma: f64,
|
||||||
) where
|
) where
|
||||||
Module<B>: GGLWESwitchingKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ GLWEKeyswitchFamily<B>
|
+ VecZnxDftFromVecZnx<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ SvpApplyInplace<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree,
|
||||||
B: TakeVecZnxDftImpl<B>
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxSwithcDegree,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VmpPMatAlloc, VmpPMatPrepare, ZnxView,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -16,27 +20,44 @@ use crate::layouts::{
|
|||||||
prepared::{LWESwitchingKeyPrepared, PrepareAlloc},
|
prepared::{LWESwitchingKeyPrepared, PrepareAlloc},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWEEncryptSkFamily, GLWEDecryptFamily, GLWEKeyswitchFamily, GLWESecretPreparedModuleFamily};
|
|
||||||
|
|
||||||
pub fn test_lwe_keyswitch<B: Backend>(module: &Module<B>)
|
pub fn test_lwe_keyswitch<B: Backend>(module: &Module<B>)
|
||||||
where
|
where
|
||||||
Module<B>: GGLWEEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWEDecryptFamily<B>
|
+ VecZnxBigNormalize<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GLWEKeyswitchFamily<B>
|
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ GLWESecretPreparedModuleFamily<B>,
|
+ VmpApplyTmpBytes
|
||||||
B: TakeScalarZnxImpl<B>
|
+ VmpApply<B>
|
||||||
+ TakeVecZnxDftImpl<B>
|
+ VmpApplyAdd<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ TakeVecZnxImpl<B>
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxAutomorphismInplace,
|
||||||
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>,
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
|
+ ScratchAvailableImpl<B>
|
||||||
|
+ TakeScalarZnxImpl<B>
|
||||||
|
+ TakeVecZnxImpl<B>,
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let basek: usize = 17;
|
let basek: usize = 17;
|
||||||
|
|||||||
@@ -2,8 +2,13 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigSubSmallBInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VecZnxRotateInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -19,37 +24,54 @@ use crate::{
|
|||||||
GGLWEAutomorphismKey, GLWECiphertext, GLWEPlaintext, GLWESecret,
|
GGLWEAutomorphismKey, GLWECiphertext, GLWEPlaintext, GLWESecret,
|
||||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily, GLWEPackingFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
pub fn test_glwe_packing<B: Backend>(module: &Module<B>)
|
||||||
|
where
|
||||||
pub trait PackingTestModuleFamily<B: Backend> = GLWEPackingFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
|
||||||
+ GGLWESwitchingKeyEncryptSkFamily<B>
|
|
||||||
+ GLWEKeyswitchFamily<B>
|
|
||||||
+ GLWEDecryptFamily<B>
|
|
||||||
+ VecZnxSwithcDegree
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxRotateInplace
|
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
+ VecZnxBigSubSmallBInplace<B>
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxRotateInplace
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>;
|
+ VmpPrepare<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
pub trait PackingTestScratchFamily<B: Backend> = TakeVecZnxDftImpl<B>
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxCopy,
|
||||||
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
+ TakeScalarZnxImpl<B>
|
+ TakeScalarZnxImpl<B>
|
||||||
+ TakeVecZnxImpl<B>;
|
+ TakeVecZnxImpl<B>,
|
||||||
|
|
||||||
pub fn test_glwe_packing<B: Backend>(module: &Module<B>)
|
|
||||||
where
|
|
||||||
Module<B>: PackingTestModuleFamily<B>,
|
|
||||||
B: PackingTestScratchFamily<B>,
|
|
||||||
{
|
{
|
||||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigAutomorphismInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace,
|
||||||
VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxFillUniform, VecZnxNormalizeInplace, VecZnxRotateInplace, VecZnxRshInplace,
|
VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigAddInplace, VecZnxBigAddSmallInplace,
|
||||||
VecZnxSubABInplace, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, ZnxView, ZnxViewMut,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -20,39 +24,51 @@ use crate::{
|
|||||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
},
|
||||||
noise::var_noise_gglwe_product,
|
noise::var_noise_gglwe_product,
|
||||||
trait_families::{GLWEDecryptFamily, GLWEKeyswitchFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::trait_families::{GGLWESwitchingKeyEncryptSkFamily, GLWESecretPreparedModuleFamily};
|
pub fn test_glwe_trace_inplace<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
||||||
|
where
|
||||||
pub trait TraceTestModuleFamily<B: Backend> = GGLWESwitchingKeyEncryptSkFamily<B>
|
Module<B>: VecZnxDftAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
|
||||||
+ GLWEKeyswitchFamily<B>
|
|
||||||
+ GLWEDecryptFamily<B>
|
|
||||||
+ VecZnxSwithcDegree
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxRotateInplace
|
|
||||||
+ VecZnxBigSubSmallBInplace<B>
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
+ VecZnxRshInplace
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxRotateInplace
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxAddScalarInplace
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>;
|
+ VmpPrepare<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
pub trait TraceTestScratchFamily<B: Backend> = TakeVecZnxDftImpl<B>
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxCopy,
|
||||||
|
B: TakeVecZnxDftImpl<B>
|
||||||
+ TakeVecZnxBigImpl<B>
|
+ TakeVecZnxBigImpl<B>
|
||||||
+ TakeSvpPPolImpl<B>
|
+ TakeSvpPPolImpl<B>
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ ScratchAvailableImpl<B>
|
+ ScratchAvailableImpl<B>
|
||||||
+ TakeScalarZnxImpl<B>
|
+ TakeScalarZnxImpl<B>
|
||||||
+ TakeVecZnxImpl<B>;
|
+ TakeVecZnxImpl<B>,
|
||||||
|
|
||||||
pub fn test_glwe_trace_inplace<B: Backend>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
|
||||||
where
|
|
||||||
Module<B>: TraceTestModuleFamily<B>,
|
|
||||||
B: TraceTestScratchFamily<B>,
|
|
||||||
{
|
{
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let k_autokey: usize = k + basek;
|
let k_autokey: usize = k + basek;
|
||||||
|
|||||||
@@ -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<B> =
|
|
||||||
GLWEKeyswitchFamily<B> + VecZnxBigAllocBytes + VecZnxDftCopy<B> + VecZnxDftAddInplace<B> + VecZnxDftToVecZnxBigTmpA<B>;
|
|
||||||
pub trait GGLWEEncryptSkFamily<B: Backend> = GLWEEncryptSkFamily<B>;
|
|
||||||
pub trait GGLWESwitchingKeyEncryptSkFamily<B: Backend> = GGLWEEncryptSkFamily<B>;
|
|
||||||
pub trait GGLWEAutomorphismKeyEncryptSkFamily<B: Backend> = GGLWEEncryptSkFamily<B>;
|
|
||||||
pub trait GGLWETensorKeyEncryptSkFamily<B: Backend> =
|
|
||||||
GGLWEEncryptSkFamily<B> + VecZnxBigAllocBytes + VecZnxDftToVecZnxBigTmpA<B> + SvpApply<B>;
|
|
||||||
pub trait GGSWEncryptSkFamily<B: Backend> = GLWEEncryptSkFamily<B>;
|
|
||||||
pub trait GGSWAssertNoiseFamily<B: Backend> = GLWEDecryptFamily<B>
|
|
||||||
+ VecZnxBigAlloc<B>
|
|
||||||
+ VecZnxDftAlloc<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxDftToVecZnxBigTmpA<B>;
|
|
||||||
pub trait GLWEDecryptFamily<B: Backend> = VecZnxDftAllocBytes
|
|
||||||
+ VecZnxBigAllocBytes
|
|
||||||
+ VecZnxDftFromVecZnx<B>
|
|
||||||
+ SvpApplyInplace<B>
|
|
||||||
+ VecZnxDftToVecZnxBigConsume<B>
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes;
|
|
||||||
pub trait GLWEEncryptSkFamily<B: Backend> = VecZnxDftAllocBytes
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxDftFromVecZnx<B>
|
|
||||||
+ SvpApplyInplace<B>
|
|
||||||
+ VecZnxDftToVecZnxBigConsume<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxFillUniform
|
|
||||||
+ VecZnxSubABInplace
|
|
||||||
+ VecZnxAddInplace
|
|
||||||
+ VecZnxNormalizeInplace<B>
|
|
||||||
+ VecZnxAddNormal
|
|
||||||
+ VecZnxNormalize<B>
|
|
||||||
+ VecZnxSub;
|
|
||||||
pub trait GLWEEncryptPkFamily<B: Backend> = VecZnxDftAllocBytes
|
|
||||||
+ VecZnxBigAllocBytes
|
|
||||||
+ SvpPPolAllocBytes
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpApply<B>
|
|
||||||
+ VecZnxDftToVecZnxBigConsume<B>
|
|
||||||
+ VecZnxBigAddNormal<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes;
|
|
||||||
pub trait GLWEExternalProductFamily<B: Backend> = VecZnxDftAllocBytes
|
|
||||||
+ VmpApplyTmpBytes
|
|
||||||
+ VmpApply<B>
|
|
||||||
+ VmpApplyAdd<B>
|
|
||||||
+ VecZnxDftFromVecZnx<B>
|
|
||||||
+ VecZnxDftToVecZnxBigConsume<B>
|
|
||||||
+ VecZnxBigNormalize<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes;
|
|
||||||
pub trait GLWEKeyswitchFamily<B: Backend> = VecZnxDftAllocBytes
|
|
||||||
+ VmpApplyTmpBytes
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VmpApplyTmpBytes
|
|
||||||
+ VmpApply<B>
|
|
||||||
+ VmpApplyAdd<B>
|
|
||||||
+ VecZnxDftFromVecZnx<B>
|
|
||||||
+ VecZnxDftToVecZnxBigConsume<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxBigNormalize<B>;
|
|
||||||
pub trait GLWEPackingFamily<B: Backend> = GLWEKeyswitchFamily<B>
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxRotateInplace
|
|
||||||
+ VecZnxSub
|
|
||||||
+ VecZnxNegateInplace
|
|
||||||
+ VecZnxRshInplace
|
|
||||||
+ VecZnxAddInplace
|
|
||||||
+ VecZnxNormalizeInplace<B>
|
|
||||||
+ VecZnxSubABInplace
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ VecZnxAutomorphismInplace
|
|
||||||
+ VecZnxBigSubSmallBInplace<B>
|
|
||||||
+ VecZnxBigAutomorphismInplace<B>;
|
|
||||||
pub trait GLWESecretPreparedModuleFamily<B: Backend> = SvpPrepare<B> + SvpPPolAllocBytes + SvpPPolAlloc<B>;
|
|
||||||
pub trait GGLWEPreparedLayoutFamily<B: Backend> = VmpPMatAlloc<B> + VmpPMatAllocBytes + VmpPMatPrepare<B>;
|
|
||||||
pub trait GLWETraceModuleFamily<B: Backend> =
|
|
||||||
GLWEKeyswitchFamily<B> + VecZnxCopy + VecZnxRshInplace + VecZnxBigAutomorphismInplace<B>;
|
|
||||||
pub trait GLWETraceScratchFamily<B: Backend> = TakeVecZnxDft<B> + ScratchAvailable;
|
|
||||||
pub trait GGSWLayoutFamily<B: Backend> = VmpPMatAlloc<B> + VmpPMatAllocBytes + VmpPMatPrepare<B>;
|
|
||||||
|
|
||||||
pub trait DecompressFamily<B: Backend> = VecZnxFillUniform + VecZnxCopy;
|
|
||||||
pub trait Decompress<B: Backend, C> {
|
|
||||||
fn decompress(&mut self, module: &Module<B>, other: &C)
|
|
||||||
where
|
|
||||||
Module<B>: DecompressFamily<B>;
|
|
||||||
}
|
|
||||||
10
poulpy/Cargo.toml
Normal file
10
poulpy/Cargo.toml
Normal file
@@ -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"}
|
||||||
171
poulpy/README.md
Normal file
171
poulpy/README.md
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
# 🐙 Poulpy
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="poulpy.png" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[](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<B: Backend> {
|
||||||
|
fn svp_prepare<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||||
|
where
|
||||||
|
R: SvpPPolToMut<B>,
|
||||||
|
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<B> SvpPrepare<B> for Module<B>
|
||||||
|
where
|
||||||
|
B: Backend + SvpPrepareImpl<B>,
|
||||||
|
{
|
||||||
|
fn svp_prepare<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||||
|
where
|
||||||
|
R: SvpPPolToMut<B>,
|
||||||
|
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<D: Data, B: Backend> {
|
||||||
|
data: D,
|
||||||
|
n: usize,
|
||||||
|
cols: usize,
|
||||||
|
_phantom: PhantomData<B>,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **`oep`**: open extension points, which can be implemented by the user to provide a custom backend.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub unsafe trait SvpPrepareImpl<B: Backend> {
|
||||||
|
fn svp_prepare_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||||
|
where
|
||||||
|
R: SvpPPolToMut<B>,
|
||||||
|
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<Self> for FFT64 {
|
||||||
|
fn svp_prepare_impl<R, A>(module: &Module<Self>, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||||
|
where
|
||||||
|
R: SvpPPolToMut<Self>,
|
||||||
|
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<D: Data> {
|
||||||
|
pub(crate) data: ScalarZnx<D>,
|
||||||
|
pub(crate) dist: Distribution,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct GLWESecrecPrepared<D: Data, B: Backend> {
|
||||||
|
pub(crate) data: SvpPPol<D, B>,
|
||||||
|
pub(crate) dist: Distribution,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<D: DataMut, B: Backend> GLWESecretPrepared<D, B> {
|
||||||
|
pub fn prepare<O>(&mut self, module: &Module<B>, sk: &GLWESecret<O>)
|
||||||
|
where
|
||||||
|
O: DataRef,
|
||||||
|
Module<B>: SvpPrepare<B>,
|
||||||
|
{
|
||||||
|
(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}
|
||||||
|
}
|
||||||
218
poulpy/examples/circuit_bootstrapping.rs
Normal file
218
poulpy/examples/circuit_bootstrapping.rs
Normal file
@@ -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<FFT64> = Module::<FFT64>::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<FFT64> = 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<Vec<u8>> = 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<Vec<u8>> = 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<Vec<u8>, 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<Vec<u8>> = 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<Vec<u8>> = 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<Vec<u8>, 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<Vec<u8>> = 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<Vec<u8>, 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<Vec<u8>> = 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<Vec<u8>> = 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<Vec<u8>> = GLWEPlaintext::alloc(n_glwe, basek, basek);
|
||||||
|
let mut data_vec: Vec<i64> = 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<Vec<u8>, 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<Vec<u8>> = 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]);
|
||||||
|
}
|
||||||
BIN
poulpy/poulpy.png
Normal file
BIN
poulpy/poulpy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
15
poulpy/src/lib.rs
Normal file
15
poulpy/src/lib.rs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
pub mod backend {
|
||||||
|
pub use ::backend::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod core {
|
||||||
|
pub use ::core::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod sampling {
|
||||||
|
pub use ::sampling::*;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod schemes {
|
||||||
|
pub use ::schemes::*;
|
||||||
|
}
|
||||||
@@ -1,2 +1 @@
|
|||||||
#![feature(trait_alias)]
|
|
||||||
pub mod tfhe;
|
pub mod tfhe;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, SvpApply, SvpPPolAllocBytes, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice,
|
ScratchAvailable, SvpApply, SvpPPolAllocBytes, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice,
|
||||||
TakeVecZnxSlice, VecZnxAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigNormalizeTmpBytes, VecZnxCopy,
|
TakeVecZnxSlice, VecZnxAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigNormalize,
|
||||||
VecZnxDftAdd, VecZnxDftAddInplace, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftSubABInplace, VecZnxDftToVecZnxBig,
|
VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAdd, VecZnxDftAddInplace, VecZnxDftAllocBytes, VecZnxDftFromVecZnx,
|
||||||
VecZnxDftToVecZnxBigTmpBytes, VecZnxDftZero, VecZnxMulXpMinusOneInplace, VecZnxNormalize, VecZnxNormalizeInplace,
|
VecZnxDftSubABInplace, VecZnxDftToVecZnxBig, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpBytes, VecZnxDftZero,
|
||||||
VecZnxRotate, VecZnxSubABInplace, VmpApplyTmpBytes, ZnxView, ZnxZero,
|
VecZnxMulXpMinusOneInplace, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate,
|
||||||
|
VecZnxSubABInplace, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, ZnxView, ZnxZero,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch, SvpPPol, VecZnx},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch, SvpPPol, VecZnx},
|
||||||
};
|
};
|
||||||
@@ -13,36 +14,12 @@ use itertools::izip;
|
|||||||
use core::{
|
use core::{
|
||||||
Distribution, GLWEOperations, TakeGLWECt,
|
Distribution, GLWEOperations, TakeGLWECt,
|
||||||
layouts::{GLWECiphertext, GLWECiphertextToMut, Infos, LWECiphertext, LWECiphertextToRef},
|
layouts::{GLWECiphertext, GLWECiphertextToMut, Infos, LWECiphertext, LWECiphertextToRef},
|
||||||
trait_families::GLWEExternalProductFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tfhe::blind_rotation::{
|
use crate::tfhe::blind_rotation::{
|
||||||
BlincRotationExecute, BlindRotationKeyPrepared, CGGI, LookUpTable, LookUpTableRotationDirection,
|
BlincRotationExecute, BlindRotationKeyPrepared, CGGI, LookUpTable, LookUpTableRotationDirection,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait CCGIBlindRotationFamily<B: Backend> = VecZnxBigAllocBytes
|
|
||||||
+ VecZnxDftAllocBytes
|
|
||||||
+ SvpPPolAllocBytes
|
|
||||||
+ VmpApplyTmpBytes
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VecZnxDftToVecZnxBigTmpBytes
|
|
||||||
+ VecZnxDftToVecZnxBig<B>
|
|
||||||
+ VecZnxDftAdd<B>
|
|
||||||
+ VecZnxDftAddInplace<B>
|
|
||||||
+ VecZnxDftFromVecZnx<B>
|
|
||||||
+ VecZnxDftZero<B>
|
|
||||||
+ SvpApply<B>
|
|
||||||
+ VecZnxDftSubABInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ GLWEExternalProductFamily<B>
|
|
||||||
+ VecZnxRotate
|
|
||||||
+ VecZnxAddInplace
|
|
||||||
+ VecZnxSubABInplace
|
|
||||||
+ VecZnxNormalize<B>
|
|
||||||
+ VecZnxNormalizeInplace<B>
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VecZnxMulXpMinusOneInplace;
|
|
||||||
|
|
||||||
pub fn cggi_blind_rotate_scratch_space<B: Backend>(
|
pub fn cggi_blind_rotate_scratch_space<B: Backend>(
|
||||||
module: &Module<B>,
|
module: &Module<B>,
|
||||||
n: usize,
|
n: usize,
|
||||||
@@ -55,7 +32,12 @@ pub fn cggi_blind_rotate_scratch_space<B: Backend>(
|
|||||||
rank: usize,
|
rank: usize,
|
||||||
) -> usize
|
) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: CCGIBlindRotationFamily<B>,
|
Module<B>: VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes,
|
||||||
{
|
{
|
||||||
let brk_size: usize = k_brk.div_ceil(basek);
|
let brk_size: usize = k_brk.div_ceil(basek);
|
||||||
|
|
||||||
@@ -89,7 +71,32 @@ where
|
|||||||
|
|
||||||
impl<D: DataRef, B: Backend> BlincRotationExecute<B> for BlindRotationKeyPrepared<D, CGGI, B>
|
impl<D: DataRef, B: Backend> BlincRotationExecute<B> for BlindRotationKeyPrepared<D, CGGI, B>
|
||||||
where
|
where
|
||||||
Module<B>: CCGIBlindRotationFamily<B>,
|
Module<B>: VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBig<B>
|
||||||
|
+ VecZnxDftAdd<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftZero<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftSubABInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxMulXpMinusOneInplace
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes,
|
||||||
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + TakeVecZnx + ScratchAvailable,
|
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + TakeVecZnx + ScratchAvailable,
|
||||||
{
|
{
|
||||||
fn execute<DR: DataMut, DI: DataRef>(
|
fn execute<DR: DataMut, DI: DataRef>(
|
||||||
@@ -126,7 +133,29 @@ fn execute_block_binary_extended<DataRes, DataIn, DataBrk, B: Backend>(
|
|||||||
DataRes: DataMut,
|
DataRes: DataMut,
|
||||||
DataIn: DataRef,
|
DataIn: DataRef,
|
||||||
DataBrk: DataRef,
|
DataBrk: DataRef,
|
||||||
Module<B>: CCGIBlindRotationFamily<B>,
|
Module<B>: VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBig<B>
|
||||||
|
+ VecZnxDftAdd<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftZero<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftSubABInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxMulXpMinusOneInplace
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VmpApply<B>,
|
||||||
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
let n_glwe: usize = brk.n();
|
let n_glwe: usize = brk.n();
|
||||||
@@ -271,7 +300,29 @@ fn execute_block_binary<DataRes, DataIn, DataBrk, B: Backend>(
|
|||||||
DataRes: DataMut,
|
DataRes: DataMut,
|
||||||
DataIn: DataRef,
|
DataIn: DataRef,
|
||||||
DataBrk: DataRef,
|
DataBrk: DataRef,
|
||||||
Module<B>: CCGIBlindRotationFamily<B>,
|
Module<B>: VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBig<B>
|
||||||
|
+ VecZnxDftAdd<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftZero<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftSubABInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxMulXpMinusOneInplace
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VecZnxBigNormalize<B>,
|
||||||
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
let n_glwe: usize = brk.n();
|
let n_glwe: usize = brk.n();
|
||||||
@@ -363,7 +414,32 @@ fn execute_standard<DataRes, DataIn, DataBrk, B: Backend>(
|
|||||||
DataRes: DataMut,
|
DataRes: DataMut,
|
||||||
DataIn: DataRef,
|
DataIn: DataRef,
|
||||||
DataBrk: DataRef,
|
DataBrk: DataRef,
|
||||||
Module<B>: CCGIBlindRotationFamily<B>,
|
Module<B>: VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBig<B>
|
||||||
|
+ VecZnxDftAdd<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftZero<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftSubABInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxMulXpMinusOneInplace
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes,
|
||||||
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDftSlice<B> + TakeVecZnxDft<B> + TakeVecZnxBig<B> + TakeVecZnxSlice + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -454,7 +530,7 @@ pub(crate) fn mod_switch_2n(n: usize, res: &mut [i64], lwe: &LWECiphertext<&[u8]
|
|||||||
}
|
}
|
||||||
|
|
||||||
if basek > log2n {
|
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| {
|
res.iter_mut().for_each(|x| {
|
||||||
*x = div_round_by_pow2(x, diff);
|
*x = div_round_by_pow2(x, diff);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
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},
|
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch},
|
||||||
};
|
};
|
||||||
@@ -15,7 +18,6 @@ use core::{
|
|||||||
compressed::GGSWCiphertextCompressed,
|
compressed::GGSWCiphertextCompressed,
|
||||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared},
|
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
trait_families::GGSWEncryptSkFamily,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tfhe::blind_rotation::{
|
use crate::tfhe::blind_rotation::{
|
||||||
@@ -38,7 +40,7 @@ impl BlindRotationKeyAlloc for BlindRotationKey<Vec<u8>, CGGI> {
|
|||||||
impl BlindRotationKey<Vec<u8>, CGGI> {
|
impl BlindRotationKey<Vec<u8>, CGGI> {
|
||||||
pub fn generate_from_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn generate_from_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGSWEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||||
{
|
{
|
||||||
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
||||||
}
|
}
|
||||||
@@ -46,7 +48,20 @@ impl BlindRotationKey<Vec<u8>, CGGI> {
|
|||||||
|
|
||||||
impl<D: DataMut, B: Backend> BlindRotationKeyEncryptSk<B> for BlindRotationKey<D, CGGI>
|
impl<D: DataMut, B: Backend> BlindRotationKeyEncryptSk<B> for BlindRotationKey<D, CGGI>
|
||||||
where
|
where
|
||||||
Module<B>: GGSWEncryptSkFamily<B> + VecZnxAddScalarInplace,
|
Module<B>: VecZnxAddScalarInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
fn encrypt_sk<DataSkGLWE, DataSkLWE>(
|
fn encrypt_sk<DataSkGLWE, DataSkLWE>(
|
||||||
@@ -92,7 +107,7 @@ where
|
|||||||
|
|
||||||
impl<B: Backend> BlindRotationKeyPreparedAlloc<B> for BlindRotationKeyPrepared<Vec<u8>, CGGI, B>
|
impl<B: Backend> BlindRotationKeyPreparedAlloc<B> for BlindRotationKeyPrepared<Vec<u8>, CGGI, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn alloc(module: &Module<B>, n_glwe: usize, n_lwe: usize, basek: usize, k: usize, rows: usize, rank: usize) -> Self {
|
fn alloc(module: &Module<B>, n_glwe: usize, n_lwe: usize, basek: usize, k: usize, rows: usize, rank: usize) -> Self {
|
||||||
let mut data: Vec<GGSWCiphertextPrepared<Vec<u8>, B>> = Vec::with_capacity(n_lwe);
|
let mut data: Vec<GGSWCiphertextPrepared<Vec<u8>, B>> = Vec::with_capacity(n_lwe);
|
||||||
@@ -127,7 +142,7 @@ impl BlindRotationKeyCompressed<Vec<u8>, CGGI> {
|
|||||||
|
|
||||||
pub fn generate_from_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
pub fn generate_from_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank: usize) -> usize
|
||||||
where
|
where
|
||||||
Module<B>: GGSWEncryptSkFamily<B>,
|
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||||
{
|
{
|
||||||
GGSWCiphertextCompressed::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
GGSWCiphertextCompressed::encrypt_sk_scratch_space(module, n, basek, k, rank)
|
||||||
}
|
}
|
||||||
@@ -146,7 +161,20 @@ impl<D: DataMut> BlindRotationKeyCompressed<D, CGGI> {
|
|||||||
) where
|
) where
|
||||||
DataSkGLWE: DataRef,
|
DataSkGLWE: DataRef,
|
||||||
DataSkLWE: DataRef,
|
DataSkLWE: DataRef,
|
||||||
Module<B>: GGSWEncryptSkFamily<B> + VecZnxAddScalarInplace,
|
Module<B>: VecZnxAddScalarInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{SvpPPolAlloc, SvpPrepare, VmpPMatAlloc, VmpPMatPrepare},
|
api::{SvpPPolAlloc, SvpPrepare, VmpPMatAlloc, VmpPrepare},
|
||||||
layouts::{Backend, Data, DataMut, DataRef, Module, ScalarZnx, Scratch, SvpPPol},
|
layouts::{Backend, Data, DataMut, DataRef, Module, ScalarZnx, Scratch, SvpPPol},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ where
|
|||||||
impl<DM: DataMut, DR: DataRef, BRA: BlindRotationAlgo, B: Backend> Prepare<B, BlindRotationKey<DR, BRA>>
|
impl<DM: DataMut, DR: DataRef, BRA: BlindRotationAlgo, B: Backend> Prepare<B, BlindRotationKey<DR, BRA>>
|
||||||
for BlindRotationKeyPrepared<DM, BRA, B>
|
for BlindRotationKeyPrepared<DM, BRA, B>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B> + SvpPPolAlloc<B> + SvpPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B> + SvpPPolAlloc<B> + SvpPrepare<B>,
|
||||||
{
|
{
|
||||||
fn prepare(&mut self, module: &Module<B>, other: &BlindRotationKey<DR, BRA>, scratch: &mut Scratch<B>) {
|
fn prepare(&mut self, module: &Module<B>, other: &BlindRotationKey<DR, BRA>, scratch: &mut Scratch<B>) {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ impl DivRound for usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn max_bit_size(vec: &[i64]) -> u32 {
|
fn max_bit_size(vec: &[i64]) -> u32 {
|
||||||
vec.iter()
|
vec.iter()
|
||||||
.map(|&v| {
|
.map(|&v| {
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxFillUniform, VecZnxRotateInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare,
|
||||||
VecZnxSub, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare, ZnxView,
|
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},
|
layouts::{Backend, Module, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -12,23 +17,45 @@ use backend::hal::{
|
|||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use crate::tfhe::blind_rotation::{
|
use crate::tfhe::blind_rotation::{
|
||||||
BlincRotationExecute, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared,
|
BlincRotationExecute, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared, CGGI,
|
||||||
CCGIBlindRotationFamily, CGGI, LookUpTable, cggi_blind_rotate_scratch_space, mod_switch_2n,
|
LookUpTable, cggi_blind_rotate_scratch_space, mod_switch_2n,
|
||||||
};
|
};
|
||||||
|
|
||||||
use core::{
|
use core::layouts::{
|
||||||
layouts::{
|
|
||||||
GLWECiphertext, GLWEPlaintext, GLWESecret, Infos, LWECiphertext, LWECiphertextToRef, LWEPlaintext, LWESecret,
|
GLWECiphertext, GLWEPlaintext, GLWESecret, Infos, LWECiphertext, LWECiphertextToRef, LWEPlaintext, LWESecret,
|
||||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||||
},
|
|
||||||
trait_families::{GLWEDecryptFamily, GLWESecretPreparedModuleFamily},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_blind_rotation<B: Backend>(module: &Module<B>, n_lwe: usize, block_size: usize, extension_factor: usize)
|
pub fn test_blind_rotation<B: Backend>(module: &Module<B>, n_lwe: usize, block_size: usize, extension_factor: usize)
|
||||||
where
|
where
|
||||||
Module<B>: CCGIBlindRotationFamily<B>
|
Module<B>: VecZnxBigAllocBytes
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxDftAllocBytes
|
||||||
+ GLWEDecryptFamily<B>
|
+ SvpPPolAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBigTmpBytes
|
||||||
|
+ VecZnxDftToVecZnxBig<B>
|
||||||
|
+ VecZnxDftAdd<B>
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftZero<B>
|
||||||
|
+ SvpApply<B>
|
||||||
|
+ VecZnxDftSubABInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxRotate
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxMulXpMinusOneInplace
|
||||||
|
+ SvpPrepare<B>
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ VecZnxAddNormal
|
+ VecZnxAddNormal
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
@@ -36,7 +63,9 @@ where
|
|||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxSub
|
+ VecZnxSub
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>,
|
+ VmpPrepare<B>
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>,
|
||||||
B: VecZnxDftAllocBytesImpl<B>
|
B: VecZnxDftAllocBytesImpl<B>
|
||||||
+ VecZnxBigAllocBytesImpl<B>
|
+ VecZnxBigAllocBytesImpl<B>
|
||||||
+ ScratchOwnedAllocImpl<B>
|
+ ScratchOwnedAllocImpl<B>
|
||||||
@@ -57,7 +86,9 @@ where
|
|||||||
let k_res: usize = 2 * basek;
|
let k_res: usize = 2 * basek;
|
||||||
let rank: usize = 1;
|
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_xs: Source = Source::new([2u8; 32]);
|
||||||
let mut source_xe: Source = Source::new([2u8; 32]);
|
let mut source_xe: Source = Source::new([2u8; 32]);
|
||||||
@@ -103,10 +134,9 @@ where
|
|||||||
|
|
||||||
let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(basek, k_lwe);
|
let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(basek, k_lwe);
|
||||||
|
|
||||||
let x: i64 = 2;
|
let x: i64 = 15 % (message_modulus as i64);
|
||||||
let bits: usize = 8;
|
|
||||||
|
|
||||||
pt_lwe.encode_i64(x, bits);
|
pt_lwe.encode_i64(x, log_message_modulus + 1);
|
||||||
|
|
||||||
lwe.encrypt_sk(
|
lwe.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
@@ -117,13 +147,16 @@ where
|
|||||||
3.2,
|
3.2,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut f: Vec<i64> = vec![0i64; message_modulus];
|
let f = |x: i64| -> i64 { 2 * x + 1 };
|
||||||
f.iter_mut()
|
|
||||||
|
let mut f_vec: Vec<i64> = vec![0i64; message_modulus];
|
||||||
|
f_vec
|
||||||
|
.iter_mut()
|
||||||
.enumerate()
|
.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);
|
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<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_res, rank);
|
let mut res: GLWECiphertext<Vec<u8>> = 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
|
// First limb should be exactly equal (test are parameterized such that the noise does not reach
|
||||||
// the first limb)
|
// the first limb)
|
||||||
assert_eq!(pt_have.data.at(0, 0), lut.data[0].at(0, 0));
|
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,34 @@
|
|||||||
use std::{collections::HashMap, time::Instant, usize};
|
use std::{collections::HashMap, usize};
|
||||||
|
|
||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeMatZnx, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice, TakeVecZnxSlice,
|
ScratchAvailable, TakeMatZnx, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice, TakeVecZnxSlice,
|
||||||
VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAutomorphismInplace, VecZnxBigSubSmallBInplace, VecZnxCopy,
|
VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAllocBytes, VecZnxBigAutomorphismInplace,
|
||||||
VecZnxDftCopy, VecZnxDftToVecZnxBigTmpA, VecZnxNegateInplace, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes,
|
VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallBInplace, VecZnxCopy, VecZnxDftAddInplace,
|
||||||
VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree,
|
VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA,
|
||||||
|
VecZnxNegateInplace, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace,
|
||||||
|
VecZnxRshInplace, VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes,
|
||||||
},
|
},
|
||||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl},
|
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 core::layouts::{GGSWCiphertext, GLWECiphertext, LWECiphertext, prepared::GGLWEAutomorphismKeyPrepared};
|
||||||
|
|
||||||
use crate::tfhe::{
|
use crate::tfhe::{
|
||||||
blind_rotation::{
|
blind_rotation::{
|
||||||
BlincRotationExecute, BlindRotationAlgo, BlindRotationKeyPrepared, CCGIBlindRotationFamily, LookUpTable,
|
BlincRotationExecute, BlindRotationAlgo, BlindRotationKeyPrepared, LookUpTable, LookUpTableRotationDirection,
|
||||||
LookUpTableRotationDirection,
|
|
||||||
},
|
},
|
||||||
circuit_bootstrapping::{CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute},
|
circuit_bootstrapping::{CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait CircuitBootstrapFamily<B: Backend> = VecZnxRotateInplace
|
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CirtuitBootstrappingExecute<B> for CircuitBootstrappingKeyPrepared<D, BRA, B>
|
||||||
|
where
|
||||||
|
Module<B>: VecZnxRotateInplace
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ VecZnxNormalizeInplace<B>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ VecZnxNormalizeTmpBytes
|
||||||
+ CCGIBlindRotationFamily<B>
|
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ VecZnxBigAutomorphismInplace<B>
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
+ VecZnxRshInplace
|
+ VecZnxRshInplace
|
||||||
@@ -37,14 +39,20 @@ pub trait CircuitBootstrapFamily<B: Backend> = VecZnxRotateInplace
|
|||||||
+ VecZnxNegateInplace
|
+ VecZnxNegateInplace
|
||||||
+ VecZnxCopy
|
+ VecZnxCopy
|
||||||
+ VecZnxSubABInplace
|
+ VecZnxSubABInplace
|
||||||
+ GLWETraceModuleFamily<B>
|
+ VecZnxDftAllocBytes
|
||||||
+ VecZnxRotateInplace
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
+ VecZnxAutomorphismInplace
|
+ VecZnxAutomorphismInplace
|
||||||
+ VecZnxBigSubSmallBInplace<B>;
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CirtuitBootstrappingExecute<B> for CircuitBootstrappingKeyPrepared<D, BRA, B>
|
+ VecZnxDftAddInplace<B>
|
||||||
where
|
+ VecZnxRotate,
|
||||||
Module<B>: CircuitBootstrapFamily<B>,
|
|
||||||
B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||||
Scratch<B>: TakeVecZnx
|
Scratch<B>: TakeVecZnx
|
||||||
+ TakeVecZnxDftSlice<B>
|
+ TakeVecZnxDftSlice<B>
|
||||||
@@ -115,7 +123,33 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B: Backe
|
|||||||
DRes: DataMut,
|
DRes: DataMut,
|
||||||
DLwe: DataRef,
|
DLwe: DataRef,
|
||||||
DBrk: DataRef,
|
DBrk: DataRef,
|
||||||
Module<B>: CircuitBootstrapFamily<B>,
|
Module<B>: VecZnxRotateInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxRotate,
|
||||||
B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
B: ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||||
Scratch<B>: TakeVecZnxDftSlice<B>
|
Scratch<B>: TakeVecZnxDftSlice<B>
|
||||||
+ TakeVecZnxBig<B>
|
+ TakeVecZnxBig<B>
|
||||||
@@ -165,14 +199,10 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B: Backe
|
|||||||
|
|
||||||
// TODO: separate GGSW k from output of blind rotation k
|
// TODO: separate GGSW k from output of blind rotation k
|
||||||
let (mut res_glwe, scratch1) = scratch.take_glwe_ct(n, basek, k, rank);
|
let (mut res_glwe, scratch1) = scratch.take_glwe_ct(n, basek, k, rank);
|
||||||
let (mut tmp_gglwe, scratch2) = scratch1.take_gglwe(n, basek, k, rows, 1, rank, rank);
|
let (mut tmp_gglwe, scratch2) = scratch1.take_gglwe(n, basek, k, rows, 1, rank.max(1), rank);
|
||||||
|
|
||||||
let now: Instant = Instant::now();
|
|
||||||
|
|
||||||
key.brk.execute(module, &mut res_glwe, &lwe, &lut, scratch2);
|
key.brk.execute(module, &mut res_glwe, &lwe, &lut, scratch2);
|
||||||
|
|
||||||
println!("blind_rotate: {} ms", now.elapsed().as_millis());
|
|
||||||
|
|
||||||
let gap: usize = 2 * lut.drift / lut.extension_factor();
|
let gap: usize = 2 * lut.drift / lut.extension_factor();
|
||||||
|
|
||||||
let log_gap_in: usize = (usize::BITS - (gap * alpha - 1).leading_zeros()) as _;
|
let log_gap_in: usize = (usize::BITS - (gap * alpha - 1).leading_zeros()) as _;
|
||||||
@@ -181,8 +211,6 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B: Backe
|
|||||||
let mut tmp_glwe: GLWECiphertext<&mut [u8]> = tmp_gglwe.at_mut(i, 0);
|
let mut tmp_glwe: GLWECiphertext<&mut [u8]> = tmp_gglwe.at_mut(i, 0);
|
||||||
|
|
||||||
if to_exponent {
|
if to_exponent {
|
||||||
let now: Instant = Instant::now();
|
|
||||||
|
|
||||||
// Isolates i-th LUT and moves coefficients according to requested gap.
|
// Isolates i-th LUT and moves coefficients according to requested gap.
|
||||||
post_process(
|
post_process(
|
||||||
module,
|
module,
|
||||||
@@ -194,7 +222,6 @@ pub fn circuit_bootstrap_core<DRes, DLwe, DBrk, BRA: BlindRotationAlgo, B: Backe
|
|||||||
&key.atk,
|
&key.atk,
|
||||||
scratch2,
|
scratch2,
|
||||||
);
|
);
|
||||||
println!("post_process: {} ms", now.elapsed().as_millis());
|
|
||||||
} else {
|
} else {
|
||||||
tmp_glwe.trace(module, 0, module.log_n(), &res_glwe, &key.atk, scratch2);
|
tmp_glwe.trace(module, 0, module.log_n(), &res_glwe, &key.atk, scratch2);
|
||||||
}
|
}
|
||||||
@@ -220,7 +247,31 @@ fn post_process<DataRes, DataA, B: Backend>(
|
|||||||
) where
|
) where
|
||||||
DataRes: DataMut,
|
DataRes: DataMut,
|
||||||
DataA: DataRef,
|
DataA: DataRef,
|
||||||
Module<B>: CircuitBootstrapFamily<B>,
|
Module<B>: VecZnxRotateInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxRotate,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||||
{
|
{
|
||||||
let log_n: usize = module.log_n();
|
let log_n: usize = module.log_n();
|
||||||
@@ -248,10 +299,7 @@ fn post_process<DataRes, DataA, B: Backend>(
|
|||||||
}
|
}
|
||||||
cts.insert(i as usize * (1 << log_gap_out), res.clone());
|
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);
|
pack(module, &mut cts, log_gap_out, auto_keys, scratch);
|
||||||
println!("pack: {} ms", now.elapsed().as_millis());
|
|
||||||
let packed: GLWECiphertext<Vec<u8>> = cts.remove(&0).unwrap();
|
let packed: GLWECiphertext<Vec<u8>> = cts.remove(&0).unwrap();
|
||||||
res.trace(
|
res.trace(
|
||||||
module,
|
module,
|
||||||
@@ -271,7 +319,31 @@ pub fn pack<D: DataMut, B: Backend>(
|
|||||||
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
auto_keys: &HashMap<i64, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: CircuitBootstrapFamily<B>,
|
Module<B>: VecZnxRotateInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxRotate,
|
||||||
Scratch<B>: TakeVecZnx + TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnx + TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
let log_n: usize = module.log_n();
|
let log_n: usize = module.log_n();
|
||||||
@@ -281,8 +353,6 @@ pub fn pack<D: DataMut, B: Backend>(
|
|||||||
let rank: usize = cts.get(&0).unwrap().rank();
|
let rank: usize = cts.get(&0).unwrap().rank();
|
||||||
|
|
||||||
(0..log_n - log_gap_out).for_each(|i| {
|
(0..log_n - log_gap_out).for_each(|i| {
|
||||||
let now: Instant = Instant::now();
|
|
||||||
|
|
||||||
let t = 16.min(1 << (log_n - 1 - i));
|
let t = 16.min(1 << (log_n - 1 - i));
|
||||||
|
|
||||||
let auto_key: &GGLWEAutomorphismKeyPrepared<Vec<u8>, B>;
|
let auto_key: &GGLWEAutomorphismKeyPrepared<Vec<u8>, B>;
|
||||||
@@ -314,8 +384,6 @@ pub fn pack<D: DataMut, B: Backend>(
|
|||||||
cts.insert(j, b);
|
cts.insert(j, b);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("combine: {} us", now.elapsed().as_micros());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +398,31 @@ fn combine<A: DataMut, D: DataMut, DataAK: DataRef, B: Backend>(
|
|||||||
auto_key: &GGLWEAutomorphismKeyPrepared<DataAK, B>,
|
auto_key: &GGLWEAutomorphismKeyPrepared<DataAK, B>,
|
||||||
scratch: &mut Scratch<B>,
|
scratch: &mut Scratch<B>,
|
||||||
) where
|
) where
|
||||||
Module<B>: CircuitBootstrapFamily<B>,
|
Module<B>: VecZnxRotateInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSwithcDegree
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxRotate,
|
||||||
Scratch<B>: TakeVecZnx + TakeVecZnxDft<B> + ScratchAvailable,
|
Scratch<B>: TakeVecZnx + TakeVecZnxDft<B> + ScratchAvailable,
|
||||||
{
|
{
|
||||||
// Goal is to evaluate: a = a + b*X^t + phi(a - b*X^t))
|
// Goal is to evaluate: a = a + b*X^t + phi(a - b*X^t))
|
||||||
|
|||||||
@@ -6,17 +6,16 @@ use std::{collections::HashMap, usize};
|
|||||||
|
|
||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchAvailable, TakeScalarZnx, TakeSvpPPol, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAddScalarInplace,
|
ScratchAvailable, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, TakeScalarZnx, TakeSvpPPol,
|
||||||
VecZnxAutomorphism, VecZnxSwithcDegree, VmpPMatAlloc, VmpPMatPrepare,
|
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},
|
layouts::{Backend, Data, DataRef, Module, Scratch},
|
||||||
};
|
};
|
||||||
use sampling::source::Source;
|
use sampling::source::Source;
|
||||||
|
|
||||||
use core::trait_families::{
|
|
||||||
GGLWEAutomorphismKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWEncryptSkFamily, GLWESecretPreparedModuleFamily,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::tfhe::blind_rotation::{
|
use crate::tfhe::blind_rotation::{
|
||||||
BlindRotationAlgo, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared,
|
BlindRotationAlgo, BlindRotationKey, BlindRotationKeyAlloc, BlindRotationKeyEncryptSk, BlindRotationKeyPrepared,
|
||||||
};
|
};
|
||||||
@@ -52,13 +51,27 @@ pub struct CircuitBootstrappingKey<D: Data, BRA: BlindRotationAlgo> {
|
|||||||
impl<BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyEncryptSk<B> for CircuitBootstrappingKey<Vec<u8>, BRA>
|
impl<BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyEncryptSk<B> for CircuitBootstrappingKey<Vec<u8>, BRA>
|
||||||
where
|
where
|
||||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<B>,
|
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<B>,
|
||||||
Module<B>: GGSWEncryptSkFamily<B>
|
Module<B>: SvpApply<B>
|
||||||
+ GLWESecretPreparedModuleFamily<B>
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GGLWEAutomorphismKeyEncryptSkFamily<B>
|
+ VecZnxDftAllocBytes
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxFillUniform
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalizeInplace<B>
|
||||||
|
+ VecZnxAddNormal
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
|
+ SvpPrepare<B>
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>,
|
+ SvpPPolAllocBytes
|
||||||
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VecZnxAutomorphism,
|
||||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeSvpPPol<B> + TakeVecZnxBig<B>,
|
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeSvpPPol<B> + TakeVecZnxBig<B>,
|
||||||
{
|
{
|
||||||
fn encrypt_sk<DLwe, DGlwe>(
|
fn encrypt_sk<DLwe, DGlwe>(
|
||||||
@@ -80,6 +93,7 @@ where
|
|||||||
where
|
where
|
||||||
DLwe: DataRef,
|
DLwe: DataRef,
|
||||||
DGlwe: DataRef,
|
DGlwe: DataRef,
|
||||||
|
Module<B>:,
|
||||||
{
|
{
|
||||||
let mut auto_keys: HashMap<i64, GGLWEAutomorphismKey<Vec<u8>>> = HashMap::new();
|
let mut auto_keys: HashMap<i64, GGLWEAutomorphismKey<Vec<u8>>> = HashMap::new();
|
||||||
let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(&module);
|
let gal_els: Vec<i64> = GLWECiphertext::trace_galois_elements(&module);
|
||||||
@@ -133,7 +147,7 @@ pub struct CircuitBootstrappingKeyPrepared<D: Data, BRA: BlindRotationAlgo, B: B
|
|||||||
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> PrepareAlloc<B, CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B>>
|
impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> PrepareAlloc<B, CircuitBootstrappingKeyPrepared<Vec<u8>, BRA, B>>
|
||||||
for CircuitBootstrappingKey<D, BRA>
|
for CircuitBootstrappingKey<D, BRA>
|
||||||
where
|
where
|
||||||
Module<B>: VmpPMatAlloc<B> + VmpPMatPrepare<B>,
|
Module<B>: VmpPMatAlloc<B> + VmpPrepare<B>,
|
||||||
BlindRotationKey<D, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
|
BlindRotationKey<D, BRA>: PrepareAlloc<B, BlindRotationKeyPrepared<Vec<u8>, BRA, B>>,
|
||||||
GGLWETensorKey<D>: PrepareAlloc<B, GGLWETensorKeyPrepared<Vec<u8>, B>>,
|
GGLWETensorKey<D>: PrepareAlloc<B, GGLWETensorKeyPrepared<Vec<u8>, B>>,
|
||||||
GGLWEAutomorphismKey<D>: PrepareAlloc<B, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
GGLWEAutomorphismKey<D>: PrepareAlloc<B, GGLWEAutomorphismKeyPrepared<Vec<u8>, B>>,
|
||||||
|
|||||||
@@ -2,9 +2,14 @@ use std::time::Instant;
|
|||||||
|
|
||||||
use backend::hal::{
|
use backend::hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpPPolAlloc, SvpPrepare, VecZnxAddNormal, VecZnxAddScalarInplace,
|
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApply, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare,
|
||||||
VecZnxAutomorphism, VecZnxFillUniform, VecZnxNormalizeInplace, VecZnxRotateInplace, VecZnxSwithcDegree, VmpPMatAlloc,
|
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace,
|
||||||
VmpPMatPrepare, ZnxView, ZnxViewMut,
|
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},
|
layouts::{Backend, Module, ScalarZnx, ScratchOwned},
|
||||||
oep::{
|
oep::{
|
||||||
@@ -20,18 +25,11 @@ use crate::tfhe::{
|
|||||||
BlindRotationKeyPrepared,
|
BlindRotationKeyPrepared,
|
||||||
},
|
},
|
||||||
circuit_bootstrapping::{
|
circuit_bootstrapping::{
|
||||||
CircuitBootstrapFamily, CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyPrepared,
|
CircuitBootstrappingKey, CircuitBootstrappingKeyEncryptSk, CircuitBootstrappingKeyPrepared, CirtuitBootstrappingExecute,
|
||||||
CirtuitBootstrappingExecute,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use core::{
|
use core::layouts::prepared::PrepareAlloc;
|
||||||
layouts::prepared::PrepareAlloc,
|
|
||||||
trait_families::{
|
|
||||||
GGLWEAutomorphismKeyEncryptSkFamily, GGLWETensorKeyEncryptSkFamily, GGSWAssertNoiseFamily, GGSWEncryptSkFamily,
|
|
||||||
GLWEDecryptFamily,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use core::layouts::{
|
use core::layouts::{
|
||||||
GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret,
|
GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, LWECiphertext, LWEPlaintext, LWESecret,
|
||||||
@@ -43,19 +41,46 @@ where
|
|||||||
Module<B>: VecZnxFillUniform
|
Module<B>: VecZnxFillUniform
|
||||||
+ VecZnxAddNormal
|
+ VecZnxAddNormal
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ VecZnxNormalizeInplace<B>
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GGLWEAutomorphismKeyEncryptSkFamily<B>
|
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VecZnxBigAllocBytes
|
||||||
+ CircuitBootstrapFamily<B>
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ SvpApply<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ SvpPrepare<B>
|
+ SvpPrepare<B>
|
||||||
+ SvpPPolAlloc<B>,
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ VecZnxRotateInplace
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxRotate,
|
||||||
B: ScratchOwnedAllocImpl<B>
|
B: ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ TakeVecZnxDftImpl<B>
|
+ TakeVecZnxDftImpl<B>
|
||||||
@@ -108,7 +133,7 @@ where
|
|||||||
let data: i64 = 1;
|
let data: i64 = 1;
|
||||||
|
|
||||||
let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(basek, k_lwe_pt);
|
let mut pt_lwe: LWEPlaintext<Vec<u8>> = 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);
|
println!("pt_lwe: {}", pt_lwe);
|
||||||
|
|
||||||
@@ -203,19 +228,46 @@ where
|
|||||||
Module<B>: VecZnxFillUniform
|
Module<B>: VecZnxFillUniform
|
||||||
+ VecZnxAddNormal
|
+ VecZnxAddNormal
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ VecZnxNormalizeInplace<B>
|
||||||
+ GGSWEncryptSkFamily<B>
|
+ VecZnxDftAllocBytes
|
||||||
|
+ VecZnxBigNormalize<B>
|
||||||
|
+ VecZnxDftFromVecZnx<B>
|
||||||
|
+ SvpApplyInplace<B>
|
||||||
|
+ VecZnxDftToVecZnxBigConsume<B>
|
||||||
|
+ VecZnxNormalizeTmpBytes
|
||||||
|
+ VecZnxSubABInplace
|
||||||
|
+ VecZnxAddInplace
|
||||||
|
+ VecZnxNormalize<B>
|
||||||
|
+ VecZnxSub
|
||||||
+ VecZnxAddScalarInplace
|
+ VecZnxAddScalarInplace
|
||||||
+ GGLWEAutomorphismKeyEncryptSkFamily<B>
|
|
||||||
+ VecZnxAutomorphism
|
+ VecZnxAutomorphism
|
||||||
+ VecZnxSwithcDegree
|
+ VecZnxSwithcDegree
|
||||||
+ GGLWETensorKeyEncryptSkFamily<B>
|
+ VecZnxBigAllocBytes
|
||||||
+ CircuitBootstrapFamily<B>
|
+ VecZnxDftToVecZnxBigTmpA<B>
|
||||||
+ GLWEDecryptFamily<B>
|
+ SvpApply<B>
|
||||||
+ GGSWAssertNoiseFamily<B>
|
+ VecZnxBigAddInplace<B>
|
||||||
|
+ VecZnxBigAddSmallInplace<B>
|
||||||
|
+ VecZnxBigAlloc<B>
|
||||||
|
+ VecZnxDftAlloc<B>
|
||||||
|
+ VecZnxBigNormalizeTmpBytes
|
||||||
+ VmpPMatAlloc<B>
|
+ VmpPMatAlloc<B>
|
||||||
+ VmpPMatPrepare<B>
|
+ VmpPrepare<B>
|
||||||
+ SvpPrepare<B>
|
+ SvpPrepare<B>
|
||||||
+ SvpPPolAlloc<B>,
|
+ SvpPPolAlloc<B>
|
||||||
|
+ VmpApplyTmpBytes
|
||||||
|
+ VmpApply<B>
|
||||||
|
+ VmpApplyAdd<B>
|
||||||
|
+ SvpPPolAllocBytes
|
||||||
|
+ VecZnxRotateInplace
|
||||||
|
+ VecZnxBigAutomorphismInplace<B>
|
||||||
|
+ VecZnxRshInplace
|
||||||
|
+ VecZnxDftCopy<B>
|
||||||
|
+ VecZnxNegateInplace
|
||||||
|
+ VecZnxCopy
|
||||||
|
+ VecZnxAutomorphismInplace
|
||||||
|
+ VecZnxBigSubSmallBInplace<B>
|
||||||
|
+ VecZnxBigAllocBytes
|
||||||
|
+ VecZnxDftAddInplace<B>
|
||||||
|
+ VecZnxRotate,
|
||||||
B: ScratchOwnedAllocImpl<B>
|
B: ScratchOwnedAllocImpl<B>
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
+ ScratchOwnedBorrowImpl<B>
|
||||||
+ TakeVecZnxDftImpl<B>
|
+ TakeVecZnxDftImpl<B>
|
||||||
@@ -268,7 +320,7 @@ where
|
|||||||
let data: i64 = 1;
|
let data: i64 = 1;
|
||||||
|
|
||||||
let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(basek, k_lwe_pt);
|
let mut pt_lwe: LWEPlaintext<Vec<u8>> = 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);
|
println!("pt_lwe: {}", pt_lwe);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "utils"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
license = "Apache-2.0"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
fnv = "1.0.7"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod map;
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
use std::hash::Hash;
|
|
||||||
|
|
||||||
use fnv::FnvHashMap;
|
|
||||||
|
|
||||||
pub struct Map<K, V>(pub FnvHashMap<K, V>);
|
|
||||||
|
|
||||||
impl<K: Eq + Hash, V> Map<K, V> {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
0: FnvHashMap::<K, V>::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert(&mut self, k: K, data: V) -> Option<V> {
|
|
||||||
self.0.insert(k, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self, k: &K) -> Option<&V> {
|
|
||||||
self.0.get(k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user