Skip to content

Commit

Permalink
Only benchmark our library by default (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth authored Feb 23, 2023
1 parent 3c3a3b2 commit 2ca01e5
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 159 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
- name: Install cargo-udeps
uses: actions-rs/[email protected]
with:
command: install
command: install
args: cargo-udeps

- name: Run cargo udeps
Expand All @@ -185,7 +185,8 @@ jobs:
os: [ubuntu-latest, macOS-latest]
target: [native, aarch64-unknown-linux-gnu, i686-unknown-linux-gnu]
args:
- --release --all-targets
- --all-targets
- --release --all-targets --features ring-benchmarks
- --no-default-features --features non-fips
- --no-default-features --features non-fips,ring-io
- --no-default-features --features non-fips,ring-sig-verify
Expand Down Expand Up @@ -268,10 +269,10 @@ jobs:
- name: Install cargo-llvm-cov
uses: actions-rs/[email protected]
with:
command: install
command: install
args: cargo-llvm-cov

# TODO: add bot to post coverage details to PR, or upload results to AWS
# TODO: add bot to post coverage details to PR, or upload results to AWS
# account. Using --html can give us more insight which regions are missing
# coverage immediately.
- name: Run coverage
Expand Down Expand Up @@ -334,7 +335,7 @@ jobs:
RUSTFLAGS: -Zsanitizer=address
RUSTDOCFLAGS: -Zsanitizer=address
with:
command: test
command: test
args: --lib --bins --tests --examples --target x86_64-unknown-linux-gnu --features asan

asan-release:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ alloc = []
default = ["aws-lc-sys", "alloc", "ring-io", "ring-sig-verify"]
ring-io = ["dep:untrusted"]
ring-sig-verify = ["dep:untrusted"]
ring-benchmarks = []
bindgen = ["aws-lc-sys?/bindgen", "aws-lc-fips-sys?/bindgen"]
asan = ["aws-lc-sys?/asan", "aws-lc-fips-sys?/asan"]

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ coverage:

ci:
cargo fmt --check --verbose
cargo test --all-targets --features ring-benchmarks
cargo test --release --all-targets
ifeq ($(UNAME_S),Linux)
cargo test --release --all-targets --features fips
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ Allows implementation to allocate values of unbounded size. (The meaning of this
feature of *ring*.) Currently, this is only required by the `io::writer` module.

* `ring-io` (*default*)
Enable feature to access the io module.
This feature enables the `io` module. Requires `untrusted = "0.7.1"`.

* `ring-sig-verify` (*default*)
This feature enables Trait method `signature::VerificationAlgorithm::verify`. This method is deprecated,
use `signature::VerificationAlgorithm::verify_sig` instead. Requires `untrusted = "0.7.1"`.

* `ring-benchmarks`
This feature enables benchmarks to run against `ring`.

* `asan`
Performs an “address sanitizer” build of *AWS-LC*. This can be used to help detect memory leaks. See the
Expand Down
58 changes: 33 additions & 25 deletions benches/aead_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ macro_rules! benchmark_aead
mod [<$pkg _benchmarks>] {

use $pkg::{aead, error};
/*
mod ring_benchmarks {
use ring::{aead, error, test};
*/

use criterion::black_box;
use crate::AeadConfig;
use aead::{
Expand Down Expand Up @@ -122,8 +119,9 @@ mod ring_benchmarks {
}
}}}

benchmark_aead!(ring);
benchmark_aead!(aws_lc_rust);
#[cfg(feature = "ring-benchmarks")]
benchmark_aead!(ring);

fn test_aes_128_gcm(c: &mut Criterion) {
test::run(
Expand Down Expand Up @@ -201,13 +199,17 @@ fn test_aead_separate(c: &mut Criterion, config: &AeadConfig) {
});
});

