This commit is contained in:
Pro7ech
2025-10-15 18:26:32 +02:00
parent 10817a8529
commit 2ea59310fb
57 changed files with 363 additions and 314 deletions

View File

@@ -7,7 +7,7 @@ use poulpy_hal::{
use crate::{
encryption::compressed::gglwe_ct::GGLWECompressedEncryptSk,
layouts::{
Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos,
GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, RingDegree,
compressed::{GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedToMut},
prepared::GLWESecretPrepared,
},
@@ -110,7 +110,7 @@ where
);
});
let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(Degree(n as u32), sk_out.rank());
let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(RingDegree(n as u32), sk_out.rank());
{
let (mut tmp, _) = scratch_2.take_scalar_znx(n, 1);
(0..sk_out.rank().into()).for_each(|i| {

View File

@@ -9,7 +9,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, prepared::GLWESecretPrepared,
GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, RingDegree, prepared::GLWESecretPrepared,
};
impl GLWESwitchingKey<Vec<u8>> {
@@ -85,7 +85,7 @@ impl<DataSelf: DataMut> GLWESwitchingKey<DataSelf> {
);
});
let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(Degree(n as u32), sk_out.rank());
let (mut sk_out_tmp, scratch_2) = scratch_1.take_glwe_secret_prepared(RingDegree(n as u32), sk_out.rank());
{
let (mut tmp, _) = scratch_2.take_scalar_znx(n, 1);
(0..sk_out.rank().into()).for_each(|i| {

View File

@@ -10,7 +10,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Degree, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, TensorKey, prepared::GLWESecretPrepared,
GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, RingDegree, TensorKey, prepared::GLWESecretPrepared,
};
impl TensorKey<Vec<u8>> {
@@ -23,7 +23,7 @@ impl TensorKey<Vec<u8>> {
+ module.bytes_of_vec_znx_dft(infos.rank_out().into(), 1)
+ module.bytes_of_vec_znx_big(1, 1)
+ module.bytes_of_vec_znx_dft(1, 1)
+ GLWESecret::bytes_of(Degree(module.n() as u32), Rank(1))
+ GLWESecret::bytes_of(RingDegree(module.n() as u32), Rank(1))
+ GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos)
}
}
@@ -64,7 +64,7 @@ impl<DataSelf: DataMut> TensorKey<DataSelf> {
assert_eq!(self.n(), sk.n());
}
let n: Degree = sk.n();
let n: RingDegree = sk.n();
let rank: Rank = self.rank_out();
let (mut sk_dft_prep, scratch_1) = scratch.take_glwe_secret_prepared(n, rank);

View File

@@ -10,7 +10,8 @@ use poulpy_hal::{
};
use crate::layouts::{
Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank, prepared::GLWESecretPrepared,
GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank, RingDegree,
prepared::GLWESecretPrepared,
};
impl LWESwitchingKey<Vec<u8>> {
@@ -34,7 +35,7 @@ impl LWESwitchingKey<Vec<u8>> {
1,
"rank_out > 1 is not supported for LWESwitchingKey"
);
GLWESecret::bytes_of(Degree(module.n() as u32), Rank(1))
GLWESecret::bytes_of(RingDegree(module.n() as u32), Rank(1))
+ GLWESecretPrepared::bytes_of(module, Rank(1))
+ GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos)
}

View File

@@ -9,7 +9,7 @@ use poulpy_hal::{
source::Source,
};
use crate::layouts::{Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank};
use crate::layouts::{GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank, RingDegree};
impl LWEToGLWESwitchingKey<Vec<u8>> {
pub fn encrypt_sk_tmp_bytes<B: Backend, A>(module: &Module<B>, infos: &A) -> usize
@@ -22,7 +22,8 @@ impl LWEToGLWESwitchingKey<Vec<u8>> {
Rank(1),
"rank_in != 1 is not supported for LWEToGLWESwitchingKey"
);
GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos) + GLWESecret::bytes_of(Degree(module.n() as u32), infos.rank_in())
GLWESwitchingKey::encrypt_sk_tmp_bytes(module, infos)
+ GLWESecret::bytes_of(RingDegree(module.n() as u32), infos.rank_in())
}
}

View File

