@@ -45,7 +45,7 @@ impl Default for HashEngine {
4545impl EngineTrait for HashEngine {
4646 type MidState = Midstate ;
4747
48- #[ cfg( not( feature = "fuzztarget" ) ) ]
48+ #[ cfg( not( fuzzing ) ) ]
4949 fn midstate ( & self ) -> Midstate {
5050 let mut ret = [ 0 ; 32 ] ;
5151 for ( val, ret_bytes) in self . h . iter ( ) . zip ( ret. chunks_mut ( 4 ) ) {
@@ -54,7 +54,7 @@ impl EngineTrait for HashEngine {
5454 Midstate ( ret)
5555 }
5656
57- #[ cfg( feature = "fuzztarget" ) ]
57+ #[ cfg( fuzzing ) ]
5858 fn midstate ( & self ) -> Midstate {
5959 let mut ret = [ 0 ; 32 ] ;
6060 ret. copy_from_slice ( & self . buffer [ ..32 ] ) ;
@@ -93,7 +93,7 @@ impl HashTrait for Hash {
9393 type Engine = HashEngine ;
9494 type Inner = [ u8 ; 32 ] ;
9595
96- #[ cfg( not( feature = "fuzztarget" ) ) ]
96+ #[ cfg( not( fuzzing ) ) ]
9797 fn from_engine ( mut e : HashEngine ) -> Hash {
9898 // pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
9999 let data_len = e. length as u64 ;
@@ -113,9 +113,15 @@ impl HashTrait for Hash {
113113 Hash ( e. midstate ( ) . into_inner ( ) )
114114 }
115115
116- #[ cfg( feature = "fuzztarget" ) ]
116+ #[ 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