mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Removed traits on structs not dependent on Module API
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
use poulpy_hal::{
|
||||
api::{
|
||||
ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow,
|
||||
VecZnxAutomorphism,VecZnxFillUniform,
|
||||
},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned, GaloisElement},
|
||||
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAutomorphism, VecZnxFillUniform},
|
||||
layouts::{Backend, GaloisElement, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
compressed::AutomorphismKeyCompressed, prepared::GLWESecretPrepared,
|
||||
AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos,
|
||||
GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKeyAlloc, GLWESwitchingKeyDecompress
|
||||
AutomorphismKey, AutomorphismKeyDecompress, AutomorphismKeyLayout, GLWEInfos, GLWESecret, GLWESecretPrepare,
|
||||
GLWESecretPreparedAlloc, GLWESwitchingKeyDecompress, compressed::AutomorphismKeyCompressed, prepared::GLWESecretPrepared,
|
||||
},
|
||||
noise::GGLWENoise,
|
||||
GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore
|
||||
};
|
||||
|
||||
pub fn test_gglwe_automorphism_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
@@ -24,7 +20,6 @@ where
|
||||
+ GGLWEKeyswitch<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESwitchingKeyAlloc
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ GLWESwitchingKeyCompressedEncryptSk<BE>
|
||||
+ GLWESwitchingKeyDecompress
|
||||
@@ -32,7 +27,7 @@ where
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxAutomorphism,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 12;
|
||||
let k_ksk: usize = 60;
|
||||
@@ -51,17 +46,15 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(module, &atk_infos);
|
||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&atk_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_tmp_bytes(
|
||||
module, &atk_infos,
|
||||
));
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_tmp_bytes(module, &atk_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &atk_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&atk_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let p = -5;
|
||||
@@ -101,7 +94,6 @@ where
|
||||
+ GGLWEKeyswitch<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESwitchingKeyAlloc
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ GLWESwitchingKeyCompressedEncryptSk<BE>
|
||||
+ AutomorphismKeyDecompress
|
||||
@@ -109,7 +101,7 @@ where
|
||||
+ VecZnxFillUniform
|
||||
+ GGLWENoise<BE>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let base2k: usize = 12;
|
||||
let k_ksk: usize = 60;
|
||||
@@ -128,16 +120,14 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut atk_compressed: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc_from_infos(module, &atk_infos);
|
||||
let mut atk_compressed: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc_from_infos(&atk_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_tmp_bytes(
|
||||
module, &atk_infos,
|
||||
));
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(AutomorphismKey::encrypt_sk_tmp_bytes(module, &atk_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &atk_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&atk_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let p = -5;
|
||||
@@ -159,7 +149,7 @@ where
|
||||
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank().into());
|
||||
sk_out_prepared.prepare(module, &sk_out);
|
||||
|
||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(module, &atk_infos);
|
||||
let mut atk: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_from_infos(&atk_infos);
|
||||
atk.decompress(module, &atk_compressed);
|
||||
|
||||
atk.key
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
use poulpy_hal::{
|
||||
api::{
|
||||
ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform,
|
||||
},
|
||||
api::{ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxFillUniform},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
decryption::GLWEDecrypt, encryption::SIGMA, layouts::{
|
||||
prepared::{GGLWEPrepare, GGLWEPreparedAlloc, GLWESecretPrepared}, GGLWELayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyCompressed, GLWESwitchingKeyDecompress
|
||||
}, noise::GGLWENoise, GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore
|
||||
GGLWEEncryptSk, GGLWEKeyswitch, GLWESwitchingKeyCompressedEncryptSk, GLWESwitchingKeyEncryptSk, ScratchTakeCore,
|
||||
decryption::GLWEDecrypt,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GGLWELayout, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, GLWESwitchingKey, GLWESwitchingKeyCompressed,
|
||||
GLWESwitchingKeyDecompress,
|
||||
prepared::{GGLWEPrepare, GGLWEPreparedAlloc, GLWESecretPrepared},
|
||||
},
|
||||
noise::GGLWENoise,
|
||||
};
|
||||
|
||||
pub fn test_gglwe_switching_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
@@ -21,20 +25,19 @@ where
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESwitchingKeyAlloc
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GGLWENoise<BE>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let n = module.n();
|
||||
let base2k: usize = 12;
|
||||
let k_ksk: usize = 54;
|
||||
let dsize: usize = k_ksk / base2k;
|
||||
for rank_in in 1_usize..3 {
|
||||
for rank_out in 1_usize..3 {
|
||||
for di in 1_usize..dsize + 1 {
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let gglwe_infos: GGLWELayout = GGLWELayout {
|
||||
@@ -47,21 +50,19 @@ where
|
||||
rank_out: rank_out.into(),
|
||||
};
|
||||
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(module, &gglwe_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(GLWESwitchingKey::encrypt_sk_tmp_bytes(
|
||||
module,
|
||||
&gglwe_infos,
|
||||
));
|
||||
let mut scratch: ScratchOwned<BE> =
|
||||
ScratchOwned::alloc(GLWESwitchingKey::encrypt_sk_tmp_bytes(module, &gglwe_infos));
|
||||
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_in.into());
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_in.into());
|
||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_out.into());
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
||||
sk_out.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank_out.into());
|
||||
sk_out_prepared.prepare(module, &sk_out);
|
||||
@@ -91,7 +92,6 @@ where
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESwitchingKeyAlloc
|
||||
+ GLWESwitchingKeyEncryptSk<BE>
|
||||
+ GLWESwitchingKeyCompressedEncryptSk<BE>
|
||||
+ GLWESwitchingKeyDecompress
|
||||
@@ -100,13 +100,13 @@ where
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
let n: usize = module.n();
|
||||
let base2k: usize = 12;
|
||||
let k_ksk: usize = 54;
|
||||
let dsize: usize = k_ksk / base2k;
|
||||
for rank_in in 1_usize..3 {
|
||||
for rank_out in 1_usize..3 {
|
||||
for di in 1_usize..dsize + 1 {
|
||||
let n: usize = module.n();
|
||||
let dnum: usize = (k_ksk - di * base2k) / (di * base2k);
|
||||
|
||||
let gglwe_infos: GGLWELayout = GGLWELayout {
|
||||
@@ -120,7 +120,7 @@ where
|
||||
};
|
||||
|
||||
let mut ksk_compressed: GLWESwitchingKeyCompressed<Vec<u8>> =
|
||||
GLWESwitchingKeyCompressed::alloc_from_infos(module, &gglwe_infos);
|
||||
GLWESwitchingKeyCompressed::alloc_from_infos(&gglwe_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
@@ -130,10 +130,10 @@ where
|
||||
&gglwe_infos,
|
||||
));
|
||||
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_in.into());
|
||||
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_in.into());
|
||||
sk_in.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, rank_out.into());
|
||||
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), rank_out.into());
|
||||
sk_out.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank_out.into());
|
||||
sk_out_prepared.prepare(module, &sk_out);
|
||||
@@ -149,7 +149,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(module, &gglwe_infos);
|
||||
let mut ksk: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc_from_infos(&gglwe_infos);
|
||||
ksk.decompress(module, &ksk_compressed);
|
||||
|
||||
ksk.key
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::{
|
||||
decryption::GLWEDecrypt,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
GLWE, GLWEAlloc, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWEPublicKey, GLWEPublicKeyPrepare,
|
||||
GLWEPublicKeyPreparedAlloc, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, LWEInfos,
|
||||
GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWEPublicKey, GLWEPublicKeyPrepare, GLWEPublicKeyPreparedAlloc,
|
||||
GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, LWEInfos,
|
||||
compressed::GLWECompressed,
|
||||
prepared::{GLWEPublicKeyPrepared, GLWESecretPrepared},
|
||||
},
|
||||
@@ -18,13 +18,8 @@ use crate::{
|
||||
|
||||
pub fn test_glwe_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWEEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GLWESub,
|
||||
Module<BE>:
|
||||
GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxFillUniform + GLWESub,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
@@ -48,9 +43,9 @@ where
|
||||
k: k_pt.into(),
|
||||
};
|
||||
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(module, &glwe_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &pt_infos);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &pt_infos);
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&pt_infos);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&pt_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
@@ -59,7 +54,7 @@ where
|
||||
let mut scratch: ScratchOwned<BE> =
|
||||
ScratchOwned::alloc(GLWE::encrypt_sk_tmp_bytes(module, &glwe_infos) | GLWE::decrypt_tmp_bytes(module, &glwe_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
@@ -89,8 +84,7 @@ where
|
||||
|
||||
pub fn test_glwe_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWECompressedEncryptSk<BE>
|
||||
Module<BE>: GLWECompressedEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
@@ -120,10 +114,10 @@ where
|
||||
k: k_pt.into(),
|
||||
};
|
||||
|
||||
let mut ct_compressed: GLWECompressed<Vec<u8>> = GLWECompressed::alloc_from_infos(module, &glwe_infos);
|
||||
let mut ct_compressed: GLWECompressed<Vec<u8>> = GLWECompressed::alloc_from_infos(&glwe_infos);
|
||||
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &pt_infos);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &pt_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&pt_infos);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&pt_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
@@ -133,7 +127,7 @@ where
|
||||
GLWECompressed::encrypt_sk_tmp_bytes(module, &glwe_infos) | GLWE::decrypt_tmp_bytes(module, &glwe_infos),
|
||||
);
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
@@ -152,7 +146,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(module, &glwe_infos);
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_infos);
|
||||
ct.decompress(module, &ct_compressed);
|
||||
|
||||
ct.decrypt(module, &mut pt_have, &sk_prepared, scratch.borrow());
|
||||
@@ -172,13 +166,8 @@ where
|
||||
|
||||
pub fn test_glwe_encrypt_zero_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWEEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ VecZnxFillUniform
|
||||
+ GLWESub,
|
||||
Module<BE>:
|
||||
GLWEEncryptSk<BE> + GLWEDecrypt<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxFillUniform + GLWESub,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
|
||||
{
|
||||
@@ -195,7 +184,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &glwe_infos);
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([1u8; 32]);
|
||||
@@ -204,13 +193,13 @@ where
|
||||
let mut scratch: ScratchOwned<BE> =
|
||||
ScratchOwned::alloc(GLWE::decrypt_tmp_bytes(module, &glwe_infos) | GLWE::encrypt_sk_tmp_bytes(module, &glwe_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(module, &glwe_infos);
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_infos);
|
||||
|
||||
ct.encrypt_zero_sk(
|
||||
module,
|
||||
@@ -227,8 +216,7 @@ where
|
||||
|
||||
pub fn test_glwe_encrypt_pk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: GLWEAlloc
|
||||
+ GLWEEncryptPk<BE>
|
||||
Module<BE>: GLWEEncryptPk<BE>
|
||||
+ GLWEPublicKeyPrepare<BE>
|
||||
+ GLWEPublicKeyPreparedAlloc<BE>
|
||||
+ GLWEPublicKeyGenerate<BE>
|
||||
@@ -253,9 +241,9 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(module, &glwe_infos);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &glwe_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &glwe_infos);
|
||||
let mut ct: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&glwe_infos);
|
||||
let mut pt_have: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_infos);
|
||||
let mut pt_want: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&glwe_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
@@ -265,13 +253,13 @@ where
|
||||
let mut scratch: ScratchOwned<BE> =
|
||||
ScratchOwned::alloc(GLWE::decrypt_tmp_bytes(module, &glwe_infos) | GLWE::encrypt_pk_tmp_bytes(module, &glwe_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &glwe_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
|
||||
let mut pk: GLWEPublicKey<Vec<u8>> = GLWEPublicKey::alloc_from_infos(module, &glwe_infos);
|
||||
let mut pk: GLWEPublicKey<Vec<u8>> = GLWEPublicKey::alloc_from_infos(&glwe_infos);
|
||||
pk.generate(module, &sk_prepared, &mut source_xa, &mut source_xe);
|
||||
|
||||
module.vec_znx_fill_uniform(base2k, &mut pt_want.data, 0, &mut source_xa);
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
use poulpy_hal::{
|
||||
api::{
|
||||
ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDft, VecZnxBigAlloc, VecZnxBigNormalize, VecZnxCopy, VecZnxDftAlloc, VecZnxDftApply, VecZnxFillUniform, VecZnxIdftApplyTmpA, VecZnxSubScalarInplace, VecZnxSwitchRing
|
||||
}, layouts::{Backend, Module, Scratch, ScratchOwned, VecZnxDft}, oep::{VecZnxNormalizeImpl, VecZnxNormalizeInplaceImpl}, source::Source
|
||||
ScratchAvailable, ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDft, VecZnxBigAlloc, VecZnxBigNormalize,
|
||||
VecZnxCopy, VecZnxDftAlloc, VecZnxDftApply, VecZnxFillUniform, VecZnxIdftApplyTmpA, VecZnxSubScalarInplace,
|
||||
VecZnxSwitchRing,
|
||||
},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned, VecZnxDft},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
decryption::GLWEDecrypt, encryption::SIGMA, layouts::{
|
||||
prepared::GLWESecretPrepared, Dsize, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, TensorKey, TensorKeyAlloc, TensorKeyCompressed, TensorKeyLayout
|
||||
}, GGLWETensorKeyCompressedEncryptSk, ScratchTakeCore, TensorKeyEncryptSk
|
||||
GGLWETensorKeyCompressedEncryptSk, ScratchTakeCore, TensorKeyEncryptSk,
|
||||
decryption::GLWEDecrypt,
|
||||
encryption::SIGMA,
|
||||
layouts::{
|
||||
Dsize, GLWEPlaintext, GLWESecret, GLWESecretPrepare, GLWESecretPreparedAlloc, TensorKey, TensorKeyCompressed,
|
||||
TensorKeyLayout, prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn test_gglwe_tensor_key_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: TensorKeyEncryptSk<BE>
|
||||
+ TensorKeyAlloc
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
@@ -43,18 +50,15 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(module, &tensor_key_infos);
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tensor_key_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
let mut source_xa: Source = Source::new([0u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(TensorKey::encrypt_sk_tmp_bytes(
|
||||
module,
|
||||
&tensor_key_infos,
|
||||
));
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(TensorKey::encrypt_sk_tmp_bytes(module, &tensor_key_infos));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &tensor_key_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&tensor_key_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
@@ -67,11 +71,11 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &tensor_key_infos);
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&tensor_key_infos);
|
||||
|
||||
let mut sk_ij_dft = module.vec_znx_dft_alloc(1, 1);
|
||||
let mut sk_ij_big = module.vec_znx_big_alloc(1, 1);
|
||||
let mut sk_ij: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, 1_u32.into());
|
||||
let mut sk_ij: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), 1_u32.into());
|
||||
let mut sk_dft: VecZnxDft<Vec<u8>, BE> = module.vec_znx_dft_alloc(rank, 1);
|
||||
|
||||
for i in 0..rank {
|
||||
@@ -92,9 +96,7 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
for row_i in 0..dnum {
|
||||
let ct = tensor_key
|
||||
.at(i, j)
|
||||
.at(row_i, 0);
|
||||
let ct = tensor_key.at(i, j).at(row_i, 0);
|
||||
|
||||
ct.decrypt(module, &mut pt, &sk_prepared, scratch.borrow());
|
||||
|
||||
@@ -111,20 +113,19 @@ where
|
||||
pub fn test_gglwe_tensor_key_compressed_encrypt_sk<BE: Backend>(module: &Module<BE>)
|
||||
where
|
||||
Module<BE>: TensorKeyEncryptSk<BE>
|
||||
+ TensorKeyAlloc
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GGLWETensorKeyCompressedEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ VecZnxDftAlloc<BE>
|
||||
+ VecZnxBigAlloc<BE>
|
||||
+ VecZnxDftApply<BE>
|
||||
+ SvpApplyDftToDft<BE>
|
||||
+ VecZnxIdftApplyTmpA<BE>
|
||||
+ VecZnxSubScalarInplace
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxCopy
|
||||
+ VecZnxSwitchRing,
|
||||
+ GLWESecretPrepare<BE>
|
||||
+ GLWESecretPreparedAlloc<BE>
|
||||
+ GGLWETensorKeyCompressedEncryptSk<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ VecZnxDftAlloc<BE>
|
||||
+ VecZnxBigAlloc<BE>
|
||||
+ VecZnxDftApply<BE>
|
||||
+ SvpApplyDftToDft<BE>
|
||||
+ VecZnxIdftApplyTmpA<BE>
|
||||
+ VecZnxSubScalarInplace
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxCopy
|
||||
+ VecZnxSwitchRing,
|
||||
// + VecZnxNormalizeInplaceImpl<BE>
|
||||
// + VecZnxNormalizeImpl<BE>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
@@ -145,7 +146,7 @@ where
|
||||
rank: rank.into(),
|
||||
};
|
||||
|
||||
let mut tensor_key_compressed: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc_from_infos(module, &tensor_key_infos);
|
||||
let mut tensor_key_compressed: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc_from_infos(&tensor_key_infos);
|
||||
|
||||
let mut source_xs: Source = Source::new([0u8; 32]);
|
||||
let mut source_xe: Source = Source::new([0u8; 32]);
|
||||
@@ -155,7 +156,7 @@ where
|
||||
&tensor_key_infos,
|
||||
));
|
||||
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(module, &tensor_key_infos);
|
||||
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&tensor_key_infos);
|
||||
sk.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, rank.into());
|
||||
sk_prepared.prepare(module, &sk);
|
||||
@@ -164,14 +165,14 @@ where
|
||||
|
||||
tensor_key_compressed.encrypt_sk(module, &sk, seed_xa, &mut source_xe, scratch.borrow());
|
||||
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(module, &tensor_key_infos);
|
||||
let mut tensor_key: TensorKey<Vec<u8>> = TensorKey::alloc_from_infos(&tensor_key_infos);
|
||||
tensor_key.decompress(module, &tensor_key_compressed);
|
||||
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(module, &tensor_key_infos);
|
||||
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&tensor_key_infos);
|
||||
|
||||
let mut sk_ij_dft = module.vec_znx_dft_alloc(1, 1);
|
||||
let mut sk_ij_big = module.vec_znx_big_alloc(1, 1);
|
||||
let mut sk_ij: GLWESecret<Vec<u8>> = GLWESecret::alloc(module, 1_u32.into());
|
||||
let mut sk_ij: GLWESecret<Vec<u8>> = GLWESecret::alloc(n.into(), 1_u32.into());
|
||||
let mut sk_dft: VecZnxDft<Vec<u8>, BE> = module.vec_znx_dft_alloc(rank, 1);
|
||||
|
||||
for i in 0..rank {
|
||||
|
||||
Reference in New Issue
Block a user