mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
some fixes
This commit is contained in:
@@ -371,3 +371,19 @@ impl VecZnxToRef for VecZnx<&[u8]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<DataSelf> VecZnx<DataSelf>
|
||||||
|
where
|
||||||
|
VecZnx<DataSelf>: VecZnxToRef,
|
||||||
|
{
|
||||||
|
pub fn clone(&self) -> VecZnx<Vec<u8>> {
|
||||||
|
let self_ref: VecZnx<&[u8]> = self.to_ref();
|
||||||
|
|
||||||
|
VecZnx {
|
||||||
|
data: self_ref.data.to_vec(),
|
||||||
|
n: self_ref.n,
|
||||||
|
cols: self_ref.cols,
|
||||||
|
size: self_ref.size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use crate::{
|
|||||||
elem::{Infos, SetMetaData},
|
elem::{Infos, SetMetaData},
|
||||||
ggsw_ciphertext::GGSWCiphertext,
|
ggsw_ciphertext::GGSWCiphertext,
|
||||||
glwe_ciphertext_fourier::GLWECiphertextFourier,
|
glwe_ciphertext_fourier::GLWECiphertextFourier,
|
||||||
glwe_ops::GLWEOps,
|
|
||||||
glwe_plaintext::GLWEPlaintext,
|
glwe_plaintext::GLWEPlaintext,
|
||||||
keys::{GLWEPublicKey, SecretDistribution, SecretKeyFourier},
|
keys::{GLWEPublicKey, SecretDistribution, SecretKeyFourier},
|
||||||
keyswitch_key::GLWESwitchingKey,
|
keyswitch_key::GLWESwitchingKey,
|
||||||
@@ -215,8 +214,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DataSelf> GLWEOps<FFT64> for GLWECiphertext<DataSelf> where VecZnx<DataSelf>: VecZnxToMut {}
|
|
||||||
|
|
||||||
impl<DataSelf> GLWECiphertext<DataSelf>
|
impl<DataSelf> GLWECiphertext<DataSelf>
|
||||||
where
|
where
|
||||||
VecZnx<DataSelf>: VecZnxToMut,
|
VecZnx<DataSelf>: VecZnxToMut,
|
||||||
@@ -713,6 +710,14 @@ impl<DataSelf> GLWECiphertext<DataSelf>
|
|||||||
where
|
where
|
||||||
VecZnx<DataSelf>: VecZnxToRef,
|
VecZnx<DataSelf>: VecZnxToRef,
|
||||||
{
|
{
|
||||||
|
pub fn clone(&self) -> GLWECiphertext<Vec<u8>> {
|
||||||
|
GLWECiphertext {
|
||||||
|
data: self.data.clone(),
|
||||||
|
basek: self.basek(),
|
||||||
|
k: self.k(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn decrypt<DataPt, DataSk>(
|
pub fn decrypt<DataPt, DataSk>(
|
||||||
&self,
|
&self,
|
||||||
module: &Module<FFT64>,
|
module: &Module<FFT64>,
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
use backend::{Backend, Module, Scratch, VecZnx, VecZnxOps, VecZnxToMut, VecZnxToRef, ZnxZero};
|
use backend::{FFT64, Module, Scratch, VecZnx, VecZnxOps, VecZnxToMut, VecZnxToRef, ZnxZero};
|
||||||
|
|
||||||
use crate::elem::{Infos, SetMetaData};
|
use crate::{
|
||||||
|
elem::{Infos, SetMetaData},
|
||||||
|
glwe_ciphertext::GLWECiphertext,
|
||||||
|
};
|
||||||
|
|
||||||
pub trait GLWEOps<BACKEND: Backend>
|
impl<DataSelf> GLWECiphertext<DataSelf>
|
||||||
where
|
where
|
||||||
Self: Sized + VecZnxToMut + SetMetaData + Infos,
|
Self: Infos,
|
||||||
|
VecZnx<DataSelf>: VecZnxToMut,
|
||||||
{
|
{
|
||||||
fn add<A, B>(&mut self, module: &Module<BACKEND>, a: &A, b: &B)
|
pub fn add<A, B>(&mut self, module: &Module<FFT64>, a: &A, b: &B)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
B: VecZnxToRef + Infos,
|
B: VecZnxToRef + Infos,
|
||||||
@@ -50,7 +54,7 @@ where
|
|||||||
self.set_k(a.k().max(b.k()));
|
self.set_k(a.k().max(b.k()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_inplace<A>(&mut self, module: &Module<BACKEND>, a: &A)
|
pub fn add_inplace<A>(&mut self, module: &Module<FFT64>, a: &A)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
{
|
{
|
||||||
@@ -69,7 +73,7 @@ where
|
|||||||
self.set_k(a.k().max(self.k()));
|
self.set_k(a.k().max(self.k()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub<A, B>(&mut self, module: &Module<BACKEND>, a: &A, b: &B)
|
pub fn sub<A, B>(&mut self, module: &Module<FFT64>, a: &A, b: &B)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
B: VecZnxToRef + Infos,
|
B: VecZnxToRef + Infos,
|
||||||
@@ -114,7 +118,7 @@ where
|
|||||||
self.set_k(a.k().max(b.k()));
|
self.set_k(a.k().max(b.k()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub_inplace_ab<A>(&mut self, module: &Module<BACKEND>, a: &A)
|
pub fn sub_inplace_ab<A>(&mut self, module: &Module<FFT64>, a: &A)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
{
|
{
|
||||||
@@ -133,7 +137,7 @@ where
|
|||||||
self.set_k(a.k().max(self.k()));
|
self.set_k(a.k().max(self.k()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub_inplace_ba<A>(&mut self, module: &Module<BACKEND>, a: &A)
|
pub fn sub_inplace_ba<A>(&mut self, module: &Module<FFT64>, a: &A)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
{
|
{
|
||||||
@@ -152,7 +156,7 @@ where
|
|||||||
self.set_k(a.k().max(self.k()));
|
self.set_k(a.k().max(self.k()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotate<A>(&mut self, module: &Module<BACKEND>, k: i64, a: &A)
|
pub fn rotate<A>(&mut self, module: &Module<FFT64>, k: i64, a: &A)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
{
|
{
|
||||||
@@ -160,7 +164,6 @@ where
|
|||||||
{
|
{
|
||||||
assert_eq!(a.n(), module.n());
|
assert_eq!(a.n(), module.n());
|
||||||
assert_eq!(self.n(), module.n());
|
assert_eq!(self.n(), module.n());
|
||||||
assert_eq!(self.basek(), a.basek());
|
|
||||||
assert_eq!(self.rank(), a.rank())
|
assert_eq!(self.rank(), a.rank())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,10 +171,11 @@ where
|
|||||||
module.vec_znx_rotate(k, self, i, a, i);
|
module.vec_znx_rotate(k, self, i, a, i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.set_basek(a.basek());
|
||||||
self.set_k(a.k());
|
self.set_k(a.k());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_inplace<A>(&mut self, module: &Module<BACKEND>, k: i64)
|
pub fn rotate_inplace<A>(&mut self, module: &Module<FFT64>, k: i64)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
{
|
{
|
||||||
@@ -185,7 +189,7 @@ where
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy<A>(&mut self, module: &Module<BACKEND>, a: &A)
|
pub fn copy<A>(&mut self, module: &Module<FFT64>, a: &A)
|
||||||
where
|
where
|
||||||
A: VecZnxToRef + Infos,
|
A: VecZnxToRef + Infos,
|
||||||
{
|
{
|
||||||
@@ -193,11 +197,10 @@ where
|
|||||||
{
|
{
|
||||||
assert_eq!(self.n(), module.n());
|
assert_eq!(self.n(), module.n());
|
||||||
assert_eq!(a.n(), module.n());
|
assert_eq!(a.n(), module.n());
|
||||||
|
assert_eq!(self.rank(), a.rank());
|
||||||
}
|
}
|
||||||
|
|
||||||
let cols: usize = self.rank().min(a.rank()) + 1;
|
(0..self.rank() + 1).for_each(|i| {
|
||||||
|
|
||||||
(0..cols).for_each(|i| {
|
|
||||||
module.vec_znx_copy(self, i, a, i);
|
module.vec_znx_copy(self, i, a, i);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -205,9 +208,37 @@ where
|
|||||||
self.set_basek(a.basek());
|
self.set_basek(a.basek());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rsh(&mut self, k: usize, scratch: &mut Scratch) {
|
pub fn rsh(&mut self, k: usize, scratch: &mut Scratch) {
|
||||||
let basek: usize = self.basek();
|
let basek: usize = self.basek();
|
||||||
let mut self_mut: VecZnx<&mut [u8]> = self.to_mut();
|
let mut self_mut: VecZnx<&mut [u8]> = self.to_mut();
|
||||||
self_mut.rsh(basek, k, scratch);
|
self_mut.rsh(basek, k, scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn normalize<A>(&mut self, module: &Module<FFT64>, a: &A, scratch: &mut Scratch)
|
||||||
|
where
|
||||||
|
A: VecZnxToMut + Infos,
|
||||||
|
{
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
|
assert_eq!(self.n(), module.n());
|
||||||
|
assert_eq!(a.n(), module.n());
|
||||||
|
assert_eq!(self.rank(), a.rank());
|
||||||
|
}
|
||||||
|
|
||||||
|
(0..self.rank() + 1).for_each(|i| {
|
||||||
|
module.vec_znx_normalize(a.basek(), self, i, a, i, scratch);
|
||||||
|
});
|
||||||
|
self.set_basek(a.basek());
|
||||||
|
self.set_k(a.k());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn normalize_inplace(&mut self, module: &Module<FFT64>, scratch: &mut Scratch) {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
|
assert_eq!(self.n(), module.n());
|
||||||
|
}
|
||||||
|
(0..self.rank() + 1).for_each(|i| {
|
||||||
|
module.vec_znx_normalize_inplace(self.basek(), self, i, scratch);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use backend::{FFT64, MatZnxDft, MatZnxDftToRef, Module, Scratch, VecZnx, VecZnxToMut, VecZnxToRef};
|
use backend::{FFT64, MatZnxDft, MatZnxDftToRef, Module, Scratch, VecZnx, VecZnxToMut, VecZnxToRef};
|
||||||
|
|
||||||
use crate::{automorphism::AutomorphismKey, glwe_ciphertext::GLWECiphertext, glwe_ops::GLWEOps};
|
use crate::{automorphism::AutomorphismKey, glwe_ciphertext::GLWECiphertext};
|
||||||
|
|
||||||
impl GLWECiphertext<Vec<u8>> {
|
impl GLWECiphertext<Vec<u8>> {
|
||||||
pub fn trace_galois_elements(module: &Module<FFT64>) -> Vec<i64> {
|
pub fn trace_galois_elements(module: &Module<FFT64>) -> Vec<i64> {
|
||||||
|
|||||||
Reference in New Issue
Block a user