fixed missing implementations

This commit is contained in:
Jean-Philippe Bossuat
2025-10-18 12:56:30 +02:00
parent 0b8dcb1f16
commit a84ad06086
50 changed files with 444 additions and 419 deletions

View File

@@ -1,5 +1,5 @@
use poulpy_core::layouts::{ use poulpy_core::layouts::{
Base2K, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, RingDegree, TorusPrecision, Base2K, Degree, Dnum, Dsize, GGSW, GGSWLayout, GLWE, GLWELayout, GLWESecret, Rank, TorusPrecision,
prepared::{GGSWPrepared, GLWESecretPrepared}, prepared::{GGSWPrepared, GLWESecretPrepared},
}; };
use std::hint::black_box; use std::hint::black_box;
@@ -28,7 +28,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
fn runner(p: Params) -> impl FnMut() { fn runner(p: Params) -> impl FnMut() {
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n); let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
let n: RingDegree = RingDegree(module.n() as u32); let n: Degree = Degree(module.n() as u32);
let base2k: Base2K = p.base2k; let base2k: Base2K = p.base2k;
let k_ct_in: TorusPrecision = p.k_ct_in; let k_ct_in: TorusPrecision = p.k_ct_in;
let k_ct_out: TorusPrecision = p.k_ct_out; let k_ct_out: TorusPrecision = p.k_ct_out;
@@ -140,7 +140,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
fn runner(p: Params) -> impl FnMut() { fn runner(p: Params) -> impl FnMut() {
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n); let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
let n: RingDegree = RingDegree(module.n() as u32); let n: Degree = Degree(module.n() as u32);
let base2k: Base2K = p.base2k; let base2k: Base2K = p.base2k;
let k_glwe: TorusPrecision = p.k_ct; let k_glwe: TorusPrecision = p.k_ct;
let k_ggsw: TorusPrecision = p.k_ggsw; let k_ggsw: TorusPrecision = p.k_ggsw;

View File

@@ -1,6 +1,6 @@
use poulpy_core::layouts::{ use poulpy_core::layouts::{
AutomorphismKey, AutomorphismKeyLayout, Base2K, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey, AutomorphismKey, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GLWE, GLWELayout, GLWESecret, GLWESwitchingKey,
GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, RingDegree, TorusPrecision, GLWESwitchingKeyLayout, GLWESwitchingKeyPrepared, Rank, TorusPrecision,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared}, prepared::{AutomorphismKeyPrepared, GLWESecretPrepared},
}; };
use std::{hint::black_box, time::Duration}; use std::{hint::black_box, time::Duration};
@@ -29,7 +29,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
fn runner(p: Params) -> impl FnMut() { fn runner(p: Params) -> impl FnMut() {
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n); let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
let n: RingDegree = RingDegree(module.n() as u32); let n: Degree = Degree(module.n() as u32);
let base2k: Base2K = p.base2k; let base2k: Base2K = p.base2k;
let k_glwe_in: TorusPrecision = p.k_ct_in; let k_glwe_in: TorusPrecision = p.k_ct_in;
let k_glwe_out: TorusPrecision = p.k_ct_out; let k_glwe_out: TorusPrecision = p.k_ct_out;
@@ -151,7 +151,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
fn runner(p: Params) -> impl FnMut() { fn runner(p: Params) -> impl FnMut() {
let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n); let module: Module<FFT64Spqlios> = Module::<FFT64Spqlios>::new(1 << p.log_n);
let n: RingDegree = RingDegree(module.n() as u32); let n: Degree = Degree(module.n() as u32);
let base2k: Base2K = p.base2k; let base2k: Base2K = p.base2k;
let k_ct: TorusPrecision = p.k_ct; let k_ct: TorusPrecision = p.k_ct;
let k_ksk: TorusPrecision = p.k_ksk; let k_ksk: TorusPrecision = p.k_ksk;

View File

@@ -2,7 +2,7 @@ use poulpy_backend::cpu_spqlios::FFT64Spqlios;
use poulpy_core::{ use poulpy_core::{
GLWESub, SIGMA, GLWESub, SIGMA,
layouts::{ layouts::{
Base2K, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, RingDegree, TorusPrecision, Base2K, Degree, GLWE, GLWELayout, GLWEPlaintext, GLWEPlaintextLayout, GLWESecret, LWEInfos, Rank, TorusPrecision,
prepared::GLWESecretPrepared, prepared::GLWESecretPrepared,
}, },
}; };
@@ -16,7 +16,7 @@ fn main() {
// Ring degree // Ring degree
let log_n: usize = 10; let log_n: usize = 10;
let n: RingDegree = RingDegree(1 << log_n); let n: Degree = Degree(1 << log_n);
// Base-2-k (implicit digit decomposition) // Base-2-k (implicit digit decomposition)
let base2k: Base2K = Base2K(14); let base2k: Base2K = Base2K(14);

View File

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

View File

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

View File

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

View File

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

View File

@@ -6,7 +6,7 @@ use poulpy_hal::{
}; };
use crate::layouts::{ use crate::layouts::{
Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToMut, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision,
compressed::{GLWECompressed, GLWEDecompress}, compressed::{GLWECompressed, GLWEDecompress},
}; };
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@@ -23,8 +23,8 @@ pub struct GGSWCompressed<D: Data> {
} }
impl<D: Data> LWEInfos for GGSWCompressed<D> { impl<D: Data> LWEInfos for GGSWCompressed<D> {
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
RingDegree(self.data.n() as u32) Degree(self.data.n() as u32)
} }
fn base2k(&self) -> Base2K { fn base2k(&self) -> Base2K {
@@ -76,9 +76,11 @@ impl<D: DataMut> FillUniform for GGSWCompressed<D> {
} }
} }
impl<BE: Backend> GGSWCompressedAlloc for Module<BE> where Self: GetDegree {}
pub trait GGSWCompressedAlloc pub trait GGSWCompressedAlloc
where where
Self: GetRingDegree, Self: GetDegree,
{ {
fn alloc_ggsw_compressed( fn alloc_ggsw_compressed(
&self, &self,

View File

@@ -6,9 +6,7 @@ use poulpy_hal::{
source::Source, source::Source,
}; };
use crate::layouts::{ use crate::layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GetDegree, LWEInfos, Rank, SetGLWEInfos, TorusPrecision};
Base2K, GLWE, GLWEInfos, GLWEToMut, GetRingDegree, LWEInfos, Rank, RingDegree, SetGLWEInfos, TorusPrecision,
};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt; use std::fmt;
@@ -34,8 +32,8 @@ impl<D: Data> LWEInfos for GLWECompressed<D> {
self.data.size() self.data.size()
} }
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
RingDegree(self.data.n() as u32) Degree(self.data.n() as u32)
} }
} }
impl<D: Data> GLWEInfos for GLWECompressed<D> { impl<D: Data> GLWEInfos for GLWECompressed<D> {
@@ -72,7 +70,7 @@ impl<D: DataMut> FillUniform for GLWECompressed<D> {
pub trait GLWECompressedAlloc pub trait GLWECompressedAlloc
where where
Self: GetRingDegree, Self: GetDegree,
{ {
fn alloc_glwe_compressed(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWECompressed<Vec<u8>> { fn alloc_glwe_compressed(&self, base2k: Base2K, k: TorusPrecision, rank: Rank) -> GLWECompressed<Vec<u8>> {
GLWECompressed { GLWECompressed {
@@ -113,7 +111,7 @@ where
} }
} }
impl<B: Backend> GLWECompressedAlloc for Module<B> where Self: GetRingDegree {} impl<B: Backend> GLWECompressedAlloc for Module<B> where Self: GetDegree {}
impl GLWECompressed<Vec<u8>> { impl GLWECompressed<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -169,7 +167,7 @@ impl<D: DataRef> WriterTo for GLWECompressed<D> {
pub trait GLWEDecompress pub trait GLWEDecompress
where where
Self: GetRingDegree + VecZnxFillUniform + VecZnxCopy, Self: GetDegree + VecZnxFillUniform + VecZnxCopy,
{ {
fn decompress_glwe<R, O>(&self, res: &mut R, other: &O) fn decompress_glwe<R, O>(&self, res: &mut R, other: &O)
where where
@@ -203,7 +201,7 @@ where
} }
} }
impl<B: Backend> GLWEDecompress for Module<B> where Self: GetRingDegree + VecZnxFillUniform + VecZnxCopy {} impl<B: Backend> GLWEDecompress for Module<B> where Self: GetDegree + VecZnxFillUniform + VecZnxCopy {}
impl<D: DataMut> GLWE<D> { impl<D: DataMut> GLWE<D> {
pub fn decompress<O, M>(&mut self, module: &M, other: &O) pub fn decompress<O, M>(&mut self, module: &M, other: &O)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,7 +5,7 @@ use poulpy_hal::{
source::Source, source::Source,
}; };
use crate::layouts::{Base2K, Dnum, Dsize, GLWE, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision}; use crate::layouts::{Base2K, Degree, Dnum, Dsize, GLWE, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::fmt; use std::fmt;
@@ -37,7 +37,7 @@ pub trait SetGGLWEInfos {
#[derive(PartialEq, Eq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct GGLWELayout { pub struct GGLWELayout {
pub n: RingDegree, pub n: Degree,
pub base2k: Base2K, pub base2k: Base2K,
pub k: TorusPrecision, pub k: TorusPrecision,
pub rank_in: Rank, pub rank_in: Rank,
@@ -55,7 +55,7 @@ impl LWEInfos for GGLWELayout {
self.k self.k
} }
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
self.n self.n
} }
} }
@@ -101,8 +101,8 @@ impl<D: Data> LWEInfos for GGLWE<D> {
self.k self.k
} }
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
RingDegree(self.data.n() as u32) Degree(self.data.n() as u32)
} }
fn size(&self) -> usize { fn size(&self) -> usize {
@@ -193,7 +193,7 @@ impl<D: DataMut> GGLWE<D> {
pub trait GGLWEAlloc pub trait GGLWEAlloc
where where
Self: GetRingDegree, Self: GetDegree,
{ {
fn alloc_gglwe( fn alloc_gglwe(
&self, &self,
@@ -293,7 +293,7 @@ where
} }
} }
impl<B: Backend> GGLWEAlloc for Module<B> where Self: GetRingDegree {} impl<B: Backend> GGLWEAlloc for Module<B> where Self: GetDegree {}
impl GGLWE<Vec<u8>> { impl GGLWE<Vec<u8>> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,7 @@ use poulpy_hal::{
}; };
use crate::layouts::{ use crate::layouts::{
Base2K, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetRingDegree, LWEInfos, Rank, RingDegree, TorusPrecision, Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GetDegree, LWEInfos, Rank, TorusPrecision,
}; };
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@@ -16,8 +16,8 @@ pub struct GGSWPrepared<D: Data, B: Backend> {
} }
impl<D: Data, B: Backend> LWEInfos for GGSWPrepared<D, B> { impl<D: Data, B: Backend> LWEInfos for GGSWPrepared<D, B> {
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
RingDegree(self.data.n() as u32) Degree(self.data.n() as u32)
} }
fn base2k(&self) -> Base2K { fn base2k(&self) -> Base2K {
@@ -51,7 +51,7 @@ impl<D: Data, B: Backend> GGSWInfos for GGSWPrepared<D, B> {
pub trait GGSWPreparedAlloc<B: Backend> pub trait GGSWPreparedAlloc<B: Backend>
where where
Self: GetRingDegree + VmpPMatAlloc<B> + VmpPMatBytesOf, Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf,
{ {
fn alloc_ggsw_prepared( fn alloc_ggsw_prepared(
&self, &self,
@@ -135,7 +135,7 @@ where
} }
} }
impl<B: Backend> GGSWPreparedAlloc<B> for Module<B> where Self: GetRingDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {} impl<B: Backend> GGSWPreparedAlloc<B> for Module<B> where Self: GetDegree + VmpPMatAlloc<B> + VmpPMatBytesOf {}
impl<B: Backend> GGSWPrepared<Vec<u8>, B> { impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
@@ -177,7 +177,7 @@ impl<D: DataRef, B: Backend> GGSWPrepared<D, B> {
pub trait GGSWPrepare<B: Backend> pub trait GGSWPrepare<B: Backend>
where where
Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare<B>, Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B>,
{ {
fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize fn ggsw_prepare_tmp_bytes<A>(&self, infos: &A) -> usize
where where
@@ -207,7 +207,7 @@ where
} }
} }
impl<B: Backend> GGSWPrepare<B> for Module<B> where Self: GetRingDegree + VmpPrepareTmpBytes + VmpPrepare<B> {} impl<B: Backend> GGSWPrepare<B> for Module<B> where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare<B> {}
impl<B: Backend> GGSWPrepared<Vec<u8>, B> { impl<B: Backend> GGSWPrepared<Vec<u8>, B> {
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -25,4 +25,4 @@ pub use encryption::SIGMA;
pub use scratch::*; pub use scratch::*;
// pub mod tests; pub mod tests;

View File

@@ -1,182 +1,182 @@
pub mod test_suite; // pub mod test_suite;
#[cfg(test)] #[cfg(test)]
mod serialization; mod serialization;
#[allow(unused_imports)] //#[allow(unused_imports)]
use poulpy_hal::backend_test_suite; // use poulpy_hal::backend_test_suite;
#[cfg(test)] // #[cfg(test)]
backend_test_suite!( // backend_test_suite!(
mod cpu_spqlios, // mod cpu_spqlios,
backend = poulpy_backend::cpu_spqlios::FFT64Spqlios, // backend = poulpy_backend::cpu_spqlios::FFT64Spqlios,
size = 1<<8, // size = 1<<8,
tests = { // tests = {
// GLWE Encryption // GLWE Encryption
glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, // glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk,
glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, // glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk,
glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, // glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk,
glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, // glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk,
// GLWE Keyswitch // GLWE Keyswitch
glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, // glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch,
glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, // glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace,
// GLWE Automorphism // GLWE Automorphism
glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, // glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism,
glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, // glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace,
// GLWE External Product // GLWE External Product
glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, // glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product,
glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, // glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace,
// GLWE Trace // GLWE Trace
glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, // glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace,
glwe_packing => crate::tests::test_suite::test_glwe_packing, // glwe_packing => crate::tests::test_suite::test_glwe_packing,
// GGLWE Encryption // GGLWE Encryption
gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, // gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk,
gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, // gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk,
gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, // gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk,
gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, // gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk,
gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, // gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk,
gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, // gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk,
// GGLWE Keyswitching // GGLWE Keyswitching
gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, // gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch,
gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, // gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace,
// GGLWE External Product // GGLWE External Product
gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, // gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product,
gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, // gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace,
// GGLWE Automorphism // GGLWE Automorphism
gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, // gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism,
gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, // gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace,
// GGSW Encryption // GGSW Encryption
ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, // ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk,
ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, // ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk,
// GGSW Keyswitching // GGSW Keyswitching
ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, // ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch,
ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, // ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace,
// GGSW External Product // GGSW External Product
ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, // ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product,
ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, // ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace,
// GGSW Automorphism // GGSW Automorphism
ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, // ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism,
ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, // ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace,
// LWE // LWE
lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, // lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch,
glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, // glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe,
lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, // lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
} // }
); // );
//
#[cfg(test)] // #[cfg(test)]
backend_test_suite!( // backend_test_suite!(
mod cpu_ref, // mod cpu_ref,
backend = poulpy_backend::cpu_fft64_ref::FFT64Ref, // backend = poulpy_backend::cpu_fft64_ref::FFT64Ref,
size = 1<<8, // size = 1<<8,
tests = { // tests = {
// GLWE Encryption // GLWE Encryption
glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, // glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk,
glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, // glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk,
glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, // glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk,
glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, // glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk,
// GLWE Keyswitch // GLWE Keyswitch
glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, // glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch,
glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, // glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace,
// GLWE Automorphism // GLWE Automorphism
glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, // glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism,
glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, // glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace,
// GLWE External Product // GLWE External Product
glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, // glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product,
glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, // glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace,
// GLWE Trace // GLWE Trace
glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, // glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace,
glwe_packing => crate::tests::test_suite::test_glwe_packing, // glwe_packing => crate::tests::test_suite::test_glwe_packing,
// GGLWE Encryption // GGLWE Encryption
gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, // gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk,
gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, // gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk,
gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, // gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk,
gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, // gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk,
gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, // gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk,
gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, // gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk,
// GGLWE Keyswitching // GGLWE Keyswitching
gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, // gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch,
gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, // gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace,
// GGLWE External Product // GGLWE External Product
gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, // gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product,
gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, // gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace,
// GGLWE Automorphism // GGLWE Automorphism
gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, // gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism,
gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, // gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace,
// GGSW Encryption // GGSW Encryption
ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, // ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk,
ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, // ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk,
// GGSW Keyswitching // GGSW Keyswitching
ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, // ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch,
ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, // ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace,
// GGSW External Product // GGSW External Product
ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, // ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product,
ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, // ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace,
// GGSW Automorphism // GGSW Automorphism
ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, // ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism,
ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, // ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace,
// LWE // LWE
lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, // lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch,
glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, // glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe,
lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, // lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
} // }
); // );
//
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] // #[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
#[cfg(test)] // #[cfg(test)]
backend_test_suite!( // backend_test_suite!(
mod cpu_avx, // mod cpu_avx,
backend = poulpy_backend::cpu_fft64_avx::FFT64Avx, // backend = poulpy_backend::cpu_fft64_avx::FFT64Avx,
size = 1<<8, // size = 1<<8,
tests = { // tests = {
// GLWE Encryption // GLWE Encryption
glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk, // glwe_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_sk,
glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk, // glwe_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_glwe_compressed_encrypt_sk,
glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk, // glwe_encrypt_zero_sk => crate::tests::test_suite::encryption::test_glwe_encrypt_zero_sk,
glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk, // glwe_encrypt_pk => crate::tests::test_suite::encryption::test_glwe_encrypt_pk,
// GLWE Keyswitch // GLWE Keyswitch
glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch, // glwe_keyswitch => crate::tests::test_suite::keyswitch::test_glwe_keyswitch,
glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace, // glwe_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_glwe_keyswitch_inplace,
// GLWE Automorphism // GLWE Automorphism
glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism, // glwe_automorphism => crate::tests::test_suite::automorphism::test_glwe_automorphism,
glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace, // glwe_automorphism_inplace => crate::tests::test_suite::automorphism::test_glwe_automorphism_inplace,
// GLWE External Product // GLWE External Product
glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product, // glwe_external_product => crate::tests::test_suite::external_product::test_glwe_external_product,
glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace, // glwe_external_product_inplace => crate::tests::test_suite::external_product::test_glwe_external_product_inplace,
// GLWE Trace // GLWE Trace
glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace, // glwe_trace_inplace => crate::tests::test_suite::test_glwe_trace_inplace,
glwe_packing => crate::tests::test_suite::test_glwe_packing, // glwe_packing => crate::tests::test_suite::test_glwe_packing,
// GGLWE Encryption // GGLWE Encryption
gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk, // gglwe_switching_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_encrypt_sk,
gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk, // gglwe_switching_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_switching_key_compressed_encrypt_sk,
gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk, // gglwe_automorphisk_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_encrypt_sk,
gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk, // gglwe_automorphisk_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_automorphisk_key_compressed_encrypt_sk,
gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk, // gglwe_tensor_key_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_encrypt_sk,
gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk, // gglwe_tensor_key_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_gglwe_tensor_key_compressed_encrypt_sk,
// GGLWE Keyswitching // GGLWE Keyswitching
gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch, // gglwe_switching_key_keyswitch => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch,
gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace, // gglwe_switching_key_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_gglwe_switching_key_keyswitch_inplace,
// GGLWE External Product // GGLWE External Product
gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product, // gglwe_switching_key_external_product => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product,
gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace, // gglwe_switching_key_external_product_inplace => crate::tests::test_suite::external_product::test_gglwe_switching_key_external_product_inplace,
// GGLWE Automorphism // GGLWE Automorphism
gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism, // gglwe_automorphism_key_automorphism => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism,
gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace, // gglwe_automorphism_key_automorphism_inplace => crate::tests::test_suite::automorphism::test_gglwe_automorphism_key_automorphism_inplace,
// GGSW Encryption // GGSW Encryption
ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk, // ggsw_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_encrypt_sk,
ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk, // ggsw_compressed_encrypt_sk => crate::tests::test_suite::encryption::test_ggsw_compressed_encrypt_sk,
// GGSW Keyswitching // GGSW Keyswitching
ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch, // ggsw_keyswitch => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch,
ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace, // ggsw_keyswitch_inplace => crate::tests::test_suite::keyswitch::test_ggsw_keyswitch_inplace,
// GGSW External Product // GGSW External Product
ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product, // ggsw_external_product => crate::tests::test_suite::external_product::test_ggsw_external_product,
ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace, // ggsw_external_product_inplace => crate::tests::test_suite::external_product::test_ggsw_external_product_inplace,
// GGSW Automorphism // GGSW Automorphism
ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism, // ggsw_automorphism => crate::tests::test_suite::automorphism::test_ggsw_automorphism,
ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace, // ggsw_automorphism_inplace => crate::tests::test_suite::automorphism::test_ggsw_automorphism_inplace,
// LWE // LWE
lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch, // lwe_keyswitch => crate::tests::test_suite::keyswitch::test_lwe_keyswitch,
glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe, // glwe_to_lwe => crate::tests::test_suite::test_glwe_to_lwe,
lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe, // lwe_to_glwe => crate::tests::test_suite::test_lwe_to_glwe,
} // }
); // );

View File

@@ -1,4 +1,5 @@
use poulpy_hal::test_suite::serialization::test_reader_writer_interface; use poulpy_backend::FFT64Ref;
use poulpy_hal::{api::ModuleNew, layouts::Module, test_suite::serialization::test_reader_writer_interface};
use crate::layouts::{ use crate::layouts::{
AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE, AutomorphismKey, Base2K, Degree, Dnum, Dsize, GGLWE, GGSW, GLWE, GLWESwitchingKey, GLWEToLWESwitchingKey, LWE,
@@ -20,123 +21,143 @@ const DSIZE: Dsize = Dsize(1);
#[test] #[test]
fn glwe_serialization() { fn glwe_serialization() {
let original: GLWE<Vec<u8>> = GLWE::alloc(N_GLWE, BASE2K, K, RANK); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GLWE<Vec<u8>> = GLWE::alloc(&module, BASE2K, K, RANK);
poulpy_hal::test_suite::serialization::test_reader_writer_interface(original); poulpy_hal::test_suite::serialization::test_reader_writer_interface(original);
} }
#[test] #[test]
fn glwe_compressed_serialization() { fn glwe_compressed_serialization() {
let original: GLWECompressed<Vec<u8>> = GLWECompressed::alloc(N_GLWE, BASE2K, K, RANK); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GLWECompressed<Vec<u8>> = GLWECompressed::alloc(&module, BASE2K, K, RANK);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn lwe_serialization() { fn lwe_serialization() {
let original: LWE<Vec<u8>> = LWE::alloc(N_LWE, BASE2K, K); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: LWE<Vec<u8>> = LWE::alloc(&module, N_LWE, BASE2K, K);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn lwe_compressed_serialization() { fn lwe_compressed_serialization() {
let original: LWECompressed<Vec<u8>> = LWECompressed::alloc(BASE2K, K); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: LWECompressed<Vec<u8>> = LWECompressed::alloc(&module, BASE2K, K);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_gglwe_serialization() { fn test_gglwe_serialization() {
let original: GGLWE<Vec<u8>> = GGLWE::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GGLWE<Vec<u8>> = GGLWE::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_gglwe_compressed_serialization() { fn test_gglwe_compressed_serialization() {
let original: GGLWECompressed<Vec<u8>> = GGLWECompressed::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GGLWECompressed<Vec<u8>> = GGLWECompressed::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_glwe_switching_key_serialization() { fn test_glwe_switching_key_serialization() {
let original: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GLWESwitchingKey<Vec<u8>> = GLWESwitchingKey::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_glwe_switching_key_compressed_serialization() { fn test_glwe_switching_key_compressed_serialization() {
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GLWESwitchingKeyCompressed<Vec<u8>> = let original: GLWESwitchingKeyCompressed<Vec<u8>> =
GLWESwitchingKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, RANK, DNUM, DSIZE); GLWESwitchingKeyCompressed::alloc(&module, BASE2K, K, RANK, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_automorphism_key_serialization() { fn test_automorphism_key_serialization() {
let original: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: AutomorphismKey<Vec<u8>> = AutomorphismKey::alloc_with(&module, BASE2K, K, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_automorphism_key_compressed_serialization() { fn test_automorphism_key_compressed_serialization() {
let original: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: AutomorphismKeyCompressed<Vec<u8>> = AutomorphismKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_tensor_key_serialization() { fn test_tensor_key_serialization() {
let original: TensorKey<Vec<u8>> = TensorKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: TensorKey<Vec<u8>> = TensorKey::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn test_tensor_key_compressed_serialization() { fn test_tensor_key_compressed_serialization() {
let original: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: TensorKeyCompressed<Vec<u8>> = TensorKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn glwe_to_lwe_switching_key_serialization() { fn glwe_to_lwe_switching_key_serialization() {
let original: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GLWEToLWESwitchingKey<Vec<u8>> = GLWEToLWESwitchingKey::alloc(&module, BASE2K, K, RANK, DNUM);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn glwe_to_lwe_switching_key_compressed_serialization() { fn glwe_to_lwe_switching_key_compressed_serialization() {
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GLWEToLWESwitchingKeyCompressed<Vec<u8>> = let original: GLWEToLWESwitchingKeyCompressed<Vec<u8>> =
GLWEToLWESwitchingKeyCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM); GLWEToLWESwitchingKeyCompressed::alloc(&module, BASE2K, K, RANK, DNUM);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn lwe_to_glwe_switching_key_serialization() { fn lwe_to_glwe_switching_key_serialization() {
let original: LWEToGLWESwitchingKey<Vec<u8>> = LWEToGLWESwitchingKey::alloc(N_GLWE, BASE2K, K, RANK, DNUM); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: LWEToGLWESwitchingKey<Vec<u8>> = LWEToGLWESwitchingKey::alloc(&module, BASE2K, K, RANK, DNUM);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn lwe_to_glwe_switching_key_compressed_serialization() { fn lwe_to_glwe_switching_key_compressed_serialization() {
let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: LWEToGLWESwitchingKeyCompressed<Vec<u8>> = let original: LWEToGLWESwitchingKeyCompressed<Vec<u8>> =
LWEToGLWESwitchingKeyCompressed::alloc_with(N_GLWE, BASE2K, K, RANK, DNUM); LWEToGLWESwitchingKeyCompressed::alloc_with(&module, BASE2K, K, RANK, DNUM);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn lwe_switching_key_serialization() { fn lwe_switching_key_serialization() {
let original: LWESwitchingKey<Vec<u8>> = LWESwitchingKey::alloc(N_GLWE, BASE2K, K, DNUM); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: LWESwitchingKey<Vec<u8>> = LWESwitchingKey::alloc(&module, BASE2K, K, DNUM);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn lwe_switching_key_compressed_serialization() { fn lwe_switching_key_compressed_serialization() {
let original: LWESwitchingKeyCompressed<Vec<u8>> = LWESwitchingKeyCompressed::alloc(N_GLWE, BASE2K, K, DNUM); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: LWESwitchingKeyCompressed<Vec<u8>> = LWESwitchingKeyCompressed::alloc(&module, BASE2K, K, DNUM);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn ggsw_serialization() { fn ggsw_serialization() {
let original: GGSW<Vec<u8>> = GGSW::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GGSW<Vec<u8>> = GGSW::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }
#[test] #[test]
fn ggsw_compressed_serialization() { fn ggsw_compressed_serialization() {
let original: GGSWCompressed<Vec<u8>> = GGSWCompressed::alloc(N_GLWE, BASE2K, K, RANK, DNUM, DSIZE); let module: Module<FFT64Ref> = Module::<FFT64Ref>::new(N_GLWE.as_u32() as u64);
let original: GGSWCompressed<Vec<u8>> = GGSWCompressed::alloc(&module, BASE2K, K, RANK, DNUM, DSIZE);
test_reader_writer_interface(original); test_reader_writer_interface(original);
} }

View File

@@ -188,8 +188,8 @@ where
// Scratch space (4MB) // Scratch space (4MB)
let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(1 << 22); let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(1 << 22);
let n_glwe: poulpy_core::layouts::RingDegree = params.cbt_infos.layout_brk.n_glwe(); let n_glwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_glwe();
let n_lwe: poulpy_core::layouts::RingDegree = params.cbt_infos.layout_brk.n_lwe(); let n_lwe: poulpy_core::layouts::Degree = params.cbt_infos.layout_brk.n_lwe();
let rank: poulpy_core::layouts::Rank = params.cbt_infos.layout_brk.rank; let rank: poulpy_core::layouts::Rank = params.cbt_infos.layout_brk.rank;
let module: Module<B> = Module::<B>::new(n_glwe.as_u32() as u64); let module: Module<B> = Module::<B>::new(n_glwe.as_u32() as u64);

View File

@@ -38,7 +38,7 @@ impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintBlocks<D, T> {
self.blocks[0].k() self.blocks[0].k()
} }
fn n(&self) -> poulpy_core::layouts::RingDegree { fn n(&self) -> poulpy_core::layouts::Degree {
self.blocks[0].n() self.blocks[0].n()
} }
} }

View File

@@ -225,7 +225,7 @@ impl<D: DataRef, T: UnsignedInteger, B: Backend> LWEInfos for FheUintBlocksPrep<
self.blocks[0].k() self.blocks[0].k()
} }
fn n(&self) -> poulpy_core::layouts::RingDegree { fn n(&self) -> poulpy_core::layouts::Degree {
self.blocks[0].n() self.blocks[0].n()
} }
} }
@@ -256,7 +256,7 @@ impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintBlocksPrepDebug<D, T> {
self.blocks[0].k() self.blocks[0].k()
} }
fn n(&self) -> poulpy_core::layouts::RingDegree { fn n(&self) -> poulpy_core::layouts::Degree {
self.blocks[0].n() self.blocks[0].n()
} }
} }

View File

@@ -87,7 +87,7 @@ impl<D: DataRef, T: UnsignedInteger> LWEInfos for FheUintWord<D, T> {
self.0.k() self.0.k()
} }
fn n(&self) -> poulpy_core::layouts::RingDegree { fn n(&self) -> poulpy_core::layouts::Degree {
self.0.n() self.0.n()
} }
} }

View File

@@ -1,6 +1,6 @@
#[cfg(test)] #[cfg(test)]
use poulpy_core::layouts::{ use poulpy_core::layouts::{
AutomorphismKeyLayout, Base2K, Dnum, Dsize, GGSWLayout, GLWELayout, GLWEToLWEKeyLayout, Rank, RingDegree, TensorKeyLayout, AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GGSWLayout, GLWELayout, GLWEToLWEKeyLayout, Rank, TensorKeyLayout,
TorusPrecision, TorusPrecision,
}; };
@@ -26,7 +26,7 @@ pub(crate) const TEST_RANK: u32 = 2;
#[cfg(test)] #[cfg(test)]
pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout { pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout {
n: RingDegree(TEST_N_GLWE), n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K), base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(TEST_K_GLWE), k: TorusPrecision(TEST_K_GLWE),
rank: Rank(TEST_RANK), rank: Rank(TEST_RANK),
@@ -34,7 +34,7 @@ pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout {
#[cfg(test)] #[cfg(test)]
pub(crate) static TEST_GGSW_INFOS: GGSWLayout = GGSWLayout { pub(crate) static TEST_GGSW_INFOS: GGSWLayout = GGSWLayout {
n: RingDegree(TEST_N_GLWE), n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K), base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(TEST_K_GGSW), k: TorusPrecision(TEST_K_GGSW),
rank: Rank(TEST_RANK), rank: Rank(TEST_RANK),
@@ -46,15 +46,15 @@ pub(crate) static TEST_GGSW_INFOS: GGSWLayout = GGSWLayout {
pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout { pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout {
cbt: CircuitBootstrappingKeyLayout { cbt: CircuitBootstrappingKeyLayout {
layout_brk: BlindRotationKeyLayout { layout_brk: BlindRotationKeyLayout {
n_glwe: RingDegree(TEST_N_GLWE), n_glwe: Degree(TEST_N_GLWE),
n_lwe: RingDegree(TEST_N_LWE), n_lwe: Degree(TEST_N_LWE),
base2k: Base2K(TEST_BASE2K), base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(52), k: TorusPrecision(52),
dnum: Dnum(3), dnum: Dnum(3),
rank: Rank(TEST_RANK), rank: Rank(TEST_RANK),
}, },
layout_atk: AutomorphismKeyLayout { layout_atk: AutomorphismKeyLayout {
n: RingDegree(TEST_N_GLWE), n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K), base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(52), k: TorusPrecision(52),
rank: Rank(TEST_RANK), rank: Rank(TEST_RANK),
@@ -62,7 +62,7 @@ pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout {
dsize: Dsize(1), dsize: Dsize(1),
}, },
layout_tsk: TensorKeyLayout { layout_tsk: TensorKeyLayout {
n: RingDegree(TEST_N_GLWE), n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K), base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(52), k: TorusPrecision(52),
rank: Rank(TEST_RANK), rank: Rank(TEST_RANK),
@@ -71,7 +71,7 @@ pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout {
}, },
}, },
ks: GLWEToLWEKeyLayout { ks: GLWEToLWEKeyLayout {
n: RingDegree(TEST_N_GLWE), n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K), base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(39), k: TorusPrecision(39),
rank_in: Rank(TEST_RANK), rank_in: Rank(TEST_RANK),

View File

@@ -8,7 +8,7 @@ use std::{fmt, marker::PhantomData};
use poulpy_core::{ use poulpy_core::{
Distribution, Distribution,
layouts::{ layouts::{
Base2K, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, RingDegree, TorusPrecision, Base2K, Degree, Dnum, Dsize, GGSW, GGSWInfos, GLWEInfos, LWEInfos, LWESecret, Rank, TorusPrecision,
prepared::GLWESecretPrepared, prepared::GLWESecretPrepared,
}, },
}; };
@@ -19,8 +19,8 @@ use crate::tfhe::blind_rotation::BlindRotationAlgo;
#[derive(PartialEq, Eq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub struct BlindRotationKeyLayout { pub struct BlindRotationKeyLayout {
pub n_glwe: RingDegree, pub n_glwe: Degree,
pub n_lwe: RingDegree, pub n_lwe: Degree,
pub base2k: Base2K, pub base2k: Base2K,
pub k: TorusPrecision, pub k: TorusPrecision,
pub dnum: Dnum, pub dnum: Dnum,
@@ -28,11 +28,11 @@ pub struct BlindRotationKeyLayout {
} }
impl BlindRotationKeyInfos for BlindRotationKeyLayout { impl BlindRotationKeyInfos for BlindRotationKeyLayout {
fn n_glwe(&self) -> RingDegree { fn n_glwe(&self) -> Degree {
self.n_glwe self.n_glwe
} }
fn n_lwe(&self) -> RingDegree { fn n_lwe(&self) -> Degree {
self.n_lwe self.n_lwe
} }
} }
@@ -62,7 +62,7 @@ impl LWEInfos for BlindRotationKeyLayout {
self.k self.k
} }
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
self.n_glwe self.n_glwe
} }
} }
@@ -71,8 +71,8 @@ pub trait BlindRotationKeyInfos
where where
Self: GGSWInfos, Self: GGSWInfos,
{ {
fn n_glwe(&self) -> RingDegree; fn n_glwe(&self) -> Degree;
fn n_lwe(&self) -> RingDegree; fn n_lwe(&self) -> Degree;
} }
pub trait BlindRotationKeyAlloc { pub trait BlindRotationKeyAlloc {
@@ -178,12 +178,12 @@ impl<D: DataRef, BRT: BlindRotationAlgo> WriterTo for BlindRotationKey<D, BRT> {
} }
impl<D: DataRef, BRT: BlindRotationAlgo> BlindRotationKeyInfos for BlindRotationKey<D, BRT> { impl<D: DataRef, BRT: BlindRotationAlgo> BlindRotationKeyInfos for BlindRotationKey<D, BRT> {
fn n_glwe(&self) -> RingDegree { fn n_glwe(&self) -> Degree {
self.n() self.n()
} }
fn n_lwe(&self) -> RingDegree { fn n_lwe(&self) -> Degree {
RingDegree(self.keys.len() as u32) Degree(self.keys.len() as u32)
} }
} }
@@ -206,7 +206,7 @@ impl<D: DataRef, BRT: BlindRotationAlgo> LWEInfos for BlindRotationKey<D, BRT> {
self.keys[0].k() self.keys[0].k()
} }
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
self.keys[0].n() self.keys[0].n()
} }

View File

@@ -8,7 +8,7 @@ use std::{fmt, marker::PhantomData};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use poulpy_core::{ use poulpy_core::{
Distribution, Distribution,
layouts::{Base2K, Dsize, GGSWInfos, GLWEInfos, LWEInfos, RingDegree, TorusPrecision, compressed::GGSWCompressed}, layouts::{Base2K, Degree, Dsize, GGSWInfos, GLWEInfos, LWEInfos, TorusPrecision, compressed::GGSWCompressed},
}; };
use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyInfos}; use crate::tfhe::blind_rotation::{BlindRotationAlgo, BlindRotationKeyInfos};
@@ -94,17 +94,17 @@ impl<D: DataRef, BRT: BlindRotationAlgo> WriterTo for BlindRotationKeyCompressed
} }
impl<D: DataRef, BRA: BlindRotationAlgo> BlindRotationKeyInfos for BlindRotationKeyCompressed<D, BRA> { impl<D: DataRef, BRA: BlindRotationAlgo> BlindRotationKeyInfos for BlindRotationKeyCompressed<D, BRA> {
fn n_glwe(&self) -> RingDegree { fn n_glwe(&self) -> Degree {
self.n() self.n()
} }
fn n_lwe(&self) -> RingDegree { fn n_lwe(&self) -> Degree {
RingDegree(self.keys.len() as u32) Degree(self.keys.len() as u32)
} }
} }
impl<D: DataRef, BRA: BlindRotationAlgo> LWEInfos for BlindRotationKeyCompressed<D, BRA> { impl<D: DataRef, BRA: BlindRotationAlgo> LWEInfos for BlindRotationKeyCompressed<D, BRA> {
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
self.keys[0].n() self.keys[0].n()
} }

View File

@@ -8,7 +8,7 @@ use std::marker::PhantomData;
use poulpy_core::{ use poulpy_core::{
Distribution, Distribution,
layouts::{ layouts::{
Base2K, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, RingDegree, TorusPrecision, Base2K, Degree, Dnum, Dsize, GGSWInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
prepared::{GGSWPrepared, Prepare, PrepareAlloc}, prepared::{GGSWPrepared, Prepare, PrepareAlloc},
}, },
}; };
@@ -30,12 +30,12 @@ pub struct BlindRotationKeyPrepared<D: Data, BRT: BlindRotationAlgo, B: Backend>
} }
impl<D: Data, BRT: BlindRotationAlgo, B: Backend> BlindRotationKeyInfos for BlindRotationKeyPrepared<D, BRT, B> { impl<D: Data, BRT: BlindRotationAlgo, B: Backend> BlindRotationKeyInfos for BlindRotationKeyPrepared<D, BRT, B> {
fn n_glwe(&self) -> RingDegree { fn n_glwe(&self) -> Degree {
self.n() self.n()
} }
fn n_lwe(&self) -> RingDegree { fn n_lwe(&self) -> Degree {
RingDegree(self.data.len() as u32) Degree(self.data.len() as u32)
} }
} }
@@ -48,7 +48,7 @@ impl<D: Data, BRT: BlindRotationAlgo, B: Backend> LWEInfos for BlindRotationKeyP
self.data[0].k() self.data[0].k()
} }
fn n(&self) -> RingDegree { fn n(&self) -> Degree {
self.data[0].n() self.data[0].n()
} }