You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #[macro_use]
  2. extern crate criterion;
  3. use algebra::ed_on_bls12_377::EdwardsProjective as Edwards;
  4. use blake2::Blake2s;
  5. use criterion::Criterion;
  6. use crypto_primitives::signature::{schnorr::*, SignatureScheme};
  7. use rand::{self, Rng};
  8. type SchnorrEdwards = Schnorr<Edwards, Blake2s>;
  9. fn schnorr_signature_setup(c: &mut Criterion) {
  10. c.bench_function("SchnorrEdwards: Setup", move |b| {
  11. b.iter(|| {
  12. let mut rng = &mut rand::thread_rng();
  13. SchnorrEdwards::setup(&mut rng).unwrap()
  14. })
  15. });
  16. }
  17. fn schnorr_signature_keygen(c: &mut Criterion) {
  18. let mut rng = &mut rand::thread_rng();
  19. let parameters = SchnorrEdwards::setup(&mut rng).unwrap();
  20. c.bench_function("SchnorrEdwards: KeyGen", move |b| {
  21. b.iter(|| {
  22. let mut rng = &mut rand::thread_rng();
  23. SchnorrEdwards::keygen(&parameters, &mut rng).unwrap()
  24. })
  25. });
  26. }
  27. fn schnorr_signature_sign(c: &mut Criterion) {
  28. let mut rng = &mut rand::thread_rng();
  29. let parameters = SchnorrEdwards::setup(&mut rng).unwrap();
  30. let (_, sk) = SchnorrEdwards::keygen(&parameters, &mut rng).unwrap();
  31. let message = [100u8; 128];
  32. c.bench_function("SchnorrEdwards: Sign", move |b| {
  33. b.iter(|| {
  34. let mut rng = &mut rand::thread_rng();
  35. SchnorrEdwards::sign(&parameters, &sk, &message, &mut rng).unwrap()
  36. })
  37. });
  38. }
  39. fn schnorr_signature_verify(c: &mut Criterion) {
  40. let mut rng = &mut rand::thread_rng();
  41. let parameters = SchnorrEdwards::setup(&mut rng).unwrap();
  42. let (pk, sk) = SchnorrEdwards::keygen(&parameters, &mut rng).unwrap();
  43. let message = [100u8; 128];
  44. let signature = SchnorrEdwards::sign(&parameters, &sk, &message, &mut rng).unwrap();
  45. c.bench_function("SchnorrEdwards: Verify", move |b| {
  46. b.iter(|| SchnorrEdwards::verify(&parameters, &pk, &message, &signature).unwrap())
  47. });
  48. }
  49. fn schnorr_signature_randomize_pk(c: &mut Criterion) {
  50. let mut rng = &mut rand::thread_rng();
  51. let parameters = SchnorrEdwards::setup(&mut rng).unwrap();
  52. let (pk, _) = SchnorrEdwards::keygen(&parameters, &mut rng).unwrap();
  53. let randomness: [u8; 32] = rng.gen();
  54. c.bench_function("SchnorrEdwards: Randomize PubKey", move |b| {
  55. b.iter(|| SchnorrEdwards::randomize_public_key(&parameters, &pk, &randomness).unwrap())
  56. });
  57. }
  58. fn schnorr_signature_randomize_signature(c: &mut Criterion) {
  59. let mut rng = &mut rand::thread_rng();
  60. let parameters = SchnorrEdwards::setup(&mut rng).unwrap();
  61. let (_, sk) = SchnorrEdwards::keygen(&parameters, &mut rng).unwrap();
  62. let randomness: [u8; 32] = rng.gen();
  63. let message = [100u8; 128];
  64. let signature = SchnorrEdwards::sign(&parameters, &sk, &message, &mut rng).unwrap();
  65. c.bench_function("SchnorrEdwards: Randomize Signature", move |b| {
  66. b.iter(|| {
  67. SchnorrEdwards::randomize_signature(&parameters, &signature, &randomness).unwrap()
  68. })
  69. });
  70. }
  71. criterion_group! {
  72. name = schnorr_sig;
  73. config = Criterion::default().sample_size(20);
  74. targets = schnorr_signature_setup, schnorr_signature_keygen, schnorr_signature_sign,
  75. schnorr_signature_verify, schnorr_signature_randomize_pk, schnorr_signature_randomize_signature
  76. }
  77. criterion_main!(schnorr_sig);