mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Update doc & readme (#122)
* update poulpy_arch.svg * update main readme * update lib_diagram.png & main readme * update poulpy-core readme * update backend readmes * update poulpy-hal readme * update poulpy-schemes readme * update CHANGELOG.md
This commit is contained in:
committed by
GitHub
parent
ad837c8fa8
commit
8a039e1c3a
@@ -5,14 +5,14 @@
|
||||
## Getting Started
|
||||
|
||||
```rust
|
||||
use poulpy_backend::cpu_spqlios::FFT64;
|
||||
use poulpy_core::{
|
||||
GLWEOperations, SIGMA,
|
||||
GLWESub, SIGMA,
|
||||
layouts::{
|
||||
GLWECiphertext, GLWEPlaintext, GLWESecret, Infos,
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
Base2K, Degree, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
use poulpy_cpu_ref::FFT64Ref;
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform},
|
||||
layouts::{Module, ScratchOwned},
|
||||
@@ -23,27 +23,36 @@ fn main() {
|
||||
// Ring degree
|
||||
let log_n: usize = 10;
|
||||
|
||||
let n: usize = 1<<log_n;
|
||||
let n: Degree = Degree(1 << log_n);
|
||||
|
||||
// Base-2-k (implicit digit decomposition)
|
||||
let base2k: usize = 14;
|
||||
let base2k: Base2K = Base2K(14);
|
||||
|
||||
// Ciphertext Torus precision (equivalent to ciphertext modulus)
|
||||
let k_ct: usize = 27;
|
||||
let k_ct: TorusPrecision = TorusPrecision(27);
|
||||
|
||||
// Plaintext Torus precision (equivament to plaintext modulus)
|
||||
let k_pt: usize = base2k;
|
||||
let k_pt: TorusPrecision = TorusPrecision(base2k.into());
|
||||
|
||||
// GLWE rank
|
||||
let rank: usize = 1;
|
||||
let rank: Rank = Rank(1);
|
||||
|
||||
// Instantiate Module (DFT Tables)
|
||||
let module: Module<FFT64> = Module::<FFT64>::new(n as u64);
|
||||
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(n.0 as u64);
|
||||
|
||||
let glwe_ct_infos: GLWELayout = GLWELayout {
|
||||
n,
|
||||
base2k,
|
||||
k: k_ct,
|
||||
rank,
|
||||
};
|
||||
|
||||
let glwe_pt_infos: GLWEPlaintextLayout = GLWEPlaintextLayout { n, base2k, k: k_pt };
|
||||
|
||||
// Allocates ciphertext & plaintexts
|
||||
let mut ct: GLWECiphertext<Vec<u8>> = GLWECiphertext::alloc(n, base2k, k_ct, rank);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, base2k, k_pt);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, base2k, k_pt);
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_ct_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_infos);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_pt_infos);
|
||||
|
||||
// CPRNG
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
@@ -51,20 +60,20 @@ fn main() {
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
|
||||
// Scratch space
|
||||
let mut scratch: ScratchOwned<FFT64> = ScratchOwned::alloc(
|
||||
GLWECiphertext::encrypt_sk_tmp_bytes(&module, n, base2k, ct.k())
|
||||
| GLWECiphertext::decrypt_tmp_bytes(&module, n, base2k, ct.k()),
|
||||
let mut scratch: ScratchOwned<FFT64Ref> = ScratchOwned::alloc(
|
||||
GLWE::encrypt_sk_tmp_bytes(&module, &glwe_ct_infos) | GLWE::decrypt_tmp_bytes(&module, &glwe_ct_infos),
|
||||
);
|
||||
|
||||
// Generate secret-key
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_ct_infos);
|
||||
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());
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, FFT64Ref> = GLWESecretPrepared::alloc(&module, rank);
|
||||
sk_prepared.prepare(&module, &sk);
|
||||
|
||||
// Uniform plaintext
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, k_pt, &mut source_xa);
|
||||
module.vec_znx_fill_uniform(base2k.into(), &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
// Encryption
|
||||
ct.encrypt_sk(
|
||||
@@ -80,10 +89,10 @@ fn main() {
|
||||
ct.decrypt(&module, &mut pt_have, &sk_prepared, scratch.borrow());
|
||||
|
||||
// Diff between pt - Dec(Enc(pt))
|
||||
pt_want.sub_inplace_ab(&module, &pt_have);
|
||||
module.glwe_sub_inplace(&mut pt_want, &pt_have);
|
||||
|
||||
// Ideal vs. actual noise
|
||||
let noise_have: f64 = pt_want.data.std(base2k, 0) * (ct.k() as f64).exp2();
|
||||
let noise_have: f64 = pt_want.data.stats(base2k.into(), 0).std() * (ct.k().as_u32() as f64).exp2();
|
||||
let noise_want: f64 = SIGMA;
|
||||
|
||||
// Check
|
||||
@@ -169,4 +178,4 @@ ggsw.automorphism(...);
|
||||
|
||||
## Tests
|
||||
|
||||
A fully generic test suite is available in [`src/tests/generics`](./src/tests/generics).
|
||||
A fully generic test suite is available in [`src/tests/test_suite`](./src/tests/test_suite).
|
||||
Reference in New Issue
Block a user