Generalize out the FROST test for signing/signing with an offset

Moves Schnorr signature tests from test_curve to the new test_schnorr, 
which is more a test_frost.

Relevant to https://github.com/serai-dex/serai/issues/9.
This commit is contained in:
Luke Parker
2022-06-03 19:08:25 -04:00
parent 33241a5bb6
commit 9b52cf4d20
7 changed files with 83 additions and 66 deletions

View File

@@ -1,2 +1 @@
mod p256;
mod schnorr;

View File

@@ -12,7 +12,7 @@ use p256::{elliptic_curve::bigint::{Encoding, U384}, Scalar, ProjectivePoint};
use crate::{
CurveError, Curve,
algorithm::Hram,
tests::{curve::test_curve, vectors::{Vectors, vectors}}
tests::{curve::test_curve, schnorr::test_schnorr, vectors::{Vectors, vectors}}
};
const CONTEXT_STRING: &[u8] = b"FROST-P256-SHA256-v5";
@@ -179,8 +179,13 @@ fn p256_curve() {
test_curve::<_, P256>(&mut OsRng);
}
#[test]
fn p256_schnorr() {
test_schnorr::<_, P256>(&mut OsRng);
}
#[derive(Clone)]
pub struct IetfP256Hram {}
pub struct IetfP256Hram;
impl Hram<P256> for IetfP256Hram {
#[allow(non_snake_case)]
fn hram(R: &ProjectivePoint, A: &ProjectivePoint, m: &[u8]) -> Scalar {

View File

@@ -1,42 +0,0 @@
use std::rc::Rc;
use rand::rngs::OsRng;
use crate::{
Curve, schnorr, algorithm::{Hram, Schnorr},
tests::{key_gen, algorithm_machines, sign as sign_test, literal::p256::{P256, IetfP256Hram}}
};
const MESSAGE: &[u8] = b"Hello World";
#[test]
fn sign() {
sign_test(
&mut OsRng,
algorithm_machines(
&mut OsRng,
Schnorr::<P256, IetfP256Hram>::new(),
&key_gen::<_, P256>(&mut OsRng)
),
MESSAGE
);
}
#[test]
fn sign_with_offset() {
let mut keys = key_gen::<_, P256>(&mut OsRng);
let group_key = keys[&1].group_key();
let offset = P256::hash_to_F(b"offset", &[]);
for i in 1 ..= u16::try_from(keys.len()).unwrap() {
keys.insert(i, Rc::new(keys[&i].offset(offset)));
}
let offset_key = group_key + (P256::generator_table() * offset);
let sig = sign_test(
&mut OsRng,
algorithm_machines(&mut OsRng, Schnorr::<P256, IetfP256Hram>::new(), &keys),
MESSAGE
);
assert!(schnorr::verify(offset_key, IetfP256Hram::hram(&sig.R, &offset_key, MESSAGE), &sig));
}