automorphism tests

This commit is contained in:
Pro7ech
2025-10-20 16:31:25 +02:00
parent b91918dcaf
commit 1e2478852e
10 changed files with 154 additions and 354 deletions

View File

@@ -86,6 +86,7 @@ where
); );
let cols_out: usize = (key.rank_out() + 1).into(); let cols_out: usize = (key.rank_out() + 1).into();
let cols_in: usize = key.rank_in().into();
let p: i64 = a.p(); let p: i64 = a.p();
let p_inv: i64 = self.galois_element_inv(p); let p_inv: i64 = self.galois_element_inv(p);
@@ -95,7 +96,7 @@ where
let a: &GGLWE<&[u8]> = &a.to_ref(); let a: &GGLWE<&[u8]> = &a.to_ref();
for row in 0..res.dnum().as_usize() { for row in 0..res.dnum().as_usize() {
for col in 0..cols_out { for col in 0..cols_in {
let mut res_tmp: GLWE<&mut [u8]> = res.at_mut(row, col); let mut res_tmp: GLWE<&mut [u8]> = res.at_mut(row, col);
let a_ct: GLWE<&[u8]> = a.at(row, col); let a_ct: GLWE<&[u8]> = a.at(row, col);
@@ -133,18 +134,19 @@ where
); );
let cols_out: usize = (key.rank_out() + 1).into(); let cols_out: usize = (key.rank_out() + 1).into();
let cols_in: usize = key.rank_in().into();
let p: i64 = res.p(); let p: i64 = res.p();
let p_inv: i64 = self.galois_element_inv(p); let p_inv: i64 = self.galois_element_inv(p);
{ {
let res: &mut GGLWE<&mut [u8]> = &mut res.to_mut(); let res: &mut GGLWE<&mut [u8]> = &mut res.to_mut();
for row in 0..res.dnum().as_usize() { for row in 0..res.dnum().as_usize() {
for col in 0..cols_out { for col in 0..cols_in {
let mut res_tmp: GLWE<&mut [u8]> = res.at_mut(row, col); let mut res_tmp: GLWE<&mut [u8]> = res.at_mut(row, col);
// Reverts the automorphism X^{-k}: (-pi^{-1}_{k}(s)a + s, a) to (-sa + pi_{k}(s), a) // Reverts the automorphism X^{-k}: (-pi^{-1}_{k}(s)a + s, a) to (-sa + pi_{k}(s), a)
for i in 0..cols_out { for i in 0..cols_out {
self.vec_znx_automorphism_inplace(p_inv, res_tmp.data_mut(), i, scratch); self.vec_znx_automorphism_inplace(p, res_tmp.data_mut(), i, scratch);
} }
// Key-switch (-sa + pi_{k}(s), a) to (-pi^{-1}_{k'}(s)a + pi_{k}(s), a) // Key-switch (-sa + pi_{k}(s), a) to (-pi^{-1}_{k'}(s)a + pi_{k}(s), a)

View File

@@ -121,7 +121,7 @@ where
{ {
let (mut sk_out, _) = scratch_1.take_glwe_secret(self, sk.rank()); let (mut sk_out, _) = scratch_1.take_glwe_secret(self, sk.rank());
(0..res.rank_out().into()).for_each(|i| { for i in 0..res.rank().into() {
self.vec_znx_automorphism( self.vec_znx_automorphism(
self.galois_element_inv(p), self.galois_element_inv(p),
&mut sk_out.data.as_vec_znx_mut(), &mut sk_out.data.as_vec_znx_mut(),
@@ -129,7 +129,7 @@ where
&sk.data.as_vec_znx(), &sk.data.as_vec_znx(),
i, i,
); );
}); }
sk_out_prepared.prepare(self, &sk_out); sk_out_prepared.prepare(self, &sk_out);
} }

View File

@@ -156,7 +156,6 @@ where
// //
// (-(a*s) + s0, a) // (-(a*s) + s0, a)
// (-(b*s) + s1, b) // (-(b*s) + s1, b)
for col_i in 0..rank_in { for col_i in 0..rank_in {
for row_i in 0..dnum { for row_i in 0..dnum {
// Adds the scalar_znx_pt to the i-th limb of the vec_znx_pt // Adds the scalar_znx_pt to the i-th limb of the vec_znx_pt

View File

@@ -173,7 +173,7 @@ impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
} }
} }
pub trait PrepareAutomorphismKey<B: Backend> pub trait AutomorphismKeyPrepare<B: Backend>
where where
Self: GGLWEPrepare<B>, Self: GGLWEPrepare<B>,
{ {
@@ -194,12 +194,12 @@ where
} }
} }
impl<B: Backend> PrepareAutomorphismKey<B> for Module<B> where Module<B>: GGLWEPrepare<B> {} impl<B: Backend> AutomorphismKeyPrepare<B> for Module<B> where Module<B>: GGLWEPrepare<B> {}
impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> { impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
where where
M: PrepareAutomorphismKey<B>, M: AutomorphismKeyPrepare<B>,
{ {
module.prepare_automorphism_key_tmp_bytes(self) module.prepare_automorphism_key_tmp_bytes(self)
} }
@@ -209,7 +209,7 @@ impl<D: DataMut, B: Backend> AutomorphismKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>) pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
where where
O: GGLWEToRef + GetAutomorphismGaloisElement, O: GGLWEToRef + GetAutomorphismGaloisElement,
M: PrepareAutomorphismKey<B>, M: AutomorphismKeyPrepare<B>,
{ {
module.prepare_automorphism_key(self, other, scratch); module.prepare_automorphism_key(self, other, scratch);
} }

View File

@@ -21,8 +21,8 @@ backend_test_suite!(
glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch,
glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace,
// GLWE Automorphism // GLWE Automorphism
// 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,
@@ -43,8 +43,8 @@ gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::te
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,
// GGSW Encryption // GGSW Encryption
ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk,
ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk,
@@ -55,8 +55,8 @@ ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswit
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,
// LWE // LWE
lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch,
// glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, // glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe,

View File

@@ -1,71 +1,35 @@
use poulpy_hal::{ use poulpy_hal::{
api::{ api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAutomorphism, VecZnxSubScalarInplace},
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare, layouts::{Backend, GaloisElement, Module, Scratch, ScratchOwned},
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace,
VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes,
VecZnxCopy, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize,
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSubScalarInplace, VecZnxSwitchRing,
VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare,
},
layouts::{Backend, Module, ScratchOwned},
oep::{
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl,
},
source::Source, source::Source,
}; };
use crate::{ use crate::{
AutomorphismKeyAutomorphism, AutomorphismKeyEncryptSk, GLWEDecrypt, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
AutomorphismKey, AutomorphismKeyLayout, GGLWEInfos, GLWEPlaintext, GLWESecret, AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GGLWEInfos, GLWEPlaintext,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared},
}, },
noise::log2_std_noise_gglwe_product, noise::log2_std_noise_gglwe_product,
}; };
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn test_gglwe_automorphism_key_automorphism<B>(module: &Module<B>) pub fn test_gglwe_automorphism_key_automorphism<BE: Backend>(module: &Module<BE>)
where where
Module<B>: VecZnxDftBytesOf Module<BE>: AutomorphismKeyEncryptSk<BE>
+ VmpApplyDftToDftTmpBytes + AutomorphismKeyPreparedAlloc<BE>
+ VecZnxBigNormalizeTmpBytes + AutomorphismKeyPrepare<BE>
+ VmpApplyDftToDft<B> + AutomorphismKeyAutomorphism<BE>
+ VmpApplyDftToDftAdd<B>
+ VecZnxDftApply<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxBigAddSmallInplace<B>
+ VecZnxBigNormalize<B>
+ VecZnxAutomorphism + VecZnxAutomorphism
+ VecZnxAutomorphismInplace<B> + GaloisElement
+ SvpPPolBytesOf + VecZnxSubScalarInplace
+ VecZnxDftBytesOf + GLWESecretPrepare<BE>
+ VecZnxNormalizeTmpBytes + GLWESecretPreparedAlloc<BE>
+ VmpPMatAlloc<B> + GLWEDecrypt<BE>,
+ VmpPrepare<B> ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
+ SvpPrepare<B> Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
+ SvpApplyDftToDftInplace<B>
+ VecZnxAddScalarInplace
+ VecZnxFillUniform
+ VecZnxSubInplace
+ VecZnxAddInplace
+ VecZnxNormalizeInplace<B>
+ VecZnxAddNormal
+ VecZnxNormalize<B>
+ VecZnxSub
+ VecZnxSwitchRing
+ SvpPPolAlloc<B>
+ VecZnxBigAddInplace<B>
+ VecZnxSubScalarInplace,
B: Backend
+ ScratchOwnedAllocImpl<B>
+ ScratchOwnedBorrowImpl<B>
+ ScratchAvailableImpl<B>
+ TakeScalarZnxImpl<B>
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxImpl<B>
+ TakeSvpPPolImpl<B>
+ TakeVecZnxBigImpl<B>,
{ {
let base2k: usize = 12; let base2k: usize = 12;
let k_in: usize = 60; let k_in: usize = 60;
@@ -119,7 +83,7 @@ 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(
AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_in_infos) AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_in_infos)
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply_infos) | AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply_infos)
| AutomorphismKey::automorphism_tmp_bytes( | AutomorphismKey::automorphism_tmp_bytes(
@@ -153,7 +117,7 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_infos); AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_infos);
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow()); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
@@ -180,7 +144,8 @@ where
); );
} }
let sk_auto_dft: GLWESecretPrepared<Vec<u8>, B> = sk_auto.prepare_alloc(module, scratch.borrow()); let mut sk_auto_dft: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(module, &sk_auto);
sk_auto_dft.prepare(module, &sk_auto);
(0..auto_key_out.rank_in().into()).for_each(|col_i| { (0..auto_key_out.rank_in().into()).for_each(|col_i| {
(0..auto_key_out.dnum().into()).for_each(|row_i| { (0..auto_key_out.dnum().into()).for_each(|row_i| {
@@ -222,61 +187,20 @@ where
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(module: &Module<B>) pub fn test_gglwe_automorphism_key_automorphism_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<B>: VecZnxDftBytesOf Module<BE>: AutomorphismKeyEncryptSk<BE>
+ VecZnxBigNormalize<B> + AutomorphismKeyPreparedAlloc<BE>
+ VecZnxDftApply<B> + AutomorphismKeyPrepare<BE>
+ SvpApplyDftToDftInplace<B> + AutomorphismKeyAutomorphism<BE>
+ VecZnxIdftApplyConsume<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxFillUniform
+ VecZnxSubInplace
+ VecZnxAddInplace
+ VecZnxNormalizeInplace<B>
+ VecZnxAddNormal
+ VecZnxNormalize<B>
+ VecZnxSub
+ SvpPrepare<B>
+ SvpPPolBytesOf
+ SvpPPolAlloc<B>
+ VecZnxDftBytesOf
+ VmpApplyDftToDftTmpBytes
+ VecZnxBigNormalizeTmpBytes
+ VmpApplyDftToDftTmpBytes
+ VmpApplyDftToDft<B>
+ VmpApplyDftToDftAdd<B>
+ VecZnxDftApply<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxBigAddSmallInplace<B>
+ VecZnxBigNormalize<B>
+ VecZnxAutomorphism + VecZnxAutomorphism
+ VecZnxSwitchRing + GaloisElement
+ VecZnxAddScalarInplace
+ VecZnxAutomorphism
+ VecZnxAutomorphismInplace<B>
+ VecZnxDftBytesOf
+ VecZnxBigBytesOf
+ VecZnxDftApply<B>
+ SvpApplyDftToDftInplace<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxBigAddInplace<B>
+ VecZnxBigAddSmallInplace<B>
+ VecZnxBigNormalize<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxSubScalarInplace + VecZnxSubScalarInplace
+ VecZnxCopy + GLWESecretPrepare<BE>
+ VmpPMatAlloc<B> + GLWESecretPreparedAlloc<BE>
+ VmpPrepare<B>, + GLWEDecrypt<BE>,
B: Backend ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
+ ScratchOwnedAllocImpl<B> Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
+ ScratchOwnedBorrowImpl<B>
+ ScratchAvailableImpl<B>
+ TakeScalarZnxImpl<B>
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxImpl<B>
+ TakeSvpPPolImpl<B>
+ TakeVecZnxBigImpl<B>,
{ {
let base2k: usize = 12; let base2k: usize = 12;
let k_in: usize = 60; let k_in: usize = 60;
@@ -318,10 +242,10 @@ 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(
AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key) AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply) | AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key_apply)
| AutomorphismKey::automorphism_inplace_tmp_bytes(module, &auto_key, &auto_key_apply), | AutomorphismKey::automorphism_tmp_bytes(module, &auto_key, &auto_key, &auto_key_apply),
); );
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&auto_key); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&auto_key);
@@ -347,7 +271,7 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = let mut auto_key_apply_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_layout); AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_apply_layout);
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow()); auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
@@ -370,7 +294,8 @@ where
); );
} }
let sk_auto_dft: GLWESecretPrepared<Vec<u8>, B> = sk_auto.prepare_alloc(module, scratch.borrow()); let mut sk_auto_dft: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(module, &sk_auto);
sk_auto_dft.prepare(module, &sk_auto);
(0..auto_key.rank_in().into()).for_each(|col_i| { (0..auto_key.rank_in().into()).for_each(|col_i| {
(0..auto_key.dnum().into()).for_each(|row_i| { (0..auto_key.dnum().into()).for_each(|row_i| {

View File

@@ -1,79 +1,36 @@
use poulpy_hal::{ use poulpy_hal::{
api::{ api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAutomorphismInplace},
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, layouts::{Backend, Module, ScalarZnx, Scratch, ScratchOwned},
SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace,
VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigBytesOf, VecZnxBigNormalize,
VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAddInplace, VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf,
VecZnxDftCopy, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNormalize, VecZnxNormalizeInplace,
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, VmpApplyDftToDft, VmpApplyDftToDftAdd,
VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare,
},
layouts::{Backend, Module, ScalarZnx, ScratchOwned},
oep::{
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl,
},
source::Source, source::Source,
}; };
use crate::{ use crate::{
AutomorphismKeyEncryptSk, GGSWAutomorphism, GGSWEncryptSk, GGSWNoise, ScratchTakeCore, TensorKeyEncryptSk,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
AutomorphismKey, GGSW, GGSWCiphertextLayout, GLWESecret, TensorKey, TensorKeyLayout, AutomorphismKey, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GGSW, GGSWLayout, GLWESecret, GLWESecretPrepare,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc, TensorKeyPrepared}, GLWESecretPreparedAlloc, TensorKey, TensorKeyLayout, TensorKeyPrepare, TensorKeyPreparedAlloc,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, TensorKeyPrepared},
}, },
noise::noise_ggsw_keyswitch, noise::noise_ggsw_keyswitch,
}; };
pub fn test_ggsw_automorphism<B>(module: &Module<B>) pub fn test_ggsw_automorphism<BE: Backend>(module: &Module<BE>)
where where
Module<B>: VecZnxDftBytesOf Module<BE>: GGSWEncryptSk<BE>
+ VecZnxBigBytesOf + AutomorphismKeyEncryptSk<BE>
+ VecZnxDftApply<B> + AutomorphismKeyPreparedAlloc<BE>
+ SvpApplyDftToDftInplace<B> + AutomorphismKeyPrepare<BE>
+ VecZnxIdftApplyConsume<B> + GGSWAutomorphism<BE>
+ VecZnxBigAddInplace<B> + TensorKeyPrepare<BE>
+ VecZnxBigAddSmallInplace<B> + TensorKeyPreparedAlloc<BE>
+ VecZnxBigNormalize<B> + TensorKeyEncryptSk<BE>
+ VecZnxNormalizeTmpBytes + GLWESecretPrepare<BE>
+ VecZnxBigAlloc<B> + GLWESecretPreparedAlloc<BE>
+ VecZnxDftAlloc<B> + VecZnxAutomorphismInplace<BE>
+ VecZnxBigNormalizeTmpBytes + GGSWNoise<BE>,
+ VecZnxIdftApplyTmpA<B> ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
+ SvpPrepare<B> Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
+ SvpPPolBytesOf
+ SvpPPolAlloc<B>
+ VecZnxAddScalarInplace
+ VecZnxCopy
+ VecZnxSubInplace
+ VmpPMatAlloc<B>
+ VmpPrepare<B>
+ VmpApplyDftToDftTmpBytes
+ VmpApplyDftToDft<B>
+ VmpApplyDftToDftAdd<B>
+ VecZnxDftCopy<B>
+ VecZnxDftAddInplace<B>
+ VecZnxFillUniform
+ VecZnxAddInplace
+ VecZnxNormalizeInplace<B>
+ VecZnxAddNormal
+ VecZnxNormalize<B>
+ VecZnxSub
+ SvpApplyDftToDft<B>
+ VecZnxSwitchRing
+ VecZnxAutomorphismInplace<B>
+ VecZnxAutomorphism,
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 = 54; let k_in: usize = 54;
@@ -92,7 +49,7 @@ where
let dsize_in: usize = 1; let dsize_in: usize = 1;
let ggsw_in_layout: GGSWCiphertextLayout = GGSWCiphertextLayout { let ggsw_in_layout: GGSWLayout = GGSWLayout {
n: n.into(), n: n.into(),
base2k: base2k.into(), base2k: base2k.into(),
k: k_in.into(), k: k_in.into(),
@@ -101,7 +58,7 @@ where
rank: rank.into(), rank: rank.into(),
}; };
let ggsw_out_layout: GGSWCiphertextLayout = GGSWCiphertextLayout { let ggsw_out_layout: GGSWLayout = GGSWLayout {
n: n.into(), n: n.into(),
base2k: base2k.into(), base2k: base2k.into(),
k: k_out.into(), k: k_out.into(),
@@ -138,7 +95,7 @@ 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(
GGSW::encrypt_sk_tmp_bytes(module, &ct_in) GGSW::encrypt_sk_tmp_bytes(module, &ct_in)
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key) | AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
| TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key) | TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
@@ -149,7 +106,9 @@ where
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct_out); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct_out);
sk.fill_ternary_prob(var_xs, &mut source_xs); sk.fill_ternary_prob(var_xs, &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_from_infos(module, &sk);
sk_prepared.prepare(module, &sk);
auto_key.encrypt_sk( auto_key.encrypt_sk(
module, module,
@@ -178,11 +137,12 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout); let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
tsk_prepared.prepare(module, &tensor_key, scratch.borrow()); tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
ct_out.automorphism( ct_out.automorphism(
@@ -217,56 +177,22 @@ where
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn test_ggsw_automorphism_inplace<B>(module: &Module<B>) pub fn test_ggsw_automorphism_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<B>: VecZnxDftBytesOf Module<BE>: GGSWEncryptSk<BE>
+ VecZnxBigBytesOf + AutomorphismKeyEncryptSk<BE>
+ VecZnxDftApply<B> + AutomorphismKeyPreparedAlloc<BE>
+ SvpApplyDftToDftInplace<B> + AutomorphismKeyPrepare<BE>
+ VecZnxIdftApplyConsume<B> + GGSWAutomorphism<BE>
+ VecZnxBigAddInplace<B> + TensorKeyPrepare<BE>
+ VecZnxBigAddSmallInplace<B> + TensorKeyPreparedAlloc<BE>
+ VecZnxBigNormalize<B> + TensorKeyEncryptSk<BE>
+ VecZnxNormalizeTmpBytes + GLWESecretPrepare<BE>
+ VecZnxBigAlloc<B> + GLWESecretPreparedAlloc<BE>
+ VecZnxDftAlloc<B> + VecZnxAutomorphismInplace<BE>
+ VecZnxBigNormalizeTmpBytes + GGSWNoise<BE>,
+ VecZnxIdftApplyTmpA<B> ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
+ SvpPrepare<B> Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
+ SvpPPolBytesOf
+ SvpPPolAlloc<B>
+ VecZnxAddScalarInplace
+ VecZnxCopy
+ VecZnxSubInplace
+ VmpPMatAlloc<B>
+ VmpPrepare<B>
+ VmpApplyDftToDftTmpBytes
+ VmpApplyDftToDft<B>
+ VmpApplyDftToDftAdd<B>
+ VecZnxBigAddSmallInplace<B>
+ VecZnxDftCopy<B>
+ VecZnxDftAddInplace<B>
+ VecZnxAddInplace
+ VecZnxNormalizeInplace<B>
+ VecZnxAddNormal
+ VecZnxNormalize<B>
+ VecZnxSub
+ VecZnxFillUniform
+ SvpApplyDftToDft<B>
+ VecZnxSwitchRing
+ VecZnxAutomorphismInplace<B>
+ VecZnxAutomorphism,
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 = 54; let k_out: usize = 54;
@@ -282,7 +208,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_layout: GGSWCiphertextLayout = GGSWCiphertextLayout { let ggsw_out_layout: GGSWLayout = GGSWLayout {
n: n.into(), n: n.into(),
base2k: base2k.into(), base2k: base2k.into(),
k: k_out.into(), k: k_out.into(),
@@ -318,18 +244,20 @@ 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(
GGSW::encrypt_sk_tmp_bytes(module, &ct) GGSW::encrypt_sk_tmp_bytes(module, &ct)
| AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key) | AutomorphismKey::encrypt_sk_tmp_bytes(module, &auto_key)
| TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key) | TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key)
| GGSW::automorphism_inplace_tmp_bytes(module, &ct, &auto_key, &tensor_key), | GGSW::automorphism_tmp_bytes(module, &ct, &ct, &auto_key, &tensor_key),
); );
let var_xs: f64 = 0.5; let var_xs: f64 = 0.5;
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct);
sk.fill_ternary_prob(var_xs, &mut source_xs); sk.fill_ternary_prob(var_xs, &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_from_infos(module, &sk);
sk_prepared.prepare(module, &sk);
auto_key.encrypt_sk( auto_key.encrypt_sk(
module, module,
@@ -358,11 +286,12 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = let mut auto_key_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout); AutomorphismKeyPrepared::alloc_from_infos(module, &auto_key_layout);
auto_key_prepared.prepare(module, &auto_key, scratch.borrow()); auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, B> = TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout); let mut tsk_prepared: TensorKeyPrepared<Vec<u8>, BE> =
TensorKeyPrepared::alloc_from_infos(module, &tensor_key_layout);
tsk_prepared.prepare(module, &tensor_key, scratch.borrow()); tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow()); ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow());

View File

@@ -1,69 +1,35 @@
use poulpy_hal::{ use poulpy_hal::{
api::{ api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAutomorphismInplace, VecZnxFillUniform},
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare, layouts::{Backend, Module, Scratch, ScratchOwned},
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxAutomorphismInplace,
VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes,
VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace,
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, VmpApplyDftToDft, VmpApplyDftToDftAdd,
VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare,
},
layouts::{Backend, Module, ScratchOwned},
oep::{
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl,
},
source::Source, source::Source,
}; };
use crate::{ use crate::{
AutomorphismKeyEncryptSk, GLWEAutomorphism, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
AutomorphismKey, AutomorphismKeyLayout, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, AutomorphismKey, AutomorphismKeyLayout, AutomorphismKeyPrepare, AutomorphismKeyPreparedAlloc, GLWE, GLWELayout,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared, Prepare, PrepareAlloc}, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared},
}, },
noise::log2_std_noise_gglwe_product, noise::log2_std_noise_gglwe_product,
}; };
pub fn test_glwe_automorphism<B>(module: &Module<B>) pub fn test_glwe_automorphism<BE: Backend>(module: &Module<BE>)
where where
Module<B>: VecZnxDftBytesOf Module<BE>: GLWEEncryptSk<BE>
+ VecZnxBigNormalize<B> + GLWESecretPrepare<BE>
+ VecZnxDftApply<B> + GLWESecretPreparedAlloc<BE>
+ SvpApplyDftToDftInplace<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxFillUniform + VecZnxFillUniform
+ VecZnxSubInplace + GLWEDecrypt<BE>
+ VecZnxAddInplace + GLWEAutomorphism<BE>
+ VecZnxNormalizeInplace<B> + AutomorphismKeyEncryptSk<BE>
+ VecZnxAddNormal + AutomorphismKeyPrepare<BE>
+ VecZnxNormalize<B> + AutomorphismKeyPreparedAlloc<BE>
+ VecZnxSub + GLWENoise<BE>
+ SvpPrepare<B> + VecZnxAutomorphismInplace<BE>,
+ SvpPPolBytesOf ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
+ SvpPPolAlloc<B> Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
+ VecZnxBigBytesOf
+ VecZnxBigAddInplace<B>
+ VecZnxBigAddSmallInplace<B>
+ VmpApplyDftToDftTmpBytes
+ VecZnxBigNormalizeTmpBytes
+ VmpApplyDftToDft<B>
+ VmpApplyDftToDftAdd<B>
+ VecZnxAutomorphism
+ VecZnxSwitchRing
+ VecZnxAddScalarInplace
+ VecZnxAutomorphismInplace<B>
+ VmpPMatAlloc<B>
+ VmpPrepare<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 = 60; let k_in: usize = 60;
@@ -111,7 +77,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 scratch: ScratchOwned<B> = ScratchOwned::alloc( let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
AutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey) AutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey)
| GLWE::decrypt_tmp_bytes(module, &ct_out) | GLWE::decrypt_tmp_bytes(module, &ct_out)
| GLWE::encrypt_sk_tmp_bytes(module, &ct_in) | GLWE::encrypt_sk_tmp_bytes(module, &ct_in)
@@ -120,7 +86,9 @@ where
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct_out); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct_out);
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_from_infos(module, &sk);
sk_prepared.prepare(module, &sk);
autokey.encrypt_sk( autokey.encrypt_sk(
module, module,
@@ -140,7 +108,7 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &autokey_infos); AutomorphismKeyPrepared::alloc_from_infos(module, &autokey_infos);
autokey_prepared.prepare(module, &autokey, scratch.borrow()); autokey_prepared.prepare(module, &autokey, scratch.borrow());
@@ -167,46 +135,21 @@ where
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn test_glwe_automorphism_inplace<B>(module: &Module<B>) pub fn test_glwe_automorphism_inplace<BE: Backend>(module: &Module<BE>)
where where
Module<B>: VecZnxDftBytesOf Module<BE>: GLWEEncryptSk<BE>
+ VecZnxBigNormalize<B> + GLWESecretPrepare<BE>
+ VecZnxDftApply<B> + GLWESecretPreparedAlloc<BE>
+ SvpApplyDftToDftInplace<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxFillUniform + VecZnxFillUniform
+ VecZnxSubInplace + GLWEDecrypt<BE>
+ VecZnxAddInplace + GLWEAutomorphism<BE>
+ VecZnxNormalizeInplace<B> + AutomorphismKeyEncryptSk<BE>
+ VecZnxAddNormal + AutomorphismKeyPrepare<BE>
+ VecZnxNormalize<B> + AutomorphismKeyPreparedAlloc<BE>
+ VecZnxSub + GLWENoise<BE>
+ SvpPrepare<B> + VecZnxAutomorphismInplace<BE>,
+ SvpPPolBytesOf ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
+ SvpPPolAlloc<B> Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
+ VecZnxBigBytesOf
+ VecZnxBigAddInplace<B>
+ VecZnxBigAddSmallInplace<B>
+ VmpApplyDftToDftTmpBytes
+ VecZnxBigNormalizeTmpBytes
+ VmpApplyDftToDft<B>
+ VmpApplyDftToDftAdd<B>
+ VecZnxAutomorphism
+ VecZnxSwitchRing
+ VecZnxAddScalarInplace
+ VecZnxAutomorphismInplace<B>
+ VmpPMatAlloc<B>
+ VmpPrepare<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;
@@ -245,16 +188,18 @@ 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 scratch: ScratchOwned<B> = ScratchOwned::alloc( let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
AutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey) AutomorphismKey::encrypt_sk_tmp_bytes(module, &autokey)
| GLWE::decrypt_tmp_bytes(module, &ct) | GLWE::decrypt_tmp_bytes(module, &ct)
| GLWE::encrypt_sk_tmp_bytes(module, &ct) | GLWE::encrypt_sk_tmp_bytes(module, &ct)
| GLWE::automorphism_inplace_tmp_bytes(module, &ct, &autokey), | GLWE::automorphism_tmp_bytes(module, &ct, &ct, &autokey),
); );
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct); let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&ct);
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_from_infos(module, &sk);
sk_prepared.prepare(module, &sk);
autokey.encrypt_sk( autokey.encrypt_sk(
module, module,
@@ -274,7 +219,7 @@ where
scratch.borrow(), scratch.borrow(),
); );
let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, B> = let mut autokey_prepared: AutomorphismKeyPrepared<Vec<u8>, BE> =
AutomorphismKeyPrepared::alloc_from_infos(module, &autokey); AutomorphismKeyPrepared::alloc_from_infos(module, &autokey);
autokey_prepared.prepare(module, &autokey, scratch.borrow()); autokey_prepared.prepare(module, &autokey, scratch.borrow());

View File

@@ -1,4 +1,4 @@
// 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;

View File

@@ -114,7 +114,7 @@ where
} }
let g_exp: u64 = let g_exp: u64 =
mod_exp_u64(GALOISGENERATOR, (self.cyclotomic_order() - 1) as usize) & (self.cyclotomic_order() - 1) as u64; mod_exp_u64(gal_el.unsigned_abs(), (self.cyclotomic_order() - 1) as usize) & (self.cyclotomic_order() - 1) as u64;
g_exp as i64 * gal_el.signum() g_exp as i64 * gal_el.signum()
} }
} }