electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 31ab5b2e0a911a014ea1398f6f73fa3f311e76ec
parent d4dcd551e41c885b8770d2bc7746511e53e35951
Author: ThomasV <thomasv@electrum.org>
Date:   Thu, 15 Jun 2017 10:03:18 +0200

pass hash to pubkey_from_signature

Diffstat:
Mlib/bitcoin.py | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/bitcoin.py b/lib/bitcoin.py @@ -486,14 +486,14 @@ def msg_magic(message): def verify_message(address, sig, message): try: - public_key, compressed = pubkey_from_signature(sig, message) + h = Hash(msg_magic(message)) + public_key, compressed = pubkey_from_signature(sig, h) # check public key using the address pubkey = point_to_ser(public_key.pubkey.point, compressed) addr = public_key_to_p2pkh(pubkey) if address != addr: raise Exception("Bad signature") # check message - h = Hash(msg_magic(message)) public_key.verify_digest(sig[1:], h, sigdecode = ecdsa.util.sigdecode_string) return True except Exception as e: @@ -575,7 +575,7 @@ class MyVerifyingKey(ecdsa.VerifyingKey): return klass.from_public_point( Q, curve ) -def pubkey_from_signature(sig, message): +def pubkey_from_signature(sig, h): if len(sig) != 65: raise Exception("Wrong encoding") nV = ord(sig[0]) @@ -587,7 +587,6 @@ def pubkey_from_signature(sig, message): else: compressed = False recid = nV - 27 - h = Hash(msg_magic(message)) return MyVerifyingKey.from_signature(sig[1:], recid, h, curve = SECP256k1), compressed @@ -636,12 +635,12 @@ class EC_KEY(object): def verify_message(self, sig, message): - public_key, compressed = pubkey_from_signature(sig, message) + h = Hash(msg_magic(message)) + public_key, compressed = pubkey_from_signature(sig, h) # check public key if point_to_ser(public_key.pubkey.point, compressed) != point_to_ser(self.pubkey.point, compressed): raise Exception("Bad signature") # check message - h = Hash(msg_magic(message)) public_key.verify_digest(sig[1:], h, sigdecode = ecdsa.util.sigdecode_string)