mirror of
https://github.com/arnaucube/kesto.git
synced 2026-02-06 19:16:44 +01:00
Add rust JubJub & BabyJubJub EdDSA benchmarks
This commit is contained in:
@@ -44,4 +44,21 @@ mod tests {
|
||||
"Fr(0x28410c403c92a9f18d1f27b22218b3649b3be8640dc160ad53bd21cf02f98d81)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_usage_bytes() {
|
||||
let msg = "hello";
|
||||
let b: BigInt = BigInt::parse_bytes(msg.as_bytes(), 10).unwrap();
|
||||
let v: Fr = Fr::from_str(&b.to_string()).unwrap();
|
||||
|
||||
let mut to_hash: Vec<Fr> = Vec::new();
|
||||
to_hash.push(v);
|
||||
|
||||
let poseidon = Poseidon::new();
|
||||
let h = poseidon.hash(to_hash).unwrap();
|
||||
assert_eq!(
|
||||
h.to_string(),
|
||||
"Fr(0x28410c403c92a9f18d1f27b22218b3649b3be8640dc160ad53bd21cf02f98d81)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
2
rust-crypto-benchmarks/.gitignore
vendored
Normal file
2
rust-crypto-benchmarks/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
24
rust-crypto-benchmarks/Cargo.toml
Normal file
24
rust-crypto-benchmarks/Cargo.toml
Normal file
@@ -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
|
||||
5
rust-crypto-benchmarks/README.md
Normal file
5
rust-crypto-benchmarks/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# rust-crypto-benchmarks
|
||||
|
||||
```
|
||||
cargo bench
|
||||
```
|
||||
44
rust-crypto-benchmarks/benches/bench_eddsa.rs
Normal file
44
rust-crypto-benchmarks/benches/bench_eddsa.rs
Normal file
@@ -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);
|
||||
7
rust-crypto-benchmarks/src/lib.rs
Normal file
7
rust-crypto-benchmarks/src/lib.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user