@@ -1,22 +1,48 @@
use poulpy_hal::{
api::{
ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftApply,
VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft,
VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes,
},
layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxView, ZnxViewMut, ZnxZero},
api::ScratchAvailable,
layouts::{Backend, DataMut, Module, Scratch, ZnxView, ZnxViewMut, ZnxZero},
};
use crate::{
ScratchTakeCore,
keyswitching::glwe_ct::GLWEKeySwitch,
layouts::{prepared::LWESwitchingKeyPrepared, GGLWEInfos, GLWEAlloc, GLWELayout, GetDegree, LWEToRef, LWEInfos, Rank, TorusPrecision, GLWE, LWE},
layouts::{
GGLWEInfos, GLWE, GLWEAlloc, GLWELayout, LWE, LWEInfos, LWEToMut, LWEToRef, Rank, TorusPrecision,
prepared::{LWESwitchingKeyPrepared, LWESwitchingKeyPreparedToRef},
},
};
impl LWE<Vec<u8>> {
pub fn keyswitch_tmp_bytes<M, R, A, K, BE: Backend>(module: &M, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
where
R: LWEInfos,
A: LWEInfos,
K: GGLWEInfos,
M: LWEKeySwitch<BE>,
{
module.lwe_keyswitch_tmp_bytes(res_infos, a_infos, key_infos)
}
}
impl<D: DataMut> LWE<D> {
pub fn keyswitch<M, A, K, BE: Backend>(&mut self, module: &M, a: &A, ksk: &K, scratch: &mut Scratch<BE>)
where
A: LWEToRef,
K: LWESwitchingKeyPreparedToRef<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
M: LWEKeySwitch<BE>,
{
module.lwe_keyswitch(self, a, ksk, scratch);
}
}
impl<BE: Backend> LWEKeySwitch<BE> for Module<BE> where Self: LWEKeySwitch<BE> {}
pub trait LWEKeySwitch<BE: Backend>
where
Self: GLWEKeySwitch<BE> + GLWEAlloc,
{
fn keyswitch_tmp_bytes<B: Backend, R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
fn lwe_keyswitch_tmp_bytes<R, A, K>(&self, res_infos: &R, a_infos: &A, key_infos: &K) -> usize
where
R: LWEInfos,
A: LWEInfos,
@@ -25,14 +51,14 @@ where
let max_k: TorusPrecision = a_infos.k().max(res_infos.k());
let glwe_a_infos: GLWELayout = GLWELayout {
n: GetDegree::n(self),
n: self.ring_degree(),
base2k: a_infos.base2k(),
k: max_k,
rank: Rank(1),
};
let glwe_res_infos: GLWELayout = GLWELayout {
n: GetDegree::n(self),
n: self.ring_degree(),
base2k: res_infos.base2k(),
k: max_k,
rank: Rank(1),
@@ -45,39 +71,46 @@ where
glwe_in + glwe_out + ks
}
fn keyswitch<A, DKs, B: Backend>(
&mut self,
module: &Module<B>,
a: &A,
ksk: &K,
scratch: &mut Scratch<B>,
) where
fn lwe_keyswitch<R, A, K>(&self, res: &mut R, a: &A, ksk: &K, scratch: &mut Scratch<BE>)
where
R: LWEToMut,
A: LWEToRef,
DKs: DataRef,
Scratch<B>: ScratchAvailable,
K: LWESwitchingKeyPreparedToRef<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{
assert!(self.n() <= module.n() as u32);
assert!(a.n() <= module.n() as u32);
assert!(scratch.available() >= LWE::keyswitch_tmp_bytes(module, self, a, ksk));
let res: &mut LWE<&mut [u8]> = &mut res.to_mut();
let a: &LWE<&[u8]> = &a.to_ref();
let ksk: &LWESwitchingKeyPrepared<&[u8], BE> = &ksk.to_ref();
let max_k: TorusPrecision = self.k().max(a.k());
assert!(res.n().as_usize() <= self.n());
assert!(a.n().as_usize() <= self.n());
assert_eq!(ksk.n(), self.n() as u32);
assert!(scratch.available() >= self.lwe_keyswitch_tmp_bytes(res, a, ksk));
let max_k: TorusPrecision = res.k().max(a.k());
let a_size: usize = a.k().div_ceil(ksk.base2k()) as usize;
let (mut glwe_in, scratch_1) = scratch.take_glwe_ct(&GLWELayout {
n: ksk.n(),
base2k: a.base2k(),
k: max_k,
rank: Rank(1),
});
let (mut glwe_in, scratch_1) = scratch.take_glwe_ct(
self,
&GLWELayout {
n: ksk.n(),
base2k: a.base2k(),
k: max_k,
rank: Rank(1),
},
);
glwe_in.data.zero();
let (mut glwe_out, scratch_1) = scratch_1.take_glwe_ct(&GLWELayout {
n: ksk.n(),
base2k: self.base2k(),
k: max_k,
rank: Rank(1),
});
let (mut glwe_out, scratch_1) = scratch_1.take_glwe_ct(
self,
&GLWELayout {
n: ksk.n(),
base2k: res.base2k(),
k: max_k,
rank: Rank(1),
},
);
let n_lwe: usize = a.n().into();
@@ -87,13 +120,7 @@ where
glwe_in.data.at_mut(1, i)[..n_lwe].copy_from_slice(&data_lwe[1..]);
}
glwe_out.keyswitch(module, &glwe_in, &ksk.0, scratch_1);
self.sample_extract(&glwe_out);
self.glwe_keyswitch(&mut glwe_out, &glwe_in, &ksk.0, scratch_1);
res.sample_extract(&glwe_out);
}
}
impl LWE<Vec<u8>> {}
impl<DLwe: DataMut> LWE<DLwe> {
}

View File

