Update keygen_with_dealer to return a hashmap (#288)

* Change keygen_with_dealer to return a HashMap (#282)

Update docs

* Add vscode folder to gitignore
This commit is contained in:
natalie 2023-03-23 22:24:33 +00:00 committed by GitHub
parent ed5faa707b
commit c6f2d6b5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 70 additions and 55 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
Cargo.lock
*~
**/.DS_Store
.vscode/*

View File

@ -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),

View File

@ -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);
@ -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,

View File

@ -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)
}

View File

@ -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();

View File

@ -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
@ -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)
}

View File

@ -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();

View File

@ -196,6 +196,7 @@ 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.
@ -203,7 +204,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)
}

View File

@ -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();

View File

@ -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
@ -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)
}

View File

@ -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>> =

View File

@ -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();

View File

@ -190,6 +190,7 @@ 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.
@ -197,7 +198,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)
}

View File

@ -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();

View File

@ -225,6 +225,7 @@ 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.
@ -232,7 +233,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)
}