-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
88 additions
and
1 deletion.
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,82 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use ark_bls12_381::Bls12_381 as E; | ||
use ark_ec::pairing::Pairing; | ||
use ark_std::{test_rng, UniformRand}; | ||
use commuting_signature::{Params, Signer}; | ||
|
||
type Fr = <E as Pairing>::ScalarField; | ||
|
||
criterion_group!( | ||
benches, | ||
bench_sign, | ||
bench_verify, | ||
bench_verify_ciphertexts, | ||
bench_sign_on_ciphertexts | ||
); | ||
|
||
criterion_main!(benches); | ||
|
||
pub fn bench_sign(c: &mut Criterion) { | ||
let rng = &mut test_rng(); | ||
|
||
let params = Params::<E>::rand(rng); | ||
let signer = Signer::rand(rng); | ||
let value = Fr::rand(rng); | ||
|
||
c.bench_function("sign", |b| { | ||
b.iter(|| { | ||
signer.sign(rng, ¶ms, value); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn bench_verify(c: &mut Criterion) { | ||
let rng = &mut test_rng(); | ||
|
||
let params = Params::<E>::rand(rng); | ||
let signer = Signer::rand(rng); | ||
let verifier = signer.verifier(¶ms); | ||
let value = Fr::rand(rng); | ||
|
||
let (message, signature, _) = signer.sign(rng, ¶ms, value); | ||
|
||
c.bench_function("verify", |b| { | ||
b.iter(|| { | ||
verifier.verify(¶ms, &message, &signature); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn bench_verify_ciphertexts(c: &mut Criterion) { | ||
let rng = &mut test_rng(); | ||
|
||
let params = Params::<E>::rand(rng); | ||
let signer = Signer::rand(rng); | ||
let verifier = signer.verifier(¶ms); | ||
let value = Fr::rand(rng); | ||
|
||
let (_, _, ciphertexts) = signer.sign(rng, ¶ms, value); | ||
|
||
c.bench_function("verify_ciphertexts", |b| { | ||
b.iter(|| { | ||
verifier.verify_ciphertexts(¶ms, &ciphertexts); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn bench_sign_on_ciphertexts(c: &mut Criterion) { | ||
let rng = &mut test_rng(); | ||
|
||
let params = Params::<E>::rand(rng); | ||
let signer = Signer::rand(rng); | ||
let value = Fr::rand(rng); | ||
|
||
let (_, _, ciphertexts) = signer.sign(rng, ¶ms, value); | ||
|
||
c.bench_function("sign_on_ciphertexts", |b| { | ||
b.iter(|| { | ||
signer.sign_on_ciphertexts(rng, ¶ms, &ciphertexts); | ||
}) | ||
}); | ||
} |