mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
wip
This commit is contained in:
@@ -5,20 +5,20 @@ use poulpy_hal::{
|
||||
};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWESwitchingKey, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKey, LWEInfos, Rank, TorusPrecision,
|
||||
compressed::{Decompress, GGLWECiphertextCompressed, GGLWECiphertextCompressedToMut, GGLWECiphertextCompressedToRef},
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct GGLWEKeyCompressed<D: Data> {
|
||||
pub struct GLWESwitchingKeyCompressed<D: Data> {
|
||||
pub(crate) key: GGLWECiphertextCompressed<D>,
|
||||
pub(crate) sk_in_n: usize, // Degree of sk_in
|
||||
pub(crate) sk_out_n: usize, // Degree of sk_out
|
||||
}
|
||||
|
||||
impl<D: Data> LWEInfos for GGLWEKeyCompressed<D> {
|
||||
impl<D: Data> LWEInfos for GLWESwitchingKeyCompressed<D> {
|
||||
fn n(&self) -> Degree {
|
||||
self.key.n()
|
||||
}
|
||||
@@ -35,13 +35,13 @@ impl<D: Data> LWEInfos for GGLWEKeyCompressed<D> {
|
||||
self.key.size()
|
||||
}
|
||||
}
|
||||
impl<D: Data> GLWEInfos for GGLWEKeyCompressed<D> {
|
||||
impl<D: Data> GLWEInfos for GLWESwitchingKeyCompressed<D> {
|
||||
fn rank(&self) -> Rank {
|
||||
self.rank_out()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> GGLWEInfos for GGLWEKeyCompressed<D> {
|
||||
impl<D: Data> GGLWEInfos for GLWESwitchingKeyCompressed<D> {
|
||||
fn rank_in(&self) -> Rank {
|
||||
self.key.rank_in()
|
||||
}
|
||||
@@ -59,19 +59,19 @@ impl<D: Data> GGLWEInfos for GGLWEKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Debug for GGLWEKeyCompressed<D> {
|
||||
impl<D: DataRef> fmt::Debug for GLWESwitchingKeyCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{self}")
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> FillUniform for GGLWEKeyCompressed<D> {
|
||||
impl<D: DataMut> FillUniform for GLWESwitchingKeyCompressed<D> {
|
||||
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
||||
self.key.fill_uniform(log_bound, source);
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> fmt::Display for GGLWEKeyCompressed<D> {
|
||||
impl<D: DataRef> fmt::Display for GLWESwitchingKeyCompressed<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
@@ -81,12 +81,12 @@ impl<D: DataRef> fmt::Display for GGLWEKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GGLWEKeyCompressed<Vec<u8>> {
|
||||
impl GLWESwitchingKeyCompressed<Vec<u8>> {
|
||||
pub fn alloc<A>(infos: &A) -> Self
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
GGLWEKeyCompressed {
|
||||
GLWESwitchingKeyCompressed {
|
||||
key: GGLWECiphertextCompressed::alloc(infos),
|
||||
sk_in_n: 0,
|
||||
sk_out_n: 0,
|
||||
@@ -102,7 +102,7 @@ impl GGLWEKeyCompressed<Vec<u8>> {
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> Self {
|
||||
GGLWEKeyCompressed {
|
||||
GLWESwitchingKeyCompressed {
|
||||
key: GGLWECiphertextCompressed::alloc_with(n, base2k, k, rank_in, rank_out, dnum, dsize),
|
||||
sk_in_n: 0,
|
||||
sk_out_n: 0,
|
||||
@@ -121,7 +121,7 @@ impl GGLWEKeyCompressed<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut> ReaderFrom for GGLWEKeyCompressed<D> {
|
||||
impl<D: DataMut> ReaderFrom for GLWESwitchingKeyCompressed<D> {
|
||||
fn read_from<R: std::io::Read>(&mut self, reader: &mut R) -> std::io::Result<()> {
|
||||
self.sk_in_n = reader.read_u64::<LittleEndian>()? as usize;
|
||||
self.sk_out_n = reader.read_u64::<LittleEndian>()? as usize;
|
||||
@@ -129,7 +129,7 @@ impl<D: DataMut> ReaderFrom for GGLWEKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> WriterTo for GGLWEKeyCompressed<D> {
|
||||
impl<D: DataRef> WriterTo for GLWESwitchingKeyCompressed<D> {
|
||||
fn write_to<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
|
||||
writer.write_u64::<LittleEndian>(self.sk_in_n as u64)?;
|
||||
writer.write_u64::<LittleEndian>(self.sk_out_n as u64)?;
|
||||
@@ -137,27 +137,27 @@ impl<D: DataRef> WriterTo for GGLWEKeyCompressed<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWEKeyCompressed<DR>> for GGLWESwitchingKey<D>
|
||||
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GLWESwitchingKeyCompressed<DR>> for GLWESwitchingKey<D>
|
||||
where
|
||||
Module<B>: VecZnxFillUniform + VecZnxCopy,
|
||||
{
|
||||
fn decompress(&mut self, module: &Module<B>, other: &GGLWEKeyCompressed<DR>) {
|
||||
fn decompress(&mut self, module: &Module<B>, other: &GLWESwitchingKeyCompressed<DR>) {
|
||||
self.key.decompress(module, &other.key);
|
||||
self.sk_in_n = other.sk_in_n;
|
||||
self.sk_out_n = other.sk_out_n;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GGLWEKeyCompressedToMut {
|
||||
fn to_mut(&mut self) -> GGLWEKeyCompressed<&mut [u8]>;
|
||||
pub trait GLWESwitchingKeyCompressedToMut {
|
||||
fn to_mut(&mut self) -> GLWESwitchingKeyCompressed<&mut [u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> GGLWEKeyCompressedToMut for GGLWEKeyCompressed<D>
|
||||
impl<D: DataMut> GLWESwitchingKeyCompressedToMut for GLWESwitchingKeyCompressed<D>
|
||||
where
|
||||
GGLWECiphertextCompressed<D>: GGLWECiphertextCompressedToMut,
|
||||
{
|
||||
fn to_mut(&mut self) -> GGLWEKeyCompressed<&mut [u8]> {
|
||||
GGLWEKeyCompressed {
|
||||
fn to_mut(&mut self) -> GLWESwitchingKeyCompressed<&mut [u8]> {
|
||||
GLWESwitchingKeyCompressed {
|
||||
sk_in_n: self.sk_in_n,
|
||||
sk_out_n: self.sk_out_n,
|
||||
key: self.key.to_mut(),
|
||||
@@ -165,16 +165,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GGLWEKeyCompressedToRef {
|
||||
fn to_ref(&self) -> GGLWEKeyCompressed<&[u8]>;
|
||||
pub trait GLWESwitchingKeyCompressedToRef {
|
||||
fn to_ref(&self) -> GLWESwitchingKeyCompressed<&[u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> GGLWEKeyCompressedToRef for GGLWEKeyCompressed<D>
|
||||
impl<D: DataRef> GLWESwitchingKeyCompressedToRef for GLWESwitchingKeyCompressed<D>
|
||||
where
|
||||
GGLWECiphertextCompressed<D>: GGLWECiphertextCompressedToRef,
|
||||
{
|
||||
fn to_ref(&self) -> GGLWEKeyCompressed<&[u8]> {
|
||||
GGLWEKeyCompressed {
|
||||
fn to_ref(&self) -> GLWESwitchingKeyCompressed<&[u8]> {
|
||||
GLWESwitchingKeyCompressed {
|
||||
sk_in_n: self.sk_in_n,
|
||||
sk_out_n: self.sk_out_n,
|
||||
key: self.key.to_ref(),
|
||||
|
||||
Reference in New Issue
Block a user