working cross-base2k circuit bootstrapping

This commit is contained in:
Pro7ech
2025-11-19 09:23:51 +01:00
parent 59a1b6616a
commit 48757fac7c
4 changed files with 29 additions and 25 deletions

View File

@@ -10,8 +10,8 @@ use crate::{
decryption::GLWEDecrypt, decryption::GLWEDecrypt,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
GGLWE, GGLWECompressed, GGLWEInfos, GGLWELayout, GLWESecret, GLWESecretPreparedFactory, GGLWE, GGLWECompressed, GGLWEInfos, GGLWELayout, GLWESecret, GLWESecretPreparedFactory, GLWESwitchingKey,
GLWESwitchingKey, GLWESwitchingKeyCompressed, GLWESwitchingKeyDecompress, LWEInfos, GLWESwitchingKeyCompressed, GLWESwitchingKeyDecompress, LWEInfos,
prepared::{GGLWEPreparedFactory, GLWESecretPrepared}, prepared::{GGLWEPreparedFactory, GLWESecretPrepared},
}, },
noise::GGLWENoise, noise::GGLWENoise,

View File

@@ -9,9 +9,8 @@ use crate::{
decryption::GLWEDecrypt, decryption::GLWEDecrypt,
encryption::SIGMA, encryption::SIGMA,
layouts::{ layouts::{
Dsize, GGLWEDecompress, GGLWEInfos, GLWESecret, GLWESecretPreparedFactory, GLWESecretTensor, Dsize, GGLWEDecompress, GGLWEInfos, GLWESecret, GLWESecretPreparedFactory, GLWESecretTensor, GLWESecretTensorFactory,
GLWESecretTensorFactory, GLWETensorKey, GLWETensorKeyCompressed, GLWETensorKeyLayout, LWEInfos, GLWETensorKey, GLWETensorKeyCompressed, GLWETensorKeyLayout, LWEInfos, prepared::GLWESecretPrepared,
prepared::GLWESecretPrepared,
}, },
}; };

View File

