@ -0,0 +1,2 @@ |
|||||
|
/target |
||||
|
Cargo.lock |
@ -0,0 +1,24 @@ |
|||||
|
[package] |
||||
|
name = "rust-crypto-benchmarks" |
||||
|
version = "0.0.1" |
||||
|
authors = ["arnaucube <root@arnaucube.com>"] |
||||
|
edition = "2018" |
||||
|
|
||||
|
|
||||
|
[dependencies] |
||||
|
eddsa = {git = "https://github.com/dusk-network/EdDSA.git", branch = "master"} |
||||
|
dusk-bls12_381 = "0.1.3" |
||||
|
babyjubjub-rs = {git = "https://github.com/arnaucube/babyjubjub-rs.git", branch = "master"} |
||||
|
ff = {package="ff_ce" , version="0.11", features = ["derive"]} |
||||
|
rand = "0.4" |
||||
|
rand7 = {package="rand", version="0.7.0"} |
||||
|
num = "0.2.0" |
||||
|
num-bigint = {version = "0.2.2", features = ["rand"]} |
||||
|
|
||||
|
|
||||
|
[dev-dependencies] |
||||
|
criterion = "0.3" |
||||
|
|
||||
|
[[bench]] |
||||
|
name = "bench_eddsa" |
||||
|
harness = false |
@ -0,0 +1,5 @@ |
|||||
|
# rust-crypto-benchmarks |
||||
|
|
||||
|
``` |
||||
|
cargo bench |
||||
|
``` |
@ -0,0 +1,44 @@ |
|||||
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
|
||||
|
// JubJub
|
||||
|
use dusk_bls12_381::Scalar;
|
||||
|
use eddsa::{KeyPair, Message, PublicKey};
|
||||
|
extern crate rand7;
|
||||
|
|
||||
|
// BabyJubJub
|
||||
|
extern crate rand;
|
||||
|
#[macro_use]
|
||||
|
extern crate ff;
|
||||
|
use ff::*;
|
||||
|
extern crate num;
|
||||
|
extern crate num_bigint;
|
||||
|
use babyjubjub_rs::{utils, Point};
|
||||
|
use num_bigint::{BigInt, Sign, ToBigInt};
|
||||
|
|
||||
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||
|
let mut m: [u8; 32] = rand::random::<[u8; 32]>();
|
||||
|
m[31] = 0;
|
||||
|
println!("m {:?}", m);
|
||||
|
|
||||
|
// JubJub
|
||||
|
let keypair = KeyPair::new(&mut rand7::thread_rng()).unwrap();
|
||||
|
let message = Message(Scalar::from_bytes(&m).unwrap());
|
||||
|
c.bench_function("JubJub EdDSA sign", |b| b.iter(|| keypair.sign(&message)));
|
||||
|
let a = keypair.sign(&message);
|
||||
|
c.bench_function("JubJub EdDSA verify", |b| {
|
||||
|
b.iter(|| a.verify(&message, &keypair.public_key))
|
||||
|
});
|
||||
|
|
||||
|
// BabyJubJub
|
||||
|
let sk = babyjubjub_rs::new_key();
|
||||
|
let pk = sk.public().unwrap();
|
||||
|
let msg = BigInt::from_bytes_le(Sign::Plus, &m);
|
||||
|
c.bench_function("BabyJubJub EdDSA sign", |b| b.iter(|| sk.sign(msg.clone())));
|
||||
|
let sig = sk.sign(msg.clone()).unwrap();
|
||||
|
c.bench_function("BabyJubJub EdDSA verify", |b| {
|
||||
|
b.iter(|| babyjubjub_rs::verify(pk.clone(), sig.clone(), msg.clone()))
|
||||
|
});
|
||||
|
}
|
||||
|
|
||||
|
criterion_group!(benches, criterion_benchmark);
|
||||
|
criterion_main!(benches);
|
@ -0,0 +1,7 @@ |
|||||
|
#[cfg(test)]
|
||||
|
mod tests {
|
||||
|
#[test]
|
||||
|
fn it_works() {
|
||||
|
assert_eq!(2 + 2, 4);
|
||||
|
}
|
||||
|
}
|