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

@@ -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> {
fn get_cbt_key(
&self,

View File

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

View File

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

View File

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

View File

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