Add Zn type

This commit is contained in:
Pro7ech
2025-08-21 12:16:53 +02:00
parent ccd94e36cc
commit bf513dc555
129 changed files with 1400 additions and 686 deletions

View File

@@ -92,8 +92,8 @@ pub fn test_gglwe_automorphism_key_automorphism<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, k_apply, rank)
| GGLWEAutomorphismKey::automorphism_scratch_space(module, n, basek, k_out, k_in, k_apply, digits, rank),
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, k_apply, rank)
| GGLWEAutomorphismKey::automorphism_scratch_space(module, basek, k_out, k_in, k_apply, digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -120,7 +120,7 @@ pub fn test_gglwe_automorphism_key_automorphism<B>(
);
let mut auto_key_apply_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
GGLWEAutomorphismKeyPrepared::alloc(module, n, basek, k_apply, rows_apply, digits, rank);
GGLWEAutomorphismKeyPrepared::alloc(module, basek, k_apply, rows_apply, digits, rank);
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());
@@ -266,8 +266,8 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, k_apply, rank)
| GGLWEAutomorphismKey::automorphism_inplace_scratch_space(module, n, basek, k_in, k_apply, digits, rank),
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, k_apply, rank)
| GGLWEAutomorphismKey::automorphism_inplace_scratch_space(module, basek, k_in, k_apply, digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -294,7 +294,7 @@ pub fn test_gglwe_automorphism_key_automorphism_inplace<B>(
);
let mut auto_key_apply_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
GGLWEAutomorphismKeyPrepared::alloc(module, n, basek, k_apply, rows_apply, digits, rank);
GGLWEAutomorphismKeyPrepared::alloc(module, basek, k_apply, rows_apply, digits, rank);
auto_key_apply_prepared.prepare(module, &auto_key_apply, scratch.borrow());

View File

@@ -102,11 +102,11 @@ pub fn test_ggsw_automorphism<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_in, rank)
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, k_ksk, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, n, basek, k_tsk, rank)
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_in, rank)
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, k_ksk, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, basek, k_tsk, rank)
| GGSWCiphertext::automorphism_scratch_space(
module, n, basek, k_out, k_in, k_ksk, digits, k_tsk, digits, rank,
module, basek, k_out, k_in, k_ksk, digits, k_tsk, digits, rank,
),
);
@@ -144,11 +144,11 @@ pub fn test_ggsw_automorphism<B>(
);
let mut auto_key_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
GGLWEAutomorphismKeyPrepared::alloc(module, n, basek, k_ksk, rows, digits, rank);
GGLWEAutomorphismKeyPrepared::alloc(module, basek, k_ksk, rows, digits, rank);
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> =
GGLWETensorKeyPrepared::alloc(module, n, basek, k_tsk, rows, digits, rank);
GGLWETensorKeyPrepared::alloc(module, basek, k_tsk, rows, digits, rank);
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
ct_out.automorphism(
@@ -255,10 +255,10 @@ pub fn test_ggsw_automorphism_inplace<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_ct, rank)
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, k_ksk, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, n, basek, k_tsk, rank)
| GGSWCiphertext::automorphism_inplace_scratch_space(module, n, basek, k_ct, k_ksk, digits, k_tsk, digits, rank),
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_ct, rank)
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, k_ksk, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, basek, k_tsk, rank)
| GGSWCiphertext::automorphism_inplace_scratch_space(module, basek, k_ct, k_ksk, digits, k_tsk, digits, rank),
);
let var_xs: f64 = 0.5;
@@ -295,11 +295,11 @@ pub fn test_ggsw_automorphism_inplace<B>(
);
let mut auto_key_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
GGLWEAutomorphismKeyPrepared::alloc(module, n, basek, k_ksk, rows, digits, rank);
GGLWEAutomorphismKeyPrepared::alloc(module, basek, k_ksk, rows, digits, rank);
auto_key_prepared.prepare(module, &auto_key, scratch.borrow());
let mut tsk_prepared: GGLWETensorKeyPrepared<Vec<u8>, B> =
GGLWETensorKeyPrepared::alloc(module, n, basek, k_tsk, rows, digits, rank);
GGLWETensorKeyPrepared::alloc(module, basek, k_tsk, rows, digits, rank);
tsk_prepared.prepare(module, &tensor_key, scratch.borrow());
ct.automorphism_inplace(module, &auto_key_prepared, &tsk_prepared, scratch.borrow());

View File

