Skip to content

Commit

Permalink
Updates for manul API
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Nov 10, 2024
1 parent 5444f65 commit 7a3eada
Show file tree
Hide file tree
Showing 10 changed files with 548 additions and 454 deletions.
14 changes: 6 additions & 8 deletions synedrion/src/cggmp21/protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ pub(crate) mod signing;
#[cfg(test)]
pub(crate) mod signing_malicious;

pub use aux_gen::{AuxGenError, AuxGenProtocol};
pub use interactive_signing::{
InteractiveSigningInputs, InteractiveSigningProtocol, InteractiveSigningRound1,
};
pub use key_init::{KeyInitError, KeyInitProtocol};
pub use key_refresh::KeyRefreshProtocol;
pub use presigning::{PresigningError, PresigningProof, PresigningProtocol};
pub use signing::{SigningProof, SigningProtocol};
pub use aux_gen::{AuxGen, AuxGenProtocol};
pub use interactive_signing::{InteractiveSigning, InteractiveSigningProtocol};
pub use key_init::{KeyInit, KeyInitProtocol};
pub use key_refresh::{KeyRefresh, KeyRefreshProtocol};
pub use presigning::{Presigning, PresigningProtocol};
pub use signing::{Signing, SigningProtocol};
155 changes: 82 additions & 73 deletions synedrion/src/cggmp21/protocols/aux_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,68 +91,33 @@ impl ProtocolError for AuxGenError {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "PrmProof<P>: Serialize"))]
#[serde(bound(deserialize = "PrmProof<P>: for<'x> Deserialize<'x>"))]
pub struct PublicData1<P: SchemeParams> {
cap_y: Point,
cap_b: SchCommitment,
paillier_pk: PublicKeyPaillier<P::Paillier>, // $N_i$
rp_params: RPParams<P::Paillier>, // $s_i$ and $t_i$
hat_psi: PrmProof<P>,
rho: BitVec,
u: BitVec,
}

#[derive(Debug, Clone)]
pub struct PublicData1Precomp<P: SchemeParams> {
data: PublicData1<P>,
paillier_pk: PublicKeyPaillierPrecomputed<P::Paillier>,
rp_params: RPParamsMod<P::Paillier>,
}

