What changed, and why it matters
This commit is a routine refactoring that moves hash benchmarking code from inside the main source files into a separate benchmark suite using the Criterion library. It does not change how the hashing functions work, what data they process, or how they are exposed to users. There is no security fix or vulnerability here.
No security action needed. This is a benign build/test infrastructure change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes the nightly-only test crate benchmark modules guarded by #[cfg(bench)] from hashes/src/*.rs and adds equivalent Criterion-based benchmarks under benches/hashes/. It also updates benches/Cargo.toml to depend on bitcoin_hashes and registers the new benchmark targets, and removes the cfg(bench) check from hashes/Cargo.toml lints. No cryptographic logic, public APIs, or runtime behavior is modified.
Changed components
benches/Cargo.tomlbenches/hashes/*.rshashes/Cargo.tomlhashes/src/cmp.rshashes/src/hash160/mod.rshashes/src/hmac/mod.rshashes/src/lib.rshashes/src/ripemd160/mod.rshashes/src/sha1/mod.rshashes/src/sha256/mod.rshashes/src/sha256d/mod.rshashes/src/sha384/mod.rshashes/src/sha3_256/mod.rshashes/src/sha512/mod.rshashes/src/sha512_256/mod.rshashes/src/siphash24/mod.rsInspect captured patch +386 / −324
diff --git a/benches/Cargo.toml b/benches/Cargo.toml
index f3c609a4..955587e2 100644
--- a/benches/Cargo.toml
+++ b/benches/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
bitcoin = { path = "../bitcoin", default-features = false, features = ["std"] }
+bitcoin_hashes = { path = "../hashes" }
criterion = "0.7"
hex_lit = "0.1.1"
@@ -24,3 +25,58 @@ harness = false
name = "witness"
path = "bitcoin/witness.rs"
harness = false
+
+[[bench]]
+name = "cmp"
+path = "hashes/cmp.rs"
+harness = false
+
+[[bench]]
+name = "hash160"
+path = "hashes/hash160.rs"
+harness = false
+
+[[bench]]
+name = "hmac"
+path = "hashes/hmac.rs"
+harness = false
+
+[[bench]]
+name = "ripemd160"
+path = "hashes/ripemd160.rs"
+harness = false
+
+[[bench]]
+name = "sha1"
+path = "hashes/sha1.rs"
+harness = false
+
+[[bench]]
+name = "sha3_256"
+path = "hashes/sha3_256.rs"
+harness = false
+
+[[bench]]
+name = "sha256"
+path = "hashes/sha256.rs"
+harness = false
+
+[[bench]]
+name = "sha384"
+path = "hashes/sha384.rs"
+harness = false
+
+[[bench]]
+name = "sha512_256"
+path = "hashes/sha512_256.rs"
+harness = false
+
+[[bench]]
+name = "sha512"
+path = "hashes/sha512.rs"
+harness = false
+
+[[bench]]
+name = "siphash24"
+path = "hashes/siphash24.rs"
+harness = false
diff --git a/benches/hashes/cmp.rs b/benches/hashes/cmp.rs
new file mode 100644
index 00000000..13695c32
--- /dev/null
+++ b/benches/hashes/cmp.rs
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha256, sha512};
+use bitcoin_hashes::cmp::fixed_time_eq;
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
+
+fn bench_cmp(c: &mut Criterion) {
+ let mut g = c.benchmark_group("cmp");
+
+ // 32-byte comparisons
+ let a32 = sha256::Hash::hash(&[0; 1]);
+ let b32eq = sha256::Hash::hash(&[0; 1]);
+ let b32ne = sha256::Hash::hash(&[1; 1]);
+
+ g.bench_function(BenchmarkId::new("ct_eq", 32), |b| {
+ b.iter(|| fixed_time_eq(black_box(a32.as_byte_array()), black_box(b32eq.as_byte_array())));
+ });
+ g.bench_function(BenchmarkId::new("slice_eq", 32), |b| {
+ b.iter(|| black_box(a32.as_byte_array() == b32eq.as_byte_array()));
+ });
+ g.bench_function(BenchmarkId::new("ct_ne", 32), |b| {
+ b.iter(|| fixed_time_eq(black_box(a32.as_byte_array()), black_box(b32ne.as_byte_array())));
+ });
+ g.bench_function(BenchmarkId::new("slice_ne", 32), |b| {
+ b.iter(|| black_box(a32.as_byte_array() == b32ne.as_byte_array()));
+ });
+
+ // 64-byte comparisons
+ let a64 = sha512::Hash::hash(&[0; 1]);
+ let b64eq = sha512::Hash::hash(&[0; 1]);
+ let b64ne = sha512::Hash::hash(&[1; 1]);
+
+ g.bench_function(BenchmarkId::new("ct_eq", 64), |b| {
+ b.iter(|| fixed_time_eq(black_box(a64.as_byte_array()), black_box(b64eq.as_byte_array())));
+ });
+ g.bench_function(BenchmarkId::new("slice_eq", 64), |b| {
+ b.iter(|| black_box(a64.as_byte_array() == b64eq.as_byte_array()));
+ });
+ g.bench_function(BenchmarkId::new("ct_ne", 64), |b| {
+ b.iter(|| fixed_time_eq(black_box(a64.as_byte_array()), black_box(b64ne.as_byte_array())));
+ });
+ g.bench_function(BenchmarkId::new("slice_ne", 64), |b| {
+ b.iter(|| black_box(a64.as_byte_array() == b64ne.as_byte_array()));
+ });
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_cmp);
+criterion_main!(benches);
diff --git a/benches/hashes/hash160.rs b/benches/hashes/hash160.rs
new file mode 100644
index 00000000..452fd454
--- /dev/null
+++ b/benches/hashes/hash160.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{hash160, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_hash160(c: &mut Criterion) {
+ let mut g = c.benchmark_group("hash160");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = hash160::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_hash160);
+criterion_main!(benches);
diff --git a/benches/hashes/hmac.rs b/benches/hashes/hmac.rs
new file mode 100644
index 00000000..adc90e51
--- /dev/null
+++ b/benches/hashes/hmac.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha256, HashEngine as _, HmacEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_hmac(c: &mut Criterion) {
+ let mut g = c.benchmark_group("hmac_sha256");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = HmacEngine::<sha256::HashEngine>::new(&[]);
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_hmac);
+criterion_main!(benches);
diff --git a/benches/hashes/ripemd160.rs b/benches/hashes/ripemd160.rs
new file mode 100644
index 00000000..b786e77a
--- /dev/null
+++ b/benches/hashes/ripemd160.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{ripemd160, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_ripemd160(c: &mut Criterion) {
+ let mut g = c.benchmark_group("ripemd160");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = ripemd160::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_ripemd160);
+criterion_main!(benches);
diff --git a/benches/hashes/sha1.rs b/benches/hashes/sha1.rs
new file mode 100644
index 00000000..a63773f5
--- /dev/null
+++ b/benches/hashes/sha1.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha1, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_sha1(c: &mut Criterion) {
+ let mut g = c.benchmark_group("sha1");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = sha1::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_sha1);
+criterion_main!(benches);
diff --git a/benches/hashes/sha256.rs b/benches/hashes/sha256.rs
new file mode 100644
index 00000000..a8f2d104
--- /dev/null
+++ b/benches/hashes/sha256.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha256, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_sha256(c: &mut Criterion) {
+ let mut g = c.benchmark_group("sha256");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = sha256::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_sha256);
+criterion_main!(benches);
diff --git a/benches/hashes/sha384.rs b/benches/hashes/sha384.rs
new file mode 100644
index 00000000..77004ccf
--- /dev/null
+++ b/benches/hashes/sha384.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha384, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_sha384(c: &mut Criterion) {
+ let mut g = c.benchmark_group("sha384");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = sha384::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_sha384);
+criterion_main!(benches);
diff --git a/benches/hashes/sha3_256.rs b/benches/hashes/sha3_256.rs
new file mode 100644
index 00000000..2d4e1087
--- /dev/null
+++ b/benches/hashes/sha3_256.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha3_256, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_sha3_256(c: &mut Criterion) {
+ let mut g = c.benchmark_group("sha3_256");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = sha3_256::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_sha3_256);
+criterion_main!(benches);
diff --git a/benches/hashes/sha512.rs b/benches/hashes/sha512.rs
new file mode 100644
index 00000000..c72d9e61
--- /dev/null
+++ b/benches/hashes/sha512.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha512, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_sha512(c: &mut Criterion) {
+ let mut g = c.benchmark_group("sha512");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = sha512::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_sha512);
+criterion_main!(benches);
diff --git a/benches/hashes/sha512_256.rs b/benches/hashes/sha512_256.rs
new file mode 100644
index 00000000..c4cc075d
--- /dev/null
+++ b/benches/hashes/sha512_256.rs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{sha512_256, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_sha512_256(c: &mut Criterion) {
+ let mut g = c.benchmark_group("sha512_256");
+
+ for &size in &[10usize, 1024, 65536] {
+ let mut engine = sha512_256::Hash::engine();
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_sha512_256);
+criterion_main!(benches);
diff --git a/benches/hashes/siphash24.rs b/benches/hashes/siphash24.rs
new file mode 100644
index 00000000..f25d6d66
--- /dev/null
+++ b/benches/hashes/siphash24.rs
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: CC0-1.0
+
+use std::hint::black_box;
+
+use bitcoin_hashes::{siphash24, HashEngine};
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
+
+fn bench_siphash24(c: &mut Criterion) {
+ let mut g = c.benchmark_group("siphash24");
+
+ for &size in &[1024usize, 65536] {
+ let mut engine = siphash24::HashEngine::with_keys(0, 0);
+ let bytes = vec![1u8; size];
+ g.throughput(Throughput::Bytes(size as u64));
+ g.bench_function(BenchmarkId::new("engine_input", size), |b| {
+ b.iter(|| {
+ engine.input(black_box(&bytes));
+ });
+ });
+ }
+
+ // Hash-with-keys and to_u64 variants
+ let k0 = 0x_07_06_05_04_03_02_01_00;
+ let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08;
+ let bytes = vec![1u8; 1024];
+ g.throughput(Throughput::Bytes(bytes.len() as u64));
+ g.bench_function("hash_with_keys/1k", |b| {
+ b.iter(|| {
+ let _ = siphash24::Hash::hash_with_keys(k0, k1, black_box(&bytes));
+ });
+ });
+ g.bench_function("hash_to_u64_with_keys/1k", |b| {
+ b.iter(|| {
+ let _ = siphash24::Hash::hash_to_u64_with_keys(k0, k1, black_box(&bytes));
+ });
+ });
+
+ g.finish();
+}
+
+criterion_group!(benches, bench_siphash24);
+criterion_main!(benches);
diff --git a/hashes/Cargo.toml b/hashes/Cargo.toml
index 8e6c6e36..35f55df1 100644
--- a/hashes/Cargo.toml
+++ b/hashes/Cargo.toml
@@ -35,4 +35,4 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[lints.rust]
-unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(hashes_fuzz)', 'cfg(rust_v_1_64)' ] }
+unexpected_cfgs = { level = "deny", check-cfg = ['cfg(hashes_fuzz)', 'cfg(rust_v_1_64)' ] }
diff --git a/hashes/src/cmp.rs b/hashes/src/cmp.rs
index 2f971d39..3eeded7a 100644
--- a/hashes/src/cmp.rs
+++ b/hashes/src/cmp.rs
@@ -102,68 +102,3 @@ mod tests {
assert!(!fixed_time_eq(&[0b00000000, 0b00000000], &[0b00000001, 0b00000001]));
}
}
-
-#[cfg(bench)]
-#[cfg(feature = "hex")]
-mod benches {
- use test::Bencher;
-
- use crate::cmp::fixed_time_eq;
- use crate::{sha256, sha512, Hash};
-
- #[bench]
- fn bench_32b_constant_time_cmp_ne(bh: &mut Bencher) {
- let hash_a = sha256::Hash::hash(&[0; 1]);
- let hash_b = sha256::Hash::hash(&[1; 1]);
- bh.iter(|| fixed_time_eq(hash_a.as_byte_array(), hash_b.as_byte_array()))
- }
-
- #[bench]
- fn bench_32b_slice_cmp_ne(bh: &mut Bencher) {
- let hash_a = sha256::Hash::hash(&[0; 1]);
- let hash_b = sha256::Hash::hash(&[1; 1]);
- bh.iter(|| hash_a.as_byte_array() == hash_b.as_byte_array())
- }
-
- #[bench]
- fn bench_32b_constant_time_cmp_eq(bh: &mut Bencher) {
- let hash_a = sha256::Hash::hash(&[0; 1]);
- let hash_b = sha256::Hash::hash(&[0; 1]);
- bh.iter(|| fixed_time_eq(hash_a.as_byte_array(), hash_b.as_byte_array()))
- }
-
- #[bench]
- fn bench_32b_slice_cmp_eq(bh: &mut Bencher) {
- let hash_a = sha256::Hash::hash(&[0; 1]);
- let hash_b = sha256::Hash::hash(&[0; 1]);
- bh.iter(|| hash_a.as_byte_array() == hash_b.as_byte_array())
- }
-
- #[bench]
- fn bench_64b_constant_time_cmp_ne(bh: &mut Bencher) {
- let hash_a = sha512::Hash::hash(&[0; 1]);
- let hash_b = sha512::Hash::hash(&[1; 1]);
- bh.iter(|| fixed_time_eq(hash_a.as_byte_array(), hash_b.as_byte_array()))
- }
-
- #[bench]
- fn bench_64b_slice_cmp_ne(bh: &mut Bencher) {
- let hash_a = sha512::Hash::hash(&[0; 1]);
- let hash_b = sha512::Hash::hash(&[1; 1]);
- bh.iter(|| hash_a.as_byte_array() == hash_b.as_byte_array())
- }
-
- #[bench]
- fn bench_64b_constant_time_cmp_eq(bh: &mut Bencher) {
- let hash_a = sha512::Hash::hash(&[0; 1]);
- let hash_b = sha512::Hash::hash(&[0; 1]);
- bh.iter(|| fixed_time_eq(hash_a.as_byte_array(), hash_b.as_byte_array()))
- }
-
- #[bench]
- fn bench_64b_slice_cmp_eq(bh: &mut Bencher) {
- let hash_a = sha512::Hash::hash(&[0; 1]);
- let hash_b = sha512::Hash::hash(&[0; 1]);
- bh.iter(|| hash_a.as_byte_array() == hash_b.as_byte_array())
- }
-}
diff --git a/hashes/src/hash160/mod.rs b/hashes/src/hash160/mod.rs
index fbb11e1d..21440c30 100644
--- a/hashes/src/hash160/mod.rs
+++ b/hashes/src/hash160/mod.rs
@@ -130,40 +130,3 @@ mod tests {
assert_tokens(&hash.readable(), &[Token::Str("132072df690933835eb8b6ad0b77e7b6f14acad7")]);
}
}
-
-#[cfg(bench)]
-mod benches {
- use test::Bencher;
-
- use crate::{hash160, Hash as _, HashEngine};
-
- #[bench]
- pub fn hash160_10(bh: &mut Bencher) {
- let mut engine = hash160::Hash::engine();
- let bytes = [1u8; 10];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn hash160_1k(bh: &mut Bencher) {
- let mut engine = hash160::Hash::engine();
- let bytes = [1u8; 1024];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn hash160_64k(bh: &mut Bencher) {
- let mut engine = hash160::Hash::engine();
- let bytes = [1u8; 65536];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-}
diff --git a/hashes/src/hmac/mod.rs b/hashes/src/hmac/mod.rs
index 8651aa4d..1acaee30 100644
--- a/hashes/src/hmac/mod.rs
+++ b/hashes/src/hmac/mod.rs
@@ -311,40 +311,3 @@ mod tests {
);
}
}
-
-#[cfg(bench)]
-mod benches {
- use test::Bencher;
-
- use crate::{sha256, HashEngine as _, HmacEngine};
-
- #[bench]
- pub fn hmac_sha256_10(bh: &mut Bencher) {
- let mut engine = HmacEngine::<sha256::HashEngine>::new(&[]);
- let bytes = [1u8; 10];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn hmac_sha256_1k(bh: &mut Bencher) {
- let mut engine = HmacEngine::<sha256::HashEngine>::new(&[]);
- let bytes = [1u8; 1024];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn hmac_sha256_64k(bh: &mut Bencher) {
- let mut engine = HmacEngine::<sha256::HashEngine>::new(&[]);
- let bytes = [1u8; 65536];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-}
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index bcd32f52..167dc71c 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -53,7 +53,6 @@
#![no_std]
// Experimental features we need.
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
-#![cfg_attr(bench, feature(test))]
// Coding conventions.
#![warn(missing_docs)]
#![warn(deprecated_in_future)]
@@ -62,7 +61,6 @@
#![warn(clippy::return_self_not_must_use)]
// Instead of littering the codebase for non-fuzzing and bench code just globally allow.
#![cfg_attr(hashes_fuzz, allow(dead_code, unused_imports))]
-#![cfg_attr(bench, allow(dead_code, unused_imports))]
// Exclude lints we don't think are valuable.
#![allow(clippy::needless_question_mark)] // https://github.com/rust-bitcoin/rust-bitcoin/pull/2134
#![allow(clippy::manual_range_contains)] // More readable than clippy's format.
@@ -82,8 +80,6 @@ pub extern crate serde;
#[cfg(all(test, feature = "serde"))]
extern crate serde_test;
-#[cfg(bench)]
-extern crate test;
/// Re-export the `hex-conservative` crate.
#[cfg(feature = "hex")]
diff --git a/hashes/src/ripemd160/mod.rs b/hashes/src/ripemd160/mod.rs
index 26178387..de98690c 100644
--- a/hashes/src/ripemd160/mod.rs
+++ b/hashes/src/ripemd160/mod.rs
@@ -3,12 +3,7 @@
//! RIPEMD160 implementation.
use internals::slice::SliceExt;
-
-#[cfg(bench)]
-mod benches;
mod crypto;
-#[cfg(bench)]
-mod tests;
use core::cmp;
diff --git a/hashes/src/sha1/mod.rs b/hashes/src/sha1/mod.rs
index ca5e92ac..1451f0c3 100644
--- a/hashes/src/sha1/mod.rs
+++ b/hashes/src/sha1/mod.rs
@@ -3,12 +3,7 @@
//! SHA1 implementation.
use internals::slice::SliceExt;
-
-#[cfg(bench)]
-mod benches;
mod crypto;
-#[cfg(bench)]
-mod tests;
use core::cmp;
diff --git a/hashes/src/sha256/mod.rs b/hashes/src/sha256/mod.rs
index bc3068aa..5234dcba 100644
--- a/hashes/src/sha256/mod.rs
+++ b/hashes/src/sha256/mod.rs
@@ -2,11 +2,7 @@
//! SHA256 implementation.
-#[cfg(bench)]
-mod benches;
mod crypto;
-#[cfg(bench)]
-mod tests;
use core::{cmp, convert, fmt};
diff --git a/hashes/src/sha256d/mod.rs b/hashes/src/sha256d/mod.rs
index add1935e..0e158351 100644
--- a/hashes/src/sha256d/mod.rs
+++ b/hashes/src/sha256d/mod.rs
@@ -137,40 +137,3 @@ mod tests {
);
}
}
-
-#[cfg(bench)]
-mod benches {
- use test::Bencher;
-
- use crate::{sha256d, Hash, HashEngine};
-
- #[bench]
- pub fn sha256d_10(bh: &mut Bencher) {
- let mut engine = sha256d::Hash::engine();
- let bytes = [1u8; 10];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn sha256d_1k(bh: &mut Bencher) {
- let mut engine = sha256d::Hash::engine();
- let bytes = [1u8; 1024];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn sha256d_64k(bh: &mut Bencher) {
- let mut engine = sha256d::Hash::engine();
- let bytes = [1u8; 65536];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-}
diff --git a/hashes/src/sha384/mod.rs b/hashes/src/sha384/mod.rs
index 06d55e62..f1a53ff4 100644
--- a/hashes/src/sha384/mod.rs
+++ b/hashes/src/sha384/mod.rs
@@ -142,40 +142,3 @@ mod tests {
}
}
}
-
-#[cfg(bench)]
-mod benches {
- use test::Bencher;
-
- use crate::{sha384, Hash, HashEngine};
-
- #[bench]
- pub fn sha384_10(bh: &mut Bencher) {
- let mut engine = sha384::Hash::engine();
- let bytes = [1u8; 10];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn sha384_1k(bh: &mut Bencher) {
- let mut engine = sha384::Hash::engine();
- let bytes = [1u8; 1024];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn sha384_64k(bh: &mut Bencher) {
- let mut engine = sha384::Hash::engine();
- let bytes = [1u8; 65536];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-}
diff --git a/hashes/src/sha3_256/mod.rs b/hashes/src/sha3_256/mod.rs
index 85091dd6..9838da1f 100644
--- a/hashes/src/sha3_256/mod.rs
+++ b/hashes/src/sha3_256/mod.rs
@@ -17,8 +17,7 @@
//
// To read this file, follow the example code: https://keccak.team/keccak_specs_summary.html
// For a detailed specification: https://keccak.team/files/Keccak-reference-3.0.pdf
-#[cfg(bench)]
-mod benches;
+
use core::fmt;
crate::internal_macros::general_hash_type! {
diff --git a/hashes/src/sha512/mod.rs b/hashes/src/sha512/mod.rs
index 0f73f328..a2f72130 100644
--- a/hashes/src/sha512/mod.rs
+++ b/hashes/src/sha512/mod.rs
@@ -4,11 +4,7 @@
use internals::slice::SliceExt;
-#[cfg(bench)]
-mod benches;
mod crypto;
-#[cfg(bench)]
-mod tests;
use core::cmp;
diff --git a/hashes/src/sha512_256/mod.rs b/hashes/src/sha512_256/mod.rs
index 291eac9f..c2b64f60 100644
--- a/hashes/src/sha512_256/mod.rs
+++ b/hashes/src/sha512_256/mod.rs
@@ -142,40 +142,3 @@ mod tests {
}
}
}
-
-#[cfg(bench)]
-mod benches {
- use test::Bencher;
-
- use crate::{sha512_256, Hash, HashEngine};
-
- #[bench]
- pub fn sha512_256_10(bh: &mut Bencher) {
- let mut engine = sha512_256::Hash::engine();
- let bytes = [1u8; 10];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn sha512_256_1k(bh: &mut Bencher) {
- let mut engine = sha512_256::Hash::engine();
- let bytes = [1u8; 1024];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn sha512_256_64k(bh: &mut Bencher) {
- let mut engine = sha512_256::Hash::engine();
- let bytes = [1u8; 65536];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-}
diff --git a/hashes/src/siphash24/mod.rs b/hashes/src/siphash24/mod.rs
index 316cdc6c..9dced9d2 100644
--- a/hashes/src/siphash24/mod.rs
+++ b/hashes/src/siphash24/mod.rs
@@ -329,52 +329,3 @@ mod tests {
}
}
}
-
-#[cfg(bench)]
-mod benches {
- use test::Bencher;
-
- use crate::{siphash24, Hash, HashEngine};
-
- #[bench]
- pub fn siphash24_1ki(bh: &mut Bencher) {
- let mut engine = siphash24::HashEngine::with_keys(0, 0);
- let bytes = [1u8; 1024];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn siphash24_64ki(bh: &mut Bencher) {
- let mut engine = siphash24::HashEngine::with_keys(0, 0);
- let bytes = [1u8; 65536];
- bh.iter(|| {
- engine.input(&bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn siphash24_1ki_hash(bh: &mut Bencher) {
- let k0 = 0x_07_06_05_04_03_02_01_00;
- let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08;
- let bytes = [1u8; 1024];
- bh.iter(|| {
- let _ = siphash24::Hash::hash_with_keys(k0, k1, &bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-
- #[bench]
- pub fn siphash24_1ki_hash_u64(bh: &mut Bencher) {
- let k0 = 0x_07_06_05_04_03_02_01_00;
- let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08;
- let bytes = [1u8; 1024];
- bh.iter(|| {
- let _ = siphash24::Hash::hash_to_u64_with_keys(k0, k1, &bytes);
- });
- bh.bytes = bytes.len() as u64;
- }
-}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.