From c31b6e741422e856803b4eeae1b4ed4bda71c3ed Mon Sep 17 00:00:00 2001 From: Mark B Lundeberg <36528214+markblundeberg@users.noreply.github.com> Date: Sun, 3 Feb 2019 12:59:20 -0800 Subject: [PATCH] misc fixes key.py * EC_POINT_mul hears you the first time, don't need to call twice. * EC_KEY_set_private_key makes a copy of the key; without freeing it we have a memory leak. * BN_bin2bn happy to take None as arg and do allocation. --- bitcoin/core/key.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bitcoin/core/key.py b/bitcoin/core/key.py index 4fce32c2..9341d7f6 100644 --- a/bitcoin/core/key.py +++ b/bitcoin/core/key.py @@ -211,16 +211,16 @@ def __del__(self): self.k = None def set_secretbytes(self, secret): - priv_key = _ssl.BN_bin2bn(secret, 32, _ssl.BN_new()) + priv_key = _ssl.BN_bin2bn(secret, 32, None) group = _ssl.EC_KEY_get0_group(self.k) pub_key = _ssl.EC_POINT_new(group) ctx = _ssl.BN_CTX_new() if not _ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx): raise ValueError("Could not derive public key from the supplied secret.") - _ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx) _ssl.EC_KEY_set_private_key(self.k, priv_key) _ssl.EC_KEY_set_public_key(self.k, pub_key) _ssl.EC_POINT_free(pub_key) + _ssl.BN_free(priv_key) _ssl.BN_CTX_free(ctx) return self.k