add RandomizedParams::from_randomizer() (#421)

This commit is contained in:
Conrado Gouvea 2023-06-30 07:56:14 -03:00 committed by GitHub
parent 19b4dbd874
commit de351a3edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -9,7 +9,7 @@ pub use frost_core;
use frost_core::{
frost::{self, keys::PublicKeyPackage},
Ciphersuite, Error, Field, Group, VerifyingKey,
Ciphersuite, Error, Field, Group, Scalar, VerifyingKey,
};
// When pulled into `reddsa`, that has its own sibling `rand_core` import.
@ -191,6 +191,18 @@ where
mut rng: R,
) -> Self {
let randomizer = <<C::Group as Group>::Field as Field>::random(&mut rng);
Self::from_randomizer(public_key_package, randomizer)
}
/// Create a new RandomizedParams for the given [`PublicKeyPackage`]
/// with the given `randomizer`. The `randomizer` MUST be generated uniformly
/// at random! Use [`RandomizedParams::new()`] which generates a fresh
/// randomizer, unless your application requires generating a randomizer
/// outside.
pub fn from_randomizer(
public_key_package: &PublicKeyPackage<C>,
randomizer: Scalar<C>,
) -> Self {
let randomizer_point = <C::Group as Group>::generator() * randomizer;
let group_public_point = public_key_package.group_public().to_element();

View File

@ -3,7 +3,7 @@
use std::collections::HashMap;
use crate::{frost_core::frost, frost_core::Ciphersuite, RandomizedParams};
use frost_core::{Signature, VerifyingKey};
use frost_core::{Field, Group, Signature, VerifyingKey};
use rand_core::{CryptoRng, RngCore};
/// Test re-randomized FROST signing with trusted dealer with a Ciphersuite.
@ -33,6 +33,7 @@ pub fn check_randomized_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>
let mut commitments: HashMap<frost::Identifier<C>, frost::round1::SigningCommitments<C>> =
HashMap::new();
check_from_randomizer(&pubkeys, &mut rng);
let randomizer_params = RandomizedParams::new(&pubkeys, &mut rng);
////////////////////////////////////////////////////////////////////////////
@ -116,3 +117,14 @@ pub fn check_randomized_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>
*randomizer_params.randomized_group_public_key(),
)
}
fn check_from_randomizer<C: Ciphersuite, R: RngCore + CryptoRng>(
pubkeys: &frost::keys::PublicKeyPackage<C>,
mut rng: &mut R,
) {
let randomizer = <<C::Group as Group>::Field as Field>::random(&mut rng);
let randomizer_params = RandomizedParams::from_randomizer(pubkeys, randomizer);
assert!(*randomizer_params.randomizer() == randomizer);
}