mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
conversions tests
This commit is contained in:
@@ -112,14 +112,13 @@ impl<D: DataMut> LWE<D> {
|
|||||||
module.lwe_sample_extract(self, a);
|
module.lwe_sample_extract(self, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_glwe<R, A, K, M, BE: Backend>(&self, module: &M, res: &mut R, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
pub fn from_glwe<A, K, M, BE: Backend>(&mut self, module: &M, a: &A, key: &K, scratch: &mut Scratch<BE>)
|
||||||
where
|
where
|
||||||
R: LWEToMut,
|
|
||||||
A: GLWEToRef,
|
A: GLWEToRef,
|
||||||
K: GGLWEPreparedToRef<BE> + GGLWEInfos,
|
K: GGLWEPreparedToRef<BE> + GGLWEInfos,
|
||||||
M: LWEFromGLWE<BE>,
|
M: LWEFromGLWE<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
module.lwe_from_glwe(res, a, key, scratch);
|
module.lwe_from_glwe(self, a, key, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ impl GLWEToLWESwitchingKey<Vec<u8>> {
|
|||||||
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: GLWEToLWESwitchingKeyEncrypt<BE>,
|
M: GLWEToLWESwitchingKeyEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes(infos)
|
module.glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
|||||||
source_xe: &mut Source,
|
source_xe: &mut Source,
|
||||||
scratch: &mut Scratch<BE>,
|
scratch: &mut Scratch<BE>,
|
||||||
) where
|
) where
|
||||||
M: GLWEToLWESwitchingKeyEncrypt<BE>,
|
M: GLWEToLWESwitchingKeyEncryptSk<BE>,
|
||||||
S1: LWESecretToRef,
|
S1: LWESecretToRef,
|
||||||
S2: GLWESecretToRef,
|
S2: GLWESecretToRef,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
@@ -42,7 +42,7 @@ impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GLWEToLWESwitchingKeyEncrypt<BE: Backend> {
|
pub trait GLWEToLWESwitchingKeyEncryptSk<BE: Backend> {
|
||||||
fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
@@ -61,7 +61,7 @@ pub trait GLWEToLWESwitchingKeyEncrypt<BE: Backend> {
|
|||||||
R: GGLWEToMut;
|
R: GGLWEToMut;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> GLWEToLWESwitchingKeyEncrypt<BE> for Module<BE>
|
impl<BE: Backend> GLWEToLWESwitchingKeyEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: ModuleN
|
Self: ModuleN
|
||||||
+ GGLWEEncryptSk<BE>
|
+ GGLWEEncryptSk<BE>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ impl LWEToGLWESwitchingKey<Vec<u8>> {
|
|||||||
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos,
|
A: GGLWEInfos,
|
||||||
M: LWEToGLWESwitchingKeyEncrypt<BE>,
|
M: LWEToGLWESwitchingKeyEncryptSk<BE>,
|
||||||
{
|
{
|
||||||
module.lwe_to_glwe_switching_key_encrypt_sk_tmp_bytes(infos)
|
module.lwe_to_glwe_switching_key_encrypt_sk_tmp_bytes(infos)
|
||||||
}
|
}
|
||||||
@@ -34,14 +34,14 @@ impl<D: DataMut> LWEToGLWESwitchingKey<D> {
|
|||||||
) where
|
) where
|
||||||
S1: LWESecretToRef,
|
S1: LWESecretToRef,
|
||||||
S2: GLWESecretPreparedToRef<BE>,
|
S2: GLWESecretPreparedToRef<BE>,
|
||||||
M: LWEToGLWESwitchingKeyEncrypt<BE>,
|
M: LWEToGLWESwitchingKeyEncryptSk<BE>,
|
||||||
Scratch<BE>: ScratchTakeCore<BE>,
|
Scratch<BE>: ScratchTakeCore<BE>,
|
||||||
{
|
{
|
||||||
module.lwe_to_glwe_switching_key_encrypt_sk(self, sk_lwe, sk_glwe, source_xa, source_xe, scratch);
|
module.lwe_to_glwe_switching_key_encrypt_sk(self, sk_lwe, sk_glwe, source_xa, source_xe, scratch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LWEToGLWESwitchingKeyEncrypt<BE: Backend> {
|
pub trait LWEToGLWESwitchingKeyEncryptSk<BE: Backend> {
|
||||||
fn lwe_to_glwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
fn lwe_to_glwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||||
where
|
where
|
||||||
A: GGLWEInfos;
|
A: GGLWEInfos;
|
||||||
@@ -60,7 +60,7 @@ pub trait LWEToGLWESwitchingKeyEncrypt<BE: Backend> {
|
|||||||
R: GGLWEToMut;
|
R: GGLWEToMut;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<BE: Backend> LWEToGLWESwitchingKeyEncrypt<BE> for Module<BE>
|
impl<BE: Backend> LWEToGLWESwitchingKeyEncryptSk<BE> for Module<BE>
|
||||||
where
|
where
|
||||||
Self: ModuleN
|
Self: ModuleN
|
||||||
+ GGLWEEncryptSk<BE>
|
+ GGLWEEncryptSk<BE>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::layouts::{
|
use crate::layouts::{
|
||||||
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESwitchingKey,
|
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyDegrees,
|
||||||
GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -217,3 +217,13 @@ impl<D: DataMut> GLWESwitchingKeyDegreesMut for GLWEToLWESwitchingKey<D> {
|
|||||||
&mut self.0.output_degree
|
&mut self.0.output_degree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: DataRef> GLWESwitchingKeyDegrees for GLWEToLWESwitchingKey<D> {
|
||||||
|
fn input_degree(&self) -> &Degree {
|
||||||
|
&self.0.input_degree
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_degree(&self) -> &Degree {
|
||||||
|
&self.0.output_degree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use poulpy_hal::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::layouts::{
|
use crate::layouts::{
|
||||||
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESwitchingKey,
|
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyDegrees,
|
||||||
GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -217,3 +217,13 @@ impl<D: DataMut> GLWESwitchingKeyDegreesMut for LWEToGLWESwitchingKey<D> {
|
|||||||
&mut self.0.output_degree
|
&mut self.0.output_degree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: DataRef> GLWESwitchingKeyDegrees for LWEToGLWESwitchingKey<D> {
|
||||||
|
fn input_degree(&self) -> &Degree {
|
||||||
|
&self.0.input_degree
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_degree(&self) -> &Degree {
|
||||||
|
&self.0.output_degree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -206,3 +206,13 @@ impl<D: DataMut, B: Backend> GLWESwitchingKeyDegreesMut for GLWEToLWESwitchingKe
|
|||||||
&mut self.0.output_degree
|
&mut self.0.output_degree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: DataRef, B: Backend> GLWESwitchingKeyDegrees for GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||||
|
fn input_degree(&self) -> &Degree {
|
||||||
|
&self.0.input_degree
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_degree(&self) -> &Degree {
|
||||||
|
&self.0.output_degree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorph
|
|||||||
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,
|
||||||
// lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
|
lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// #[cfg(test)]
|
// #[cfg(test)]
|
||||||
|
|||||||
@@ -1,68 +1,33 @@
|
|||||||
use poulpy_hal::{
|
use poulpy_hal::{
|
||||||
api::{
|
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||||
ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare,
|
layouts::{Backend, Module, Scratch, ScratchOwned, ZnxView},
|
||||||
VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigAddInplace,
|
|
||||||
VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftApply,
|
|
||||||
VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace,
|
|
||||||
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, VmpApplyDftToDft, VmpApplyDftToDftAdd,
|
|
||||||
VmpApplyDftToDftTmpBytes, VmpPMatAlloc, VmpPrepare, ZnAddNormal, ZnFillUniform, ZnNormalizeInplace,
|
|
||||||
},
|
|
||||||
layouts::{Backend, Module, ScratchOwned, ZnxView},
|
|
||||||
oep::{
|
|
||||||
ScratchAvailableImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeScalarZnxImpl, TakeSvpPPolImpl,
|
|
||||||
TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxImpl,
|
|
||||||
},
|
|
||||||
source::Source,
|
source::Source,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::layouts::{
|
use crate::{
|
||||||
Base2K, Degree, Dnum, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, LWE,
|
GLWEDecrypt, GLWEEncryptSk, GLWEFromLWE, GLWEToLWESwitchingKeyEncryptSk, LWEDecrypt, LWEEncryptSk,
|
||||||
LWECiphertextLayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, Rank, TorusPrecision,
|
LWEToGLWESwitchingKeyEncryptSk, ScratchTakeCore,
|
||||||
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared, PrepareAlloc},
|
layouts::{
|
||||||
|
Base2K, Degree, Dnum, GLWE, GLWELayout, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc,
|
||||||
|
GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyPrepare, GLWEToLWESwitchingKeyPreparedAlloc, LWE,
|
||||||
|
LWELayout, LWEPlaintext, LWESecret, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyLayout, LWEToGLWESwitchingKeyPrepare,
|
||||||
|
LWEToGLWESwitchingKeyPreparedAlloc, Rank, TorusPrecision,
|
||||||
|
prepared::{GLWESecretPrepared, GLWEToLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPrepared},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn test_lwe_to_glwe<B>(module: &Module<B>)
|
pub fn test_lwe_to_glwe<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GLWEFromLWE<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ LWEToGLWESwitchingKeyEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ VecZnxFillUniform
|
+ LWEEncryptSk<BE>
|
||||||
+ VecZnxSubInplace
|
+ LWEToGLWESwitchingKeyPreparedAlloc<BE>
|
||||||
+ VecZnxAddInplace
|
+ LWEToGLWESwitchingKeyPrepare<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>
|
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ ZnNormalizeInplace<B>
|
|
||||||
+ ZnFillUniform
|
|
||||||
+ ZnAddNormal,
|
|
||||||
B: Backend
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>,
|
|
||||||
{
|
{
|
||||||
let n_glwe: Degree = Degree(module.n() as u32);
|
let n_glwe: Degree = Degree(module.n() as u32);
|
||||||
let n_lwe: Degree = Degree(22);
|
let n_lwe: Degree = Degree(22);
|
||||||
@@ -89,13 +54,13 @@ where
|
|||||||
rank,
|
rank,
|
||||||
};
|
};
|
||||||
|
|
||||||
let lwe_infos: LWECiphertextLayout = LWECiphertextLayout {
|
let lwe_infos: LWELayout = LWELayout {
|
||||||
n: n_lwe,
|
n: n_lwe,
|
||||||
base2k: Base2K(17),
|
base2k: Base2K(17),
|
||||||
k: TorusPrecision(34),
|
k: TorusPrecision(34),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
LWEToGLWESwitchingKey::encrypt_sk_tmp_bytes(module, &lwe_to_glwe_infos)
|
LWEToGLWESwitchingKey::encrypt_sk_tmp_bytes(module, &lwe_to_glwe_infos)
|
||||||
| GLWE::from_lwe_tmp_bytes(module, &glwe_infos, &lwe_infos, &lwe_to_glwe_infos)
|
| GLWE::from_lwe_tmp_bytes(module, &glwe_infos, &lwe_infos, &lwe_to_glwe_infos)
|
||||||
| GLWE::decrypt_tmp_bytes(module, &glwe_infos),
|
| GLWE::decrypt_tmp_bytes(module, &glwe_infos),
|
||||||
@@ -104,7 +69,8 @@ where
|
|||||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_glwe.prepare_alloc(module, scratch.borrow());
|
let mut sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(module, &sk_glwe);
|
||||||
|
sk_glwe_prepared.prepare(module, &sk_glwe);
|
||||||
|
|
||||||
let mut sk_lwe: LWESecret<Vec<u8>> = LWESecret::alloc(n_lwe);
|
let mut sk_lwe: LWESecret<Vec<u8>> = LWESecret::alloc(n_lwe);
|
||||||
sk_lwe.fill_ternary_prob(0.5, &mut source_xs);
|
sk_lwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
@@ -122,7 +88,7 @@ where
|
|||||||
ksk.encrypt_sk(
|
ksk.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
&sk_lwe,
|
&sk_lwe,
|
||||||
&sk_glwe,
|
&sk_glwe_prepared,
|
||||||
&mut source_xa,
|
&mut source_xa,
|
||||||
&mut source_xe,
|
&mut source_xe,
|
||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
@@ -130,7 +96,9 @@ where
|
|||||||
|
|
||||||
let mut glwe_ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_infos);
|
let mut glwe_ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_infos);
|
||||||
|
|
||||||
let ksk_prepared: LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
let mut ksk_prepared: LWEToGLWESwitchingKeyPrepared<Vec<u8>, BE> =
|
||||||
|
LWEToGLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
||||||
|
ksk_prepared.prepare(module, &ksk, scratch.borrow());
|
||||||
|
|
||||||
glwe_ct.from_lwe(module, &lwe_ct, &ksk_prepared, scratch.borrow());
|
glwe_ct.from_lwe(module, &lwe_ct, &ksk_prepared, scratch.borrow());
|
||||||
|
|
||||||
@@ -140,46 +108,20 @@ where
|
|||||||
assert_eq!(glwe_pt.data.at(0, 0)[0], lwe_pt.data.at(0, 0)[0]);
|
assert_eq!(glwe_pt.data.at(0, 0)[0], lwe_pt.data.at(0, 0)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_glwe_to_lwe<B>(module: &Module<B>)
|
pub fn test_glwe_to_lwe<BE: Backend>(module: &Module<BE>)
|
||||||
where
|
where
|
||||||
Module<B>: VecZnxDftBytesOf
|
Module<BE>: GLWEFromLWE<BE>
|
||||||
+ VecZnxBigNormalize<B>
|
+ GLWEToLWESwitchingKeyEncryptSk<BE>
|
||||||
+ VecZnxDftApply<B>
|
+ GLWEEncryptSk<BE>
|
||||||
+ SvpApplyDftToDftInplace<B>
|
+ LWEDecrypt<BE>
|
||||||
+ VecZnxIdftApplyConsume<B>
|
+ GLWEDecrypt<BE>
|
||||||
+ VecZnxFillUniform
|
+ GLWESecretPrepare<BE>
|
||||||
+ VecZnxSubInplace
|
+ GLWESecretPreparedAlloc<BE>
|
||||||
+ VecZnxAddInplace
|
+ GLWEToLWESwitchingKeyEncryptSk<BE>
|
||||||
+ VecZnxNormalizeInplace<B>
|
+ GLWEToLWESwitchingKeyPrepare<BE>
|
||||||
+ VecZnxAddNormal
|
+ GLWEToLWESwitchingKeyPreparedAlloc<BE>,
|
||||||
+ VecZnxNormalize<B>
|
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||||
+ VecZnxSub
|
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||||
+ SvpPrepare<B>
|
|
||||||
+ SvpPPolBytesOf
|
|
||||||
+ SvpPPolAlloc<B>
|
|
||||||
+ VecZnxBigBytesOf
|
|
||||||
+ VecZnxBigAddInplace<B>
|
|
||||||
+ VecZnxBigAddSmallInplace<B>
|
|
||||||
+ VecZnxNormalizeTmpBytes
|
|
||||||
+ VecZnxAddScalarInplace
|
|
||||||
+ VmpPMatAlloc<B>
|
|
||||||
+ VmpPrepare<B>
|
|
||||||
+ VmpApplyDftToDftTmpBytes
|
|
||||||
+ VmpApplyDftToDft<B>
|
|
||||||
+ VmpApplyDftToDftAdd<B>
|
|
||||||
+ VecZnxBigNormalizeTmpBytes
|
|
||||||
+ VecZnxSwitchRing
|
|
||||||
+ VecZnxAutomorphismInplace<B>
|
|
||||||
+ ZnNormalizeInplace<B>,
|
|
||||||
B: Backend
|
|
||||||
+ TakeVecZnxDftImpl<B>
|
|
||||||
+ TakeVecZnxBigImpl<B>
|
|
||||||
+ TakeSvpPPolImpl<B>
|
|
||||||
+ ScratchOwnedAllocImpl<B>
|
|
||||||
+ ScratchOwnedBorrowImpl<B>
|
|
||||||
+ ScratchAvailableImpl<B>
|
|
||||||
+ TakeScalarZnxImpl<B>
|
|
||||||
+ TakeVecZnxImpl<B>,
|
|
||||||
{
|
{
|
||||||
let n_glwe: Degree = Degree(module.n() as u32);
|
let n_glwe: Degree = Degree(module.n() as u32);
|
||||||
let n_lwe: Degree = Degree(22);
|
let n_lwe: Degree = Degree(22);
|
||||||
@@ -202,7 +144,7 @@ where
|
|||||||
rank,
|
rank,
|
||||||
};
|
};
|
||||||
|
|
||||||
let lwe_infos: LWECiphertextLayout = LWECiphertextLayout {
|
let lwe_infos: LWELayout = LWELayout {
|
||||||
n: n_lwe,
|
n: n_lwe,
|
||||||
base2k: Base2K(17),
|
base2k: Base2K(17),
|
||||||
k: TorusPrecision(34),
|
k: TorusPrecision(34),
|
||||||
@@ -212,7 +154,7 @@ where
|
|||||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
let mut source_xa: 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(
|
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(
|
||||||
GLWEToLWESwitchingKey::encrypt_sk_tmp_bytes(module, &glwe_to_lwe_infos)
|
GLWEToLWESwitchingKey::encrypt_sk_tmp_bytes(module, &glwe_to_lwe_infos)
|
||||||
| LWE::from_glwe_tmp_bytes(module, &lwe_infos, &glwe_infos, &glwe_to_lwe_infos)
|
| LWE::from_glwe_tmp_bytes(module, &lwe_infos, &glwe_infos, &glwe_to_lwe_infos)
|
||||||
| GLWE::decrypt_tmp_bytes(module, &glwe_infos),
|
| GLWE::decrypt_tmp_bytes(module, &glwe_infos),
|
||||||
@@ -221,7 +163,8 @@ where
|
|||||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
|
|
||||||
let sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, B> = sk_glwe.prepare_alloc(module, scratch.borrow());
|
let mut sk_glwe_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(module, &sk_glwe);
|
||||||
|
sk_glwe_prepared.prepare(module, &sk_glwe);
|
||||||
|
|
||||||
let mut sk_lwe: LWESecret<Vec<u8>> = LWESecret::alloc(n_lwe);
|
let mut sk_lwe: LWESecret<Vec<u8>> = LWESecret::alloc(n_lwe);
|
||||||
sk_lwe.fill_ternary_prob(0.5, &mut source_xs);
|
sk_lwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||||
@@ -230,7 +173,7 @@ where
|
|||||||
let mut glwe_pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_infos);
|
let mut glwe_pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_infos);
|
||||||
glwe_pt.encode_coeff_i64(data, k_lwe_pt, 0);
|
glwe_pt.encode_coeff_i64(data, k_lwe_pt, 0);
|
||||||
|
|
||||||
let mut glwe_ct = GLWE::alloc_from_infos(&glwe_infos);
|
let mut glwe_ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_infos);
|
||||||
glwe_ct.encrypt_sk(
|
glwe_ct.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
&glwe_pt,
|
&glwe_pt,
|
||||||
@@ -240,7 +183,7 @@ where
|
|||||||
scratch.borrow(),
|
scratch.borrow(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut ksk: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(&glwe_to_lwe_infos);
|
let mut ksk: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc_from_infos(&glwe_to_lwe_infos);
|
||||||
|
|
||||||
ksk.encrypt_sk(
|
ksk.encrypt_sk(
|
||||||
module,
|
module,
|
||||||
@@ -253,7 +196,9 @@ where
|
|||||||
|
|
||||||
let mut lwe_ct: LWE<Vec<u8>> = LWE::alloc_from_infos(&lwe_infos);
|
let mut lwe_ct: LWE<Vec<u8>> = LWE::alloc_from_infos(&lwe_infos);
|
||||||
|
|
||||||
let ksk_prepared: GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> = ksk.prepare_alloc(module, scratch.borrow());
|
let mut ksk_prepared: GLWEToLWESwitchingKeyPrepared<Vec<u8>, BE> =
|
||||||
|
GLWEToLWESwitchingKeyPrepared::alloc_from_infos(module, &ksk);
|
||||||
|
ksk_prepared.prepare(module, &ksk, scratch.borrow());
|
||||||
|
|
||||||
lwe_ct.from_glwe(module, &glwe_ct, &ksk_prepared, scratch.borrow());
|
lwe_ct.from_glwe(module, &glwe_ct, &ksk_prepared, scratch.borrow());
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ pub mod encryption;
|
|||||||
pub mod external_product;
|
pub mod external_product;
|
||||||
pub mod keyswitch;
|
pub mod keyswitch;
|
||||||
|
|
||||||
// mod conversion;
|
mod conversion;
|
||||||
// mod packing;
|
// mod packing;
|
||||||
// mod trace;
|
// mod trace;
|
||||||
|
|
||||||
// pub use conversion::*;
|
pub use conversion::*;
|
||||||
// pub use packing::*;
|
// pub use packing::*;
|
||||||
// pub use trace::*;
|
// pub use trace::*;
|
||||||
|
|||||||
Reference in New Issue
Block a user