Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit c90d263

Browse files
committed
Never return a SHA256 hash of 0 in fuzzing mode
This prevents downstream software that wishes to use SHA256 output as private keys from needing to handle the 0-hash case explicitly.
1 parent d5c6d77 commit c90d263

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/sha256.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ impl HashTrait for Hash {
115115

116116
#[cfg(fuzzing)]
117117
fn from_engine(e: HashEngine) -> Hash {
118-
Hash(e.midstate().into_inner())
118+
let mut hash = e.midstate().into_inner();
119+
if hash == [0; 32] {
120+
// Assume sha256 is secure and never generate 0-hashes (which represent invalid
121+
// secp256k1 secret keys, causing downstream application breakage).
122+
hash[0] = 1;
123+
}
124+
Hash(hash)
119125
}
120126

121127
const LEN: usize = 32;

0 commit comments

Comments
 (0)