Skip to content

Commit

Permalink
Update keygen_with_dealer to return a hashmap (#288)
Browse files Browse the repository at this point in the history
* Change keygen_with_dealer to return a HashMap (#282)

Update docs

* Add vscode folder to gitignore
  • Loading branch information
natalieesk authored Mar 23, 2023
1 parent ed5faa7 commit c6f2d6b
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Cargo.lock
*~
**/.DS_Store
.vscode/*
15 changes: 6 additions & 9 deletions frost-core/src/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,12 @@ pub fn bench_sign<C: Ciphersuite, R: RngCore + CryptoRng + Clone>(
frost::keys::keygen_with_dealer::<C, R>(max_signers, min_signers, rng).unwrap();

// Verifies the secret shares from the dealer
let key_packages: HashMap<_, _> = shares
.into_iter()
.map(|share| {
(
share.identifier,
frost::keys::KeyPackage::try_from(share).unwrap(),
)
})
.collect();
let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
HashMap::new();

for (k, v) in shares {
key_packages.insert(k, frost::keys::KeyPackage::try_from(v).unwrap());
}

group.bench_with_input(
BenchmarkId::new("Round 1", min_signers),
Expand Down
11 changes: 8 additions & 3 deletions frost-core/src/frost/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub fn keygen_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
max_signers: u16,
min_signers: u16,
rng: &mut R,
) -> Result<(Vec<SecretShare<C>>, PublicKeyPackage<C>), Error<C>> {
) -> Result<(HashMap<Identifier<C>, SecretShare<C>>, PublicKeyPackage<C>), Error<C>> {
let mut bytes = [0; 64];
rng.fill_bytes(&mut bytes);

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

for secret_share in &secret_shares {
let mut secret_shares_by_id: HashMap<Identifier<C>, SecretShare<C>> =
HashMap::with_capacity(max_signers as usize);

for secret_share in secret_shares {
let signer_public = secret_share.value.into();
signer_pubkeys.insert(secret_share.identifier, signer_public);

secret_shares_by_id.insert(secret_share.identifier, secret_share);
}

Ok((
secret_shares,
secret_shares_by_id,
PublicKeyPackage {
signer_pubkeys,
group_public,
Expand Down
16 changes: 7 additions & 9 deletions frost-core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ pub fn check_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap();

// Verifies the secret shares from the dealer
let key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> = shares
.into_iter()
.map(|share| {
(
share.identifier,
frost::keys::KeyPackage::try_from(share).unwrap(),
)
})
.collect();
let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
HashMap::new();

for (k, v) in shares {
let key_package = frost::keys::KeyPackage::try_from(v).unwrap();
key_packages.insert(k, key_package);
}

check_sign(min_signers, key_packages, rng, pubkeys)
}
Expand Down
10 changes: 6 additions & 4 deletions frost-ed25519/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
// Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
.collect::<Result<_, frost::Error>>()?;
let mut key_packages: HashMap<_, _> = HashMap::new();

for (k, v) in shares {
let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}

let mut nonces = HashMap::new();
let mut commitments = HashMap::new();
Expand Down
4 changes: 3 additions & 1 deletion frost-ed25519/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ pub type Identifier = frost::Identifier<E>;

/// FROST(Ed25519, SHA-512) keys, key generation, key shares.
pub mod keys {
use std::collections::HashMap;

use super::*;

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

Expand Down
10 changes: 6 additions & 4 deletions frost-ed448/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
// Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
.collect::<Result<_, frost::Error>>()?;
let mut key_packages: HashMap<_, _> = HashMap::new();

for (k, v) in shares {
let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}

let mut nonces = HashMap::new();
let mut commitments = HashMap::new();
Expand Down
3 changes: 2 additions & 1 deletion frost-ed448/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,15 @@ pub type Identifier = frost::Identifier<E>;
/// FROST(Ed448, SHAKE256) keys, key generation, key shares.
pub mod keys {
use super::*;
use std::collections::HashMap;

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

Expand Down
10 changes: 6 additions & 4 deletions frost-p256/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
// Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
.collect::<Result<_, frost::Error>>()?;
let mut key_packages: HashMap<_, _> = HashMap::new();

for (k, v) in shares {
let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}

let mut nonces = HashMap::new();
let mut commitments = HashMap::new();
Expand Down
4 changes: 3 additions & 1 deletion frost-p256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ pub type Identifier = frost::Identifier<P>;

/// FROST(P-256, SHA-256) keys, key generation, key shares.
pub mod keys {
use std::collections::HashMap;

use super::*;

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

Expand Down
15 changes: 6 additions & 9 deletions frost-rerandomized/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ pub fn check_randomized_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>
frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap();

// Verifies the secret shares from the dealer
let key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> = shares
.into_iter()
.map(|share| {
(
share.identifier,
frost::keys::KeyPackage::try_from(share).unwrap(),
)
})
.collect();
let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
HashMap::new();

for (k, v) in shares {
key_packages.insert(k, frost::keys::KeyPackage::try_from(v).unwrap());
}

let mut nonces: HashMap<frost::Identifier<C>, frost::round1::SigningNonces<C>> = HashMap::new();
let mut commitments: HashMap<frost::Identifier<C>, frost::round1::SigningCommitments<C>> =
Expand Down
10 changes: 6 additions & 4 deletions frost-ristretto255/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
// Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
.collect::<Result<_, frost::Error>>()?;
let mut key_packages: HashMap<_, _> = HashMap::new();

for (k, v) in shares {
let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}

let mut nonces = HashMap::new();
let mut commitments = HashMap::new();
Expand Down
3 changes: 2 additions & 1 deletion frost-ristretto255/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,15 @@ pub type Identifier = frost::Identifier<R>;
/// FROST(ristretto255, SHA-512) keys, key generation, key shares.
pub mod keys {
use super::*;
use std::collections::HashMap;

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

Expand Down
10 changes: 6 additions & 4 deletions frost-secp256k1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ let (shares, pubkeys) = frost::keys::keygen_with_dealer(max_signers, min_signers
// Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?)))
.collect::<Result<_, frost::Error>>()?;
let mut key_packages: HashMap<_, _> = HashMap::new();

for (k, v) in shares {
let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}

let mut nonces = HashMap::new();
let mut commitments = HashMap::new();
Expand Down
3 changes: 2 additions & 1 deletion frost-secp256k1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ pub type Identifier = frost::Identifier<S>;
/// FROST(secp256k1, SHA-256) keys, key generation, key shares.
pub mod keys {
use super::*;
use std::collections::HashMap;

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

Expand Down

0 comments on commit c6f2d6b

Please sign in to comment.