From 141b2fa77621f98bbb12abe3d201b89fd8dbfb91 Mon Sep 17 00:00:00 2001 From: Joey Kraut Date: Mon, 15 Apr 2024 11:32:50 -0700 Subject: [PATCH] offline-phase: lowgear: shared-random: Generate authenticated, shared randomness --- offline-phase/src/lowgear/mod.rs | 11 ++++++++--- offline-phase/src/lowgear/shared_random.rs | 8 ++++++++ offline-phase/src/structs.rs | 12 ++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/offline-phase/src/lowgear/mod.rs b/offline-phase/src/lowgear/mod.rs index 2542cd6..ee6f9f4 100644 --- a/offline-phase/src/lowgear/mod.rs +++ b/offline-phase/src/lowgear/mod.rs @@ -50,6 +50,8 @@ pub struct LowGear> { pub inverse_tuples: (ValueMacBatch, ValueMacBatch), /// The shared bits generated during the offline phase pub shared_bits: ValueMacBatch, + /// The shared random values generated during the offline phase + pub shared_randomness: ValueMacBatch, /// A reference to the underlying network connection pub network: N, } @@ -72,6 +74,7 @@ impl + Unpin> LowGear { triples: Default::default(), inverse_tuples: Default::default(), shared_bits: Default::default(), + shared_randomness: Default::default(), network, } } @@ -98,12 +101,14 @@ impl + Unpin> LowGear { } /// Get the prep result from the LowGear - pub fn get_offline_result(&mut self) -> LowGearPrep { - LowGearPrep::new( + pub fn get_offline_result(&mut self) -> Result, LowGearError> { + Ok(LowGearPrep::new( + self.get_setup_params()?, self.inverse_tuples.clone(), self.shared_bits.clone(), + self.shared_randomness.clone(), self.triples.clone(), - ) + )) } /// Get a plaintext with the local mac share in all slots diff --git a/offline-phase/src/lowgear/shared_random.rs b/offline-phase/src/lowgear/shared_random.rs index 35e3b6e..7fa706c 100644 --- a/offline-phase/src/lowgear/shared_random.rs +++ b/offline-phase/src/lowgear/shared_random.rs @@ -11,6 +11,14 @@ use crate::{error::LowGearError, structs::ValueMacBatch}; use super::LowGear; impl + Unpin + Send> LowGear { + /// Generate shared randomness to store in the offline phase result + pub async fn generate_shared_randomness(&mut self, n: usize) -> Result<(), LowGearError> { + let random_vals = self.get_authenticated_randomness_vec(n).await?; + self.shared_randomness = random_vals; + + Ok(()) + } + /// Generate a single shared random value via commit/reveal pub async fn get_shared_randomness(&mut self) -> Result, LowGearError> { Ok(self.get_shared_randomness_vec(1).await?[0]) diff --git a/offline-phase/src/structs.rs b/offline-phase/src/structs.rs index 3bd0e63..7750c71 100644 --- a/offline-phase/src/structs.rs +++ b/offline-phase/src/structs.rs @@ -31,10 +31,14 @@ pub struct LowGearParams { /// The resulting shared values created by the lowgear offline phase #[derive(Clone)] pub struct LowGearPrep { + /// The params in the lowgear instance + pub params: LowGearParams, /// The shared inverse pairs pub inverse_pairs: (ValueMacBatch, ValueMacBatch), /// The shared bits pub bits: ValueMacBatch, + /// The shared random values + pub shared_randomness: ValueMacBatch, /// The shared Beaver triplets pub triplets: (ValueMacBatch, ValueMacBatch, ValueMacBatch), } @@ -42,18 +46,22 @@ pub struct LowGearPrep { impl LowGearPrep { /// Create a new `LowGearPrep` pub fn new( + params: LowGearParams, inverse_pairs: (ValueMacBatch, ValueMacBatch), bits: ValueMacBatch, + shared_randomness: ValueMacBatch, triplets: (ValueMacBatch, ValueMacBatch, ValueMacBatch), ) -> Self { - Self { inverse_pairs, bits, triplets } + Self { params, inverse_pairs, bits, shared_randomness, triplets } } /// Create an empty `LowGearPrep` - pub fn empty() -> Self { + pub fn empty(params: LowGearParams) -> Self { Self { + params, inverse_pairs: (ValueMacBatch::new(vec![]), ValueMacBatch::new(vec![])), bits: ValueMacBatch::new(vec![]), + shared_randomness: ValueMacBatch::new(vec![]), triplets: ( ValueMacBatch::new(vec![]), ValueMacBatch::new(vec![]),