@@ -75,7 +75,7 @@ int wally_sha256(const unsigned char *bytes, size_t bytes_len,
7575 struct sha256 sha ;
7676 bool aligned = alignment_ok (bytes_out , sizeof (sha .u .u32 ));
7777
78- if (!bytes || !bytes_out || len != SHA256_LEN )
78+ if (( !bytes && bytes_len != 0 ) || !bytes_out || len != SHA256_LEN )
7979 return WALLY_EINVAL ;
8080
8181 sha256 (aligned ? (struct sha256 * )bytes_out : & sha , bytes , bytes_len );
@@ -102,7 +102,7 @@ int wally_sha256_midstate(const unsigned char *bytes, size_t bytes_len,
102102 struct sha256_ctx ctx ;
103103 bool aligned = alignment_ok (bytes_out , sizeof (sha .u .u32 ));
104104
105- if (!bytes || !bytes_out || len != SHA256_LEN )
105+ if (( !bytes && bytes_len != 0 ) || !bytes_out || len != SHA256_LEN )
106106 return WALLY_EINVAL ;
107107
108108 sha256_init (& ctx );
@@ -123,7 +123,7 @@ int wally_sha256d(const unsigned char *bytes, size_t bytes_len,
123123 struct sha256 sha_1 , sha_2 ;
124124 bool aligned = alignment_ok (bytes_out , sizeof (sha_1 .u .u32 ));
125125
126- if (!bytes || !bytes_out || len != SHA256_LEN )
126+ if (( !bytes && bytes_len != 0 ) || !bytes_out || len != SHA256_LEN )
127127 return WALLY_EINVAL ;
128128
129129 sha256 (& sha_1 , bytes , bytes_len );
@@ -142,7 +142,7 @@ int wally_sha512(const unsigned char *bytes, size_t bytes_len,
142142 struct sha512 sha ;
143143 bool aligned = alignment_ok (bytes_out , sizeof (sha .u .u64 ));
144144
145- if (!bytes || !bytes_out || len != SHA512_LEN )
145+ if (( !bytes && bytes_len != 0 ) || !bytes_out || len != SHA512_LEN )
146146 return WALLY_EINVAL ;
147147
148148 sha512 (aligned ? (struct sha512 * )bytes_out : & sha , bytes , bytes_len );
@@ -160,7 +160,7 @@ int wally_hash160(const unsigned char *bytes, size_t bytes_len,
160160 struct ripemd160 ripemd ;
161161 bool aligned = alignment_ok (bytes_out , sizeof (ripemd .u .u32 ));
162162
163- if (!bytes || !bytes_out || len != HASH160_LEN )
163+ if (( !bytes && bytes_len != 0 ) || !bytes_out || len != HASH160_LEN )
164164 return WALLY_EINVAL ;
165165
166166 BUILD_ASSERT (sizeof (ripemd ) == HASH160_LEN );
0 commit comments