let mut ring_sealing_key = ring_benchmarks::create_sealing_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let ring_aad = ring_benchmarks::aad(config);
let _tag = ring_benchmarks::seal_separate(&mut ring_sealing_key, ring_aad, &mut in_out);
#[cfg(feature = "ring-benchmarks")]
{
let mut ring_sealing_key = ring_benchmarks::create_sealing_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let ring_aad = ring_benchmarks::aad(config);
let _tag =
ring_benchmarks::seal_separate(&mut ring_sealing_key, ring_aad, &mut in_out);
});
});
});
}
}

fn test_aead_append(c: &mut Criterion, config: &AeadConfig) {
Expand All @@ -225,14 +227,17 @@ fn test_aead_append(c: &mut Criterion, config: &AeadConfig) {
});
});

let mut ring_sealing_key = ring_benchmarks::create_sealing_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let mut ring_in_out = in_out.clone();
let ring_aad = ring_benchmarks::aad(config);
ring_benchmarks::seal_append(&mut ring_sealing_key, ring_aad, &mut ring_in_out);
#[cfg(feature = "ring-benchmarks")]
{
let mut ring_sealing_key = ring_benchmarks::create_sealing_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let mut ring_in_out = in_out.clone();
let ring_aad = ring_benchmarks::aad(config);
ring_benchmarks::seal_append(&mut ring_sealing_key, ring_aad, &mut ring_in_out);
});
});
});
}
}

fn test_aead_open(c: &mut Criterion, config: &AeadConfig) {
Expand All @@ -254,14 +259,17 @@ fn test_aead_open(c: &mut Criterion, config: &AeadConfig) {
});
});

let mut ring_opening_key = ring_benchmarks::create_opening_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let mut ring_in_out = in_out.clone();
let ring_aad = ring_benchmarks::aad(config);
ring_benchmarks::open(&mut ring_opening_key, ring_aad, &mut ring_in_out);
#[cfg(feature = "ring-benchmarks")]
{
let mut ring_opening_key = ring_benchmarks::create_opening_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let mut ring_in_out = in_out.clone();
let ring_aad = ring_benchmarks::aad(config);
ring_benchmarks::open(&mut ring_opening_key, ring_aad, &mut ring_in_out);
});
});
});
}
}

criterion_group!(benches, test_aes_128_gcm, test_aes_256_gcm, test_chacha20,);
Expand Down
21 changes: 10 additions & 11 deletions benches/agreement_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ macro_rules! benchmark_agreement {

use $pkg::{agreement, test};

/*
mod ring_benchmarks {
use ring::{agreement, test};
*/
use crate::{AgreementConfig, Curve};
use agreement::{
agree_ephemeral, Algorithm, EphemeralPrivateKey, UnparsedPublicKey, ECDH_P256, ECDH_P384,
Expand Down Expand Up @@ -86,6 +82,7 @@ mod ring_benchmarks {
}

benchmark_agreement!(aws_lc_rust);
#[cfg(feature = "ring-benchmarks")]
benchmark_agreement!(ring);

fn test_agree_ephemeral(c: &mut Criterion, config: &AgreementConfig) {
Expand All @@ -100,14 +97,16 @@ fn test_agree_ephemeral(c: &mut Criterion, config: &AgreementConfig) {
aws_lc_rust_benchmarks::agreement(private_key, &aws_peer_public_key);
});
});

let ring_peer_public_key = ring_benchmarks::peer_public_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let private_key = ring_benchmarks::private_key(config);
ring_benchmarks::agreement(private_key, &ring_peer_public_key);
#[cfg(feature = "ring-benchmarks")]
{
let ring_peer_public_key = ring_benchmarks::peer_public_key(config);
group.bench_function("Ring", |b| {
b.iter(|| {
let private_key = ring_benchmarks::private_key(config);
ring_benchmarks::agreement(private_key, &ring_peer_public_key);
});
});
});
}
}

fn test_agreement(c: &mut Criterion) {
Expand Down
27 changes: 16 additions & 11 deletions benches/digest_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ macro_rules! benchmark_digest {
};
}

benchmark_digest!(ring);
benchmark_digest!(aws_lc_rust);
#[cfg(feature = "ring-benchmarks")]
benchmark_digest!(ring);

