mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
Add BDD Arithmetic (#98)
* Added some circuit, evaluation + some layouts * Refactor + memory reduction * Rows -> Dnum, Digits -> Dsize * fix #96 + glwe_packing (indirectly CBT) * clippy
This commit is contained in:
committed by
GitHub
parent
37e13b965c
commit
6357a05509
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWEAutomorphismKey, GGLWELayoutInfos, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKey, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
@@ -40,7 +40,7 @@ impl<D: Data> GLWEInfos for GGLWEAutomorphismKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWEAutomorphismKeyCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWEAutomorphismKeyCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -49,12 +49,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWEAutomorphismKeyCompressed<D> {
|
||||
self.key.rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.key.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.key.dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.key.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.key.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ impl<D: DataRef> fmt::Display for GGLWEAutomorphismKeyCompressed<D> {
|
||||
impl GGLWEAutomorphismKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(infos.rank_in(), infos.rank_out());
|
||||
Self {
|
||||
@@ -88,23 +88,23 @@ impl GGLWEAutomorphismKeyCompressed<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
Self {
|
||||
key: GGLWESwitchingKeyCompressed::alloc_with(n, base2k, k, rows, digits, rank, rank),
|
||||
key: GGLWESwitchingKeyCompressed::alloc_with(n, base2k, k, rank, rank, dnum, dsize),
|
||||
p: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(infos.rank_in(), infos.rank_out());
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rows, digits, rank, rank)
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rank, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWECiphertext, GGLWELayoutInfos, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWECiphertext, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GLWECiphertextCompressed},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
@@ -17,7 +17,7 @@ pub struct GGLWECiphertextCompressed<D: Data> {
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) rank_out: Rank,
|
||||
pub(crate) digits: Digits,
|
||||
pub(crate) dsize: Dsize,
|
||||
pub(crate) seed: Vec<[u8; 32]>,
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ impl<D: Data> GLWEInfos for GGLWECiphertextCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWECiphertextCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWECiphertextCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
Rank(self.data.cols_in() as u32)
|
||||
}
|
||||
@@ -53,12 +53,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWECiphertextCompressed<D> {
|
||||
self.rank_out
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
Rows(self.data.rows() as u32)
|
||||
fn dnum(&self) -> Dnum {
|
||||
Dnum(self.data.rows() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ impl<D: DataRef> fmt::Display for GGLWECiphertextCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"(GGLWECiphertextCompressed: base2k={} k={} digits={}) {}",
|
||||
self.base2k.0, self.k.0, self.digits.0, self.data
|
||||
"(GGLWECiphertextCompressed: base2k={} k={} dsize={}) {}",
|
||||
self.base2k.0, self.k.0, self.dsize.0, self.data
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -87,16 +87,16 @@ impl<D: DataRef> fmt::Display for GGLWECiphertextCompressed<D> {
|
||||
impl GGLWECiphertextCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
Self::alloc_with(
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -104,82 +104,73 @@ impl GGLWECiphertextCompressed<Vec<u8>> {
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> Self {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid gglwe: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid gglwe: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
Self {
|
||||
data: MatZnx::alloc(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
rank_in.into(),
|
||||
1,
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
),
|
||||
k,
|
||||
base2k,
|
||||
digits,
|
||||
dsize,
|
||||
rank_out,
|
||||
seed: vec![[0u8; 32]; (rows.0 * rank_in.0) as usize],
|
||||
seed: vec![[0u8; 32]; (dnum.0 * rank_in.0) as usize],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
Self::alloc_bytes_with(
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
_rank_out: Rank,
|
||||
) -> usize {
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid gglwe: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid gglwe: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
MatZnx::alloc_bytes(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
rank_in.into(),
|
||||
1,
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
@@ -217,7 +208,7 @@ impl<D: DataMut> ReaderFrom for GGLWECiphertextCompressed<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?);
|
||||
self.base2k = Base2K(reader.read_u32::<LittleEndian>()?);
|
||||
self.digits = Digits(reader.read_u32::<LittleEndian>()?);
|
||||
self.dsize = Dsize(reader.read_u32::<LittleEndian>()?);
|
||||
self.rank_out = Rank(reader.read_u32::<LittleEndian>()?);
|
||||
let seed_len: u32 = reader.read_u32::<LittleEndian>()?;
|
||||
self.seed = vec![[0u8; 32]; seed_len as usize];
|
||||
@@ -232,7 +223,7 @@ impl<D: DataRef> WriterTo for GGLWECiphertextCompressed<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write_u32::<LittleEndian>(self.k.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.base2k.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.digits.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.dsize.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.rank_out.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.seed.len() as u32)?;
|
||||
for s in &self.seed {
|
||||
@@ -279,19 +270,19 @@ where
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
self.rows(),
|
||||
other.rows(),
|
||||
"invalid receiver: self.rows()={} != other.rows()={}",
|
||||
self.rows(),
|
||||
other.rows()
|
||||
self.dnum(),
|
||||
other.dnum(),
|
||||
"invalid receiver: self.dnum()={} != other.dnum()={}",
|
||||
self.dnum(),
|
||||
other.dnum()
|
||||
);
|
||||
}
|
||||
|
||||
let rank_in: usize = self.rank_in().into();
|
||||
let rows: usize = self.rows().into();
|
||||
let dnum: usize = self.dnum().into();
|
||||
|
||||
(0..rank_in).for_each(|col_i| {
|
||||
(0..rows).for_each(|row_i| {
|
||||
(0..dnum).for_each(|row_i| {
|
||||
self.at_mut(row_i, col_i)
|
||||
.decompress(module, &other.at(row_i, col_i));
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GGLWECiphertextCompressed},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
@@ -41,7 +41,7 @@ impl<D: Data> GLWEInfos for GGLWESwitchingKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWESwitchingKeyCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWESwitchingKeyCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -50,12 +50,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWESwitchingKeyCompressed<D> {
|
||||
self.key.rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.key.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.key.dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.key.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.key.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ impl<D: DataRef> fmt::Display for GGLWESwitchingKeyCompressed<D> {
|
||||
impl GGLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
GGLWESwitchingKeyCompressed {
|
||||
key: GGLWECiphertextCompressed::alloc(infos),
|
||||
@@ -97,13 +97,13 @@ impl GGLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> Self {
|
||||
GGLWESwitchingKeyCompressed {
|
||||
key: GGLWECiphertextCompressed::alloc_with(n, base2k, k, rows, digits, rank_in, rank_out),
|
||||
key: GGLWECiphertextCompressed::alloc_with(n, base2k, k, rank_in, rank_out, dnum, dsize),
|
||||
sk_in_n: 0,
|
||||
sk_out_n: 0,
|
||||
}
|
||||
@@ -111,21 +111,13 @@ impl GGLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
GGLWECiphertextCompressed::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
) -> usize {
|
||||
GGLWECiphertextCompressed::alloc_bytes_with(n, base2k, k, rows, digits, rank_in, rank_out)
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
GGLWECiphertextCompressed::alloc_bytes_with(n, base2k, k, rank_in, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWETensorKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWETensorKey, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
@@ -38,7 +38,7 @@ impl<D: Data> GLWEInfos for GGLWETensorKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWETensorKeyCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWETensorKeyCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
@@ -47,12 +47,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWETensorKeyCompressed<D> {
|
||||
self.keys[0].rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.keys[0].digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.keys[0].dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.keys[0].rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.keys[0].dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ impl<D: DataRef> fmt::Display for GGLWETensorKeyCompressed<D> {
|
||||
impl GGLWETensorKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
@@ -94,13 +94,13 @@ impl GGLWETensorKeyCompressed<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
let mut keys: Vec<GGLWESwitchingKeyCompressed<Vec<u8>>> = Vec::new();
|
||||
let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1);
|
||||
(0..pairs).for_each(|_| {
|
||||
@@ -108,10 +108,10 @@ impl GGLWETensorKeyCompressed<Vec<u8>> {
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
digits,
|
||||
Rank(1),
|
||||
rank,
|
||||
dnum,
|
||||
dsize,
|
||||
));
|
||||
});
|
||||
Self { keys }
|
||||
@@ -119,7 +119,7 @@ impl GGLWETensorKeyCompressed<Vec<u8>> {
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
@@ -133,16 +133,15 @@ impl GGLWETensorKeyCompressed<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
Rank(1),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> usize {
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
let pairs: usize = (((rank.0 + 1) * rank.0) >> 1).max(1) as usize;
|
||||
pairs * GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rows, digits, Rank(1), rank)
|
||||
pairs * GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GLWECiphertextCompressed},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
@@ -16,7 +16,7 @@ pub struct GGSWCiphertextCompressed<D: Data> {
|
||||
pub(crate) data: MatZnx<D>,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) digits: Digits,
|
||||
pub(crate) dsize: Dsize,
|
||||
pub(crate) rank: Rank,
|
||||
pub(crate) seed: Vec<[u8; 32]>,
|
||||
}
|
||||
@@ -44,12 +44,12 @@ impl<D: Data> GLWEInfos for GGSWCiphertextCompressed<D> {
|
||||
}
|
||||
|
||||
impl<D: Data> GGSWInfos for GGSWCiphertextCompressed<D> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
Rows(self.data.rows() as u32)
|
||||
fn dnum(&self) -> Dnum {
|
||||
Dnum(self.data.rows() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ impl<D: DataRef> fmt::Display for GGSWCiphertextCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"(GGSWCiphertextCompressed: base2k={} k={} digits={}) {}",
|
||||
self.base2k, self.k, self.digits, self.data
|
||||
"(GGSWCiphertextCompressed: base2k={} k={} dsize={}) {}",
|
||||
self.base2k, self.k, self.dsize, self.data
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -84,38 +84,38 @@ impl GGSWCiphertextCompressed<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
Self {
|
||||
data: MatZnx::alloc(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
(rank + 1).into(),
|
||||
1,
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
),
|
||||
k,
|
||||
base2k,
|
||||
digits,
|
||||
dsize,
|
||||
rank,
|
||||
seed: Vec::new(),
|
||||
}
|
||||
@@ -129,30 +129,30 @@ impl GGSWCiphertextCompressed<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> usize {
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
MatZnx::alloc_bytes(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
(rank + 1).into(),
|
||||
1,
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
@@ -190,7 +190,7 @@ impl<D: DataMut> ReaderFrom for GGSWCiphertextCompressed<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?);
|
||||
self.base2k = Base2K(reader.read_u32::<LittleEndian>()?);
|
||||
self.digits = Digits(reader.read_u32::<LittleEndian>()?);
|
||||
self.dsize = Dsize(reader.read_u32::<LittleEndian>()?);
|
||||
self.rank = Rank(reader.read_u32::<LittleEndian>()?);
|
||||
let seed_len: usize = reader.read_u32::<LittleEndian>()? as usize;
|
||||
self.seed = vec![[0u8; 32]; seed_len];
|
||||
@@ -205,7 +205,7 @@ impl<D: DataRef> WriterTo for GGSWCiphertextCompressed<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write_u32::<LittleEndian>(self.k.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.base2k.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.digits.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.dsize.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.rank.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.seed.len() as u32)?;
|
||||
for s in &self.seed {
|
||||
@@ -225,9 +225,9 @@ where
|
||||
assert_eq!(self.rank(), other.rank())
|
||||
}
|
||||
|
||||
let rows: usize = self.rows().into();
|
||||
let dnum: usize = self.dnum().into();
|
||||
let rank: usize = self.rank().into();
|
||||
(0..rows).for_each(|row_i| {
|
||||
(0..dnum).for_each(|row_i| {
|
||||
(0..rank + 1).for_each(|col_j| {
|
||||
self.at_mut(row_i, col_j)
|
||||
.decompress(module, &other.at(row_i, col_j));
|
||||
|
||||
@@ -6,8 +6,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
compressed::GGLWESwitchingKeyCompressed,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision, compressed::GGLWESwitchingKeyCompressed,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
@@ -36,21 +35,21 @@ impl<D: Data> GLWEInfos for GLWEToLWESwitchingKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GLWEToLWESwitchingKeyCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GLWEToLWESwitchingKeyCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.0.rank_in()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +86,7 @@ impl<D: DataRef> WriterTo for GLWEToLWESwitchingKeyCompressed<D> {
|
||||
impl GLWEToLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.rank_out().0,
|
||||
@@ -95,28 +94,28 @@ impl GLWEToLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
"rank_out > 1 is unsupported for GLWEToLWESwitchingKeyCompressed"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is unsupported for GLWEToLWESwitchingKeyCompressed"
|
||||
"dsize > 1 is unsupported for GLWEToLWESwitchingKeyCompressed"
|
||||
);
|
||||
Self(GGLWESwitchingKeyCompressed::alloc(infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_in: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self {
|
||||
Self(GGLWESwitchingKeyCompressed::alloc_with(
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
rank_in,
|
||||
Rank(1),
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.rank_out().0,
|
||||
@@ -124,14 +123,14 @@ impl GLWEToLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
"rank_out > 1 is unsupported for GLWEToLWESwitchingKeyCompressed"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is unsupported for GLWEToLWESwitchingKeyCompressed"
|
||||
"dsize > 1 is unsupported for GLWEToLWESwitchingKeyCompressed"
|
||||
);
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_in: Rank) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rows, Digits(1), rank_in, Rank(1))
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_in: Rank) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rank_in, dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GLWEInfos, LWEInfos, LWESwitchingKey, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||
};
|
||||
use std::fmt;
|
||||
@@ -35,9 +35,9 @@ impl<D: Data> GLWEInfos for LWESwitchingKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for LWESwitchingKeyCompressed<D> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
impl<D: Data> GGLWEInfos for LWESwitchingKeyCompressed<D> {
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_in(&self) -> Rank {
|
||||
@@ -48,8 +48,8 @@ impl<D: Data> GGLWELayoutInfos for LWESwitchingKeyCompressed<D> {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ impl<D: DataRef> WriterTo for LWESwitchingKeyCompressed<D> {
|
||||
impl LWESwitchingKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWESwitchingKeyCompressed"
|
||||
"dsize > 1 is not supported for LWESwitchingKeyCompressed"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -106,26 +106,26 @@ impl LWESwitchingKeyCompressed<Vec<u8>> {
|
||||
Self(GGLWESwitchingKeyCompressed::alloc(infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self {
|
||||
Self(GGLWESwitchingKeyCompressed::alloc_with(
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
Rank(1),
|
||||
Rank(1),
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -140,8 +140,8 @@ impl LWESwitchingKeyCompressed<Vec<u8>> {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rows, Digits(1), Rank(1), Rank(1))
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GGLWESwitchingKeyCompressed},
|
||||
};
|
||||
use std::fmt;
|
||||
@@ -35,9 +35,9 @@ impl<D: Data> GLWEInfos for LWEToGLWESwitchingKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for LWEToGLWESwitchingKeyCompressed<D> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
impl<D: Data> GGLWEInfos for LWEToGLWESwitchingKeyCompressed<D> {
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_in(&self) -> Rank {
|
||||
@@ -48,8 +48,8 @@ impl<D: Data> GGLWELayoutInfos for LWEToGLWESwitchingKeyCompressed<D> {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ impl<D: DataRef> WriterTo for LWEToGLWESwitchingKeyCompressed<D> {
|
||||
impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWEToGLWESwitchingKeyCompressed"
|
||||
"dsize > 1 is not supported for LWEToGLWESwitchingKeyCompressed"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -101,21 +101,21 @@ impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
Self(GGLWESwitchingKeyCompressed::alloc(infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_out: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self {
|
||||
Self(GGLWESwitchingKeyCompressed::alloc_with(
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
Rank(1),
|
||||
rank_out,
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -123,15 +123,15 @@ impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
"rank_in > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_out: Rank) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, rows, Digits(1), Rank(1), rank_out)
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize {
|
||||
GGLWESwitchingKeyCompressed::alloc_bytes_with(n, base2k, k, Rank(1), dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWESwitchingKey, GLWECiphertext, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWECiphertext, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
@@ -15,9 +15,9 @@ pub struct GGLWEAutomorphismKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub digits: Digits,
|
||||
pub rank: Rank,
|
||||
pub dnum: Dnum,
|
||||
pub dsize: Dsize,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
@@ -56,7 +56,7 @@ impl<D: Data> GLWEInfos for GGLWEAutomorphismKey<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWEAutomorphismKey<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWEAutomorphismKey<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -65,12 +65,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWEAutomorphismKey<D> {
|
||||
self.key.rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.key.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.key.dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.key.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.key.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,21 +94,21 @@ impl GLWEInfos for GGLWEAutomorphismKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWELayoutInfos for GGLWEAutomorphismKeyLayout {
|
||||
impl GGLWEInfos for GGLWEAutomorphismKeyLayout {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
self.rank
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ impl<D: DataRef> fmt::Display for GGLWEAutomorphismKey<D> {
|
||||
impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
@@ -146,16 +146,16 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
GGLWEAutomorphismKey {
|
||||
key: GGLWESwitchingKey::alloc_with(n, base2k, k, rows, digits, rank, rank),
|
||||
key: GGLWESwitchingKey::alloc_with(n, base2k, k, rank, rank, dnum, dsize),
|
||||
p: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
@@ -165,8 +165,8 @@ impl GGLWEAutomorphismKey<Vec<u8>> {
|
||||
GGLWESwitchingKey::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn bytes_of(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rows, digits, rank, rank)
|
||||
pub fn bytes_of(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rank, rank, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,17 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{Base2K, BuildError, Degree, Digits, GLWECiphertext, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision};
|
||||
use crate::layouts::{Base2K, BuildError, Degree, Dnum, Dsize, GLWECiphertext, GLWEInfos, LWEInfos, Rank, TorusPrecision};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
pub trait GGLWELayoutInfos
|
||||
pub trait GGLWEInfos
|
||||
where
|
||||
Self: GLWEInfos,
|
||||
{
|
||||
fn rows(&self) -> Rows;
|
||||
fn digits(&self) -> Digits;
|
||||
fn dnum(&self) -> Dnum;
|
||||
fn dsize(&self) -> Dsize;
|
||||
fn rank_in(&self) -> Rank;
|
||||
fn rank_out(&self) -> Rank;
|
||||
fn layout(&self) -> GGLWECiphertextLayout {
|
||||
@@ -23,8 +23,8 @@ where
|
||||
k: self.k(),
|
||||
rank_in: self.rank_in(),
|
||||
rank_out: self.rank_out(),
|
||||
digits: self.digits(),
|
||||
rows: self.rows(),
|
||||
dsize: self.dsize(),
|
||||
dnum: self.dnum(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,10 @@ pub struct GGLWECiphertextLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub digits: Digits,
|
||||
pub rank_in: Rank,
|
||||
pub rank_out: Rank,
|
||||
pub dnum: Dnum,
|
||||
pub dsize: Dsize,
|
||||
}
|
||||
|
||||
impl LWEInfos for GGLWECiphertextLayout {
|
||||
@@ -60,21 +60,21 @@ impl GLWEInfos for GGLWECiphertextLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWELayoutInfos for GGLWECiphertextLayout {
|
||||
impl GGLWEInfos for GGLWECiphertextLayout {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank_in
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
self.rank_out
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ pub struct GGLWECiphertext<D: Data> {
|
||||
pub(crate) data: MatZnx<D>,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) digits: Digits,
|
||||
pub(crate) dsize: Dsize,
|
||||
}
|
||||
|
||||
impl<D: Data> LWEInfos for GGLWECiphertext<D> {
|
||||
@@ -110,7 +110,7 @@ impl<D: Data> GLWEInfos for GGLWECiphertext<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWECiphertext<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWECiphertext<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
Rank(self.data.cols_in() as u32)
|
||||
}
|
||||
@@ -119,12 +119,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWECiphertext<D> {
|
||||
Rank(self.data.cols_out() as u32 - 1)
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
Rows(self.data.rows() as u32)
|
||||
fn dnum(&self) -> Dnum {
|
||||
Dnum(self.data.rows() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ pub struct GGLWECiphertextBuilder<D: Data> {
|
||||
data: Option<MatZnx<D>>,
|
||||
base2k: Option<Base2K>,
|
||||
k: Option<TorusPrecision>,
|
||||
digits: Option<Digits>,
|
||||
dsize: Option<Dsize>,
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWECiphertext<D> {
|
||||
@@ -142,7 +142,7 @@ impl<D: Data> GGLWECiphertext<D> {
|
||||
data: None,
|
||||
base2k: None,
|
||||
k: None,
|
||||
digits: None,
|
||||
dsize: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,18 +151,18 @@ impl GGLWECiphertextBuilder<Vec<u8>> {
|
||||
#[inline]
|
||||
pub fn layout<A>(mut self, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.data = Some(MatZnx::alloc(
|
||||
infos.n().into(),
|
||||
infos.rows().into(),
|
||||
infos.dnum().into(),
|
||||
infos.rank_in().into(),
|
||||
(infos.rank_out() + 1).into(),
|
||||
infos.size(),
|
||||
));
|
||||
self.base2k = Some(infos.base2k());
|
||||
self.k = Some(infos.k());
|
||||
self.digits = Some(infos.digits());
|
||||
self.dsize = Some(infos.dsize());
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -185,8 +185,8 @@ impl<D: Data> GGLWECiphertextBuilder<D> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn digits(mut self, digits: Digits) -> Self {
|
||||
self.digits = Some(digits);
|
||||
pub fn dsize(mut self, dsize: Dsize) -> Self {
|
||||
self.dsize = Some(dsize);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -194,13 +194,13 @@ impl<D: Data> GGLWECiphertextBuilder<D> {
|
||||
let data: MatZnx<D> = self.data.ok_or(BuildError::MissingData)?;
|
||||
let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?;
|
||||
let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;
|
||||
let digits: Digits = self.digits.ok_or(BuildError::MissingDigits)?;
|
||||
let dsize: Dsize = self.dsize.ok_or(BuildError::MissingDigits)?;
|
||||
|
||||
if base2k == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
if digits == 0_u32 {
|
||||
if dsize == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ impl<D: Data> GGLWECiphertextBuilder<D> {
|
||||
data,
|
||||
base2k,
|
||||
k,
|
||||
digits,
|
||||
dsize,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -257,10 +257,10 @@ impl<D: DataRef> fmt::Display for GGLWECiphertext<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"(GGLWECiphertext: k={} base2k={} digits={}) {}",
|
||||
"(GGLWECiphertext: k={} base2k={} dsize={}) {}",
|
||||
self.k().0,
|
||||
self.base2k().0,
|
||||
self.digits().0,
|
||||
self.dsize().0,
|
||||
self.data
|
||||
)
|
||||
}
|
||||
@@ -291,16 +291,16 @@ impl<D: DataMut> GGLWECiphertext<D> {
|
||||
impl GGLWECiphertext<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
Self::alloc_with(
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -308,51 +308,51 @@ impl GGLWECiphertext<Vec<u8>> {
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> Self {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid gglwe: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid gglwe: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
Self {
|
||||
data: MatZnx::alloc(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
rank_in.into(),
|
||||
(rank_out + 1).into(),
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
),
|
||||
k,
|
||||
base2k,
|
||||
digits,
|
||||
dsize,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
Self::alloc_bytes_with(
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -360,28 +360,28 @@ impl GGLWECiphertext<Vec<u8>> {
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> usize {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid gglwe: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid gglwe: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
MatZnx::alloc_bytes(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
rank_in.into(),
|
||||
(rank_out + 1).into(),
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
@@ -393,7 +393,7 @@ impl<D: DataMut> ReaderFrom for GGLWECiphertext<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?);
|
||||
self.base2k = Base2K(reader.read_u32::<LittleEndian>()?);
|
||||
self.digits = Digits(reader.read_u32::<LittleEndian>()?);
|
||||
self.dsize = Dsize(reader.read_u32::<LittleEndian>()?);
|
||||
self.data.read_from(reader)
|
||||
}
|
||||
}
|
||||
@@ -402,7 +402,7 @@ impl<D: DataRef> WriterTo for GGLWECiphertext<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write_u32::<LittleEndian>(self.k.0)?;
|
||||
writer.write_u32::<LittleEndian>(self.base2k.0)?;
|
||||
writer.write_u32::<LittleEndian>(self.digits.0)?;
|
||||
writer.write_u32::<LittleEndian>(self.dsize.0)?;
|
||||
self.data.write_to(writer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWECiphertext, GGLWELayoutInfos, GLWECiphertext, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWECiphertext, GGLWEInfos, GLWECiphertext, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
@@ -15,10 +15,10 @@ pub struct GGLWESwitchingKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub digits: Digits,
|
||||
pub rank_in: Rank,
|
||||
pub rank_out: Rank,
|
||||
pub dnum: Dnum,
|
||||
pub dsize: Dsize,
|
||||
}
|
||||
|
||||
impl LWEInfos for GGLWESwitchingKeyLayout {
|
||||
@@ -41,7 +41,7 @@ impl GLWEInfos for GGLWESwitchingKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWELayoutInfos for GGLWESwitchingKeyLayout {
|
||||
impl GGLWEInfos for GGLWESwitchingKeyLayout {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank_in
|
||||
}
|
||||
@@ -50,12 +50,12 @@ impl GGLWELayoutInfos for GGLWESwitchingKeyLayout {
|
||||
self.rank_out
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ impl<D: Data> GLWEInfos for GGLWESwitchingKey<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWESwitchingKey<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWESwitchingKey<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -99,12 +99,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWESwitchingKey<D> {
|
||||
self.key.rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.key.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.key.dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.key.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.key.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ impl<D: DataMut> FillUniform for GGLWESwitchingKey<D> {
|
||||
impl GGLWESwitchingKey<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
GGLWESwitchingKey {
|
||||
key: GGLWECiphertext::alloc(infos),
|
||||
@@ -148,13 +148,13 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> Self {
|
||||
GGLWESwitchingKey {
|
||||
key: GGLWECiphertext::alloc_with(n, base2k, k, rows, digits, rank_in, rank_out),
|
||||
key: GGLWECiphertext::alloc_with(n, base2k, k, rank_in, rank_out, dnum, dsize),
|
||||
sk_in_n: 0,
|
||||
sk_out_n: 0,
|
||||
}
|
||||
@@ -162,7 +162,7 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
GGLWECiphertext::alloc_bytes(infos)
|
||||
}
|
||||
@@ -171,12 +171,12 @@ impl GGLWESwitchingKey<Vec<u8>> {
|
||||
n: Degree,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> usize {
|
||||
GGLWECiphertext::alloc_bytes_with(n, base2k, k, rows, digits, rank_in, rank_out)
|
||||
GGLWECiphertext::alloc_bytes_with(n, base2k, k, rank_in, rank_out, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,7 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
};
|
||||
use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
use std::fmt;
|
||||
@@ -15,9 +13,9 @@ pub struct GGLWETensorKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub digits: Digits,
|
||||
pub rank: Rank,
|
||||
pub dnum: Dnum,
|
||||
pub dsize: Dsize,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
@@ -49,7 +47,7 @@ impl<D: Data> GLWEInfos for GGLWETensorKey<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for GGLWETensorKey<D> {
|
||||
impl<D: Data> GGLWEInfos for GGLWETensorKey<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
@@ -58,12 +56,12 @@ impl<D: Data> GGLWELayoutInfos for GGLWETensorKey<D> {
|
||||
self.keys[0].rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.keys[0].digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.keys[0].dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.keys[0].rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.keys[0].dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,21 +85,21 @@ impl GLWEInfos for GGLWETensorKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWELayoutInfos for GGLWETensorKeyLayout {
|
||||
impl GGLWEInfos for GGLWETensorKeyLayout {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
self.rank
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +130,7 @@ impl<D: DataRef> fmt::Display for GGLWETensorKey<D> {
|
||||
impl GGLWETensorKey<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
@@ -143,13 +141,13 @@ impl GGLWETensorKey<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
let mut keys: Vec<GGLWESwitchingKey<Vec<u8>>> = Vec::new();
|
||||
let pairs: u32 = (((rank.0 + 1) * rank.0) >> 1).max(1);
|
||||
(0..pairs).for_each(|_| {
|
||||
@@ -157,10 +155,10 @@ impl GGLWETensorKey<Vec<u8>> {
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
digits,
|
||||
Rank(1),
|
||||
rank,
|
||||
dnum,
|
||||
dsize,
|
||||
));
|
||||
});
|
||||
Self { keys }
|
||||
@@ -168,7 +166,7 @@ impl GGLWETensorKey<Vec<u8>> {
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
@@ -182,16 +180,16 @@ impl GGLWETensorKey<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
Rank(1),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> usize {
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
let pairs: usize = (((rank.0 + 1) * rank.0) >> 1).max(1) as usize;
|
||||
pairs * GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rows, digits, Rank(1), rank)
|
||||
pairs * GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), rank, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,22 +4,22 @@ use poulpy_hal::{
|
||||
};
|
||||
use std::fmt;
|
||||
|
||||
use crate::layouts::{Base2K, BuildError, Degree, Digits, GLWECiphertext, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision};
|
||||
use crate::layouts::{Base2K, BuildError, Degree, Dnum, Dsize, GLWECiphertext, GLWEInfos, LWEInfos, Rank, TorusPrecision};
|
||||
|
||||
pub trait GGSWInfos
|
||||
where
|
||||
Self: GLWEInfos,
|
||||
{
|
||||
fn rows(&self) -> Rows;
|
||||
fn digits(&self) -> Digits;
|
||||
fn dnum(&self) -> Dnum;
|
||||
fn dsize(&self) -> Dsize;
|
||||
fn layout(&self) -> GGSWCiphertextLayout {
|
||||
GGSWCiphertextLayout {
|
||||
n: self.n(),
|
||||
base2k: self.base2k(),
|
||||
k: self.k(),
|
||||
rank: self.rank(),
|
||||
rows: self.rows(),
|
||||
digits: self.digits(),
|
||||
dnum: self.dnum(),
|
||||
dsize: self.dsize(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ pub struct GGSWCiphertextLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub digits: Digits,
|
||||
pub rank: Rank,
|
||||
pub dnum: Dnum,
|
||||
pub dsize: Dsize,
|
||||
}
|
||||
|
||||
impl LWEInfos for GGSWCiphertextLayout {
|
||||
@@ -54,12 +54,12 @@ impl GLWEInfos for GGSWCiphertextLayout {
|
||||
}
|
||||
|
||||
impl GGSWInfos for GGSWCiphertextLayout {
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ pub struct GGSWCiphertext<D: Data> {
|
||||
pub(crate) data: MatZnx<D>,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) digits: Digits,
|
||||
pub(crate) dsize: Dsize,
|
||||
}
|
||||
|
||||
impl<D: Data> LWEInfos for GGSWCiphertext<D> {
|
||||
@@ -96,12 +96,12 @@ impl<D: Data> GLWEInfos for GGSWCiphertext<D> {
|
||||
}
|
||||
|
||||
impl<D: Data> GGSWInfos for GGSWCiphertext<D> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
Rows(self.data.rows() as u32)
|
||||
fn dnum(&self) -> Dnum {
|
||||
Dnum(self.data.rows() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ pub struct GGSWCiphertextBuilder<D: Data> {
|
||||
data: Option<MatZnx<D>>,
|
||||
base2k: Option<Base2K>,
|
||||
k: Option<TorusPrecision>,
|
||||
digits: Option<Digits>,
|
||||
dsize: Option<Dsize>,
|
||||
}
|
||||
|
||||
impl<D: Data> GGSWCiphertext<D> {
|
||||
@@ -119,7 +119,7 @@ impl<D: Data> GGSWCiphertext<D> {
|
||||
data: None,
|
||||
base2k: None,
|
||||
k: None,
|
||||
digits: None,
|
||||
dsize: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,30 +131,30 @@ impl GGSWCiphertextBuilder<Vec<u8>> {
|
||||
A: GGSWInfos,
|
||||
{
|
||||
debug_assert!(
|
||||
infos.size() as u32 > infos.digits().0,
|
||||
"invalid ggsw: ceil(k/base2k): {} <= digits: {}",
|
||||
infos.size() as u32 > infos.dsize().0,
|
||||
"invalid ggsw: ceil(k/base2k): {} <= dsize: {}",
|
||||
infos.size(),
|
||||
infos.digits()
|
||||
infos.dsize()
|
||||
);
|
||||
|
||||
assert!(
|
||||
infos.rows().0 * infos.digits().0 <= infos.size() as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {}",
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.dnum().0 * infos.dsize().0 <= infos.size() as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {}",
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
infos.size(),
|
||||
);
|
||||
|
||||
self.data = Some(MatZnx::alloc(
|
||||
infos.n().into(),
|
||||
infos.rows().into(),
|
||||
infos.dnum().into(),
|
||||
(infos.rank() + 1).into(),
|
||||
(infos.rank() + 1).into(),
|
||||
infos.size(),
|
||||
));
|
||||
self.base2k = Some(infos.base2k());
|
||||
self.k = Some(infos.k());
|
||||
self.digits = Some(infos.digits());
|
||||
self.dsize = Some(infos.dsize());
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -177,8 +177,8 @@ impl<D: Data> GGSWCiphertextBuilder<D> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn digits(mut self, digits: Digits) -> Self {
|
||||
self.digits = Some(digits);
|
||||
pub fn dsize(mut self, dsize: Dsize) -> Self {
|
||||
self.dsize = Some(dsize);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -186,13 +186,13 @@ impl<D: Data> GGSWCiphertextBuilder<D> {
|
||||
let data: MatZnx<D> = self.data.ok_or(BuildError::MissingData)?;
|
||||
let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?;
|
||||
let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;
|
||||
let digits: Digits = self.digits.ok_or(BuildError::MissingDigits)?;
|
||||
let dsize: Dsize = self.dsize.ok_or(BuildError::MissingDigits)?;
|
||||
|
||||
if base2k == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
if digits == 0_u32 {
|
||||
if dsize == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ impl<D: Data> GGSWCiphertextBuilder<D> {
|
||||
data,
|
||||
base2k,
|
||||
k,
|
||||
digits,
|
||||
dsize,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -231,10 +231,10 @@ impl<D: DataRef> fmt::Display for GGSWCiphertext<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"(GGSWCiphertext: k: {} base2k: {} digits: {}) {}",
|
||||
"(GGSWCiphertext: k: {} base2k: {} dsize: {}) {}",
|
||||
self.k().0,
|
||||
self.base2k().0,
|
||||
self.digits().0,
|
||||
self.dsize().0,
|
||||
self.data
|
||||
)
|
||||
}
|
||||
@@ -277,38 +277,38 @@ impl GGSWCiphertext<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
Self {
|
||||
data: MatZnx::alloc(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
(rank + 1).into(),
|
||||
(rank + 1).into(),
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
),
|
||||
k,
|
||||
base2k,
|
||||
digits,
|
||||
dsize,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,30 +320,30 @@ impl GGSWCiphertext<Vec<u8>> {
|
||||
infos.n(),
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> usize {
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
MatZnx::alloc_bytes(
|
||||
n.into(),
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
(rank + 1).into(),
|
||||
(rank + 1).into(),
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
@@ -357,7 +357,7 @@ impl<D: DataMut> ReaderFrom for GGSWCiphertext<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
self.k = TorusPrecision(reader.read_u32::<LittleEndian>()?);
|
||||
self.base2k = Base2K(reader.read_u32::<LittleEndian>()?);
|
||||
self.digits = Digits(reader.read_u32::<LittleEndian>()?);
|
||||
self.dsize = Dsize(reader.read_u32::<LittleEndian>()?);
|
||||
self.data.read_from(reader)
|
||||
}
|
||||
}
|
||||
@@ -366,7 +366,7 @@ impl<D: DataRef> WriterTo for GGSWCiphertext<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write_u32::<LittleEndian>(self.k.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.base2k.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.digits.into())?;
|
||||
writer.write_u32::<LittleEndian>(self.dsize.into())?;
|
||||
self.data.write_to(writer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,22 +3,20 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
};
|
||||
use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub struct GLWEToLWESwitchingKeyLayout {
|
||||
pub struct GLWEToLWEKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub rank_in: Rank,
|
||||
pub dnum: Dnum,
|
||||
}
|
||||
|
||||
impl LWEInfos for GLWEToLWESwitchingKeyLayout {
|
||||
impl LWEInfos for GLWEToLWEKeyLayout {
|
||||
fn n(&self) -> Degree {
|
||||
self.n
|
||||
}
|
||||
@@ -32,35 +30,35 @@ impl LWEInfos for GLWEToLWESwitchingKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GLWEInfos for GLWEToLWESwitchingKeyLayout {
|
||||
impl GLWEInfos for GLWEToLWEKeyLayout {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWELayoutInfos for GLWEToLWESwitchingKeyLayout {
|
||||
impl GGLWEInfos for GLWEToLWEKeyLayout {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank_in
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
Digits(1)
|
||||
fn dsize(&self) -> Dsize {
|
||||
Dsize(1)
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
Rank(1)
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
/// A special [GLWESwitchingKey] required to for the conversion from [GLWECiphertext] to [LWECiphertext].
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct GLWEToLWESwitchingKey<D: Data>(pub(crate) GGLWESwitchingKey<D>);
|
||||
pub struct GLWEToLWEKey<D: Data>(pub(crate) GGLWESwitchingKey<D>);
|
||||
|
||||
impl<D: Data> LWEInfos for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: Data> LWEInfos for GLWEToLWEKey<D> {
|
||||
fn base2k(&self) -> Base2K {
|
||||
self.0.base2k()
|
||||
}
|
||||
@@ -78,63 +76,63 @@ impl<D: Data> LWEInfos for GLWEToLWESwitchingKey<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GLWEInfos for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: Data> GLWEInfos for GLWEToLWEKey<D> {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
impl<D: Data> GGLWELayoutInfos for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: Data> GGLWEInfos for GLWEToLWEKey<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.0.rank_in()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Debug for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: DataRef> fmt::Debug for GLWEToLWEKey<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> FillUniform for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: DataMut> FillUniform for GLWEToLWEKey<D> {
|
||||
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
||||
self.0.fill_uniform(log_bound, source);
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Display for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: DataRef> fmt::Display for GLWEToLWEKey<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "(GLWEToLWESwitchingKey) {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> ReaderFrom for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: DataMut> ReaderFrom for GLWEToLWEKey<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
self.0.read_from(reader)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> WriterTo for GLWEToLWESwitchingKey<D> {
|
||||
impl<D: DataRef> WriterTo for GLWEToLWEKey<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
self.0.write_to(writer)
|
||||
}
|
||||
}
|
||||
|
||||
impl GLWEToLWESwitchingKey<Vec<u8>> {
|
||||
impl GLWEToLWEKey<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.rank_out().0,
|
||||
@@ -142,28 +140,28 @@ impl GLWEToLWESwitchingKey<Vec<u8>> {
|
||||
"rank_out > 1 is not supported for GLWEToLWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for GLWEToLWESwitchingKey"
|
||||
"dsize > 1 is not supported for GLWEToLWESwitchingKey"
|
||||
);
|
||||
Self(GGLWESwitchingKey::alloc(infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_in: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self {
|
||||
Self(GGLWESwitchingKey::alloc_with(
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
rank_in,
|
||||
Rank(1),
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.rank_out().0,
|
||||
@@ -171,14 +169,14 @@ impl GLWEToLWESwitchingKey<Vec<u8>> {
|
||||
"rank_out > 1 is not supported for GLWEToLWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for GLWEToLWESwitchingKey"
|
||||
"dsize > 1 is not supported for GLWEToLWESwitchingKey"
|
||||
);
|
||||
GGLWESwitchingKey::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_in: Rank) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rows, Digits(1), rank_in, Rank(1))
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rank_in, Rank(1), dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,14 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
};
|
||||
use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision};
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub struct LWESwitchingKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub dnum: Dnum,
|
||||
}
|
||||
|
||||
impl LWEInfos for LWESwitchingKeyLayout {
|
||||
@@ -37,21 +35,21 @@ impl GLWEInfos for LWESwitchingKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWELayoutInfos for LWESwitchingKeyLayout {
|
||||
impl GGLWEInfos for LWESwitchingKeyLayout {
|
||||
fn rank_in(&self) -> Rank {
|
||||
Rank(1)
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
Digits(1)
|
||||
fn dsize(&self) -> Dsize {
|
||||
Dsize(1)
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
Rank(1)
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,9 +80,9 @@ impl<D: Data> GLWEInfos for LWESwitchingKey<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWELayoutInfos for LWESwitchingKey<D> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
impl<D: Data> GGLWEInfos for LWESwitchingKey<D> {
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_in(&self) -> Rank {
|
||||
@@ -95,20 +93,20 @@ impl<D: Data> GGLWELayoutInfos for LWESwitchingKey<D> {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl LWESwitchingKey<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -123,26 +121,26 @@ impl LWESwitchingKey<Vec<u8>> {
|
||||
Self(GGLWESwitchingKey::alloc(infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self {
|
||||
Self(GGLWESwitchingKey::alloc_with(
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
Rank(1),
|
||||
Rank(1),
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -157,8 +155,8 @@ impl LWESwitchingKey<Vec<u8>> {
|
||||
GGLWESwitchingKey::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rows, Digits(1), Rank(1), Rank(1))
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), Rank(1), dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,15 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
};
|
||||
use crate::layouts::{Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision};
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||
pub struct LWEToGLWESwitchingKeyLayout {
|
||||
pub n: Degree,
|
||||
pub base2k: Base2K,
|
||||
pub k: TorusPrecision,
|
||||
pub rows: Rows,
|
||||
pub rank_out: Rank,
|
||||
pub dnum: Dnum,
|
||||
}
|
||||
|
||||
impl LWEInfos for LWEToGLWESwitchingKeyLayout {
|
||||
@@ -38,21 +36,21 @@ impl GLWEInfos for LWEToGLWESwitchingKeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWELayoutInfos for LWEToGLWESwitchingKeyLayout {
|
||||
impl GGLWEInfos for LWEToGLWESwitchingKeyLayout {
|
||||
fn rank_in(&self) -> Rank {
|
||||
Rank(1)
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
Digits(1)
|
||||
fn dsize(&self) -> Dsize {
|
||||
Dsize(1)
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
self.rank_out
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.rows
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.dnum
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,9 +80,9 @@ impl<D: Data> GLWEInfos for LWEToGLWESwitchingKey<D> {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
impl<D: Data> GGLWELayoutInfos for LWEToGLWESwitchingKey<D> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
impl<D: Data> GGLWEInfos for LWEToGLWESwitchingKey<D> {
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_in(&self) -> Rank {
|
||||
@@ -95,8 +93,8 @@ impl<D: Data> GGLWELayoutInfos for LWEToGLWESwitchingKey<D> {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +131,7 @@ impl<D: DataRef> WriterTo for LWEToGLWESwitchingKey<D> {
|
||||
impl LWEToGLWESwitchingKey<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -141,28 +139,28 @@ impl LWEToGLWESwitchingKey<Vec<u8>> {
|
||||
"rank_in > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
Self(GGLWESwitchingKey::alloc(infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_out: Rank) -> Self {
|
||||
pub fn alloc_with(n: Degree, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self {
|
||||
Self(GGLWESwitchingKey::alloc_with(
|
||||
n,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
Rank(1),
|
||||
rank_out,
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -170,14 +168,14 @@ impl LWEToGLWESwitchingKey<Vec<u8>> {
|
||||
"rank_in > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
GGLWESwitchingKey::alloc_bytes(infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_out: Rank) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, rows, Digits(1), Rank(1), rank_out)
|
||||
pub fn alloc_bytes_with(n: Degree, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_out: Rank) -> usize {
|
||||
GGLWESwitchingKey::alloc_bytes_with(n, base2k, k, Rank(1), rank_out, dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,9 +209,9 @@ macro_rules! newtype_u32 {
|
||||
newtype_u32!(Degree);
|
||||
newtype_u32!(TorusPrecision);
|
||||
newtype_u32!(Base2K);
|
||||
newtype_u32!(Rows);
|
||||
newtype_u32!(Dnum);
|
||||
newtype_u32!(Rank);
|
||||
newtype_u32!(Digits);
|
||||
newtype_u32!(Dsize);
|
||||
|
||||
impl Degree {
|
||||
pub fn log2(&self) -> usize {
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWEAutomorphismKey, GGLWELayoutInfos, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEAutomorphismKey, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ impl<D: Data, B: Backend> GLWEInfos for GGLWEAutomorphismKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWEAutomorphismKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GGLWEInfos for GGLWEAutomorphismKeyPrepared<D, B> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -53,19 +53,19 @@ impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWEAutomorphismKeyPrepared<D, B
|
||||
self.key.rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.key.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.key.dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.key.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.key.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GGLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
assert_eq!(
|
||||
@@ -79,19 +79,19 @@ impl<B: Backend> GGLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
GGLWEAutomorphismKeyPrepared {
|
||||
key: GGLWESwitchingKeyPrepared::alloc_with(module, base2k, k, rows, digits, rank, rank),
|
||||
key: GGLWESwitchingKeyPrepared::alloc_with(module, base2k, k, rank, rank, dnum, dsize),
|
||||
p: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
assert_eq!(
|
||||
@@ -102,18 +102,11 @@ impl<B: Backend> GGLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes(module, infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(
|
||||
module: &Module<B>,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank: Rank,
|
||||
) -> usize
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rows, digits, rank, rank)
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rank, rank, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, BuildError, Degree, Digits, GGLWECiphertext, GGLWELayoutInfos, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, BuildError, Degree, Dnum, Dsize, GGLWECiphertext, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct GGLWECiphertextPrepared<D: Data, B: Backend> {
|
||||
pub(crate) data: VmpPMat<D, B>,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) digits: Digits,
|
||||
pub(crate) dsize: Dsize,
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> LWEInfos for GGLWECiphertextPrepared<D, B> {
|
||||
@@ -41,7 +41,7 @@ impl<D: Data, B: Backend> GLWEInfos for GGLWECiphertextPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWECiphertextPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GGLWEInfos for GGLWECiphertextPrepared<D, B> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
Rank(self.data.cols_in() as u32)
|
||||
}
|
||||
@@ -50,12 +50,12 @@ impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWECiphertextPrepared<D, B> {
|
||||
Rank(self.data.cols_out() as u32 - 1)
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
Rows(self.data.rows() as u32)
|
||||
fn dnum(&self) -> Dnum {
|
||||
Dnum(self.data.rows() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ pub struct GGLWECiphertextPreparedBuilder<D: Data, B: Backend> {
|
||||
data: Option<VmpPMat<D, B>>,
|
||||
base2k: Option<Base2K>,
|
||||
k: Option<TorusPrecision>,
|
||||
digits: Option<Digits>,
|
||||
dsize: Option<Dsize>,
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWECiphertextPrepared<D, B> {
|
||||
@@ -73,7 +73,7 @@ impl<D: Data, B: Backend> GGLWECiphertextPrepared<D, B> {
|
||||
data: None,
|
||||
base2k: None,
|
||||
k: None,
|
||||
digits: None,
|
||||
dsize: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,19 +82,19 @@ impl<B: Backend> GGLWECiphertextPreparedBuilder<Vec<u8>, B> {
|
||||
#[inline]
|
||||
pub fn layout<A>(mut self, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
B: VmpPMatAllocBytesImpl<B>,
|
||||
{
|
||||
self.data = Some(VmpPMat::alloc(
|
||||
infos.n().into(),
|
||||
infos.rows().into(),
|
||||
infos.dnum().into(),
|
||||
infos.rank_in().into(),
|
||||
(infos.rank_out() + 1).into(),
|
||||
infos.size(),
|
||||
));
|
||||
self.base2k = Some(infos.base2k());
|
||||
self.k = Some(infos.k());
|
||||
self.digits = Some(infos.digits());
|
||||
self.dsize = Some(infos.dsize());
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -117,8 +117,8 @@ impl<D: Data, B: Backend> GGLWECiphertextPreparedBuilder<D, B> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn digits(mut self, digits: Digits) -> Self {
|
||||
self.digits = Some(digits);
|
||||
pub fn dsize(mut self, dsize: Dsize) -> Self {
|
||||
self.dsize = Some(dsize);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -126,13 +126,13 @@ impl<D: Data, B: Backend> GGLWECiphertextPreparedBuilder<D, B> {
|
||||
let data: VmpPMat<D, B> = self.data.ok_or(BuildError::MissingData)?;
|
||||
let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?;
|
||||
let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;
|
||||
let digits: Digits = self.digits.ok_or(BuildError::MissingDigits)?;
|
||||
let dsize: Dsize = self.dsize.ok_or(BuildError::MissingDigits)?;
|
||||
|
||||
if base2k == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
if digits == 0_u32 {
|
||||
if dsize == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ impl<D: Data, B: Backend> GGLWECiphertextPreparedBuilder<D, B> {
|
||||
data,
|
||||
base2k,
|
||||
k,
|
||||
digits,
|
||||
dsize,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -164,7 +164,7 @@ impl<D: Data, B: Backend> GGLWECiphertextPreparedBuilder<D, B> {
|
||||
impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> {
|
||||
pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
debug_assert_eq!(module.n(), infos.n().0 as usize, "module.n() != infos.n()");
|
||||
@@ -172,10 +172,10 @@ impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -183,39 +183,39 @@ impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> {
|
||||
module: &Module<B>,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid gglwe: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid gglwe: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
Self {
|
||||
data: module.vmp_pmat_alloc(rows.into(), rank_in.into(), (rank_out + 1).into(), size),
|
||||
data: module.vmp_pmat_alloc(dnum.into(), rank_in.into(), (rank_out + 1).into(), size),
|
||||
k,
|
||||
base2k,
|
||||
digits,
|
||||
dsize,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
debug_assert_eq!(module.n(), infos.n().0 as usize, "module.n() != infos.n()");
|
||||
@@ -223,10 +223,10 @@ impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -234,29 +234,29 @@ impl<B: Backend> GGLWECiphertextPrepared<Vec<u8>, B> {
|
||||
module: &Module<B>,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid gglwe: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid gglwe: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid gglwe: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
module.vmp_pmat_alloc_bytes(rows.into(), rank_in.into(), (rank_out + 1).into(), size)
|
||||
module.vmp_pmat_alloc_bytes(dnum.into(), rank_in.into(), (rank_out + 1).into(), size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ where
|
||||
module.vmp_prepare(&mut self.data, &other.data, scratch);
|
||||
self.k = other.k;
|
||||
self.base2k = other.base2k;
|
||||
self.digits = other.digits;
|
||||
self.dsize = other.dsize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GGLWECiphertextPrepared, Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -39,7 +39,7 @@ impl<D: Data, B: Backend> GLWEInfos for GGLWESwitchingKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWESwitchingKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GGLWEInfos for GGLWESwitchingKeyPrepared<D, B> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -48,19 +48,19 @@ impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWESwitchingKeyPrepared<D, B> {
|
||||
self.key.rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.key.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.key.dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.key.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.key.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
debug_assert_eq!(module.n() as u32, infos.n(), "module.n() != infos.n()");
|
||||
@@ -75,16 +75,16 @@ impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
module: &Module<B>,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
GGLWESwitchingKeyPrepared::<Vec<u8>, B> {
|
||||
key: GGLWECiphertextPrepared::alloc_with(module, base2k, k, rows, digits, rank_in, rank_out),
|
||||
key: GGLWECiphertextPrepared::alloc_with(module, base2k, k, rank_in, rank_out, dnum, dsize),
|
||||
sk_in_n: 0,
|
||||
sk_out_n: 0,
|
||||
}
|
||||
@@ -92,7 +92,7 @@ impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
|
||||
pub fn alloc_bytes<A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
debug_assert_eq!(module.n() as u32, infos.n(), "module.n() != infos.n()");
|
||||
@@ -103,15 +103,15 @@ impl<B: Backend> GGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
module: &Module<B>,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank_in: Rank,
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
GGLWECiphertextPrepared::alloc_bytes_with(module, base2k, k, rows, digits, rank_in, rank_out)
|
||||
GGLWECiphertextPrepared::alloc_bytes_with(module, base2k, k, rank_in, rank_out, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GGLWETensorKey, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWETensorKey, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ impl<D: Data, B: Backend> GLWEInfos for GGLWETensorKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWETensorKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GGLWEInfos for GGLWETensorKeyPrepared<D, B> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
@@ -46,19 +46,19 @@ impl<D: Data, B: Backend> GGLWELayoutInfos for GGLWETensorKeyPrepared<D, B> {
|
||||
self.keys[0].rank_out()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.keys[0].digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.keys[0].dsize()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.keys[0].rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.keys[0].dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GGLWETensorKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
assert_eq!(
|
||||
@@ -70,13 +70,13 @@ impl<B: Backend> GGLWETensorKeyPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
infos.rank_out(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
@@ -87,10 +87,10 @@ impl<B: Backend> GGLWETensorKeyPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
digits,
|
||||
Rank(1),
|
||||
rank,
|
||||
dnum,
|
||||
dsize,
|
||||
));
|
||||
});
|
||||
Self { keys }
|
||||
@@ -98,7 +98,7 @@ impl<B: Backend> GGLWETensorKeyPrepared<Vec<u8>, B> {
|
||||
|
||||
pub fn alloc_bytes<A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
assert_eq!(
|
||||
@@ -113,26 +113,19 @@ impl<B: Backend> GGLWETensorKeyPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
Rank(1),
|
||||
infos.rank_out(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(
|
||||
module: &Module<B>,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank: Rank,
|
||||
) -> usize
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
let pairs: usize = (((rank.0 + 1) * rank.0) >> 1).max(1) as usize;
|
||||
pairs * GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rows, digits, Rank(1), rank)
|
||||
pairs * GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), rank, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use poulpy_hal::{
|
||||
api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare},
|
||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat, ZnxInfos},
|
||||
layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat, VmpPMatToRef, ZnxInfos},
|
||||
oep::VmpPMatAllocBytesImpl,
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, BuildError, Degree, Digits, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, BuildError, Degree, Dnum, Dsize, GGSWCiphertext, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct GGSWCiphertextPrepared<D: Data, B: Backend> {
|
||||
pub(crate) data: VmpPMat<D, B>,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) digits: Digits,
|
||||
pub(crate) dsize: Dsize,
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> LWEInfos for GGSWCiphertextPrepared<D, B> {
|
||||
@@ -42,12 +42,12 @@ impl<D: Data, B: Backend> GLWEInfos for GGSWCiphertextPrepared<D, B> {
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGSWInfos for GGSWCiphertextPrepared<D, B> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.digits
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.dsize
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
Rows(self.data.rows() as u32)
|
||||
fn dnum(&self) -> Dnum {
|
||||
Dnum(self.data.rows() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ pub struct GGSWCiphertextPreparedBuilder<D: Data, B: Backend> {
|
||||
data: Option<VmpPMat<D, B>>,
|
||||
base2k: Option<Base2K>,
|
||||
k: Option<TorusPrecision>,
|
||||
digits: Option<Digits>,
|
||||
dsize: Option<Dsize>,
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGSWCiphertextPrepared<D, B> {
|
||||
@@ -65,7 +65,7 @@ impl<D: Data, B: Backend> GGSWCiphertextPrepared<D, B> {
|
||||
data: None,
|
||||
base2k: None,
|
||||
k: None,
|
||||
digits: None,
|
||||
dsize: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,30 +78,30 @@ impl<B: Backend> GGSWCiphertextPreparedBuilder<Vec<u8>, B> {
|
||||
B: VmpPMatAllocBytesImpl<B>,
|
||||
{
|
||||
debug_assert!(
|
||||
infos.size() as u32 > infos.digits().0,
|
||||
"invalid ggsw: ceil(k/base2k): {} <= digits: {}",
|
||||
infos.size() as u32 > infos.dsize().0,
|
||||
"invalid ggsw: ceil(k/base2k): {} <= dsize: {}",
|
||||
infos.size(),
|
||||
infos.digits()
|
||||
infos.dsize()
|
||||
);
|
||||
|
||||
assert!(
|
||||
infos.rows().0 * infos.digits().0 <= infos.size() as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {}",
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.dnum().0 * infos.dsize().0 <= infos.size() as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {}",
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
infos.size(),
|
||||
);
|
||||
|
||||
self.data = Some(VmpPMat::alloc(
|
||||
infos.n().into(),
|
||||
infos.rows().into(),
|
||||
infos.dnum().into(),
|
||||
(infos.rank() + 1).into(),
|
||||
(infos.rank() + 1).into(),
|
||||
infos.size(),
|
||||
));
|
||||
self.base2k = Some(infos.base2k());
|
||||
self.k = Some(infos.k());
|
||||
self.digits = Some(infos.digits());
|
||||
self.dsize = Some(infos.dsize());
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -124,8 +124,8 @@ impl<D: Data, B: Backend> GGSWCiphertextPreparedBuilder<D, B> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn digits(mut self, digits: Digits) -> Self {
|
||||
self.digits = Some(digits);
|
||||
pub fn dsize(mut self, dsize: Dsize) -> Self {
|
||||
self.dsize = Some(dsize);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -133,13 +133,13 @@ impl<D: Data, B: Backend> GGSWCiphertextPreparedBuilder<D, B> {
|
||||
let data: VmpPMat<D, B> = self.data.ok_or(BuildError::MissingData)?;
|
||||
let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?;
|
||||
let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;
|
||||
let digits: Digits = self.digits.ok_or(BuildError::MissingDigits)?;
|
||||
let dsize: Dsize = self.dsize.ok_or(BuildError::MissingDigits)?;
|
||||
|
||||
if base2k == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
if digits == 0_u32 {
|
||||
if dsize == 0_u32 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ impl<D: Data, B: Backend> GGSWCiphertextPreparedBuilder<D, B> {
|
||||
data,
|
||||
base2k,
|
||||
k,
|
||||
digits,
|
||||
dsize,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -178,40 +178,40 @@ impl<B: Backend> GGSWCiphertextPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
infos.rank(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows, digits: Digits, rank: Rank) -> Self
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
Self {
|
||||
data: module.vmp_pmat_alloc(
|
||||
rows.into(),
|
||||
dnum.into(),
|
||||
(rank + 1).into(),
|
||||
(rank + 1).into(),
|
||||
k.0.div_ceil(base2k.0) as usize,
|
||||
),
|
||||
k,
|
||||
base2k,
|
||||
digits,
|
||||
dsize,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,38 +224,31 @@ impl<B: Backend> GGSWCiphertextPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
infos.rows(),
|
||||
infos.digits(),
|
||||
infos.dnum(),
|
||||
infos.dsize(),
|
||||
infos.rank(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(
|
||||
module: &Module<B>,
|
||||
base2k: Base2K,
|
||||
k: TorusPrecision,
|
||||
rows: Rows,
|
||||
digits: Digits,
|
||||
rank: Rank,
|
||||
) -> usize
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > digits.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= digits: {}",
|
||||
digits.0
|
||||
size as u32 > dsize.0,
|
||||
"invalid ggsw: ceil(k/base2k): {size} <= dsize: {}",
|
||||
dsize.0
|
||||
);
|
||||
|
||||
assert!(
|
||||
rows.0 * digits.0 <= size as u32,
|
||||
"invalid ggsw: rows: {} * digits:{} > ceil(k/base2k): {size}",
|
||||
rows.0,
|
||||
digits.0,
|
||||
dnum.0 * dsize.0 <= size as u32,
|
||||
"invalid ggsw: dnum: {} * dsize:{} > ceil(k/base2k): {size}",
|
||||
dnum.0,
|
||||
dsize.0,
|
||||
);
|
||||
|
||||
module.vmp_pmat_alloc_bytes(rows.into(), (rank + 1).into(), (rank + 1).into(), size)
|
||||
module.vmp_pmat_alloc_bytes(dnum.into(), (rank + 1).into(), (rank + 1).into(), size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +266,7 @@ where
|
||||
module.vmp_prepare(&mut self.data, &other.data, scratch);
|
||||
self.k = other.k;
|
||||
self.base2k = other.base2k;
|
||||
self.digits = other.digits;
|
||||
self.dsize = other.dsize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,3 +280,19 @@ where
|
||||
ggsw_prepared
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GGSWCiphertextPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> GGSWCiphertextPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> GGSWCiphertextPreparedToRef<B> for GGSWCiphertextPrepared<D, B> {
|
||||
fn to_ref(&self) -> GGSWCiphertextPrepared<&[u8], B> {
|
||||
GGSWCiphertextPrepared::builder()
|
||||
.base2k(self.base2k())
|
||||
.dsize(self.dsize())
|
||||
.k(self.k())
|
||||
.data(self.data.to_ref())
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GLWEInfos, GLWEToLWESwitchingKey, LWEInfos, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWEKey, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -35,28 +35,28 @@ impl<D: Data, B: Backend> GLWEInfos for GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWELayoutInfos for GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GGLWEInfos for GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.0.rank_in()
|
||||
}
|
||||
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_out(&self) -> Rank {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
@@ -65,14 +65,14 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
"rank_out > 1 is not supported for GLWEToLWESwitchingKeyPrepared"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for GLWEToLWESwitchingKeyPrepared"
|
||||
"dsize > 1 is not supported for GLWEToLWESwitchingKeyPrepared"
|
||||
);
|
||||
Self(GGLWESwitchingKeyPrepared::alloc(module, infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_in: Rank) -> Self
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
@@ -80,16 +80,16 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
rank_in,
|
||||
Rank(1),
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
@@ -98,22 +98,22 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
"rank_out > 1 is not supported for GLWEToLWESwitchingKeyPrepared"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for GLWEToLWESwitchingKeyPrepared"
|
||||
"dsize > 1 is not supported for GLWEToLWESwitchingKeyPrepared"
|
||||
);
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes(module, infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_in: Rank) -> usize
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rows, Digits(1), rank_in, Rank(1))
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rank_in, Rank(1), dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWEToLWESwitchingKeyPrepared<Vec<u8>, B>> for GLWEToLWESwitchingKey<D>
|
||||
impl<D: DataRef, B: Backend> PrepareAlloc<B, GLWEToLWESwitchingKeyPrepared<Vec<u8>, B>> for GLWEToLWEKey<D>
|
||||
where
|
||||
Module<B>: VmpPrepare<B> + VmpPMatAlloc<B>,
|
||||
{
|
||||
@@ -124,11 +124,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, GLWEToLWESwitchingKey<DR>> for GLWEToLWESwitchingKeyPrepared<DM, B>
|
||||
impl<DM: DataMut, DR: DataRef, B: Backend> Prepare<B, GLWEToLWEKey<DR>> for GLWEToLWESwitchingKeyPrepared<DM, B>
|
||||
where
|
||||
Module<B>: VmpPrepare<B>,
|
||||
{
|
||||
fn prepare(&mut self, module: &Module<B>, other: &GLWEToLWESwitchingKey<DR>, scratch: &mut Scratch<B>) {
|
||||
fn prepare(&mut self, module: &Module<B>, other: &GLWEToLWEKey<DR>, scratch: &mut Scratch<B>) {
|
||||
self.0.prepare(module, &other.0, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GLWEInfos, LWEInfos, LWESwitchingKey, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKey, Rank, TorusPrecision,
|
||||
prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -34,9 +34,9 @@ impl<D: Data, B: Backend> GLWEInfos for LWESwitchingKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWELayoutInfos for LWESwitchingKeyPrepared<D, B> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
impl<D: Data, B: Backend> GGLWEInfos for LWESwitchingKeyPrepared<D, B> {
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_in(&self) -> Rank {
|
||||
@@ -47,21 +47,21 @@ impl<D: Data, B: Backend> GGLWELayoutInfos for LWESwitchingKeyPrepared<D, B> {
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -76,7 +76,7 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
Self(GGLWESwitchingKeyPrepared::alloc(module, infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows) -> Self
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
@@ -84,22 +84,22 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
Rank(1),
|
||||
Rank(1),
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.rank_in().0,
|
||||
@@ -114,11 +114,11 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes(module, infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows) -> usize
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rows, Digits(1), Rank(1), Rank(1))
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), Rank(1), dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Digits, GGLWELayoutInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, Rank, Rows, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKey, Rank, TorusPrecision,
|
||||
prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc},
|
||||
};
|
||||
|
||||
@@ -36,9 +36,9 @@ impl<D: Data, B: Backend> GLWEInfos for LWEToGLWESwitchingKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWELayoutInfos for LWEToGLWESwitchingKeyPrepared<D, B> {
|
||||
fn digits(&self) -> Digits {
|
||||
self.0.digits()
|
||||
impl<D: Data, B: Backend> GGLWEInfos for LWEToGLWESwitchingKeyPrepared<D, B> {
|
||||
fn dsize(&self) -> Dsize {
|
||||
self.0.dsize()
|
||||
}
|
||||
|
||||
fn rank_in(&self) -> Rank {
|
||||
@@ -49,15 +49,15 @@ impl<D: Data, B: Backend> GGLWELayoutInfos for LWEToGLWESwitchingKeyPrepared<D,
|
||||
self.0.rank_out()
|
||||
}
|
||||
|
||||
fn rows(&self) -> Rows {
|
||||
self.0.rows()
|
||||
fn dnum(&self) -> Dnum {
|
||||
self.0.dnum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc<A>(module: &Module<B>, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
@@ -66,14 +66,14 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
"rank_in > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
Self(GGLWESwitchingKeyPrepared::alloc(module, infos))
|
||||
}
|
||||
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_out: Rank) -> Self
|
||||
pub fn alloc_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self
|
||||
where
|
||||
Module<B>: VmpPMatAlloc<B>,
|
||||
{
|
||||
@@ -81,16 +81,16 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
module,
|
||||
base2k,
|
||||
k,
|
||||
rows,
|
||||
Digits(1),
|
||||
Rank(1),
|
||||
rank_out,
|
||||
dnum,
|
||||
Dsize(1),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn alloc_bytes<A>(module: &Module<B>, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWELayoutInfos,
|
||||
A: GGLWEInfos,
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
debug_assert_eq!(
|
||||
@@ -99,18 +99,18 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
"rank_in > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
debug_assert_eq!(
|
||||
infos.digits().0,
|
||||
infos.dsize().0,
|
||||
1,
|
||||
"digits > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
"dsize > 1 is not supported for LWEToGLWESwitchingKey"
|
||||
);
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes(module, infos)
|
||||
}
|
||||
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, rows: Rows, rank_out: Rank) -> usize
|
||||
pub fn alloc_bytes_with(module: &Module<B>, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_out: Rank) -> usize
|
||||
where
|
||||
Module<B>: VmpPMatAllocBytes,
|
||||
{
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, rows, Digits(1), Rank(1), rank_out)
|
||||
GGLWESwitchingKeyPrepared::alloc_bytes_with(module, base2k, k, Rank(1), rank_out, dnum, Dsize(1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user