add ed25519 interoperability test (#208)
* add ed25519 interoperability test * add multiple iterations to check_sign_with_dkg in ed25519
This commit is contained in:
parent
9be13c4bfa
commit
084ed95f46
|
@ -1,7 +1,7 @@
|
|||
//! Ciphersuite-generic test functions.
|
||||
use std::{collections::HashMap, convert::TryFrom};
|
||||
|
||||
use crate::frost;
|
||||
use crate::{frost, Signature, VerifyingKey};
|
||||
use rand_core::{CryptoRng, RngCore};
|
||||
|
||||
use crate::Ciphersuite;
|
||||
|
@ -35,7 +35,9 @@ pub fn check_share_generation<C: Ciphersuite, R: RngCore + CryptoRng>(mut rng: R
|
|||
}
|
||||
|
||||
/// Test FROST signing with trusted dealer with a Ciphersuite.
|
||||
pub fn check_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(mut rng: R) {
|
||||
pub fn check_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
|
||||
mut rng: R,
|
||||
) -> (Vec<u8>, Signature<C>, VerifyingKey<C>) {
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Key generation
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -56,7 +58,7 @@ pub fn check_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(mut rng: R
|
|||
})
|
||||
.collect();
|
||||
|
||||
check_sign(min_signers, key_packages, rng, pubkeys);
|
||||
check_sign(min_signers, key_packages, rng, pubkeys)
|
||||
}
|
||||
|
||||
fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
|
||||
|
@ -64,7 +66,7 @@ fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
|
|||
key_packages: HashMap<frost::Identifier<C>, frost::keys::KeyPackage<C>>,
|
||||
mut rng: R,
|
||||
pubkeys: frost::keys::PublicKeyPackage<C>,
|
||||
) {
|
||||
) -> (Vec<u8>, Signature<C>, VerifyingKey<C>) {
|
||||
let mut nonces: HashMap<frost::Identifier<C>, frost::round1::SigningNonces<C>> = HashMap::new();
|
||||
let mut commitments: HashMap<frost::Identifier<C>, frost::round1::SigningCommitments<C>> =
|
||||
HashMap::new();
|
||||
|
@ -141,10 +143,14 @@ fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
|
|||
.verify(message, &group_signature)
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
(message.to_owned(), group_signature, pubkeys.group_public)
|
||||
}
|
||||
|
||||
/// Test FROST signing with trusted dealer with a Ciphersuite.
|
||||
pub fn check_sign_with_dkg<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(mut rng: R)
|
||||
pub fn check_sign_with_dkg<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
|
||||
mut rng: R,
|
||||
) -> (Vec<u8>, Signature<C>, VerifyingKey<C>)
|
||||
where
|
||||
C::Group: std::cmp::PartialEq,
|
||||
{
|
||||
|
@ -303,5 +309,5 @@ where
|
|||
};
|
||||
|
||||
// Proceed with the signing test.
|
||||
check_sign(min_signers, key_packages, rng, pubkeys);
|
||||
check_sign(min_signers, key_packages, rng, pubkeys)
|
||||
}
|
||||
|
|
|
@ -1,20 +1,56 @@
|
|||
use curve25519_dalek::{edwards::EdwardsPoint, traits::Identity};
|
||||
use frost_core::{Ciphersuite, Group, GroupError};
|
||||
use frost_ed25519::*;
|
||||
|
||||
use curve25519_dalek::{edwards::EdwardsPoint, traits::Identity};
|
||||
use ed25519_dalek::Verifier;
|
||||
use rand::thread_rng;
|
||||
|
||||
fn verify_signature(
|
||||
msg: &[u8],
|
||||
group_signature: frost_core::Signature<Ed25519Sha512>,
|
||||
group_pubkey: frost_core::VerifyingKey<Ed25519Sha512>,
|
||||
) {
|
||||
let sig = {
|
||||
let bytes: [u8; 64] = group_signature.to_bytes();
|
||||
ed25519_dalek::Signature::from(bytes)
|
||||
};
|
||||
let pub_key = {
|
||||
let bytes = group_pubkey.to_bytes();
|
||||
ed25519_dalek::PublicKey::from_bytes(&bytes).unwrap()
|
||||
};
|
||||
// Check that signature validation has the expected result.
|
||||
assert!(pub_key.verify(msg, &sig).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_sign_with_dealer() {
|
||||
let rng = thread_rng();
|
||||
|
||||
frost_core::tests::check_sign_with_dealer::<Ed25519Sha512, _>(rng);
|
||||
// Test with multiple keys/signatures to better exercise the key generation
|
||||
// and the interoperability check.
|
||||
for _ in 0..256 {
|
||||
let (msg, group_signature, group_pubkey) =
|
||||
frost_core::tests::check_sign_with_dealer::<Ed25519Sha512, _>(rng.clone());
|
||||
|
||||
// Check that the threshold signature can be verified by the `ed25519_dalek` crate
|
||||
// public key (interoperability test)
|
||||
verify_signature(&msg, group_signature, group_pubkey);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_sign_with_dkg() {
|
||||
let rng = thread_rng();
|
||||
|
||||
frost_core::tests::check_sign_with_dkg::<Ed25519Sha512, _>(rng);
|
||||
// Test with multiple keys/signatures to better exercise the key generation
|
||||
// and the interoperability check. A smaller number of iterations is used
|
||||
// because DKG takes longer and otherwise the test would be too slow.
|
||||
for _ in 0..32 {
|
||||
let (msg, group_signature, group_pubkey) =
|
||||
frost_core::tests::check_sign_with_dkg::<Ed25519Sha512, _>(rng.clone());
|
||||
|
||||
verify_signature(&msg, group_signature, group_pubkey);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue