mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
external product tests
This commit is contained in:
@@ -95,13 +95,7 @@ where
|
|||||||
impl<BE: Backend> GGLWEExternalProduct<BE> for Module<BE> where Self: GLWEExternalProduct<BE> {}
|
impl<BE: Backend> GGLWEExternalProduct<BE> for Module<BE> where Self: GLWEExternalProduct<BE> {}
|
||||||
|
|
||||||
impl GLWESwitchingKey<Vec<u8>> {
|
impl GLWESwitchingKey<Vec<u8>> {
|
||||||
pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>(
|
pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>(module: &M, res_infos: &R, a_infos: &A, b_infos: &B) -> usize
|
||||||
&self,
|
|
||||||
module: &M,
|
|
||||||
res_infos: &R,
|
|
||||||
a_infos: &A,
|
|
||||||
b_infos: &B,
|
|
||||||
) -> usize
|
|
||||||
where
|
where
|
||||||
R: GGLWEInfos,
|
R: GGLWEInfos,
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
|
|||||||
@@ -97,13 +97,7 @@ where
|
|||||||
impl<BE: Backend> GGSWExternalProduct<BE> for Module<BE> where Self: GLWEExternalProduct<BE> {}
|
impl<BE: Backend> GGSWExternalProduct<BE> for Module<BE> where Self: GLWEExternalProduct<BE> {}
|
||||||
|
|
||||||
impl GGSW<Vec<u8>> {
|
impl GGSW<Vec<u8>> {
|
||||||
pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>(
|
pub fn external_product_tmp_bytes<R, A, B, M, BE: Backend>(module: &M, res_infos: &R, a_infos: &A, b_infos: &B) -> usize
|
||||||
&self,
|
|
||||||
module: &M,
|
|
||||||
res_infos: &R,
|
|
||||||
a_infos: &A,
|
|
||||||
b_infos: &B,
|
|
||||||
) -> usize
|
|
||||||
where
|
where
|
||||||
R: GGSWInfos,
|
R: GGSWInfos,
|
||||||
A: GGSWInfos,
|
A: GGSWInfos,
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswit
|
|||||||
// glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism,
|
// glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism,
|
||||||
// glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace,
|
// glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace,
|
||||||
// GLWE External Product
|
// GLWE External Product
|
||||||
// glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product,
|
glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product,
|
||||||
// glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace,
|
glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace,
|
||||||
// GLWE Trace
|
// GLWE Trace
|
||||||
// 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,
|
||||||
@@ -40,8 +40,8 @@ gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::
|
|||||||
gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch,
|
gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch,
|
||||||
gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace,
|
gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace,
|
||||||
// GGLWE External Product
|
// GGLWE External Product
|
||||||
// gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product,
|
gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product,
|
||||||
// gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace,
|
gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace,
|
||||||
// GGLWE Automorphism
|
// GGLWE Automorphism
|
||||||
// gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism,
|
// gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism,
|
||||||
// gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace,
|
// gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace,
|
||||||
@@ -52,8 +52,8 @@ ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_co
|
|||||||
ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch,
|
ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch,
|
||||||
ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace,
|
ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace,
|
||||||
// GGSW External Product
|
// GGSW External Product
|
||||||
// ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product,
|
ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product,
|
||||||
// ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace,
|
ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace,
|
||||||
// GGSW Automorphism
|
// GGSW Automorphism
|
||||||
// ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism,
|
// ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism,
|
||||||
// ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace,
|
// ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace,
|
||||||
|
|||||||
@@ -1,72 +1,34 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace},
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare,
|
layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, Scratch, ScratchOwned, ZnxViewMut},
|
||||||
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace,
|
|
||||||
VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxCopy, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform,
|
|
||||||
VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotateInplace, VecZnxSub,
|
|
||||||
VecZnxSubInplace, VecZnxSubScalarInplace, VecZnxSwitchRing, VmpApplyDftToDft, VmpApplyDftToDftAdd,
|
|
||||||
VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare,
|
|
||||||
},
|
|
||||||
layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, ScratchOwned, ZnxViewMut},
|
|
||||||
oep::{
|
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
|
||||||
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl,
|
|
||||||
},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
GGLWEExternalProduct, GGLWENoise, GGSWEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGSW, GGSWCiphertextLayout, GLWESecret, GLWESwitchingKey, GLWESwitchingKeyLayout,
|
GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc,
|
||||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
GLWESwitchingKey, GLWESwitchingKeyLayout,
|
||||||
|
prepared::{GGSWPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_product,
|
noise::noise_ggsw_product,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_gglwe_switching_key_external_product<B>(module: &Module<B>)
|
pub fn test_gglwe_switching_key_external_product<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGLWEExternalProduct<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGSWEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ VecZnxRotateInplace<BE>
|
||||||
+ VecZnxFillUniform
|
+ GGSWPrepare<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWPreparedAlloc<BE>
|
||||||
+ VecZnxAddInplace
|
+ GGLWENoise<BE>,
|
||||||
+ VecZnxNormalizeInplace<B>
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxAddNormal
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ VecZnxNormalize<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxSubScalarInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<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_in: usize = 60;
|
let k_in: usize = 60;
|
||||||
@@ -101,7 +63,7 @@ where
|
|||||||
rank_out: rank_out.into(),
|
rank_out: rank_out.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ggsw_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ggsw.into(),
|
k: k_ggsw.into(),
|
||||||
@@ -120,14 +82,9 @@ 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(
|
||||||
GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &gglwe_in_infos)
|
GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &gglwe_in_infos)
|
||||||
| GLWESwitchingKey::external_product_tmp_bytes(
|
| GLWESwitchingKey::external_product_tmp_bytes(module, &gglwe_out_infos, &gglwe_in_infos, &ggsw_infos)
|
||||||
module,
|
|
||||||
&gglwe_out_infos,
|
|
||||||
&gglwe_in_infos,
|
|
||||||
&ggsw_infos,
|
|
||||||
)
|
|
||||||
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_infos),
|
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_infos),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -142,7 +99,9 @@ where
|
|||||||
|
|
||||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
||||||
sk_out.fill_ternary_prob(var_xs, &mut source_xs);
|
sk_out.fill_ternary_prob(var_xs, &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);
|
||||||
|
|
||||||
// gglwe_{s1}(s0) = s0 -> s1
|
// gglwe_{s1}(s0) = s0 -> s1
|
||||||
ct_gglwe_in.encrypt_sk(
|
ct_gglwe_in.encrypt_sk(
|
||||||
@@ -163,7 +122,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ct_rgsw_prepared: GGSWPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow());
|
let mut ct_rgsw_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &ct_rgsw);
|
||||||
|
ct_rgsw_prepared.prepare(module, &ct_rgsw, scratch.borrow());
|
||||||
|
|
||||||
// gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k)
|
// gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k)
|
||||||
ct_gglwe_out.external_product(module, &ct_gglwe_in, &ct_rgsw_prepared, scratch.borrow());
|
ct_gglwe_out.external_product(module, &ct_gglwe_in, &ct_rgsw_prepared, scratch.borrow());
|
||||||
@@ -207,48 +167,19 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_gglwe_switching_key_external_product_inplace<B>(module: &Module<B>)
|
pub fn test_gglwe_switching_key_external_product_inplace<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGLWEExternalProduct<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGSWEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GLWESwitchingKeyEncryptSk<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ VecZnxRotateInplace<BE>
|
||||||
+ VecZnxFillUniform
|
+ GGSWPrepare<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWPreparedAlloc<BE>
|
||||||
+ VecZnxAddInplace
|
+ GGLWENoise<BE>,
|
||||||
+ VecZnxNormalizeInplace<B>
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxAddNormal
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ VecZnxNormalize<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxSubScalarInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<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_out: usize = 60;
|
let k_out: usize = 60;
|
||||||
@@ -273,7 +204,7 @@ where
|
|||||||
rank_out: rank_out.into(),
|
rank_out: rank_out.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ggsw_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ggsw.into(),
|
k: k_ggsw.into(),
|
||||||
@@ -291,9 +222,9 @@ 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(
|
||||||
GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &gglwe_out_infos)
|
GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &gglwe_out_infos)
|
||||||
| GLWESwitchingKey::external_product_inplace_tmp_bytes(module, &gglwe_out_infos, &ggsw_infos)
|
| GLWESwitchingKey::external_product_tmp_bytes(module, &gglwe_out_infos, &gglwe_out_infos, &ggsw_infos)
|
||||||
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_infos),
|
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_infos),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -308,7 +239,9 @@ where
|
|||||||
|
|
||||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
||||||
sk_out.fill_ternary_prob(var_xs, &mut source_xs);
|
sk_out.fill_ternary_prob(var_xs, &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);
|
||||||
|
|
||||||
// gglwe_{s1}(s0) = s0 -> s1
|
// gglwe_{s1}(s0) = s0 -> s1
|
||||||
ct_gglwe.encrypt_sk(
|
ct_gglwe.encrypt_sk(
|
||||||
@@ -329,7 +262,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ct_rgsw_prepared: GGSWPrepared<Vec<u8>, B> = ct_rgsw.prepare_alloc(module, scratch.borrow());
|
let mut ct_rgsw_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &ct_rgsw);
|
||||||
|
ct_rgsw_prepared.prepare(module, &ct_rgsw, scratch.borrow());
|
||||||
|
|
||||||
// gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k)
|
// gglwe_(m) (x) RGSW_(X^k) = gglwe_(m * X^k)
|
||||||
ct_gglwe.external_product_inplace(module, &ct_rgsw_prepared, scratch.borrow());
|
ct_gglwe.external_product_inplace(module, &ct_rgsw_prepared, scratch.borrow());
|
||||||
|
|||||||
@@ -1,74 +1,32 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxRotateInplace},
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare,
|
layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, Scratch, ScratchOwned, ZnxViewMut},
|
||||||
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc,
|
|
||||||
VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAlloc, VecZnxDftApply,
|
|
||||||
VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNormalize,
|
|
||||||
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotateInplace, VecZnxSub, VecZnxSubInplace, VmpApplyDftToDft,
|
|
||||||
VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare,
|
|
||||||
},
|
|
||||||
layouts::{Backend, Module, ScalarZnx, ScalarZnxToMut, ScratchOwned, ZnxViewMut},
|
|
||||||
oep::{
|
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
|
||||||
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl,
|
|
||||||
},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
GGSWEncryptSk, GGSWExternalProduct, GGSWNoise, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGSW, GGSWCiphertextLayout, GLWESecret,
|
GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc,
|
||||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
prepared::{GGSWPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_product,
|
noise::noise_ggsw_product,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_ggsw_external_product<B>(module: &Module<B>)
|
pub fn test_ggsw_external_product<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGSWExternalProduct<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GGSWPrepare<BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GGSWPreparedAlloc<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxRotateInplace<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWNoise<BE>,
|
||||||
+ VecZnxAddInplace
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxNormalizeInplace<B>
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ VecZnxAddNormal
|
|
||||||
+ VecZnxNormalize<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ VecZnxBigAlloc<B>
|
|
||||||
+ VecZnxDftAlloc<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VecZnxIdftApplyTmpA<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_in: usize = 60;
|
let k_in: usize = 60;
|
||||||
@@ -84,7 +42,7 @@ where
|
|||||||
let dnum_in: usize = k_in.div_euclid(base2k * di);
|
let dnum_in: usize = k_in.div_euclid(base2k * di);
|
||||||
let dsize_in: usize = 1;
|
let dsize_in: usize = 1;
|
||||||
|
|
||||||
let ggsw_in_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_in_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_in.into(),
|
k: k_in.into(),
|
||||||
@@ -93,7 +51,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ggsw_out_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_out_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_out.into(),
|
k: k_out.into(),
|
||||||
@@ -102,7 +60,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ggsw_apply_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_apply_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_apply.into(),
|
k: k_apply.into(),
|
||||||
@@ -127,7 +85,7 @@ where
|
|||||||
|
|
||||||
pt_apply.to_mut().raw_mut()[k] = 1; //X^{k}
|
pt_apply.to_mut().raw_mut()[k] = 1; //X^{k}
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
||||||
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_in_infos)
|
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_in_infos)
|
||||||
| GGSW::external_product_tmp_bytes(module, &ggsw_out_infos, &ggsw_in_infos, &ggsw_apply_infos),
|
| GGSW::external_product_tmp_bytes(module, &ggsw_out_infos, &ggsw_in_infos, &ggsw_apply_infos),
|
||||||
@@ -135,7 +93,9 @@ where
|
|||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, B> = sk.prepare_alloc(module, scratch.borrow());
|
|
||||||
|
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||||
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
ggsw_apply.encrypt_sk(
|
ggsw_apply.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
@@ -155,7 +115,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ct_rhs_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
let mut ct_rhs_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &ggsw_apply);
|
||||||
|
ct_rhs_prepared.prepare(module, &ggsw_apply, scratch.borrow());
|
||||||
|
|
||||||
ggsw_out.external_product(module, &ggsw_in, &ct_rhs_prepared, scratch.borrow());
|
ggsw_out.external_product(module, &ggsw_in, &ct_rhs_prepared, scratch.borrow());
|
||||||
|
|
||||||
@@ -190,50 +151,18 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_ggsw_external_product_inplace<B>(module: &Module<B>)
|
pub fn test_ggsw_external_product_inplace<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGSWExternalProduct<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GGSWPrepare<BE>
|
||||||
+ VecZnxNormalizeTmpBytes
|
+ GGSWPreparedAlloc<BE>
|
||||||
+ VecZnxFillUniform
|
+ VecZnxRotateInplace<BE>
|
||||||
+ VecZnxSubInplace
|
+ GGSWNoise<BE>,
|
||||||
+ VecZnxAddInplace
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxNormalizeInplace<B>
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ VecZnxAddNormal
|
|
||||||
+ VecZnxNormalize<B>
|
|
||||||
+ VecZnxSub
|
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxCopy
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ VecZnxBigAlloc<B>
|
|
||||||
+ VecZnxDftAlloc<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VecZnxIdftApplyTmpA<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_out: usize = 60;
|
let k_out: usize = 60;
|
||||||
@@ -247,7 +176,7 @@ where
|
|||||||
let dnum_in: usize = k_out.div_euclid(base2k * di);
|
let dnum_in: usize = k_out.div_euclid(base2k * di);
|
||||||
let dsize_in: usize = 1;
|
let dsize_in: usize = 1;
|
||||||
|
|
||||||
let ggsw_out_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_out_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_out.into(),
|
k: k_out.into(),
|
||||||
@@ -256,7 +185,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ggsw_apply_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_apply_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_apply.into(),
|
k: k_apply.into(),
|
||||||
@@ -281,15 +210,17 @@ where
|
|||||||
|
|
||||||
pt_apply.to_mut().raw_mut()[k] = 1; //X^{k}
|
pt_apply.to_mut().raw_mut()[k] = 1; //X^{k}
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
||||||
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_out_infos)
|
| GGSW::encrypt_sk_tmp_bytes(module, &ggsw_out_infos)
|
||||||
| GGSW::external_product_inplace_tmp_bytes(module, &ggsw_out_infos, &ggsw_apply_infos),
|
| GGSW::external_product_tmp_bytes(module, &ggsw_out_infos, &ggsw_out_infos, &ggsw_apply_infos),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, B> = sk.prepare_alloc(module, scratch.borrow());
|
|
||||||
|
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||||
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
ggsw_apply.encrypt_sk(
|
ggsw_apply.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
@@ -309,7 +240,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ct_rhs_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
let mut ct_rhs_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &ggsw_apply);
|
||||||
|
ct_rhs_prepared.prepare(module, &ggsw_apply, scratch.borrow());
|
||||||
|
|
||||||
ggsw_out.external_product_inplace(module, &ct_rhs_prepared, scratch.borrow());
|
ggsw_out.external_product_inplace(module, &ct_rhs_prepared, scratch.borrow());
|
||||||
|
|
||||||
|
|||||||
@@ -1,66 +1,35 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform, VecZnxRotateInplace},
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare,
|
layouts::{Backend, Module, ScalarZnx, Scratch, ScratchOwned, ZnxViewMut},
|
||||||
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace,
|
|
||||||
VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume,
|
|
||||||
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotateInplace, VecZnxSub, VecZnxSubInplace,
|
|
||||||
VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare,
|
|
||||||
},
|
|
||||||
layouts::{Backend, Module, ScalarZnx, ScratchOwned, ZnxViewMut},
|
|
||||||
oep::{
|
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
|
||||||
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl,
|
|
||||||
},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
GGSWEncryptSk, GLWEEncryptSk, GLWEExternalProduct, GLWENoise, ScratchTakeCore,
|
||||||
encryption::SIGMA,
|
encryption::SIGMA,
|
||||||
layouts::{
|
layouts::{
|
||||||
GGSW, GGSWCiphertextLayout, GLWE, GLWELayout, GLWEPlaintext, GLWESecret,
|
GGSW, GGSWLayout, GGSWPrepare, GGSWPreparedAlloc, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare,
|
||||||
prepared::{GGSWPrepared, GLWESecretPrepared, PrepareAlloc},
|
GLWESecretPreparedAlloc,
|
||||||
|
prepared::{GGSWPrepared, GLWESecretPrepared},
|
||||||
},
|
},
|
||||||
noise::noise_ggsw_product,
|
noise::noise_ggsw_product,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_glwe_external_product<B>(module: &Module<B>)
|
pub fn test_glwe_external_product<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGSWPrepare<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GGSWPreparedAlloc<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
|
||||||
+ VecZnxIdftApplyConsume<B>
|
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubInplace
|
+ GLWEExternalProduct<BE>
|
||||||
+ VecZnxAddInplace
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWENoise<BE>
|
||||||
+ VecZnxAddNormal
|
+ VecZnxRotateInplace<BE>
|
||||||
+ VecZnxNormalize<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxSub
|
+ GLWESecretPreparedAlloc<BE>,
|
||||||
+ SvpPrepare<B>
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ SvpPPolBytesOf
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>,
|
|
||||||
B: Backend
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>,
|
|
||||||
{
|
{
|
||||||
let base2k: usize = 12;
|
let base2k: usize = 12;
|
||||||
let k_in: usize = 45;
|
let k_in: usize = 45;
|
||||||
@@ -87,7 +56,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ggsw_apply_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_apply_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ggsw.into(),
|
k: k_ggsw.into(),
|
||||||
@@ -115,7 +84,7 @@ where
|
|||||||
|
|
||||||
pt_ggsw.raw_mut()[k] = 1; // X^{k}
|
pt_ggsw.raw_mut()[k] = 1; // X^{k}
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(module, &glwe_in_infos)
|
| GLWE::encrypt_sk_tmp_bytes(module, &glwe_in_infos)
|
||||||
| GLWE::external_product_tmp_bytes(module, &glwe_out_infos, &glwe_in_infos, &ggsw_apply_infos),
|
| GLWE::external_product_tmp_bytes(module, &glwe_out_infos, &glwe_in_infos, &ggsw_apply_infos),
|
||||||
@@ -123,7 +92,9 @@ where
|
|||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, B> = sk.prepare_alloc(module, scratch.borrow());
|
|
||||||
|
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||||
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
ggsw_apply.encrypt_sk(
|
ggsw_apply.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
@@ -143,7 +114,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ct_ggsw_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
let mut ct_ggsw_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &ggsw_apply);
|
||||||
|
ct_ggsw_prepared.prepare(module, &ggsw_apply, scratch.borrow());
|
||||||
|
|
||||||
glwe_out.external_product(module, &glwe_in, &ct_ggsw_prepared, scratch.borrow());
|
glwe_out.external_product(module, &glwe_in, &ct_ggsw_prepared, scratch.borrow());
|
||||||
|
|
||||||
@@ -176,43 +148,20 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn test_glwe_external_product_inplace<B>(module: &Module<B>)
|
pub fn test_glwe_external_product_inplace<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GGSWEncryptSk<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GGSWPrepare<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GGSWPreparedAlloc<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
|
||||||
+ VecZnxIdftApplyConsume<B>
|
|
||||||
+ VecZnxFillUniform
|
+ VecZnxFillUniform
|
||||||
+ VecZnxSubInplace
|
+ GLWEExternalProduct<BE>
|
||||||
+ VecZnxAddInplace
|
+ GLWEEncryptSk<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWENoise<BE>
|
||||||
+ VecZnxAddNormal
|
+ VecZnxRotateInplace<BE>
|
||||||
+ VecZnxNormalize<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxSub
|
+ GLWESecretPreparedAlloc<BE>,
|
||||||
+ SvpPrepare<B>
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ SvpPPolBytesOf
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VecZnxRotateInplace<B>
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>,
|
|
||||||
B: Backend
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>,
|
|
||||||
{
|
{
|
||||||
let base2k: usize = 12;
|
let base2k: usize = 12;
|
||||||
let k_out: usize = 60;
|
let k_out: usize = 60;
|
||||||
@@ -231,7 +180,7 @@ where
|
|||||||
rank: rank.into(),
|
rank: rank.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ggsw_apply_infos: GGSWCiphertextLayout = GGSWCiphertextLayout {
|
let ggsw_apply_infos: GGSWLayout = GGSWLayout {
|
||||||
n: n.into(),
|
n: n.into(),
|
||||||
base2k: base2k.into(),
|
base2k: base2k.into(),
|
||||||
k: k_ggsw.into(),
|
k: k_ggsw.into(),
|
||||||
@@ -258,15 +207,17 @@ where
|
|||||||
|
|
||||||
pt_ggsw.raw_mut()[k] = 1; // X^{k}
|
pt_ggsw.raw_mut()[k] = 1; // X^{k}
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
GGSW::encrypt_sk_tmp_bytes(module, &ggsw_apply_infos)
|
||||||
| GLWE::encrypt_sk_tmp_bytes(module, &glwe_out_infos)
|
| GLWE::encrypt_sk_tmp_bytes(module, &glwe_out_infos)
|
||||||
| GLWE::external_product_inplace_tmp_bytes(module, &glwe_out_infos, &ggsw_apply_infos),
|
| GLWE::external_product_tmp_bytes(module, &glwe_out_infos, &glwe_out_infos, &ggsw_apply_infos),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank.into());
|
||||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
let sk_prepared: GLWESecretPrepared<Vec<u8>, B> = sk.prepare_alloc(module, scratch.borrow());
|
|
||||||
|
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||||
|
sk_prepared.prepare(module, &sk);
|
||||||
|
|
||||||
ggsw_apply.encrypt_sk(
|
ggsw_apply.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
@@ -286,7 +237,8 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ct_ggsw_prepared: GGSWPrepared<Vec<u8>, B> = ggsw_apply.prepare_alloc(module, scratch.borrow());
|
let mut ct_ggsw_prepared: GGSWPrepared<Vec<u8>, BE> = GGSWPrepared::alloc_from_infos(module, &ggsw_apply);
|
||||||
|
ct_ggsw_prepared.prepare(module, &ggsw_apply, scratch.borrow());
|
||||||
|
|
||||||
glwe_out.external_product_inplace(module, &ct_ggsw_prepared, scratch.borrow());
|
glwe_out.external_product_inplace(module, &ct_ggsw_prepared, scratch.borrow());
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// pub mod automorphism;
|
// pub mod automorphism;
|
||||||
pub mod encryption;
|
pub mod encryption;
|
||||||
// pub mod external_product;
|
pub mod external_product;
|
||||||
pub mod keyswitch;
|
pub mod keyswitch;
|
||||||
|
|
||||||
// mod conversion;
|
// mod conversion;
|
||||||
|
|||||||
Reference in New Issue
Block a user