@@ -89,12 +89,11 @@ pub fn test_glwe_automorphism<B>(
module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, k_in, &mut source_xa);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, autokey.k(), rank)
| GLWECiphertext::decrypt_scratch_space(module, n, basek, ct_out.k())
| GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct_in.k())
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, autokey.k(), rank)
| GLWECiphertext::decrypt_scratch_space(module, basek, ct_out.k())
| GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct_in.k())
| GLWECiphertext::automorphism_scratch_space(
module,
n,
basek,
ct_out.k(),
ct_in.k(),
@@ -127,7 +126,7 @@ pub fn test_glwe_automorphism<B>(
);
let mut autokey_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
GGLWEAutomorphismKeyPrepared::alloc(module, n, basek, k_ksk, rows, digits, rank);
GGLWEAutomorphismKeyPrepared::alloc(module, basek, k_ksk, rows, digits, rank);
autokey_prepared.prepare(module, &autokey, scratch.borrow());
ct_out.automorphism(module, &ct_in, &autokey_prepared, scratch.borrow());
@@ -213,10 +212,10 @@ pub fn test_glwe_automorphism_inplace<B>(
module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, k_ct, &mut source_xa);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, autokey.k(), rank)
| GLWECiphertext::decrypt_scratch_space(module, n, basek, ct.k())
| GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct.k())
| GLWECiphertext::automorphism_inplace_scratch_space(module, n, basek, ct.k(), autokey.k(), digits, rank),
GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, autokey.k(), rank)
| GLWECiphertext::decrypt_scratch_space(module, basek, ct.k())
| GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct.k())
| GLWECiphertext::automorphism_inplace_scratch_space(module, basek, ct.k(), autokey.k(), digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -242,7 +241,7 @@ pub fn test_glwe_automorphism_inplace<B>(
);
let mut autokey_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, B> =
GGLWEAutomorphismKeyPrepared::alloc(module, n, basek, k_ksk, rows, digits, rank);
GGLWEAutomorphismKeyPrepared::alloc(module, basek, k_ksk, rows, digits, rank);
autokey_prepared.prepare(module, &autokey, scratch.borrow());
ct.automorphism_inplace(module, &autokey_prepared, scratch.borrow());

View File

@@ -5,7 +5,7 @@ use poulpy_hal::{
VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, VecZnxDftFromVecZnx,
VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes,
VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare,
ZnxView,
ZnAddNormal, ZnFillUniform, ZnNormalizeInplace, ZnxView,
},
layouts::{Backend, Module, ScratchOwned},
oep::{
@@ -50,7 +50,10 @@ where
+ VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace,
+ VecZnxAutomorphismInplace
+ ZnNormalizeInplace<B>
+ ZnFillUniform
+ ZnAddNormal,
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
@@ -79,9 +82,9 @@ where
let mut source_xe: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k_ksk, rank)
| GLWECiphertext::from_lwe_scratch_space(module, n, basek, k_lwe_ct, k_glwe_ct, k_ksk, rank)
| GLWECiphertext::decrypt_scratch_space(module, n, basek, k_glwe_ct),
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k_ksk, rank)
| GLWECiphertext::from_lwe_scratch_space(module, basek, k_lwe_ct, k_glwe_ct, k_ksk, rank)
| GLWECiphertext::decrypt_scratch_space(module, basek, k_glwe_ct),
);
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -152,7 +155,8 @@ where
+ VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace,
+ VecZnxAutomorphismInplace
+ ZnNormalizeInplace<B>,
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
@@ -181,9 +185,9 @@ where
let mut source_xe: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k_ksk, rank)
| LWECiphertext::from_glwe_scratch_space(module, n, basek, k_lwe_ct, k_glwe_ct, k_ksk, rank)
| GLWECiphertext::decrypt_scratch_space(module, n, basek, k_glwe_ct),
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k_ksk, rank)
| LWECiphertext::from_glwe_scratch_space(module, basek, k_lwe_ct, k_glwe_ct, k_ksk, rank)
| GLWECiphertext::decrypt_scratch_space(module, basek, k_glwe_ct),
);
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -77,7 +77,7 @@ where
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWEAutomorphismKey::encrypt_sk_scratch_space(
module, n, basek, k_ksk, rank,
module, basek, k_ksk, rank,
));
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -169,7 +169,7 @@ pub fn test_gglwe_automorphisk_key_compressed_encrypt_sk<B>(
let mut source_xe: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWEAutomorphismKey::encrypt_sk_scratch_space(
module, n, basek, k_ksk, rank,
module, basek, k_ksk, rank,
));
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -78,7 +78,7 @@ pub fn test_gglwe_switching_key_encrypt_sk<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::encrypt_sk_scratch_space(
module, n, basek, k_ksk, rank_in, rank_out,
module, basek, k_ksk, rank_in, rank_out,
));
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank_in);
@@ -156,7 +156,7 @@ pub fn test_gglwe_switching_key_compressed_encrypt_sk<B>(
let mut source_xe: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKeyCompressed::encrypt_sk_scratch_space(
module, n, basek, k_ksk, rank_in, rank_out,
module, basek, k_ksk, rank_in, rank_out,
));
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank_in);

