mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
gglwe tests
This commit is contained in:
@@ -510,7 +510,7 @@ where
|
||||
// ct[i] = uniform (+ pt)
|
||||
self.vec_znx_fill_uniform(base2k, ct, col_ct, source_xa);
|
||||
|
||||
println!("vec_znx_fill_uniform: {}", ct);
|
||||
// println!("vec_znx_fill_uniform: {}", ct);
|
||||
|
||||
let (mut ci_dft, scratch_3) = scratch_2.take_vec_znx_dft(self, 1, size);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use poulpy_hal::{
|
||||
api::{ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxSubScalarInplace},
|
||||
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxFillUniform, VecZnxSubScalarInplace},
|
||||
layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, ZnxZero},
|
||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, VecZnxSubScalarInplaceImpl},
|
||||
};
|
||||
|
||||
use crate::decryption::GLWEDecrypt;
|
||||
@@ -11,7 +10,7 @@ use crate::layouts::{
|
||||
};
|
||||
|
||||
impl<D: DataRef> GGLWE<D> {
|
||||
pub fn assert_noise<M, BE, DataSk, DataWant>(
|
||||
pub fn assert_noise<M, DataSk, DataWant, BE: Backend>(
|
||||
&self,
|
||||
module: &M,
|
||||
sk_prepared: &GLWESecretPrepared<DataSk, BE>,
|
||||
@@ -21,62 +20,12 @@ impl<D: DataRef> GGLWE<D> {
|
||||
DataSk: DataRef,
|
||||
DataWant: DataRef,
|
||||
M: GGLWENoise<BE>,
|
||||
BE: Backend
|
||||
+ ScratchOwnedAllocImpl<BE>
|
||||
+ ScratchOwnedBorrowImpl<BE>
|
||||
+ ScratchOwnedBorrow<BE>
|
||||
+ VecZnxSubScalarInplaceImpl<BE>,
|
||||
Scratch<BE>: ScratchTakeBasic,
|
||||
{
|
||||
module.gglwe_assert_noise(self, sk_prepared, pt_want, max_noise);
|
||||
}
|
||||
|
||||
// pub fn assert_noise<B, DataSk, DataWant>(
|
||||
// &self,
|
||||
// module: &Module<B>,
|
||||
// sk: &GLWESecretPrepared<DataSk, B>,
|
||||
// pt_want: &ScalarZnx<DataWant>,
|
||||
// max_noise: f64,
|
||||
// ) where
|
||||
// DataSk: DataRef,
|
||||
// DataWant: DataRef,
|
||||
// Module<B>: VecZnxDftBytesOf
|
||||
// + VecZnxBigBytesOf
|
||||
// + VecZnxDftApply<B>
|
||||
// + SvpApplyDftToDftInplace<B>
|
||||
// + VecZnxIdftApplyConsume<B>
|
||||
// + VecZnxBigAddInplace<B>
|
||||
// + VecZnxBigAddSmallInplace<B>
|
||||
// + VecZnxBigNormalize<B>
|
||||
// + VecZnxNormalizeTmpBytes
|
||||
// + VecZnxSubScalarInplace,
|
||||
// B: Backend + ScratchOwnedAllocImpl<B> + ScratchOwnedBorrowImpl<B>,
|
||||
// {
|
||||
// let dsize: usize = self.dsize().into();
|
||||
// let base2k: usize = self.base2k().into();
|
||||
|
||||
// let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWE::decrypt_tmp_bytes(module, self));
|
||||
// let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, self);
|
||||
|
||||
// (0..self.rank_in().into()).for_each(|col_i| {
|
||||
// (0..self.dnum().into()).for_each(|row_i| {
|
||||
// self.at(row_i, col_i)
|
||||
// .decrypt(module, &mut pt, sk, scratch.borrow());
|
||||
|
||||
// module.vec_znx_sub_scalar_inplace(&mut pt.data, 0, (dsize - 1) + row_i * dsize, pt_want, col_i);
|
||||
|
||||
// let noise_have: f64 = pt.data.std(base2k, 0).log2();
|
||||
|
||||
// println!("noise_have: {noise_have}");
|
||||
|
||||
// assert!(
|
||||
// noise_have <= max_noise,
|
||||
// "noise_have: {noise_have} > max_noise: {max_noise}"
|
||||
// );
|
||||
|
||||
// pt.data.zero();
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
pub trait GGLWENoise<BE: Backend> {
|
||||
@@ -85,24 +34,22 @@ pub trait GGLWENoise<BE: Backend> {
|
||||
R: GGLWEToRef,
|
||||
S: GLWESecretPreparedToRef<BE>,
|
||||
P: ScalarZnxToRef,
|
||||
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>;
|
||||
Scratch<BE>: ScratchTakeBasic;
|
||||
}
|
||||
|
||||
impl<BE: Backend> GGLWENoise<BE> for Module<BE>
|
||||
where
|
||||
Module<BE>: GLWEDecrypt<BE>,
|
||||
Scratch<BE>: ScratchTakeBasic
|
||||
+ ScratchOwnedAllocImpl<BE>
|
||||
+ ScratchOwnedBorrowImpl<BE>
|
||||
+ ScratchOwnedBorrowImpl<BE>
|
||||
+ ScratchOwnedBorrow<BE>,
|
||||
Module<BE>: GLWEDecrypt<BE> + VecZnxFillUniform + VecZnxSubScalarInplace,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeBasic,
|
||||
{
|
||||
fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64)
|
||||
where
|
||||
R: GGLWEToRef,
|
||||
S: GLWESecretPreparedToRef<BE>,
|
||||
P: ScalarZnxToRef,
|
||||
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeBasic,
|
||||
{
|
||||
let res: &GGLWE<&[u8]> = &res.to_ref();
|
||||
|
||||
@@ -125,7 +72,7 @@ where
|
||||
|
||||
let noise_have: f64 = pt.data.std(base2k, 0).log2();
|
||||
|
||||
println!("noise_have: {noise_have}");
|
||||
// println!("noise_have: {noise_have}");
|
||||
|
||||
assert!(
|
||||
noise_have <= max_noise,
|
||||
|
||||
@@ -2,6 +2,10 @@ mod gglwe_ct;
|
||||
mod ggsw_ct;
|
||||
mod glwe_ct;
|
||||
|
||||
pub use gglwe_ct::*;
|
||||
pub use ggsw_ct::*;
|
||||
pub use glwe_ct::*;
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn var_noise_gglwe_product(
|
||||
|
||||
@@ -30,8 +30,8 @@ backend_test_suite!(
|
||||
// glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace,
|
||||
// glwe_packing => crate::tests::test_suite::test_glwe_packing,
|
||||
// GGLWE Encryption
|
||||
// gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk,
|
||||
// gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk,
|
||||
gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk,
|
||||
gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk,
|
||||
// gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk,
|
||||
// gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk,
|
||||
// gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk,
|
||||
|
||||
@@ -1,66 +1,32 @@
|
||||
use poulpy_hal::{
|
||||
api::{
|
||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare,
|
||||
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace,
|
||||
VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxCopy, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform,
|
||||
VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace,
|
||||
VecZnxSubScalarInplace, VecZnxSwitchRing, VmpPMatAlloc, VmpPrepare,
|
||||
},
|
||||
layouts::{Backend, Module, ScratchOwned},
|
||||
oep::{
|
||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
||||
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl,
|
||||
ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform,
|
||||
},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWECiphertextLayout, GLWESecret, GLWESwitchingKey,
|
||||
compressed::{Decompress, GLWESwitchingKeyCompressed},
|
||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
||||
},
|
||||
decryption::GLWEDecrypt, encryption::SIGMA, layouts::{
|
||||
prepared::{GGLWEPrepare, GGLWEPreparedAlloc, GLWESecretPrepared}, GGLWELayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyCompressed, GLWESwitchingKeyDecompress
|
||||
}, noise::GGLWENoise, GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore
|
||||
};
|
||||
|
||||
pub fn test_gglwe_switching_key_encrypt_sk<B>(module: &Module<B>)
|
||||
pub fn test_gglwe_switching_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<B>: VecZnxDftBytesOf
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxDftApply<B>
|
||||
+ SvpApplyDftToDftInplace<B>
|
||||
+ VecZnxIdftApplyConsume<B>
|
||||
+ VecZnxNormalizeTmpBytes
|
||||
Module<BE>: GGLWEEncryptSk<BE>
|
||||
+ GGLWEPrepare<BE>
|
||||
+ GGLWEPreparedAlloc<BE>
|
||||
+ GGLWEKeyswitch<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESwitchingKeyAlloc
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxSubInplace
|
||||
+ VecZnxAddInplace
|
||||
+ VecZnxNormalizeInplace<B>
|
||||
+ VecZnxAddNormal
|
||||
+ VecZnxNormalize<B>
|
||||
+ VecZnxSub
|
||||
+ SvpPrepare<B>
|
||||
+ SvpPPolBytesOf
|
||||
+ SvpPPolAlloc<B>
|
||||
+ VecZnxBigAddSmallInplace<B>
|
||||
+ VecZnxSwitchRing
|
||||
+ VecZnxAddScalarInplace
|
||||
+ VecZnxBigBytesOf
|
||||
+ VecZnxBigAddInplace<B>
|
||||
+ VecZnxSubScalarInplace
|
||||
+ VecZnxCopy
|
||||
+ VmpPMatAlloc<B>
|
||||
+ VmpPrepare<B>,
|
||||
B: Backend
|
||||
+ TakeVecZnxDftImpl<B>
|
||||
+ TakeVecZnxBigImpl<B>
|
||||
+ ScratchOwnedAllocImpl<B>
|
||||
+ ScratchOwnedBorrowImpl<B>
|
||||
+ ScratchAvailableImpl<B>
|
||||
+ TakeScalarZnxImpl<B>
|
||||
+ TakeVecZnxImpl<B>
|
||||
+ VecZnxDftAllocBytesImpl<B>
|
||||
+ VecZnxBigAllocBytesImpl<B>
|
||||
+ TakeSvpPPolImpl<B>,
|
||||
+ GGLWENoise<BE>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 12;
|
||||
let k_ksk: usize = 54;
|
||||
@@ -71,7 +37,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let gglwe_infos: GGLWECiphertextLayout = GGLWECiphertextLayout {
|
||||
let gglwe_infos: GGLWELayout = GGLWELayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -81,23 +47,24 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(module, &gglwe_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKey::encrypt_sk_tmp_bytes(
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWESwitchingKey::encrypt_sk_tmp_bytes(
|
||||
module,
|
||||
&gglwe_infos,
|
||||
));
|
||||
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_in.into());
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_in.into());
|
||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_out.into());
|
||||
sk_out.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let sk_out_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_out.prepare_alloc(module, scratch.borrow());
|
||||
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank_out.into());
|
||||
sk_out_prepared.prepare(module, &sk_out);
|
||||
|
||||
ksk.encrypt_sk(
|
||||
module,
|
||||
@@ -115,44 +82,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>(module: &Module<B>)
|
||||
pub fn test_gglwe_switching_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<B>: VecZnxDftBytesOf
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxDftApply<B>
|
||||
+ SvpApplyDftToDftInplace<B>
|
||||
+ VecZnxIdftApplyConsume<B>
|
||||
+ VecZnxNormalizeTmpBytes
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxSubInplace
|
||||
+ VecZnxAddInplace
|
||||
+ VecZnxNormalizeInplace<B>
|
||||
+ VecZnxAddNormal
|
||||
+ VecZnxNormalize<B>
|
||||
+ VecZnxSub
|
||||
+ SvpPrepare<B>
|
||||
+ SvpPPolBytesOf
|
||||
+ SvpPPolAlloc<B>
|
||||
+ VecZnxBigAddSmallInplace<B>
|
||||
+ VecZnxSwitchRing
|
||||
+ VecZnxAddScalarInplace
|
||||
+ VecZnxBigBytesOf
|
||||
+ VecZnxBigAddInplace<B>
|
||||
+ VecZnxSubScalarInplace
|
||||
+ VecZnxCopy
|
||||
+ VmpPMatAlloc<B>
|
||||
+ VmpPrepare<B>,
|
||||
B: Backend
|
||||
+ TakeVecZnxDftImpl<B>
|
||||
+ TakeVecZnxBigImpl<B>
|
||||
+ ScratchOwnedAllocImpl<B>
|
||||
+ ScratchOwnedBorrowImpl<B>
|
||||
+ ScratchAvailableImpl<B>
|
||||
+ TakeScalarZnxImpl<B>
|
||||
+ TakeVecZnxImpl<B>
|
||||
+ VecZnxDftAllocBytesImpl<B>
|
||||
+ VecZnxBigAllocBytesImpl<B>
|
||||
+ TakeSvpPPolImpl<B>,
|
||||
Module<BE>: GGLWEEncryptSk<BE>
|
||||
+ GGLWEPrepare<BE>
|
||||
+ GGLWEPreparedAlloc<BE>
|
||||
+ GGLWEKeyswitch<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESwitchingKeyAlloc
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ GLWESwitchingKeyCompressedEncryptSk<BE>
|
||||
+ GLWESwitchingKeyDecompress
|
||||
+ GGLWENoise<BE>
|
||||
+ VecZnxFillUniform,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 12;
|
||||
let k_ksk: usize = 54;
|
||||
@@ -163,7 +109,7 @@ where
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let gglwe_infos: GGLWECiphertextLayout = GGLWECiphertextLayout {
|
||||
let gglwe_infos: GGLWELayout = GGLWELayout {
|
||||
n: n.into(),
|
||||
base2k: base2k.into(),
|
||||
k: k_ksk.into(),
|
||||
@@ -174,22 +120,23 @@ where
|
||||
};
|
||||
|
||||
let mut ksk_compressed: GLWESwitchingKeyCompressed<Vec<u8>> =
|
||||
GLWESwitchingKeyCompressed::alloc_from_infos(&gglwe_infos);
|
||||
GLWESwitchingKeyCompressed::alloc_from_infos(module, &gglwe_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GLWESwitchingKeyCompressed::encrypt_sk_tmp_bytes(
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWESwitchingKeyCompressed::encrypt_sk_tmp_bytes(
|
||||
module,
|
||||
&gglwe_infos,
|
||||
));
|
||||
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_in.into());
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_in.into());
|
||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_out.into());
|
||||
sk_out.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let sk_out_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_out.prepare_alloc(module, scratch.borrow());
|
||||
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank_out.into());
|
||||
sk_out_prepared.prepare(module, &sk_out);
|
||||
|
||||
let seed_xa = [1u8; 32];
|
||||
|
||||
@@ -202,7 +149,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(module, &gglwe_infos);
|
||||
ksk.decompress(module, &ksk_compressed);
|
||||
|
||||
ksk.key
|
||||
|
||||
@@ -16,17 +16,17 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_glwe_encrypt_sk<B: Backend>(module: &Module<B>)
|
||||
pub fn test_glwe_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<B>: GLWEAlloc
|
||||
+ GLWEEncryptSk<B>
|
||||
+ GLWEDecrypt<B>
|
||||
+ GLWESecretPreparedAlloc<B>
|
||||
+ GLWESecretPrepare<B>
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWEEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GLWESub,
|
||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 8;
|
||||
let k_ct: usize = 54;
|
||||
@@ -56,13 +56,13 @@ where
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> =
|
||||
let mut scratch: ScratchOwned<BE> =
|
||||
ScratchOwned::alloc(GLWE::encrypt_sk_tmp_bytes(module, &glwe_infos) | GLWE::decrypt_tmp_bytes(module, &glwe_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, B> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
@@ -87,24 +87,24 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_glwe_compressed_encrypt_sk<B: Backend>(module: &Module<B>)
|
||||
pub fn test_glwe_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<B>: GLWEAlloc
|
||||
+ GLWECompressedEncryptSk<B>
|
||||
+ GLWEDecrypt<B>
|
||||
+ GLWESecretPreparedAlloc<B>
|
||||
+ GLWESecretPrepare<B>
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWECompressedEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GLWESub,
|
||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 8;
|
||||
let k_ct: usize = 54;
|
||||
let k_pt: usize = 30;
|
||||
|
||||
for rank in 1_usize..3 {
|
||||
println!("rank: {}", rank);
|
||||
// println!("rank: {}", rank);
|
||||
let n: usize = module.n();
|
||||
|
||||
let glwe_infos: GLWELayout = GLWELayout {
|
||||
@@ -129,14 +129,14 @@ where
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||
GLWECompressed::encrypt_sk_tmp_bytes(module, &glwe_infos) | GLWE::decrypt_tmp_bytes(module, &glwe_infos),
|
||||
);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, B> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
@@ -170,17 +170,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_glwe_encrypt_zero_sk<B: Backend>(module: &Module<B>)
|
||||
pub fn test_glwe_encrypt_zero_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<B>: GLWEAlloc
|
||||
+ GLWEEncryptSk<B>
|
||||
+ GLWEDecrypt<B>
|
||||
+ GLWESecretPreparedAlloc<B>
|
||||
+ GLWESecretPrepare<B>
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWEEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GLWESub,
|
||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 8;
|
||||
let k_ct: usize = 54;
|
||||
@@ -201,13 +201,13 @@ where
|
||||
let mut source_xe: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> =
|
||||
let mut scratch: ScratchOwned<BE> =
|
||||
ScratchOwned::alloc(GLWE::decrypt_tmp_bytes(module, &glwe_infos) | GLWE::encrypt_sk_tmp_bytes(module, &glwe_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, B> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(module, &glwe_infos);
|
||||
@@ -225,20 +225,20 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_glwe_encrypt_pk<B: Backend>(module: &Module<B>)
|
||||
pub fn test_glwe_encrypt_pk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<B>: GLWEAlloc
|
||||
+ GLWEEncryptPk<B>
|
||||
+ GLWEPublicKeyPrepare<B>
|
||||
+ GLWEPublicKeyPreparedAlloc<B>
|
||||
+ GLWEPublicKeyGenerate<B>
|
||||
+ GLWEDecrypt<B>
|
||||
+ GLWESecretPreparedAlloc<B>
|
||||
+ GLWESecretPrepare<B>
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWEEncryptPk<BE>
|
||||
+ GLWEPublicKeyPrepare<BE>
|
||||
+ GLWEPublicKeyPreparedAlloc<BE>
|
||||
+ GLWEPublicKeyGenerate<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GLWESub,
|
||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 8;
|
||||
let k_ct: usize = 54;
|
||||
@@ -262,13 +262,13 @@ where
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
let mut source_xu: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<B> =
|
||||
let mut scratch: ScratchOwned<BE> =
|
||||
ScratchOwned::alloc(GLWE::decrypt_tmp_bytes(module, &glwe_infos) | GLWE::encrypt_pk_tmp_bytes(module, &glwe_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, B> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
|
||||
let mut pk: GLWEPublicKey<Vec<u8>> = GLWEPublicKey::alloc_from_infos(module, &glwe_infos);
|
||||
@@ -276,7 +276,7 @@ where
|
||||
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
let mut pk_prepared: GLWEPublicKeyPrepared<Vec<u8>, B> = GLWEPublicKeyPrepared::alloc_from_infos(module, &glwe_infos);
|
||||
let mut pk_prepared: GLWEPublicKeyPrepared<Vec<u8>, BE> = GLWEPublicKeyPrepared::alloc_from_infos(module, &glwe_infos);
|
||||
pk_prepared.prepare(module, &pk);
|
||||
|
||||
ct.encrypt_pk(
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// mod gglwe_atk;
|
||||
// mod gglwe_ct;
|
||||
mod gglwe_ct;
|
||||
// mod ggsw_ct;
|
||||
mod glwe_ct;
|
||||
// mod glwe_tsk;
|
||||
|
||||
// pub use gglwe_atk::*;
|
||||
// pub use gglwe_ct::*;
|
||||
pub use gglwe_ct::*;
|
||||
// pub use ggsw_ct::*;
|
||||
pub use glwe_ct::*;
|
||||
// pub use glwe_tsk::*;
|
||||
|
||||
Reference in New Issue
Block a user