mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Update READMEs & add SECURITY.md (#78)
This commit is contained in:
committed by
GitHub
parent
3b94ab047e
commit
ccd94e36cc
@@ -11,8 +11,8 @@ documentation = "https://docs.rs/poulpy"
|
||||
[dependencies]
|
||||
rug = {workspace = true}
|
||||
criterion = {workspace = true}
|
||||
poulpy-hal = "0.1.2"
|
||||
poulpy-backend = "0.1.2"
|
||||
poulpy-hal = {path="../poulpy-hal"}
|
||||
poulpy-backend = {path="../poulpy-backend"}
|
||||
itertools = {workspace = true}
|
||||
byteorder = {workspace = true}
|
||||
|
||||
|
||||
172
poulpy-core/README.md
Normal file
172
poulpy-core/README.md
Normal file
@@ -0,0 +1,172 @@
|
||||
# 🐙 Poulpy-Core
|
||||
|
||||
**Poulpy-Core** is a Rust crate built on **`poulpy-hal`**, providing scheme- and backend-agnostic RLWE-based homomorphic encryption building blocks.
|
||||
|
||||
## Getting Started
|
||||
|
||||
```rust
|
||||
use poulpy_backend::cpu_spqlios::FFT64;
|
||||
use poulpy_core::{
|
||||
GLWEOperations, SIGMA,
|
||||
layouts::{
|
||||
GLWECiphertext, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform},
|
||||
layouts::{Module, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
// Ring degree
|
||||
let log_n: usize = 10;
|
||||
|
||||
let n: usize = 1<<log_n;
|
||||
|
||||
// Base-2-k (implicit digit decomposition)
|
||||
let basek: usize = 14;
|
||||
|
||||
// Ciphertext Torus precision (equivalent to ciphertext modulus)
|
||||
let k_ct: usize = 27;
|
||||
|
||||
// Plaintext Torus precision (equivament to plaintext modulus)
|
||||
let k_pt: usize = basek;
|
||||
|
||||
// GLWE rank
|
||||
let rank: usize = 1;
|
||||
|
||||
// Instantiate Module (DFT Tables)
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(n as u64);
|
||||
|
||||
// Allocates ciphertext & plaintexts
|
||||
let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
|
||||
|
||||
// CPRNG
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
|
||||
// Scratch space
|
||||
let mut scratch: ScratchOwned<FFT64> = ScratchOwned::alloc(
|
||||
GLWECiphertext::encrypt_sk_scratch_space(&module, n, basek, ct.k())
|
||||
| GLWECiphertext::decrypt_scratch_space(&module, n, basek, ct.k()),
|
||||
);
|
||||
|
||||
// Generate secret-key
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
// Backend-prepared secret
|
||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64> = sk.prepare_alloc(&module, scratch.borrow());
|
||||
|
||||
// Uniform plaintext
|
||||
module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, k_pt, &mut source_xa);
|
||||
|
||||
// Encryption
|
||||
ct.encrypt_sk(
|
||||
&module,
|
||||
&pt_want,
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
// Decryption
|
||||
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
|
||||
|
||||
// Diff between pt - Dec(Enc(pt))
|
||||
pt_want.sub_inplace_ab(&module, &pt_have);
|
||||
|
||||
// Ideal vs. actual noise
|
||||
let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
|
||||
let noise_want: f64 = SIGMA;
|
||||
|
||||
// Check
|
||||
assert!(noise_have <= noise_want + 0.2);
|
||||
}
|
||||
```
|
||||
|
||||
## Layouts
|
||||
|
||||
This crate defines three categories of layouts for `LWE`, `GLWE`, `GGLWE`, and `GGSW` objects (and their derivatives), all instantiated using **`poulpy-hal`** layouts. Each serves a distinct purpose:
|
||||
|
||||
* **Standard** → Front-end, serializable layouts. These are backend-agnostic and act as inputs/outputs of computations (e.g., `GGLWEAutomorphismKey`).
|
||||
* **Compressed** → Compact serializable variants of the standard layouts. They are not usable for computation but significantly reduce storage size (e.g., `GGLWEAutomorphismKeyCompressed`).
|
||||
* **Prepared** → Backend-optimized, opaque layouts used only for computation (write-only). These store preprocessed data for efficient execution on a specific backend (e.g., `GGLWEAutomorphismKeyPrepared`).
|
||||
|
||||
All **standard** and **compressed** layouts implement the `WriterTo` and `ReaderFrom` traits, enabling straightforward serialization/deserialization with any type implementing `Write` or `Read`:
|
||||
|
||||
```rust
|
||||
pub trait WriterTo {
|
||||
fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>;
|
||||
}
|
||||
|
||||
pub trait ReaderFrom {
|
||||
fn read_from<R: Read>(&mut self, reader: &mut R) -> Result<()>;
|
||||
}
|
||||
```
|
||||
|
||||
### Example Workflow
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A[GGLWEAutomorphismKeyCompressed]-->|decompress|B[GGLWEAutomorphismKey]-->|prepare|C[GGLWEAutomorphismKeyPrepared]
|
||||
```
|
||||
|
||||
Equivalent Rust:
|
||||
|
||||
```rust
|
||||
let mut atk_compressed: GGLWEAutomorphismKeyCompressed<Vec<u8>> =
|
||||
GGLWEAutomorphismKeyCompressed::alloc(...);
|
||||
let mut atk: GGLWEAutomorphismKey<Vec<u8>> =
|
||||
GGLWEAutomorphismKey::alloc(...);
|
||||
atk.decompress(module, &atk_compressed);
|
||||
let mut atk_prep: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = GLWESecretPrepared<Vec<u8>, B> = atk.prepare_alloc(...);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Encryption & Decryption
|
||||
|
||||
* **Encryption** → Supported for all **standard** and **compressed** layouts.
|
||||
* **Decryption** → Only directly available for `LWECiphertext` and `GLWECiphertext`.
|
||||
However, it remains naturally usable on `GGLWE` and `GGSW` objects, since these are vectors/matrices of `GLWECiphertext`.
|
||||
|
||||
```rust
|
||||
let mut atk: GGLWEAutomorphismKey<Vec<u8>> =
|
||||
GGLWEAutomorphismKey::alloc(...);
|
||||
atk.encrypt_sk(...);
|
||||
atk.at(row, 0).decrypt(...);
|
||||
```
|
||||
## Keyswitching, Automorphism & External Product
|
||||
|
||||
Keyswitching, automorphisms, and external products are supported for all ciphertext types where they are well-defined.
|
||||
This includes subtypes such as `GGLWEAutomorphismKey`.
|
||||
|
||||
For example:
|
||||
|
||||
```rust
|
||||
atk.external_product(...);
|
||||
ggsw.automorphism(...);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Additional Features
|
||||
|
||||
* Ciphertexts: `LWE` and `GLWE`
|
||||
* `GLWE` ring packing
|
||||
* `GLWE` trace
|
||||
* Noise analysis for `GLWE`, `GGLWE`, `GGSW`
|
||||
* Basic operations over `GLWE` ciphertexts and plaintexts
|
||||
|
||||
---
|
||||
|
||||
## Tests
|
||||
|
||||
A fully generic test suite is available in [`src/tests/generics`](./src/tests/generics).
|
||||
@@ -37,7 +37,6 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
let digits: usize = 1;
|
||||
|
||||
let rows: usize = 1; //(p.k_ct_in.div_ceil(p.basek);
|
||||
let sigma: f64 = 3.2;
|
||||
|
||||
let mut ct_ggsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(n, basek, k_ggsw, rows, digits, rank);
|
||||
let mut ct_glwe_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct_in, rank);
|
||||
@@ -73,7 +72,6 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -82,7 +80,6 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -134,7 +131,6 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
let digits: usize = 1;
|
||||
|
||||
let rows: usize = p.k_ct.div_ceil(p.basek);
|
||||
let sigma: f64 = 3.2;
|
||||
|
||||
let mut ct_ggsw: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(n, basek, k_ggsw, rows, digits, rank);
|
||||
let mut ct_glwe: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_glwe, rank);
|
||||
@@ -168,7 +164,6 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -177,7 +172,6 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
||||
let digits: usize = p.digits;
|
||||
|
||||
let rows: usize = p.k_ct_in.div_ceil(p.basek * digits);
|
||||
let sigma: f64 = 3.2;
|
||||
|
||||
let mut ksk: GGLWEAutomorphismKey<Vec<u8>> = GGLWEAutomorphismKey::alloc(n, basek, k_grlwe, rows, digits, rank_out);
|
||||
let mut ct_in: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_rlwe_in, rank_in);
|
||||
@@ -78,7 +77,6 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
||||
&sk_in,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -87,7 +85,6 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
|
||||
&sk_in_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -146,7 +143,6 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
let digits: usize = 1;
|
||||
|
||||
let rows: usize = p.k_ct.div_ceil(p.basek);
|
||||
let sigma: f64 = 3.2;
|
||||
|
||||
let mut ksk: GGLWESwitchingKey<Vec<u8>> = GGLWESwitchingKey::alloc(n, basek, k_ksk, rows, digits, rank, rank);
|
||||
let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
|
||||
@@ -174,7 +170,6 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -183,7 +178,6 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
|
||||
&sk_in_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
|
||||
84
poulpy-core/examples/encryption.rs
Normal file
84
poulpy-core/examples/encryption.rs
Normal file
@@ -0,0 +1,84 @@
|
||||
use poulpy_backend::cpu_spqlios::FFT64;
|
||||
use poulpy_core::{
|
||||
GLWEOperations, SIGMA,
|
||||
layouts::{
|
||||
GLWECiphertext, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform},
|
||||
layouts::{Module, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
// Ring degree
|
||||
let log_n: usize = 10;
|
||||
|
||||
let n: usize = 1 << log_n;
|
||||
|
||||
// Base-2-k (implicit digit decomposition)
|
||||
let basek: usize = 14;
|
||||
|
||||
// Ciphertext Torus precision (equivalent to ciphertext modulus)
|
||||
let k_ct: usize = 27;
|
||||
|
||||
// Plaintext Torus precision (equivament to plaintext modulus)
|
||||
let k_pt: usize = basek;
|
||||
|
||||
// GLWE rank
|
||||
let rank: usize = 1;
|
||||
|
||||
// Instantiate Module (DFT Tables)
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(n as u64);
|
||||
|
||||
// Allocates ciphertext & plaintexts
|
||||
let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, basek, k_ct, rank);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k_pt);
|
||||
|
||||
// CPRNG
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
|
||||
// Scratch space
|
||||
let mut scratch: ScratchOwned<FFT64> = ScratchOwned::alloc(
|
||||
GLWECiphertext::encrypt_sk_scratch_space(&module, n, basek, ct.k())
|
||||
| GLWECiphertext::decrypt_scratch_space(&module, n, basek, ct.k()),
|
||||
);
|
||||
|
||||
// Generate secret-key
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
// Backend-prepared secret
|
||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64> = sk.prepare_alloc(&module, scratch.borrow());
|
||||
|
||||
// Uniform plaintext
|
||||
module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, k_pt, &mut source_xa);
|
||||
|
||||
// Encryption
|
||||
ct.encrypt_sk(
|
||||
&module,
|
||||
&pt_want,
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
// Decryption
|
||||
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
|
||||
|
||||
// Diff between pt - Dec(Enc(pt))
|
||||
pt_want.sub_inplace_ab(&module, &pt_have);
|
||||
|
||||
// Ideal vs. actual noise
|
||||
let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
|
||||
let noise_want: f64 = SIGMA;
|
||||
|
||||
// Check
|
||||
assert!(noise_have <= noise_want + 0.2);
|
||||
}
|
||||
@@ -35,7 +35,6 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAutomorphism
|
||||
@@ -97,7 +96,7 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> {
|
||||
}
|
||||
|
||||
self.key
|
||||
.encrypt_sk(module, sk, &sk_out, seed_xa, source_xe, sigma, scratch_1);
|
||||
.encrypt_sk(module, sk, &sk_out, seed_xa, source_xe, scratch_1);
|
||||
|
||||
self.p = p;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use poulpy_hal::{
|
||||
|
||||
use crate::{
|
||||
TakeGLWEPt,
|
||||
encryption::glwe_encrypt_sk_internal,
|
||||
encryption::{SIGMA, glwe_encrypt_sk_internal},
|
||||
layouts::{GGLWECiphertext, Infos, compressed::GGLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
||||
};
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<D: DataMut> GGLWECiphertextCompressed<D> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -128,7 +127,7 @@ impl<D: DataMut> GGLWECiphertextCompressed<D> {
|
||||
sk,
|
||||
&mut source_xa_tmp,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scrach_1,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -41,7 +41,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKeyCompressed<DataSelf> {
|
||||
sk_out: &GLWESecret<DataSkOut>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -119,7 +118,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKeyCompressed<DataSelf> {
|
||||
&sk_out_tmp,
|
||||
seed_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch2,
|
||||
);
|
||||
self.sk_in_n = sk_in.n();
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpApply<B>
|
||||
@@ -104,7 +103,7 @@ impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> {
|
||||
let (seed_xa_tmp, _) = source_xa.branch();
|
||||
|
||||
self.at_mut(i, j)
|
||||
.encrypt_sk(module, &sk_ij, sk, seed_xa_tmp, source_xe, sigma, scratch5);
|
||||
.encrypt_sk(module, &sk_ij, sk, seed_xa_tmp, source_xe, scratch5);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use poulpy_hal::{
|
||||
|
||||
use crate::{
|
||||
TakeGLWEPt,
|
||||
encryption::glwe_encrypt_sk_internal,
|
||||
encryption::{SIGMA, glwe_encrypt_sk_internal},
|
||||
layouts::{GGSWCiphertext, Infos, compressed::GGSWCiphertextCompressed, prepared::GLWESecretPrepared},
|
||||
};
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<DataSelf: DataMut> GGSWCiphertextCompressed<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -97,7 +96,7 @@ impl<DataSelf: DataMut> GGSWCiphertextCompressed<DataSelf> {
|
||||
sk,
|
||||
&mut source_xa_tmp,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scratch_1,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::glwe_ct::glwe_encrypt_sk_internal,
|
||||
encryption::{SIGMA, glwe_ct::glwe_encrypt_sk_internal},
|
||||
layouts::{GLWECiphertext, GLWEPlaintext, Infos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared},
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -49,15 +48,7 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
+ VecZnxSub,
|
||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||
{
|
||||
self.encrypt_sk_internal(
|
||||
module,
|
||||
Some((pt, 0)),
|
||||
sk,
|
||||
seed_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
self.encrypt_sk_internal(module, Some((pt, 0)), sk, seed_xa, source_xe, scratch);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -68,7 +59,6 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -99,7 +89,7 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
sk,
|
||||
&mut source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scratch,
|
||||
);
|
||||
self.seed = seed_xa;
|
||||
|
||||
@@ -36,7 +36,6 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -92,7 +91,7 @@ impl<DataSelf: DataMut> GGLWEAutomorphismKey<DataSelf> {
|
||||
}
|
||||
|
||||
self.key
|
||||
.encrypt_sk(module, sk, &sk_out, source_xa, source_xe, sigma, scratch_1);
|
||||
.encrypt_sk(module, sk, &sk_out, source_xa, source_xe, scratch_1);
|
||||
|
||||
self.p = p;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -127,7 +126,7 @@ impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> {
|
||||
|
||||
// rlwe encrypt of vec_znx_pt into vec_znx_ct
|
||||
self.at_mut(row_i, col_i)
|
||||
.encrypt_sk(module, &tmp_pt, sk, source_xa, source_xe, sigma, scrach_1);
|
||||
.encrypt_sk(module, &tmp_pt, sk, source_xa, source_xe, scrach_1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
||||
sk_out: &GLWESecret<DataSkOut>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -130,7 +129,6 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
||||
&sk_out_tmp,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch2,
|
||||
);
|
||||
self.sk_in_n = sk_in.n();
|
||||
|
||||
@@ -39,7 +39,6 @@ impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> {
|
||||
sk: &GLWESecret<DataSk>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpApply<B>
|
||||
@@ -102,7 +101,7 @@ impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> {
|
||||
);
|
||||
|
||||
self.at_mut(i, j)
|
||||
.encrypt_sk(module, &sk_ij, sk, source_xa, source_xe, sigma, scratch5);
|
||||
.encrypt_sk(module, &sk_ij, sk, source_xa, source_xe, scratch5);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxAddScalarInplace
|
||||
@@ -86,7 +85,6 @@ impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch1,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,8 +10,8 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
SIX_SIGMA,
|
||||
dist::Distribution,
|
||||
encryption::{SIGMA, SIGMA_BOUND},
|
||||
layouts::{
|
||||
GLWECiphertext, GLWEPlaintext, Infos,
|
||||
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared},
|
||||
@@ -46,7 +46,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -77,15 +76,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
)
|
||||
}
|
||||
|
||||
self.encrypt_sk_internal(
|
||||
module,
|
||||
Some((pt, 0)),
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
self.encrypt_sk_internal(module, Some((pt, 0)), sk, source_xa, source_xe, scratch);
|
||||
}
|
||||
|
||||
pub fn encrypt_zero_sk<DataSk: DataRef, B: Backend>(
|
||||
@@ -94,7 +85,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -129,7 +119,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
}
|
||||
@@ -142,7 +131,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -172,7 +160,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
sk,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
SIGMA,
|
||||
scratch,
|
||||
);
|
||||
}
|
||||
@@ -185,7 +173,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk: &GLWEPublicKeyPrepared<DataPk, B>,
|
||||
source_xu: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -196,15 +183,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
+ VecZnxBigNormalize<B>,
|
||||
Scratch<B>: TakeSvpPPol<B> + TakeScalarZnx + TakeVecZnxDft<B>,
|
||||
{
|
||||
self.encrypt_pk_internal::<DataPt, DataPk, B>(
|
||||
module,
|
||||
Some((pt, 0)),
|
||||
pk,
|
||||
source_xu,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
self.encrypt_pk_internal::<DataPt, DataPk, B>(module, Some((pt, 0)), pk, source_xu, source_xe, scratch);
|
||||
}
|
||||
|
||||
pub fn encrypt_zero_pk<DataPk: DataRef, B: Backend>(
|
||||
@@ -213,7 +192,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk: &GLWEPublicKeyPrepared<DataPk, B>,
|
||||
source_xu: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -230,7 +208,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk,
|
||||
source_xu,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch,
|
||||
);
|
||||
}
|
||||
@@ -243,7 +220,6 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
pk: &GLWEPublicKeyPrepared<DataPk, B>,
|
||||
source_xu: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: SvpPrepare<B>
|
||||
@@ -300,15 +276,7 @@ impl<DataSelf: DataMut> GLWECiphertext<DataSelf> {
|
||||
let mut ci_big = module.vec_znx_dft_to_vec_znx_big_consume(ci_dft);
|
||||
|
||||
// ci_big = u * pk[i] + e
|
||||
module.vec_znx_big_add_normal(
|
||||
basek,
|
||||
&mut ci_big,
|
||||
0,
|
||||
pk.k(),
|
||||
source_xe,
|
||||
sigma,
|
||||
sigma * SIX_SIGMA,
|
||||
);
|
||||
module.vec_znx_big_add_normal(basek, &mut ci_big, 0, pk.k(), source_xe, SIGMA, SIGMA_BOUND);
|
||||
|
||||
// ci_big = u * pk[i] + e + m (if col = i)
|
||||
if let Some((pt, col)) = pt
|
||||
@@ -412,7 +380,7 @@ pub(crate) fn glwe_encrypt_sk_internal<DataCt: DataMut, DataPt: DataRef, DataSk:
|
||||
}
|
||||
|
||||
// c[0] += e
|
||||
module.vec_znx_add_normal(basek, &mut c0, 0, k, source_xe, sigma, sigma * SIX_SIGMA);
|
||||
module.vec_znx_add_normal(basek, &mut c0, 0, k, source_xe, sigma, SIGMA_BOUND);
|
||||
|
||||
// c[0] += m if col = 0
|
||||
if let Some((pt, col)) = pt
|
||||
|
||||
@@ -18,7 +18,6 @@ impl<D: DataMut> GLWEPublicKey<D> {
|
||||
sk: &GLWESecretPrepared<S, B>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>:,
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -61,7 +60,7 @@ impl<D: DataMut> GLWEPublicKey<D> {
|
||||
));
|
||||
|
||||
let mut tmp: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(self.n(), self.basek(), self.k(), self.rank());
|
||||
tmp.encrypt_zero_sk(module, sk, source_xa, source_xe, sigma, scratch.borrow());
|
||||
tmp.encrypt_zero_sk(module, sk, source_xa, source_xe, scratch.borrow());
|
||||
self.dist = sk.dist;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
||||
sk_glwe: &GLWESecret<DGlwe>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
DLwe: DataRef,
|
||||
@@ -75,7 +74,6 @@ impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
||||
&sk_lwe_as_glwe,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch1,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
SIX_SIGMA,
|
||||
encryption::{SIGMA, SIGMA_BOUND},
|
||||
layouts::{Infos, LWECiphertext, LWEPlaintext, LWESecret},
|
||||
};
|
||||
|
||||
@@ -20,7 +20,6 @@ impl<DataSelf: DataMut> LWECiphertext<DataSelf> {
|
||||
sk: &LWESecret<DataSk>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
) where
|
||||
DataPt: DataRef,
|
||||
DataSk: DataRef,
|
||||
@@ -58,15 +57,7 @@ impl<DataSelf: DataMut> LWECiphertext<DataSelf> {
|
||||
.sum::<i64>();
|
||||
});
|
||||
|
||||
module.vec_znx_add_normal(
|
||||
basek,
|
||||
&mut self.data,
|
||||
0,
|
||||
k,
|
||||
source_xe,
|
||||
sigma,
|
||||
sigma * SIX_SIGMA,
|
||||
);
|
||||
module.vec_znx_add_normal(basek, &mut self.data, 0, k, source_xe, SIGMA, SIGMA_BOUND);
|
||||
|
||||
module.vec_znx_normalize_inplace(
|
||||
basek,
|
||||
|
||||
@@ -34,7 +34,6 @@ impl<D: DataMut> LWESwitchingKey<D> {
|
||||
sk_lwe_out: &LWESecret<DOut>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
DIn: DataRef,
|
||||
@@ -83,7 +82,6 @@ impl<D: DataMut> LWESwitchingKey<D> {
|
||||
&sk_out_glwe,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch2,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ impl<D: DataMut> LWEToGLWESwitchingKey<D> {
|
||||
sk_glwe: &GLWESecret<DGlwe>,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
DLwe: DataRef,
|
||||
@@ -73,7 +72,6 @@ impl<D: DataMut> LWEToGLWESwitchingKey<D> {
|
||||
sk_glwe,
|
||||
source_xa,
|
||||
source_xe,
|
||||
sigma,
|
||||
scratch1,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,3 +12,6 @@ mod lwe_ksk;
|
||||
mod lwe_to_glwe_ksk;
|
||||
|
||||
pub(crate) use glwe_ct::glwe_encrypt_sk_internal;
|
||||
|
||||
pub const SIGMA: f64 = 3.2;
|
||||
pub(crate) const SIGMA_BOUND: f64 = 6.0 * SIGMA;
|
||||
|
||||
@@ -17,8 +17,8 @@ pub mod layouts;
|
||||
pub use dist::*;
|
||||
pub use glwe_packing::*;
|
||||
|
||||
pub use encryption::SIGMA;
|
||||
|
||||
pub use scratch::*;
|
||||
|
||||
pub(crate) const SIX_SIGMA: f64 = 6.0;
|
||||
|
||||
pub mod tests;
|
||||
|
||||
@@ -16,6 +16,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
@@ -33,7 +34,6 @@ pub fn test_gglwe_automorphism_key_automorphism<B>(
|
||||
k_in: usize,
|
||||
k_out: usize,
|
||||
k_apply: usize,
|
||||
sigma: f64,
|
||||
rank: usize,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -106,7 +106,6 @@ pub fn test_gglwe_automorphism_key_automorphism<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -117,7 +116,6 @@ pub fn test_gglwe_automorphism_key_automorphism<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -171,7 +169,7 @@ pub fn test_gglwe_automorphism_key_automorphism<B>(
|
||||
0.5,
|
||||
0.5,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_out,
|
||||
@@ -197,7 +195,6 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(
|
||||
digits: usize,
|
||||
k_in: usize,
|
||||
k_apply: usize,
|
||||
sigma: f64,
|
||||
rank: usize,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
@@ -283,7 +280,6 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -294,7 +290,6 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -343,7 +338,7 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(
|
||||
0.5,
|
||||
0.5,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_in,
|
||||
|
||||
@@ -17,6 +17,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWETensorKey, GGSWCiphertext, GLWESecret,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
@@ -35,7 +36,6 @@ pub fn test_ggsw_automorphism<B>(
|
||||
k_tsk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigAllocBytes
|
||||
@@ -122,7 +122,6 @@ pub fn test_ggsw_automorphism<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
tensor_key.encrypt_sk(
|
||||
@@ -130,7 +129,6 @@ pub fn test_ggsw_automorphism<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -142,7 +140,6 @@ pub fn test_ggsw_automorphism<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -171,7 +168,7 @@ pub fn test_ggsw_automorphism<B>(
|
||||
col_j,
|
||||
var_xs,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_in,
|
||||
@@ -193,7 +190,6 @@ pub fn test_ggsw_automorphism_inplace<B>(
|
||||
k_tsk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigAllocBytes
|
||||
@@ -277,7 +273,6 @@ pub fn test_ggsw_automorphism_inplace<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
tensor_key.encrypt_sk(
|
||||
@@ -285,7 +280,6 @@ pub fn test_ggsw_automorphism_inplace<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -297,7 +291,6 @@ pub fn test_ggsw_automorphism_inplace<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -320,7 +313,7 @@ pub fn test_ggsw_automorphism_inplace<B>(
|
||||
col_j,
|
||||
var_xs,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_ct,
|
||||
|
||||
@@ -16,6 +16,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GLWECiphertext, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc},
|
||||
@@ -33,7 +34,6 @@ pub fn test_glwe_automorphism<B>(
|
||||
k_ksk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -114,7 +114,6 @@ pub fn test_glwe_automorphism<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -124,7 +123,6 @@ pub fn test_glwe_automorphism<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -140,7 +138,7 @@ pub fn test_glwe_automorphism<B>(
|
||||
0.5,
|
||||
0.5,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_in,
|
||||
@@ -161,7 +159,6 @@ pub fn test_glwe_automorphism_inplace<B>(
|
||||
k_ksk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -232,7 +229,6 @@ pub fn test_glwe_automorphism_inplace<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -242,7 +238,6 @@ pub fn test_glwe_automorphism_inplace<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -258,7 +253,7 @@ pub fn test_glwe_automorphism_inplace<B>(
|
||||
0.5,
|
||||
0.5,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_ct,
|
||||
|
||||
@@ -63,7 +63,6 @@ where
|
||||
{
|
||||
let n: usize = module.n();
|
||||
let basek: usize = 17;
|
||||
let sigma: f64 = 3.2;
|
||||
|
||||
let rank: usize = 2;
|
||||
|
||||
@@ -99,14 +98,7 @@ where
|
||||
lwe_pt.encode_i64(data, k_lwe_pt);
|
||||
|
||||
let mut lwe_ct: LWECiphertext<Vec<u8>> = LWECiphertext::alloc(n_lwe, basek, k_lwe_ct);
|
||||
lwe_ct.encrypt_sk(
|
||||
module,
|
||||
&lwe_pt,
|
||||
&sk_lwe,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
);
|
||||
lwe_ct.encrypt_sk(module, &lwe_pt, &sk_lwe, &mut source_xa, &mut source_xe);
|
||||
|
||||
let mut ksk: LWEToGLWESwitchingKey<Vec<u8>> = LWEToGLWESwitchingKey::alloc(n, basek, k_ksk, lwe_ct.size(), rank);
|
||||
|
||||
@@ -116,7 +108,6 @@ where
|
||||
&sk_glwe,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -174,7 +165,6 @@ where
|
||||
{
|
||||
let n: usize = module.n();
|
||||
let basek: usize = 17;
|
||||
let sigma: f64 = 3.2;
|
||||
|
||||
let rank: usize = 2;
|
||||
|
||||
@@ -215,7 +205,6 @@ where
|
||||
&sk_glwe_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -227,7 +216,6 @@ where
|
||||
&sk_glwe,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
|
||||
@@ -15,20 +15,17 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
GGLWEAutomorphismKey, GLWESecret,
|
||||
compressed::{Decompress, GGLWEAutomorphismKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GLWESecret,
|
||||
compressed::{Decompress, GGLWEAutomorphismKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_gglwe_automorphisk_key_encrypt_sk<B>(
|
||||
module: &Module<B>,
|
||||
basek: usize,
|
||||
k_ksk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
pub fn test_gglwe_automorphisk_key_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ksk: usize, digits: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxDftFromVecZnx<B>
|
||||
@@ -94,7 +91,6 @@ pub fn test_gglwe_automorphisk_key_encrypt_sk<B>(
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -112,7 +108,7 @@ pub fn test_gglwe_automorphisk_key_encrypt_sk<B>(
|
||||
|
||||
atk.key
|
||||
.key
|
||||
.assert_noise(module, &sk_out_prepared, &sk.data, sigma);
|
||||
.assert_noise(module, &sk_out_prepared, &sk.data, SIGMA);
|
||||
}
|
||||
|
||||
pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>(
|
||||
@@ -121,7 +117,6 @@ pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>(
|
||||
k_ksk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -184,15 +179,7 @@ pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>(
|
||||
|
||||
let seed_xa: [u8; 32] = [1u8; 32];
|
||||
|
||||
atk_compressed.encrypt_sk(
|
||||
module,
|
||||
p,
|
||||
&sk,
|
||||
seed_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
atk_compressed.encrypt_sk(module, p, &sk, seed_xa, &mut source_xe, scratch.borrow());
|
||||
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = sk.clone();
|
||||
(0..atk_compressed.rank()).for_each(|i| {
|
||||
@@ -211,5 +198,5 @@ pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>(
|
||||
|
||||
atk.key
|
||||
.key
|
||||
.assert_noise(module, &sk_out_prepared, &sk.data, sigma);
|
||||
.assert_noise(module, &sk_out_prepared, &sk.data, SIGMA);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,13 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
GGLWESwitchingKey, GLWESecret,
|
||||
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GLWESecret,
|
||||
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_gglwe_switching_key_encrypt_sk<B>(
|
||||
@@ -27,7 +30,6 @@ pub fn test_gglwe_switching_key_encrypt_sk<B>(
|
||||
digits: usize,
|
||||
rank_in: usize,
|
||||
rank_out: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -92,12 +94,11 @@ pub fn test_gglwe_switching_key_encrypt_sk<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
ksk.key
|
||||
.assert_noise(module, &sk_out_prepared, &sk_in.data, sigma);
|
||||
.assert_noise(module, &sk_out_prepared, &sk_in.data, SIGMA);
|
||||
}
|
||||
|
||||
pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>(
|
||||
@@ -107,7 +108,6 @@ pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>(
|
||||
digits: usize,
|
||||
rank_in: usize,
|
||||
rank_out: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -174,7 +174,6 @@ pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>(
|
||||
&sk_out,
|
||||
seed_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -182,5 +181,5 @@ pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>(
|
||||
ksk.decompress(module, &ksk_compressed);
|
||||
|
||||
ksk.key
|
||||
.assert_noise(module, &sk_out_prepared, &sk_in.data, sigma);
|
||||
.assert_noise(module, &sk_out_prepared, &sk_in.data, SIGMA);
|
||||
}
|
||||
|
||||
@@ -14,13 +14,16 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
GGSWCiphertext, GLWESecret,
|
||||
compressed::{Decompress, GGSWCiphertextCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGSWCiphertext, GLWESecret,
|
||||
compressed::{Decompress, GGSWCiphertextCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_ggsw_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64)
|
||||
pub fn test_ggsw_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -89,16 +92,15 @@ where
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let noise_f = |_col_i: usize| -(k as f64) + sigma.log2() + 0.5;
|
||||
let noise_f = |_col_i: usize| -(k as f64) + SIGMA.log2() + 0.5;
|
||||
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f);
|
||||
}
|
||||
|
||||
pub fn test_ggsw_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize, sigma: f64)
|
||||
pub fn test_ggsw_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, digits: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -167,11 +169,10 @@ where
|
||||
&sk_prepared,
|
||||
seed_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let noise_f = |_col_i: usize| -(k as f64) + sigma.log2() + 0.5;
|
||||
let noise_f = |_col_i: usize| -(k as f64) + SIGMA.log2() + 0.5;
|
||||
|
||||
let mut ct: GGSWCiphertext<Vec<u8>> = GGSWCiphertext::alloc(n, basek, k, rows, digits, rank);
|
||||
ct.decompress(module, &ct_compressed);
|
||||
|
||||
@@ -15,6 +15,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GLWECiphertext, GLWEPlaintext, GLWEPublicKey, GLWESecret, Infos,
|
||||
compressed::{Decompress, GLWECiphertextCompressed},
|
||||
@@ -23,7 +24,7 @@ use crate::{
|
||||
operations::GLWEOperations,
|
||||
};
|
||||
|
||||
pub fn test_glwe_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize)
|
||||
pub fn test_glwe_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigAllocBytes
|
||||
@@ -96,7 +97,6 @@ where
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -105,12 +105,12 @@ where
|
||||
pt_want.sub_inplace_ab(module, &pt_have);
|
||||
|
||||
let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
|
||||
let noise_want: f64 = sigma;
|
||||
let noise_want: f64 = SIGMA;
|
||||
|
||||
assert!(noise_have <= noise_want + 0.2);
|
||||
}
|
||||
|
||||
pub fn test_glwe_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, sigma: f64, rank: usize)
|
||||
pub fn test_glwe_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pt: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigAllocBytes
|
||||
@@ -187,7 +187,6 @@ where
|
||||
&sk_prepared,
|
||||
seed_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -199,7 +198,7 @@ where
|
||||
pt_want.sub_inplace_ab(module, &pt_have);
|
||||
|
||||
let noise_have: f64 = pt_want.data.std(basek, 0) * (ct.k() as f64).exp2();
|
||||
let noise_want: f64 = sigma;
|
||||
let noise_want: f64 = SIGMA;
|
||||
|
||||
assert!(
|
||||
noise_have <= noise_want + 0.2,
|
||||
@@ -209,7 +208,7 @@ where
|
||||
);
|
||||
}
|
||||
|
||||
pub fn test_glwe_encrypt_zero_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, sigma: f64, rank: usize)
|
||||
pub fn test_glwe_encrypt_zero_sk<B>(module: &Module<B>, basek: usize, k_ct: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigAllocBytes
|
||||
@@ -279,15 +278,14 @@ where
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
ct.decrypt(module, &mut pt, &sk_prepared, scratch.borrow());
|
||||
|
||||
assert!((sigma - pt.data.std(basek, 0) * (k_ct as f64).exp2()) <= 0.2);
|
||||
assert!((SIGMA - pt.data.std(basek, 0) * (k_ct as f64).exp2()) <= 0.2);
|
||||
}
|
||||
|
||||
pub fn test_glwe_encrypt_pk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, sigma: f64, rank: usize)
|
||||
pub fn test_glwe_encrypt_pk<B>(module: &Module<B>, basek: usize, k_ct: usize, k_pk: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -343,7 +341,7 @@ where
|
||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, B> = sk.prepare_alloc(module, scratch.borrow());
|
||||
|
||||
let mut pk: GLWEPublicKey<Vec<u8>> = GLWEPublicKey::alloc(n, basek, k_pk, rank);
|
||||
pk.generate_from_sk(module, &sk_prepared, &mut source_xa, &mut source_xe, sigma);
|
||||
pk.generate_from_sk(module, &sk_prepared, &mut source_xa, &mut source_xe);
|
||||
|
||||
module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, k_ct, &mut source_xa);
|
||||
|
||||
@@ -355,7 +353,6 @@ where
|
||||
&pk_prepared,
|
||||
&mut source_xu,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -364,7 +361,7 @@ where
|
||||
pt_want.sub_inplace_ab(module, &pt_have);
|
||||
|
||||
let noise_have: f64 = pt_want.data.std(basek, 0).log2();
|
||||
let noise_want: f64 = ((((rank as f64) + 1.0) * n as f64 * 0.5 * sigma * sigma).sqrt()).log2() - (k_ct as f64);
|
||||
let noise_want: f64 = ((((rank as f64) + 1.0) * n as f64 * 0.5 * SIGMA * SIGMA).sqrt()).log2() - (k_ct as f64);
|
||||
|
||||
assert!(
|
||||
noise_have <= noise_want + 0.2,
|
||||
|
||||
@@ -14,13 +14,16 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
GGLWETensorKey, GLWEPlaintext, GLWESecret, Infos,
|
||||
compressed::{Decompress, GGLWETensorKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWETensorKey, GLWEPlaintext, GLWESecret, Infos,
|
||||
compressed::{Decompress, GGLWETensorKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_glwe_tensor_key_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
||||
pub fn test_glwe_tensor_key_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -87,7 +90,6 @@ where
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -124,14 +126,14 @@ where
|
||||
module.vec_znx_sub_scalar_inplace(&mut pt.data, 0, row_i, &sk_ij.data, col_i);
|
||||
|
||||
let std_pt: f64 = pt.data.std(basek, 0) * (k as f64).exp2();
|
||||
assert!((sigma - std_pt).abs() <= 0.5, "{} {}", sigma, std_pt);
|
||||
assert!((SIGMA - std_pt).abs() <= 0.5, "{} {}", SIGMA, std_pt);
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn test_glwe_tensor_key_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
||||
pub fn test_glwe_tensor_key_compressed_encrypt_sk<B>(module: &Module<B>, basek: usize, k: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -195,14 +197,7 @@ where
|
||||
|
||||
let seed_xa: [u8; 32] = [1u8; 32];
|
||||
|
||||
tensor_key_compressed.encrypt_sk(
|
||||
module,
|
||||
&sk,
|
||||
seed_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
tensor_key_compressed.encrypt_sk(module, &sk, seed_xa, &mut source_xe, scratch.borrow());
|
||||
|
||||
let mut tensor_key: GGLWETensorKey<Vec<u8>> = GGLWETensorKey::alloc(n, basek, k, rows, 1, rank);
|
||||
tensor_key.decompress(module, &tensor_key_compressed);
|
||||
@@ -240,7 +235,7 @@ where
|
||||
module.vec_znx_sub_scalar_inplace(&mut pt.data, 0, row_i, &sk_ij.data, col_i);
|
||||
|
||||
let std_pt: f64 = pt.data.std(basek, 0) * (k as f64).exp2();
|
||||
assert!((sigma - std_pt).abs() <= 0.5, "{} {}", sigma, std_pt);
|
||||
assert!((SIGMA - std_pt).abs() <= 0.5, "{} {}", SIGMA, std_pt);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
@@ -16,6 +16,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GGSWCiphertext, GLWESecret,
|
||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
@@ -33,7 +34,6 @@ pub fn test_gglwe_switching_key_external_product<B>(
|
||||
digits: usize,
|
||||
rank_in: usize,
|
||||
rank_out: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -118,7 +118,6 @@ pub fn test_gglwe_switching_key_external_product<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -128,7 +127,6 @@ pub fn test_gglwe_switching_key_external_product<B>(
|
||||
&sk_out_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -141,11 +139,11 @@ pub fn test_gglwe_switching_key_external_product<B>(
|
||||
module.vec_znx_rotate_inplace(r as i64, &mut sk_in.data.as_vec_znx_mut(), i); // * X^{r}
|
||||
});
|
||||
|
||||
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||
let var_gct_err_lhs: f64 = SIGMA * SIGMA;
|
||||
let var_gct_err_rhs: f64 = 0f64;
|
||||
|
||||
let var_msg: f64 = 1f64 / n as f64; // X^{k}
|
||||
let var_a0_err: f64 = sigma * sigma;
|
||||
let var_a0_err: f64 = SIGMA * SIGMA;
|
||||
let var_a1_err: f64 = 1f64 / 12f64;
|
||||
|
||||
let max_noise: f64 = noise_ggsw_product(
|
||||
@@ -176,7 +174,6 @@ pub fn test_gglwe_switching_key_external_product_inplace<B>(
|
||||
digits: usize,
|
||||
rank_in: usize,
|
||||
rank_out: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -259,7 +256,6 @@ pub fn test_gglwe_switching_key_external_product_inplace<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -269,7 +265,6 @@ pub fn test_gglwe_switching_key_external_product_inplace<B>(
|
||||
&sk_out_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -282,11 +277,11 @@ pub fn test_gglwe_switching_key_external_product_inplace<B>(
|
||||
module.vec_znx_rotate_inplace(r as i64, &mut sk_in.data.as_vec_znx_mut(), i); // * X^{r}
|
||||
});
|
||||
|
||||
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||
let var_gct_err_lhs: f64 = SIGMA * SIGMA;
|
||||
let var_gct_err_rhs: f64 = 0f64;
|
||||
|
||||
let var_msg: f64 = 1f64 / n as f64; // X^{k}
|
||||
let var_a0_err: f64 = sigma * sigma;
|
||||
let var_a0_err: f64 = SIGMA * SIGMA;
|
||||
let var_a1_err: f64 = 1f64 / 12f64;
|
||||
|
||||
let max_noise: f64 = noise_ggsw_product(
|
||||
|
||||
@@ -16,6 +16,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGSWCiphertext, GLWESecret,
|
||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
@@ -32,7 +33,6 @@ pub fn test_ggsw_external_product<B>(
|
||||
k_ggsw: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -113,7 +113,6 @@ pub fn test_ggsw_external_product<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -123,7 +122,6 @@ pub fn test_ggsw_external_product<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -133,11 +131,11 @@ pub fn test_ggsw_external_product<B>(
|
||||
|
||||
module.vec_znx_rotate_inplace(k as i64, &mut pt_ggsw_lhs.as_vec_znx_mut(), 0);
|
||||
|
||||
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||
let var_gct_err_lhs: f64 = SIGMA * SIGMA;
|
||||
let var_gct_err_rhs: f64 = 0f64;
|
||||
|
||||
let var_msg: f64 = 1f64 / n as f64; // X^{k}
|
||||
let var_a0_err: f64 = sigma * sigma;
|
||||
let var_a0_err: f64 = SIGMA * SIGMA;
|
||||
let var_a1_err: f64 = 1f64 / 12f64;
|
||||
|
||||
let max_noise = |_col_j: usize| -> f64 {
|
||||
@@ -167,7 +165,6 @@ pub fn test_ggsw_external_product_inplace<B>(
|
||||
k_ggsw: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -248,7 +245,6 @@ pub fn test_ggsw_external_product_inplace<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -258,7 +254,6 @@ pub fn test_ggsw_external_product_inplace<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -268,11 +263,11 @@ pub fn test_ggsw_external_product_inplace<B>(
|
||||
|
||||
module.vec_znx_rotate_inplace(k as i64, &mut pt_ggsw_lhs.as_vec_znx_mut(), 0);
|
||||
|
||||
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||
let var_gct_err_lhs: f64 = SIGMA * SIGMA;
|
||||
let var_gct_err_rhs: f64 = 0f64;
|
||||
|
||||
let var_msg: f64 = 1f64 / n as f64; // X^{k}
|
||||
let var_a0_err: f64 = sigma * sigma;
|
||||
let var_a0_err: f64 = SIGMA * SIGMA;
|
||||
let var_a1_err: f64 = 1f64 / 12f64;
|
||||
|
||||
let max_noise = |_col_j: usize| -> f64 {
|
||||
|
||||
@@ -15,6 +15,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGSWCiphertext, GLWECiphertext, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
@@ -31,7 +32,6 @@ pub fn test_glwe_external_product<B>(
|
||||
k_ggsw: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -116,7 +116,6 @@ pub fn test_glwe_external_product<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -126,7 +125,6 @@ pub fn test_glwe_external_product<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -136,11 +134,11 @@ pub fn test_glwe_external_product<B>(
|
||||
|
||||
module.vec_znx_rotate_inplace(k as i64, &mut pt_want.data, 0);
|
||||
|
||||
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||
let var_gct_err_lhs: f64 = SIGMA * SIGMA;
|
||||
let var_gct_err_rhs: f64 = 0f64;
|
||||
|
||||
let var_msg: f64 = 1f64 / n as f64; // X^{k}
|
||||
let var_a0_err: f64 = sigma * sigma;
|
||||
let var_a0_err: f64 = SIGMA * SIGMA;
|
||||
let var_a1_err: f64 = 1f64 / 12f64;
|
||||
|
||||
let max_noise: f64 = noise_ggsw_product(
|
||||
@@ -168,7 +166,6 @@ pub fn test_glwe_external_product_inplace<B>(
|
||||
k_ggsw: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -243,7 +240,6 @@ pub fn test_glwe_external_product_inplace<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -253,7 +249,6 @@ pub fn test_glwe_external_product_inplace<B>(
|
||||
&sk_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -263,11 +258,11 @@ pub fn test_glwe_external_product_inplace<B>(
|
||||
|
||||
module.vec_znx_rotate_inplace(k as i64, &mut pt_want.data, 0);
|
||||
|
||||
let var_gct_err_lhs: f64 = sigma * sigma;
|
||||
let var_gct_err_lhs: f64 = SIGMA * SIGMA;
|
||||
let var_gct_err_rhs: f64 = 0f64;
|
||||
|
||||
let var_msg: f64 = 1f64 / n as f64; // X^{k}
|
||||
let var_a0_err: f64 = sigma * sigma;
|
||||
let var_a0_err: f64 = SIGMA * SIGMA;
|
||||
let var_a1_err: f64 = 1f64 / 12f64;
|
||||
|
||||
let max_noise: f64 = noise_ggsw_product(
|
||||
|
||||
@@ -15,6 +15,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GLWESecret,
|
||||
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
@@ -33,7 +34,6 @@ pub fn test_gglwe_switching_key_keyswitch<B>(
|
||||
rank_in_s0s1: usize,
|
||||
rank_out_s0s1: usize,
|
||||
rank_out_s1s2: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -132,7 +132,6 @@ pub fn test_gglwe_switching_key_keyswitch<B>(
|
||||
&sk1,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch_enc.borrow(),
|
||||
);
|
||||
|
||||
@@ -143,7 +142,6 @@ pub fn test_gglwe_switching_key_keyswitch<B>(
|
||||
&sk2,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch_enc.borrow(),
|
||||
);
|
||||
|
||||
@@ -164,7 +162,7 @@ pub fn test_gglwe_switching_key_keyswitch<B>(
|
||||
0.5,
|
||||
0.5,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank_out_s0s1 as f64,
|
||||
k_in,
|
||||
@@ -185,7 +183,6 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B>(
|
||||
digits: usize,
|
||||
rank_in: usize,
|
||||
rank_out: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -269,7 +266,6 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B>(
|
||||
&sk1,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch_enc.borrow(),
|
||||
);
|
||||
|
||||
@@ -280,7 +276,6 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B>(
|
||||
&sk2,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch_enc.borrow(),
|
||||
);
|
||||
|
||||
@@ -298,7 +293,7 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B>(
|
||||
var_xs,
|
||||
var_xs,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank_out as f64,
|
||||
k_ct,
|
||||
|
||||
@@ -16,6 +16,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GGLWETensorKey, GGSWCiphertext, GLWESecret,
|
||||
prepared::{GGLWESwitchingKeyPrepared, GGLWETensorKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
@@ -33,7 +34,6 @@ pub fn test_ggsw_keyswitch<B>(
|
||||
k_tsk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -118,7 +118,6 @@ pub fn test_ggsw_keyswitch<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
tsk.encrypt_sk(
|
||||
@@ -126,7 +125,6 @@ pub fn test_ggsw_keyswitch<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -138,7 +136,6 @@ pub fn test_ggsw_keyswitch<B>(
|
||||
&sk_in_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -160,7 +157,7 @@ pub fn test_ggsw_keyswitch<B>(
|
||||
col_j,
|
||||
var_xs,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_in,
|
||||
@@ -181,7 +178,6 @@ pub fn test_ggsw_keyswitch_inplace<B>(
|
||||
k_tsk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -263,7 +259,6 @@ pub fn test_ggsw_keyswitch_inplace<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
tsk.encrypt_sk(
|
||||
@@ -271,7 +266,6 @@ pub fn test_ggsw_keyswitch_inplace<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -283,7 +277,6 @@ pub fn test_ggsw_keyswitch_inplace<B>(
|
||||
&sk_in_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -299,7 +292,7 @@ pub fn test_ggsw_keyswitch_inplace<B>(
|
||||
col_j,
|
||||
var_xs,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_ct,
|
||||
|
||||
@@ -15,6 +15,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWESwitchingKey, GLWECiphertext, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
@@ -32,7 +33,6 @@ pub fn test_glwe_keyswitch<B>(
|
||||
digits: usize,
|
||||
rank_in: usize,
|
||||
rank_out: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
@@ -115,7 +115,6 @@ pub fn test_glwe_keyswitch<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -125,7 +124,6 @@ pub fn test_glwe_keyswitch<B>(
|
||||
&sk_in_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -139,7 +137,7 @@ pub fn test_glwe_keyswitch<B>(
|
||||
0.5,
|
||||
0.5,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank_in as f64,
|
||||
k_in,
|
||||
@@ -149,15 +147,8 @@ pub fn test_glwe_keyswitch<B>(
|
||||
ct_out.assert_noise(module, &sk_out_prepared, &pt_want, max_noise + 0.5);
|
||||
}
|
||||
|
||||
pub fn test_glwe_keyswitch_inplace<B>(
|
||||
module: &Module<B>,
|
||||
basek: usize,
|
||||
k_ct: usize,
|
||||
k_ksk: usize,
|
||||
digits: usize,
|
||||
rank: usize,
|
||||
sigma: f64,
|
||||
) where
|
||||
pub fn test_glwe_keyswitch_inplace<B>(module: &Module<B>, basek: usize, k_ct: usize, k_ksk: usize, digits: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxDftFromVecZnx<B>
|
||||
@@ -228,7 +219,6 @@ pub fn test_glwe_keyswitch_inplace<B>(
|
||||
&sk_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -238,7 +228,6 @@ pub fn test_glwe_keyswitch_inplace<B>(
|
||||
&sk_in_prepared,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -252,7 +241,7 @@ pub fn test_glwe_keyswitch_inplace<B>(
|
||||
0.5,
|
||||
0.5,
|
||||
0f64,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0f64,
|
||||
rank as f64,
|
||||
k_ct,
|
||||
|
||||
@@ -62,7 +62,6 @@ where
|
||||
{
|
||||
let n: usize = module.n();
|
||||
let basek: usize = 17;
|
||||
let sigma: f64 = 3.2;
|
||||
|
||||
let n_lwe_in: usize = 22;
|
||||
let n_lwe_out: usize = 30;
|
||||
@@ -99,7 +98,6 @@ where
|
||||
&sk_lwe_in,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
);
|
||||
|
||||
let mut ksk: LWESwitchingKey<Vec<u8>> = LWESwitchingKey::alloc(n, basek, k_ksk, lwe_ct_in.size());
|
||||
@@ -110,7 +108,6 @@ where
|
||||
&sk_lwe_out,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@ where
|
||||
let k_ct: usize = 36;
|
||||
let pt_k: usize = 18;
|
||||
let rank: usize = 3;
|
||||
let sigma: f64 = 3.2;
|
||||
let digits: usize = 1;
|
||||
let k_ksk: usize = k_ct + basek * digits;
|
||||
|
||||
@@ -118,7 +117,6 @@ where
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
let atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow());
|
||||
@@ -137,7 +135,6 @@ where
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -150,7 +147,6 @@ where
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GLWECiphertext, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GGLWEAutomorphismKeyPrepared, GLWESecretPrepared, PrepareAlloc},
|
||||
@@ -26,7 +27,7 @@ use crate::{
|
||||
noise::var_noise_gglwe_product,
|
||||
};
|
||||
|
||||
pub fn test_glwe_trace_inplace<B>(module: &Module<B>, basek: usize, k: usize, sigma: f64, rank: usize)
|
||||
pub fn test_glwe_trace_inplace<B>(module: &Module<B>, basek: usize, k: usize, rank: usize)
|
||||
where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxAutomorphism
|
||||
@@ -110,7 +111,6 @@ where
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
@@ -124,7 +124,6 @@ where
|
||||
&sk,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
let atk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> = tmp.prepare_alloc(module, scratch.borrow());
|
||||
@@ -149,13 +148,13 @@ where
|
||||
0.5,
|
||||
0.5,
|
||||
1.0 / 12.0,
|
||||
sigma * sigma,
|
||||
SIGMA * SIGMA,
|
||||
0.0,
|
||||
rank as f64,
|
||||
k,
|
||||
k_autokey,
|
||||
);
|
||||
noise_want += sigma * sigma * (-2.0 * (k) as f64).exp2();
|
||||
noise_want += SIGMA * SIGMA * (-2.0 * (k) as f64).exp2();
|
||||
noise_want += n as f64 * 1.0 / 12.0 * 0.5 * rank as f64 * (-2.0 * (k) as f64).exp2();
|
||||
noise_want = noise_want.sqrt().log2();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ fn gglwe_switching_key_encrypt_sk() {
|
||||
"test_gglwe_switching_key_encrypt_sk digits: {} ranks: ({} {})",
|
||||
di, rank_in, rank_out
|
||||
);
|
||||
test_gglwe_switching_key_encrypt_sk(&module, basek, k_ksk, di, rank_in, rank_out, 3.2);
|
||||
test_gglwe_switching_key_encrypt_sk(&module, basek, k_ksk, di, rank_in, rank_out);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -46,7 +46,7 @@ fn gglwe_switching_key_compressed_encrypt_sk() {
|
||||
"test_gglwe_switching_key_compressed_encrypt_sk digits: {} ranks: ({} {})",
|
||||
di, rank_in, rank_out
|
||||
);
|
||||
test_gglwe_switching_key_compressed_encrypt_sk(&module, basek, k_ksk, di, rank_in, rank_out, 3.2);
|
||||
test_gglwe_switching_key_compressed_encrypt_sk(&module, basek, k_ksk, di, rank_in, rank_out);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -79,7 +79,6 @@ fn gglwe_switching_key_keyswitch() {
|
||||
rank_in_s0s1,
|
||||
rank_out_s0s1,
|
||||
rank_out_s1s2,
|
||||
3.2,
|
||||
);
|
||||
})
|
||||
})
|
||||
@@ -102,16 +101,7 @@ fn gglwe_switching_key_keyswitch_inplace() {
|
||||
"test_gglwe_switching_key_keyswitch_inplace digits: {} ranks: ({},{})",
|
||||
di, rank_in_s0s1, rank_out_s0s1
|
||||
);
|
||||
test_gglwe_switching_key_keyswitch_inplace(
|
||||
&module,
|
||||
basek,
|
||||
k_ct,
|
||||
k_ksk,
|
||||
di,
|
||||
rank_in_s0s1,
|
||||
rank_out_s0s1,
|
||||
3.2,
|
||||
);
|
||||
test_gglwe_switching_key_keyswitch_inplace(&module, basek, k_ct, k_ksk, di, rank_in_s0s1, rank_out_s0s1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -133,9 +123,7 @@ fn gglwe_switching_key_external_product() {
|
||||
di, rank_in, rank_out
|
||||
);
|
||||
let k_out: usize = k_in; // Better capture noise.
|
||||
test_gglwe_switching_key_external_product(
|
||||
&module, basek, k_out, k_in, k_ggsw, di, rank_in, rank_out, 3.2,
|
||||
);
|
||||
test_gglwe_switching_key_external_product(&module, basek, k_out, k_in, k_ggsw, di, rank_in, rank_out);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -156,7 +144,7 @@ fn gglwe_switching_key_external_product_inplace() {
|
||||
"test_gglwe_switching_key_external_product_inplace digits: {} ranks: ({} {})",
|
||||
di, rank_in, rank_out
|
||||
);
|
||||
test_gglwe_switching_key_external_product_inplace(&module, basek, k_ct, k_ggsw, di, rank_in, rank_out, 3.2);
|
||||
test_gglwe_switching_key_external_product_inplace(&module, basek, k_ct, k_ggsw, di, rank_in, rank_out);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -169,14 +157,13 @@ fn gglwe_automorphisk_key_encrypt_sk() {
|
||||
let basek: usize = 12;
|
||||
let k: usize = 60;
|
||||
let digits: usize = k.div_ceil(basek) - 1;
|
||||
let sigma: f64 = 3.2;
|
||||
(1..4).for_each(|rank| {
|
||||
(2..digits + 1).for_each(|di| {
|
||||
println!(
|
||||
"test_gglwe_automorphisk_key_encrypt_sk digits: {} rank: {}",
|
||||
di, rank
|
||||
);
|
||||
test_gglwe_automorphisk_key_encrypt_sk(&module, basek, k, di, rank, sigma);
|
||||
test_gglwe_automorphisk_key_encrypt_sk(&module, basek, k, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -188,14 +175,13 @@ fn gglwe_automorphisk_key_compressed_encrypt_sk() {
|
||||
let basek: usize = 12;
|
||||
let k: usize = 60;
|
||||
let digits: usize = k.div_ceil(basek) - 1;
|
||||
let sigma: f64 = 3.2;
|
||||
(1..4).for_each(|rank| {
|
||||
(2..digits + 1).for_each(|di| {
|
||||
println!(
|
||||
"test_gglwe_automorphisk_key_compressed_encrypt_sk digits: {} rank: {}",
|
||||
di, rank
|
||||
);
|
||||
test_gglwe_automorphisk_key_compressed_encrypt_sk(&module, basek, k, di, rank, sigma);
|
||||
test_gglwe_automorphisk_key_compressed_encrypt_sk(&module, basek, k, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -208,7 +194,6 @@ fn gglwe_automorphism_key_automorphism() {
|
||||
let k_in: usize = 60;
|
||||
let k_out: usize = 40;
|
||||
let digits: usize = k_in.div_ceil(basek);
|
||||
let sigma: f64 = 3.2;
|
||||
(1..4).for_each(|rank| {
|
||||
(2..digits + 1).for_each(|di| {
|
||||
println!(
|
||||
@@ -216,7 +201,7 @@ fn gglwe_automorphism_key_automorphism() {
|
||||
di, rank
|
||||
);
|
||||
let k_apply: usize = (digits + di) * basek;
|
||||
test_gglwe_automorphism_key_automorphism(&module, -1, 5, basek, di, k_in, k_out, k_apply, sigma, rank);
|
||||
test_gglwe_automorphism_key_automorphism(&module, -1, 5, basek, di, k_in, k_out, k_apply, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -228,7 +213,6 @@ fn gglwe_automorphism_key_automorphism_inplace() {
|
||||
let basek: usize = 12;
|
||||
let k_in: usize = 60;
|
||||
let digits: usize = k_in.div_ceil(basek);
|
||||
let sigma: f64 = 3.2;
|
||||
(1..4).for_each(|rank| {
|
||||
(2..digits + 1).for_each(|di| {
|
||||
println!(
|
||||
@@ -236,7 +220,7 @@ fn gglwe_automorphism_key_automorphism_inplace() {
|
||||
di, rank
|
||||
);
|
||||
let k_apply: usize = (digits + di) * basek;
|
||||
test_gglwe_automorphism_key_automorphism_inplace(&module, -1, 5, basek, di, k_in, k_apply, sigma, rank);
|
||||
test_gglwe_automorphism_key_automorphism_inplace(&module, -1, 5, basek, di, k_in, k_apply, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -247,7 +231,7 @@ fn glwe_tensor_key_encrypt_sk() {
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(1 << log_n);
|
||||
(1..4).for_each(|rank| {
|
||||
println!("test_glwe_tensor_key_encrypt_sk rank: {}", rank);
|
||||
test_glwe_tensor_key_encrypt_sk(&module, 16, 54, 3.2, rank);
|
||||
test_glwe_tensor_key_encrypt_sk(&module, 16, 54, rank);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -257,6 +241,6 @@ fn glwe_tensor_key_compressed_encrypt_sk() {
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(1 << log_n);
|
||||
(1..4).for_each(|rank| {
|
||||
println!("test_glwe_tensor_key_compressed_encrypt_sk rank: {}", rank);
|
||||
test_glwe_tensor_key_compressed_encrypt_sk(&module, 16, 54, 3.2, rank);
|
||||
test_glwe_tensor_key_compressed_encrypt_sk(&module, 16, 54, rank);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ fn ggsw_encrypt_sk() {
|
||||
(1..4).for_each(|rank| {
|
||||
(1..digits + 1).for_each(|di| {
|
||||
println!("test_ggsw_encrypt_sk digits: {} rank: {}", di, rank);
|
||||
test_ggsw_encrypt_sk(&module, basek, k_ct, di, rank, 3.2);
|
||||
test_ggsw_encrypt_sk(&module, basek, k_ct, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -36,7 +36,7 @@ fn ggsw_compressed_encrypt_sk() {
|
||||
"test_ggsw_compressed_encrypt_sk digits: {} rank: {}",
|
||||
di, rank
|
||||
);
|
||||
test_ggsw_compressed_encrypt_sk(&module, basek, k_ct, di, rank, 3.2);
|
||||
test_ggsw_compressed_encrypt_sk(&module, basek, k_ct, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -54,7 +54,7 @@ fn ggsw_keyswitch() {
|
||||
let k_tsk: usize = k_ksk;
|
||||
println!("test_ggsw_keyswitch digits: {} rank: {}", di, rank);
|
||||
let k_out: usize = k_ksk; // Better capture noise.
|
||||
test_ggsw_keyswitch(&module, basek, k_out, k_in, k_ksk, k_tsk, di, rank, 3.2);
|
||||
test_ggsw_keyswitch(&module, basek, k_out, k_in, k_ksk, k_tsk, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -71,7 +71,7 @@ fn ggsw_keyswitch_inplace() {
|
||||
let k_ksk: usize = k_ct + basek * di;
|
||||
let k_tsk: usize = k_ksk;
|
||||
println!("test_ggsw_keyswitch_inplace digits: {} rank: {}", di, rank);
|
||||
test_ggsw_keyswitch_inplace(&module, basek, k_ct, k_ksk, k_tsk, di, rank, 3.2);
|
||||
test_ggsw_keyswitch_inplace(&module, basek, k_ct, k_ksk, k_tsk, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -89,7 +89,7 @@ fn ggsw_automorphism() {
|
||||
let k_tsk: usize = k_ksk;
|
||||
println!("test_ggsw_automorphism rank: {}", rank);
|
||||
let k_out: usize = k_ksk; // Better capture noise.
|
||||
test_ggsw_automorphism(-5, &module, basek, k_out, k_in, k_ksk, k_tsk, di, rank, 3.2);
|
||||
test_ggsw_automorphism(-5, &module, basek, k_out, k_in, k_ksk, k_tsk, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -106,7 +106,7 @@ fn ggsw_automorphism_inplace() {
|
||||
let k_ksk: usize = k_ct + basek * di;
|
||||
let k_tsk: usize = k_ksk;
|
||||
println!("test_ggsw_automorphism_inplace rank: {}", rank);
|
||||
test_ggsw_automorphism_inplace(-5, &module, basek, k_ct, k_ksk, k_tsk, di, rank, 3.2);
|
||||
test_ggsw_automorphism_inplace(-5, &module, basek, k_ct, k_ksk, k_tsk, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -123,7 +123,7 @@ fn ggsw_external_product() {
|
||||
let k_ggsw: usize = k_in + basek * di;
|
||||
println!("test external_product digits: {} ranks: {}", di, rank);
|
||||
let k_out: usize = k_in; // Better capture noise.
|
||||
test_ggsw_external_product(&module, basek, k_in, k_out, k_ggsw, di, rank, 3.2);
|
||||
test_ggsw_external_product(&module, basek, k_in, k_out, k_ggsw, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -142,7 +142,7 @@ fn ggsw_external_product_inplace() {
|
||||
"test_ggsw_external_product_inplace digits: {} rank: {}",
|
||||
di, rank
|
||||
);
|
||||
test_ggsw_external_product_inplace(&module, basek, k_ct, k_ggsw, di, rank, 3.2);
|
||||
test_ggsw_external_product_inplace(&module, basek, k_ct, k_ggsw, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ fn glwe_encrypt_sk() {
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(1 << log_n);
|
||||
(1..4).for_each(|rank| {
|
||||
println!("test_glwe_encrypt_sk rank: {}", rank);
|
||||
test_glwe_encrypt_sk(&module, 8, 54, 30, 3.2, rank);
|
||||
test_glwe_encrypt_sk(&module, 8, 54, 30, rank);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ fn glwe_compressed_encrypt_sk() {
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(1 << log_n);
|
||||
(1..4).for_each(|rank| {
|
||||
println!("test_glwe_compressed_encrypt_sk rank: {}", rank);
|
||||
test_glwe_compressed_encrypt_sk(&module, 8, 54, 30, 3.2, rank);
|
||||
test_glwe_compressed_encrypt_sk(&module, 8, 54, 30, rank);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ fn glwe_encrypt_zero_sk() {
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(1 << log_n);
|
||||
(1..4).for_each(|rank| {
|
||||
println!("test_glwe_encrypt_zero_sk rank: {}", rank);
|
||||
test_glwe_encrypt_zero_sk(&module, 8, 64, 3.2, rank);
|
||||
test_glwe_encrypt_zero_sk(&module, 8, 64, rank);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ fn glwe_encrypt_pk() {
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(1 << log_n);
|
||||
(1..4).for_each(|rank| {
|
||||
println!("test_glwe_encrypt_pk rank: {}", rank);
|
||||
test_glwe_encrypt_pk(&module, 8, 64, 64, 3.2, rank)
|
||||
test_glwe_encrypt_pk(&module, 8, 64, 64, rank)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,9 +65,7 @@ fn glwe_keyswitch() {
|
||||
"test_glwe_keyswitch digits: {} rank_in: {} rank_out: {}",
|
||||
di, rank_in, rank_out
|
||||
);
|
||||
test_glwe_keyswitch(
|
||||
&module, basek, k_out, k_in, k_ksk, di, rank_in, rank_out, 3.2,
|
||||
);
|
||||
test_glwe_keyswitch(&module, basek, k_out, k_in, k_ksk, di, rank_in, rank_out);
|
||||
})
|
||||
});
|
||||
});
|
||||
@@ -84,7 +82,7 @@ fn glwe_keyswitch_inplace() {
|
||||
(1..digits + 1).for_each(|di| {
|
||||
let k_ksk: usize = k_ct + basek * di;
|
||||
println!("test_glwe_keyswitch_inplace digits: {} rank: {}", di, rank);
|
||||
test_glwe_keyswitch_inplace(&module, basek, k_ct, k_ksk, di, rank, 3.2);
|
||||
test_glwe_keyswitch_inplace(&module, basek, k_ct, k_ksk, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -101,7 +99,7 @@ fn glwe_automorphism() {
|
||||
let k_ksk: usize = k_in + basek * di;
|
||||
let k_out: usize = k_ksk; // Better capture noise.
|
||||
println!("test_glwe_automorphism digits: {} rank: {}", di, rank);
|
||||
test_glwe_automorphism(&module, basek, -5, k_out, k_in, k_ksk, di, rank, 3.2);
|
||||
test_glwe_automorphism(&module, basek, -5, k_out, k_in, k_ksk, di, rank);
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -120,7 +118,7 @@ fn glwe_automorphism_inplace() {
|
||||
"test_glwe_automorphism_inplace digits: {} rank: {}",
|
||||
di, rank
|
||||
);
|
||||
test_glwe_automorphism_inplace(&module, basek, -5, k_ct, k_ksk, di, rank, 3.2);
|
||||
test_glwe_automorphism_inplace(&module, basek, -5, k_ct, k_ksk, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -137,7 +135,7 @@ fn glwe_external_product() {
|
||||
let k_ggsw: usize = k_in + basek * di;
|
||||
let k_out: usize = k_ggsw; // Better capture noise
|
||||
println!("test_glwe_external_product digits: {} rank: {}", di, rank);
|
||||
test_glwe_external_product(&module, basek, k_out, k_in, k_ggsw, di, rank, 3.2);
|
||||
test_glwe_external_product(&module, basek, k_out, k_in, k_ggsw, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -156,7 +154,7 @@ fn glwe_external_product_inplace() {
|
||||
"test_glwe_external_product_inplace digits: {} rank: {}",
|
||||
di, rank
|
||||
);
|
||||
test_glwe_external_product_inplace(&module, basek, k_ct, k_ggsw, di, rank, 3.2);
|
||||
test_glwe_external_product_inplace(&module, basek, k_ct, k_ggsw, di, rank);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -167,7 +165,7 @@ fn glwe_trace_inplace() {
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(1 << log_n);
|
||||
(1..4).for_each(|rank| {
|
||||
println!("test_glwe_trace_inplace rank: {}", rank);
|
||||
test_glwe_trace_inplace(&module, 8, 54, 3.2, rank);
|
||||
test_glwe_trace_inplace(&module, 8, 54, rank);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user