Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offline-phase: lowgear: Implement input auth methods for lowgear #85

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions offline-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ pub(crate) mod test_helpers {
let mut lowgear2 = LowGear::new(net2);

// Setup the lowgear instances
let params = &lowgear1.params;
let keypair1 = BGVKeypair::gen(params);
let keypair2 = BGVKeypair::gen(params);
let params1 = &lowgear1.params;
let params2 = &lowgear2.params;
let keypair1 = BGVKeypair::gen(params1);
let keypair2 = BGVKeypair::gen(params2);

let mac_share1 = Scalar::random(&mut rng);
let mac_share2 = Scalar::random(&mut rng);
Expand All @@ -204,9 +205,9 @@ pub(crate) mod test_helpers {

// Set the exchanged values
lowgear1.other_pk = Some(keypair2.public_key());
lowgear1.other_mac_enc = Some(encrypt_all(mac_share2, &keypair2.public_key(), params));
lowgear1.other_mac_enc = Some(encrypt_all(mac_share2, &keypair2.public_key(), params1));
lowgear2.other_pk = Some(keypair1.public_key());
lowgear2.other_mac_enc = Some(encrypt_all(mac_share1, &keypair1.public_key(), params));
lowgear2.other_mac_enc = Some(encrypt_all(mac_share1, &keypair1.public_key(), params2));

(lowgear1, lowgear2)
}
Expand Down
1 change: 1 addition & 0 deletions offline-phase/src/lowgear/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl<C: CurveGroup, N: MpcNetwork<C> + Unpin> LowGear<C, N> {
self.inverse_tuples.clone(),
self.shared_bits.clone(),
self.shared_randomness.clone(),
self.input_masks.clone(),
self.triples.clone(),
))
}
Expand Down
40 changes: 36 additions & 4 deletions offline-phase/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct LowGearPrep<C: CurveGroup> {
pub bits: ValueMacBatch<C>,
/// The shared random values
pub shared_randomness: ValueMacBatch<C>,
/// The input masks
pub input_masks: InputMasks<C>,
/// The shared Beaver triplets
pub triplets: (ValueMacBatch<C>, ValueMacBatch<C>, ValueMacBatch<C>),
}
Expand All @@ -51,9 +53,10 @@ impl<C: CurveGroup> LowGearPrep<C> {
inverse_pairs: (ValueMacBatch<C>, ValueMacBatch<C>),
bits: ValueMacBatch<C>,
shared_randomness: ValueMacBatch<C>,
input_masks: InputMasks<C>,
triplets: (ValueMacBatch<C>, ValueMacBatch<C>, ValueMacBatch<C>),
) -> Self {
Self { params, inverse_pairs, bits, shared_randomness, triplets }
Self { params, inverse_pairs, bits, shared_randomness, input_masks, triplets }
}

/// Create an empty `LowGearPrep`
Expand All @@ -63,6 +66,7 @@ impl<C: CurveGroup> LowGearPrep<C> {
inverse_pairs: (ValueMacBatch::new(vec![]), ValueMacBatch::new(vec![])),
bits: ValueMacBatch::new(vec![]),
shared_randomness: ValueMacBatch::new(vec![]),
input_masks: InputMasks::default(),
triplets: (
ValueMacBatch::new(vec![]),
ValueMacBatch::new(vec![]),
Expand Down Expand Up @@ -94,6 +98,30 @@ impl<C: CurveGroup> LowGearPrep<C> {
}

impl<C: CurveGroup> PreprocessingPhase<C> for LowGearPrep<C> {
fn get_mac_key_share(&self) -> Scalar<C> {
self.params.mac_key_share
}

fn next_local_input_mask(&mut self) -> (Scalar<C>, ScalarShare<C>) {
self.input_masks.get_local_mask()
}

fn next_local_input_mask_batch(
&mut self,
num_values: usize,
) -> (Vec<Scalar<C>>, Vec<ScalarShare<C>>) {
let (masks, mask_shares) = self.input_masks.get_local_mask_batch(num_values);
(masks, mask_shares.into_inner())
}

fn next_counterparty_input_mask(&mut self) -> ScalarShare<C> {
self.input_masks.get_counterparty_mask()
}

fn next_counterparty_input_mask_batch(&mut self, num_values: usize) -> Vec<ScalarShare<C>> {
self.input_masks.get_counterparty_mask_batch(num_values).into_inner()
}

fn next_shared_bit(&mut self) -> ScalarShare<C> {
self.bits.split_off(1).into_inner()[0]
}
Expand Down Expand Up @@ -380,9 +408,13 @@ mod test {
#[tokio::test]
async fn test_lowgear_offline_phase() {
// Setup the mock offline phase
const N: usize = 100;
let (prep1, prep2) = mock_lowgear_with_triples(
100, // num_triples
|mut lowgear| async move { lowgear.get_offline_result().unwrap() },
N, // num_triples
|mut lowgear| async move {
lowgear.generate_input_masks(N).await.unwrap();
lowgear.get_offline_result().unwrap()
},
)
.await;

Expand All @@ -398,7 +430,7 @@ mod test {
let b_shared = fabric.share_scalar(b, PARTY1);

let c = a_shared * b_shared;
c.open().await
c.open_authenticated().await.unwrap()
},
prep1,
prep2,
Expand Down
Loading