non-compressed finished

This commit is contained in:
Rasoul Akhavan Mahdavi
2025-10-16 23:49:33 -04:00
parent a5600593ca
commit 1247d3e4b7
8 changed files with 917 additions and 317 deletions

View File

@@ -5,58 +5,36 @@ use poulpy_hal::{
VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace,
VecZnxSwitchRing,
},
layouts::{Backend, DataMut, Module, Scratch},
layouts::{Backend, DataMut, GaloisElement, Module, Scratch},
source::Source,
};
use crate::{
ScratchTakeCore,
layouts::{
AutomorphismKey, AutomorphismKeyToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, LWEInfos,
AutomorphismKey, AutomorphismKeyToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey,
},
};
impl AutomorphismKey<Vec<u8>> {
pub fn encrypt_sk_tmp_bytes<BE: Backend, A>(module: &Module<BE>, infos: &A) -> usize
pub fn encrypt_sk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
where
A: GGLWEInfos,
Module<BE>: ModuleN + SvpPPolBytesOf + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + VecZnxNormalizeTmpBytes + SvpPPolAlloc<BE>,
M: GGLWEAutomorphismKeyEncryptSk<BE>
{
assert_eq!(
infos.rank_in(),
infos.rank_out(),
"rank_in != rank_out is not supported for GGLWEAutomorphismKey"
);
GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos) + GLWESecret::bytes_of_from_infos(module, &infos.glwe_layout())
module.gglwe_automorphism_key_encrypt_sk_tmp_bytes(infos)
}
pub fn encrypt_pk_tmp_bytes<BE: Backend, A>(module: &Module<BE>, _infos: &A) -> usize
pub fn encrypt_pk_tmp_bytes<M, A, BE: Backend>(module: &M, infos: &A) -> usize
where
A: GGLWEInfos,
M: GGLWEAutomorphismKeyEncryptPk<BE>
{
assert_eq!(
_infos.rank_in(),
_infos.rank_out(),
"rank_in != rank_out is not supported for GGLWEAutomorphismKey"
);
GLWESwitchingKey::encrypt_pk_tmp_bytes(module, _infos)
module.gglwe_automorphism_key_encrypt_pk_tmp_bytes(infos)
}
}
pub trait GGLWEAutomorphismKeyEncryptSk<BE: Backend> {
fn gglwe_automorphism_key_encrypt_sk<A, B>(
&self,
res: &mut A,
p: i64,
sk: &B,
source_xa: &mut Source,
source_xe: &mut Source,
scratch: &mut Scratch<BE>,
) where
A: AutomorphismKeyToMut,
B: GLWESecretToRef;
}
impl<DM: DataMut> AutomorphismKey<DM>
where
Self: AutomorphismKeyToMut,
@@ -77,6 +55,24 @@ where
}
}
pub trait GGLWEAutomorphismKeyEncryptSk<BE: Backend> {
fn gglwe_automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn gglwe_automorphism_key_encrypt_sk<A, B>(
&self,
res: &mut A,
p: i64,
sk: &B,
source_xa: &mut Source,
source_xe: &mut Source,
scratch: &mut Scratch<BE>,
) where
A: AutomorphismKeyToMut,
B: GLWESecretToRef;
}
impl<BE: Backend> GGLWEAutomorphismKeyEncryptSk<BE> for Module<BE>
where
Module<BE>: ModuleN
@@ -99,9 +95,22 @@ where
+ SvpPPolBytesOf
+ VecZnxAutomorphism
+ SvpPPolAlloc<BE>
+ SvpPPolBytesOf,
+ GaloisElement,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{
fn gglwe_automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos,
{
assert_eq!(
infos.rank_in(),
infos.rank_out(),
"rank_in != rank_out is not supported for GGLWEAutomorphismKey"
);
GLWESwitchingKey::encrypt_sk_tmp_bytes(self, infos) + GLWESecret::bytes_of_from_infos(self, &infos.glwe_layout())
}
fn gglwe_automorphism_key_encrypt_sk<A, B>(
&self,
res: &mut A,
@@ -151,4 +160,47 @@ where
res.p = p;
}
}
pub trait GGLWEAutomorphismKeyEncryptPk<BE: Backend> {
fn gglwe_automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
}
impl<BE: Backend> GGLWEAutomorphismKeyEncryptPk<BE> for Module<BE>
where
Module<BE>: ModuleN
+ VecZnxAddScalarInplace
+ VecZnxDftBytesOf
+ VecZnxBigNormalize<BE>
+ VecZnxDftApply<BE>
+ SvpApplyDftToDftInplace<BE>
+ VecZnxIdftApplyConsume<BE>
+ VecZnxNormalizeTmpBytes
+ VecZnxFillUniform
+ VecZnxSubInplace
+ VecZnxAddInplace
+ VecZnxNormalizeInplace<BE>
+ VecZnxAddNormal
+ VecZnxNormalize<BE>
+ VecZnxSub
+ SvpPPolBytesOf
+ SvpPPolAlloc<BE>,
Scratch<BE>: ScratchAvailable + ScratchTakeCore<BE>,
{
fn gglwe_automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos,
{
assert_eq!(
infos.rank_in(),
infos.rank_out(),
"rank_in != rank_out is not supported for GGLWEAutomorphismKey"
);
GLWESwitchingKey::encrypt_pk_tmp_bytes(self, infos)
}
}