fix remaining issues before fixing tests

This commit is contained in:
Pro7ech
2025-10-18 11:59:50 +02:00
parent a282e88126
commit 0b8dcb1f16
34 changed files with 224 additions and 160 deletions

View File

@@ -61,7 +61,7 @@ pub trait AutomorphismKeyCompressedEncryptSk<BE: Backend> {
impl<BE: Backend> AutomorphismKeyCompressedEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN + GaloisElement + VecZnxAutomorphism + GLWESwitchingKeyCompressedEncryptSk<BE>,
Self: ModuleN + GaloisElement + VecZnxAutomorphism + GLWESwitchingKeyCompressedEncryptSk<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{
fn automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -99,7 +99,7 @@ where
let (mut sk_out, scratch_1) = scratch.take_glwe_secret(self, sk.rank());
{
for i in 0..res.rank_out().into(){
for i in 0..res.rank_out().into() {
self.vec_znx_automorphism(
self.galois_element_inv(p),
&mut sk_out.data.as_vec_znx_mut(),
@@ -107,7 +107,7 @@ where
&sk.data.as_vec_znx(),
i,
);
};
}
}
self.glwe_switching_key_compressed_encrypt_sk(&mut res.key, sk, &sk_out, seed_xa, source_xe, scratch_1);

View File

@@ -67,7 +67,7 @@ pub trait GGLWECompressedEncryptSk<BE: Backend> {
impl<BE: Backend> GGLWECompressedEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN
Self: ModuleN
+ GLWEEncryptSkInternal<BE>
+ GLWEEncryptSk<BE>
+ VecZnxDftBytesOf

View File

@@ -64,7 +64,7 @@ pub trait GLWESwitchingKeyCompressedEncryptSk<BE: Backend> {
impl<BE: Backend> GLWESwitchingKeyCompressedEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing,
Self: ModuleN + GGLWECompressedEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + GLWESecretPrepare<BE> + VecZnxSwitchRing,
Scratch<BE>: ScratchTakeCore<BE>,
{
fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize

View File

@@ -1,9 +1,9 @@
use poulpy_hal::{
api::{
ModuleN, ScratchTakeBasic, SvpApplyDftToDft, SvpPPolAlloc, SvpPPolBytesOf, SvpPrepare, VecZnxBigBytesOf,
VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes,
ModuleN, ScratchTakeBasic, SvpApplyDftToDft, SvpPPolBytesOf, SvpPrepare, VecZnxBigBytesOf, VecZnxBigNormalize,
VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyTmpA,
},
layouts::{Backend, DataMut, DataRef, Module, Scratch},
layouts::{Backend, DataMut, Module, Scratch},
oep::{SvpPPolAllocBytesImpl, VecZnxBigAllocBytesImpl, VecZnxDftAllocBytesImpl},
source::Source,
};
@@ -13,7 +13,7 @@ use crate::{
encryption::compressed::gglwe_ksk::GLWESwitchingKeyCompressedEncryptSk,
encryption::gglwe_tsk::TensorKeyEncryptSk,
layouts::{
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, LWEInfos, Rank, TensorKey,
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, LWEInfos, Rank,
compressed::{TensorKeyCompressed, TensorKeyCompressedToMut},
},
};
@@ -29,23 +29,22 @@ impl TensorKeyCompressed<Vec<u8>> {
}
impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> {
pub fn encrypt_sk<DataSk: DataRef, BE: Backend>(
pub fn encrypt_sk<S, M, BE: Backend>(
&mut self,
module: &Module<BE>,
sk: &GLWESecret<DataSk>,
module: &M,
sk: &S,
seed_xa: [u8; 32],
source_xe: &mut Source,
scratch: &mut Scratch<BE>,
) where
GLWESecret<DataSk>: GetDist,
Module<BE>: GGLWETensorKeyCompressedEncryptSk<BE>,
S: GLWESecretToRef + GetDist,
M: GGLWETensorKeyCompressedEncryptSk<BE>,
{
module.gglwe_tensor_key_encrypt_sk(self, sk, seed_xa, source_xe, scratch);
}
}
pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
@@ -64,7 +63,7 @@ pub trait GGLWETensorKeyCompressedEncryptSk<BE: Backend> {
impl<BE: Backend> GGLWETensorKeyCompressedEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN
Self: ModuleN
+ GLWESwitchingKeyCompressedEncryptSk<BE>
+ TensorKeyEncryptSk<BE>
+ VecZnxDftApply<BE>
@@ -82,7 +81,7 @@ where
{
fn gglwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos
A: GGLWEInfos,
{
self.tensor_key_encrypt_sk_tmp_bytes(infos)
}
@@ -154,4 +153,4 @@ where
}
}
}
}
}

View File

@@ -1,6 +1,6 @@
use poulpy_hal::{
api::{ModuleN, VecZnxAddScalarInplace, VecZnxNormalizeInplace},
layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero},
layouts::{Backend, DataMut, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero},
source::Source,
};
@@ -26,22 +26,23 @@ impl GGSWCompressed<Vec<u8>> {
impl<DataSelf: DataMut> GGSWCompressed<DataSelf> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, BE: Backend>(
pub fn encrypt_sk<P, S, M, BE: Backend>(
&mut self,
module: &Module<BE>,
pt: &ScalarZnx<DataPt>,
sk: &GLWESecretPrepared<DataSk, BE>,
module: &M,
pt: &P,
sk: &S,
seed_xa: [u8; 32],
source_xe: &mut Source,
scratch: &mut Scratch<BE>,
) where
Module<BE>: GGSWCompressedEncryptSk<BE>,
P: ScalarZnxToRef,
S: GLWESecretPreparedToRef<BE>,
M: GGSWCompressedEncryptSk<BE>,
{
module.ggsw_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch);
}
}
pub trait GGSWCompressedEncryptSk<BE: Backend> {
fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
@@ -63,11 +64,12 @@ pub trait GGSWCompressedEncryptSk<BE: Backend> {
impl<BE: Backend> GGSWCompressedEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN + GLWEEncryptSkInternal<BE> + GGSWEncryptSk<BE> + VecZnxAddScalarInplace + VecZnxNormalizeInplace<BE>,
Self: ModuleN + GLWEEncryptSkInternal<BE> + GGSWEncryptSk<BE> + VecZnxAddScalarInplace + VecZnxNormalizeInplace<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{
fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where A: GGSWInfos,
where
A: GGSWInfos,
{
self.ggsw_encrypt_sk_tmp_bytes(infos)
}
@@ -139,4 +141,4 @@ where
}
}
}
}
}