@@ -389,12 +389,12 @@ fn post_process<R, A, M, H, K, BE: Backend>(
// TODO: from Scratch // TODO: from Scratch
let (mut cts_vec, scratch_2) = scratch_1.take_glwe_slice(steps, a); let (mut cts_vec, scratch_2) = scratch_1.take_glwe_slice(steps, a);
for i in 0..steps { for (i, ct) in cts_vec.iter_mut().enumerate().take(steps) {
if i != 0 { if i != 0 {
module.glwe_rotate_inplace(-(1 << log_gap_in), &mut a_trace, scratch_2); module.glwe_rotate_inplace(-(1 << log_gap_in), &mut a_trace, scratch_2);
} }
module.glwe_copy(&mut cts_vec[i], &a_trace); module.glwe_copy(ct, &a_trace);
} }
let mut cts: HashMap<usize, &mut GLWE<&mut [u8]>> = HashMap::new(); let mut cts: HashMap<usize, &mut GLWE<&mut [u8]>> = HashMap::new();

View File

@@ -46,7 +46,11 @@ where
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let n_glwe: usize = module.n(); let n_glwe: usize = module.n();
let base2k: usize = 17; let base2k_res: usize = 15;
let base2k_lwe: usize = 14;
let base2k_brk: usize = 13;
let base2k_tsk: usize = 12;
let base2k_atk: usize = 11;
let extension_factor: usize = 1; let extension_factor: usize = 1;
let rank: usize = 1; let rank: usize = 1;
@@ -55,36 +59,36 @@ where
let k_lwe_ct: usize = 22; let k_lwe_ct: usize = 22;
let block_size: usize = 7; let block_size: usize = 7;
let k_brk: usize = 5 * base2k; let k_ggsw_res: usize = 4 * base2k_res;
let rows_ggsw_res: usize = 3;
let k_brk: usize = k_ggsw_res + base2k_brk;
let rows_brk: usize = 4; let rows_brk: usize = 4;
let k_atk: usize = 5 * base2k; let k_atk: usize = k_ggsw_res + base2k_tsk;
let rows_atk: usize = 4; let rows_atk: usize = 4;
let k_tsk: usize = 5 * base2k; let k_tsk: usize = k_ggsw_res + base2k_atk;
let rows_tsk: usize = 4; let rows_tsk: usize = 4;
let k_ggsw_res: usize = 4 * base2k;
let rows_ggsw_res: usize = 2;
let lwe_infos: LWELayout = LWELayout { let lwe_infos: LWELayout = LWELayout {
n: n_lwe.into(), n: n_lwe.into(),
k: k_lwe_ct.into(), k: k_lwe_ct.into(),
base2k: base2k.into(), base2k: base2k_lwe.into(),
}; };
let cbt_infos: CircuitBootstrappingKeyLayout = CircuitBootstrappingKeyLayout { let cbt_infos: CircuitBootstrappingKeyLayout = CircuitBootstrappingKeyLayout {
layout_brk: BlindRotationKeyLayout { layout_brk: BlindRotationKeyLayout {
n_glwe: n_glwe.into(), n_glwe: n_glwe.into(),
n_lwe: n_lwe.into(), n_lwe: n_lwe.into(),
base2k: base2k.into(), base2k: base2k_brk.into(),
k: k_brk.into(), k: k_brk.into(),
dnum: rows_brk.into(), dnum: rows_brk.into(),
rank: rank.into(), rank: rank.into(),
}, },
layout_atk: GLWEAutomorphismKeyLayout { layout_atk: GLWEAutomorphismKeyLayout {
n: n_glwe.into(), n: n_glwe.into(),
base2k: base2k.into(), base2k: base2k_atk.into(),
k: k_atk.into(), k: k_atk.into(),
dnum: rows_atk.into(), dnum: rows_atk.into(),
rank: rank.into(), rank: rank.into(),
@@ -92,7 +96,7 @@ where
}, },
layout_tsk: GGLWEToGGSWKeyLayout { layout_tsk: GGLWEToGGSWKeyLayout {
n: n_glwe.into(), n: n_glwe.into(),
base2k: base2k.into(), base2k: base2k_tsk.into(),
k: k_tsk.into(), k: k_tsk.into(),
dnum: rows_tsk.into(), dnum: rows_tsk.into(),
dsize: Dsize(1), dsize: Dsize(1),
@@ -102,7 +106,7 @@ where
let ggsw_infos: GGSWLayout = GGSWLayout { let ggsw_infos: GGSWLayout = GGSWLayout {
n: n_glwe.into(), n: n_glwe.into(),
base2k: base2k.into(), base2k: base2k_res.into(),
k: k_ggsw_res.into(), k: k_ggsw_res.into(),
dnum: rows_ggsw_res.into(), dnum: rows_ggsw_res.into(),
dsize: Dsize(1), dsize: Dsize(1),
@@ -126,7 +130,7 @@ where
let data: i64 = 1; let data: i64 = 1;
let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(base2k.into(), k_lwe_pt.into()); let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(base2k_lwe.into(), k_lwe_pt.into());
pt_lwe.encode_i64(data, (k_lwe_pt + 1).into()); pt_lwe.encode_i64(data, (k_lwe_pt + 1).into());
println!("pt_lwe: {pt_lwe}"); println!("pt_lwe: {pt_lwe}");
@@ -205,7 +209,7 @@ where
} }
let mut ct_glwe: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ggsw_infos); let mut ct_glwe: GLWE<Vec<u8>> = GLWE::alloc_from_infos(&ggsw_infos);
let mut pt_glwe: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&ggsw_infos); let mut pt_glwe: GLWEPlaintext<Vec<u8>> = GLWEPlaintext::alloc_from_infos(&ggsw_infos);
pt_glwe.data.at_mut(0, 0)[0] = 1 << (base2k - 2); pt_glwe.data.at_mut(0, 0)[0] = 1 << (base2k_res - 2);
ct_glwe.encrypt_sk( ct_glwe.encrypt_sk(
module, module,
@@ -249,7 +253,8 @@ where
Scratch<BE>: ScratchTakeCore<BE>, Scratch<BE>: ScratchTakeCore<BE>,
{ {
let n_glwe: usize = module.n(); let n_glwe: usize = module.n();
let base2k_res: usize = 14; let base2k_res: usize = 15;
let base2k_lwe: usize = 14;
let base2k_brk: usize = 13; let base2k_brk: usize = 13;
let base2k_tsk: usize = 12; let base2k_tsk: usize = 12;
let base2k_atk: usize = 11; let base2k_atk: usize = 11;
@@ -265,7 +270,7 @@ where
let rows_ggsw_res: usize = 3; let rows_ggsw_res: usize = 3;
let k_brk: usize = k_ggsw_res + base2k_brk; let k_brk: usize = k_ggsw_res + base2k_brk;
let rows_brk: usize = 3; let rows_brk: usize = 4;
let k_atk: usize = k_ggsw_res + base2k_tsk; let k_atk: usize = k_ggsw_res + base2k_tsk;
let rows_atk: usize = 4; let rows_atk: usize = 4;
@@ -276,7 +281,7 @@ where
let lwe_infos: LWELayout = LWELayout { let lwe_infos: LWELayout = LWELayout {
n: n_lwe.into(), n: n_lwe.into(),
k: k_lwe_ct.into(), k: k_lwe_ct.into(),
base2k: base2k_brk.into(), base2k: base2k_lwe.into(),
}; };
let cbt_infos: CircuitBootstrappingKeyLayout = CircuitBootstrappingKeyLayout { let cbt_infos: CircuitBootstrappingKeyLayout = CircuitBootstrappingKeyLayout {
@@ -332,7 +337,7 @@ where
let data: i64 = 1; let data: i64 = 1;
let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(base2k_res.into(), k_lwe_pt.into()); let mut pt_lwe: LWEPlaintext<Vec<u8>> = LWEPlaintext::alloc(base2k_lwe.into(), k_lwe_pt.into());
pt_lwe.encode_i64(data, (k_lwe_pt + 1).into()); pt_lwe.encode_i64(data, (k_lwe_pt + 1).into());
println!("pt_lwe: {pt_lwe}"); println!("pt_lwe: {pt_lwe}");