Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
renegade-dealer, renegade-dealer-api: Add optional mac_key to request
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Apr 22, 2024
1 parent c226330 commit 6f865e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
28 changes: 27 additions & 1 deletion renegade-dealer-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct ErrorResponse {
}

/// A request for offline phase randomness from the dealer
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq)]
pub struct DealerRequest {
/// The public key of the first party in the exchange
#[serde(serialize_with = "serialize_key", deserialize_with = "deserialize_key")]
Expand All @@ -72,6 +72,12 @@ pub struct DealerRequest {
#[serde(serialize_with = "serialize_key", deserialize_with = "deserialize_key")]
pub second_party_key: PublicKey,

/// The mac key to use for the request
///
/// If not present, the dealer will generate one
#[serde(default)]
pub mac_key: Option<Scalar>,

/// The number of random bits to generate
#[serde(default)]
pub n_random_bits: u32,
Expand All @@ -92,12 +98,26 @@ pub struct DealerRequest {
pub n_triples: u32,
}

impl PartialEq for DealerRequest {
// Ignore the mac key
fn eq(&self, other: &Self) -> bool {
self.first_party_key == other.first_party_key
&& self.second_party_key == other.second_party_key
&& self.n_random_bits == other.n_random_bits
&& self.n_random_values == other.n_random_values
&& self.n_input_masks == other.n_input_masks
&& self.n_inverse_pairs == other.n_inverse_pairs
&& self.n_triples == other.n_triples
}
}

impl DealerRequest {
/// Create a new request from a pair of keys
pub fn new(first_party_key: PublicKey, second_party_key: PublicKey) -> Self {
Self {
first_party_key,
second_party_key,
mac_key: None,
n_random_bits: 0,
n_random_values: 0,
n_input_masks: 0,
Expand All @@ -115,6 +135,12 @@ impl DealerRequest {
+ self.n_triples
}

/// Set the mac key to use for the request
pub fn with_mac_key(mut self, mac_key: Scalar) -> Self {
self.mac_key = Some(mac_key);
self
}

/// Set the number of random bits to generate
pub fn with_n_random_bits(mut self, n_random_bits: u32) -> Self {
self.n_random_bits = n_random_bits;
Expand Down
6 changes: 3 additions & 3 deletions renegade-dealer/src/dealer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ impl Dealer {
let req = &req1.request;

// Generate the mac key
let mac_key = Scalar::random(&mut rng);
let mac_share1 = Scalar::random(&mut rng);
let mac_share2 = mac_key - mac_share1;
let mac_share1 = req1.request.mac_key.unwrap_or_else(|| Scalar::random(&mut rng));
let mac_share2 = req2.request.mac_key.unwrap_or_else(|| Scalar::random(&mut rng));
let mac_key = mac_share1 + mac_share2;

let mut resp1 = DealerResponse { mac_key_share: mac_share1, ..Default::default() };
let mut resp2 = DealerResponse { mac_key_share: mac_share2, ..Default::default() };
Expand Down

0 comments on commit 6f865e6

Please sign in to comment.