diff --git a/.gitignore b/.gitignore index b3e1d16e..5d3d773b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ Cargo.lock *~ **/.DS_Store +.vscode/* diff --git a/frost-core/src/benches.rs b/frost-core/src/benches.rs index 02741395..b8a27859 100644 --- a/frost-core/src/benches.rs +++ b/frost-core/src/benches.rs @@ -102,15 +102,12 @@ pub fn bench_sign( frost::keys::keygen_with_dealer::(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::keys::KeyPackage> = + 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), diff --git a/frost-core/src/frost/keys.rs b/frost-core/src/frost/keys.rs index f07aeb4d..49e7ff4d 100644 --- a/frost-core/src/frost/keys.rs +++ b/frost-core/src/frost/keys.rs @@ -323,7 +323,7 @@ pub fn keygen_with_dealer( max_signers: u16, min_signers: u16, rng: &mut R, -) -> Result<(Vec>, PublicKeyPackage), Error> { +) -> Result<(HashMap, SecretShare>, PublicKeyPackage), Error> { let mut bytes = [0; 64]; rng.fill_bytes(&mut bytes); @@ -336,13 +336,18 @@ pub fn keygen_with_dealer( let mut signer_pubkeys: HashMap, VerifyingShare> = HashMap::with_capacity(max_signers as usize); - for secret_share in &secret_shares { + let mut secret_shares_by_id: HashMap, SecretShare> = + 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, diff --git a/frost-core/src/tests.rs b/frost-core/src/tests.rs index 0315b59c..ba19d985 100644 --- a/frost-core/src/tests.rs +++ b/frost-core/src/tests.rs @@ -48,15 +48,13 @@ pub fn check_sign_with_dealer( frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap(); // Verifies the secret shares from the dealer - let key_packages: HashMap, frost::keys::KeyPackage> = shares - .into_iter() - .map(|share| { - ( - share.identifier, - frost::keys::KeyPackage::try_from(share).unwrap(), - ) - }) - .collect(); + let mut key_packages: HashMap, frost::keys::KeyPackage> = + 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) } diff --git a/frost-ed25519/README.md b/frost-ed25519/README.md index 0022d3d9..d355b43e 100644 --- a/frost-ed25519/README.md +++ b/frost-ed25519/README.md @@ -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::>()?; +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(); diff --git a/frost-ed25519/src/lib.rs b/frost-ed25519/src/lib.rs index 9673651d..be4bab66 100644 --- a/frost-ed25519/src/lib.rs +++ b/frost-ed25519/src/lib.rs @@ -200,6 +200,8 @@ pub type Identifier = frost::Identifier; /// 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, PublicKeyPackage), Error> { + ) -> Result<(HashMap, PublicKeyPackage), Error> { frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng) } diff --git a/frost-ed448/README.md b/frost-ed448/README.md index 61391af5..de00eee7 100644 --- a/frost-ed448/README.md +++ b/frost-ed448/README.md @@ -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::>()?; +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(); diff --git a/frost-ed448/src/lib.rs b/frost-ed448/src/lib.rs index 32705d8f..d6449f79 100644 --- a/frost-ed448/src/lib.rs +++ b/frost-ed448/src/lib.rs @@ -196,6 +196,7 @@ pub type Identifier = frost::Identifier; /// 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, PublicKeyPackage), Error> { + ) -> Result<(HashMap, PublicKeyPackage), Error> { frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng) } diff --git a/frost-p256/README.md b/frost-p256/README.md index d16f6738..e3774fbc 100644 --- a/frost-p256/README.md +++ b/frost-p256/README.md @@ -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::>()?; +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(); diff --git a/frost-p256/src/lib.rs b/frost-p256/src/lib.rs index f33ada0d..b53d216c 100644 --- a/frost-p256/src/lib.rs +++ b/frost-p256/src/lib.rs @@ -224,6 +224,8 @@ pub type Identifier = frost::Identifier

; /// 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, PublicKeyPackage), Error> { + ) -> Result<(HashMap, PublicKeyPackage), Error> { frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng) } diff --git a/frost-rerandomized/src/tests.rs b/frost-rerandomized/src/tests.rs index a08ad41b..8c5ebc1b 100644 --- a/frost-rerandomized/src/tests.rs +++ b/frost-rerandomized/src/tests.rs @@ -22,15 +22,12 @@ pub fn check_randomized_sign_with_dealer frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng).unwrap(); // Verifies the secret shares from the dealer - let key_packages: HashMap, frost::keys::KeyPackage> = shares - .into_iter() - .map(|share| { - ( - share.identifier, - frost::keys::KeyPackage::try_from(share).unwrap(), - ) - }) - .collect(); + let mut key_packages: HashMap, frost::keys::KeyPackage> = + HashMap::new(); + + for (k, v) in shares { + key_packages.insert(k, frost::keys::KeyPackage::try_from(v).unwrap()); + } let mut nonces: HashMap, frost::round1::SigningNonces> = HashMap::new(); let mut commitments: HashMap, frost::round1::SigningCommitments> = diff --git a/frost-ristretto255/README.md b/frost-ristretto255/README.md index 219c0c99..923e57f2 100644 --- a/frost-ristretto255/README.md +++ b/frost-ristretto255/README.md @@ -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::>()?; +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(); diff --git a/frost-ristretto255/src/lib.rs b/frost-ristretto255/src/lib.rs index 82e4aeb3..9270ba5b 100644 --- a/frost-ristretto255/src/lib.rs +++ b/frost-ristretto255/src/lib.rs @@ -190,6 +190,7 @@ pub type Identifier = frost::Identifier; /// 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, PublicKeyPackage), Error> { + ) -> Result<(HashMap, PublicKeyPackage), Error> { frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng) } diff --git a/frost-secp256k1/README.md b/frost-secp256k1/README.md index ad2b0d23..af179e0e 100644 --- a/frost-secp256k1/README.md +++ b/frost-secp256k1/README.md @@ -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::>()?; +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(); diff --git a/frost-secp256k1/src/lib.rs b/frost-secp256k1/src/lib.rs index 56308ac2..581a9bc9 100644 --- a/frost-secp256k1/src/lib.rs +++ b/frost-secp256k1/src/lib.rs @@ -225,6 +225,7 @@ pub type Identifier = frost::Identifier; /// 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, PublicKeyPackage), Error> { + ) -> Result<(HashMap, PublicKeyPackage), Error> { frost::keys::keygen_with_dealer(max_signers, min_signers, &mut rng) }