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)
|
// ct[i] = uniform (+ pt)
|
||||||
self.vec_znx_fill_uniform(base2k, ct, col_ct, source_xa);
|
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);
|
let (mut ci_dft, scratch_3) = scratch_2.take_vec_znx_dft(self, 1, size);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxSubScalarInplace},
|
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, ScratchTakeBasic, VecZnxFillUniform, VecZnxSubScalarInplace},
|
||||||
layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, ZnxZero},
|
layouts::{Backend, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ScratchOwned, ZnxZero},
|
||||||
oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, VecZnxSubScalarInplaceImpl},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::decryption::GLWEDecrypt;
|
use crate::decryption::GLWEDecrypt;
|
||||||
@@ -11,7 +10,7 @@ use crate::layouts::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
impl<D: DataRef> GGLWE<D> {
|
impl<D: DataRef> GGLWE<D> {
|
||||||
pub fn assert_noise<M, BE, DataSk, DataWant>(
|
pub fn assert_noise<M, DataSk, DataWant, BE: Backend>(
|
||||||
&self,
|
&self,
|
||||||
module: &M,
|
module: &M,
|
||||||
sk_prepared: &GLWESecretPrepared<DataSk, BE>,
|
sk_prepared: &GLWESecretPrepared<DataSk, BE>,
|
||||||
@@ -21,62 +20,12 @@ impl<D: DataRef> GGLWE<D> {
|
|||||||
DataSk: DataRef,
|
DataSk: DataRef,
|
||||||
DataWant: DataRef,
|
DataWant: DataRef,
|
||||||
M: GGLWENoise<BE>,
|
M: GGLWENoise<BE>,
|
||||||
BE: Backend
|
Scratch<BE>: ScratchTakeBasic,
|
||||||
+ ScratchOwnedAllocImpl<BE>
|
|
||||||
+ ScratchOwnedBorrowImpl<BE>
|
|
||||||
+ ScratchOwnedBorrow<BE>
|
|
||||||
+ VecZnxSubScalarInplaceImpl<BE>,
|
|
||||||
{
|
{
|
||||||
module.gglwe_assert_noise(self, sk_prepared, pt_want, max_noise);
|
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> {
|
pub trait GGLWENoise<BE: Backend> {
|
||||||
@@ -85,24 +34,22 @@ pub trait GGLWENoise<BE: Backend> {
|
|||||||
R: GGLWEToRef,
|
R: GGLWEToRef,
|
||||||
S: GLWESecretPreparedToRef<BE>,
|
S: GLWESecretPreparedToRef<BE>,
|
||||||
P: ScalarZnxToRef,
|
P: ScalarZnxToRef,
|
||||||
BE: ScratchOwnedAllocImpl<BE> + ScratchOwnedBorrowImpl<BE> + ScratchOwnedBorrow<BE> + VecZnxSubScalarInplaceImpl<BE>;
|
Scratch<BE>: ScratchTakeBasic;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> GGLWENoise<BE> for Module<BE>
|
impl<BE: Backend> GGLWENoise<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Module<BE>: GLWEDecrypt<BE>,
|
Module<BE>: GLWEDecrypt<BE> + VecZnxFillUniform + VecZnxSubScalarInplace,
|
||||||
Scratch<BE>: ScratchTakeBasic
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ ScratchOwnedAllocImpl<BE>
|
Scratch<BE>: ScratchAvailable + ScratchTakeBasic,
|
||||||
+ ScratchOwnedBorrowImpl<BE>
|
|
||||||
+ ScratchOwnedBorrowImpl<BE>
|
|
||||||
+ ScratchOwnedBorrow<BE>,
|
|
||||||
{
|
{
|
||||||
fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64)
|
fn gglwe_assert_noise<R, S, P>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: f64)
|
||||||
where
|
where
|
||||||
R: GGLWEToRef,
|
R: GGLWEToRef,
|
||||||
S: GLWESecretPreparedToRef<BE>,
|
S: GLWESecretPreparedToRef<BE>,
|
||||||
P: ScalarZnxToRef,
|
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();
|
let res: &GGLWE<&[u8]> = &res.to_ref();
|
||||||
|
|
||||||
@@ -125,7 +72,7 @@ where
|
|||||||
|
|
||||||
let noise_have: f64 = pt.data.std(base2k, 0).log2();
|
let noise_have: f64 = pt.data.std(base2k, 0).log2();
|
||||||
|
|
||||||
println!("noise_have: {noise_have}");
|
// println!("noise_have: {noise_have}");
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
noise_have <= max_noise,
|
noise_have <= max_noise,
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ mod gglwe_ct;
|
|||||||
mod ggsw_ct;
|
mod ggsw_ct;
|
||||||
mod glwe_ct;
|
mod glwe_ct;
|
||||||
|
|
||||||
|
pub use gglwe_ct::*;
|
||||||
|
pub use ggsw_ct::*;
|
||||||
|
pub use glwe_ct::*;
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn var_noise_gglwe_product(
|
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_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace,
|
||||||
// glwe_packing => crate::tests::test_suite::test_glwe_packing,
|
// glwe_packing => crate::tests::test_suite::test_glwe_packing,
|
||||||
// GGLWE Encryption
|
// GGLWE Encryption
|
||||||
// gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_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_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_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_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,
|
// gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk,
|
||||||
|
|||||||
@@ -1,66 +1,32 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare,
|
ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform,
|
||||||
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,
|
|
||||||
},
|
},
|
||||||
|
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
encryption::SIGMA,
|
decryption::GLWEDecrypt, encryption::SIGMA, layouts::{
|
||||||
layouts::{
|
prepared::{GGLWEPrepare, GGLWEPreparedAlloc, GLWESecretPrepared}, GGLWELayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyCompressed, GLWESwitchingKeyDecompress
|
||||||
GGLWECiphertextLayout, GLWESecret, GLWESwitchingKey,
|
}, noise::GGLWENoise, GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore
|
||||||
compressed::{Decompress, GLWESwitchingKeyCompressed},
|
|
||||||
prepared::{GLWESecretPrepared, PrepareAlloc},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGLWEEncryptSk<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGLWEPrepare<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GGLWEPreparedAlloc<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ GGLWEKeyswitch<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
|
+ GLWESecretPrepare<BE>
|
||||||
|
+ GLWESwitchingKeyAlloc
|
||||||
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubInplace
|
+ GGLWENoise<BE>,
|
||||||
+ VecZnxAddInplace
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxNormalizeInplace<B>
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ 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>,
|
|
||||||
{
|
{
|
||||||
let base2k: usize = 12;
|
let base2k: usize = 12;
|
||||||
let k_ksk: usize = 54;
|
let k_ksk: usize = 54;
|
||||||
@@ -71,7 +37,7 @@ where
|
|||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||||
|
|
||||||
let gglwe_infos: GGLWECiphertextLayout = GGLWECiphertextLayout {
|
let gglwe_infos: GGLWELayout = GGLWELayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -81,23 +47,24 @@ where
|
|||||||
rank_out: rank_out.into(),
|
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_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: 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 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,
|
module,
|
||||||
&gglwe_infos,
|
&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);
|
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);
|
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(
|
ksk.encrypt_sk(
|
||||||
module,
|
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
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGLWEEncryptSk<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGLWEPrepare<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GGLWEPreparedAlloc<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ GGLWEKeyswitch<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ VecZnxFillUniform
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxSubInplace
|
+ GLWESwitchingKeyAlloc
|
||||||
+ VecZnxAddInplace
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWESwitchingKeyCompressedEncryptSk<BE>
|
||||||
+ VecZnxAddNormal
|
+ GLWESwitchingKeyDecompress
|
||||||
+ VecZnxNormalize<B>
|
+ GGLWENoise<BE>
|
||||||
+ VecZnxSub
|
+ VecZnxFillUniform,
|
||||||
+ SvpPrepare<B>
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ SvpPPolBytesOf
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ 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>,
|
|
||||||
{
|
{
|
||||||
let base2k: usize = 12;
|
let base2k: usize = 12;
|
||||||
let k_ksk: usize = 54;
|
let k_ksk: usize = 54;
|
||||||
@@ -163,7 +109,7 @@ where
|
|||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||||
|
|
||||||
let gglwe_infos: GGLWECiphertextLayout = GGLWECiphertextLayout {
|
let gglwe_infos: GGLWELayout = GGLWELayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ksk.into(),
|
k: k_ksk.into(),
|
||||||
@@ -174,22 +120,23 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut ksk_compressed: GLWESwitchingKeyCompressed<Vec<u8>> =
|
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_xs: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xe: 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,
|
module,
|
||||||
&gglwe_infos,
|
&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);
|
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);
|
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];
|
let seed_xa = [1u8; 32];
|
||||||
|
|
||||||
@@ -202,7 +149,7 @@ where
|
|||||||
scratch.borrow(),
|
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.decompress(module, &ksk_compressed);
|
||||||
|
|
||||||
ksk.key
|
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
|
where
|
||||||
Module<B>: GLWEAlloc
|
Module<BE>: GLWEAlloc
|
||||||
+ GLWEEncryptSk<B>
|
+ GLWEEncryptSk<BE>
|
||||||
+ GLWEDecrypt<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ GLWESecretPreparedAlloc<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ GLWESecretPrepare<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ GLWESub,
|
+ GLWESub,
|
||||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
let base2k: usize = 8;
|
let base2k: usize = 8;
|
||||||
let k_ct: usize = 54;
|
let k_ct: usize = 54;
|
||||||
@@ -56,13 +56,13 @@ where
|
|||||||
let mut source_xe: 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 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));
|
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);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
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);
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
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
|
where
|
||||||
Module<B>: GLWEAlloc
|
Module<BE>: GLWEAlloc
|
||||||
+ GLWECompressedEncryptSk<B>
|
+ GLWECompressedEncryptSk<BE>
|
||||||
+ GLWEDecrypt<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ GLWESecretPreparedAlloc<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ GLWESecretPrepare<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ GLWESub,
|
+ GLWESub,
|
||||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
let base2k: usize = 8;
|
let base2k: usize = 8;
|
||||||
let k_ct: usize = 54;
|
let k_ct: usize = 54;
|
||||||
let k_pt: usize = 30;
|
let k_pt: usize = 30;
|
||||||
|
|
||||||
for rank in 1_usize..3 {
|
for rank in 1_usize..3 {
|
||||||
println!("rank: {}", rank);
|
// println!("rank: {}", rank);
|
||||||
let n: usize = module.n();
|
let n: usize = module.n();
|
||||||
|
|
||||||
let glwe_infos: GLWELayout = GLWELayout {
|
let glwe_infos: GLWELayout = GLWELayout {
|
||||||
@@ -129,14 +129,14 @@ where
|
|||||||
let mut source_xe: 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 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),
|
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);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
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);
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
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
|
where
|
||||||
Module<B>: GLWEAlloc
|
Module<BE>: GLWEAlloc
|
||||||
+ GLWEEncryptSk<B>
|
+ GLWEEncryptSk<BE>
|
||||||
+ GLWEDecrypt<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ GLWESecretPreparedAlloc<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ GLWESecretPrepare<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ GLWESub,
|
+ GLWESub,
|
||||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
let base2k: usize = 8;
|
let base2k: usize = 8;
|
||||||
let k_ct: usize = 54;
|
let k_ct: usize = 54;
|
||||||
@@ -201,13 +201,13 @@ where
|
|||||||
let mut source_xe: Source = Source::new([1u8; 32]);
|
let mut source_xe: Source = Source::new([1u8; 32]);
|
||||||
let mut source_xa: 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::decrypt_tmp_bytes(module, &glwe_infos) | GLWE::encrypt_sk_tmp_bytes(module, &glwe_infos));
|
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);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
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);
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(module, &glwe_infos);
|
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
|
where
|
||||||
Module<B>: GLWEAlloc
|
Module<BE>: GLWEAlloc
|
||||||
+ GLWEEncryptPk<B>
|
+ GLWEEncryptPk<BE>
|
||||||
+ GLWEPublicKeyPrepare<B>
|
+ GLWEPublicKeyPrepare<BE>
|
||||||
+ GLWEPublicKeyPreparedAlloc<B>
|
+ GLWEPublicKeyPreparedAlloc<BE>
|
||||||
+ GLWEPublicKeyGenerate<B>
|
+ GLWEPublicKeyGenerate<BE>
|
||||||
+ GLWEDecrypt<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ GLWESecretPreparedAlloc<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ GLWESecretPrepare<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ GLWESub,
|
+ GLWESub,
|
||||||
ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
Scratch<B>: ScratchAvailable + ScratchTakeCore<B>,
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
let base2k: usize = 8;
|
let base2k: usize = 8;
|
||||||
let k_ct: usize = 54;
|
let k_ct: usize = 54;
|
||||||
@@ -262,13 +262,13 @@ where
|
|||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||||
let mut source_xu: 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));
|
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);
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
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);
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
let mut pk: GLWEPublicKey<Vec<u8>> = GLWEPublicKey::alloc_from_infos(module, &glwe_infos);
|
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);
|
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);
|
pk_prepared.prepare(module, &pk);
|
||||||
|
|
||||||
ct.encrypt_pk(
|
ct.encrypt_pk(
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
// mod gglwe_atk;
|
// mod gglwe_atk;
|
||||||
// mod gglwe_ct;
|
mod gglwe_ct;
|
||||||
// mod ggsw_ct;
|
// mod ggsw_ct;
|
||||||
mod glwe_ct;
|
mod glwe_ct;
|
||||||
// mod glwe_tsk;
|
// mod glwe_tsk;
|
||||||
|
|
||||||
// pub use gglwe_atk::*;
|
// pub use gglwe_atk::*;
|
||||||
// pub use gglwe_ct::*;
|
pub use gglwe_ct::*;
|
||||||
// pub use ggsw_ct::*;
|
// pub use ggsw_ct::*;
|
||||||
pub use glwe_ct::*;
|
pub use glwe_ct::*;
|
||||||
// pub use glwe_tsk::*;
|
// pub use glwe_tsk::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user