keyswitch tests

This commit is contained in:
Pro7ech
2025-10-20 15:32:52 +02:00
parent 0c894c19db
commit 252eda36fe
60 changed files with 918 additions and 945 deletions

View File

@@ -119,10 +119,6 @@ where
+ VmpApplyDftToDftTmpBytes
+ VecZnxBigBytesOf
+ VecZnxNormalizeTmpBytes
+ VecZnxDftBytesOf
+ VmpApplyDftToDftTmpBytes
+ VecZnxBigBytesOf
+ VecZnxNormalizeTmpBytes
+ VecZnxDftApply<BE>
+ VecZnxDftCopy<BE>
+ VmpApplyDftToDft<BE>
@@ -236,7 +232,7 @@ where
// =
// (-(x0s0 + x1s1 + x2s2) + s0(a0s0 + a1s1 + a2s2), x0, x1, x2)
for col_i in 1..cols {
let pmat: &VmpPMat<&[u8], BE> = &tsk.at(col_i - 1, col_j - 1).key.data; // Selects Enc(s[i]s[j])
let pmat: &VmpPMat<&[u8], BE> = &tsk.at(col_i - 1, col_j - 1).data; // Selects Enc(s[i]s[j])
// Extracts a[i] and multipies with Enc(s[i]s[j])
for di in 0..dsize {

View File

@@ -5,10 +5,7 @@ use poulpy_hal::{
use crate::{
GLWEKeyswitch, ScratchTakeCore,
layouts::{
GGLWEInfos, GLWE, GLWEInfos, GLWELayout, GLWEToRef, LWE, LWEInfos, LWEToMut, Rank,
prepared::{LWEToGLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPreparedToRef},
},
layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWELayout, GLWEToRef, LWE, LWEInfos, LWEToMut, Rank},
};
pub trait LWESampleExtract
@@ -71,12 +68,11 @@ where
where
R: LWEToMut,
A: GLWEToRef,
K: LWEToGLWESwitchingKeyPreparedToRef<BE> + GGLWEInfos,
K: GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>,
{
let res: &mut LWE<&mut [u8]> = &mut res.to_mut();
let a: &GLWE<&[u8]> = &a.to_ref();
let key: &LWEToGLWESwitchingKeyPrepared<&[u8], BE> = &key.to_ref();
assert_eq!(a.n(), self.n() as u32);
assert_eq!(key.n(), self.n() as u32);
@@ -90,7 +86,7 @@ where
};
let (mut tmp_glwe, scratch_1) = scratch.take_glwe_ct(self, &glwe_layout);
self.glwe_keyswitch(&mut tmp_glwe, a, &key.0, scratch_1);
self.glwe_keyswitch(&mut tmp_glwe, a, key, scratch_1);
self.lwe_sample_extract(res, &tmp_glwe);
}
}
@@ -120,7 +116,7 @@ impl<D: DataMut> LWE<D> {
where
R: LWEToMut,
A: GLWEToRef,
K: LWEToGLWESwitchingKeyPreparedToRef<BE> + GGLWEInfos,
K: GGLWEPreparedToRef<BE> + GGLWEInfos,
M: LWEFromGLWE<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
{

View File

@@ -5,10 +5,7 @@ use poulpy_hal::{
use crate::{
GLWEKeyswitch, ScratchTakeCore,
layouts::{
GGLWEInfos, GLWE, GLWEInfos, GLWELayout, GLWEToMut, LWE, LWEInfos, LWEToRef,
prepared::{LWEToGLWESwitchingKeyPrepared, LWEToGLWESwitchingKeyPreparedToRef},
},
layouts::{GGLWEInfos, GGLWEPreparedToRef, GLWE, GLWEInfos, GLWELayout, GLWEToMut, LWE, LWEInfos, LWEToRef},
};
impl<BE: Backend> GLWEFromLWE<BE> for Module<BE> where Self: GLWEKeyswitch<BE> {}
@@ -43,12 +40,11 @@ where
where
R: GLWEToMut,
A: LWEToRef,
K: LWEToGLWESwitchingKeyPreparedToRef<BE>,
K: GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>,
{
let res: &mut GLWE<&mut [u8]> = &mut res.to_mut();
let lwe: &LWE<&[u8]> = &lwe.to_ref();
let ksk: &LWEToGLWESwitchingKeyPrepared<&[u8], BE> = &ksk.to_ref();
assert_eq!(res.n(), self.n() as u32);
assert_eq!(ksk.n(), self.n() as u32);
@@ -108,7 +104,7 @@ where
);
}
self.glwe_keyswitch(res, &glwe, &ksk.0, scratch_1);
self.glwe_keyswitch(res, &glwe, ksk, scratch_1);
}
}
@@ -129,7 +125,7 @@ impl<D: DataMut> GLWE<D> {
where
M: GLWEFromLWE<BE>,
A: LWEToRef,
K: LWEToGLWESwitchingKeyPreparedToRef<BE>,
K: GGLWEPreparedToRef<BE> + GGLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>,
{
module.glwe_from_lwe(self, lwe, ksk, scratch);