View File

@@ -79,7 +79,7 @@ where
pt_scalar.fill_ternary_hw(0, n, &mut source_xs);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGSWCiphertext::encrypt_sk_scratch_space(
module, n, basek, k, rank,
module, basek, k, rank,
));
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -154,7 +154,7 @@ where
pt_scalar.fill_ternary_hw(0, n, &mut source_xs);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGSWCiphertextCompressed::encrypt_sk_scratch_space(
module, n, basek, k, rank,
module, basek, k, rank,
));
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -81,8 +81,8 @@ where
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct.k())
| GLWECiphertext::decrypt_scratch_space(module, n, basek, ct.k()),
GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct.k())
| GLWECiphertext::decrypt_scratch_space(module, basek, ct.k()),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -169,8 +169,8 @@ where
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GLWECiphertextCompressed::encrypt_sk_scratch_space(module, n, basek, k_ct)
| GLWECiphertext::decrypt_scratch_space(module, n, basek, k_ct),
GLWECiphertextCompressed::encrypt_sk_scratch_space(module, basek, k_ct)
| GLWECiphertext::decrypt_scratch_space(module, basek, k_ct),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -263,8 +263,8 @@ where
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GLWECiphertext::decrypt_scratch_space(module, n, basek, k_ct)
| GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k_ct),
GLWECiphertext::decrypt_scratch_space(module, basek, k_ct)
| GLWECiphertext::encrypt_sk_scratch_space(module, basek, k_ct),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -331,9 +331,9 @@ where
let mut source_xu: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct.k())
| GLWECiphertext::decrypt_scratch_space(module, n, basek, ct.k())
| GLWECiphertext::encrypt_pk_scratch_space(module, n, basek, k_pk),
GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct.k())
| GLWECiphertext::decrypt_scratch_space(module, basek, ct.k())
| GLWECiphertext::encrypt_pk_scratch_space(module, basek, k_pk),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -75,7 +75,6 @@ where
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWETensorKey::encrypt_sk_scratch_space(
module,
n,
basek,
tensor_key.k(),
rank,
@@ -95,10 +94,10 @@ where
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k);
let mut sk_ij_dft = module.vec_znx_dft_alloc(n, 1, 1);
let mut sk_ij_big = module.vec_znx_big_alloc(n, 1, 1);
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(n, 1);
let mut sk_dft: VecZnxDft<Vec<u8>, B> = module.vec_znx_dft_alloc(n, rank, 1);
let mut sk_dft: VecZnxDft<Vec<u8>, B> = module.vec_znx_dft_alloc(rank, 1);
(0..rank).for_each(|i| {
module.vec_znx_dft_from_vec_znx(1, 0, &mut sk_dft, i, &sk.data.as_vec_znx(), i);
@@ -185,7 +184,6 @@ where
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(GGLWETensorKeyCompressed::encrypt_sk_scratch_space(
module,
n,
basek,
tensor_key_compressed.k(),
rank,
@@ -204,10 +202,10 @@ where
let mut pt: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc(n, basek, k);
let mut sk_ij_dft = module.vec_znx_dft_alloc(n, 1, 1);
let mut sk_ij_big = module.vec_znx_big_alloc(n, 1, 1);
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(n, 1);
let mut sk_dft: VecZnxDft<Vec<u8>, B> = module.vec_znx_dft_alloc(n, rank, 1);
let mut sk_dft: VecZnxDft<Vec<u8>, B> = module.vec_znx_dft_alloc(rank, 1);
(0..rank).for_each(|i| {
module.vec_znx_dft_from_vec_znx(1, 0, &mut sk_dft, i, &sk.data.as_vec_znx(), i);

View File

@@ -93,9 +93,9 @@ pub fn test_gglwe_switching_key_external_product<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k_in, rank_in, rank_out)
| GGLWESwitchingKey::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank_out)
| GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_ggsw, rank_out),
GGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k_in, rank_in, rank_out)
| GGLWESwitchingKey::external_product_scratch_space(module, basek, k_out, k_in, k_ggsw, digits, rank_out)
| GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_ggsw, rank_out),
);
let r: usize = 1;
@@ -231,9 +231,9 @@ pub fn test_gglwe_switching_key_external_product_inplace<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k_ct, rank_in, rank_out)
| GGLWESwitchingKey::external_product_inplace_scratch_space(module, n, basek, k_ct, k_ggsw, digits, rank_out)
| GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_ggsw, rank_out),
GGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k_ct, rank_in, rank_out)
| GGLWESwitchingKey::external_product_inplace_scratch_space(module, basek, k_ct, k_ggsw, digits, rank_out)
| GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_ggsw, rank_out),
);
let r: usize = 1;

