-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
offline-phase: lowgear: triplets: Implement initial triplet gen phase
This involves each party generating local shares of the triplet, encrypting their `a` value, generating a ciphertext PoK, and sending it to the counterparty. The counterparty then verifies the PoK.
- Loading branch information
Showing
6 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Defines the logic for generating shared triples (a, b, c) which satisfy the | ||
//! identity: | ||
//! a * b = c | ||
//! | ||
//! These triples are used to define single-round multiplication in the SPDZ | ||
//! protocol | ||
use ark_ec::CurveGroup; | ||
use ark_mpc::network::MpcNetwork; | ||
use mp_spdz_rs::fhe::{ciphertext::CiphertextPoK, plaintext::PlaintextVector}; | ||
|
||
use crate::error::LowGearError; | ||
|
||
use super::LowGear; | ||
|
||
impl<C: CurveGroup, N: MpcNetwork<C> + Unpin> LowGear<C, N> { | ||
/// Generate a single batch of shared triples | ||
pub async fn generate_triples(&mut self) -> Result<(), LowGearError> { | ||
// First step; generate random values a and b | ||
let mut a = PlaintextVector::random_pok_batch(&self.params); | ||
let b = PlaintextVector::random_pok_batch(&self.params); | ||
|
||
// Compute a plaintext multiplication | ||
let c = &a * &b; | ||
|
||
// Encrypt `a` and send it to the counterparty | ||
let my_proof = self.local_keypair.encrypt_and_prove_vector(&mut a); | ||
self.send_message(my_proof).await?; | ||
let mut other_proof: CiphertextPoK<C> = self.receive_message().await?; | ||
|
||
let other_pk = self.other_pk.as_ref().expect("setup not run"); | ||
let other_a_enc = other_pk.verify_proof(&mut other_proof); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::test_helpers::mock_lowgear_with_keys; | ||
|
||
/// Tests the basic triplet generation flow | ||
#[tokio::test] | ||
async fn test_triplet_gen() { | ||
mock_lowgear_with_keys(|mut lowgear| async move { | ||
lowgear.generate_triples().await.unwrap(); | ||
}) | ||
.await; | ||
} | ||
} |