mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
wip
This commit is contained in:
@@ -5,7 +5,7 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{Base2K, BuildError, Degree, TorusPrecision};
|
||||
use crate::layouts::{Base2K, Degree, TorusPrecision};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
pub trait LWEInfos {
|
||||
@@ -153,82 +153,6 @@ impl LWECiphertext<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl LWECiphertextBuilder<Vec<u8>> {
|
||||
#[inline]
|
||||
pub fn layout<A>(mut self, layout: A) -> Self
|
||||
where
|
||||
A: LWEInfos,
|
||||
{
|
||||
self.data = Some(Zn::alloc((layout.n() + 1).into(), 1, layout.size()));
|
||||
self.base2k = Some(layout.base2k());
|
||||
self.k = Some(layout.k());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LWECiphertextBuilder<D: Data> {
|
||||
data: Option<Zn<D>>,
|
||||
base2k: Option<Base2K>,
|
||||
k: Option<TorusPrecision>,
|
||||
}
|
||||
|
||||
impl<D: Data> LWECiphertext<D> {
|
||||
#[inline]
|
||||
pub fn builder() -> LWECiphertextBuilder<D> {
|
||||
LWECiphertextBuilder {
|
||||
data: None,
|
||||
base2k: None,
|
||||
k: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> LWECiphertextBuilder<D> {
|
||||
#[inline]
|
||||
pub fn data(mut self, data: Zn<D>) -> Self {
|
||||
self.data = Some(data);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn base2k(mut self, base2k: Base2K) -> Self {
|
||||
self.base2k = Some(base2k);
|
||||
self
|
||||
}
|
||||
#[inline]
|
||||
pub fn k(mut self, k: TorusPrecision) -> Self {
|
||||
self.k = Some(k);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<LWECiphertext<D>, BuildError> {
|
||||
let data: Zn<D> = self.data.ok_or(BuildError::MissingData)?;
|
||||
let base2k: Base2K = self.base2k.ok_or(BuildError::MissingBase2K)?;
|
||||
let k: TorusPrecision = self.k.ok_or(BuildError::MissingK)?;
|
||||
|
||||
if base2k.0 == 0 {
|
||||
return Err(BuildError::ZeroBase2K);
|
||||
}
|
||||
|
||||
if k.0 == 0 {
|
||||
return Err(BuildError::ZeroTorusPrecision);
|
||||
}
|
||||
|
||||
if data.n() == 0 {
|
||||
return Err(BuildError::ZeroDegree);
|
||||
}
|
||||
|
||||
if data.cols() == 0 {
|
||||
return Err(BuildError::ZeroCols);
|
||||
}
|
||||
|
||||
if data.size() == 0 {
|
||||
return Err(BuildError::ZeroLimbs);
|
||||
}
|
||||
|
||||
Ok(LWECiphertext { data, base2k, k })
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LWECiphertextToRef {
|
||||
fn to_ref(&self) -> LWECiphertext<&[u8]>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user