Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Benchmark OpenSSL Sign/Verify #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions example_crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ publish = false
name = "keygen"
harness = false

[[bench]]
name = "iters"
harness = false

[[bench]]
name = "rand"
harness = false

[[bench]]
name = "secp384r1"
harness = false

[[bench]]
name = "sign"
harness = false
Expand Down
23 changes: 23 additions & 0 deletions example_crypto/benches/iters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use criterion::{criterion_group, criterion_main, Criterion};

pub struct EndlessIter<T> {
pub values: Vec<T>,
}

impl<T> Iterator for EndlessIter<T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
todo!()
}
}

fn bench(c: &mut Criterion) {}

criterion_group! {
name = iters;
config = Criterion::default();
targets = bench
}

criterion_main!(iters);
33 changes: 12 additions & 21 deletions example_crypto/benches/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
use criterion::{criterion_group, criterion_main, Criterion};
use example_crypto::openssl::keygen::{keygen_ec, keygen_ed25519, keygen_ed448, keygen_rsa, keygen_x25519, keygen_x448};
use openssl::ec::EcGroup;
use openssl::nid::Nid;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use example_crypto::openssl::benches::KeyGenerator;

pub fn bench_keygen(c: &mut Criterion) {
let secp256k1 = EcGroup::from_curve_name(Nid::SECP256K1).unwrap();
fn bench_keygen(c: &mut Criterion) {
let mut group = c.benchmark_group("openssl::keygen");

// // eddsa
c.bench_function("openssl::keygen::ed25519", |b| b.iter(|| keygen_ed25519()));
c.bench_function("openssl::keygen::ed448", |b| b.iter(|| keygen_ed448()));
c.bench_function("openssl::keygen::x25519", |b| b.iter(|| keygen_x25519()));
c.bench_function("openssl::keygen::x448", |b| b.iter(|| keygen_x448()));

// ecdsa
c.bench_function("openssl::keygen::secp256", |b| {
b.iter(|| keygen_ec(&secp256k1))
group.bench_function("prime256v1", |b| {
b.iter(black_box(KeyGenerator::prime256v1))
});

// rsa
c.bench_function("openssl::keygen::rsa2048", |b| b.iter(|| keygen_rsa(2048)));
c.bench_function("openssl::keygen::rsa3072", |b| b.iter(|| keygen_rsa(3072)));
c.bench_function("openssl::keygen::rsa4096", |b| b.iter(|| keygen_rsa(4096)));
group.bench_function("secp256k1", |b| b.iter(black_box(KeyGenerator::secp256k1)));
group.bench_function("secp384r", |b| b.iter(black_box(KeyGenerator::secp384r1)));
group.bench_function("ed25519", |b| b.iter(black_box(KeyGenerator::ed25519)));
group.bench_function("ed448", |b| b.iter(black_box(KeyGenerator::ed448)));
}

criterion_group!{
criterion_group! {
name = keygen;
config = Criterion::default();
targets = bench_keygen
}

criterion_main!(keygen);
criterion_main!(keygen);
44 changes: 44 additions & 0 deletions example_crypto/benches/secp384r1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use criterion::{criterion_group, criterion_main, Criterion};
use openssl::ec::{EcGroup, EcKey};
use openssl::hash::MessageDigest;
use openssl::nid::Nid;
use openssl::pkey::{PKey, Private};
use openssl::sign::Signer;

struct Key {
pkey: PKey<Private>,
digest: MessageDigest,
}

impl Key {
fn secp384r1(digest: MessageDigest) -> Self {
Self {
pkey: PKey::from_ec_key(
EcKey::generate(EcGroup::from_curve_name(Nid::SECP384R1).unwrap().as_ref())
.unwrap(),
)
.unwrap(),
digest,
}
}

pub fn secp384r1_sha256() -> Self {
Self::secp384r1(MessageDigest::sha256())
}

pub fn secp384r1_sha384() -> Self {
Self::secp384r1(MessageDigest::sha384())
}
}

fn bench_secp384r1(c: &mut Criterion) {
c.bench_function("secp384r1::generate", |b| b.ite)
}

criterion_group! {
name = secp384r1;
config = Criterion::default();
targets = bench_secp384r1
}

criterion_main!(secp384r1);
Loading