fix gglwe to ggsw key layout type

This commit is contained in:
Pro7ech
2025-11-05 22:21:26 +01:00
parent be6483df75
commit 18652da7e0
7 changed files with 35 additions and 24 deletions

View File

@@ -5,8 +5,8 @@ use poulpy_backend::{FFT64Avx, FFT64Ref, FFT64Spqlios};
use poulpy_core::{ use poulpy_core::{
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore, GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore,
layouts::{ layouts::{
Dsize, GGSW, GGSWLayout, GGSWPreparedFactory, GLWEAutomorphismKeyLayout, GLWESecret, GLWESecretPreparedFactory, Dsize, GGLWEToGGSWKeyLayout, GGSW, GGSWLayout, GGSWPreparedFactory, GLWEAutomorphismKeyLayout, GLWESecret,
GLWETensorKeyLayout, LWE, LWELayout, LWESecret, GLWESecretPreparedFactory, LWE, LWELayout, LWESecret,
}, },
}; };
use poulpy_hal::{ use poulpy_hal::{
@@ -161,7 +161,7 @@ where
dsize: Dsize(1), dsize: Dsize(1),
rank: 2_u32.into(), rank: 2_u32.into(),
}, },
layout_tsk: GLWETensorKeyLayout { layout_tsk: GGLWEToGGSWKeyLayout {
n: 1024_u32.into(), n: 1024_u32.into(),
base2k: 13_u32.into(), base2k: 13_u32.into(),
k: 52_u32.into(), k: 52_u32.into(),

View File

@@ -1,7 +1,7 @@
use poulpy_core::{ use poulpy_core::{
GLWENormalize, GLWENormalize,
layouts::{ layouts::{
GGSW, GGSWLayout, GLWE, GLWEAutomorphismKeyLayout, GLWELayout, GLWEPlaintext, GLWESecret, GLWETensorKeyLayout, LWE, GGLWEToGGSWKeyLayout, GGSW, GGSWLayout, GLWE, GLWEAutomorphismKeyLayout, GLWELayout, GLWEPlaintext, GLWESecret, LWE,
LWEInfos, LWELayout, LWEPlaintext, LWESecret, LWEInfos, LWELayout, LWEPlaintext, LWESecret,
prepared::{GGSWPrepared, GLWESecretPrepared}, prepared::{GGSWPrepared, GLWESecretPrepared},
}, },
@@ -94,7 +94,7 @@ fn main() {
dsize: 1_u32.into(), dsize: 1_u32.into(),
rank: rank.into(), rank: rank.into(),
}, },
layout_tsk: GLWETensorKeyLayout { layout_tsk: GGLWEToGGSWKeyLayout {
n: n_glwe.into(), n: n_glwe.into(),
base2k: base2k.into(), base2k: base2k.into(),
k: k_tsk.into(), k: k_tsk.into(),

View File

@@ -194,6 +194,17 @@ impl<BRA: BlindRotationAlgo, BE: Backend> BDDKeyPrepared<Vec<u8>, BRA, BE> {
} }
} }
impl<D: DataRef, BRA: BlindRotationAlgo, BE: Backend> BDDKeyHelper<D, BRA, BE> for BDDKeyPrepared<D, BRA, BE> {
fn get_cbt_key(
&self,
) -> (
&CircuitBootstrappingKeyPrepared<D, BRA, BE>,
&GLWEToLWEKeyPrepared<D, BE>,
) {
(&self.cbt, &self.ks)
}
}
pub trait BDDKeyHelper<D: DataRef, BRA: BlindRotationAlgo, BE: Backend> { pub trait BDDKeyHelper<D: DataRef, BRA: BlindRotationAlgo, BE: Backend> {
fn get_cbt_key( fn get_cbt_key(
&self, &self,

View File

@@ -38,8 +38,8 @@ pub use xor::*;
use poulpy_core::{ use poulpy_core::{
ScratchTakeCore, ScratchTakeCore,
layouts::{ layouts::{
Base2K, Degree, Dnum, Dsize, GGSWLayout, GLWEAutomorphismKeyLayout, GLWELayout, GLWESecret, GLWESecretPrepared, Base2K, Degree, Dnum, Dsize, GGLWEToGGSWKeyLayout, GGSWLayout, GLWEAutomorphismKeyLayout, GLWELayout, GLWESecret,
GLWESecretPreparedFactory, GLWETensorKeyLayout, GLWEToLWEKeyLayout, LWESecret, Rank, TorusPrecision, GLWESecretPrepared, GLWESecretPreparedFactory, GLWEToLWEKeyLayout, LWESecret, Rank, TorusPrecision,
}, },
}; };
@@ -167,7 +167,7 @@ pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout {
dnum: Dnum(3), dnum: Dnum(3),
dsize: Dsize(1), dsize: Dsize(1),
}, },
layout_tsk: GLWETensorKeyLayout { layout_tsk: GGLWEToGGSWKeyLayout {
n: Degree(TEST_N_GLWE), n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K), base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(52), k: TorusPrecision(52),

View File

@@ -1,8 +1,8 @@
use poulpy_core::{ use poulpy_core::{
Distribution, GGLWEToGGSWKeyEncryptSk, GLWEAutomorphismKeyEncryptSk, GetDistribution, ScratchTakeCore, Distribution, GGLWEToGGSWKeyEncryptSk, GLWEAutomorphismKeyEncryptSk, GetDistribution, ScratchTakeCore,
layouts::{ layouts::{
GGLWEInfos, GGLWEToGGSWKey, GGSWInfos, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEInfos, GGLWEInfos, GGLWEToGGSWKey, GGLWEToGGSWKeyLayout, GGSWInfos, GLWEAutomorphismKey, GLWEAutomorphismKeyLayout, GLWEInfos,
GLWESecretPreparedFactory, GLWESecretToRef, GLWETensorKeyLayout, LWEInfos, LWESecretToRef, prepared::GLWESecretPrepared, GLWESecretPreparedFactory, GLWESecretToRef, LWEInfos, LWESecretToRef, prepared::GLWESecretPrepared,
}, },
trace_galois_elements, trace_galois_elements,
}; };
@@ -21,14 +21,14 @@ use crate::tfhe::blind_rotation::{
pub trait CircuitBootstrappingKeyInfos { pub trait CircuitBootstrappingKeyInfos {
fn brk_infos(&self) -> BlindRotationKeyLayout; fn brk_infos(&self) -> BlindRotationKeyLayout;
fn atk_infos(&self) -> GLWEAutomorphismKeyLayout; fn atk_infos(&self) -> GLWEAutomorphismKeyLayout;
fn tsk_infos(&self) -> GLWETensorKeyLayout; fn tsk_infos(&self) -> GGLWEToGGSWKeyLayout;
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct CircuitBootstrappingKeyLayout { pub struct CircuitBootstrappingKeyLayout {
pub layout_brk: BlindRotationKeyLayout, pub layout_brk: BlindRotationKeyLayout,
pub layout_atk: GLWEAutomorphismKeyLayout, pub layout_atk: GLWEAutomorphismKeyLayout,
pub layout_tsk: GLWETensorKeyLayout, pub layout_tsk: GGLWEToGGSWKeyLayout,
} }
impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout { impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout {
@@ -40,7 +40,7 @@ impl CircuitBootstrappingKeyInfos for CircuitBootstrappingKeyLayout {
self.layout_brk self.layout_brk
} }
fn tsk_infos(&self) -> GLWETensorKeyLayout { fn tsk_infos(&self) -> GGLWEToGGSWKeyLayout {
self.layout_tsk self.layout_tsk
} }
} }
@@ -69,7 +69,7 @@ impl<BRA: BlindRotationAlgo> CircuitBootstrappingKey<Vec<u8>, BRA> {
{ {
let atk_infos: &GLWEAutomorphismKeyLayout = &infos.atk_infos(); let atk_infos: &GLWEAutomorphismKeyLayout = &infos.atk_infos();
let brk_infos: &BlindRotationKeyLayout = &infos.brk_infos(); let brk_infos: &BlindRotationKeyLayout = &infos.brk_infos();
let trk_infos: &GLWETensorKeyLayout = &infos.tsk_infos(); let trk_infos: &GGLWEToGGSWKeyLayout = &infos.tsk_infos();
let gal_els: Vec<i64> = trace_galois_elements(atk_infos.log_n(), 2 * atk_infos.n().as_usize() as i64); let gal_els: Vec<i64> = trace_galois_elements(atk_infos.log_n(), 2 * atk_infos.n().as_usize() as i64);
Self { Self {
@@ -133,7 +133,7 @@ where
{ {
let brk_infos: &BlindRotationKeyLayout = &res.brk_infos(); let brk_infos: &BlindRotationKeyLayout = &res.brk_infos();
let atk_infos: &GLWEAutomorphismKeyLayout = &res.atk_infos(); let atk_infos: &GLWEAutomorphismKeyLayout = &res.atk_infos();
let tsk_infos: &GLWETensorKeyLayout = &res.tsk_infos(); let tsk_infos: &GGLWEToGGSWKeyLayout = &res.tsk_infos();
assert_eq!(sk_lwe.n(), brk_infos.n_lwe()); assert_eq!(sk_lwe.n(), brk_infos.n_lwe());
assert_eq!(sk_glwe.n(), brk_infos.n_glwe()); assert_eq!(sk_glwe.n(), brk_infos.n_glwe());
@@ -187,8 +187,8 @@ impl<D: DataRef, BRA: BlindRotationAlgo> CircuitBootstrappingKeyInfos for Circui
} }
} }
fn tsk_infos(&self) -> GLWETensorKeyLayout { fn tsk_infos(&self) -> GGLWEToGGSWKeyLayout {
GLWETensorKeyLayout { GGLWEToGGSWKeyLayout {
n: self.tsk.n(), n: self.tsk.n(),
base2k: self.tsk.base2k(), base2k: self.tsk.base2k(),
k: self.tsk.k(), k: self.tsk.k(),

View File

@@ -1,7 +1,7 @@
use poulpy_core::{ use poulpy_core::{
layouts::{ layouts::{
GGLWEInfos, GGLWEToGGSWKeyPrepared, GGLWEToGGSWKeyPreparedFactory, GGSWInfos, GLWEAutomorphismKeyHelper, GGLWEInfos, GGLWEToGGSWKeyLayout, GGLWEToGGSWKeyPrepared, GGLWEToGGSWKeyPreparedFactory, GGSWInfos,
GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWEInfos, GLWETensorKeyLayout, GLWEAutomorphismKeyHelper, GLWEAutomorphismKeyLayout, GLWEAutomorphismKeyPreparedFactory, GLWEInfos,
GLWETensorKeyPreparedFactory, LWEInfos, prepared::GLWEAutomorphismKeyPrepared, GLWETensorKeyPreparedFactory, LWEInfos, prepared::GLWEAutomorphismKeyPrepared,
}, },
trace_galois_elements, trace_galois_elements,
@@ -145,8 +145,8 @@ impl<D: DataRef, BRA: BlindRotationAlgo, B: Backend> CircuitBootstrappingKeyInfo
} }
} }
fn tsk_infos(&self) -> GLWETensorKeyLayout { fn tsk_infos(&self) -> GGLWEToGGSWKeyLayout {
GLWETensorKeyLayout { GGLWEToGGSWKeyLayout {
n: self.tsk.n(), n: self.tsk.n(),
base2k: self.tsk.base2k(), base2k: self.tsk.base2k(),
k: self.tsk.k(), k: self.tsk.k(),

View File

@@ -17,7 +17,7 @@ use crate::tfhe::{
use poulpy_core::{ use poulpy_core::{
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore, GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWEExternalProduct, LWEEncryptSk, ScratchTakeCore,
layouts::{ layouts::{
Dsize, GGSWLayout, GGSWPreparedFactory, GLWEAutomorphismKeyLayout, GLWESecretPreparedFactory, GLWETensorKeyLayout, Dsize, GGLWEToGGSWKeyLayout, GGSWLayout, GGSWPreparedFactory, GLWEAutomorphismKeyLayout, GLWESecretPreparedFactory,
LWELayout, LWELayout,
}, },
}; };
@@ -90,7 +90,7 @@ where
rank: rank.into(), rank: rank.into(),
dsize: Dsize(1), dsize: Dsize(1),
}, },
layout_tsk: GLWETensorKeyLayout { layout_tsk: GGLWEToGGSWKeyLayout {
n: n_glwe.into(), n: n_glwe.into(),
base2k: base2k.into(), base2k: base2k.into(),
k: k_tsk.into(), k: k_tsk.into(),
@@ -271,7 +271,7 @@ where
rank: rank.into(), rank: rank.into(),
dsize: Dsize(1), dsize: Dsize(1),
}, },
layout_tsk: GLWETensorKeyLayout { layout_tsk: GGLWEToGGSWKeyLayout {
n: n_glwe.into(), n: n_glwe.into(),
base2k: base2k.into(), base2k: base2k.into(),
k: k_tsk.into(), k: k_tsk.into(),