mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
Reorganized other crates
This commit is contained in:
@@ -2,7 +2,7 @@ use backend::{Decoding, Encoding, FFT64, Module, ScratchOwned, Stats, VecZnxOps,
|
||||
use itertools::izip;
|
||||
use sampling::source::Source;
|
||||
|
||||
use crate::{FourierGLWECiphertext, GLWECiphertext, GLWEPlaintext, GLWEPublicKey, GLWESecret, Infos};
|
||||
use crate::{FourierGLWECiphertext, FourierGLWESecret, GLWECiphertext, GLWEPlaintext, GLWEPublicKey, GLWESecret, Infos};
|
||||
|
||||
#[test]
|
||||
fn encrypt_sk() {
|
||||
@@ -46,8 +46,9 @@ fn test_encrypt_sk(log_n: usize, basek: usize, k_ct: usize, k_pt: usize, sigma:
|
||||
| GLWECiphertext::decrypt_scratch_space(&module, basek, ct.k()),
|
||||
);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>, FFT64> = GLWESecret::alloc(&module, rank);
|
||||
sk.fill_ternary_prob(&module, 0.5, &mut source_xs);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(&module, rank);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let sk_dft: FourierGLWESecret<Vec<u8>, FFT64> = FourierGLWESecret::from(&module, &sk);
|
||||
|
||||
let mut data_want: Vec<i64> = vec![0i64; module.n()];
|
||||
|
||||
@@ -60,7 +61,7 @@ fn test_encrypt_sk(log_n: usize, basek: usize, k_ct: usize, k_pt: usize, sigma:
|
||||
ct.encrypt_sk(
|
||||
&module,
|
||||
&pt,
|
||||
&sk,
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
@@ -69,7 +70,7 @@ fn test_encrypt_sk(log_n: usize, basek: usize, k_ct: usize, k_pt: usize, sigma:
|
||||
|
||||
pt.data.zero();
|
||||
|
||||
ct.decrypt(&module, &mut pt, &sk, scratch.borrow());
|
||||
ct.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
||||
|
||||
let mut data_have: Vec<i64> = vec![0i64; module.n()];
|
||||
|
||||
@@ -98,8 +99,9 @@ fn test_encrypt_zero_sk(log_n: usize, basek: usize, k_ct: usize, sigma: f64, ran
|
||||
let mut source_xe: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>, FFT64> = GLWESecret::alloc(&module, rank);
|
||||
sk.fill_ternary_prob(&module, 0.5, &mut source_xs);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(&module, rank);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let sk_dft: FourierGLWESecret<Vec<u8>, FFT64> = FourierGLWESecret::from(&module, &sk);
|
||||
|
||||
let mut ct_dft: FourierGLWECiphertext<Vec<u8>, FFT64> = FourierGLWECiphertext::alloc(&module, basek, k_ct, rank);
|
||||
|
||||
@@ -110,13 +112,13 @@ fn test_encrypt_zero_sk(log_n: usize, basek: usize, k_ct: usize, sigma: f64, ran
|
||||
|
||||
ct_dft.encrypt_zero_sk(
|
||||
&module,
|
||||
&sk,
|
||||
&sk_dft,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
sigma,
|
||||
scratch.borrow(),
|
||||
);
|
||||
ct_dft.decrypt(&module, &mut pt, &sk, scratch.borrow());
|
||||
ct_dft.decrypt(&module, &mut pt, &sk_dft, scratch.borrow());
|
||||
|
||||
assert!((sigma - pt.data.std(0, basek) * (k_ct as f64).exp2()) <= 0.2);
|
||||
}
|
||||
@@ -132,11 +134,12 @@ fn test_encrypt_pk(log_n: usize, basek: usize, k_ct: usize, k_pk: usize, sigma:
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
let mut source_xu: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>, FFT64> = GLWESecret::alloc(&module, rank);
|
||||
sk.fill_ternary_prob(&module, 0.5, &mut source_xs);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(&module, rank);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let sk_dft: FourierGLWESecret<Vec<u8>, FFT64> = FourierGLWESecret::from(&module, &sk);
|
||||
|
||||
let mut pk: GLWEPublicKey<Vec<u8>, FFT64> = GLWEPublicKey::alloc(&module, basek, k_pk, rank);
|
||||
pk.generate_from_sk(&module, &sk, &mut source_xa, &mut source_xe, sigma);
|
||||
pk.generate_from_sk(&module, &sk_dft, &mut source_xa, &mut source_xe, sigma);
|
||||
|
||||
let mut scratch: ScratchOwned = ScratchOwned::new(
|
||||
GLWECiphertext::encrypt_sk_scratch_space(&module, basek, ct.k())
|
||||
@@ -164,7 +167,7 @@ fn test_encrypt_pk(log_n: usize, basek: usize, k_ct: usize, k_pk: usize, sigma:
|
||||
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(&module, basek, k_ct);
|
||||
|
||||
ct.decrypt(&module, &mut pt_have, &sk, scratch.borrow());
|
||||
ct.decrypt(&module, &mut pt_have, &sk_dft, scratch.borrow());
|
||||
|
||||
module.vec_znx_sub_ab_inplace(&mut pt_want.data, 0, &pt_have.data, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user