#[derive(Debug)]
struct Context<P: SchemeParams, I> {
paillier_sk: SecretKeyPaillierPrecomputed<P::Paillier>,
y: Scalar,
tau_y: SchSecret,
data_precomp: PublicData1Precomp<P>,
pub struct AuxGen<P, I> {
my_id: I,
other_ids: BTreeSet<I>,
sid_hash: HashOutput,
phantom: PhantomData<P>,
}

impl<P: SchemeParams> PublicData1<P> {
fn hash<I: Serialize>(&self, sid_hash: &HashOutput, my_id: &I) -> HashOutput {
FofHasher::new_with_dst(b"Auxiliary")
.chain(sid_hash)
.chain(my_id)
.chain(self)
.finalize()
impl<P, I: PartyId> AuxGen<P, I> {
pub fn new(my_id: I, other_ids: BTreeSet<I>) -> Self {
Self {
my_id,
other_ids,
phantom: PhantomData,
}
}
}

#[derive(Debug)]
pub struct Round1<P: SchemeParams, I> {
context: Context<P, I>,
}

pub struct AuxGenInputs<I> {
pub other_ids: BTreeSet<I>,
}

impl<P: SchemeParams, I: PartyId + Serialize> EntryPoint<I> for Round1<P, I> {
type Inputs = AuxGenInputs<I>;
impl<P: SchemeParams, I: PartyId> EntryPoint<I> for AuxGen<P, I> {
type Protocol = AuxGenProtocol<P, I>;

fn new(
fn make_round(
self,
rng: &mut impl CryptoRngCore,
shared_randomness: &[u8],
id: I,
inputs: Self::Inputs,
) -> Result<BoxedRound<I, Self::Protocol>, LocalError> {
let mut all_ids = inputs.other_ids.clone();
all_ids.insert(id.clone());
let mut all_ids = self.other_ids.clone();
all_ids.insert(self.my_id.clone());

let sid_hash = FofHasher::new_with_dst(b"SID")
.chain_type::<P>()
Expand All @@ -177,7 +142,7 @@ impl<P: SchemeParams, I: PartyId + Serialize> EntryPoint<I> for Round1<P, I> {
// Ring-Pedersen parameters ($s$, $t$) bundled in a single object.
let rp_params = RPParamsMod::random_with_secret(rng, &lambda, paillier_pk);

let aux = (&sid_hash, &id);
let aux = (&sid_hash, &self.my_id);
let hat_psi = PrmProof::<P>::new(rng, &paillier_sk, &lambda, &rp_params, &aux);

let rho = BitVec::random(rng, P::SECURITY_PARAMETER);
Expand All @@ -204,25 +169,71 @@ impl<P: SchemeParams, I: PartyId + Serialize> EntryPoint<I> for Round1<P, I> {
y,
tau_y,
data_precomp,
my_id: id,
other_ids: inputs.other_ids,
my_id: self.my_id,
other_ids: self.other_ids,
sid_hash,
};

Ok(BoxedRound::new_dynamic(Self { context }))
Ok(BoxedRound::new_dynamic(Round1 { context }))
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "PrmProof<P>: Serialize"))]
#[serde(bound(deserialize = "PrmProof<P>: for<'x> Deserialize<'x>"))]
struct PublicData1<P: SchemeParams> {
cap_y: Point,
cap_b: SchCommitment,
paillier_pk: PublicKeyPaillier<P::Paillier>, // $N_i$
rp_params: RPParams<P::Paillier>, // $s_i$ and $t_i$
hat_psi: PrmProof<P>,
rho: BitVec,
u: BitVec,
}

#[derive(Debug, Clone)]
struct PublicData1Precomp<P: SchemeParams> {
data: PublicData1<P>,
paillier_pk: PublicKeyPaillierPrecomputed<P::Paillier>,
rp_params: RPParamsMod<P::Paillier>,
}

#[derive(Debug)]
struct Context<P: SchemeParams, I> {
paillier_sk: SecretKeyPaillierPrecomputed<P::Paillier>,
y: Scalar,
tau_y: SchSecret,
data_precomp: PublicData1Precomp<P>,
my_id: I,
other_ids: BTreeSet<I>,
sid_hash: HashOutput,
}

impl<P: SchemeParams> PublicData1<P> {
fn hash<I: Serialize>(&self, sid_hash: &HashOutput, my_id: &I) -> HashOutput {
FofHasher::new_with_dst(b"Auxiliary")
.chain(sid_hash)
.chain(my_id)
.chain(self)
.finalize()
}
}

#[derive(Debug)]
struct Round1<P: SchemeParams, I> {
context: Context<P, I>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Round1Message {
struct Round1Message {
cap_v: HashOutput,
}

pub struct Round1Payload {
struct Round1Payload {
cap_v: HashOutput,
}

impl<P: SchemeParams, I: PartyId + Serialize> Round<I> for Round1<P, I> {
impl<P: SchemeParams, I: PartyId> Round<I> for Round1<P, I> {
type Protocol = AuxGenProtocol<P, I>;

fn id(&self) -> RoundId {
Expand Down Expand Up @@ -296,23 +307,23 @@ impl<P: SchemeParams, I: PartyId + Serialize> Round<I> for Round1<P, I> {
}

#[derive(Debug)]
pub struct Round2<P: SchemeParams, I> {
struct Round2<P: SchemeParams, I> {
context: Context<P, I>,
others_cap_v: BTreeMap<I, HashOutput>,
}

#[derive(Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "PublicData1<P>: Serialize"))]
#[serde(bound(deserialize = "PublicData1<P>: for<'x> Deserialize<'x>"))]
pub struct Round2Message<P: SchemeParams> {
struct Round2Message<P: SchemeParams> {
data: PublicData1<P>,
}

pub struct Round2Payload<P: SchemeParams> {
struct Round2Payload<P: SchemeParams> {
data: PublicData1Precomp<P>,
}

impl<P: SchemeParams, I: PartyId + Serialize> Round<I> for Round2<P, I> {
impl<P: SchemeParams, I: PartyId> Round<I> for Round2<P, I> {
type Protocol = AuxGenProtocol<P, I>;

fn id(&self) -> RoundId {
Expand Down Expand Up @@ -414,7 +425,7 @@ impl<P: SchemeParams, I: PartyId + Serialize> Round<I> for Round2<P, I> {
}

#[derive(Debug)]
pub struct Round3<P: SchemeParams, I> {
struct Round3<P: SchemeParams, I> {
context: Context<P, I>,
rho: BitVec,
others_data: BTreeMap<I, PublicData1Precomp<P>>,
Expand All @@ -431,13 +442,13 @@ pub struct Round3<P: SchemeParams, I> {
ModProof<P>: for<'x> Deserialize<'x>,
FacProof<P>: for<'x> Deserialize<'x>,
"))]
pub struct PublicData2<P: SchemeParams> {
struct PublicData2<P: SchemeParams> {
psi_mod: ModProof<P>, // $\psi_i$, a P^{mod} for the Paillier modulus
phi: FacProof<P>,
pi: SchProof,
}

impl<P: SchemeParams, I: PartyId + Serialize> Round3<P, I> {
impl<P: SchemeParams, I: PartyId> Round3<P, I> {
fn new(
rng: &mut impl CryptoRngCore,
context: Context<P, I>,
Expand Down Expand Up @@ -468,7 +479,7 @@ impl<P: SchemeParams, I: PartyId + Serialize> Round3<P, I> {
#[derive(Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "PublicData2<P>: Serialize"))]
#[serde(bound(deserialize = "PublicData2<P>: for<'x> Deserialize<'x>"))]
pub struct Round3Message<P: SchemeParams> {
struct Round3Message<P: SchemeParams> {
data2: PublicData2<P>,
}

Expand Down Expand Up @@ -617,7 +628,7 @@ mod tests {
use rand_core::{OsRng, RngCore};
use secrecy::ExposeSecret;

use super::{AuxGenInputs, Round1};
use super::AuxGen;
use crate::cggmp21::TestParams;
use crate::tools::Without;

Expand All @@ -629,23 +640,21 @@ mod tests {
.iter()
.map(|signer| signer.verifying_key())
.collect::<BTreeSet<_>>();
let inputs = signers
let entry_points = signers
.into_iter()
.map(|signer| {
(
signer,
AuxGenInputs {
other_ids: all_ids.clone().without(&signer.verifying_key()),
},
AuxGen::<TestParams, TestVerifier>::new(
signer.verifying_key(),
all_ids.clone().without(&signer.verifying_key()),
),
)
})
.collect::<Vec<_>>();

let reports =
run_sync::<Round1<TestParams, TestVerifier>, TestSessionParams<BinaryFormat>>(
&mut OsRng, inputs,
)
.unwrap();
run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points).unwrap();

let aux_infos = reports
.into_iter()
Expand Down
Loading

0 comments on commit 7a3eada

Please sign in to comment.