fixed encryption

This commit is contained in:
Pro7ech
2025-10-19 18:11:04 +02:00
parent d6e9805a8f
commit a706b759d6
17 changed files with 289 additions and 196 deletions

View File

@@ -4,8 +4,9 @@ use poulpy_hal::{
};
use crate::{
GetDistribution, GetDistributionMut,
dist::Distribution,
layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision},
layouts::{Base2K, Degree, GLWEInfos, GLWEPublicKey, GLWEPublicKeyToRef, GetDegree, LWEInfos, Rank, TorusPrecision},
};
#[derive(PartialEq, Eq)]
@@ -16,13 +17,15 @@ pub struct GLWEPublicKeyPrepared<D: Data, B: Backend> {
pub(crate) dist: Distribution,
}
pub trait SetDist {
fn set_dist(&mut self, dist: Distribution);
impl<D: DataRef, BE: Backend> GetDistribution for GLWEPublicKeyPrepared<D, BE> {
fn dist(&self) -> &Distribution {
&self.dist
}
}
impl<D: Data, B: Backend> SetDist for GLWEPublicKeyPrepared<D, B> {
fn set_dist(&mut self, dist: Distribution) {
self.dist = dist
impl<D: DataMut, BE: Backend> GetDistributionMut for GLWEPublicKeyPrepared<D, BE> {
fn dist_mut(&mut self) -> &mut Distribution {
&mut self.dist
}
}
@@ -122,8 +125,8 @@ where
{
fn prepare_glwe_public_key<R, O>(&self, res: &mut R, other: &O)
where
R: GLWEPublicKeyPreparedToMut<B> + SetDist,
O: GLWEPublicKeyToRef + GetDist,
R: GLWEPublicKeyPreparedToMut<B> + GetDistributionMut,
O: GLWEPublicKeyToRef + GetDistribution,
{
{
let mut res: GLWEPublicKeyPrepared<&mut [u8], B> = res.to_mut();
@@ -140,7 +143,7 @@ where
}
}
res.set_dist(other.get_dist());
*res.dist_mut() = *other.dist();
}
}
@@ -149,7 +152,7 @@ impl<B: Backend> GLWEPublicKeyPrepare<B> for Module<B> where Self: GetDegree + V
impl<D: DataMut, B: Backend> GLWEPublicKeyPrepared<D, B> {
pub fn prepare<O, M>(&mut self, module: &M, other: &O)
where
O: GLWEPublicKeyToRef + GetDist,
O: GLWEPublicKeyToRef + GetDistribution,
M: GLWEPublicKeyPrepare<B>,
{
module.prepare_glwe_public_key(self, other);

View File

@@ -4,11 +4,9 @@ use poulpy_hal::{
};
use crate::{
GetDistribution, GetDistributionMut,
dist::Distribution,
layouts::{
Base2K, Degree, GLWEInfos, GLWESecret, GLWESecretToRef, GetDegree, GetDist, LWEInfos, Rank, TorusPrecision,
prepared::SetDist,
},
layouts::{Base2K, Degree, GLWEInfos, GLWESecret, GLWESecretToRef, GetDegree, LWEInfos, Rank, TorusPrecision},
};
pub struct GLWESecretPrepared<D: Data, B: Backend> {
@@ -16,9 +14,15 @@ pub struct GLWESecretPrepared<D: Data, B: Backend> {
pub(crate) dist: Distribution,
}
impl<D: DataRef, B: Backend> SetDist for GLWESecretPrepared<D, B> {
fn set_dist(&mut self, dist: Distribution) {
self.dist = dist
impl<D: DataRef, BE: Backend> GetDistribution for GLWESecretPrepared<D, BE> {
fn dist(&self) -> &Distribution {
&self.dist
}
}
impl<D: DataMut, BE: Backend> GetDistributionMut for GLWESecretPrepared<D, BE> {
fn dist_mut(&mut self) -> &mut Distribution {
&mut self.dist
}
}
@@ -125,8 +129,8 @@ where
{
fn prepare_glwe_secret<R, O>(&self, res: &mut R, other: &O)
where
R: GLWESecretPreparedToMut<B> + SetDist,
O: GLWESecretToRef + GetDist,
R: GLWESecretPreparedToMut<B> + GetDistributionMut,
O: GLWESecretToRef + GetDistribution,
{
{
let mut res: GLWESecretPrepared<&mut [u8], _> = res.to_mut();
@@ -137,7 +141,7 @@ where
}
}
res.set_dist(other.get_dist());
*res.dist_mut() = *other.dist();
}
}
@@ -147,7 +151,7 @@ impl<D: DataMut, B: Backend> GLWESecretPrepared<D, B> {
pub fn prepare<M, O>(&mut self, module: &M, other: &O)
where
M: GLWESecretPrepare<B>,
O: GLWESecretToRef + GetDist,
O: GLWESecretToRef + GetDistribution,
{
module.prepare_glwe_secret(self, other);
}