Skip to content

Commit 73ef673

Browse files
authored
match compatible-with-abe (#158)
1 parent c18cc56 commit 73ef673

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/io/eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use itertools::Itertools;
77
use mxx::parallel_iter;
88
use mxx::{
99
bgg::{digits_to_int::DigitsToInt, encoding::BggEncoding, sampler::BGGPublicKeySampler},
10-
lookup::simple_eval::SimpleBggEncodingPltEvaluator,
10+
lookup::lwe_eval::LweBggEncodingPltEvaluator,
1111
matrix::PolyMatrix,
1212
poly::{Poly, PolyParams},
1313
sampler::{PolyHashSampler, PolyTrapdoorSampler},
@@ -54,8 +54,8 @@ where
5454
hash_key.copy_from_slice(&bytes);
5555
hash_key
5656
};
57-
58-
let bgg_pubkey_sampler = BGGPublicKeySampler::<_, SH>::new(hash_key, d);
57+
// explictly sample d+1 public keys
58+
let bgg_pubkey_sampler = BGGPublicKeySampler::<_, SH>::new(hash_key, d + 1);
5959
let public_data = PublicSampledData::<SH>::sample(&obf_params, hash_key);
6060
log_mem("Sampled public data");
6161
let packed_input_size = public_data.packed_input_size;
@@ -341,7 +341,7 @@ where
341341
}
342342
}
343343
let bgg_encoding_plt_evaluator =
344-
SimpleBggEncodingPltEvaluator::<M, SH>::new(hash_key, dir_path.clone(), p_l_plus_one);
344+
LweBggEncodingPltEvaluator::<M, SH>::new(hash_key, dir_path.clone(), p_l_plus_one);
345345
let output_encodings = final_circuit.eval(
346346
params.as_ref(),
347347
&new_encodings[0],

src/io/obf.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use itertools::Itertools;
1111
use mxx::storage::store_and_drop_poly;
1212
use mxx::{
1313
bgg::{digits_to_int::DigitsToInt, public_key::BggPublicKey, sampler::BGGPublicKeySampler},
14-
lookup::simple_eval::SimpleBggPubKeyEvaluator,
14+
lookup::lwe_eval::LweBggPubKeyEvaluator,
1515
matrix::PolyMatrix,
1616
poly::{Poly, PolyParams},
1717
rlwe_enc::rlwe_encrypt,
@@ -62,7 +62,8 @@ where
6262
let d = obf_params.d;
6363
let sampler_uniform = SU::new();
6464
let sampler_trapdoor = ST::new(&params, obf_params.trapdoor_sigma);
65-
let bgg_pubkey_sampler = BGGPublicKeySampler::<_, SH>::new(hash_key, d);
65+
// sample d+1 public keys explictly
66+
let bgg_pubkey_sampler = BGGPublicKeySampler::<_, SH>::new(hash_key, d + 1);
6667
let m_b = (1 + packed_input_size) * (d + 1) * (2 + log_base_q);
6768
let packed_output_size = public_data.packed_output_size;
6869

@@ -80,9 +81,6 @@ where
8081
=============================================================================
8182
*/
8283

83-
// Sample BGG+ encoding secret key
84-
let s_bars = sampler_uniform.sample_uniform(&params, 1, d, DistType::BitDist).get_row(0);
85-
log_mem("Sampled s_bars");
8684
// Sample FHE secret key t
8785
let t_bar = sampler_uniform.sample_uniform(&params, 1, 1, DistType::BitDist);
8886
log_mem("Sampled t_bar");
@@ -102,6 +100,9 @@ where
102100
reveals
103101
};
104102
let s_init = {
103+
// Sample BGG+ encoding secret key
104+
let s_bars = sampler_uniform.sample_uniform(&params, 1, d, DistType::BitDist).get_row(0);
105+
log_mem("Sampled s_bars");
105106
let minus_one_poly = <SU::M as PolyMatrix>::P::const_minus_one(&params);
106107
let mut secrets = s_bars.to_vec();
107108
secrets.push(minus_one_poly);
@@ -401,7 +402,7 @@ where
401402
);
402403
log_mem("Computed final_circuit");
403404

404-
let bgg_plt_evaluator = SimpleBggPubKeyEvaluator::<M, SH, SU, ST>::new(
405+
let bgg_plt_evaluator = LweBggPubKeyEvaluator::<M, SH, ST>::new(
405406
hash_key,
406407
sampler_trapdoor.clone(),
407408
b_l_plus_one.clone(),

tests/test_io_final_circuit.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use keccak_asm::Keccak256;
33
use mxx::{
44
bgg::{digits_to_int::DigitsToInt, public_key::BggPublicKey, sampler::BGGPublicKeySampler},
55
circuit::PolyCircuit,
6-
lookup::simple_eval::SimpleBggPubKeyEvaluator,
6+
lookup::lwe_eval::LweBggPubKeyEvaluator,
77
matrix::dcrt_poly::DCRTPolyMatrix,
88
poly::{
99
dcrt::{params::DCRTPolyParams, poly::DCRTPoly},
@@ -82,7 +82,7 @@ fn test_build_final_step_circuit() {
8282
let packed_input_size = input_size.div_ceil(dim) + 1;
8383

8484
let bgg_pubkey_sampler =
85-
BGGPublicKeySampler::<_, DCRTPolyHashSampler<Keccak256>>::new(hash_key, d);
85+
BGGPublicKeySampler::<_, DCRTPolyHashSampler<Keccak256>>::new(hash_key, d + 1);
8686
// consider inserting t on plaintext
8787
let reveal_plaintexts = [vec![true; packed_input_size], vec![false; 1]].concat();
8888
let pubkeys = bgg_pubkey_sampler.sample(&params, b"BGG_PUBKEY_INPUT:", &reveal_plaintexts);
@@ -93,10 +93,9 @@ fn test_build_final_step_circuit() {
9393
&pubkeys[0],
9494
&pubkeys[1..],
9595
None::<
96-
SimpleBggPubKeyEvaluator<
96+
LweBggPubKeyEvaluator<
9797
DCRTPolyMatrix,
9898
DCRTPolyHashSampler<Keccak256>,
99-
DCRTPolyUniformSampler,
10099
DCRTPolyTrapdoorSampler,
101100
>,
102101
>,

0 commit comments

Comments
 (0)