mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
Traits reduction, file + structs renaming
This commit is contained in:
@@ -5,26 +5,25 @@ use poulpy_hal::{
|
||||
|
||||
use crate::layouts::{
|
||||
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWECompressed, GGLWECompressedSeedMut, GGLWECompressedToMut,
|
||||
GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWECompressed, GLWECompressedToMut, GLWECompressedToRef,
|
||||
GLWEDecompress, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement},
|
||||
GGLWECompressedToRef, GGLWEDecompress, GGLWEInfos, GGLWEToMut, GLWEDecompress, GLWEInfos, GetGaloisElement, LWEInfos, Rank,
|
||||
SetGaloisElement, TorusPrecision,
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct AutomorphismKeyCompressed<D: Data> {
|
||||
pub struct GLWEAutomorphismKeyCompressed<D: Data> {
|
||||
pub(crate) key: GGLWECompressed<D>,
|
||||
pub(crate) p: i64,
|
||||
}
|
||||
|
||||
impl<D: Data> GetAutomorphismGaloisElement for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataRef> GetGaloisElement for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn p(&self) -> i64 {
|
||||
self.p
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> {
|
||||
impl<D: Data> LWEInfos for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn n(&self) -> Degree {
|
||||
self.key.n()
|
||||
}
|
||||
@@ -42,13 +41,13 @@ impl<D: Data> LWEInfos for AutomorphismKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GLWEInfos for AutomorphismKeyCompressed<D> {
|
||||
impl<D: Data> GLWEInfos for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWEInfos for AutomorphismKeyCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -66,25 +65,25 @@ impl<D: Data> GGLWEInfos for AutomorphismKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Debug for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataRef> fmt::Debug for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> FillUniform for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataMut> FillUniform for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
||||
self.key.fill_uniform(log_bound, source);
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Display for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataRef> fmt::Display for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "(AutomorphismKeyCompressed: p={}) {}", self.p, self.key)
|
||||
}
|
||||
}
|
||||
|
||||
impl AutomorphismKeyCompressed<Vec<u8>> {
|
||||
impl GLWEAutomorphismKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc_from_infos<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
@@ -100,7 +99,7 @@ impl AutomorphismKeyCompressed<Vec<u8>> {
|
||||
}
|
||||
|
||||
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
AutomorphismKeyCompressed {
|
||||
GLWEAutomorphismKeyCompressed {
|
||||
key: GGLWECompressed::alloc(n, base2k, k, rank, rank, dnum, dsize),
|
||||
p: 0,
|
||||
}
|
||||
@@ -125,14 +124,14 @@ impl AutomorphismKeyCompressed<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> ReaderFrom for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataMut> ReaderFrom for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
self.p = reader.read_u64::<LittleEndian>()? as i64;
|
||||
self.key.read_from(reader)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> WriterTo for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataRef> WriterTo for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write_u64::<LittleEndian>(self.p as u64)?;
|
||||
self.key.write_to(writer)
|
||||
@@ -145,8 +144,8 @@ where
|
||||
{
|
||||
fn decompress_automorphism_key<R, O>(&self, res: &mut R, other: &O)
|
||||
where
|
||||
R: GGLWEToMut + SetAutomorphismGaloisElement,
|
||||
O: GGLWECompressedToRef + GetAutomorphismGaloisElement,
|
||||
R: GGLWEToMut + SetGaloisElement,
|
||||
O: GGLWECompressedToRef + GetGaloisElement,
|
||||
{
|
||||
self.decompress_gglwe(res, other);
|
||||
res.set_p(other.p());
|
||||
@@ -157,68 +156,36 @@ impl<B: Backend> AutomorphismKeyDecompress for Module<B> where Self: GLWEDecompr
|
||||
|
||||
impl<D: DataMut> AutomorphismKey<D>
|
||||
where
|
||||
Self: SetAutomorphismGaloisElement,
|
||||
Self: SetGaloisElement,
|
||||
{
|
||||
pub fn decompress<O, M>(&mut self, module: &M, other: &O)
|
||||
where
|
||||
O: GGLWECompressedToRef + GetAutomorphismGaloisElement,
|
||||
O: GGLWECompressedToRef + GetGaloisElement,
|
||||
M: AutomorphismKeyDecompress,
|
||||
{
|
||||
module.decompress_automorphism_key(self, other);
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> GGLWECompressedToRef for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataRef> GGLWECompressedToRef for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn to_ref(&self) -> GGLWECompressed<&[u8]> {
|
||||
self.key.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> GGLWECompressedToMut for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataMut> GGLWECompressedToMut for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn to_mut(&mut self) -> GGLWECompressed<&mut [u8]> {
|
||||
self.key.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AutomorphismKeyCompressedToRef {
|
||||
fn to_ref(&self) -> AutomorphismKeyCompressed<&[u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataRef> AutomorphismKeyCompressedToRef for AutomorphismKeyCompressed<D>
|
||||
where
|
||||
GLWECompressed<D>: GLWECompressedToRef,
|
||||
{
|
||||
fn to_ref(&self) -> AutomorphismKeyCompressed<&[u8]> {
|
||||
AutomorphismKeyCompressed {
|
||||
key: self.key.to_ref(),
|
||||
p: self.p,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AutomorphismKeyCompressedToMut {
|
||||
fn to_mut(&mut self) -> AutomorphismKeyCompressed<&mut [u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> AutomorphismKeyCompressedToMut for AutomorphismKeyCompressed<D>
|
||||
where
|
||||
GLWECompressed<D>: GLWECompressedToMut,
|
||||
{
|
||||
fn to_mut(&mut self) -> AutomorphismKeyCompressed<&mut [u8]> {
|
||||
AutomorphismKeyCompressed {
|
||||
p: self.p,
|
||||
key: self.key.to_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> GGLWECompressedSeedMut for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataMut> GGLWECompressedSeedMut for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn seed_mut(&mut self) -> &mut Vec<[u8; 32]> {
|
||||
&mut self.key.seed
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> SetAutomorphismGaloisElement for AutomorphismKeyCompressed<D> {
|
||||
impl<D: DataMut> SetGaloisElement for GLWEAutomorphismKeyCompressed<D> {
|
||||
fn set_p(&mut self, p: i64) {
|
||||
self.p = p
|
||||
}
|
||||
@@ -11,11 +11,11 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct TensorKeyCompressed<D: Data> {
|
||||
pub struct GLWETensorKeyCompressed<D: Data> {
|
||||
pub(crate) keys: Vec<GGLWECompressed<D>>,
|
||||
}
|
||||
|
||||
impl<D: Data> LWEInfos for TensorKeyCompressed<D> {
|
||||
impl<D: Data> LWEInfos for GLWETensorKeyCompressed<D> {
|
||||
fn n(&self) -> Degree {
|
||||
self.keys[0].n()
|
||||
}
|
||||
@@ -31,13 +31,13 @@ impl<D: Data> LWEInfos for TensorKeyCompressed<D> {
|
||||
self.keys[0].size()
|
||||
}
|
||||
}
|
||||
impl<D: Data> GLWEInfos for TensorKeyCompressed<D> {
|
||||
impl<D: Data> GLWEInfos for GLWETensorKeyCompressed<D> {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWEInfos for TensorKeyCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GLWETensorKeyCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
@@ -55,13 +55,13 @@ impl<D: Data> GGLWEInfos for TensorKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Debug for TensorKeyCompressed<D> {
|
||||
impl<D: DataRef> fmt::Debug for GLWETensorKeyCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> FillUniform for TensorKeyCompressed<D> {
|
||||
impl<D: DataMut> FillUniform for GLWETensorKeyCompressed<D> {
|
||||
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
||||
self.keys
|
||||
.iter_mut()
|
||||
@@ -69,7 +69,7 @@ impl<D: DataMut> FillUniform for TensorKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Display for TensorKeyCompressed<D> {
|
||||
impl<D: DataRef> fmt::Display for GLWETensorKeyCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f, "(GLWETensorKeyCompressed)",)?;
|
||||
for (i, key) in self.keys.iter().enumerate() {
|
||||
@@ -79,7 +79,7 @@ impl<D: DataRef> fmt::Display for TensorKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl TensorKeyCompressed<Vec<u8>> {
|
||||
impl GLWETensorKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc_from_infos<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
@@ -96,7 +96,7 @@ impl TensorKeyCompressed<Vec<u8>> {
|
||||
|
||||
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self {
|
||||
let pairs: u32 = (((rank.as_u32() + 1) * rank.as_u32()) >> 1).max(1);
|
||||
TensorKeyCompressed {
|
||||
GLWETensorKeyCompressed {
|
||||
keys: (0..pairs)
|
||||
.map(|_| GGLWECompressed::alloc(n, base2k, k, Rank(1), rank, dnum, dsize))
|
||||
.collect(),
|
||||
@@ -123,7 +123,7 @@ impl TensorKeyCompressed<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> ReaderFrom for TensorKeyCompressed<D> {
|
||||
impl<D: DataMut> ReaderFrom for GLWETensorKeyCompressed<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
let len: usize = reader.read_u64::<LittleEndian>()? as usize;
|
||||
if self.keys.len() != len {
|
||||
@@ -139,7 +139,7 @@ impl<D: DataMut> ReaderFrom for TensorKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> WriterTo for TensorKeyCompressed<D> {
|
||||
impl<D: DataRef> WriterTo for GLWETensorKeyCompressed<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write_u64::<LittleEndian>(self.keys.len() as u64)?;
|
||||
for key in &self.keys {
|
||||
@@ -153,7 +153,7 @@ pub trait TensorKeyCompressedAtRef<D: DataRef> {
|
||||
fn at(&self, i: usize, j: usize) -> &GGLWECompressed<D>;
|
||||
}
|
||||
|
||||
impl<D: DataRef> TensorKeyCompressedAtRef<D> for TensorKeyCompressed<D> {
|
||||
impl<D: DataRef> TensorKeyCompressedAtRef<D> for GLWETensorKeyCompressed<D> {
|
||||
fn at(&self, mut i: usize, mut j: usize) -> &GGLWECompressed<D> {
|
||||
if i > j {
|
||||
std::mem::swap(&mut i, &mut j);
|
||||
@@ -167,7 +167,7 @@ pub trait TensorKeyCompressedAtMut<D: DataMut> {
|
||||
fn at_mut(&mut self, i: usize, j: usize) -> &mut GGLWECompressed<D>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> TensorKeyCompressedAtMut<D> for TensorKeyCompressed<D> {
|
||||
impl<D: DataMut> TensorKeyCompressedAtMut<D> for GLWETensorKeyCompressed<D> {
|
||||
fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWECompressed<D> {
|
||||
if i > j {
|
||||
std::mem::swap(&mut i, &mut j);
|
||||
@@ -187,7 +187,7 @@ where
|
||||
O: TensorKeyCompressedToRef,
|
||||
{
|
||||
let res: &mut TensorKey<&mut [u8]> = &mut res.to_mut();
|
||||
let other: &TensorKeyCompressed<&[u8]> = &other.to_ref();
|
||||
let other: &GLWETensorKeyCompressed<&[u8]> = &other.to_ref();
|
||||
|
||||
assert_eq!(
|
||||
res.keys.len(),
|
||||
@@ -216,30 +216,30 @@ impl<D: DataMut> TensorKey<D> {
|
||||
}
|
||||
|
||||
pub trait TensorKeyCompressedToMut {
|
||||
fn to_mut(&mut self) -> TensorKeyCompressed<&mut [u8]>;
|
||||
fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> TensorKeyCompressedToMut for TensorKeyCompressed<D>
|
||||
impl<D: DataMut> TensorKeyCompressedToMut for GLWETensorKeyCompressed<D>
|
||||
where
|
||||
GGLWECompressed<D>: GGLWECompressedToMut,
|
||||
{
|
||||
fn to_mut(&mut self) -> TensorKeyCompressed<&mut [u8]> {
|
||||
TensorKeyCompressed {
|
||||
fn to_mut(&mut self) -> GLWETensorKeyCompressed<&mut [u8]> {
|
||||
GLWETensorKeyCompressed {
|
||||
keys: self.keys.iter_mut().map(|c| c.to_mut()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyCompressedToRef {
|
||||
fn to_ref(&self) -> TensorKeyCompressed<&[u8]>;
|
||||
fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataRef> TensorKeyCompressedToRef for TensorKeyCompressed<D>
|
||||
impl<D: DataRef> TensorKeyCompressedToRef for GLWETensorKeyCompressed<D>
|
||||
where
|
||||
GGLWECompressed<D>: GGLWECompressedToRef,
|
||||
{
|
||||
fn to_ref(&self) -> TensorKeyCompressed<&[u8]> {
|
||||
TensorKeyCompressed {
|
||||
fn to_ref(&self) -> GLWETensorKeyCompressed<&[u8]> {
|
||||
GLWETensorKeyCompressed {
|
||||
keys: self.keys.iter().map(|c| c.to_ref()).collect(),
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
mod gglwe_atk;
|
||||
mod gglwe_ct;
|
||||
mod gglwe_ksk;
|
||||
mod gglwe_tsk;
|
||||
mod ggsw_ct;
|
||||
mod glwe_ct;
|
||||
mod glwe_to_lwe_ksk;
|
||||
mod lwe_ct;
|
||||
mod lwe_ksk;
|
||||
mod lwe_to_glwe_ksk;
|
||||
mod gglwe;
|
||||
mod ggsw;
|
||||
mod glwe;
|
||||
mod glwe_automorphism_key;
|
||||
mod glwe_switching_key;
|
||||
mod glwe_tensor_key;
|
||||
mod glwe_to_lwe_switching_key;
|
||||
mod lwe;
|
||||
mod lwe_switching_key;
|
||||
mod lwe_to_glwe_switching_key;
|
||||
|
||||
pub use gglwe_atk::*;
|
||||
pub use gglwe_ct::*;
|
||||
pub use gglwe_ksk::*;
|
||||
pub use gglwe_tsk::*;
|
||||
pub use ggsw_ct::*;
|
||||
pub use glwe_ct::*;
|
||||
pub use glwe_to_lwe_ksk::*;
|
||||
pub use lwe_ct::*;
|
||||
pub use lwe_ksk::*;
|
||||
pub use lwe_to_glwe_ksk::*;
|
||||
pub use gglwe::*;
|
||||
pub use ggsw::*;
|
||||
pub use glwe::*;
|
||||
pub use glwe_automorphism_key::*;
|
||||
pub use glwe_switching_key::*;
|
||||
pub use glwe_tensor_key::*;
|
||||
pub use glwe_to_lwe_switching_key::*;
|
||||
pub use lwe::*;
|
||||
pub use lwe_switching_key::*;
|
||||
pub use lwe_to_glwe_switching_key::*;
|
||||
|
||||
@@ -5,7 +5,6 @@ use poulpy_hal::{
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWE, GGLWEInfos, GGLWEToMut, GGLWEToRef, GLWE, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GetAutomorphismGaloisElement, SetAutomorphismGaloisElement},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
@@ -27,13 +26,21 @@ pub struct AutomorphismKey<D: Data> {
|
||||
pub(crate) p: i64,
|
||||
}
|
||||
|
||||
impl<D: DataMut> SetAutomorphismGaloisElement for AutomorphismKey<D> {
|
||||
pub trait GetGaloisElement {
|
||||
fn p(&self) -> i64;
|
||||
}
|
||||
|
||||
pub trait SetGaloisElement {
|
||||
fn set_p(&mut self, p: i64);
|
||||
}
|
||||
|
||||
impl<D: DataMut> SetGaloisElement for AutomorphismKey<D> {
|
||||
fn set_p(&mut self, p: i64) {
|
||||
self.p = p
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> GetAutomorphismGaloisElement for AutomorphismKey<D> {
|
||||
impl<D: DataRef> GetGaloisElement for AutomorphismKey<D> {
|
||||
fn p(&self) -> i64 {
|
||||
self.p
|
||||
}
|
||||
@@ -1,17 +1,14 @@
|
||||
use poulpy_hal::layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, VecZnxToMut, VecZnxToRef, WriterTo, ZnxInfos};
|
||||
use poulpy_hal::layouts::{Data, DataMut, DataRef, ReaderFrom, VecZnx, WriterTo};
|
||||
|
||||
use crate::{
|
||||
GetDistribution, GetDistributionMut,
|
||||
dist::Distribution,
|
||||
layouts::{Base2K, Degree, GLWEInfos, LWEInfos, Rank, TorusPrecision},
|
||||
layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, Rank, TorusPrecision},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct GLWEPublicKey<D: Data> {
|
||||
pub(crate) data: VecZnx<D>,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) key: GLWE<D>,
|
||||
pub(crate) dist: Distribution,
|
||||
}
|
||||
|
||||
@@ -37,25 +34,25 @@ pub struct GLWEPublicKeyLayout {
|
||||
|
||||
impl<D: Data> LWEInfos for GLWEPublicKey<D> {
|
||||
fn base2k(&self) -> Base2K {
|
||||
self.base2k
|
||||
self.key.base2k()
|
||||
}
|
||||
|
||||
fn k(&self) -> TorusPrecision {
|
||||
self.k
|
||||
self.key.k()
|
||||
}
|
||||
|
||||
fn n(&self) -> Degree {
|
||||
Degree(self.data.n() as u32)
|
||||
self.key.n()
|
||||
}
|
||||
|
||||
fn size(&self) -> usize {
|
||||
self.data.size()
|
||||
self.key.size()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GLWEInfos for GLWEPublicKey<D> {
|
||||
fn rank(&self) -> Rank {
|
||||
Rank(self.data.cols() as u32 - 1)
|
||||
self.key.rank()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +90,7 @@ impl GLWEPublicKey<Vec<u8>> {
|
||||
|
||||
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
|
||||
GLWEPublicKey {
|
||||
data: VecZnx::alloc(n.into(), (rank + 1).into(), k.0.div_ceil(base2k.0) as usize),
|
||||
base2k,
|
||||
k,
|
||||
key: GLWE::alloc(n, base2k, k, rank),
|
||||
dist: Distribution::NONE,
|
||||
}
|
||||
}
|
||||
@@ -114,54 +109,32 @@ impl GLWEPublicKey<Vec<u8>> {
|
||||
|
||||
impl<D: DataMut> ReaderFrom for GLWEPublicKey<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>()?);
|
||||
match Distribution::read_from(reader) {
|
||||
Ok(dist) => self.dist = dist,
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
self.data.read_from(reader)
|
||||
self.key.read_from(reader)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> WriterTo for GLWEPublicKey<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)?;
|
||||
match self.dist.write_to(writer) {
|
||||
Ok(()) => {}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
self.data.write_to(writer)
|
||||
self.key.write_to(writer)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPublicKeyToRef {
|
||||
fn to_ref(&self) -> GLWEPublicKey<&[u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataRef> GLWEPublicKeyToRef for GLWEPublicKey<D> {
|
||||
fn to_ref(&self) -> GLWEPublicKey<&[u8]> {
|
||||
GLWEPublicKey {
|
||||
data: self.data.to_ref(),
|
||||
base2k: self.base2k,
|
||||
k: self.k,
|
||||
dist: self.dist,
|
||||
}
|
||||
impl<D: DataRef> GLWEToRef for GLWEPublicKey<D> {
|
||||
fn to_ref(&self) -> GLWE<&[u8]> {
|
||||
self.key.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPublicKeyToMut {
|
||||
fn to_mut(&mut self) -> GLWEPublicKey<&mut [u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> GLWEPublicKeyToMut for GLWEPublicKey<D> {
|
||||
fn to_mut(&mut self) -> GLWEPublicKey<&mut [u8]> {
|
||||
GLWEPublicKey {
|
||||
base2k: self.base2k,
|
||||
k: self.k,
|
||||
dist: self.dist,
|
||||
data: self.data.to_mut(),
|
||||
}
|
||||
impl<D: DataMut> GLWEToMut for GLWEPublicKey<D> {
|
||||
fn to_mut(&mut self) -> GLWE<&mut [u8]> {
|
||||
self.key.to_mut()
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,38 @@
|
||||
mod gglwe_atk;
|
||||
mod gglwe_ct;
|
||||
mod gglwe_ksk;
|
||||
mod gglwe_tsk;
|
||||
mod ggsw_ct;
|
||||
mod glwe_ct;
|
||||
mod glwe_pk;
|
||||
mod glwe_pt;
|
||||
mod glwe_sk;
|
||||
mod glwe_to_lwe_ksk;
|
||||
mod lwe_ct;
|
||||
mod lwe_ksk;
|
||||
mod lwe_pt;
|
||||
mod lwe_sk;
|
||||
mod lwe_to_glwe_ksk;
|
||||
mod gglwe;
|
||||
mod ggsw;
|
||||
mod glwe;
|
||||
mod glwe_automorphism_key;
|
||||
mod glwe_plaintext;
|
||||
mod glwe_public_key;
|
||||
mod glwe_secret;
|
||||
mod glwe_switching_key;
|
||||
mod glwe_tensor_key;
|
||||
mod glwe_to_lwe_switching_key;
|
||||
mod lwe;
|
||||
mod lwe_plaintext;
|
||||
mod lwe_secret;
|
||||
mod lwe_switching_key;
|
||||
mod lwe_to_glwe_switching_key;
|
||||
|
||||
pub mod compressed;
|
||||
pub mod prepared;
|
||||
|
||||
pub use compressed::*;
|
||||
pub use gglwe_atk::*;
|
||||
pub use gglwe_ct::*;
|
||||
pub use gglwe_ksk::*;
|
||||
pub use gglwe_tsk::*;
|
||||
pub use ggsw_ct::*;
|
||||
pub use glwe_ct::*;
|
||||
pub use glwe_pk::*;
|
||||
pub use glwe_pt::*;
|
||||
pub use glwe_sk::*;
|
||||
pub use glwe_to_lwe_ksk::*;
|
||||
pub use lwe_ct::*;
|
||||
pub use lwe_ksk::*;
|
||||
pub use lwe_pt::*;
|
||||
pub use lwe_sk::*;
|
||||
pub use lwe_to_glwe_ksk::*;
|
||||
pub use gglwe::*;
|
||||
pub use ggsw::*;
|
||||
pub use glwe::*;
|
||||
pub use glwe_automorphism_key::*;
|
||||
pub use glwe_plaintext::*;
|
||||
pub use glwe_public_key::*;
|
||||
pub use glwe_secret::*;
|
||||
pub use glwe_switching_key::*;
|
||||
pub use glwe_tensor_key::*;
|
||||
pub use glwe_to_lwe_switching_key::*;
|
||||
pub use lwe::*;
|
||||
pub use lwe_plaintext::*;
|
||||
pub use lwe_secret::*;
|
||||
pub use lwe_switching_key::*;
|
||||
pub use lwe_to_glwe_switching_key::*;
|
||||
pub use prepared::*;
|
||||
|
||||
use poulpy_hal::layouts::{Backend, Module};
|
||||
|
||||
@@ -57,9 +57,9 @@ impl<D: Data, B: Backend> GGLWEInfos for GGLWEPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GGLWEPreparedAlloc<B: Backend>
|
||||
pub trait GGLWEPreparedAlloc<BE: Backend>
|
||||
where
|
||||
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf,
|
||||
Self: GetDegree + VmpPMatAlloc<BE> + VmpPMatBytesOf + VmpPrepare<BE> + VmpPrepareTmpBytes,
|
||||
{
|
||||
fn alloc_gglwe_prepared(
|
||||
&self,
|
||||
@@ -69,7 +69,7 @@ where
|
||||
rank_out: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> GGLWEPrepared<Vec<u8>, B> {
|
||||
) -> GGLWEPrepared<Vec<u8>, BE> {
|
||||
let size: usize = k.0.div_ceil(base2k.0) as usize;
|
||||
debug_assert!(
|
||||
size as u32 > dsize.0,
|
||||
@@ -92,7 +92,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn alloc_gglwe_prepared_from_infos<A>(&self, infos: &A) -> GGLWEPrepared<Vec<u8>, B>
|
||||
fn alloc_gglwe_prepared_from_infos<A>(&self, infos: &A) -> GGLWEPrepared<Vec<u8>, BE>
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
@@ -147,9 +147,41 @@ where
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
fn prepare_gglwe_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.vmp_prepare_tmp_bytes(
|
||||
infos.dnum().into(),
|
||||
infos.rank_in().into(),
|
||||
(infos.rank() + 1).into(),
|
||||
infos.size(),
|
||||
)
|
||||
}
|
||||
|
||||
fn prepare_gglwe<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<BE>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<BE>,
|
||||
O: GGLWEToRef,
|
||||
{
|
||||
let mut res: GGLWEPrepared<&mut [u8], BE> = res.to_mut();
|
||||
let other: GGLWE<&[u8]> = other.to_ref();
|
||||
|
||||
assert_eq!(res.n(), self.ring_degree());
|
||||
assert_eq!(other.n(), self.ring_degree());
|
||||
assert_eq!(res.base2k, other.base2k);
|
||||
assert_eq!(res.k, other.k);
|
||||
assert_eq!(res.dsize, other.dsize);
|
||||
|
||||
self.vmp_prepare(&mut res.data, &other.data, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GGLWEPreparedAlloc<B> for Module<B> where Module<B>: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {}
|
||||
impl<BE: Backend> GGLWEPreparedAlloc<BE> for Module<BE> where
|
||||
Module<BE>: GetDegree + VmpPMatAlloc<BE> + VmpPMatBytesOf + VmpPrepare<BE> + VmpPrepareTmpBytes
|
||||
{
|
||||
}
|
||||
|
||||
impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
@@ -199,47 +231,11 @@ impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GGLWEPrepare<B: Backend>
|
||||
where
|
||||
Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B>,
|
||||
{
|
||||
fn prepare_gglwe_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.vmp_prepare_tmp_bytes(
|
||||
infos.dnum().into(),
|
||||
infos.rank_in().into(),
|
||||
(infos.rank() + 1).into(),
|
||||
infos.size(),
|
||||
)
|
||||
}
|
||||
|
||||
fn prepare_gglwe<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B>,
|
||||
O: GGLWEToRef,
|
||||
{
|
||||
let mut res: GGLWEPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: GGLWE<&[u8]> = other.to_ref();
|
||||
|
||||
assert_eq!(res.n(), self.ring_degree());
|
||||
assert_eq!(other.n(), self.ring_degree());
|
||||
assert_eq!(res.base2k, other.base2k);
|
||||
assert_eq!(res.k, other.k);
|
||||
assert_eq!(res.dsize, other.dsize);
|
||||
|
||||
self.vmp_prepare(&mut res.data, &other.data, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GGLWEPrepare<B> for Module<B> where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B> {}
|
||||
|
||||
impl<D: DataMut, B: Backend> GGLWEPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GGLWEToRef,
|
||||
M: GGLWEPrepare<B>,
|
||||
M: GGLWEPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_gglwe(self, other, scratch);
|
||||
}
|
||||
@@ -248,7 +244,7 @@ impl<D: DataMut, B: Backend> GGLWEPrepared<D, B> {
|
||||
impl<B: Backend> GGLWEPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
|
||||
where
|
||||
M: GGLWEPrepare<B>,
|
||||
M: GGLWEPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_gglwe_tmp_bytes(self)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl<D: Data, B: Backend> GGSWInfos for GGSWPrepared<D, B> {
|
||||
|
||||
pub trait GGSWPreparedAlloc<B: Backend>
|
||||
where
|
||||
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf,
|
||||
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf + VmpPrepareTmpBytes + VmpPrepare<B>,
|
||||
{
|
||||
fn alloc_ggsw_prepared(
|
||||
&self,
|
||||
@@ -133,9 +133,39 @@ where
|
||||
infos.rank(),
|
||||
)
|
||||
}
|
||||
|
||||
fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGSWInfos,
|
||||
{
|
||||
assert_eq!(self.ring_degree(), infos.n());
|
||||
self.vmp_prepare_tmp_bytes(
|
||||
infos.dnum().into(),
|
||||
(infos.rank() + 1).into(),
|
||||
(infos.rank() + 1).into(),
|
||||
infos.size(),
|
||||
)
|
||||
}
|
||||
fn ggsw_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGSWPreparedToMut<B>,
|
||||
O: GGSWToRef,
|
||||
{
|
||||
let mut res: GGSWPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: GGSW<&[u8]> = other.to_ref();
|
||||
assert_eq!(res.n(), self.ring_degree());
|
||||
assert_eq!(other.n(), self.ring_degree());
|
||||
assert_eq!(res.k, other.k);
|
||||
assert_eq!(res.base2k, other.base2k);
|
||||
assert_eq!(res.dsize, other.dsize);
|
||||
self.vmp_prepare(&mut res.data, &other.data, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GGSWPreparedAlloc<B> for Module<B> where Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {}
|
||||
impl<B: Backend> GGSWPreparedAlloc<B> for Module<B> where
|
||||
Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf + VmpPrepareTmpBytes + VmpPrepare<B>
|
||||
{
|
||||
}
|
||||
|
||||
impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
@@ -175,45 +205,11 @@ impl<D: DataRef, B: Backend> GGSWPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GGSWPrepare<B: Backend>
|
||||
where
|
||||
Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B>,
|
||||
{
|
||||
fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGSWInfos,
|
||||
{
|
||||
assert_eq!(self.ring_degree(), infos.n());
|
||||
self.vmp_prepare_tmp_bytes(
|
||||
infos.dnum().into(),
|
||||
(infos.rank() + 1).into(),
|
||||
(infos.rank() + 1).into(),
|
||||
infos.size(),
|
||||
)
|
||||
}
|
||||
fn ggsw_prepare<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGSWPreparedToMut<B>,
|
||||
O: GGSWToRef,
|
||||
{
|
||||
let mut res: GGSWPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: GGSW<&[u8]> = other.to_ref();
|
||||
assert_eq!(res.n(), self.ring_degree());
|
||||
assert_eq!(other.n(), self.ring_degree());
|
||||
assert_eq!(res.k, other.k);
|
||||
assert_eq!(res.base2k, other.base2k);
|
||||
assert_eq!(res.dsize, other.dsize);
|
||||
self.vmp_prepare(&mut res.data, &other.data, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GGSWPrepare<B> for Module<B> where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B> {}
|
||||
|
||||
impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
|
||||
where
|
||||
A: GGSWInfos,
|
||||
M: GGSWPrepare<B>,
|
||||
M: GGSWPreparedAlloc<B>,
|
||||
{
|
||||
module.ggsw_prepare_tmp_bytes(infos)
|
||||
}
|
||||
@@ -223,7 +219,7 @@ impl<D: DataMut, B: Backend> GGSWPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GGSWToRef,
|
||||
M: GGSWPrepare<B>,
|
||||
M: GGSWPreparedAlloc<B>,
|
||||
{
|
||||
module.ggsw_prepare(self, other, scratch);
|
||||
}
|
||||
161
poulpy-core/src/layouts/prepared/glwe.rs
Normal file
161
poulpy-core/src/layouts/prepared/glwe.rs
Normal file
@@ -0,0 +1,161 @@
|
||||
use poulpy_hal::{
|
||||
api::{VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf},
|
||||
layouts::{Backend, Data, DataMut, DataRef, Module, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, ZnxInfos},
|
||||
};
|
||||
|
||||
use crate::layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToRef, GetDegree, LWEInfos, Rank, TorusPrecision};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct GLWEPrepared<D: Data, B: Backend> {
|
||||
pub(crate) data: VecZnxDft<D, B>,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) k: TorusPrecision,
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> LWEInfos for GLWEPrepared<D, B> {
|
||||
fn base2k(&self) -> Base2K {
|
||||
self.base2k
|
||||
}
|
||||
|
||||
fn k(&self) -> TorusPrecision {
|
||||
self.k
|
||||
}
|
||||
|
||||
fn size(&self) -> usize {
|
||||
self.data.size()
|
||||
}
|
||||
|
||||
fn n(&self) -> Degree {
|
||||
Degree(self.data.n() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GLWEInfos for GLWEPrepared<D, B> {
|
||||
fn rank(&self) -> Rank {
|
||||
Rank(self.data.cols() as u32 - 1)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPreparedAlloc<B: Backend>
|
||||
where
|
||||
Self: GetDegree + VecZnxDftAlloc<B> + VecZnxDftBytesOf + VecZnxDftApply<B>,
|
||||
{
|
||||
fn alloc_glwe_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPrepared<Vec<u8>, B> {
|
||||
GLWEPrepared {
|
||||
data: self.vec_znx_dft_alloc((rank + 1).into(), k.0.div_ceil(base2k.0) as usize),
|
||||
base2k,
|
||||
k,
|
||||
}
|
||||
}
|
||||
|
||||
fn alloc_glwe_prepared_from_infos<A>(&self, infos: &A) -> GLWEPrepared<Vec<u8>, B>
|
||||
where
|
||||
A: GLWEInfos,
|
||||
{
|
||||
self.alloc_glwe_prepared(infos.base2k(), infos.k(), infos.rank())
|
||||
}
|
||||
|
||||
fn bytes_of_glwe_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize {
|
||||
self.bytes_of_vec_znx_dft((rank + 1).into(), k.0.div_ceil(base2k.0) as usize)
|
||||
}
|
||||
|
||||
fn bytes_of_glwe_prepared_from_infos<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GLWEInfos,
|
||||
{
|
||||
self.bytes_of_glwe_prepared(infos.base2k(), infos.k(), infos.rank())
|
||||
}
|
||||
|
||||
fn prepare_glwe<R, O>(&self, res: &mut R, other: &O)
|
||||
where
|
||||
R: GLWEPreparedToMut<B>,
|
||||
O: GLWEToRef,
|
||||
{
|
||||
{
|
||||
let mut res: GLWEPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: GLWE<&[u8]> = other.to_ref();
|
||||
|
||||
assert_eq!(res.n(), self.ring_degree());
|
||||
assert_eq!(other.n(), self.ring_degree());
|
||||
assert_eq!(res.size(), other.size());
|
||||
assert_eq!(res.k(), other.k());
|
||||
assert_eq!(res.base2k(), other.base2k());
|
||||
|
||||
for i in 0..(res.rank() + 1).into() {
|
||||
self.vec_znx_dft_apply(1, 0, &mut res.data, i, &other.data, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWEPreparedAlloc<B> for Module<B> where Self: VecZnxDftAlloc<B> + VecZnxDftBytesOf + VecZnxDftApply<B> {}
|
||||
|
||||
impl<B: Backend> GLWEPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
where
|
||||
A: GLWEInfos,
|
||||
M: GLWEPreparedAlloc<B>,
|
||||
{
|
||||
module.alloc_glwe_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self
|
||||
where
|
||||
M: GLWEPreparedAlloc<B>,
|
||||
{
|
||||
module.alloc_glwe_prepared(base2k, k, rank)
|
||||
}
|
||||
|
||||
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
|
||||
where
|
||||
A: GLWEInfos,
|
||||
M: GLWEPreparedAlloc<B>,
|
||||
{
|
||||
module.bytes_of_glwe_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize
|
||||
where
|
||||
M: GLWEPreparedAlloc<B>,
|
||||
{
|
||||
module.bytes_of_glwe_prepared(base2k, k, rank)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWEPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O)
|
||||
where
|
||||
O: GLWEToRef,
|
||||
M: GLWEPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_glwe(self, other);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> GLWEPrepared<&mut [u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWEPreparedToMut<B> for GLWEPrepared<D, B> {
|
||||
fn to_mut(&mut self) -> GLWEPrepared<&mut [u8], B> {
|
||||
GLWEPrepared {
|
||||
k: self.k,
|
||||
base2k: self.base2k,
|
||||
data: self.data.to_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> GLWEPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> GLWEPreparedToRef<B> for GLWEPrepared<D, B> {
|
||||
fn to_ref(&self) -> GLWEPrepared<&[u8], B> {
|
||||
GLWEPrepared {
|
||||
data: self.data.to_ref(),
|
||||
k: self.k,
|
||||
base2k: self.base2k,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut,
|
||||
GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef,
|
||||
GGLWEToRef, GLWEInfos, GetGaloisElement, LWEInfos, Rank, SetGaloisElement, TorusPrecision,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct AutomorphismKeyPrepared<D: Data, B: Backend> {
|
||||
pub struct GLWEAutomorphismKeyPrepared<D: Data, B: Backend> {
|
||||
pub(crate) key: GGLWEPrepared<D, B>,
|
||||
pub(crate) p: i64,
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> LWEInfos for AutomorphismKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> LWEInfos for GLWEAutomorphismKeyPrepared<D, B> {
|
||||
fn n(&self) -> Degree {
|
||||
self.key.n()
|
||||
}
|
||||
@@ -29,33 +29,25 @@ impl<D: Data, B: Backend> LWEInfos for AutomorphismKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GetAutomorphismGaloisElement {
|
||||
fn p(&self) -> i64;
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GetAutomorphismGaloisElement for AutomorphismKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GetGaloisElement for GLWEAutomorphismKeyPrepared<D, B> {
|
||||
fn p(&self) -> i64 {
|
||||
self.p
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SetAutomorphismGaloisElement {
|
||||
fn set_p(&mut self, p: i64);
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> SetAutomorphismGaloisElement for AutomorphismKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> SetGaloisElement for GLWEAutomorphismKeyPrepared<D, B> {
|
||||
fn set_p(&mut self, p: i64) {
|
||||
self.p = p
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GLWEInfos for AutomorphismKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GLWEInfos for GLWEAutomorphismKeyPrepared<D, B> {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GGLWEInfos for AutomorphismKeyPrepared<D, B> {
|
||||
impl<D: Data, B: Backend> GGLWEInfos for GLWEAutomorphismKeyPrepared<D, B> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -73,7 +65,7 @@ impl<D: Data, B: Backend> GGLWEInfos for AutomorphismKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AutomorphismKeyPreparedAlloc<B: Backend>
|
||||
pub trait GLWEAutomorphismKeyPreparedApi<B: Backend>
|
||||
where
|
||||
Self: GGLWEPreparedAlloc<B>,
|
||||
{
|
||||
@@ -84,14 +76,14 @@ where
|
||||
rank: Rank,
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
AutomorphismKeyPrepared::<Vec<u8>, B> {
|
||||
) -> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
GLWEAutomorphismKeyPrepared::<Vec<u8>, B> {
|
||||
key: self.alloc_gglwe_prepared(base2k, k, rank, rank, dnum, dsize),
|
||||
p: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn alloc_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> AutomorphismKeyPrepared<Vec<u8>, B>
|
||||
fn alloc_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> GLWEAutomorphismKeyPrepared<Vec<u8>, B>
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
@@ -137,46 +129,7 @@ where
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> AutomorphismKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}
|
||||
|
||||
impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: AutomorphismKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.alloc_automorphism_key_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self
|
||||
where
|
||||
M: AutomorphismKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.alloc_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
|
||||
}
|
||||
|
||||
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: AutomorphismKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.bytes_of_automorphism_key_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize
|
||||
where
|
||||
M: AutomorphismKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.bytes_of_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AutomorphismKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GGLWEPrepare<B>,
|
||||
{
|
||||
fn prepare_automorphism_key_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
@@ -186,42 +139,74 @@ where
|
||||
|
||||
fn prepare_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + SetAutomorphismGaloisElement,
|
||||
O: GGLWEToRef + GetAutomorphismGaloisElement,
|
||||
R: GGLWEPreparedToMut<B> + SetGaloisElement,
|
||||
O: GGLWEToRef + GetGaloisElement,
|
||||
{
|
||||
self.prepare_gglwe(res, other, scratch);
|
||||
res.set_p(other.p());
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> AutomorphismKeyPrepare<B> for Module<B> where Module<B>: GGLWEPrepare<B> {}
|
||||
impl<B: Backend> GLWEAutomorphismKeyPreparedApi<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}
|
||||
|
||||
impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: GLWEAutomorphismKeyPreparedApi<B>,
|
||||
{
|
||||
module.alloc_automorphism_key_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self
|
||||
where
|
||||
M: GLWEAutomorphismKeyPreparedApi<B>,
|
||||
{
|
||||
module.alloc_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
|
||||
}
|
||||
|
||||
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: GLWEAutomorphismKeyPreparedApi<B>,
|
||||
{
|
||||
module.bytes_of_automorphism_key_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn bytes_of<M>(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize
|
||||
where
|
||||
M: GLWEAutomorphismKeyPreparedApi<B>,
|
||||
{
|
||||
module.bytes_of_automorphism_key_prepared(base2k, k, rank, dnum, dsize)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWEAutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
|
||||
where
|
||||
M: AutomorphismKeyPrepare<B>,
|
||||
M: GLWEAutomorphismKeyPreparedApi<B>,
|
||||
{
|
||||
module.prepare_automorphism_key_tmp_bytes(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> AutomorphismKeyPrepared<D, B> {
|
||||
impl<D: DataMut, B: Backend> GLWEAutomorphismKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GGLWEToRef + GetAutomorphismGaloisElement,
|
||||
M: AutomorphismKeyPrepare<B>,
|
||||
O: GGLWEToRef + GetGaloisElement,
|
||||
M: GLWEAutomorphismKeyPreparedApi<B>,
|
||||
{
|
||||
module.prepare_automorphism_key(self, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for AutomorphismKeyPrepared<D, B> {
|
||||
impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for GLWEAutomorphismKeyPrepared<D, B> {
|
||||
fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> {
|
||||
self.key.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef, BE: Backend> GGLWEPreparedToRef<BE> for AutomorphismKeyPrepared<D, BE> {
|
||||
impl<D: DataRef, BE: Backend> GGLWEPreparedToRef<BE> for GLWEAutomorphismKeyPrepared<D, BE> {
|
||||
fn to_ref(&self) -> GGLWEPrepared<&[u8], BE> {
|
||||
self.key.to_ref()
|
||||
}
|
||||
@@ -1,19 +1,20 @@
|
||||
use poulpy_hal::{
|
||||
api::{VecZnxDftAlloc, VecZnxDftApply, VecZnxDftBytesOf},
|
||||
layouts::{Backend, Data, DataMut, DataRef, Module, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, ZnxInfos},
|
||||
layouts::{Backend, Data, DataMut, DataRef, Module},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
GetDistribution, GetDistributionMut,
|
||||
dist::Distribution,
|
||||
layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, LWEInfos, Rank, TorusPrecision},
|
||||
layouts::{
|
||||
Base2K, Degree, GLWEInfos, GLWEPrepared, GLWEPreparedAlloc, GLWEPreparedToMut, GLWEPreparedToRef, GLWEToRef, GetDegree,
|
||||
LWEInfos, Rank, TorusPrecision,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct GLWEPublicKeyPrepared<D: Data, B: Backend> {
|
||||
pub(crate) data: VecZnxDft<D, B>,
|
||||
pub(crate) base2k: Base2K,
|
||||
pub(crate) k: TorusPrecision,
|
||||
pub(crate) key: GLWEPrepared<D, B>,
|
||||
pub(crate) dist: Distribution,
|
||||
}
|
||||
|
||||
@@ -31,37 +32,35 @@ impl<D: DataMut, BE: Backend> GetDistributionMut for GLWEPublicKeyPrepared<D, BE
|
||||
|
||||
impl<D: Data, B: Backend> LWEInfos for GLWEPublicKeyPrepared<D, B> {
|
||||
fn base2k(&self) -> Base2K {
|
||||
self.base2k
|
||||
self.key.base2k()
|
||||
}
|
||||
|
||||
fn k(&self) -> TorusPrecision {
|
||||
self.k
|
||||
self.key.k()
|
||||
}
|
||||
|
||||
fn size(&self) -> usize {
|
||||
self.data.size()
|
||||
self.key.size()
|
||||
}
|
||||
|
||||
fn n(&self) -> Degree {
|
||||
Degree(self.data.n() as u32)
|
||||
self.key.n()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GLWEInfos for GLWEPublicKeyPrepared<D, B> {
|
||||
fn rank(&self) -> Rank {
|
||||
Rank(self.data.cols() as u32 - 1)
|
||||
self.key.rank()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPublicKeyPreparedAlloc<B: Backend>
|
||||
where
|
||||
Self: GetDegree + VecZnxDftAlloc<B> + VecZnxDftBytesOf,
|
||||
Self: GetDegree + GLWEPreparedAlloc<B>,
|
||||
{
|
||||
fn alloc_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWEPublicKeyPrepared<Vec<u8>, B> {
|
||||
GLWEPublicKeyPrepared {
|
||||
data: self.vec_znx_dft_alloc((rank + 1).into(), k.0.div_ceil(base2k.0) as usize),
|
||||
base2k,
|
||||
k,
|
||||
key: self.alloc_glwe_prepared(base2k, k, rank),
|
||||
dist: Distribution::NONE,
|
||||
}
|
||||
}
|
||||
@@ -74,7 +73,7 @@ where
|
||||
}
|
||||
|
||||
fn bytes_of_glwe_public_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize {
|
||||
self.bytes_of_vec_znx_dft((rank + 1).into(), k.0.div_ceil(base2k.0) as usize)
|
||||
self.bytes_of_glwe_prepared(base2k, k, rank)
|
||||
}
|
||||
|
||||
fn bytes_of_glwe_public_key_prepared_from_infos<A>(&self, infos: &A) -> usize
|
||||
@@ -83,9 +82,18 @@ where
|
||||
{
|
||||
self.bytes_of_glwe_public_key_prepared(infos.base2k(), infos.k(), infos.rank())
|
||||
}
|
||||
|
||||
fn prepare_glwe_public_key<R, O>(&self, res: &mut R, other: &O)
|
||||
where
|
||||
R: GLWEPreparedToMut<B> + GetDistributionMut,
|
||||
O: GLWEToRef + GetDistribution,
|
||||
{
|
||||
self.prepare_glwe(res, other);
|
||||
*res.dist_mut() = *other.dist();
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWEPublicKeyPreparedAlloc<B> for Module<B> where Self: VecZnxDftAlloc<B> + VecZnxDftBytesOf {}
|
||||
impl<B: Backend> GLWEPublicKeyPreparedAlloc<B> for Module<B> where Self: VecZnxDftAlloc<B> + VecZnxDftBytesOf + VecZnxDftApply<B> {}
|
||||
|
||||
impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
@@ -119,72 +127,30 @@ impl<B: Backend> GLWEPublicKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPublicKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GetDegree + VecZnxDftApply<B>,
|
||||
{
|
||||
fn prepare_glwe_public_key<R, O>(&self, res: &mut R, other: &O)
|
||||
where
|
||||
R: GLWEPublicKeyPreparedToMut<B> + GetDistributionMut,
|
||||
O: GLWEPublicKeyToRef + GetDistribution,
|
||||
{
|
||||
{
|
||||
let mut res: GLWEPublicKeyPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: GLWEPublicKey<&[u8]> = other.to_ref();
|
||||
|
||||
assert_eq!(res.n(), self.ring_degree());
|
||||
assert_eq!(other.n(), self.ring_degree());
|
||||
assert_eq!(res.size(), other.size());
|
||||
assert_eq!(res.k(), other.k());
|
||||
assert_eq!(res.base2k(), other.base2k());
|
||||
|
||||
for i in 0..(res.rank() + 1).into() {
|
||||
self.vec_znx_dft_apply(1, 0, &mut res.data, i, &other.data, i);
|
||||
}
|
||||
}
|
||||
|
||||
*res.dist_mut() = *other.dist();
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWEPublicKeyPrepare<B> for Module<B> where Self: GetDegree + VecZnxDftApply<B> {}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWEPublicKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O)
|
||||
where
|
||||
O: GLWEPublicKeyToRef + GetDistribution,
|
||||
M: GLWEPublicKeyPrepare<B>,
|
||||
O: GLWEToRef + GetDistribution,
|
||||
M: GLWEPublicKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_glwe_public_key(self, other);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPublicKeyPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> GLWEPublicKeyPrepared<&mut [u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWEPublicKeyPreparedToMut<B> for GLWEPublicKeyPrepared<D, B> {
|
||||
fn to_mut(&mut self) -> GLWEPublicKeyPrepared<&mut [u8], B> {
|
||||
GLWEPublicKeyPrepared {
|
||||
dist: self.dist,
|
||||
k: self.k,
|
||||
base2k: self.base2k,
|
||||
data: self.data.to_mut(),
|
||||
}
|
||||
impl<D: DataMut, B: Backend> GLWEPreparedToMut<B> for GLWEPublicKeyPrepared<D, B>
|
||||
where
|
||||
GLWEPrepared<D, B>: GLWEPreparedToMut<B>,
|
||||
{
|
||||
fn to_mut(&mut self) -> GLWEPrepared<&mut [u8], B> {
|
||||
self.key.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEPublicKeyPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> GLWEPublicKeyPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> GLWEPublicKeyPreparedToRef<B> for GLWEPublicKeyPrepared<D, B> {
|
||||
fn to_ref(&self) -> GLWEPublicKeyPrepared<&[u8], B> {
|
||||
GLWEPublicKeyPrepared {
|
||||
data: self.data.to_ref(),
|
||||
dist: self.dist,
|
||||
k: self.k,
|
||||
base2k: self.base2k,
|
||||
}
|
||||
impl<D: DataRef, B: Backend> GLWEPreparedToRef<B> for GLWEPublicKeyPrepared<D, B>
|
||||
where
|
||||
GLWEPrepared<D, B>: GLWEPreparedToRef<B>,
|
||||
{
|
||||
fn to_ref(&self) -> GLWEPrepared<&[u8], B> {
|
||||
self.key.to_ref()
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,9 @@ impl<D: Data, B: Backend> GLWEInfos for GLWESecretPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWESecretPreparedAlloc<B: Backend>
|
||||
pub trait GLWESecretPreparedApi<B: Backend>
|
||||
where
|
||||
Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B>,
|
||||
Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B> + SvpPrepare<B>,
|
||||
{
|
||||
fn alloc_glwe_secret_prepared(&self, rank: Rank) -> GLWESecretPrepared<Vec<u8>, B> {
|
||||
GLWESecretPrepared {
|
||||
@@ -77,56 +77,7 @@ where
|
||||
assert_eq!(self.ring_degree(), infos.n());
|
||||
self.bytes_of_glwe_secret_prepared(infos.rank())
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWESecretPreparedAlloc<B> for Module<B> where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B> {}
|
||||
|
||||
impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
where
|
||||
A: GLWEInfos,
|
||||
M: GLWESecretPreparedAlloc<B>,
|
||||
{
|
||||
module.alloc_glwe_secret_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn alloc<M>(module: &M, rank: Rank) -> Self
|
||||
where
|
||||
M: GLWESecretPreparedAlloc<B>,
|
||||
{
|
||||
module.alloc_glwe_secret_prepared(rank)
|
||||
}
|
||||
|
||||
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
|
||||
where
|
||||
A: GLWEInfos,
|
||||
M: GLWESecretPreparedAlloc<B>,
|
||||
{
|
||||
module.bytes_of_glwe_secret_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn bytes_of<M>(module: &M, rank: Rank) -> usize
|
||||
where
|
||||
M: GLWESecretPreparedAlloc<B>,
|
||||
{
|
||||
module.bytes_of_glwe_secret_prepared(rank)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GLWESecretPrepared<D, B> {
|
||||
pub fn n(&self) -> Degree {
|
||||
Degree(self.data.n() as u32)
|
||||
}
|
||||
|
||||
pub fn rank(&self) -> Rank {
|
||||
Rank(self.data.cols() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWESecretPrepare<B: Backend>
|
||||
where
|
||||
Self: SvpPrepare<B>,
|
||||
{
|
||||
fn prepare_glwe_secret<R, O>(&self, res: &mut R, other: &O)
|
||||
where
|
||||
R: GLWESecretPreparedToMut<B> + GetDistributionMut,
|
||||
@@ -145,12 +96,54 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWESecretPrepare<B> for Module<B> where Self: SvpPrepare<B> {}
|
||||
impl<B: Backend> GLWESecretPreparedApi<B> for Module<B> where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc<B> + SvpPrepare<B> {}
|
||||
|
||||
impl<B: Backend> GLWESecretPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
where
|
||||
A: GLWEInfos,
|
||||
M: GLWESecretPreparedApi<B>,
|
||||
{
|
||||
module.alloc_glwe_secret_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn alloc<M>(module: &M, rank: Rank) -> Self
|
||||
where
|
||||
M: GLWESecretPreparedApi<B>,
|
||||
{
|
||||
module.alloc_glwe_secret_prepared(rank)
|
||||
}
|
||||
|
||||
pub fn bytes_of_from_infos<A, M>(module: &M, infos: &A) -> usize
|
||||
where
|
||||
A: GLWEInfos,
|
||||
M: GLWESecretPreparedApi<B>,
|
||||
{
|
||||
module.bytes_of_glwe_secret_prepared_from_infos(infos)
|
||||
}
|
||||
|
||||
pub fn bytes_of<M>(module: &M, rank: Rank) -> usize
|
||||
where
|
||||
M: GLWESecretPreparedApi<B>,
|
||||
{
|
||||
module.bytes_of_glwe_secret_prepared(rank)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> GLWESecretPrepared<D, B> {
|
||||
pub fn n(&self) -> Degree {
|
||||
Degree(self.data.n() as u32)
|
||||
}
|
||||
|
||||
pub fn rank(&self) -> Rank {
|
||||
Rank(self.data.cols() as u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWESecretPrepared<D, B> {
|
||||
pub fn prepare<M, O>(&mut self, module: &M, other: &O)
|
||||
where
|
||||
M: GLWESecretPrepare<B>,
|
||||
M: GLWESecretPreparedApi<B>,
|
||||
O: GLWESecretToRef + GetDistribution,
|
||||
{
|
||||
module.prepare_glwe_secret(self, other);
|
||||
@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut,
|
||||
LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef},
|
||||
prepared::{GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -134,6 +134,23 @@ where
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
fn prepare_glwe_switching_key_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_gglwe_tmp_bytes(infos)
|
||||
}
|
||||
|
||||
fn prepare_glwe_switching<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_gglwe(res, other, scratch);
|
||||
*res.input_degree() = *other.input_degree();
|
||||
*res.output_degree() = *other.output_degree();
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GGLWEPreparedAlloc<B> {}
|
||||
@@ -186,35 +203,11 @@ impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWESwitchingKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GGLWEPrepare<B>,
|
||||
{
|
||||
fn prepare_glwe_switching_key_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_gglwe_tmp_bytes(infos)
|
||||
}
|
||||
|
||||
fn prepare_glwe_switching<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_gglwe(res, other, scratch);
|
||||
*res.input_degree() = *other.input_degree();
|
||||
*res.output_degree() = *other.output_degree();
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWESwitchingKeyPrepare<B> for Module<B> where Self: GGLWEPrepare<B> {}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: GLWESwitchingKeyPrepare<B>,
|
||||
M: GLWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_glwe_switching(self, other, scratch);
|
||||
}
|
||||
@@ -223,7 +216,7 @@ impl<D: DataMut, B: Backend> GLWESwitchingKeyPrepared<D, B> {
|
||||
impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
|
||||
where
|
||||
M: GLWESwitchingKeyPrepare<B>,
|
||||
M: GLWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_glwe_switching_key_tmp_bytes(self)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut,
|
||||
GGLWEPreparedToRef, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef,
|
||||
GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -107,6 +107,28 @@ where
|
||||
infos.dsize(),
|
||||
)
|
||||
}
|
||||
|
||||
fn prepare_tensor_key_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_gglwe_tmp_bytes(infos)
|
||||
}
|
||||
|
||||
fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: TensorKeyPreparedToMut<B>,
|
||||
O: TensorKeyToRef,
|
||||
{
|
||||
let mut res: TensorKeyPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: TensorKey<&[u8]> = other.to_ref();
|
||||
|
||||
assert_eq!(res.keys.len(), other.keys.len());
|
||||
|
||||
for (a, b) in res.keys.iter_mut().zip(other.keys.iter()) {
|
||||
self.prepare_gglwe(a, b, scratch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> TensorKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}
|
||||
@@ -165,40 +187,11 @@ impl<D: DataRef, B: Backend> TensorKeyPrepared<D, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TensorKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GGLWEPrepare<B>,
|
||||
{
|
||||
fn prepare_tensor_key_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_gglwe_tmp_bytes(infos)
|
||||
}
|
||||
|
||||
fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: TensorKeyPreparedToMut<B>,
|
||||
O: TensorKeyToRef,
|
||||
{
|
||||
let mut res: TensorKeyPrepared<&mut [u8], B> = res.to_mut();
|
||||
let other: TensorKey<&[u8]> = other.to_ref();
|
||||
|
||||
assert_eq!(res.keys.len(), other.keys.len());
|
||||
|
||||
for (a, b) in res.keys.iter_mut().zip(other.keys.iter()) {
|
||||
self.prepare_gglwe(a, b, scratch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> TensorKeyPrepare<B> for Module<B> where Self: GGLWEPrepare<B> {}
|
||||
|
||||
impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: TensorKeyPrepare<B>,
|
||||
M: TensorKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_tensor_key_tmp_bytes(infos)
|
||||
}
|
||||
@@ -208,7 +201,7 @@ impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: TensorKeyToRef,
|
||||
M: TensorKeyPrepare<B>,
|
||||
M: TensorKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_tensor_key(self, other, scratch);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
|
||||
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -101,6 +101,21 @@ where
|
||||
);
|
||||
self.bytes_of_glwe_to_lwe_switching_key_prepared(infos.base2k(), infos.k(), infos.rank_in(), infos.dnum())
|
||||
}
|
||||
|
||||
fn prepare_glwe_to_lwe_switching_key_tmp_bytes<A>(&self, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
|
||||
fn prepare_glwe_to_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWEToLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}
|
||||
@@ -137,33 +152,11 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEToLWESwitchingKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GLWESwitchingKeyPrepare<B>,
|
||||
{
|
||||
fn prepare_glwe_to_lwe_switching_key_tmp_bytes<A>(&self, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
|
||||
fn prepare_glwe_to_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> GLWEToLWESwitchingKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {}
|
||||
|
||||
impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: GLWEToLWESwitchingKeyPrepare<B>,
|
||||
M: GLWEToLWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_glwe_to_lwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
@@ -173,7 +166,7 @@ impl<D: DataMut, B: Backend> GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: GLWEToLWESwitchingKeyPrepare<B>,
|
||||
M: GLWEToLWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_glwe_to_lwe_switching_key(self, other, scratch);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
|
||||
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -110,6 +110,20 @@ where
|
||||
);
|
||||
self.bytes_of_lwe_switching_key_prepared(infos.base2k(), infos.k(), infos.dnum())
|
||||
}
|
||||
|
||||
fn prepare_lwe_switching_key_tmp_bytes<A>(&self, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
fn prepare_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> LWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}
|
||||
@@ -146,32 +160,11 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LWESwitchingKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GLWESwitchingKeyPrepare<B>,
|
||||
{
|
||||
fn prepare_lwe_switching_key_tmp_bytes<A>(&self, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
fn prepare_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> LWESwitchingKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {}
|
||||
|
||||
impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: LWESwitchingKeyPrepare<B>,
|
||||
M: LWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_lwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
@@ -181,7 +174,7 @@ impl<D: DataMut, B: Backend> LWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: LWESwitchingKeyPrepare<B>,
|
||||
M: LWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_lwe_switching_key(self, other, scratch);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
|
||||
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
prepared::{GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
};
|
||||
|
||||
/// A special [GLWESwitchingKey] required to for the conversion from [LWE] to [GLWE].
|
||||
@@ -108,6 +108,21 @@ where
|
||||
);
|
||||
self.bytes_of_lwe_to_glwe_switching_key_prepared(infos.base2k(), infos.k(), infos.rank_out(), infos.dnum())
|
||||
}
|
||||
|
||||
fn prepare_lwe_to_glwe_switching_key_tmp_bytes<A>(&self, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
|
||||
fn prepare_lwe_to_glwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> LWEToGLWESwitchingKeyPreparedAlloc<B> for Module<B> where Self: GLWESwitchingKeyPreparedAlloc<B> {}
|
||||
@@ -144,33 +159,11 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LWEToGLWESwitchingKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GLWESwitchingKeyPrepare<B>,
|
||||
{
|
||||
fn prepare_lwe_to_glwe_switching_key_tmp_bytes<A>(&self, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
|
||||
fn prepare_lwe_to_glwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> LWEToGLWESwitchingKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {}
|
||||
|
||||
impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A)
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
M: LWEToGLWESwitchingKeyPrepare<B>,
|
||||
M: LWEToGLWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_lwe_to_glwe_switching_key_tmp_bytes(infos);
|
||||
}
|
||||
@@ -180,7 +173,7 @@ impl<D: DataMut, B: Backend> LWEToGLWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: LWEToGLWESwitchingKeyPrepare<B>,
|
||||
M: LWEToGLWESwitchingKeyPreparedAlloc<B>,
|
||||
{
|
||||
module.prepare_lwe_to_glwe_switching_key(self, other, scratch);
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
mod gglwe_atk;
|
||||
mod gglwe_ct;
|
||||
mod gglwe_ksk;
|
||||
mod gglwe_tsk;
|
||||
mod ggsw_ct;
|
||||
mod glwe_pk;
|
||||
mod glwe_sk;
|
||||
mod glwe_to_lwe_ksk;
|
||||
mod lwe_ksk;
|
||||
mod lwe_to_glwe_ksk;
|
||||
mod gglwe;
|
||||
mod ggsw;
|
||||
mod glwe;
|
||||
mod glwe_automorphism_key;
|
||||
mod glwe_public_key;
|
||||
mod glwe_secret;
|
||||
mod glwe_switching_key;
|
||||
mod glwe_tensor_key;
|
||||
mod glwe_to_lwe_switching_key;
|
||||
mod lwe_switching_key;
|
||||
mod lwe_to_glwe_switching_key;
|
||||
|
||||
pub use gglwe_atk::*;
|
||||
pub use gglwe_ct::*;
|
||||
pub use gglwe_ksk::*;
|
||||
pub use gglwe_tsk::*;
|
||||
pub use ggsw_ct::*;
|
||||
pub use glwe_pk::*;
|
||||
pub use glwe_sk::*;
|
||||
pub use glwe_to_lwe_ksk::*;
|
||||
pub use lwe_ksk::*;
|
||||
pub use lwe_to_glwe_ksk::*;
|
||||
pub use gglwe::*;
|
||||
pub use ggsw::*;
|
||||
pub use glwe::*;
|
||||
pub use glwe_automorphism_key::*;
|
||||
pub use glwe_public_key::*;
|
||||
pub use glwe_secret::*;
|
||||
pub use glwe_switching_key::*;
|
||||
pub use glwe_tensor_key::*;
|
||||
pub use glwe_to_lwe_switching_key::*;
|
||||
pub use lwe_switching_key::*;
|
||||
pub use lwe_to_glwe_switching_key::*;
|
||||
|
||||
Reference in New Issue
Block a user