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 Cargo.lock
*~ *~
**/.DS_Store **/.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(); frost::keys::keygen_with_dealer::<C, R>(max_signers, min_signers, rng).unwrap();
// Verifies the secret shares from the dealer // Verifies the secret shares from the dealer
let key_packages: HashMap<_, _> = shares let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
.into_iter() HashMap::new();
.map(|share| {
( for (k, v) in shares {
share.identifier, key_packages.insert(k, frost::keys::KeyPackage::try_from(v).unwrap());
frost::keys::KeyPackage::try_from(share).unwrap(), }
)
})
.collect();
group.bench_with_input( group.bench_with_input(
BenchmarkId::new("Round 1", min_signers), 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, max_signers: u16,
min_signers: u16, min_signers: u16,
rng: &mut R, 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]; let mut bytes = [0; 64];
rng.fill_bytes(&mut bytes); 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>> = let mut signer_pubkeys: HashMap<Identifier<C>, VerifyingShare<C>> =
HashMap::with_capacity(max_signers as usize); 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(); let signer_public = secret_share.value.into();
signer_pubkeys.insert(secret_share.identifier, signer_public); signer_pubkeys.insert(secret_share.identifier, signer_public);
secret_shares_by_id.insert(secret_share.identifier, secret_share);
} }
Ok(( Ok((
secret_shares, secret_shares_by_id,
PublicKeyPackage { PublicKeyPackage {
signer_pubkeys, signer_pubkeys,
group_public, 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(); frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap();
// Verifies the secret shares from the dealer // Verifies the secret shares from the dealer
let key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> = shares let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
.into_iter() HashMap::new();
.map(|share| {
( for (k, v) in shares {
share.identifier, let key_package = frost::keys::KeyPackage::try_from(v).unwrap();
frost::keys::KeyPackage::try_from(share).unwrap(), key_packages.insert(k, key_package);
) }
})
.collect();
check_sign(min_signers, key_packages, rng, pubkeys) 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. // Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants // In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel. // through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares let mut key_packages: HashMap<_, _> = HashMap::new();
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) for (k, v) in shares {
.collect::<Result<_, frost::Error>>()?; let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}
let mut nonces = HashMap::new(); let mut nonces = HashMap::new();
let mut commitments = 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. /// FROST(Ed25519, SHA-512) keys, key generation, key shares.
pub mod keys { pub mod keys {
use std::collections::HashMap;
use super::*; use super::*;
/// Allows all participants' keys to be generated using a central, trusted /// Allows all participants' keys to be generated using a central, trusted
@ -208,7 +210,7 @@ pub mod keys {
max_signers: u16, max_signers: u16,
min_signers: u16, min_signers: u16,
mut rng: RNG, 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) 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. // Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants // In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel. // through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares let mut key_packages: HashMap<_, _> = HashMap::new();
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) for (k, v) in shares {
.collect::<Result<_, frost::Error>>()?; let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}
let mut nonces = HashMap::new(); let mut nonces = HashMap::new();
let mut commitments = 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. /// FROST(Ed448, SHAKE256) keys, key generation, key shares.
pub mod keys { pub mod keys {
use super::*; use super::*;
use std::collections::HashMap;
/// Allows all participants' keys to be generated using a central, trusted /// Allows all participants' keys to be generated using a central, trusted
/// dealer. /// dealer.
@ -203,7 +204,7 @@ pub mod keys {
max_signers: u16, max_signers: u16,
min_signers: u16, min_signers: u16,
mut rng: RNG, 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) 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. // Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants // In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel. // through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares let mut key_packages: HashMap<_, _> = HashMap::new();
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) for (k, v) in shares {
.collect::<Result<_, frost::Error>>()?; let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}
let mut nonces = HashMap::new(); let mut nonces = HashMap::new();
let mut commitments = 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. /// FROST(P-256, SHA-256) keys, key generation, key shares.
pub mod keys { pub mod keys {
use std::collections::HashMap;
use super::*; use super::*;
/// Allows all participants' keys to be generated using a central, trusted /// Allows all participants' keys to be generated using a central, trusted
@ -232,7 +234,7 @@ pub mod keys {
max_signers: u16, max_signers: u16,
min_signers: u16, min_signers: u16,
mut rng: RNG, 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) 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(); frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap();
// Verifies the secret shares from the dealer // Verifies the secret shares from the dealer
let key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> = shares let mut key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>> =
.into_iter() HashMap::new();
.map(|share| {
( for (k, v) in shares {
share.identifier, key_packages.insert(k, frost::keys::KeyPackage::try_from(v).unwrap());
frost::keys::KeyPackage::try_from(share).unwrap(), }
)
})
.collect();
let mut nonces: HashMap<frost::Identifier<C>, frost::round1::SigningNonces<C>> = HashMap::new(); let mut nonces: HashMap<frost::Identifier<C>, frost::round1::SigningNonces<C>> = HashMap::new();
let mut commitments: HashMap<frost::Identifier<C>, frost::round1::SigningCommitments<C>> = 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. // Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants // In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel. // through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares let mut key_packages: HashMap<_, _> = HashMap::new();
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) for (k, v) in shares {
.collect::<Result<_, frost::Error>>()?; let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}
let mut nonces = HashMap::new(); let mut nonces = HashMap::new();
let mut commitments = 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. /// FROST(ristretto255, SHA-512) keys, key generation, key shares.
pub mod keys { pub mod keys {
use super::*; use super::*;
use std::collections::HashMap;
/// Allows all participants' keys to be generated using a central, trusted /// Allows all participants' keys to be generated using a central, trusted
/// dealer. /// dealer.
@ -197,7 +198,7 @@ pub mod keys {
max_signers: u16, max_signers: u16,
min_signers: u16, min_signers: u16,
mut rng: RNG, 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) 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. // Verifies the secret shares from the dealer and store them in a HashMap.
// In practice, the KeyPackages must be sent to its respective participants // In practice, the KeyPackages must be sent to its respective participants
// through a confidential and authenticated channel. // through a confidential and authenticated channel.
let key_packages: HashMap<_, _> = shares let mut key_packages: HashMap<_, _> = HashMap::new();
.into_iter()
.map(|share| Ok((share.identifier, frost::keys::KeyPackage::try_from(share)?))) for (k, v) in shares {
.collect::<Result<_, frost::Error>>()?; let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}
let mut nonces = HashMap::new(); let mut nonces = HashMap::new();
let mut commitments = 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. /// FROST(secp256k1, SHA-256) keys, key generation, key shares.
pub mod keys { pub mod keys {
use super::*; use super::*;
use std::collections::HashMap;
/// Allows all participants' keys to be generated using a central, trusted /// Allows all participants' keys to be generated using a central, trusted
/// dealer. /// dealer.
@ -232,7 +233,7 @@ pub mod keys {
max_signers: u16, max_signers: u16,
min_signers: u16, min_signers: u16,
mut rng: RNG, 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) frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng)
} }