-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tristan/war 589 sylow code coverage (#28)
* equality + select tests on fields * first pass on coverage * second pass on coverage * added fuzzing and invariant testing * added doctests * clippy + fmt * typos * added const time check for signature generation * added const time check for pairing * fmt
- Loading branch information
Showing
13 changed files
with
691 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use dudect_bencher::{ctbench_main, BenchRng, Class, CtRunner}; | ||
use rand::Rng; | ||
use sylow::{sign, verify, KeyPair}; | ||
|
||
const MIN_MSG_LEN: usize = 1; | ||
const MAX_MSG_LEN: usize = 1024; | ||
|
||
fn generate_random_message(rng: &mut BenchRng) -> Vec<u8> { | ||
let len = rng.gen_range(MIN_MSG_LEN..=MAX_MSG_LEN); | ||
(0..len).map(|_| rng.gen::<u8>()).collect() | ||
} | ||
|
||
fn bench_pairing_generation(runner: &mut CtRunner, rng: &mut BenchRng) { | ||
let mut inputs = Vec::new(); | ||
let mut classes = Vec::new(); | ||
|
||
// Make 100,000 inputs on each run | ||
for _ in 0..10_000 { | ||
inputs.push(generate_random_message(rng)); | ||
// Randomly pick which distribution this example belongs to | ||
if rng.gen::<bool>() { | ||
classes.push(Class::Left); | ||
} else { | ||
classes.push(Class::Right); | ||
} | ||
} | ||
|
||
for (msg, class) in inputs.into_iter().zip(classes.into_iter()) { | ||
runner.run_one(class, || { | ||
let key_pair = KeyPair::generate(); | ||
match sign(&key_pair.secret_key, &msg) { | ||
Ok(signature) => { | ||
// Verify the signature | ||
match verify(&key_pair.public_key, &msg, &signature) { | ||
Ok(is_valid) => { | ||
assert!(is_valid, "Signature verification failed"); | ||
} | ||
Err(e) => println!("Verification error: {:?}", e), | ||
} | ||
} | ||
Err(e) => println!("Signing error: {:?}", e), | ||
} | ||
}); | ||
} | ||
} | ||
|
||
ctbench_main!(bench_pairing_generation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use dudect_bencher::{ctbench_main, BenchRng, Class, CtRunner}; | ||
use rand::Rng; | ||
use sha3::Keccak256; | ||
use sylow::{FieldExtensionTrait, Fp, Fr, G1Projective, GroupTrait, XMDExpander}; | ||
|
||
const DST: &[u8; 30] = b"WARLOCK-CHAOS-V01-CS01-SHA-256"; | ||
const K: u64 = 128; | ||
const MIN_MSG_LEN: usize = 1; | ||
const MAX_MSG_LEN: usize = 1024; | ||
|
||
fn generate_random_message(rng: &mut BenchRng) -> Vec<u8> { | ||
let len = rng.gen_range(MIN_MSG_LEN..=MAX_MSG_LEN); | ||
(0..len).map(|_| rng.gen::<u8>()).collect() | ||
} | ||
|
||
fn bench_signature_generation(runner: &mut CtRunner, rng: &mut BenchRng) { | ||
let mut inputs = Vec::new(); | ||
let mut classes = Vec::new(); | ||
|
||
let expander = XMDExpander::<Keccak256>::new(DST, K); | ||
let private_key = Fp::new(Fr::rand(rng).value()); | ||
|
||
// Make 100,000 inputs on each run | ||
for _ in 0..100_000 { | ||
inputs.push(generate_random_message(rng)); | ||
// Randomly pick which distribution this example belongs to | ||
if rng.gen::<bool>() { | ||
classes.push(Class::Left); | ||
} else { | ||
classes.push(Class::Right); | ||
} | ||
} | ||
|
||
for (msg, class) in inputs.into_iter().zip(classes.into_iter()) { | ||
runner.run_one(class, || { | ||
if let Ok(hashed_message) = G1Projective::hash_to_curve(&expander, &msg) { | ||
let _signature = hashed_message * private_key; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
ctbench_main!(bench_signature_generation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.