fn bench_sha1(c: &mut Criterion) {
let config = DigestConfig::new(DigestAlgorithm::SHA1);
Expand Down Expand Up @@ -110,12 +111,14 @@ fn bench_digest_one_shot(c: &mut Criterion, config: &DigestConfig) {
aws_lc_rust_benchmarks::run_digest_one_shot(config, &chunk);
});
});

group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::run_digest_one_shot(config, &chunk);
#[cfg(feature = "ring-benchmarks")]
{
group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::run_digest_one_shot(config, &chunk);
});
});
});
}
}
}

Expand Down Expand Up @@ -144,12 +147,14 @@ fn bench_digest_incremental(c: &mut Criterion, config: &DigestConfig) {
aws_lc_rust_benchmarks::run_digest_incremental(config, &chunk);
});
});

group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::run_digest_incremental(config, &chunk);
#[cfg(feature = "ring-benchmarks")]
{
group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::run_digest_incremental(config, &chunk);
});
});
});
}
}
}

Expand Down
43 changes: 21 additions & 22 deletions benches/ecdsa_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ macro_rules! benchmark_ecdsa {

use $pkg::{rand, signature};

/*
#[allow(unused_imports, unused_variables, dead_code)]
mod ring_benchmarks {
use ring::{error, rand, signature};
*/

use crate::{EcdsaConfig, EcdsaCurve, EcdsaDigest, EcdsaFormat};
use signature::{EcdsaKeyPair, EcdsaSigningAlgorithm, VerificationAlgorithm, EcdsaVerificationAlgorithm};

Expand Down Expand Up @@ -199,11 +193,12 @@ mod ring_benchmarks {
};
}

#[cfg(feature = "ring-sig-verify")]
benchmark_ecdsa!(ring);
#[cfg(feature = "ring-sig-verify")]
benchmark_ecdsa!(aws_lc_rust);

#[cfg(all(feature = "ring-sig-verify", feature = "ring-benchmarks"))]
benchmark_ecdsa!(ring);

#[cfg(feature = "ring-sig-verify")]
fn test_ecdsa_sign(c: &mut Criterion, config: &EcdsaConfig) {
let bench_group_name = format!(
Expand All @@ -223,15 +218,17 @@ fn test_ecdsa_sign(c: &mut Criterion, config: &EcdsaConfig) {
aws_lc_rust_benchmarks::sign(&aws_key_pair, &aws_rng, &config.msg);
});
});
#[cfg(feature = "ring-benchmarks")]
{
let ring_rng = ring_benchmarks::get_rng();
let ring_key_pair = ring_benchmarks::create_key_pair(config);

let ring_rng = ring_benchmarks::get_rng();
let ring_key_pair = ring_benchmarks::create_key_pair(config);

group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::sign(&ring_key_pair, &ring_rng, &config.msg);
group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::sign(&ring_key_pair, &ring_rng, &config.msg);
});
});
});
}
}

#[cfg(feature = "ring-sig-verify")]
Expand All @@ -256,15 +253,17 @@ fn test_ecdsa_verify(c: &mut Criterion, config: &EcdsaConfig) {
aws_lc_rust_benchmarks::verify(aws_verification_alg, pub_key, &config.msg, sig);
});
});
#[cfg(feature = "ring-benchmarks")]
{
let ring_verification_alg =
ring_benchmarks::verification(config.curve, config.digest, config.format);

let ring_verification_alg =
ring_benchmarks::verification(config.curve, config.digest, config.format);

group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::verify(ring_verification_alg, pub_key, &config.msg, sig);
group.bench_function("Ring", |b| {
b.iter(|| {
ring_benchmarks::verify(ring_verification_alg, pub_key, &config.msg, sig);
});
});
});
}
}
#[cfg(feature = "ring-sig-verify")]
fn test_ecdsa(c: &mut Criterion) {
Expand Down
Loading

0 comments on commit 2ca01e5

Please sign in to comment.