check if the correct number of identifiers was provided in split() (#481)
This commit is contained in:
parent
5d97cf126d
commit
f3eb8681a8
|
@ -473,18 +473,25 @@ pub fn split<C: Ciphersuite, R: RngCore + CryptoRng>(
|
|||
) -> Result<(HashMap<Identifier<C>, SecretShare<C>>, PublicKeyPackage<C>), Error<C>> {
|
||||
validate_num_of_signers(min_signers, max_signers)?;
|
||||
|
||||
if let IdentifierList::Custom(identifiers) = &identifiers {
|
||||
if identifiers.len() != max_signers as usize {
|
||||
return Err(Error::IncorrectNumberOfIdentifiers);
|
||||
}
|
||||
}
|
||||
|
||||
let group_public = VerifyingKey::from(key);
|
||||
|
||||
let coefficients = generate_coefficients::<C, R>(min_signers as usize - 1, rng);
|
||||
|
||||
let default_identifiers = default_identifiers(max_signers);
|
||||
let identifiers = match identifiers {
|
||||
IdentifierList::Custom(identifiers) => identifiers,
|
||||
IdentifierList::Default => &default_identifiers,
|
||||
let secret_shares = match identifiers {
|
||||
IdentifierList::Default => {
|
||||
let identifiers = default_identifiers(max_signers);
|
||||
generate_secret_shares(key, max_signers, min_signers, coefficients, &identifiers)?
|
||||
}
|
||||
IdentifierList::Custom(identifiers) => {
|
||||
generate_secret_shares(key, max_signers, min_signers, coefficients, identifiers)?
|
||||
}
|
||||
};
|
||||
|
||||
let secret_shares =
|
||||
generate_secret_shares(key, max_signers, min_signers, coefficients, identifiers)?;
|
||||
let mut signer_pubkeys: HashMap<Identifier<C>, VerifyingShare<C>> =
|
||||
HashMap::with_capacity(max_signers as usize);
|
||||
|
||||
|
|
|
@ -506,13 +506,13 @@ fn check_part3_different_participants<C: Ciphersuite>(
|
|||
pub fn check_sign_with_dealer_and_identifiers<C: Ciphersuite, R: RngCore + CryptoRng>(
|
||||
mut rng: R,
|
||||
) -> (Vec<u8>, Signature<C>, VerifyingKey<C>) {
|
||||
// Check error case first (repeated identifiers)
|
||||
// Check error cases first
|
||||
// Check repeated identifiers
|
||||
|
||||
let identifiers: Vec<frost::Identifier<C>> = [1u16, 42, 100, 257, 42]
|
||||
.into_iter()
|
||||
.map(|i| i.try_into().unwrap())
|
||||
.collect();
|
||||
|
||||
let max_signers = 5;
|
||||
let min_signers = 3;
|
||||
let err = frost::keys::generate_with_dealer(
|
||||
|
@ -524,6 +524,23 @@ pub fn check_sign_with_dealer_and_identifiers<C: Ciphersuite, R: RngCore + Crypt
|
|||
.unwrap_err();
|
||||
assert_eq!(err, Error::DuplicatedIdentifier);
|
||||
|
||||
// Check incorrect number of identifiers
|
||||
|
||||
let identifiers: Vec<frost::Identifier<C>> = [1u16, 42, 100, 257]
|
||||
.into_iter()
|
||||
.map(|i| i.try_into().unwrap())
|
||||
.collect();
|
||||
let max_signers = 5;
|
||||
let min_signers = 3;
|
||||
let err = frost::keys::generate_with_dealer(
|
||||
max_signers,
|
||||
min_signers,
|
||||
frost::keys::IdentifierList::Custom(&identifiers),
|
||||
&mut rng,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(err, Error::IncorrectNumberOfIdentifiers);
|
||||
|
||||
// Check correct case
|
||||
|
||||
let identifiers: Vec<frost::Identifier<C>> = [1u16, 42, 100, 257, 65535]
|
||||
|
|
Loading…
Reference in New Issue