Add Zn type

This commit is contained in:
Pro7ech
2025-08-21 12:16:53 +02:00
parent ccd94e36cc
commit bf513dc555
129 changed files with 1400 additions and 686 deletions

View File

@@ -106,11 +106,11 @@ impl<D: DataRef> WriterTo for GGLWEAutomorphismKeyCompressed<D> {
}
}
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWEAutomorphismKeyCompressed<DR>> for GGLWEAutomorphismKey<D> {
fn decompress(&mut self, module: &Module<B>, other: &GGLWEAutomorphismKeyCompressed<DR>)
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWEAutomorphismKeyCompressed<DR>> for GGLWEAutomorphismKey<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &GGLWEAutomorphismKeyCompressed<DR>) {
self.key.decompress(module, &other.key);
self.p = other.p;
}

View File

@@ -194,11 +194,11 @@ impl<D: DataRef> WriterTo for GGLWECiphertextCompressed<D> {
}
}
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGLWECiphertextCompressed<DR>> for GGLWECiphertext<D> {
fn decompress(&mut self, module: &Module<B>, other: &GGLWECiphertextCompressed<DR>)
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGLWECiphertextCompressed<DR>> for GGLWECiphertext<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &GGLWECiphertextCompressed<DR>) {
#[cfg(debug_assertions)]
{
use poulpy_hal::api::ZnxInfos;

View File

@@ -115,11 +115,11 @@ impl<D: DataRef> WriterTo for GGLWESwitchingKeyCompressed<D> {
}
}
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWESwitchingKeyCompressed<DR>> for GGLWESwitchingKey<D> {
fn decompress(&mut self, module: &Module<B>, other: &GGLWESwitchingKeyCompressed<DR>)
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWESwitchingKeyCompressed<DR>> for GGLWESwitchingKey<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &GGLWESwitchingKeyCompressed<DR>) {
self.key.decompress(module, &other.key);
self.sk_in_n = other.sk_in_n;
self.sk_out_n = other.sk_out_n;

View File

@@ -139,11 +139,11 @@ impl<D: DataMut> GGLWETensorKeyCompressed<D> {
}
}
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWETensorKeyCompressed<DR>> for GGLWETensorKey<D> {
fn decompress(&mut self, module: &Module<B>, other: &GGLWETensorKeyCompressed<DR>)
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, GGLWETensorKeyCompressed<DR>> for GGLWETensorKey<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &GGLWETensorKeyCompressed<DR>) {
#[cfg(debug_assertions)]
{
assert_eq!(

View File

@@ -185,11 +185,11 @@ impl<D: DataRef> WriterTo for GGSWCiphertextCompressed<D> {
}
}
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGSWCiphertextCompressed<DR>> for GGSWCiphertext<D> {
fn decompress(&mut self, module: &Module<B>, other: &GGSWCiphertextCompressed<DR>)
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GGSWCiphertextCompressed<DR>> for GGSWCiphertext<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &GGSWCiphertextCompressed<DR>) {
#[cfg(debug_assertions)]
{
assert_eq!(self.rank(), other.rank())

View File

@@ -111,11 +111,11 @@ impl<D: DataRef> WriterTo for GLWECiphertextCompressed<D> {
}
}
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D> {
fn decompress(&mut self, module: &Module<B>, other: &GLWECiphertextCompressed<DR>)
where
Module<B>: VecZnxCopy + VecZnxFillUniform,
{
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, GLWECiphertextCompressed<DR>> for GLWECiphertext<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &GLWECiphertextCompressed<DR>) {
#[cfg(debug_assertions)]
{
use poulpy_hal::api::ZnxInfos;

View File

@@ -93,7 +93,7 @@ impl GLWEToLWESwitchingKeyCompressed<Vec<u8>> {
))
}
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_in: usize) -> usize
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, basek: usize, k: usize, rank_in: usize) -> usize
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -112,6 +112,6 @@ impl GLWEToLWESwitchingKeyCompressed<Vec<u8>> {
+ SvpPPolAllocBytes
+ SvpPPolAlloc<B>,
{
GLWEToLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_in)
GLWEToLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k, rank_in)
}
}

View File

@@ -1,7 +1,7 @@
use std::fmt;
use poulpy_hal::{
api::{FillUniform, Reset, VecZnxFillUniform, ZnxInfos, ZnxView, ZnxViewMut},
api::{FillUniform, Reset, ZnFillUniform, ZnxInfos, ZnxView, ZnxViewMut},
layouts::{Backend, Data, DataMut, DataRef, Module, ReaderFrom, VecZnx, WriterTo},
source::Source,
};
@@ -117,13 +117,20 @@ impl<D: DataRef> WriterTo for LWECiphertextCompressed<D> {
}
}
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, LWECiphertextCompressed<DR>> for LWECiphertext<D> {
fn decompress(&mut self, module: &Module<B>, other: &LWECiphertextCompressed<DR>)
where
Module<B>: VecZnxFillUniform,
{
let mut source = Source::new(other.seed);
module.vec_znx_fill_uniform(other.basek(), &mut self.data, 0, other.k(), &mut source);
impl<D: DataMut, B: Backend, DR: DataRef> Decompress<B, LWECiphertextCompressed<DR>> for LWECiphertext<D>
where
Module<B>: ZnFillUniform,
{
fn decompress(&mut self, module: &Module<B>, other: &LWECiphertextCompressed<DR>) {
let mut source: Source = Source::new(other.seed);
module.zn_fill_uniform(
self.n(),
other.basek(),
&mut self.data,
0,
other.k(),
&mut source,
);
(0..self.size()).for_each(|i| {
self.data.at_mut(0, i)[0] = other.data.at(0, i)[0];
});

View File

@@ -94,7 +94,7 @@ impl LWESwitchingKeyCompressed<Vec<u8>> {
))
}
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize) -> usize
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, basek: usize, k: usize) -> usize
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -113,15 +113,15 @@ impl LWESwitchingKeyCompressed<Vec<u8>> {
+ SvpPPolAllocBytes
+ SvpPPolAlloc<B>,
{
LWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k)
LWESwitchingKey::encrypt_sk_scratch_space(module, basek, k)
}
}
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWESwitchingKeyCompressed<DR>> for LWESwitchingKey<D> {
fn decompress(&mut self, module: &Module<B>, other: &LWESwitchingKeyCompressed<DR>)
where
Module<B>: VecZnxCopy + VecZnxFillUniform,
{
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWESwitchingKeyCompressed<DR>> for LWESwitchingKey<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &LWESwitchingKeyCompressed<DR>) {
self.0.decompress(module, &other.0);
}
}

