Skip to content

Commit f36b5bc

Browse files
committed
Merge petertodd#246: Check that secrets are exactly 32 bytes
1c36e75 Check that secrets are exactly 32 bytes (Bob McElrath) Pull request description: Fixes petertodd#239. I agree with @dgpv, any padding should be performed by the user and we shouldn't be doing any unexpected transformations on the user's secret key material. So we just raise an exception if anything other than exactly 32 bytes are passed. Top commit has no ACKs. Tree-SHA512: 9daf6e662ae4218b22c4a11a487d1be959d688abe593326e9c0eccfb6346bffa8fb08c1e4111fd95dc30b1a5123c751f629f83075096e4b0eef9a54e1cce23c5
2 parents 7924f4d + 1c36e75 commit f36b5bc

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

bitcoin/core/key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def __del__(self):
257257
self.k = None
258258

259259
def set_secretbytes(self, secret):
260+
if(len(secret) != 32):
261+
raise ValueError("Secret bytes must be exactly 32 bytes")
260262
priv_key = _ssl.BN_bin2bn(secret, 32, None)
261263
group = _ssl.EC_KEY_get0_group(self.k)
262264
pub_key = _ssl.EC_POINT_new(group)

0 commit comments

Comments
 (0)