View File

@@ -1,15 +1,17 @@
use poulpy_hal::{
api::{VecZnxDftBytesOf, VecZnxNormalizeTmpBytes},
layouts::{Backend, DataMut, DataRef, Module, Scratch},
layouts::{Backend, DataMut, Module, Scratch},
source::Source,
};
use crate::{
encryption::{SIGMA, glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal}},
encryption::{
SIGMA,
glwe_ct::{GLWEEncryptSk, GLWEEncryptSkInternal},
},
layouts::{
GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, LWEInfos,
GLWEInfos, GLWEPlaintextToRef, LWEInfos,
compressed::{GLWECompressed, GLWECompressedToMut},
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
prepared::GLWESecretPreparedToRef,
},
};
@@ -25,22 +27,23 @@ impl GLWECompressed<Vec<u8>> {
impl<D: DataMut> GLWECompressed<D> {
#[allow(clippy::too_many_arguments)]
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, BE: Backend>(
pub fn encrypt_sk<M, P, S, BE: Backend>(
&mut self,
module: &Module<BE>,
pt: &GLWEPlaintext<DataPt>,
sk: &GLWESecretPrepared<DataSk, BE>,
module: &M,
pt: &P,
sk: &S,
seed_xa: [u8; 32],
source_xe: &mut Source,
scratch: &mut Scratch<BE>,
) where
Module<BE>: GLWECompressedEncryptSk<BE>,
M: GLWECompressedEncryptSk<BE>,
P: GLWEPlaintextToRef,
S: GLWESecretPreparedToRef<BE>,
{
module.glwe_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch);
}
}
pub trait GLWECompressedEncryptSk<BE: Backend> {
fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
@@ -62,9 +65,8 @@ pub trait GLWECompressedEncryptSk<BE: Backend> {
impl<BE: Backend> GLWECompressedEncryptSk<BE> for Module<BE>
where
Module<BE>: GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE>,
Self: GLWEEncryptSkInternal<BE> + GLWEEncryptSk<BE>,
{
fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GLWEInfos,
@@ -105,4 +107,4 @@ where
res.seed = seed_xa;
}
}
}

View File

@@ -68,7 +68,7 @@ pub trait AutomorphismKeyEncryptSk<BE: Backend> {
impl<BE: Backend> AutomorphismKeyEncryptSk<BE> for Module<BE>
where
Module<BE>: GLWESwitchingKeyEncryptSk<BE> + VecZnxAutomorphism + GaloisElement,
Self: GLWESwitchingKeyEncryptSk<BE> + VecZnxAutomorphism + GaloisElement,
Scratch<BE>: ScratchTakeCore<BE>,
{
fn automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -137,7 +137,7 @@ pub trait GGLWEAutomorphismKeyEncryptPk<BE: Backend> {
impl<BE: Backend> GGLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
where
Module<BE>:,
Self:,
Scratch<BE>: ScratchTakeCore<BE>,
{
fn automorphism_key_encrypt_pk_tmp_bytes<A>(&self, _infos: &A) -> usize

View File

@@ -73,7 +73,7 @@ pub trait GGLWEEncryptSk<BE: Backend> {
impl<BE: Backend> GGLWEEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN
Self: ModuleN
+ GLWEEncryptSk<BE>
+ VecZnxNormalizeTmpBytes
+ VecZnxDftBytesOf

View File

@@ -66,8 +66,7 @@ pub trait GLWESwitchingKeyEncryptSk<BE: Backend> {
) where
R: GLWESwitchingKeyToMut,
S1: GLWESecretToRef,
S2: GLWESecretToRef,
Scratch<BE>: ScratchTakeCore<BE>;
S2: GLWESecretToRef;
}
impl<BE: Backend> GLWESwitchingKeyEncryptSk<BE> for Module<BE>

View File

@@ -1,7 +1,7 @@
use poulpy_hal::{
api::{
ModuleN, ScratchAvailable, ScratchTakeBasic, SvpApplyDftToDft, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply,
VecZnxDftBytesOf, VecZnxIdftApplyTmpA,
ModuleN, ScratchTakeBasic, SvpApplyDftToDft, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf,
VecZnxIdftApplyTmpA,
},
layouts::{Backend, DataMut, Module, Scratch},
source::Source,
@@ -37,7 +37,7 @@ impl<DataSelf: DataMut> TensorKey<DataSelf> {
) where
M: TensorKeyEncryptSk<BE>,
S: GLWESecretToRef + GetDist,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{
module.tensor_key_encrypt_sk(self, sk, source_xa, source_xe, scratch);
}
@@ -62,7 +62,7 @@ pub trait TensorKeyEncryptSk<BE: Backend> {
impl<BE: Backend> TensorKeyEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN
Self: ModuleN
+ GLWESwitchingKeyEncryptSk<BE>
+ VecZnxDftBytesOf
+ VecZnxBigBytesOf

View File

@@ -64,7 +64,7 @@ pub trait GGSWEncryptSk<BE: Backend> {
impl<BE: Backend> GGSWEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN
Self: ModuleN
+ GLWEEncryptSkInternal<BE>
+ GLWEEncryptSk<BE>
+ VecZnxDftBytesOf

View File

@@ -38,7 +38,7 @@ impl GLWE<Vec<u8>> {
}
impl<D: DataMut> GLWE<D> {
pub fn encrypt_sk<R, P, S, M, BE: Backend>(
pub fn encrypt_sk<P, S, M, BE: Backend>(
&mut self,
module: &M,
pt: &P,
@@ -133,7 +133,7 @@ pub trait GLWEEncryptSk<BE: Backend> {
impl<BE: Backend> GLWEEncryptSk<BE> for Module<BE>
where
Module<BE>: Sized + ModuleN + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + GLWEEncryptSkInternal<BE>,
Self: Sized + ModuleN + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + GLWEEncryptSkInternal<BE>,
Scratch<BE>: ScratchAvailable,
{
fn glwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
@@ -262,7 +262,7 @@ pub trait GLWEEncryptPk<BE: Backend> {
impl<BE: Backend> GLWEEncryptPk<BE> for Module<BE>
where
Module<BE>: GLWEEncryptPkInternal<BE> + VecZnxDftBytesOf + SvpPPolBytesOf + VecZnxBigBytesOf + VecZnxNormalizeTmpBytes,
Self: GLWEEncryptPkInternal<BE> + VecZnxDftBytesOf + SvpPPolBytesOf + VecZnxBigBytesOf + VecZnxNormalizeTmpBytes,
{
fn glwe_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
where
@@ -330,7 +330,7 @@ pub(crate) trait GLWEEncryptPkInternal<BE: Backend> {
impl<BE: Backend> GLWEEncryptPkInternal<BE> for Module<BE>
where
Module<BE>: SvpPrepare<BE>
Self: SvpPrepare<BE>
+ SvpApplyDftToDft<BE>
+ VecZnxIdftApplyConsume<BE>
+ VecZnxBigAddNormal<BE>
@@ -445,7 +445,7 @@ pub(crate) trait GLWEEncryptSkInternal<BE: Backend> {
impl<BE: Backend> GLWEEncryptSkInternal<BE> for Module<BE>
where
Module<BE>: ModuleN
Self: ModuleN
+ VecZnxDftBytesOf
+ VecZnxBigNormalize<BE>
+ VecZnxDftApply<BE>
@@ -459,7 +459,7 @@ where
+ VecZnxAddNormal
+ VecZnxNormalize<BE>
+ VecZnxSub,
Scratch<BE>: ScratchAvailable + ScratchTakeBasic,
Scratch<BE>: ScratchTakeBasic,
{
fn glwe_encrypt_sk_internal<R, P, S>(
&self,

View File

@@ -1,6 +1,6 @@
use poulpy_hal::{
api::{ScratchOwnedAlloc, ScratchOwnedBorrow},
layouts::{Backend, DataMut, DataRef, Module, Scratch, ScratchOwned},
layouts::{Backend, DataMut, Module, Scratch, ScratchOwned},
source::Source,
};
@@ -14,14 +14,10 @@ use crate::{
};
impl<D: DataMut> GLWEPublicKey<D> {
pub fn generate<S: DataRef, BE: Backend>(
&mut self,
module: &Module<BE>,
sk: &GLWESecretPrepared<S, BE>,
source_xa: &mut Source,
source_xe: &mut Source,
) where
Module<BE>: GLWEPublicKeyGenerate<BE>,
pub fn generate<S, M, BE: Backend>(&mut self, module: &M, sk: &S, source_xa: &mut Source, source_xe: &mut Source)
where
S: GLWESecretPreparedToRef<BE>,
M: GLWEPublicKeyGenerate<BE>,
{
module.glwe_public_key_generate(self, sk, source_xa, source_xe);
}
@@ -36,7 +32,7 @@ pub trait GLWEPublicKeyGenerate<BE: Backend> {
impl<BE: Backend> GLWEPublicKeyGenerate<BE> for Module<BE>
where
Module<BE>: GLWEEncryptSk<BE>,
Self: GLWEEncryptSk<BE>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{

View File

@@ -64,7 +64,7 @@ pub trait GLWEToLWESwitchingKeyEncrypt<BE: Backend> {
impl<BE: Backend> GLWEToLWESwitchingKeyEncrypt<BE> for Module<BE>
where
Module<BE>: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>,
Self: ModuleN + GLWESwitchingKeyEncryptSk<BE> + GLWESecretPreparedAlloc<BE> + VecZnxAutomorphismInplace<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{
fn glwe_to_lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize