Skip to content

Commit 3ac90e2

Browse files
authored
fix calls to renamed DKG functions; move dkg code to its own file (#49)
1 parent 797c18c commit 3ac90e2

File tree

6 files changed

+188
-174
lines changed

6 files changed

+188
-174
lines changed

src/frost/redjubjub.rs

-80
Original file line numberDiff line numberDiff line change
@@ -212,86 +212,6 @@ pub mod keys {
212212
///
213213
/// Used for verification purposes before publishing a signature.
214214
pub type PublicKeyPackage = frost::keys::PublicKeyPackage<J>;
215-
216-
pub mod dkg {
217-
#![doc = include_str!("./redjubjub/dkg.md")]
218-
use super::*;
219-
220-
/// The secret package that must be kept in memory by the participant
221-
/// between the first and second parts of the DKG protocol (round 1).
222-
///
223-
/// # Security
224-
///
225-
/// This package MUST NOT be sent to other participants!
226-
pub type Round1SecretPackage = frost::keys::dkg::Round1SecretPackage<J>;
227-
228-
/// The package that must be broadcast by each participant to all other participants
229-
/// between the first and second parts of the DKG protocol (round 1).
230-
pub type Round1Package = frost::keys::dkg::Round1Package<J>;
231-
232-
/// The secret package that must be kept in memory by the participant
233-
/// between the second and third parts of the DKG protocol (round 2).
234-
///
235-
/// # Security
236-
///
237-
/// This package MUST NOT be sent to other participants!
238-
pub type Round2SecretPackage = frost::keys::dkg::Round2SecretPackage<J>;
239-
240-
/// A package that must be sent by each participant to some other participants
241-
/// in Round 2 of the DKG protocol. Note that there is one specific package
242-
/// for each specific recipient, in contrast to Round 1.
243-
///
244-
/// # Security
245-
///
246-
/// The package must be sent on an *confidential* and *authenticated* channel.
247-
pub type Round2Package = frost::keys::dkg::Round2Package<J>;
248-
249-
/// Performs the first part of the distributed key generation protocol
250-
/// for the given participant.
251-
///
252-
/// It returns the [`Round1SecretPackage`] that must be kept in memory
253-
/// by the participant for the other steps, and the [`Round1Package`] that
254-
/// must be sent to other participants.
255-
pub fn keygen_part1<R: RngCore + CryptoRng>(
256-
identifier: Identifier,
257-
max_signers: u16,
258-
min_signers: u16,
259-
mut rng: R,
260-
) -> Result<(Round1SecretPackage, Round1Package), Error> {
261-
frost::keys::dkg::keygen_part1(identifier, max_signers, min_signers, &mut rng)
262-
}
263-
264-
/// Performs the second part of the distributed key generation protocol
265-
/// for the participant holding the given [`Round1SecretPackage`],
266-
/// given the received [`Round1Package`]s received from the other participants.
267-
///
268-
/// It returns the [`Round2SecretPackage`] that must be kept in memory
269-
/// by the participant for the final step, and the [`Round2Package`]s that
270-
/// must be sent to other participants.
271-
pub fn keygen_part2(
272-
secret_package: Round1SecretPackage,
273-
round1_packages: &[Round1Package],
274-
) -> Result<(Round2SecretPackage, Vec<Round2Package>), Error> {
275-
frost::keys::dkg::keygen_part2(secret_package, round1_packages)
276-
}
277-
278-
/// Performs the third and final part of the distributed key generation protocol
279-
/// for the participant holding the given [`Round2SecretPackage`],
280-
/// given the received [`Round1Package`]s and [`Round2Package`]s received from
281-
/// the other participants.
282-
///
283-
/// It returns the [`KeyPackage`] that has the long-lived key share for the
284-
/// participant, and the [`PublicKeyPackage`]s that has public information
285-
/// about all participants; both of which are required to compute FROST
286-
/// signatures.
287-
pub fn keygen_part3(
288-
round2_secret_package: &Round2SecretPackage,
289-
round1_packages: &[Round1Package],
290-
round2_packages: &[Round2Package],
291-
) -> Result<(KeyPackage, PublicKeyPackage), Error> {
292-
frost::keys::dkg::keygen_part3(round2_secret_package, round1_packages, round2_packages)
293-
}
294-
}
295215
}
296216

297217
/// FROST(Jubjub, BLAKE2b-512) Round 1 functionality and types.

src/frost/redjubjub/dkg.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ a `u16`. The process in which these identifiers are allocated is up to the appli
99
The distributed key generation process has 3 parts, with 2 communication rounds
1010
between them, in which each participant needs to send a "package" to every other
1111
participant. In the first round, each participant sends the same package
12-
(a [`Round1Package`]) to every other. In the second round, each receiver gets
13-
their own package (a [`Round2Package`]).
12+
(a [`round1::Package`]) to every other. In the second round, each receiver gets
13+
their own package (a [`round2::Package`]).
1414

15-
Between part 1 and 2, each participant needs to hold onto a [`Round1SecretPackage`]
15+
Between part 1 and 2, each participant needs to hold onto a [`round1::SecretPackage`]
1616
that MUST be kept secret. Between part 2 and 3, each participant needs to hold
17-
onto a [`Round2SecretPackage`].
17+
onto a [`round2::SecretPackage`].
1818

1919
After the third part, each participant will get a [`KeyPackage`] with their
2020
long-term secret share that must be kept secret, and a [`PublicKeyPackage`]
@@ -53,7 +53,7 @@ let mut received_round1_packages = HashMap::new();
5353
// In practice, each participant will perform this on their own environments.
5454
for participant_index in 1..=max_signers {
5555
let participant_identifier = participant_index.try_into().expect("should be nonzero");
56-
let (secret_package, round1_package) = frost::keys::dkg::keygen_part1(
56+
let (secret_package, round1_package) = frost::keys::dkg::part1(
5757
participant_identifier,
5858
max_signers,
5959
min_signers,
@@ -99,7 +99,7 @@ let mut received_round2_packages = HashMap::new();
9999
// In practice, each participant will perform this on their own environments.
100100
for participant_index in 1..=max_signers {
101101
let participant_identifier = participant_index.try_into().expect("should be nonzero");
102-
let (round2_secret_package, round2_packages) = frost::keys::dkg::keygen_part2(
102+
let (round2_secret_package, round2_packages) = frost::keys::dkg::part2(
103103
round1_secret_packages
104104
.remove(&participant_identifier)
105105
.unwrap(),
@@ -142,7 +142,7 @@ let mut pubkey_packages = HashMap::new();
142142
// In practice, each participant will perform this on their own environments.
143143
for participant_index in 1..=max_signers {
144144
let participant_identifier = participant_index.try_into().expect("should be nonzero");
145-
let (key_package, pubkey_package_for_participant) = frost::keys::dkg::keygen_part3(
145+
let (key_package, pubkey_package_for_participant) = frost::keys::dkg::part3(
146146
&round2_secret_packages[&participant_identifier],
147147
&received_round1_packages[&participant_identifier],
148148
&received_round2_packages[&participant_identifier],

src/frost/redjubjub/keys/dkg.rs

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#![doc = include_str!("../dkg.md")]
2+
use super::*;
3+
4+
/// DKG Round 1 structures.
5+
pub mod round1 {
6+
use super::*;
7+
8+
/// The secret package that must be kept in memory by the participant
9+
/// between the first and second parts of the DKG protocol (round 1).
10+
///
11+
/// # Security
12+
///
13+
/// This package MUST NOT be sent to other participants!
14+
pub type SecretPackage = frost::keys::dkg::round1::SecretPackage<J>;
15+
16+
/// The package that must be broadcast by each participant to all other participants
17+
/// between the first and second parts of the DKG protocol (round 1).
18+
pub type Package = frost::keys::dkg::round1::Package<J>;
19+
}
20+
21+
/// DKG Round 2 structures.
22+
pub mod round2 {
23+
use super::*;
24+
25+
/// The secret package that must be kept in memory by the participant
26+
/// between the second and third parts of the DKG protocol (round 2).
27+
///
28+
/// # Security
29+
///
30+
/// This package MUST NOT be sent to other participants!
31+
pub type SecretPackage = frost::keys::dkg::round2::SecretPackage<J>;
32+
33+
/// A package that must be sent by each participant to some other participants
34+
/// in Round 2 of the DKG protocol. Note that there is one specific package
35+
/// for each specific recipient, in contrast to Round 1.
36+
///
37+
/// # Security
38+
///
39+
/// The package must be sent on an *confidential* and *authenticated* channel.
40+
pub type Package = frost::keys::dkg::round2::Package<J>;
41+
}
42+
43+
/// Performs the first part of the distributed key generation protocol
44+
/// for the given participant.
45+
///
46+
/// It returns the [`round1::SecretPackage`] that must be kept in memory
47+
/// by the participant for the other steps, and the [`round1::Package`] that
48+
/// must be sent to other participants.
49+
pub fn part1<R: RngCore + CryptoRng>(
50+
identifier: Identifier,
51+
max_signers: u16,
52+
min_signers: u16,
53+
mut rng: R,
54+
) -> Result<(round1::SecretPackage, round1::Package), Error> {
55+
frost::keys::dkg::part1(identifier, max_signers, min_signers, &mut rng)
56+
}
57+
58+
/// Performs the second part of the distributed key generation protocol
59+
/// for the participant holding the given [`round1::SecretPackage`],
60+
/// given the received [`round1::Package`]s received from the other participants.
61+
///
62+
/// It returns the [`round2::SecretPackage`] that must be kept in memory
63+
/// by the participant for the final step, and the [`round2::Package`]s that
64+
/// must be sent to other participants.
65+
pub fn part2(
66+
secret_package: round1::SecretPackage,
67+
round1_packages: &[round1::Package],
68+
) -> Result<(round2::SecretPackage, Vec<round2::Package>), Error> {
69+
frost::keys::dkg::part2(secret_package, round1_packages)
70+
}
71+
72+
/// Performs the third and final part of the distributed key generation protocol
73+
/// for the participant holding the given [`round2::SecretPackage`],
74+
/// given the received [`round1::Package`]s and [`round2::Package`]s received from
75+
/// the other participants.
76+
///
77+
/// It returns the [`KeyPackage`] that has the long-lived key share for the
78+
/// participant, and the [`PublicKeyPackage`]s that has public information
79+
/// about all participants; both of which are required to compute FROST
80+
/// signatures.
81+
pub fn part3(
82+
round2_secret_package: &round2::SecretPackage,
83+
round1_packages: &[round1::Package],
84+
round2_packages: &[round2::Package],
85+
) -> Result<(KeyPackage, PublicKeyPackage), Error> {
86+
frost::keys::dkg::part3(round2_secret_package, round1_packages, round2_packages)
87+
}

src/frost/redpallas.rs

-80
Original file line numberDiff line numberDiff line change
@@ -214,86 +214,6 @@ pub mod keys {
214214
///
215215
/// Used for verification purposes before publishing a signature.
216216
pub type PublicKeyPackage = frost::keys::PublicKeyPackage<P>;
217-
218-
pub mod dkg {
219-
#![doc = include_str!("./redpallas/dkg.md")]
220-
use super::*;
221-
222-
/// The secret package that must be kept in memory by the participant
223-
/// between the first and second parts of the DKG protocol (round 1).
224-
///
225-
/// # Security
226-
///
227-
/// This package MUST NOT be sent to other participants!
228-
pub type Round1SecretPackage = frost::keys::dkg::Round1SecretPackage<P>;
229-
230-
/// The package that must be broadcast by each participant to all other participants
231-
/// between the first and second parts of the DKG protocol (round 1).
232-
pub type Round1Package = frost::keys::dkg::Round1Package<P>;
233-
234-
/// The secret package that must be kept in memory by the participant
235-
/// between the second and third parts of the DKG protocol (round 2).
236-
///
237-
/// # Security
238-
///
239-
/// This package MUST NOT be sent to other participants!
240-
pub type Round2SecretPackage = frost::keys::dkg::Round2SecretPackage<P>;
241-
242-
/// A package that must be sent by each participant to some other participants
243-
/// in Round 2 of the DKG protocol. Note that there is one specific package
244-
/// for each specific recipient, in contrast to Round 1.
245-
///
246-
/// # Security
247-
///
248-
/// The package must be sent on an *confidential* and *authenticated* channel.
249-
pub type Round2Package = frost::keys::dkg::Round2Package<P>;
250-
251-
/// Performs the first part of the distributed key generation protocol
252-
/// for the given participant.
253-
///
254-
/// It returns the [`Round1SecretPackage`] that must be kept in memory
255-
/// by the participant for the other steps, and the [`Round1Package`] that
256-
/// must be sent to other participants.
257-
pub fn keygen_part1<R: RngCore + CryptoRng>(
258-
identifier: Identifier,
259-
max_signers: u16,
260-
min_signers: u16,
261-
mut rng: R,
262-
) -> Result<(Round1SecretPackage, Round1Package), Error> {
263-
frost::keys::dkg::keygen_part1(identifier, max_signers, min_signers, &mut rng)
264-
}
265-
266-
/// Performs the second part of the distributed key generation protocol
267-
/// for the participant holding the given [`Round1SecretPackage`],
268-
/// given the received [`Round1Package`]s received from the other participants.
269-
///
270-
/// It returns the [`Round2SecretPackage`] that must be kept in memory
271-
/// by the participant for the final step, and the [`Round2Package`]s that
272-
/// must be sent to other participants.
273-
pub fn keygen_part2(
274-
secret_package: Round1SecretPackage,
275-
round1_packages: &[Round1Package],
276-
) -> Result<(Round2SecretPackage, Vec<Round2Package>), Error> {
277-
frost::keys::dkg::keygen_part2(secret_package, round1_packages)
278-
}
279-
280-
/// Performs the third and final part of the distributed key generation protocol
281-
/// for the participant holding the given [`Round2SecretPackage`],
282-
/// given the received [`Round1Package`]s and [`Round2Package`]s received from
283-
/// the other participants.
284-
///
285-
/// It returns the [`KeyPackage`] that has the long-lived key share for the
286-
/// participant, and the [`PublicKeyPackage`]s that has public information
287-
/// about all participants; both of which are required to compute FROST
288-
/// signatures.
289-
pub fn keygen_part3(
290-
round2_secret_package: &Round2SecretPackage,
291-
round1_packages: &[Round1Package],
292-
round2_packages: &[Round2Package],
293-
) -> Result<(KeyPackage, PublicKeyPackage), Error> {
294-
frost::keys::dkg::keygen_part3(round2_secret_package, round1_packages, round2_packages)
295-
}
296-
}
297217
}
298218

299219
/// FROST(Pallas, BLAKE2b-512) Round 1 functionality and types.

src/frost/redpallas/dkg.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ a `u16`. The process in which these identifiers are allocated is up to the appli
99
The distributed key generation process has 3 parts, with 2 communication rounds
1010
between them, in which each participant needs to send a "package" to every other
1111
participant. In the first round, each participant sends the same package
12-
(a [`Round1Package`]) to every other. In the second round, each receiver gets
13-
their own package (a [`Round2Package`]).
12+
(a [`round1::Package`]) to every other. In the second round, each receiver gets
13+
their own package (a [`round2::Package`]).
1414

15-
Between part 1 and 2, each participant needs to hold onto a [`Round1SecretPackage`]
15+
Between part 1 and 2, each participant needs to hold onto a [`round1::SecretPackage`]
1616
that MUST be kept secret. Between part 2 and 3, each participant needs to hold
17-
onto a [`Round2SecretPackage`].
17+
onto a [`round2::SecretPackage`].
1818

1919
After the third part, each participant will get a [`KeyPackage`] with their
2020
long-term secret share that must be kept secret, and a [`PublicKeyPackage`]
@@ -53,7 +53,7 @@ let mut received_round1_packages = HashMap::new();
5353
// In practice, each participant will perform this on their own environments.
5454
for participant_index in 1..=max_signers {
5555
let participant_identifier = participant_index.try_into().expect("should be nonzero");
56-
let (secret_package, round1_package) = frost::keys::dkg::keygen_part1(
56+
let (secret_package, round1_package) = frost::keys::dkg::part1(
5757
participant_identifier,
5858
max_signers,
5959
min_signers,
@@ -99,7 +99,7 @@ let mut received_round2_packages = HashMap::new();
9999
// In practice, each participant will perform this on their own environments.
100100
for participant_index in 1..=max_signers {
101101
let participant_identifier = participant_index.try_into().expect("should be nonzero");
102-
let (round2_secret_package, round2_packages) = frost::keys::dkg::keygen_part2(
102+
let (round2_secret_package, round2_packages) = frost::keys::dkg::part2(
103103
round1_secret_packages
104104
.remove(&participant_identifier)
105105
.unwrap(),
@@ -142,7 +142,7 @@ let mut pubkey_packages = HashMap::new();
142142
// In practice, each participant will perform this on their own environments.
143143
for participant_index in 1..=max_signers {
144144
let participant_identifier = participant_index.try_into().expect("should be nonzero");
145-
let (key_package, pubkey_package_for_participant) = frost::keys::dkg::keygen_part3(
145+
let (key_package, pubkey_package_for_participant) = frost::keys::dkg::part3(
146146
&round2_secret_packages[&participant_identifier],
147147
&received_round1_packages[&participant_identifier],
148148
&received_round2_packages[&participant_identifier],

0 commit comments

Comments
 (0)