This commit is contained in:
Pro7ech
2025-10-22 16:43:46 +02:00
parent 5755aea58c
commit cedf7b9c59
26 changed files with 713 additions and 723 deletions

View File

@@ -116,7 +116,7 @@ where
}
}
res.set_p((p * key.p()) % (self.cyclotomic_order() as i64));
res.set_p((p * key.p()) % self.cyclotomic_order());
}
fn glwe_automorphism_key_automorphism_inplace<R, K>(&self, res: &mut R, key: &K, scratch: &mut Scratch<BE>)
@@ -160,6 +160,6 @@ where
}
}
res.set_p((res.p() * key.p()) % (self.cyclotomic_order() as i64));
res.set_p((res.p() * key.p()) % self.cyclotomic_order());
}
}

View File

@@ -107,7 +107,7 @@ where
let base2k: usize = res.base2k().into();
let rank: usize = res.rank().into();
let dsize: usize = res.dsize().into();
let cols: usize = (rank + 1).into();
let cols: usize = rank + 1;
let (mut tmp_pt, scratch_1) = scratch.take_glwe_plaintext(res);

View File

@@ -427,6 +427,7 @@ where
}
pub(crate) trait GLWEEncryptSkInternal<BE: Backend> {
#[allow(clippy::too_many_arguments)]
fn glwe_encrypt_sk_internal<R, P, S>(
&self,
base2k: usize,

View File

@@ -192,7 +192,7 @@ pub trait GLWECompressedToRef {
impl<D: DataRef> GLWECompressedToRef for GLWECompressed<D> {
fn to_ref(&self) -> GLWECompressed<&[u8]> {
GLWECompressed {
seed: self.seed.clone(),
seed: self.seed,
base2k: self.base2k,
k: self.k,
rank: self.rank,
@@ -208,7 +208,7 @@ pub trait GLWECompressedToMut {
impl<D: DataMut> GLWECompressedToMut for GLWECompressed<D> {
fn to_mut(&mut self) -> GLWECompressed<&mut [u8]> {
GLWECompressed {
seed: self.seed.clone(),
seed: self.seed,
base2k: self.base2k,
k: self.k,
rank: self.rank,

View File

@@ -146,8 +146,8 @@ where {
impl<D: DataMut> ReaderFrom for GLWESwitchingKeyCompressed<D> {
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
self.input_degree = Degree(reader.read_u32::<LittleEndian>()? as u32);
self.output_degree = Degree(reader.read_u32::<LittleEndian>()? as u32);
self.input_degree = Degree(reader.read_u32::<LittleEndian>()?);
self.output_degree = Degree(reader.read_u32::<LittleEndian>()?);
self.key.read_from(reader)
}
}

View File

@@ -240,8 +240,8 @@ impl<D: DataMut> GLWESwitchingKey<D> {
impl<D: DataMut> ReaderFrom for GLWESwitchingKey<D> {
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
self.input_degree = Degree(reader.read_u32::<LittleEndian>()? as u32);
self.output_degree = Degree(reader.read_u32::<LittleEndian>()? as u32);
self.input_degree = Degree(reader.read_u32::<LittleEndian>()?);
self.output_degree = Degree(reader.read_u32::<LittleEndian>()?);
self.key.read_from(reader)
}
}

View File

@@ -43,7 +43,7 @@ pub trait GetDegree {
impl<B: Backend> GetDegree for Module<B> {
fn ring_degree(&self) -> Degree {
Self::n(&self).into()
Self::n(self).into()
}
}

View File

@@ -69,7 +69,7 @@ pub trait GLWEAutomorphismKeyPreparedFactory<B: Backend>
where
Self: GGLWEPreparedFactory<B>,
{
fn alloc_automorphism_key_prepared(
fn alloc_glwe_automorphism_key_prepared(
&self,
base2k: Base2K,
k: TorusPrecision,
@@ -83,7 +83,7 @@ where
}
}
fn alloc_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> GLWEAutomorphismKeyPrepared<Vec<u8>, B>
fn alloc_glwe_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> GLWEAutomorphismKeyPrepared<Vec<u8>, B>
where
A: GGLWEInfos,
{
@@ -92,7 +92,7 @@ where
infos.rank_out(),
"rank_in != rank_out is not supported for AutomorphismKeyPrepared"
);
self.alloc_automorphism_key_prepared(
self.alloc_glwe_automorphism_key_prepared(
infos.base2k(),
infos.k(),
infos.rank(),
@@ -101,7 +101,7 @@ where
)
}
fn bytes_of_automorphism_key_prepared(
fn bytes_of_glwe_automorphism_key_prepared(
&self,
base2k: Base2K,
k: TorusPrecision,
@@ -112,7 +112,7 @@ where
self.bytes_of_gglwe_prepared(base2k, k, rank, rank, dnum, dsize)
}
fn bytes_of_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> usize
fn bytes_of_glwe_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos,
{
@@ -121,7 +121,7 @@ where
infos.rank_out(),
"rank_in != rank_out is not supported for AutomorphismKeyPrepared"
);
self.bytes_of_automorphism_key_prepared(
self.bytes_of_glwe_automorphism_key_prepared(
infos.base2k(),
infos.k(),
infos.rank(),
@@ -130,14 +130,14 @@ where
)
}
fn prepare_automorphism_key_tmp_bytes<A>(&self, infos: &A) -> usize
fn prepare_glwe_automorphism_key_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos,
{
self.prepare_gglwe_tmp_bytes(infos)
}
fn prepare_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
fn prepare_glwe_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
where
R: GGLWEPreparedToMut<B> + SetGaloisElement,
O: GGLWEToRef + GetGaloisElement,
@@ -155,14 +155,14 @@ impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
A: GGLWEInfos,
M: GLWEAutomorphismKeyPreparedFactory<B>,
{
module.alloc_automorphism_key_prepared_from_infos(infos)
module.alloc_glwe_automorphism_key_prepared_from_infos(infos)
}
pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self
where
M: GLWEAutomorphismKeyPreparedFactory<B>,
{
module.alloc_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
module.alloc_glwe_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
}
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
@@ -170,14 +170,14 @@ impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
A: GGLWEInfos,
M: GLWEAutomorphismKeyPreparedFactory<B>,
{
module.bytes_of_automorphism_key_prepared_from_infos(infos)
module.bytes_of_glwe_automorphism_key_prepared_from_infos(infos)
}
pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize
where
M: GLWEAutomorphismKeyPreparedFactory<B>,
{
module.bytes_of_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
module.bytes_of_glwe_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
}
}
@@ -186,7 +186,7 @@ impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
where
M: GLWEAutomorphismKeyPreparedFactory<B>,
{
module.prepare_automorphism_key_tmp_bytes(self)
module.prepare_glwe_automorphism_key_tmp_bytes(self)
}
}
@@ -196,7 +196,7 @@ impl<D: DataMut, B: Backend> GLWEAutomorphismKeyPrepared<D, B> {
O: GGLWEToRef + GetGaloisElement,
M: GLWEAutomorphismKeyPreparedFactory<B>,
{
module.prepare_automorphism_key(self, other, scratch);
module.prepare_glwe_automorphism_key(self, other, scratch);
}
}

View File

@@ -166,7 +166,10 @@ impl<D: DataRef, B: Backend> GLWESecretPreparedToRef<B> for GLWESecretPrepared<D
}
}
pub trait GLWESecretPreparedToMut<B: Backend> {
pub trait GLWESecretPreparedToMut<B: Backend>
where
Self: GLWESecretPreparedToRef<B>,
{
fn to_mut(&mut self) -> GLWESecretPrepared<&mut [u8], B>;
}

View File

@@ -102,11 +102,11 @@ where
self.bytes_of_glwe_to_lwe_switching_key_prepared(infos.base2k(), infos.k(), infos.rank_in(), infos.dnum())
}
fn prepare_glwe_to_lwe_switching_key_tmp_bytes<A>(&self, infos: &A)
fn prepare_glwe_to_lwe_switching_key_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGLWEInfos,
{
self.prepare_glwe_switching_key_tmp_bytes(infos);
self.prepare_glwe_switching_key_tmp_bytes(infos)
}
fn prepare_glwe_to_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)

View File

@@ -81,7 +81,7 @@ where
i,
);
});
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank().into());
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank());
sk_out_prepared.prepare(module, &sk_out);
atk.key
@@ -150,7 +150,7 @@ where
i,
);
});
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank().into());
let mut sk_out_prepared: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc(module, sk_out.rank());
sk_out_prepared.prepare(module, &sk_out);
let mut atk: GLWEAutomorphismKey<Vec<u8>> = GLWEAutomorphismKey::alloc_from_infos(&atk_infos);