What changed, and why it matters
This commit only adds a new unit test. It checks that when a SHA-256 hashing engine is paused mid-way through data (at a non-block-aligned point), the error object contains enough information to build a second engine that finishes hashing and produces the same final result. There is no code fix, behavior change, or security patch here.
No security action needed. Treat as routine test coverage.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single test, midstate_error_resume_hashing, in hashes/src/sha256/tests.rs. It feeds 100 bytes to a SHA-256 engine, calls midstate(), expects an error because 100 is not a multiple of the 64-byte block size, extracts the 36 unprocessed trailing bytes and the intermediate state, creates a fresh HashEngine::from_midstate, feeds the remaining bytes, and asserts both engines yield the same final hash. No production code is modified.
Changed components
hashes/src/sha256/tests.rsInspect captured patch +13 / −0
diff --git a/hashes/src/sha256/tests.rs b/hashes/src/sha256/tests.rs
index b320969e..09db17df 100644
--- a/hashes/src/sha256/tests.rs
+++ b/hashes/src/sha256/tests.rs
@@ -218,6 +218,19 @@ fn sha256_serde() {
);
}
+#[test]
+fn midstate_error_resume_hashing() {
+ let mut engine1 = sha256::Hash::engine();
+ let data = [1; 100];
+ engine1.input(&data);
+ let err = engine1.midstate().expect_err("100 bytes not block-aligned");
+ assert_eq!(err.unprocessed_bytes().len(), 36);
+ // we can resume hashing from err data
+ let mut engine2 = sha256::HashEngine::from_midstate(*err.midstate());
+ engine2.input(err.unprocessed_bytes());
+ assert_eq!(sha256::Hash::from_engine(engine1), sha256::Hash::from_engine(engine2));
+}
+
#[cfg(target_arch = "wasm32")]
mod wasm_tests {
use super::*;
Why this scored 12/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.