View File

@@ -95,7 +95,7 @@ impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
))
}
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, n: usize, basek: usize, k: usize, rank_out: usize) -> usize
pub fn encrypt_sk_scratch_space<B: Backend>(module: &Module<B>, basek: usize, k: usize, rank_out: usize) -> usize
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
@@ -114,15 +114,15 @@ impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
+ SvpPPolAllocBytes
+ SvpPPolAlloc<B>,
{
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, n, basek, k, rank_out)
LWEToGLWESwitchingKey::encrypt_sk_scratch_space(module, basek, k, rank_out)
}
}
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWEToGLWESwitchingKeyCompressed<DR>> for LWEToGLWESwitchingKey<D> {
fn decompress(&mut self, module: &Module<B>, other: &LWEToGLWESwitchingKeyCompressed<DR>)
where
Module<B>: VecZnxCopy + VecZnxFillUniform,
{
impl<D: DataMut, DR: DataRef, B: Backend> Decompress<B, LWEToGLWESwitchingKeyCompressed<DR>> for LWEToGLWESwitchingKey<D>
where
Module<B>: VecZnxFillUniform + VecZnxCopy,
{
fn decompress(&mut self, module: &Module<B>, other: &LWEToGLWESwitchingKeyCompressed<DR>) {
self.0.decompress(module, &other.0);
}
}

View File

@@ -20,13 +20,8 @@ pub use lwe_ct::*;
pub use lwe_ksk::*;
pub use lwe_to_glwe_ksk::*;
use poulpy_hal::{
api::{VecZnxCopy, VecZnxFillUniform},
layouts::{Backend, Module},
};
use poulpy_hal::layouts::{Backend, Module};
pub trait Decompress<B: Backend, C> {
fn decompress(&mut self, module: &Module<B>, other: &C)
where
Module<B>: VecZnxFillUniform + VecZnxCopy;
fn decompress(&mut self, module: &Module<B>, other: &C);
}