hashes: use the optimized scalar in sha256d_64 fallback
What changed, and why it matters
This is a small performance improvement in the rust-bitcoin library's SHA256 double-hash code. It replaces a slower fallback code path with a faster, already-existing internal implementation when advanced CPU features are not available. There is no indication of a security bug or vulnerability.
No security action needed. Treat as a normal performance optimization. If reviewing, verify that software_sha256d_64 produces identical outputs to the previous sha256d::hash call for all inputs, which is expected since it is an existing internal implementation.
Security signals we found
No security-relevant signals present in the diff or commit message.
Change is a performance optimization using existing internal code.
No input validation, memory safety, or cryptographic correctness changes visible.
Evidence from the diff
The commit changes the fallback path in sha256d_64 (64-byte SHA-256d hashing) to use an optimized scalar implementation (software_sha256d_64) instead of calling the generic sha256d::hash function. The change is purely a performance optimization (~7% speedup claimed) in the non-accelerated fallback loop. No cryptographic constants, input validation, or output handling are modified.
Changed components
hashes/src/sha256/crypto/mod.rsSHA-256d 64-byte fallback hashing pathInspect captured patch +1 / −2
diff --git a/hashes/src/sha256/crypto/mod.rs b/hashes/src/sha256/crypto/mod.rs
index ba8be2e5..b213fd81 100644
--- a/hashes/src/sha256/crypto/mod.rs
+++ b/hashes/src/sha256/crypto/mod.rs
@@ -24,7 +24,6 @@ mod avx2;
use internals::slice::SliceExt;
use super::{HashEngine, Midstate, BLOCK_SIZE};
-use crate::sha256d;
#[cfg(feature = "cpufeatures")]
#[cfg(target_arch = "aarch64")]
@@ -475,7 +474,7 @@ impl HashEngine {
// fallback
while i < count {
- outputs[i] = sha256d::hash(&inputs[i]).to_byte_array();
+ Self::software_sha256d_64(&mut outputs[i], &inputs[i]);
i += 1;
}
}
Why this scored 20/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.