From ab75e426a707e9961d96293e5f4dcfe76eeee02c Mon Sep 17 00:00:00 2001 From: brxken128 <77554505+brxken128@users.noreply.github.com> Date: Tue, 24 Jan 2023 14:25:42 +0000 Subject: [PATCH] disable benchmarks as they need async support --- Cargo.lock | 159 +------------------- crates/crypto/Cargo.toml | 28 ++-- crates/crypto/benches/aes-256-gcm.rs | 111 +++++++------- crates/crypto/benches/argon2id.rs | 58 +++---- crates/crypto/benches/xchacha20-poly1305.rs | 104 ++++++------- 5 files changed, 157 insertions(+), 303 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af40c8c2f..fcc46428f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,12 +114,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "anyhow" version = "1.0.68" @@ -681,12 +675,6 @@ dependencies = [ "toml", ] -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.0.73" @@ -785,33 +773,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "ciborium" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" - -[[package]] -name = "ciborium-ll" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" -dependencies = [ - "ciborium-io", - "half 1.8.2", -] - [[package]] name = "cipher" version = "0.4.3" @@ -834,18 +795,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clap" -version = "3.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" -dependencies = [ - "bitflags", - "clap_lex 0.2.4", - "indexmap", - "textwrap", -] - [[package]] name = "clap" version = "4.0.32" @@ -854,7 +803,7 @@ checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ "bitflags", "clap_derive", - "clap_lex 0.3.0", + "clap_lex", "is-terminal", "once_cell", "strsim", @@ -874,15 +823,6 @@ dependencies = [ "syn", ] -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "clap_lex" version = "0.3.0" @@ -897,7 +837,7 @@ name = "cli" version = "0.1.0" dependencies = [ "anyhow", - "clap 4.0.32", + "clap", "hex", "indoc", "sd-crypto", @@ -1109,42 +1049,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "criterion" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" -dependencies = [ - "anes", - "atty", - "cast", - "ciborium", - "clap 3.2.23", - "criterion-plot", - "itertools", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - [[package]] name = "crossbeam-channel" version = "0.5.6" @@ -1655,7 +1559,7 @@ checksum = "8eb5f255b5980bb0c8cf676b675d1a99be40f316881444f44e0462eaf5df5ded" dependencies = [ "bit_field", "flume", - "half 2.1.0", + "half", "lebe", "miniz_oxide 0.6.2", "smallvec 1.10.0", @@ -2274,12 +2178,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" - [[package]] name = "half" version = "2.1.0" @@ -3768,12 +3666,6 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - [[package]] name = "opaque-debug" version = "0.3.0" @@ -4251,34 +4143,6 @@ dependencies = [ "xml-rs", ] -[[package]] -name = "plotters" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" - -[[package]] -name = "plotters-svg" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" -dependencies = [ - "plotters-backend", -] - [[package]] name = "png" version = "0.11.0" @@ -5521,7 +5385,6 @@ dependencies = [ "balloon-hash", "blake3", "chacha20poly1305", - "criterion", "dashmap", "hex", "rand 0.8.5", @@ -6683,12 +6546,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thin-slice" version = "0.1.1" @@ -6773,16 +6630,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "1.6.0" diff --git a/crates/crypto/Cargo.toml b/crates/crypto/Cargo.toml index 0456ff925..1fcc0c984 100644 --- a/crates/crypto/Cargo.toml +++ b/crates/crypto/Cargo.toml @@ -44,24 +44,24 @@ hex = "0.4.3" tokio = { version = "1.21.2", features = ["io-util", "rt-multi-thread"] } -[dev-dependencies] -criterion = "0.4.0" +# [dev-dependencies] +# criterion = "0.4.0" [features] rspc = ["dep:rspc", "dep:specta"] serde = ["dep:serde", "dep:serde_json", "dep:serde-big-array", "uuid/serde"] -[[bench]] -name = "aes-256-gcm" -path = "benches/aes-256-gcm.rs" -harness = false +# [[bench]] +# name = "aes-256-gcm" +# path = "benches/aes-256-gcm.rs" +# harness = false -[[bench]] -name = "xchacha20-poly1305" -path = "benches/xchacha20-poly1305.rs" -harness = false +# [[bench]] +# name = "xchacha20-poly1305" +# path = "benches/xchacha20-poly1305.rs" +# harness = false -[[bench]] -name = "argon2id" -path = "benches/argon2id.rs" -harness = false +# [[bench]] +# name = "argon2id" +# path = "benches/argon2id.rs" +# harness = false diff --git a/crates/crypto/benches/aes-256-gcm.rs b/crates/crypto/benches/aes-256-gcm.rs index de57033d7..a58cc790d 100644 --- a/crates/crypto/benches/aes-256-gcm.rs +++ b/crates/crypto/benches/aes-256-gcm.rs @@ -1,65 +1,72 @@ -use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; -use sd_crypto::{ - crypto::stream::{Algorithm, StreamDecryption, StreamEncryption}, - primitives::{generate_master_key, generate_nonce}, -}; +// use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; +// use sd_crypto::{ +// crypto::stream::{Algorithm, StreamDecryption, StreamEncryption}, +// primitives::{generate_master_key, generate_nonce}, +// }; -const ALGORITHM: Algorithm = Algorithm::Aes256Gcm; +// const ALGORITHM: Algorithm = Algorithm::Aes256Gcm; -const KB: usize = 1024; +// const KB: usize = 1024; -const SIZES: [usize; 8] = [ - KB * 16, - KB * 32, - KB * 64, - KB * 128, - KB * 512, - KB * 1024, - KB * 2048, - KB * 4096, -]; +// const SIZES: [usize; 8] = [ +// KB * 16, +// KB * 32, +// KB * 64, +// KB * 128, +// KB * 512, +// KB * 1024, +// KB * 2048, +// KB * 4096, +// ]; -fn bench(c: &mut Criterion) { - let mut group = c.benchmark_group("aes-256-gcm"); +// async fn bench(c: &mut Criterion) { +// let mut group = c.benchmark_group("aes-256-gcm"); - for size in SIZES { - let buf = vec![0u8; size]; +// for size in SIZES { +// let buf = vec![0u8; size]; - let key = generate_master_key(); - let nonce = generate_nonce(ALGORITHM); +// let key = generate_master_key(); +// let nonce = generate_nonce(ALGORITHM); - let encrypted_bytes = - StreamEncryption::encrypt_bytes(key.clone(), &nonce, ALGORITHM, &buf, &[]).unwrap(); // bytes to decrypt +// let encrypted_bytes = +// StreamEncryption::encrypt_bytes(key.clone(), &nonce, ALGORITHM, &buf, &[]) +// .await +// .unwrap(); // bytes to decrypt - group.throughput(criterion::Throughput::Bytes(size as u64)); +// group.throughput(criterion::Throughput::Bytes(size as u64)); - group.bench_function(BenchmarkId::new("encrypt", size), |b| { - b.iter_batched( - || key.clone(), - |key| StreamEncryption::encrypt_bytes(key, &nonce, ALGORITHM, &buf, &[]).unwrap(), - BatchSize::SmallInput, - ) - }); +// group.bench_function(BenchmarkId::new("encrypt", size), |b| { +// b.iter_batched( +// || key.clone(), +// |key| async { +// StreamEncryption::encrypt_bytes(key, &nonce, ALGORITHM, &buf, &[]) +// .await +// .unwrap() +// }, +// BatchSize::SmallInput, +// ) +// }); - group.bench_function(BenchmarkId::new("decrypt", size), |b| { - b.iter_batched( - || key.clone(), - |key| { - StreamDecryption::decrypt_bytes(key, &nonce, ALGORITHM, &encrypted_bytes, &[]) - .unwrap() - }, - BatchSize::SmallInput, - ) - }); - } +// group.bench_function(BenchmarkId::new("decrypt", size), |b| { +// b.iter_batched( +// || key.clone(), +// |key| async { +// StreamDecryption::decrypt_bytes(key, &nonce, ALGORITHM, &encrypted_bytes, &[]) +// .await +// .unwrap() +// }, +// BatchSize::SmallInput, +// ) +// }); +// } - group.finish(); -} +// group.finish(); +// } -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); +// criterion_group!( +// name = benches; +// config = Criterion::default(); +// targets = bench; +// ); -criterion_main!(benches); +// criterion_main!(benches); diff --git a/crates/crypto/benches/argon2id.rs b/crates/crypto/benches/argon2id.rs index 488bce1c1..88b2adc08 100644 --- a/crates/crypto/benches/argon2id.rs +++ b/crates/crypto/benches/argon2id.rs @@ -1,36 +1,36 @@ -use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; -use sd_crypto::{ - keys::hashing::{HashingAlgorithm, Params}, - primitives::{generate_master_key, generate_salt}, - Protected, -}; +// use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; +// use sd_crypto::{ +// keys::hashing::{HashingAlgorithm, Params}, +// primitives::{generate_master_key, generate_salt}, +// Protected, +// }; -const PARAMS: [Params; 3] = [Params::Standard, Params::Hardened, Params::Paranoid]; +// const PARAMS: [Params; 3] = [Params::Standard, Params::Hardened, Params::Paranoid]; -fn bench(c: &mut Criterion) { - let mut group = c.benchmark_group("argon2id"); +// fn bench(c: &mut Criterion) { +// let mut group = c.benchmark_group("argon2id"); - for param in PARAMS { - let key = Protected::new(generate_master_key().expose().to_vec()); - let salt = generate_salt(); - let hashing_algorithm = HashingAlgorithm::Argon2id(param); +// for param in PARAMS { +// let key = Protected::new(generate_master_key().expose().to_vec()); +// let salt = generate_salt(); +// let hashing_algorithm = HashingAlgorithm::Argon2id(param); - group.bench_function(BenchmarkId::new("hash", param.argon2id().m_cost()), |b| { - b.iter_batched( - || (key.clone(), salt), - |(key, salt)| hashing_algorithm.hash(key, salt, None), - BatchSize::SmallInput, - ) - }); - } +// group.bench_function(BenchmarkId::new("hash", param.argon2id().m_cost()), |b| { +// b.iter_batched( +// || (key.clone(), salt), +// |(key, salt)| hashing_algorithm.hash(key, salt, None), +// BatchSize::SmallInput, +// ) +// }); +// } - group.finish(); -} +// group.finish(); +// } -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); +// criterion_group!( +// name = benches; +// config = Criterion::default(); +// targets = bench +// ); -criterion_main!(benches); +// criterion_main!(benches); diff --git a/crates/crypto/benches/xchacha20-poly1305.rs b/crates/crypto/benches/xchacha20-poly1305.rs index 682395390..75fce0ea0 100644 --- a/crates/crypto/benches/xchacha20-poly1305.rs +++ b/crates/crypto/benches/xchacha20-poly1305.rs @@ -1,65 +1,65 @@ -use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; -use sd_crypto::{ - crypto::stream::{Algorithm, StreamDecryption, StreamEncryption}, - primitives::{generate_master_key, generate_nonce}, -}; +// use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; +// use sd_crypto::{ +// crypto::stream::{Algorithm, StreamDecryption, StreamEncryption}, +// primitives::{generate_master_key, generate_nonce}, +// }; -const ALGORITHM: Algorithm = Algorithm::XChaCha20Poly1305; +// const ALGORITHM: Algorithm = Algorithm::XChaCha20Poly1305; -const KB: usize = 1024; +// const KB: usize = 1024; -const SIZES: [usize; 8] = [ - KB * 16, - KB * 32, - KB * 64, - KB * 128, - KB * 512, - KB * 1024, - KB * 2048, - KB * 4096, -]; +// const SIZES: [usize; 8] = [ +// KB * 16, +// KB * 32, +// KB * 64, +// KB * 128, +// KB * 512, +// KB * 1024, +// KB * 2048, +// KB * 4096, +// ]; -fn bench(c: &mut Criterion) { - let mut group = c.benchmark_group("xchacha20-poly1305"); +// fn bench(c: &mut Criterion) { +// let mut group = c.benchmark_group("xchacha20-poly1305"); - for size in SIZES { - let buf = vec![0u8; size]; +// for size in SIZES { +// let buf = vec![0u8; size]; - let key = generate_master_key(); - let nonce = generate_nonce(ALGORITHM); +// let key = generate_master_key(); +// let nonce = generate_nonce(ALGORITHM); - let encrypted_bytes = - StreamEncryption::encrypt_bytes(key.clone(), &nonce, ALGORITHM, &buf, &[]).unwrap(); // bytes to decrypt +// let encrypted_bytes = +// StreamEncryption::encrypt_bytes(key.clone(), &nonce, ALGORITHM, &buf, &[]).unwrap(); // bytes to decrypt - group.throughput(criterion::Throughput::Bytes(size as u64)); +// group.throughput(criterion::Throughput::Bytes(size as u64)); - group.bench_function(BenchmarkId::new("encrypt", size), |b| { - b.iter_batched( - || key.clone(), - |key| StreamEncryption::encrypt_bytes(key, &nonce, ALGORITHM, &buf, &[]).unwrap(), - BatchSize::SmallInput, - ) - }); +// group.bench_function(BenchmarkId::new("encrypt", size), |b| { +// b.iter_batched( +// || key.clone(), +// |key| StreamEncryption::encrypt_bytes(key, &nonce, ALGORITHM, &buf, &[]).unwrap(), +// BatchSize::SmallInput, +// ) +// }); - group.bench_function(BenchmarkId::new("decrypt", size), |b| { - b.iter_batched( - || key.clone(), - |key| { - StreamDecryption::decrypt_bytes(key, &nonce, ALGORITHM, &encrypted_bytes, &[]) - .unwrap() - }, - BatchSize::SmallInput, - ) - }); - } +// group.bench_function(BenchmarkId::new("decrypt", size), |b| { +// b.iter_batched( +// || key.clone(), +// |key| { +// StreamDecryption::decrypt_bytes(key, &nonce, ALGORITHM, &encrypted_bytes, &[]) +// .unwrap() +// }, +// BatchSize::SmallInput, +// ) +// }); +// } - group.finish(); -} +// group.finish(); +// } -criterion_group!( - name = benches; - config = Criterion::default(); - targets = bench -); +// criterion_group!( +// name = benches; +// config = Criterion::default(); +// targets = bench +// ); -criterion_main!(benches); +// criterion_main!(benches);