Skip to content

Commit

Permalink
add constructor, happy test for signing input #481
Browse files Browse the repository at this point in the history
  • Loading branch information
marsella authored Sep 14, 2023
1 parent 3467556 commit 199d02c
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions src/sign/interactive_sign/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
// of this source tree.

use rand::{CryptoRng, RngCore};
use sha2::Sha256;
use sha2::{Digest, Sha256};
use tracing::{error, info};

use crate::{
auxinfo,
errors::{CallerError, InternalError, Result},
keygen::KeySharePublic,
keygen::{self, KeySharePublic},
message_queue::MessageQueue,
messages::{Message, MessageType, SignMessageType},
participant::{ProcessOutcome, Status},
Expand Down Expand Up @@ -145,6 +146,33 @@ pub struct Input {
presign_input: presign::Input,
}

impl Input {
/// Construct a new input for interactive signing from the outputs of the
/// [`auxinfo`](crate::auxinfo::AuxInfoParticipant) and
/// [`keygen`](crate::keygen::KeygenParticipant) protocols.
///
/// The two output sets must have been generated by the same set of
/// participants (with the same set of [`ParticipantIdentifier`]s) and
/// private component of each output must correspond with the same
/// participant.
///
/// The message should be the raw bytes of the message to be signed; do not
/// "pre-hash" the message. It is hashed here using SHA2-256.
pub fn new(
message: &[u8],
keygen_output: keygen::Output,
auxinfo_output: auxinfo::Output,
) -> Result<Self> {
let presign_input = presign::Input::new(auxinfo_output, keygen_output)?;
let message_digest = Sha256::new().chain_update(message);

Ok(Self {
message_digest,
presign_input,
})
}
}

impl ProtocolParticipant for InteractiveSignParticipant {
type Input = Input;
type Output = Signature;
Expand Down Expand Up @@ -323,14 +351,25 @@ mod tests {
keygen,
messages::{Message, MessageType},
participant::ProcessOutcome,
presign,
sign::Signature,
utils::testing::init_testing,
Identifier, ParticipantConfig, ProtocolParticipant,
Identifier, ParticipantConfig, ParticipantIdentifier, ProtocolParticipant,
};

use super::{Input, InteractiveSignParticipant, Status};

#[test]
fn input_from_valid_sources_is_valid() {
let rng = &mut init_testing();
let pids = std::iter::repeat_with(|| ParticipantIdentifier::random(rng))
.take(5)
.collect::<Vec<_>>();
let keygen_output = keygen::Output::simulate(&pids, rng);
let auxinfo_output = auxinfo::Output::simulate(&pids, rng);
let message = b"greetings from the new world";
assert!(Input::new(message, keygen_output, auxinfo_output).is_ok())
}

/// Pick a random incoming message and have the correct participant process
/// it.
fn process_messages<'a>(
Expand Down Expand Up @@ -371,17 +410,13 @@ mod tests {
let auxinfo_outputs = auxinfo::Output::simulate_set(&configs, rng);

let message = b"in an old house in paris all covered in vines lived 12 little girls";
let message_digest = sha2::Sha256::new().chain_update(message);

// Save the public key for later
let public_key = &keygen_outputs[0].public_key().unwrap();

let inputs = std::iter::zip(keygen_outputs, auxinfo_outputs)
.map(|(keygen_output, auxinfo_output)| {
Ok(Input {
message_digest: message_digest.clone(),
presign_input: presign::Input::new(auxinfo_output, keygen_output)?,
})
Input::new(message, keygen_output, auxinfo_output)
})
.collect::<Result<Vec<_>>>()?;

Expand Down

0 comments on commit 199d02c

Please sign in to comment.