Skip to content

Commit c6f2d6b

Browse files
authored
Update keygen_with_dealer to return a hashmap (ZcashFoundation#288)
* Change keygen_with_dealer to return a HashMap (ZcashFoundation#282) Update docs * Add vscode folder to gitignore
1 parent ed5faa7 commit c6f2d6b

File tree

15 files changed

+70
-55
lines changed

15 files changed

+70
-55
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
Cargo.lock
44
*~
55
**/.DS_Store
6+
.vscode/*

frost-core/src/benches.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,12 @@ pub fn bench_sign<C: Ciphersuite, R: RngCore + CryptoRng + Clone>(
102102
frost::keys::keygen_with_dealer::<C, R>(max_signers, min_signers, rng).unwrap();
103103

104104
// Verifies the secret shares from the dealer
105-
let key_packages: HashMap<_, _> = shares
106-
.into_iter()
107-
.map(|share| {
108-
(
109-
share.identifier,
110-
frost::keys::KeyPackage::try_from(share).unwrap(),
111-
)
112-
})
113-
.collect();
105+
let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
106+
HashMap::new();
107+
108+
for (k, v) in shares {
109+
key_packages.insert(k, frost::keys::KeyPackage::try_from(v).unwrap());
110+
}
114111

115112
group.bench_with_input(
116113
BenchmarkId::new("Round 1", min_signers),

frost-core/src/frost/keys.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn keygen_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
323323
max_signers: u16,
324324
min_signers: u16,
325325
rng: &mut R,
326-
) -> Result<(Vec<SecretShare<C>>, PublicKeyPackage<C>), Error<C>> {
326+
) -> Result<(HashMap<Identifier<C>, SecretShare<C>>, PublicKeyPackage<C>), Error<C>> {
327327
let mut bytes = [0; 64];
328328
rng.fill_bytes(&mut bytes);
329329

@@ -336,13 +336,18 @@ pub fn keygen_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
336336
let mut signer_pubkeys: HashMap<Identifier<C>, VerifyingShare<C>> =
337337
HashMap::with_capacity(max_signers as usize);
338338

339-
for secret_share in &secret_shares {
339+
let mut secret_shares_by_id: HashMap<Identifier<C>, SecretShare<C>> =
340+
HashMap::with_capacity(max_signers as usize);
341+
342+
for secret_share in secret_shares {
340343
let signer_public = secret_share.value.into();
341344
signer_pubkeys.insert(secret_share.identifier, signer_public);
345+
346+
secret_shares_by_id.insert(secret_share.identifier, secret_share);
342347
}
343348

344349
Ok((
345-
secret_shares,
350+
secret_shares_by_id,
346351
PublicKeyPackage {
347352
signer_pubkeys,
348353
group_public,

frost-core/src/tests.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ pub fn check_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
4848
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap();
4949

5050
// Verifies the secret shares from the dealer
51-
let key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> = shares
52-
.into_iter()
53-
.map(|share| {
54-
(
55-
share.identifier,
56-
frost::keys::KeyPackage::try_from(share).unwrap(),
57-
)
58-
})
59-
.collect();
51+
let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
52+
HashMap::new();
53+
54+
for (k, v) in shares {
55+
let key_package = frost::keys::KeyPackage::try_from(v).unwrap();
56+
key_packages.insert(k, key_package);
57+
}
6058

6159
check_sign(min_signers, key_packages, rng, pubkeys)
6260
}

frost-ed25519/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
2121
// Verifies the secret shares from the dealer and store them in a HashMap.
2222
// In practice, the KeyPackages must be sent to its respective participants
2323
// through a confidential and authenticated channel.
24-
let key_packages: HashMap<_, _> = shares
25-
.into_iter()
26-
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
27-
.collect::<Result<_, frost::Error>>()?;
24+
let mut key_packages: HashMap<_, _> = HashMap::new();
25+
26+
for (k, v) in shares {
27+
let key_package = frost::keys::KeyPackage::try_from(v)?;
28+
key_packages.insert(k, key_package);
29+
}
2830

2931
let mut nonces = HashMap::new();
3032
let mut commitments = HashMap::new();

frost-ed25519/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ pub type Identifier = frost::Identifier<E>;
200200

201201
/// FROST(Ed25519, SHA-512) keys, key generation, key shares.
202202
pub mod keys {
203+
use std::collections::HashMap;
204+
203205
use super::*;
204206

205207
/// Allows all participants' keys to be generated using a central, trusted
@@ -208,7 +210,7 @@ pub mod keys {
208210
max_signers: u16,
209211
min_signers: u16,
210212
mut rng: RNG,
211-
) -> Result<(Vec<SecretShare>, PublicKeyPackage), Error> {
213+
) -> Result<(HashMap<Identifier, SecretShare>, PublicKeyPackage), Error> {
212214
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)
213215
}
214216

frost-ed448/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
2121
// Verifies the secret shares from the dealer and store them in a HashMap.
2222
// In practice, the KeyPackages must be sent to its respective participants
2323
// through a confidential and authenticated channel.
24-
let key_packages: HashMap<_, _> = shares
25-
.into_iter()
26-
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
27-
.collect::<Result<_, frost::Error>>()?;
24+
let mut key_packages: HashMap<_, _> = HashMap::new();
25+
26+
for (k, v) in shares {
27+
let key_package = frost::keys::KeyPackage::try_from(v)?;
28+
key_packages.insert(k, key_package);
29+
}
2830

2931
let mut nonces = HashMap::new();
3032
let mut commitments = HashMap::new();

frost-ed448/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ pub type Identifier = frost::Identifier<E>;
196196
/// FROST(Ed448, SHAKE256) keys, key generation, key shares.
197197
pub mod keys {
198198
use super::*;
199+
use std::collections::HashMap;
199200

200201
/// Allows all participants' keys to be generated using a central, trusted
201202
/// dealer.
202203
pub fn keygen_with_dealer<RNG: RngCore + CryptoRng>(
203204
max_signers: u16,
204205
min_signers: u16,
205206
mut rng: RNG,
206-
) -> Result<(Vec<SecretShare>, PublicKeyPackage), Error> {
207+
) -> Result<(HashMap<Identifier, SecretShare>, PublicKeyPackage), Error> {
207208
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)
208209
}
209210

frost-p256/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
2121
// Verifies the secret shares from the dealer and store them in a HashMap.
2222
// In practice, the KeyPackages must be sent to its respective participants
2323
// through a confidential and authenticated channel.
24-
let key_packages: HashMap<_, _> = shares
25-
.into_iter()
26-
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
27-
.collect::<Result<_, frost::Error>>()?;
24+
let mut key_packages: HashMap<_, _> = HashMap::new();
25+
26+
for (k, v) in shares {
27+
let key_package = frost::keys::KeyPackage::try_from(v)?;
28+
key_packages.insert(k, key_package);
29+
}
2830

2931
let mut nonces = HashMap::new();
3032
let mut commitments = HashMap::new();

frost-p256/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ pub type Identifier = frost::Identifier<P>;
224224

225225
/// FROST(P-256, SHA-256) keys, key generation, key shares.
226226
pub mod keys {
227+
use std::collections::HashMap;
228+
227229
use super::*;
228230

229231
/// Allows all participants' keys to be generated using a central, trusted
@@ -232,7 +234,7 @@ pub mod keys {
232234
max_signers: u16,
233235
min_signers: u16,
234236
mut rng: RNG,
235-
) -> Result<(Vec<SecretShare>, PublicKeyPackage), Error> {
237+
) -> Result<(HashMap<Identifier, SecretShare>, PublicKeyPackage), Error> {
236238
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)
237239
}
238240

frost-rerandomized/src/tests.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ pub fn check_randomized_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>
2222
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap();
2323

2424
// Verifies the secret shares from the dealer
25-
let key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> = shares
26-
.into_iter()
27-
.map(|share| {
28-
(
29-
share.identifier,
30-
frost::keys::KeyPackage::try_from(share).unwrap(),
31-
)
32-
})
33-
.collect();
25+
let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
26+
HashMap::new();
27+
28+
for (k, v) in shares {
29+
key_packages.insert(k, frost::keys::KeyPackage::try_from(v).unwrap());
30+
}
3431

3532
let mut nonces: HashMap<frost::Identifier<C>, frost::round1::SigningNonces<C>> = HashMap::new();
3633
let mut commitments: HashMap<frost::Identifier<C>, frost::round1::SigningCommitments<C>> =

frost-ristretto255/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
2121
// Verifies the secret shares from the dealer and store them in a HashMap.
2222
// In practice, the KeyPackages must be sent to its respective participants
2323
// through a confidential and authenticated channel.
24-
let key_packages: HashMap<_, _> = shares
25-
.into_iter()
26-
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
27-
.collect::<Result<_, frost::Error>>()?;
24+
let mut key_packages: HashMap<_, _> = HashMap::new();
25+
26+
for (k, v) in shares {
27+
let key_package = frost::keys::KeyPackage::try_from(v)?;
28+
key_packages.insert(k, key_package);
29+
}
2830

2931
let mut nonces = HashMap::new();
3032
let mut commitments = HashMap::new();

frost-ristretto255/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,15 @@ pub type Identifier = frost::Identifier<R>;
190190
/// FROST(ristretto255, SHA-512) keys, key generation, key shares.
191191
pub mod keys {
192192
use super::*;
193+
use std::collections::HashMap;
193194

194195
/// Allows all participants' keys to be generated using a central, trusted
195196
/// dealer.
196197
pub fn keygen_with_dealer<RNG: RngCore + CryptoRng>(
197198
max_signers: u16,
198199
min_signers: u16,
199200
mut rng: RNG,
200-
) -> Result<(Vec<SecretShare>, PublicKeyPackage), Error> {
201+
) -> Result<(HashMap<Identifier, SecretShare>, PublicKeyPackage), Error> {
201202
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)
202203
}
203204

frost-secp256k1/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
2121
// Verifies the secret shares from the dealer and store them in a HashMap.
2222
// In practice, the KeyPackages must be sent to its respective participants
2323
// through a confidential and authenticated channel.
24-
let key_packages: HashMap<_, _> = shares
25-
.into_iter()
26-
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
27-
.collect::<Result<_, frost::Error>>()?;
24+
let mut key_packages: HashMap<_, _> = HashMap::new();
25+
26+
for (k, v) in shares {
27+
let key_package = frost::keys::KeyPackage::try_from(v)?;
28+
key_packages.insert(k, key_package);
29+
}
2830

2931
let mut nonces = HashMap::new();
3032
let mut commitments = HashMap::new();

frost-secp256k1/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,15 @@ pub type Identifier = frost::Identifier<S>;
225225
/// FROST(secp256k1, SHA-256) keys, key generation, key shares.
226226
pub mod keys {
227227
use super::*;
228+
use std::collections::HashMap;
228229

229230
/// Allows all participants' keys to be generated using a central, trusted
230231
/// dealer.
231232
pub fn keygen_with_dealer<RNG: RngCore + CryptoRng>(
232233
max_signers: u16,
233234
min_signers: u16,
234235
mut rng: RNG,
235-
) -> Result<(Vec<SecretShare>, PublicKeyPackage), Error> {
236+
) -> Result<(HashMap<Identifier, SecretShare>, PublicKeyPackage), Error> {
236237
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)
237238
}
238239

0 commit comments

Comments
 (0)