What changed, and why it matters
This commit only adds performance benchmark tests for the SHA3-256 hashing code. It does not change any actual hashing logic, fix a bug, or alter security behavior. The commit message speculates that the existing implementation may perform poorly on small inputs, but this is an observation, not a security disclosure or patch.
No security action required. Treat as a normal development/test addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a new benches.rs file under hashes/src/sha3_256/ containing three #[bench] functions that measure sha3_256::Hash::engine().input(...) throughput for 10-byte, 1 KiB, and 64 KiB inputs. The module file hashes/src/sha3_256/mod.rs is updated only to include mod benches under #[cfg(bench)]. No cryptographic code is modified.
Changed components
hashes/src/sha3_256/benches.rshashes/src/sha3_256/mod.rsInspect captured patch +35 / −0
diff --git a/hashes/src/sha3_256/benches.rs b/hashes/src/sha3_256/benches.rs
new file mode 100644
index 00000000..afefdcb7
--- /dev/null
+++ b/hashes/src/sha3_256/benches.rs
@@ -0,0 +1,33 @@
+use test::Bencher;
+
+use crate::{Hash, HashEngine};
+
+#[bench]
+pub fn sha3_256_10(bh: &mut Bencher) {
+ let mut engine = crate::sha3_256::Hash::engine();
+ let bytes = [1u8; 10];
+ bh.iter(|| {
+ engine.input(&bytes);
+ });
+ bh.bytes = bytes.len() as u64;
+}
+
+#[bench]
+pub fn sha3_256_1k(bh: &mut Bencher) {
+ let mut engine = crate::sha3_256::Hash::engine();
+ let bytes = [1u8; 1024];
+ bh.iter(|| {
+ engine.input(&bytes);
+ });
+ bh.bytes = bytes.len() as u64;
+}
+
+#[bench]
+pub fn sha3_256_64k(bh: &mut Bencher) {
+ let mut engine = crate::sha3_256::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 eccf027a..ee150beb 100644
--- a/hashes/src/sha3_256/mod.rs
+++ b/hashes/src/sha3_256/mod.rs
@@ -17,6 +17,8 @@
//
// 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! {
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.