View File

@@ -99,8 +99,8 @@ pub fn test_ggsw_external_product<B>(
pt_ggsw_rhs.to_mut().raw_mut()[k] = 1; //X^{k}
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_ggsw, rank)
| GGSWCiphertext::external_product_scratch_space(module, n, basek, k_out, k_in, k_ggsw, digits, rank),
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_ggsw, rank)
| GGSWCiphertext::external_product_scratch_space(module, basek, k_out, k_in, k_ggsw, digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
@@ -231,8 +231,8 @@ pub fn test_ggsw_external_product_inplace<B>(
pt_ggsw_rhs.to_mut().raw_mut()[k] = 1; //X^{k}
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_ggsw, rank)
| GGSWCiphertext::external_product_inplace_scratch_space(module, n, basek, k_ct, k_ggsw, digits, rank),
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_ggsw, rank)
| GGSWCiphertext::external_product_inplace_scratch_space(module, basek, k_ct, k_ggsw, digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -92,11 +92,10 @@ pub fn test_glwe_external_product<B>(
pt_rgsw.raw_mut()[k] = 1; // X^{k}
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, ct_ggsw.k(), rank)
| GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct_glwe_in.k())
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, ct_ggsw.k(), rank)
| GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct_glwe_in.k())
| GLWECiphertext::external_product_scratch_space(
module,
n,
basek,
ct_glwe_out.k(),
ct_glwe_in.k(),
@@ -225,9 +224,9 @@ pub fn test_glwe_external_product_inplace<B>(
pt_rgsw.raw_mut()[k] = 1; // X^{k}
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, ct_ggsw.k(), rank)
| GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct_glwe.k())
| GLWECiphertext::external_product_inplace_scratch_space(module, n, basek, ct_glwe.k(), ct_ggsw.k(), digits, rank),
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, ct_ggsw.k(), rank)
| GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct_glwe.k())
| GLWECiphertext::external_product_inplace_scratch_space(module, basek, ct_glwe.k(), ct_ggsw.k(), digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -97,7 +97,6 @@ pub fn test_gglwe_switching_key_keyswitch<B>(
let mut scratch_enc: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::encrypt_sk_scratch_space(
module,
n,
basek,
k_ksk,
rank_in_s0s1 | rank_out_s0s1,
@@ -105,7 +104,6 @@ pub fn test_gglwe_switching_key_keyswitch<B>(
));
let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::keyswitch_scratch_space(
module,
n,
basek,
k_out,
k_in,
@@ -237,14 +235,13 @@ pub fn test_gglwe_switching_key_keyswitch_inplace<B>(
let mut scratch_enc: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::encrypt_sk_scratch_space(
module,
n,
basek,
k_ksk,
rank_in | rank_out,
rank_out,
));
let mut scratch_apply: ScratchOwned<B> = ScratchOwned::alloc(GGLWESwitchingKey::keyswitch_inplace_scratch_space(
module, n, basek, k_ct, k_ksk, digits, rank_out,
module, basek, k_ct, k_ksk, digits, rank_out,
));
let var_xs: f64 = 0.5;

View File

@@ -94,11 +94,11 @@ pub fn test_ggsw_keyswitch<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_in, rank)
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k_ksk, rank, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, n, basek, k_tsk, rank)
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_in, rank)
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k_ksk, rank, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, basek, k_tsk, rank)
| GGSWCiphertext::keyswitch_scratch_space(
module, n, basek, k_out, k_in, k_ksk, digits, k_tsk, digits, rank,
module, basek, k_out, k_in, k_ksk, digits, k_tsk, digits, rank,
),
);
@@ -237,10 +237,10 @@ pub fn test_ggsw_keyswitch_inplace<B>(
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGSWCiphertext::encrypt_sk_scratch_space(module, n, basek, k_ct, rank)
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k_ksk, rank, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, n, basek, k_tsk, rank)
| GGSWCiphertext::keyswitch_inplace_scratch_space(module, n, basek, k_ct, k_ksk, digits, k_tsk, digits, rank),
GGSWCiphertext::encrypt_sk_scratch_space(module, basek, k_ct, rank)
| GGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k_ksk, rank, rank)
| GGLWETensorKey::encrypt_sk_scratch_space(module, basek, k_tsk, rank)
| GGSWCiphertext::keyswitch_inplace_scratch_space(module, basek, k_ct, k_ksk, digits, k_tsk, digits, rank),
);
let var_xs: f64 = 0.5;

