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.

44 lines
1.3 KiB

  1. use criterion::{criterion_group, criterion_main, Criterion};
  2. // JubJub
  3. use dusk_bls12_381::Scalar;
  4. use eddsa::{KeyPair, Message, PublicKey};
  5. extern crate rand7;
  6. // BabyJubJub
  7. extern crate rand;
  8. #[macro_use]
  9. extern crate ff;
  10. use ff::*;
  11. extern crate num;
  12. extern crate num_bigint;
  13. use babyjubjub_rs::{utils, Point};
  14. use num_bigint::{BigInt, Sign, ToBigInt};
  15. fn criterion_benchmark(c: &mut Criterion) {
  16. let mut m: [u8; 32] = rand::random::<[u8; 32]>();
  17. m[31] = 0;
  18. println!("m {:?}", m);
  19. // JubJub
  20. let keypair = KeyPair::new(&mut rand7::thread_rng()).unwrap();
  21. let message = Message(Scalar::from_bytes(&m).unwrap());
  22. c.bench_function("JubJub EdDSA sign", |b| b.iter(|| keypair.sign(&message)));
  23. let a = keypair.sign(&message);
  24. c.bench_function("JubJub EdDSA verify", |b| {
  25. b.iter(|| a.verify(&message, &keypair.public_key))
  26. });
  27. // BabyJubJub
  28. let sk = babyjubjub_rs::new_key();
  29. let pk = sk.public().unwrap();
  30. let msg = BigInt::from_bytes_le(Sign::Plus, &m);
  31. c.bench_function("BabyJubJub EdDSA sign", |b| b.iter(|| sk.sign(msg.clone())));
  32. let sig = sk.sign(msg.clone()).unwrap();
  33. c.bench_function("BabyJubJub EdDSA verify", |b| {
  34. b.iter(|| babyjubjub_rs::verify(pk.clone(), sig.clone(), msg.clone()))
  35. });
  36. }
  37. criterion_group!(benches, criterion_benchmark);
  38. criterion_main!(benches);