@@ -4,7 +4,8 @@ use poulpy_hal::{
};
use crate::layouts::{
AutomorphismKey, AutomorphismKeyToMut, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
AutomorphismKey, AutomorphismKeyToMut, Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree,
TorusPrecision,
compressed::{
GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut,
GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress,
@@ -21,7 +22,7 @@ pub struct AutomorphismKeyCompressed<D: Data> {
}
impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.key.n()
}

View File

@@ -7,7 +7,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision,
compressed::{GLWECompressed, GLWEDecompress},
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -24,8 +24,8 @@ pub struct GGLWECompressed<D: Data> {
}
impl<D: Data> LWEInfos for GGLWECompressed<D> {
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn base2k(&self) -> Base2K {
@@ -88,7 +88,7 @@ impl<D: DataRef> fmt::Display for GGLWECompressed<D> {
pub trait GGLWECompressedAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_gglwe_compressed(
&self,
@@ -115,7 +115,7 @@ where
GGLWECompressed {
data: MatZnx::alloc(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
rank_in.into(),
1,
@@ -133,7 +133,7 @@ where
where
A: GGLWEInfos,
{
assert_eq!(infos.n(), self.n());
assert_eq!(infos.n(), self.ring_degree());
self.alloc_gglwe_compressed(
infos.base2k(),
infos.k(),
@@ -160,7 +160,7 @@ where
);
MatZnx::bytes_of(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
rank_in.into(),
1,
@@ -172,7 +172,7 @@ where
where
A: GGLWEInfos,
{
assert_eq!(infos.n(), self.n());
assert_eq!(infos.n(), self.ring_degree());
self.bytes_of_gglwe_compressed(
infos.base2k(),
infos.k(),
@@ -183,7 +183,7 @@ where
}
}
impl<B: Backend> GGLWECompressedAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GGLWECompressedAlloc for Module<B> where Self: GetRingDegree {}
impl GGLWECompressed<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self

View File

@@ -4,8 +4,8 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToMut,
LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToMut, LWEInfos,
Rank, RingDegree, TorusPrecision,
compressed::{GGLWECompressed, GGLWECompressedAlloc, GGLWECompressedToMut, GGLWECompressedToRef, GGLWEDecompress},
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -19,7 +19,7 @@ pub struct GLWESwitchingKeyCompressed<D: Data> {
}
impl<D: Data> LWEInfos for GLWESwitchingKeyCompressed<D> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.key.n()
}

View File

@@ -4,7 +4,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToMut, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TensorKey, TensorKeyToMut, TorusPrecision,
compressed::{
GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut,
GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress,
@@ -19,7 +19,7 @@ pub struct TensorKeyCompressed<D: Data> {
}
impl<D: Data> LWEInfos for TensorKeyCompressed<D> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.keys[0].n()
}

View File

@@ -6,7 +6,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision,
compressed::{GLWECompressed, GLWEDecompress},
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -23,8 +23,8 @@ pub struct GGSWCompressed<D: Data> {
}
impl<D: Data> LWEInfos for GGSWCompressed<D> {
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn base2k(&self) -> Base2K {
@@ -78,7 +78,7 @@ impl<D: DataMut> FillUniform for GGSWCompressed<D> {
pub trait GGSWCompressedAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_ggsw_compressed(
&self,
@@ -104,7 +104,7 @@ where
GGSWCompressed {
data: MatZnx::alloc(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
(rank + 1).into(),
1,
@@ -147,7 +147,7 @@ where
);
MatZnx::bytes_of(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
(rank + 1).into(),
1,

View File

@@ -6,7 +6,9 @@ use poulpy_hal::{
source::Source,
};
use crate::layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GetDegree, LWEInfos, Rank, SetGLWEInfos, TorusPrecision};
use crate::layouts::{
Base2K, GLWE, GLWEInfos, GLWEToMut, GetRingDegree, LWEInfos, Rank, RingDegree, SetGLWEInfos, TorusPrecision,
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt;
@@ -32,8 +34,8 @@ impl<D: Data> LWEInfos for GLWECompressed<D> {
self.data.size()
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
}
impl<D: Data> GLWEInfos for GLWECompressed<D> {
@@ -70,11 +72,15 @@ impl<D: DataMut> FillUniform for GLWECompressed<D> {
pub trait GLWECompressedAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_glwe_compressed(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWECompressed<Vec<u8>> {
GLWECompressed {
data: VecZnx::alloc(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize),
data: VecZnx::alloc(
self.ring_degree().into(),
1,
k.0.div_ceil(base2k.0) as usize,
),
base2k,
k,
rank,
@@ -86,24 +92,28 @@ where
where
A: GLWEInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.alloc_glwe_compressed(infos.base2k(), infos.k(), infos.rank())
}
fn bytes_of_glwe_compressed(&self, base2k: Base2K, k: TorusPrecision) -> usize {
VecZnx::bytes_of(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize)
VecZnx::bytes_of(
self.ring_degree().into(),
1,
k.0.div_ceil(base2k.0) as usize,
)
}
fn bytes_of_glwe_compressed_from_infos<A>(&self, infos: &A) -> usize
where
A: GLWEInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.bytes_of_glwe_compressed(infos.base2k(), infos.k())
}
}
impl<B: Backend> GLWECompressedAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GLWECompressedAlloc for Module<B> where Self: GetRingDegree {}
impl GLWECompressed<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -159,7 +169,7 @@ impl<D: DataRef> WriterTo for GLWECompressed<D> {
pub trait GLWEDecompress
where
Self: GetDegree + VecZnxFillUniform + VecZnxCopy,
Self: GetRingDegree + VecZnxFillUniform + VecZnxCopy,
{
fn decompress_glwe<R, O>(&self, res: &mut R, other: &O)
where
@@ -171,10 +181,10 @@ where
let other: &GLWECompressed<&[u8]> = &other.to_ref();
assert_eq!(
res.n(),
self.n(),
self.ring_degree(),
"invalid receiver: res.n()={} != other.n()={}",
res.n(),
self.n()
self.ring_degree()
);
assert_eq!(res.lwe_layout(), other.lwe_layout());
@@ -193,7 +203,7 @@ where
}
}
impl<B: Backend> GLWEDecompress for Module<B> where Self: GetDegree + VecZnxFillUniform + VecZnxCopy {}
impl<B: Backend> GLWEDecompress for Module<B> where Self: GetRingDegree + VecZnxFillUniform + VecZnxCopy {}
impl<D: DataMut> GLWE<D> {
pub fn decompress<O, M>(&mut self, module: &M, other: &O)

View File

@@ -6,7 +6,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyToMut, LWEInfos, Rank,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKey, GLWEToLWESwitchingKeyToMut, LWEInfos, Rank, RingDegree,
TorusPrecision,
compressed::{
GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut,
@@ -26,7 +26,7 @@ impl<D: Data> LWEInfos for GLWEToLWESwitchingKeyCompressed<D> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}
fn size(&self) -> usize {

View File

@@ -9,7 +9,7 @@ use poulpy_hal::{
source::Source,
};
use crate::layouts::{Base2K, Degree, LWE, LWEInfos, LWEToMut, TorusPrecision};
use crate::layouts::{Base2K, LWE, LWEInfos, LWEToMut, RingDegree, TorusPrecision};
#[derive(PartialEq, Eq, Clone)]
pub struct LWECompressed<D: Data> {
@@ -28,8 +28,8 @@ impl<D: Data> LWEInfos for LWECompressed<D> {
self.k
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn size(&self) -> usize {

View File

@@ -4,7 +4,8 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, LWESwitchingKeyToMut, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, LWESwitchingKeyToMut, Rank, RingDegree,
TorusPrecision,
compressed::{
GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut,
GLWESwitchingKeyCompressedToRef, GLWESwitchingKeyDecompress,
@@ -24,7 +25,7 @@ impl<D: Data> LWEInfos for LWESwitchingKeyCompressed<D> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}
fn size(&self) -> usize {

View File

@@ -4,7 +4,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyToMut, Rank,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, LWEToGLWESwitchingKeyToMut, Rank, RingDegree,
TorusPrecision,
compressed::{
GLWESwitchingKeyCompressed, GLWESwitchingKeyCompressedAlloc, GLWESwitchingKeyCompressedToMut,
@@ -17,7 +17,7 @@ use std::fmt;
pub struct LWEToGLWESwitchingKeyCompressed<D: Data>(pub(crate) GLWESwitchingKeyCompressed<D>);
impl<D: Data> LWEInfos for LWEToGLWESwitchingKeyCompressed<D> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}

View File

@@ -4,8 +4,8 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWE, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWE, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision,
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -13,7 +13,7 @@ use std::fmt;
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct AutomorphismKeyLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank: Rank,
@@ -34,7 +34,7 @@ impl<D: Data> AutomorphismKey<D> {
}
impl<D: Data> LWEInfos for AutomorphismKey<D> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.key.n()
}
@@ -84,7 +84,7 @@ impl LWEInfos for AutomorphismKeyLayout {
self.k
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
}

View File

@@ -5,7 +5,7 @@ use poulpy_hal::{
source::Source,
};
use crate::layouts::{Base2K, Degree, Dnum, Dsize, GLWE, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision};
use crate::layouts::{Base2K, Dnum, Dsize, GLWE, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt;
@@ -37,7 +37,7 @@ pub trait SetGGLWEInfos {
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GGLWELayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank_in: Rank,
@@ -55,7 +55,7 @@ impl LWEInfos for GGLWELayout {
self.k
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
}
@@ -101,8 +101,8 @@ impl<D: Data> LWEInfos for GGLWE<D> {
self.k
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn size(&self) -> usize {
@@ -162,7 +162,7 @@ impl<D: DataRef> fmt::Display for GGLWE<D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"(GGLWECiphertext: k={} base2k={} dsize={}) {}",
"(GGLWE: k={} base2k={} dsize={}) {}",
self.k().0,
self.base2k().0,
self.dsize().0,
@@ -193,7 +193,7 @@ impl<D: DataMut> GGLWE<D> {
pub trait GGLWEAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_gglwe(
&self,
@@ -220,7 +220,7 @@ where
GGLWE {
data: MatZnx::alloc(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
rank_in.into(),
(rank_out + 1).into(),
@@ -270,7 +270,7 @@ where
);
MatZnx::bytes_of(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
rank_in.into(),
(rank_out + 1).into(),
@@ -293,7 +293,7 @@ where
}
}
impl<B: Backend> GGLWEAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GGLWEAlloc for Module<B> where Self: GetRingDegree {}
impl GGLWE<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self

View File

@@ -4,7 +4,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEAlloc, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank,
Base2K, Dnum, Dsize, GGLWE, GGLWEAlloc, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, RingDegree,
TorusPrecision,
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -13,7 +13,7 @@ use std::fmt;
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GLWESwitchingKeyLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank_in: Rank,
@@ -23,7 +23,7 @@ pub struct GLWESwitchingKeyLayout {
}
impl LWEInfos for GLWESwitchingKeyLayout {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
@@ -98,7 +98,7 @@ impl<D: DataRef> GLWESwtichingKeyGetMetaData for GLWESwitchingKey<D> {
}
impl<D: Data> LWEInfos for GLWESwitchingKey<D> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.key.n()
}

View File

@@ -4,8 +4,8 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision,
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -13,7 +13,7 @@ use std::fmt;
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct TensorKeyLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank: Rank,
@@ -27,7 +27,7 @@ pub struct TensorKey<D: Data> {
}
impl<D: Data> LWEInfos for TensorKey<D> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.keys[0].n()
}
@@ -69,7 +69,7 @@ impl<D: Data> GGLWEInfos for TensorKey<D> {
}
impl LWEInfos for TensorKeyLayout {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}

View File

@@ -6,7 +6,7 @@ use poulpy_hal::{
};
use std::fmt;
use crate::layouts::{Base2K, Degree, Dnum, Dsize, GLWE, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision};
use crate::layouts::{Base2K, Dnum, Dsize, GLWE, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision};
pub trait GGSWInfos
where
@@ -28,7 +28,7 @@ where
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GGSWLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank: Rank,
@@ -45,7 +45,7 @@ impl LWEInfos for GGSWLayout {
self.k
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
}
@@ -74,8 +74,8 @@ pub struct GGSW<D: Data> {
}
impl<D: Data> LWEInfos for GGSW<D> {
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn base2k(&self) -> Base2K {
@@ -152,11 +152,11 @@ impl<D: DataMut> GGSW<D> {
}
}
impl<B: Backend> GGSWAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GGSWAlloc for Module<B> where Self: GetRingDegree {}
pub trait GGSWAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_ggsw(&self, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> GGSW<Vec<u8>> {
let size: usize = k.0.div_ceil(base2k.0) as usize;
@@ -175,7 +175,7 @@ where
GGSW {
data: MatZnx::alloc(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
(rank + 1).into(),
(rank + 1).into(),
@@ -216,7 +216,7 @@ where
);
MatZnx::bytes_of(
self.n().into(),
self.ring_degree().into(),
dnum.into(),
(rank + 1).into(),
(rank + 1).into(),

View File

@@ -6,7 +6,7 @@ use poulpy_hal::{
source::Source,
};
use crate::layouts::{Base2K, Degree, GetDegree, LWEInfos, Rank, TorusPrecision};
use crate::layouts::{Base2K, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt;
@@ -32,14 +32,14 @@ pub trait SetGLWEInfos {
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GLWELayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank: Rank,
}
impl LWEInfos for GLWELayout {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
@@ -96,8 +96,8 @@ impl<D: Data> LWEInfos for GLWE<D> {
self.k
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn size(&self) -> usize {
@@ -148,12 +148,12 @@ impl<D: DataMut> FillUniform for GLWE<D> {
pub trait GLWEAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_glwe(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWE<Vec<u8>> {
GLWE {
data: VecZnx::alloc(
self.n().into(),
self.ring_degree().into(),
(rank + 1).into(),
k.0.div_ceil(base2k.0) as usize,
),
@@ -171,7 +171,7 @@ where
fn bytes_of_glwe(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize {
VecZnx::bytes_of(
self.n().into(),
self.ring_degree().into(),
(rank + 1).into(),
k.0.div_ceil(base2k.0) as usize,
)
@@ -185,7 +185,7 @@ where
}
}
impl<B: Backend> GLWEAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GLWEAlloc for Module<B> where Self: GetRingDegree {}
impl GLWE<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self

View File

@@ -4,7 +4,7 @@ use poulpy_hal::layouts::{
use crate::{
dist::Distribution,
layouts::{Base2K, Degree, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision},
layouts::{Base2K, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision},
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -18,7 +18,7 @@ pub struct GLWEPublicKey<D: Data> {
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GLWEPublicKeyLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank: Rank,
@@ -43,8 +43,8 @@ impl<D: Data> LWEInfos for GLWEPublicKey<D> {
self.k
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn size(&self) -> usize {
@@ -67,7 +67,7 @@ impl LWEInfos for GLWEPublicKeyLayout {
self.k
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
@@ -84,12 +84,12 @@ impl GLWEInfos for GLWEPublicKeyLayout {
pub trait GLWEPublicKeyAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_glwe_public_key(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKey<Vec<u8>> {
GLWEPublicKey {
data: VecZnx::alloc(
self.n().into(),
self.ring_degree().into(),
(rank + 1).into(),
k.0.div_ceil(base2k.0) as usize,
),
@@ -108,7 +108,7 @@ where
fn bytes_of_glwe_public_key(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize {
VecZnx::bytes_of(
self.n().into(),
self.ring_degree().into(),
(rank + 1).into(),
k.0.div_ceil(base2k.0) as usize,
)
@@ -122,7 +122,7 @@ where
}
}
impl<B: Backend> GLWEPublicKeyAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GLWEPublicKeyAlloc for Module<B> where Self: GetRingDegree {}
impl GLWEPublicKey<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self

View File

@@ -3,12 +3,12 @@ use std::fmt;
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, VecZnx, VecZnxToMut, VecZnxToRef, ZnxInfos};
use crate::layouts::{
Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetDegree, LWEInfos, Rank, SetGLWEInfos, TorusPrecision,
Base2K, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetRingDegree, LWEInfos, Rank, RingDegree, SetGLWEInfos, TorusPrecision,
};
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GLWEPlaintextLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
}
@@ -22,7 +22,7 @@ impl LWEInfos for GLWEPlaintextLayout {
self.k
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
}
@@ -62,8 +62,8 @@ impl<D: Data> LWEInfos for GLWEPlaintext<D> {
self.data.size()
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
}
@@ -87,11 +87,15 @@ impl<D: DataRef> fmt::Display for GLWEPlaintext<D> {
pub trait GLWEPlaintextAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_glwe_plaintext(&self, base2k: Base2K, k: TorusPrecision) -> GLWEPlaintext<Vec<u8>> {
GLWEPlaintext {
data: VecZnx::alloc(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize),
data: VecZnx::alloc(
self.ring_degree().into(),
1,
k.0.div_ceil(base2k.0) as usize,
),
base2k,
k,
}
@@ -105,7 +109,11 @@ where
}
fn bytes_of_glwe_plaintext(&self, base2k: Base2K, k: TorusPrecision) -> usize {
VecZnx::bytes_of(self.n().into(), 1, k.0.div_ceil(base2k.0) as usize)
VecZnx::bytes_of(
self.ring_degree().into(),
1,
k.0.div_ceil(base2k.0) as usize,
)
}
fn bytes_of_glwe_plaintext_from_infos<A>(&self, infos: &A) -> usize
@@ -116,7 +124,7 @@ where
}
}
impl<B: Backend> GLWEPlaintextAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GLWEPlaintextAlloc for Module<B> where Self: GetRingDegree {}
impl GLWEPlaintext<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self

View File

@@ -8,12 +8,12 @@ use poulpy_hal::{
use crate::{
dist::Distribution,
layouts::{Base2K, Degree, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision},
layouts::{Base2K, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision},
};
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GLWESecretLayout {
pub n: Degree,
pub n: RingDegree,
pub rank: Rank,
}
@@ -26,7 +26,7 @@ impl LWEInfos for GLWESecretLayout {
TorusPrecision(0)
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
@@ -55,8 +55,8 @@ impl<D: Data> LWEInfos for GLWESecret<D> {
TorusPrecision(0)
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn size(&self) -> usize {
@@ -72,11 +72,11 @@ impl<D: Data> GLWEInfos for GLWESecret<D> {
pub trait GLWESecretAlloc
where
Self: GetDegree,
Self: GetRingDegree,
{
fn alloc_glwe_secret(&self, rank: Rank) -> GLWESecret<Vec<u8>> {
GLWESecret {
data: ScalarZnx::alloc(self.n().into(), rank.into()),
data: ScalarZnx::alloc(self.ring_degree().into(), rank.into()),
dist: Distribution::NONE,
}
}
@@ -89,7 +89,7 @@ where
}
fn bytes_of_glwe_secret(&self, rank: Rank) -> usize {
ScalarZnx::bytes_of(self.n().into(), rank.into())
ScalarZnx::bytes_of(self.ring_degree().into(), rank.into())
}
fn bytes_of_glwe_secret_from_infos<A>(&self, infos: &A) -> usize
@@ -100,7 +100,7 @@ where
}
}
impl<B: Backend> GLWESecretAlloc for Module<B> where Self: GetDegree {}
impl<B: Backend> GLWESecretAlloc for Module<B> where Self: GetRingDegree {}
impl GLWESecret<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self

View File

@@ -4,15 +4,15 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision,
};
use std::fmt;
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GLWEToLWEKeyLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank_in: Rank,
@@ -20,7 +20,7 @@ pub struct GLWEToLWEKeyLayout {
}
impl LWEInfos for GLWEToLWEKeyLayout {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
@@ -70,7 +70,7 @@ impl<D: Data> LWEInfos for GLWEToLWESwitchingKey<D> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}

View File

@@ -5,11 +5,11 @@ use poulpy_hal::{
source::Source,
};
use crate::layouts::{Base2K, Degree, TorusPrecision};
use crate::layouts::{Base2K, RingDegree, TorusPrecision};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
pub trait LWEInfos {
fn n(&self) -> Degree;
fn n(&self) -> RingDegree;
fn k(&self) -> TorusPrecision;
fn max_k(&self) -> TorusPrecision {
TorusPrecision(self.k().0 * self.size() as u32)
@@ -34,7 +34,7 @@ pub trait SetLWEInfos {
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct LWELayout {
pub n: Degree,
pub n: RingDegree,
pub k: TorusPrecision,
pub base2k: Base2K,
}
@@ -48,7 +48,7 @@ impl LWEInfos for LWELayout {
self.k
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
}
@@ -67,8 +67,8 @@ impl<D: Data> LWEInfos for LWE<D> {
fn k(&self) -> TorusPrecision {
self.k
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32 - 1)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32 - 1)
}
fn size(&self) -> usize {
@@ -126,7 +126,7 @@ where
}
pub trait LWEAlloc {
fn alloc_lwe(&self, n: Degree, base2k: Base2K, k: TorusPrecision) -> LWE<Vec<u8>> {
fn alloc_lwe(&self, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> LWE<Vec<u8>> {
LWE {
data: Zn::alloc((n + 1).into(), 1, k.0.div_ceil(base2k.0) as usize),
k,
@@ -141,7 +141,7 @@ pub trait LWEAlloc {
self.alloc_lwe(infos.n(), infos.base2k(), infos.k())
}
fn bytes_of_lwe(&self, n: Degree, base2k: Base2K, k: TorusPrecision) -> usize {
fn bytes_of_lwe(&self, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> usize {
Zn::bytes_of((n + 1).into(), 1, k.0.div_ceil(base2k.0) as usize)
}
@@ -164,7 +164,7 @@ impl LWE<Vec<u8>> {
module.alloc_lwe_from_infos(infos)
}
pub fn alloc<M>(module: &M, n: Degree, base2k: Base2K, k: TorusPrecision) -> Self
pub fn alloc<M>(module: &M, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> Self
where
M: LWEAlloc,
{
@@ -179,7 +179,7 @@ impl LWE<Vec<u8>> {
module.bytes_of_lwe_from_infos(infos)
}
pub fn bytes_of<M>(module: &M, n: Degree, base2k: Base2K, k: TorusPrecision) -> usize
pub fn bytes_of<M>(module: &M, n: RingDegree, base2k: Base2K, k: TorusPrecision) -> usize
where
M: LWEAlloc,
{

View File

@@ -6,20 +6,20 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision,
};
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct LWESwitchingKeyLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub dnum: Dnum,
}
impl LWEInfos for LWESwitchingKeyLayout {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
@@ -68,7 +68,7 @@ impl<D: Data> LWEInfos for LWESwitchingKey<D> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}

View File

@@ -2,7 +2,7 @@ use std::fmt;
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Zn, ZnToMut, ZnToRef, ZnxInfos};
use crate::layouts::{Base2K, Degree, LWEInfos, TorusPrecision};
use crate::layouts::{Base2K, LWEInfos, RingDegree, TorusPrecision};
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct LWEPlaintextLayout {
@@ -19,8 +19,8 @@ impl LWEInfos for LWEPlaintextLayout {
self.k
}
fn n(&self) -> Degree {
Degree(0)
fn n(&self) -> RingDegree {
RingDegree(0)
}
fn size(&self) -> usize {
@@ -43,8 +43,8 @@ impl<D: Data> LWEInfos for LWEPlaintext<D> {
self.k
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32 - 1)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32 - 1)
}
fn size(&self) -> usize {

View File

@@ -5,7 +5,7 @@ use poulpy_hal::{
use crate::{
dist::Distribution,
layouts::{Base2K, Degree, LWEInfos, TorusPrecision},
layouts::{Base2K, LWEInfos, RingDegree, TorusPrecision},
};
pub struct LWESecret<D: Data> {
@@ -14,7 +14,7 @@ pub struct LWESecret<D: Data> {
}
pub trait LWESecretAlloc {
fn alloc_lwe_secret(&self, n: Degree) -> LWESecret<Vec<u8>> {
fn alloc_lwe_secret(&self, n: RingDegree) -> LWESecret<Vec<u8>> {
LWESecret {
data: ScalarZnx::alloc(n.into(), 1),
dist: Distribution::NONE,
@@ -25,7 +25,7 @@ pub trait LWESecretAlloc {
impl<B: Backend> LWESecretAlloc for Module<B> {}
impl LWESecret<Vec<u8>> {
pub fn alloc<M>(module: &M, n: Degree) -> Self
pub fn alloc<M>(module: &M, n: RingDegree) -> Self
where
M: LWESecretAlloc,
{
@@ -55,8 +55,8 @@ impl<D: Data> LWEInfos for LWESecret<D> {
TorusPrecision(0)
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn size(&self) -> usize {

View File

@@ -6,13 +6,13 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, GLWESwitchingKeyAlloc, GLWESwitchingKeyToMut,
GLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision,
};
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct LWEToGLWESwitchingKeyLayout {
pub n: Degree,
pub n: RingDegree,
pub base2k: Base2K,
pub k: TorusPrecision,
pub rank_out: Rank,
@@ -28,7 +28,7 @@ impl LWEInfos for LWEToGLWESwitchingKeyLayout {
self.k
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.n
}
}
@@ -69,7 +69,7 @@ impl<D: Data> LWEInfos for LWEToGLWESwitchingKey<D> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}

View File

@@ -35,12 +35,12 @@ pub use lwe_to_glwe_ksk::*;
use poulpy_hal::layouts::{Backend, Module};
pub trait GetDegree {
fn n(&self) -> Degree;
pub trait GetRingDegree {
fn ring_degree(&self) -> RingDegree;
}
impl<B: Backend> GetDegree for Module<B> {
fn n(&self) -> Degree {
impl<B: Backend> GetRingDegree for Module<B> {
fn ring_degree(&self) -> RingDegree {
Self::n(&self).into()
}
}
@@ -202,14 +202,14 @@ macro_rules! newtype_u32 {
};
}
newtype_u32!(Degree);
newtype_u32!(RingDegree);
newtype_u32!(TorusPrecision);
newtype_u32!(Base2K);
newtype_u32!(Dnum);
newtype_u32!(Rank);
newtype_u32!(Dsize);
impl Degree {
impl RingDegree {
pub fn log2(&self) -> usize {
let n: usize = self.0 as usize;
(usize::BITS - (n - 1).leading_zeros()) as _

View File

@@ -1,7 +1,7 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{
AutomorphismKeyToRef, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
AutomorphismKeyToRef, Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TorusPrecision,
prepared::{
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
GLWESwitchingKeyPreparedToRef,
@@ -15,7 +15,7 @@ pub struct AutomorphismKeyPrepared<D: Data, B: Backend> {
}
impl<D: Data, B: Backend> LWEInfos for AutomorphismKeyPrepared<D, B> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.key.n()
}

View File

@@ -4,7 +4,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToRef, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToRef, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision,
};
#[derive(PartialEq, Eq)]
@@ -16,8 +16,8 @@ pub struct GGLWEPrepared<D: Data, B: Backend> {
}
impl<D: Data, B: Backend> LWEInfos for GGLWEPrepared<D, B> {
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn base2k(&self) -> Base2K {
@@ -59,7 +59,7 @@ impl<D: Data, B: Backend> GGLWEInfos for GGLWEPrepared<D, B> {
pub trait GGLWEPreparedAlloc<B: Backend>
where
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf,
Self: GetRingDegree + VmpPMatAlloc<B> + VmpPMatBytesOf,
{
fn alloc_gglwe_prepared(
&self,
@@ -96,7 +96,7 @@ where
where
A: GGLWEInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.alloc_gglwe_prepared(
infos.base2k(),
infos.k(),
@@ -137,7 +137,7 @@ where
where
A: GGLWEInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.bytes_of_gglwe_prepared(
infos.base2k(),
infos.k(),
@@ -149,7 +149,7 @@ where
}
}
impl<B: Backend> GGLWEPreparedAlloc<B> for Module<B> where Module<B>: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {}
impl<B: Backend> GGLWEPreparedAlloc<B> for Module<B> where Module<B>: GetRingDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {}
impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -201,7 +201,7 @@ impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
pub trait GGLWEPrepare<B: Backend>
where
Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B>,
Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare<B>,
{
fn prepare_gglwe_tmp_bytes<A>(&self, infos: &A) -> usize
where
@@ -223,8 +223,8 @@ where
let mut res: GGLWEPrepared<&mut [u8], B> = res.to_mut();
let other: GGLWE<&[u8]> = other.to_ref();
assert_eq!(res.n(), self.n());
assert_eq!(other.n(), self.n());
assert_eq!(res.n(), self.ring_degree());
assert_eq!(other.n(), self.ring_degree());
assert_eq!(res.base2k, other.base2k);
assert_eq!(res.k, other.k);
assert_eq!(res.dsize, other.dsize);
@@ -233,7 +233,7 @@ where
}
}
impl<B: Backend> GGLWEPrepare<B> for Module<B> where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B> {}
impl<B: Backend> GGLWEPrepare<B> for Module<B> where Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare<B> {}
impl<D: DataMut, B: Backend> GGLWEPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)

View File

@@ -1,8 +1,8 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToRef,
GLWESwtichingKeyGetMetaData, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToRef, GLWESwtichingKeyGetMetaData,
LWEInfos, Rank, RingDegree, TorusPrecision,
prepared::{GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef},
};
@@ -34,7 +34,7 @@ impl<D: DataRef, B: Backend> GLWESwtichingKeyGetMetaData for GLWESwitchingKeyPre
}
impl<D: Data, B: Backend> LWEInfos for GLWESwitchingKeyPrepared<D, B> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.key.n()
}

View File

@@ -1,7 +1,7 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TensorKey, TensorKeyToRef, TorusPrecision,
prepared::{
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
GLWESwitchingKeyPreparedToRef,
@@ -14,7 +14,7 @@ pub struct TensorKeyPrepared<D: Data, B: Backend> {
}
impl<D: Data, B: Backend> LWEInfos for TensorKeyPrepared<D, B> {
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.keys[0].n()
}

View File

@@ -4,7 +4,7 @@ use poulpy_hal::{
};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision,
};
#[derive(PartialEq, Eq)]
@@ -16,8 +16,8 @@ pub struct GGSWPrepared<D: Data, B: Backend> {
}
impl<D: Data, B: Backend> LWEInfos for GGSWPrepared<D, B> {
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn base2k(&self) -> Base2K {
@@ -51,7 +51,7 @@ impl<D: Data, B: Backend> GGSWInfos for GGSWPrepared<D, B> {
pub trait GGSWPreparedAlloc<B: Backend>
where
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf,
Self: GetRingDegree + VmpPMatAlloc<B> + VmpPMatBytesOf,
{
fn alloc_ggsw_prepared(
&self,
@@ -92,7 +92,7 @@ where
where
A: GGSWInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.alloc_ggsw_prepared(
infos.base2k(),
infos.k(),
@@ -124,7 +124,7 @@ where
where
A: GGSWInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.bytes_of_ggsw_prepared(
infos.base2k(),
infos.k(),
@@ -135,7 +135,7 @@ where
}
}
impl<B: Backend> GGSWPreparedAlloc<B> for Module<B> where Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {}
impl<B: Backend> GGSWPreparedAlloc<B> for Module<B> where Self: GetRingDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {}
impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -177,13 +177,13 @@ impl<D: DataRef, B: Backend> GGSWPrepared<D, B> {
pub trait GGSWPrepare<B: Backend>
where
Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B>,
Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare<B>,
{
fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize
where
A: GGSWInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.vmp_prepare_tmp_bytes(
infos.dnum().into(),
(infos.rank() + 1).into(),
@@ -198,8 +198,8 @@ where
{
let mut res: GGSWPrepared<&mut [u8], B> = res.to_mut();
let other: GGSW<&[u8]> = other.to_ref();
assert_eq!(res.n(), self.n());
assert_eq!(other.n(), self.n());
assert_eq!(res.n(), self.ring_degree());
assert_eq!(other.n(), self.ring_degree());
assert_eq!(res.k, other.k);
assert_eq!(res.base2k, other.base2k);
assert_eq!(res.dsize, other.dsize);
@@ -207,7 +207,7 @@ where
}
}
impl<B: Backend> GGSWPrepare<B> for Module<B> where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B> {}
impl<B: Backend> GGSWPrepare<B> for Module<B> where Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare<B> {}
impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize

View File

@@ -5,7 +5,9 @@ use poulpy_hal::{
use crate::{
dist::Distribution,
layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision},
layouts::{
Base2K, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision,
},
};
#[derive(PartialEq, Eq)]
@@ -39,8 +41,8 @@ impl<D: Data, B: Backend> LWEInfos for GLWEPublicKeyPrepared<D, B> {
self.data.size()
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
}
@@ -52,7 +54,7 @@ impl<D: Data, B: Backend> GLWEInfos for GLWEPublicKeyPrepared<D, B> {
pub trait GLWEPublicKeyPreparedAlloc<B: Backend>
where
Self: GetDegree + VecZnxDftAlloc<B> + VecZnxDftBytesOf,
Self: GetRingDegree + VecZnxDftAlloc<B> + VecZnxDftBytesOf,
{
fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared<Vec<u8>, B> {
GLWEPublicKeyPrepared {
@@ -118,7 +120,7 @@ impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> {
pub trait GLWEPublicKeyPrepare<B: Backend>
where
Self: GetDegree + VecZnxDftApply<B>,
Self: GetRingDegree + VecZnxDftApply<B>,
{
fn prepare_glwe_public_key<R, O>(&self, res: &mut R, other: &O)
where
@@ -129,8 +131,8 @@ where
let mut res: GLWEPublicKeyPrepared<&mut [u8], B> = res.to_mut();
let other: GLWEPublicKey<&[u8]> = other.to_ref();
assert_eq!(res.n(), self.n());
assert_eq!(other.n(), self.n());
assert_eq!(res.n(), self.ring_degree());
assert_eq!(other.n(), self.ring_degree());
assert_eq!(res.size(), other.size());
assert_eq!(res.k(), other.k());
assert_eq!(res.base2k(), other.base2k());
@@ -144,7 +146,7 @@ where
}
}
impl<B: Backend> GLWEPublicKeyPrepare<B> for Module<B> where Self: GetDegree + VecZnxDftApply<B> {}
impl<B: Backend> GLWEPublicKeyPrepare<B> for Module<B> where Self: GetRingDegree + VecZnxDftApply<B> {}
impl<D: DataMut, B: Backend> GLWEPublicKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O)

View File

@@ -6,7 +6,7 @@ use poulpy_hal::{
use crate::{
dist::Distribution,
layouts::{
Base2K, Degree, GLWEInfos, GLWESecret, GLWESecretToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision,
Base2K, GLWEInfos, GLWESecret, GLWESecretToRef, GetDist, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision,
prepared::SetDist,
},
};
@@ -31,8 +31,8 @@ impl<D: Data, B: Backend> LWEInfos for GLWESecretPrepared<D, B> {
TorusPrecision(0)
}
fn n(&self) -> Degree {
Degree(self.data.n() as u32)
fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
fn size(&self) -> usize {
@@ -47,7 +47,7 @@ impl<D: Data, B: Backend> GLWEInfos for GLWESecretPrepared<D, B> {
pub trait GLWESecretPreparedAlloc<B: Backend>
where
Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B>,
Self: GetRingDegree + SvpPPolBytesOf + SvpPPolAlloc<B>,
{
fn alloc_glwe_secret_prepared(&self, rank: Rank) -> GLWESecretPrepared<Vec<u8>, B> {
GLWESecretPrepared {
@@ -59,7 +59,7 @@ where
where
A: GLWEInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.alloc_glwe_secret_prepared(infos.rank())
}
@@ -70,12 +70,12 @@ where
where
A: GLWEInfos,
{
assert_eq!(self.n(), infos.n());
assert_eq!(self.ring_degree(), infos.n());
self.bytes_of_glwe_secret(infos.rank())
}
}
impl<B: Backend> GLWESecretPreparedAlloc<B> for Module<B> where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B> {}
impl<B: Backend> GLWESecretPreparedAlloc<B> for Module<B> where Self: GetRingDegree + SvpPPolBytesOf + SvpPPolAlloc<B> {}
impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -110,8 +110,8 @@ impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
}
impl<D: Data, B: Backend> GLWESecretPrepared<D, B> {
pub fn n(&self) -> Degree {
Degree(self.data.n() as u32)
pub fn n(&self) -> RingDegree {
RingDegree(self.data.n() as u32)
}
pub fn rank(&self) -> Rank {

View File

@@ -1,7 +1,7 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKeyToRef, LWEInfos, Rank, RingDegree, TorusPrecision,
prepared::{
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
GLWESwitchingKeyPreparedToRef,
@@ -20,7 +20,7 @@ impl<D: Data, B: Backend> LWEInfos for GLWEToLWESwitchingKeyPrepared<D, B> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}

View File

@@ -1,7 +1,7 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKeyToRef, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKeyToRef, Rank, RingDegree, TorusPrecision,
prepared::{
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
GLWESwitchingKeyPreparedToRef,
@@ -20,7 +20,7 @@ impl<D: Data, B: Backend> LWEInfos for LWESwitchingKeyPrepared<D, B> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}

View File

@@ -1,7 +1,7 @@
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use crate::layouts::{
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKeyToRef, Rank, TorusPrecision,
Base2K, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKeyToRef, Rank, RingDegree, TorusPrecision,
prepared::{
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
GLWESwitchingKeyPreparedToRef,
@@ -21,7 +21,7 @@ impl<D: Data, B: Backend> LWEInfos for LWEToGLWESwitchingKeyPrepared<D, B> {
self.0.k()
}
fn n(&self) -> Degree {
fn n(&self) -> RingDegree {
self.0.n()
}