View File

@@ -86,11 +86,10 @@ pub fn test_glwe_keyswitch<B>(
module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, k_in, &mut source_xa);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, ksk.k(), rank_in, rank_out)
| GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct_in.k())
GGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, ksk.k(), rank_in, rank_out)
| GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct_in.k())
| GLWECiphertext::keyswitch_scratch_space(
module,
n,
basek,
ct_out.k(),
ct_in.k(),
@@ -200,9 +199,9 @@ where
module.vec_znx_fill_uniform(basek, &mut pt_want.data, 0, k_ct, &mut source_xa);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, ksk.k(), rank, rank)
| GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct_glwe.k())
| GLWECiphertext::keyswitch_inplace_scratch_space(module, n, basek, ct_glwe.k(), ksk.k(), digits, rank),
GGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, ksk.k(), rank, rank)
| GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct_glwe.k())
| GLWECiphertext::keyswitch_inplace_scratch_space(module, basek, ct_glwe.k(), ksk.k(), digits, rank),
);
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -5,7 +5,7 @@ use poulpy_hal::{
VecZnxBigAllocBytes, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAllocBytes, VecZnxDftFromVecZnx,
VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes,
VecZnxSub, VecZnxSubABInplace, VecZnxSwithcDegree, VmpApply, VmpApplyAdd, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare,
ZnxView,
ZnAddNormal, ZnFillUniform, ZnNormalizeInplace, ZnxView,
},
layouts::{Backend, Module, ScratchOwned},
oep::{
@@ -49,7 +49,10 @@ where
+ VmpApplyAdd<B>
+ VecZnxBigNormalizeTmpBytes
+ VecZnxSwithcDegree
+ VecZnxAutomorphismInplace,
+ VecZnxAutomorphismInplace
+ ZnNormalizeInplace<B>
+ ZnFillUniform
+ ZnAddNormal,
B: Backend
+ TakeVecZnxDftImpl<B>
+ TakeVecZnxBigImpl<B>
@@ -75,8 +78,8 @@ where
let mut source_xe: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
LWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k_ksk)
| LWECiphertext::keyswitch_scratch_space(module, n, basek, k_lwe_ct, k_lwe_ct, k_ksk),
LWESwitchingKey::encrypt_sk_scratch_space(module, basek, k_ksk)
| LWECiphertext::keyswitch_scratch_space(module, basek, k_lwe_ct, k_lwe_ct, k_ksk),
);
let mut sk_lwe_in: LWESecret<Vec<u8>> = LWESecret::alloc(n_lwe_in);

View File

@@ -89,9 +89,9 @@ where
let rows: usize = k_ct.div_ceil(basek * digits);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k_ct)
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, k_ksk, rank)
| GLWEPacker::scratch_space(module, n, basek, k_ct, k_ksk, digits, rank),
GLWECiphertext::encrypt_sk_scratch_space(module, basek, k_ct)
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, k_ksk, rank)
| GLWEPacker::scratch_space(module, basek, k_ct, k_ksk, digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);

View File

@@ -87,10 +87,10 @@ where
let mut source_xa: Source = Source::new([0u8; 32]);
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(
GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, ct.k())
| GLWECiphertext::decrypt_scratch_space(module, n, basek, ct.k())
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, n, basek, k_autokey, rank)
| GLWECiphertext::trace_inplace_scratch_space(module, n, basek, ct.k(), k_autokey, digits, rank),
GLWECiphertext::encrypt_sk_scratch_space(module, basek, ct.k())
| GLWECiphertext::decrypt_scratch_space(module, basek, ct.k())
| GGLWEAutomorphismKey::encrypt_sk_scratch_space(module, basek, k_autokey, rank)
| GLWECiphertext::trace_inplace_scratch_space(module, basek, ct.k(), k_autokey, digits, rank),
);
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);