mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
wip
This commit is contained in:
@@ -9,18 +9,19 @@ use crate::{
|
||||
encryption::compressed::gglwe_ksk::GGLWEKeyCompressedEncryptSk,
|
||||
layouts::{
|
||||
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos,
|
||||
compressed::{GGLWEAutomorphismKeyCompressed, GGLWEAutomorphismKeyCompressedToMut, GGLWEKeyCompressed},
|
||||
compressed::{AutomorphismKeyCompressed, AutomorphismKeyCompressedToMut, GLWESwitchingKeyCompressed},
|
||||
},
|
||||
};
|
||||
|
||||
impl GGLWEAutomorphismKeyCompressed<Vec<u8>> {
|
||||
impl AutomorphismKeyCompressed<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes,
|
||||
{
|
||||
assert_eq!(module.n() as u32, infos.n());
|
||||
GGLWEKeyCompressed::encrypt_sk_scratch_space(module, infos) + GLWESecret::alloc_bytes_with(infos.n(), infos.rank_out())
|
||||
GLWESwitchingKeyCompressed::encrypt_sk_scratch_space(module, infos)
|
||||
+ GLWESecret::alloc_bytes_with(infos.n(), infos.rank_out())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ pub trait GGLWEAutomorphismKeyCompressedEncryptSk<B: Backend> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGLWEAutomorphismKeyCompressedToMut,
|
||||
R: AutomorphismKeyCompressedToMut,
|
||||
S: GLWESecretToRef;
|
||||
}
|
||||
|
||||
@@ -53,10 +54,10 @@ where
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGLWEAutomorphismKeyCompressedToMut,
|
||||
R: AutomorphismKeyCompressedToMut,
|
||||
S: GLWESecretToRef,
|
||||
{
|
||||
let res: &mut GGLWEAutomorphismKeyCompressed<&mut [u8]> = &mut res.to_mut();
|
||||
let res: &mut AutomorphismKeyCompressed<&mut [u8]> = &mut res.to_mut();
|
||||
let sk: &GLWESecret<&[u8]> = &sk.to_ref();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -65,10 +66,10 @@ where
|
||||
assert_eq!(res.rank_out(), res.rank_in());
|
||||
assert_eq!(sk.rank(), res.rank_out());
|
||||
assert!(
|
||||
scratch.available() >= GGLWEAutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res),
|
||||
scratch.available() >= AutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res),
|
||||
"scratch.available(): {} < AutomorphismKey::encrypt_sk_scratch_space: {}",
|
||||
scratch.available(),
|
||||
GGLWEAutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res)
|
||||
AutomorphismKeyCompressed::encrypt_sk_scratch_space(self, res)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf: DataMut> GGLWEAutomorphismKeyCompressed<DataSelf> {
|
||||
impl<DataSelf: DataMut> AutomorphismKeyCompressed<DataSelf> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn encrypt_sk<DataSk: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
TakeGLWEPt,
|
||||
encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal},
|
||||
layouts::{
|
||||
GGLWECiphertext, GGLWEInfos, LWEInfos,
|
||||
GGLWE, GGLWEInfos, LWEInfos,
|
||||
compressed::{GGLWECiphertextCompressed, GGLWECiphertextCompressedToMut},
|
||||
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
||||
},
|
||||
@@ -40,7 +40,7 @@ impl GGLWECiphertextCompressed<Vec<u8>> {
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||
{
|
||||
GGLWECiphertext::encrypt_sk_scratch_space(module, infos)
|
||||
GGLWE::encrypt_sk_scratch_space(module, infos)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,25 +11,25 @@ use crate::{
|
||||
TakeGLWESecretPrepared,
|
||||
encryption::compressed::gglwe_ct::GGLWECompressedEncryptSk,
|
||||
layouts::{
|
||||
Degree, GGLWECiphertext, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos,
|
||||
compressed::{GGLWEKeyCompressed, GGLWEKeyCompressedToMut},
|
||||
Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos,
|
||||
compressed::{GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedToMut},
|
||||
prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
|
||||
impl GGLWEKeyCompressed<Vec<u8>> {
|
||||
impl GLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + SvpPPolAllocBytes,
|
||||
{
|
||||
(GGLWECiphertext::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1))
|
||||
(GGLWE::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1))
|
||||
+ ScalarZnx::alloc_bytes(module.n(), infos.rank_in().into())
|
||||
+ GLWESecretPrepared::alloc_bytes_with(module, infos.rank_out())
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf: DataMut> GGLWEKeyCompressed<DataSelf> {
|
||||
impl<DataSelf: DataMut> GLWESwitchingKeyCompressed<DataSelf> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
@@ -56,7 +56,7 @@ pub trait GGLWEKeyCompressedEncryptSk<B: Backend> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGLWEKeyCompressedToMut,
|
||||
R: GLWESwitchingKeyCompressedToMut,
|
||||
SI: GLWESecretToRef,
|
||||
SO: GLWESecretToRef;
|
||||
}
|
||||
@@ -80,25 +80,25 @@ where
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGLWEKeyCompressedToMut,
|
||||
R: GLWESwitchingKeyCompressedToMut,
|
||||
SI: GLWESecretToRef,
|
||||
SO: GLWESecretToRef,
|
||||
{
|
||||
let res: &mut GGLWEKeyCompressed<&mut [u8]> = &mut res.to_mut();
|
||||
let res: &mut GLWESwitchingKeyCompressed<&mut [u8]> = &mut res.to_mut();
|
||||
let sk_in: &GLWESecret<&[u8]> = &sk_in.to_ref();
|
||||
let sk_out: &GLWESecret<&[u8]> = &sk_out.to_ref();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
use crate::layouts::GGLWESwitchingKey;
|
||||
use crate::layouts::GLWESwitchingKey;
|
||||
|
||||
assert!(sk_in.n().0 <= self.n() as u32);
|
||||
assert!(sk_out.n().0 <= self.n() as u32);
|
||||
assert!(
|
||||
scratch.available() >= GGLWESwitchingKey::encrypt_sk_scratch_space(self, res),
|
||||
scratch.available() >= GLWESwitchingKey::encrypt_sk_scratch_space(self, res),
|
||||
"scratch.available()={} < GLWESwitchingKey::encrypt_sk_scratch_space={}",
|
||||
scratch.available(),
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(self, res)
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(self, res)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,20 +11,19 @@ use crate::{
|
||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||
encryption::compressed::gglwe_ksk::GGLWEKeyCompressedEncryptSk,
|
||||
layouts::{
|
||||
GGLWEInfos, GGLWETensorKey, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank,
|
||||
compressed::{GGLWETensorKeyCompressed, GGLWETensorKeyCompressedToMut},
|
||||
prepared::Prepare,
|
||||
GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey,
|
||||
compressed::{TensorKeyCompressed, TensorKeyCompressedToMut},
|
||||
},
|
||||
};
|
||||
|
||||
impl GGLWETensorKeyCompressed<Vec<u8>> {
|
||||
impl TensorKeyCompressed<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
Module<B>:
|
||||
SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes + VecZnxBigAllocBytes,
|
||||
{
|
||||
GGLWETensorKey::encrypt_sk_scratch_space(module, infos)
|
||||
TensorKey::encrypt_sk_scratch_space(module, infos)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +36,7 @@ pub trait GGLWETensorKeyCompressedEncryptSk<B: Backend> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGLWETensorKeyCompressedToMut,
|
||||
R: TensorKeyCompressedToMut,
|
||||
S: GLWESecretToRef;
|
||||
}
|
||||
|
||||
@@ -59,10 +58,10 @@ where
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGLWETensorKeyCompressedToMut,
|
||||
R: TensorKeyCompressedToMut,
|
||||
S: GLWESecretToRef,
|
||||
{
|
||||
let res: &mut GGLWETensorKeyCompressed<&mut [u8]> = &mut res.to_mut();
|
||||
let res: &mut TensorKeyCompressed<&mut [u8]> = &mut res.to_mut();
|
||||
let sk: &GLWESecret<&[u8]> = &sk.to_ref();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -119,7 +118,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf: DataMut> GGLWETensorKeyCompressed<DataSelf> {
|
||||
impl<DataSelf: DataMut> TensorKeyCompressed<DataSelf> {
|
||||
pub fn encrypt_sk<DataSk: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
module: &Module<B>,
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
TakeGLWEPt,
|
||||
encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal},
|
||||
layouts::{
|
||||
GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos,
|
||||
GGSW, GGSWInfos, GLWEInfos, LWEInfos,
|
||||
compressed::{GGSWCiphertextCompressed, GGSWCiphertextCompressedToMut},
|
||||
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
||||
},
|
||||
@@ -20,7 +20,7 @@ impl GGSWCiphertextCompressed<Vec<u8>> {
|
||||
A: GGSWInfos,
|
||||
Module<B>: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes,
|
||||
{
|
||||
GGSWCiphertext::encrypt_sk_scratch_space(module, infos)
|
||||
GGSW::encrypt_sk_scratch_space(module, infos)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
use poulpy_hal::{
|
||||
api::{
|
||||
ScratchAvailable, SvpApplyDftToDftInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal,
|
||||
VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftApply, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize,
|
||||
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace,
|
||||
},
|
||||
api::{VecZnxDftAllocBytes, VecZnxNormalizeTmpBytes},
|
||||
layouts::{Backend, DataMut, DataRef, Module, Scratch},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
encryption::{SIGMA, glwe_ct::glwe_encrypt_sk_internal},
|
||||
encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal},
|
||||
layouts::{
|
||||
GLWECiphertext, GLWEInfos, GLWEPlaintext, LWEInfos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared,
|
||||
GLWECiphertext, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, LWEInfos,
|
||||
compressed::{GLWECiphertextCompressed, GLWECiphertextCompressedToMut},
|
||||
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -25,6 +23,60 @@ impl GLWECiphertextCompressed<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWECompressedEncryptSk<B: Backend> {
|
||||
fn glwe_compressed_encrypt_sk<R, P, S>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
pt: &P,
|
||||
sk: &S,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GLWECiphertextCompressedToMut,
|
||||
P: GLWEPlaintextToRef,
|
||||
S: GLWESecretPreparedToRef<B>;
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWECompressedEncryptSk<B> for Module<B>
|
||||
where
|
||||
Module<B>: GLWEEncryptSkInternal<B>,
|
||||
{
|
||||
fn glwe_compressed_encrypt_sk<R, P, S>(
|
||||
&self,
|
||||
res: &mut R,
|
||||
pt: &P,
|
||||
sk: &S,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GLWECiphertextCompressedToMut,
|
||||
P: GLWEPlaintextToRef,
|
||||
S: GLWESecretPreparedToRef<B>,
|
||||
{
|
||||
let res: &mut GLWECiphertextCompressed<&mut [u8]> = &mut res.to_mut();
|
||||
let mut source_xa: Source = Source::new(seed_xa);
|
||||
let cols: usize = (res.rank() + 1).into();
|
||||
|
||||
self.glwe_encrypt_sk_internal(
|
||||
res.base2k().into(),
|
||||
res.k().into(),
|
||||
&mut res.data,
|
||||
cols,
|
||||
true,
|
||||
Some((pt, 0)),
|
||||
sk,
|
||||
&mut source_xa,
|
||||
source_xe,
|
||||
SIGMA,
|
||||
scratch,
|
||||
);
|
||||
|
||||
res.seed = seed_xa;
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
|
||||
@@ -36,65 +88,8 @@ impl<D: DataMut> GLWECiphertextCompressed<D> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxDftApply<B>
|
||||
+ SvpApplyDftToDftInplace<B>
|
||||
+ VecZnxIdftApplyConsume<B>
|
||||
+ VecZnxNormalizeTmpBytes
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxSubInplace
|
||||
+ VecZnxAddInplace
|
||||
+ VecZnxNormalizeInplace<B>
|
||||
+ VecZnxAddNormal
|
||||
+ VecZnxNormalize<B>
|
||||
+ VecZnxSub,
|
||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||
Module<B>: GLWECompressedEncryptSk<B>,
|
||||
{
|
||||
self.encrypt_sk_internal(module, Some((pt, 0)), sk, seed_xa, source_xe, scratch);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn encrypt_sk_internal<DataPt: DataRef, DataSk: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
module: &Module<B>,
|
||||
pt: Option<(&GLWEPlaintext<DataPt>, usize)>,
|
||||
sk: &GLWESecretPrepared<DataSk, B>,
|
||||
seed_xa: [u8; 32],
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
Module<B>: VecZnxDftAllocBytes
|
||||
+ VecZnxBigNormalize<B>
|
||||
+ VecZnxDftApply<B>
|
||||
+ SvpApplyDftToDftInplace<B>
|
||||
+ VecZnxIdftApplyConsume<B>
|
||||
+ VecZnxNormalizeTmpBytes
|
||||
+ VecZnxFillUniform
|
||||
+ VecZnxSubInplace
|
||||
+ VecZnxAddInplace
|
||||
+ VecZnxNormalizeInplace<B>
|
||||
+ VecZnxAddNormal
|
||||
+ VecZnxNormalize<B>
|
||||
+ VecZnxSub,
|
||||
Scratch<B>: TakeVecZnxDft<B> + ScratchAvailable + TakeVecZnx,
|
||||
{
|
||||
let mut source_xa = Source::new(seed_xa);
|
||||
let cols: usize = (self.rank() + 1).into();
|
||||
glwe_encrypt_sk_internal(
|
||||
module,
|
||||
self.base2k().into(),
|
||||
self.k().into(),
|
||||
&mut self.data,
|
||||
cols,
|
||||
true,
|
||||
pt,
|
||||
sk,
|
||||
&mut source_xa,
|
||||
source_xe,
|
||||
SIGMA,
|
||||
scratch,
|
||||
);
|
||||
self.seed = seed_xa;
|
||||
module.glwe_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,11 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||
layouts::{
|
||||
GGLWEAutomorphismKey, GGLWEAutomorphismKeyToMut, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, GLWESecret, GLWESecretToRef,
|
||||
LWEInfos,
|
||||
AutomorphismKey, AutomorphismKeyToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, LWEInfos,
|
||||
},
|
||||
};
|
||||
|
||||
impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||
impl AutomorphismKey<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<BE: Backend, A>(module: &Module<BE>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
@@ -28,7 +27,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||
infos.rank_out(),
|
||||
"rank_in != rank_out is not supported for GGLWEAutomorphismKey"
|
||||
);
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESecret::alloc_bytes(&infos.glwe_layout())
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESecret::alloc_bytes(&infos.glwe_layout())
|
||||
}
|
||||
|
||||
pub fn encrypt_pk_scratch_space<BE: Backend, A>(module: &Module<BE>, _infos: &A) -> usize
|
||||
@@ -40,7 +39,7 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||
_infos.rank_out(),
|
||||
"rank_in != rank_out is not supported for GGLWEAutomorphismKey"
|
||||
);
|
||||
GGLWESwitchingKey::encrypt_pk_scratch_space(module, _infos)
|
||||
GLWESwitchingKey::encrypt_pk_scratch_space(module, _infos)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +53,13 @@ pub trait GGLWEAutomorphismKeyEncryptSk<BE: Backend> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
A: GGLWEAutomorphismKeyToMut,
|
||||
A: AutomorphismKeyToMut,
|
||||
B: GLWESecretToRef;
|
||||
}
|
||||
|
||||
impl<DM: DataMut> GGLWEAutomorphismKey<DM>
|
||||
impl<DM: DataMut> AutomorphismKey<DM>
|
||||
where
|
||||
Self: GGLWEAutomorphismKeyToMut,
|
||||
Self: AutomorphismKeyToMut,
|
||||
{
|
||||
pub fn encrypt_sk<S, BE: Backend>(
|
||||
&mut self,
|
||||
@@ -109,10 +108,10 @@ where
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<BE>,
|
||||
) where
|
||||
A: GGLWEAutomorphismKeyToMut,
|
||||
A: AutomorphismKeyToMut,
|
||||
B: GLWESecretToRef,
|
||||
{
|
||||
let res: &mut GGLWEAutomorphismKey<&mut [u8]> = &mut res.to_mut();
|
||||
let res: &mut AutomorphismKey<&mut [u8]> = &mut res.to_mut();
|
||||
let sk: &GLWESecret<&[u8]> = &sk.to_ref();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -123,10 +122,10 @@ where
|
||||
assert_eq!(res.rank_out(), res.rank_in());
|
||||
assert_eq!(sk.rank(), res.rank_out());
|
||||
assert!(
|
||||
scratch.available() >= GGLWEAutomorphismKey::encrypt_sk_scratch_space(self, res),
|
||||
scratch.available() >= AutomorphismKey::encrypt_sk_scratch_space(self, res),
|
||||
"scratch.available(): {} < AutomorphismKey::encrypt_sk_scratch_space: {:?}",
|
||||
scratch.available(),
|
||||
GGLWEAutomorphismKey::encrypt_sk_scratch_space(self, res)
|
||||
AutomorphismKey::encrypt_sk_scratch_space(self, res)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@ use crate::{
|
||||
TakeGLWEPt,
|
||||
encryption::glwe_ct::GLWEEncryptSk,
|
||||
layouts::{
|
||||
GGLWECiphertext, GGLWECiphertextToMut, GGLWEInfos, GLWECiphertext, GLWEPlaintext, LWEInfos,
|
||||
GGLWE, GGLWECiphertextToMut, GGLWEInfos, GLWECiphertext, GLWEPlaintext, LWEInfos,
|
||||
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
||||
},
|
||||
};
|
||||
|
||||
impl GGLWECiphertext<Vec<u8>> {
|
||||
impl GGLWE<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
@@ -68,7 +68,7 @@ where
|
||||
P: ScalarZnxToRef,
|
||||
S: GLWESecretPreparedToRef<B>,
|
||||
{
|
||||
let res: &mut GGLWECiphertext<&mut [u8]> = &mut res.to_mut();
|
||||
let res: &mut GGLWE<&mut [u8]> = &mut res.to_mut();
|
||||
let pt: &ScalarZnx<&[u8]> = &pt.to_ref();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -93,12 +93,12 @@ where
|
||||
assert_eq!(res.n(), sk.n());
|
||||
assert_eq!(pt.n() as u32, sk.n());
|
||||
assert!(
|
||||
scratch.available() >= GGLWECiphertext::encrypt_sk_scratch_space(self, res),
|
||||
scratch.available() >= GGLWE::encrypt_sk_scratch_space(self, res),
|
||||
"scratch.available: {} < GGLWECiphertext::encrypt_sk_scratch_space(self, res.rank()={}, res.size()={}): {}",
|
||||
scratch.available(),
|
||||
res.rank_out(),
|
||||
res.size(),
|
||||
GGLWECiphertext::encrypt_sk_scratch_space(self, res)
|
||||
GGLWE::encrypt_sk_scratch_space(self, res)
|
||||
);
|
||||
assert!(
|
||||
res.dnum().0 * res.dsize().0 * res.base2k().0 <= res.k().0,
|
||||
@@ -148,7 +148,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf: DataMut> GGLWECiphertext<DataSelf> {
|
||||
impl<DataSelf: DataMut> GGLWE<DataSelf> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
|
||||
@@ -11,18 +11,16 @@ use poulpy_hal::{
|
||||
|
||||
use crate::{
|
||||
TakeGLWESecretPrepared,
|
||||
layouts::{
|
||||
Degree, GGLWECiphertext, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, GLWESecret, LWEInfos, prepared::GLWESecretPrepared,
|
||||
},
|
||||
layouts::{Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
|
||||
impl GGLWESwitchingKey<Vec<u8>> {
|
||||
impl GLWESwitchingKey<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||
{
|
||||
(GGLWECiphertext::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1))
|
||||
(GGLWE::encrypt_sk_scratch_space(module, infos) | ScalarZnx::alloc_bytes(module.n(), 1))
|
||||
+ ScalarZnx::alloc_bytes(module.n(), infos.rank_in().into())
|
||||
+ GLWESecretPrepared::alloc_bytes(module, &infos.glwe_layout())
|
||||
}
|
||||
@@ -31,11 +29,11 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
GGLWECiphertext::encrypt_pk_scratch_space(module, _infos)
|
||||
GGLWE::encrypt_pk_scratch_space(module, _infos)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
||||
impl<DataSelf: DataMut> GLWESwitchingKey<DataSelf> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn encrypt_sk<DataSkIn: DataRef, DataSkOut: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
@@ -70,10 +68,10 @@ impl<DataSelf: DataMut> GGLWESwitchingKey<DataSelf> {
|
||||
assert!(sk_in.n().0 <= module.n() as u32);
|
||||
assert!(sk_out.n().0 <= module.n() as u32);
|
||||
assert!(
|
||||
scratch.available() >= GGLWESwitchingKey::encrypt_sk_scratch_space(module, self),
|
||||
scratch.available() >= GLWESwitchingKey::encrypt_sk_scratch_space(module, self),
|
||||
"scratch.available()={} < GLWESwitchingKey::encrypt_sk_scratch_space={}",
|
||||
scratch.available(),
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, self)
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, self)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,11 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||
layouts::{
|
||||
Degree, GGLWEInfos, GGLWESwitchingKey, GGLWETensorKey, GLWEInfos, GLWESecret, LWEInfos, Rank,
|
||||
prepared::{GLWESecretPrepared, Prepare},
|
||||
Degree, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, TensorKey, prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
|
||||
impl GGLWETensorKey<Vec<u8>> {
|
||||
impl TensorKey<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
@@ -29,11 +28,11 @@ impl GGLWETensorKey<Vec<u8>> {
|
||||
+ module.vec_znx_big_alloc_bytes(1, 1)
|
||||
+ module.vec_znx_dft_alloc_bytes(1, 1)
|
||||
+ GLWESecret::alloc_bytes_with(Degree(module.n() as u32), Rank(1))
|
||||
+ GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
+ GLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf: DataMut> GGLWETensorKey<DataSelf> {
|
||||
impl<DataSelf: DataMut> TensorKey<DataSelf> {
|
||||
pub fn encrypt_sk<DataSk: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
module: &Module<B>,
|
||||
|
||||
@@ -8,12 +8,12 @@ use crate::{
|
||||
SIGMA, TakeGLWEPt,
|
||||
encryption::glwe_ct::GLWEEncryptSkInternal,
|
||||
layouts::{
|
||||
GGSWCiphertext, GGSWCiphertextToMut, GGSWInfos, GLWECiphertext, GLWEInfos, LWEInfos,
|
||||
GGSW, GGSWInfos, GGSWToMut, GLWECiphertext, GLWEInfos, LWEInfos,
|
||||
prepared::{GLWESecretPrepared, GLWESecretPreparedToRef},
|
||||
},
|
||||
};
|
||||
|
||||
impl GGSWCiphertext<Vec<u8>> {
|
||||
impl GGSW<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGSWInfos,
|
||||
@@ -37,7 +37,7 @@ pub trait GGSWEncryptSk<B: Backend> {
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGSWCiphertextToMut,
|
||||
R: GGSWToMut,
|
||||
P: ScalarZnxToRef,
|
||||
S: GLWESecretPreparedToRef<B>;
|
||||
}
|
||||
@@ -56,11 +56,11 @@ where
|
||||
source_xe: &mut Source,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
R: GGSWCiphertextToMut,
|
||||
R: GGSWToMut,
|
||||
P: ScalarZnxToRef,
|
||||
S: GLWESecretPreparedToRef<B>,
|
||||
{
|
||||
let res: &mut GGSWCiphertext<&mut [u8]> = &mut res.to_mut();
|
||||
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
|
||||
let pt: &ScalarZnx<&[u8]> = &pt.to_ref();
|
||||
let sk: &GLWESecretPrepared<&[u8], B> = &sk.to_ref();
|
||||
|
||||
@@ -106,7 +106,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<DataSelf: DataMut> GGSWCiphertext<DataSelf> {
|
||||
impl<DataSelf: DataMut> GGSW<DataSelf> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn encrypt_sk<DataPt: DataRef, DataSk: DataRef, B: Backend>(
|
||||
&mut self,
|
||||
|
||||
@@ -11,22 +11,24 @@ use poulpy_hal::{
|
||||
|
||||
use crate::{
|
||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||
layouts::{GGLWEInfos, GGLWESwitchingKey, GLWESecret, GLWEToLWEKey, LWEInfos, LWESecret, Rank, prepared::GLWESecretPrepared},
|
||||
layouts::{
|
||||
GGLWEInfos, GLWESecret, GLWESwitchingKey, GLWEToLWESwitchingKey, LWEInfos, LWESecret, Rank, prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
|
||||
impl GLWEToLWEKey<Vec<u8>> {
|
||||
impl GLWEToLWESwitchingKey<Vec<u8>> {
|
||||
pub fn encrypt_sk_scratch_space<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
Module<B>: SvpPPolAllocBytes + VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes + VecZnxNormalizeTmpBytes,
|
||||
{
|
||||
GLWESecretPrepared::alloc_bytes_with(module, infos.rank_in())
|
||||
+ (GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
+ (GLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
| GLWESecret::alloc_bytes_with(infos.n(), infos.rank_in()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> GLWEToLWEKey<D> {
|
||||
impl<D: DataMut> GLWEToLWESwitchingKey<D> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn encrypt_sk<DLwe, DGlwe, B: Backend>(
|
||||
&mut self,
|
||||
|
||||
@@ -12,7 +12,7 @@ use poulpy_hal::{
|
||||
use crate::{
|
||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||
layouts::{
|
||||
Degree, GGLWEInfos, GGLWESwitchingKey, GLWESecret, LWEInfos, LWESecret, LWESwitchingKey, Rank,
|
||||
Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank,
|
||||
prepared::GLWESecretPrepared,
|
||||
},
|
||||
};
|
||||
@@ -40,7 +40,7 @@ impl LWESwitchingKey<Vec<u8>> {
|
||||
);
|
||||
GLWESecret::alloc_bytes_with(Degree(module.n() as u32), Rank(1))
|
||||
+ GLWESecretPrepared::alloc_bytes_with(module, Rank(1))
|
||||
+ GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
+ GLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use poulpy_hal::{
|
||||
|
||||
use crate::{
|
||||
TakeGLWESecret, TakeGLWESecretPrepared,
|
||||
layouts::{Degree, GGLWEInfos, GGLWESwitchingKey, GLWESecret, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank},
|
||||
layouts::{Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank},
|
||||
};
|
||||
|
||||
impl LWEToGLWESwitchingKey<Vec<u8>> {
|
||||
@@ -25,7 +25,7 @@ impl LWEToGLWESwitchingKey<Vec<u8>> {
|
||||
Rank(1),
|
||||
"rank_in != 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
GGLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
GLWESwitchingKey::encrypt_sk_scratch_space(module, infos)
|
||||
+ GLWESecret::alloc_bytes_with(Degree(module.n() as u32), infos.rank_in())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user