Skip to content

Commit e646ae7

Browse files
committed
Fix CECKey.sign() handling of invalid hashes
1 parent 82962cc commit e646ae7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

bitcoin/core/key.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def get_ecdh_key(self, other_pubkey, kdf=lambda k: hashlib.sha256(k).digest()):
9494
return kdf(r)
9595

9696
def sign(self, hash):
97+
# FIXME: need unit tests for below cases
98+
if not isinstance(hash, bytes):
99+
raise TypeError('Hash must be bytes instance; got %r' % hash.__class__)
100+
if len(hash) != 32:
101+
raise ValueError('Hash must be exactly 32 bytes long')
102+
97103
sig_size0 = ctypes.c_uint32()
98104
sig_size0.value = ssl.ECDSA_size(self.k)
99105
mb_sig = ctypes.create_string_buffer(sig_size0.value)

0 commit comments

Comments
 (0)