#![allow(clippy::too_many_arguments)]
use poulpy_hal::{
layouts::{Backend, NoiseInfos, ScalarZnxToBackendRef, ScratchArena, ZnxInfos},
source::Source,
};
use crate::{
GetDistribution, GetDistributionMut,
layouts::{
GGLWEInfos, GGLWEToBackendMut, GGLWEToGGSWKeyCompressedToBackendMut, GGLWEToGGSWKeyToBackendMut, GGSWAtViewMut,
GGSWCompressedSeedMut, GGSWCompressedToBackendMut, GGSWInfos, GGSWToBackendMut, GLWECompressedSeedMut,
GLWECompressedToBackendMut, GLWEInfos, GLWESecretToBackendRef, GLWESwitchingKeyDegreesMut, GLWEToBackendMut,
GLWEToBackendRef, LWEInfos, LWEPlaintextToBackendRef, LWESecretToBackendRef, LWEToBackendMut, SetGaloisElement,
TorusPrecision,
compressed::{GGLWECompressedSeedMut, GGLWECompressedToBackendMut},
prepared::{GLWEPreparedToBackendRef, GLWESecretPreparedToBackendRef},
},
};
pub trait DeclaredK: LWEInfos {
fn k(&self) -> TorusPrecision;
}
pub trait EncryptionInfos {
fn noise_infos(&self) -> NoiseInfos;
}
pub trait LWEEncryptSk<BE: Backend> {
fn lwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: LWEInfos;
fn lwe_encrypt_sk<R, P, S, E>(
&self,
res: &mut R,
pt: &P,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: LWEToBackendMut<BE> + LWEInfos,
P: LWEPlaintextToBackendRef<BE>,
S: LWESecretToBackendRef<BE>,
E: EncryptionInfos;
}
pub trait GLWEEncryptSk<BE: Backend> {
fn glwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GLWEInfos;
fn glwe_encrypt_sk<R, P, S, E>(
&self,
res: &mut R,
pt: &P,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GLWEToBackendMut<BE>,
P: GLWEToBackendRef<BE>,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE>;
fn glwe_encrypt_zero_sk<R, E, S>(
&self,
res: &mut R,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GLWEToBackendMut<BE>,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE>;
}
pub trait GLWEEncryptPk<BE: Backend> {
fn glwe_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GLWEInfos;
fn glwe_encrypt_pk<R, P, K, E>(
&self,
res: &mut R,
pt: &P,
pk: &K,
enc_infos: &E,
source_xu: &mut Source,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GLWEToBackendMut<BE> + GLWEInfos,
P: GLWEToBackendRef<BE> + GLWEInfos,
E: EncryptionInfos,
K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos;
fn glwe_encrypt_zero_pk<R, K, E>(
&self,
res: &mut R,
pk: &K,
enc_infos: &E,
source_xu: &mut Source,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GLWEToBackendMut<BE> + GLWEInfos,
E: EncryptionInfos,
K: GLWEPreparedToBackendRef<BE> + GetDistribution + GLWEInfos;
}
pub trait GLWEPublicKeyGenerate<BE: Backend> {
fn glwe_public_key_generate<R, S, E>(
&self,
res: &mut R,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
) where
R: GLWEToBackendMut<BE> + GetDistributionMut + GLWEInfos,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE> + GetDistribution;
}
pub trait GGLWEEncryptSk<BE: Backend> {
fn gglwe_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn gglwe_encrypt_sk<R, P, S, E>(
&self,
res: &mut R,
pt: &P,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWEToBackendMut<BE>,
P: ScalarZnxToBackendRef<BE>,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE>;
}
pub trait GGSWEncryptSk<BE: Backend> {
fn ggsw_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGSWInfos;
fn ggsw_encrypt_sk<R, P, S, E>(
&self,
res: &mut R,
pt: &P,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGSWToBackendMut<BE> + GGSWInfos + GGSWAtViewMut<BE>,
P: ScalarZnxToBackendRef<BE> + ZnxInfos,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE> + LWEInfos + GLWEInfos;
}
pub trait GGLWEToGGSWKeyEncryptSk<BE: Backend> {
fn gglwe_to_ggsw_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn gglwe_to_ggsw_key_encrypt_sk<R, S, E>(
&self,
res: &mut R,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWEToGGSWKeyToBackendMut<BE>,
E: EncryptionInfos,
S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
}
pub trait GLWESwitchingKeyEncryptSk<BE: Backend> {
fn glwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn glwe_switching_key_encrypt_sk<R, S1, S2, E>(
&self,
res: &mut R,
sk_in: &S1,
sk_out: &S2,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
E: EncryptionInfos,
S1: GLWESecretToBackendRef<BE> + GLWEInfos,
S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
}
pub trait GLWESwitchingKeyEncryptPk<BE: Backend> {
fn glwe_switching_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
}
pub trait GLWETensorKeyEncryptSk<BE: Backend> {
fn glwe_tensor_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn glwe_tensor_key_encrypt_sk<R, S, E>(
&self,
res: &mut R,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWEToBackendMut<BE> + GGLWEInfos,
E: EncryptionInfos,
S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
}
pub trait GLWEToLWESwitchingKeyEncryptSk<BE: Backend> {
fn glwe_to_lwe_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn glwe_to_lwe_key_encrypt_sk<R, S1, S2, E>(
&self,
res: &mut R,
sk_lwe: &S1,
sk_glwe: &S2,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
S1: LWESecretToBackendRef<BE>,
S2: GLWESecretToBackendRef<BE>,
E: EncryptionInfos,
R: GGLWEToBackendMut<BE> + GGLWEInfos;
}
pub trait LWESwitchingKeyEncrypt<BE: Backend> {
fn lwe_switching_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn lwe_switching_key_encrypt_sk<R, S1, S2, E>(
&self,
res: &mut R,
sk_lwe_in: &S1,
sk_lwe_out: &S2,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWEToBackendMut<BE> + GLWESwitchingKeyDegreesMut + GGLWEInfos,
E: EncryptionInfos,
S1: LWESecretToBackendRef<BE>,
S2: LWESecretToBackendRef<BE>;
}
pub trait LWEToGLWESwitchingKeyEncryptSk<BE: Backend> {
fn lwe_to_glwe_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn lwe_to_glwe_key_encrypt_sk<R, S1, S2, E>(
&self,
res: &mut R,
sk_lwe: &S1,
sk_glwe: &S2,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
S1: LWESecretToBackendRef<BE>,
S2: GLWESecretPreparedToBackendRef<BE>,
E: EncryptionInfos,
R: GGLWEToBackendMut<BE> + GGLWEInfos;
}
pub trait GLWEAutomorphismKeyEncryptSk<BE: Backend> {
fn glwe_automorphism_key_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn glwe_automorphism_key_encrypt_sk<R, S, E>(
&self,
res: &mut R,
p: i64,
sk: &S,
enc_infos: &E,
source_xe: &mut Source,
source_xa: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWEToBackendMut<BE> + SetGaloisElement + GGLWEInfos,
E: EncryptionInfos,
S: GLWESecretToBackendRef<BE> + GLWEInfos;
}
pub trait GLWEAutomorphismKeyEncryptPk<BE: Backend> {
fn glwe_automorphism_key_encrypt_pk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
}
pub trait GLWECompressedEncryptSk<BE: Backend> {
fn glwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GLWEInfos;
fn glwe_compressed_encrypt_sk<R, P, S, E>(
&self,
res: &mut R,
pt: &P,
sk: &S,
seed_xa: [u8; 32],
enc_infos: &E,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GLWECompressedToBackendMut<BE> + GLWECompressedSeedMut,
P: GLWEToBackendRef<BE>,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE>;
}
pub trait GGLWECompressedEncryptSk<BE: Backend> {
fn gglwe_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn gglwe_compressed_encrypt_sk<R, P, S, E>(
&self,
res: &mut R,
pt: &P,
sk: &S,
seed: [u8; 32],
enc_infos: &E,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut,
P: ScalarZnxToBackendRef<BE>,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE>;
}
pub trait GGSWCompressedEncryptSk<BE: Backend> {
fn ggsw_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGSWInfos;
fn ggsw_compressed_encrypt_sk<R, P, S, E>(
&self,
res: &mut R,
pt: &P,
sk: &S,
seed_xa: [u8; 32],
enc_infos: &E,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGSWCompressedToBackendMut<BE> + GGSWCompressedSeedMut + GGSWInfos,
P: ScalarZnxToBackendRef<BE>,
E: EncryptionInfos,
S: GLWESecretPreparedToBackendRef<BE>;
}
pub trait GLWESwitchingKeyCompressedEncryptSk<BE: Backend> {
fn glwe_switching_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn glwe_switching_key_compressed_encrypt_sk<R, S1, S2, E>(
&self,
res: &mut R,
sk_in: &S1,
sk_out: &S2,
seed_xa: [u8; 32],
enc_infos: &E,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + GLWESwitchingKeyDegreesMut + GGLWEInfos,
E: EncryptionInfos,
S1: GLWESecretToBackendRef<BE> + GLWEInfos,
S2: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
}
pub trait GLWEAutomorphismKeyCompressedEncryptSk<BE: Backend> {
fn glwe_automorphism_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn glwe_automorphism_key_compressed_encrypt_sk<R, S, E>(
&self,
res: &mut R,
p: i64,
sk: &S,
seed_xa: [u8; 32],
enc_infos: &E,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWECompressedToBackendMut<BE> + GGLWECompressedSeedMut + SetGaloisElement + GGLWEInfos,
E: EncryptionInfos,
S: GLWESecretToBackendRef<BE> + GLWEInfos;
}
pub trait GLWETensorKeyCompressedEncryptSk<BE: Backend> {
fn glwe_tensor_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn glwe_tensor_key_compressed_encrypt_sk<R, S, E>(
&self,
res: &mut R,
sk: &S,
seed_xa: [u8; 32],
enc_infos: &E,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWECompressedToBackendMut<BE> + GGLWEInfos + GGLWECompressedSeedMut,
E: EncryptionInfos,
S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
}
pub trait GGLWEToGGSWKeyCompressedEncryptSk<BE: Backend> {
fn gglwe_to_ggsw_key_compressed_encrypt_sk_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos;
fn gglwe_to_ggsw_key_compressed_encrypt_sk<R, S, E>(
&self,
res: &mut R,
sk: &S,
seed_xa: [u8; 32],
enc_infos: &E,
source_xe: &mut Source,
scratch: &mut ScratchArena<'_, BE>,
) where
R: GGLWEToGGSWKeyCompressedToBackendMut<BE> + GGLWEInfos,
E: EncryptionInfos,
S: GLWESecretToBackendRef<BE> + GetDistribution + GLWEInfos;
}