Skip to content

Commit

Permalink
Fix wrong constant hash to curve function
Browse files Browse the repository at this point in the history
  • Loading branch information
drskalman committed Dec 10, 2020
1 parent acc3b73 commit 3821a36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
11 changes: 2 additions & 9 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,9 @@ pub trait EngineBLS {

/// Hash one message to the signature curve.
fn hash_to_signature_curve<M: Borrow<[u8]>>(message: M) -> Self::SignatureGroup {

// TODO::arbitrary seed just to make it compile should come from the message
let seed = [
1, 0, 0, 0, 23, 0, 0, 0, 200, 1, 0, 0, 210, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
];

let mut myrng = rand::rngs::StdRng::from_seed(seed);
let mut myrng = rand::rngs::StdRng::from_seed(*array_ref![message.borrow(),0,32]);
<Self::SignatureGroup as UniformRand>::rand(&mut myrng)
}
}

/// Run the Miller loop from `Engine` but orients its arguments
/// to be a `SignatureGroup` and `PublicKeyGroup`.
Expand Down
15 changes: 11 additions & 4 deletions src/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<E: EngineBLS> Signature<E> {
// let message = s[0].into_affine().prepare();
// let signature = s[1].into_affine().prepare();
// TODO: Compare benchmarks on variants
E::verify_prepared( signature, once( & (publickey,message)) )
E::verify_prepared( signature, &[(publickey,message)] )
}
}

Expand Down Expand Up @@ -827,7 +827,8 @@ mod tests {
let good = Message::new(b"ctx",b"test message");

let mut keypair = Keypair::<ZBLS>::generate(thread_rng());
let good_sig = zbls_usual_bytes_test(keypair.sign(good));
let good_sig0 = keypair.sign(good);
let good_sig = zbls_usual_bytes_test(good_sig0);
assert!(good_sig.verify_slow());

let keypair_vt = keypair.into_vartime();
Expand All @@ -836,18 +837,24 @@ mod tests {
assert!( good_sig == keypair_vt.sign(good) );

let bad = Message::new(b"ctx",b"wrong message");
let bad_sig = zbls_usual_bytes_test(keypair.sign(bad));
let bad_sig0 = keypair.sign(bad);
let bad_sig = zbls_usual_bytes_test(bad_sig0);
assert!( bad_sig == keypair.into_vartime().sign(bad) );

assert!( bad_sig.verify() );

let another = Message::new(b"ctx",b"another message");
let another_sig = keypair.sign(another);
assert!( another_sig == keypair.into_vartime().sign(another) );
assert!( another_sig.verify() );


assert!(keypair.public.verify(good, &good_sig.signature),
"Verification of a valid signature failed!");


assert!(good != bad, "good == bad");
assert!(good_sig.signature != bad_sig.signature, "good sig == bad sig");

assert!(!keypair.public.verify(good, &bad_sig.signature),
"Verification of a signature on a different message passed!");
assert!(!keypair.public.verify(bad, &good_sig.signature),
Expand Down

0 comments on commit 3821a36

Please sign in to comment.