From eed37c41b51f99e1fa6e532a20fe879d6388729d Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 1 Sep 2014 13:15:15 +0200 Subject: [PATCH] ecies: don't drop sign of ephemeral key --- lib/bitcoin.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/bitcoin.py b/lib/bitcoin.py index 41bb1bdfe..27ea7a500 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -522,8 +522,7 @@ class EC_KEY(object): ephemeral_exponent = number_to_string(ecdsa.util.randrange(pow(2,256)), generator_secp256k1.order()) ephemeral = EC_KEY(ephemeral_exponent) - ecdh_key = (pk * ephemeral.privkey.secret_multiplier).x() - ecdh_key = ('%064x' % ecdh_key).decode('hex') + ecdh_key = point_to_ser(pk * ephemeral.privkey.secret_multiplier) key = hashlib.sha512(ecdh_key).digest() key_e, key_m = key[:32], key[32:] @@ -559,8 +558,7 @@ class EC_KEY(object): if not ecdsa.ecdsa.point_is_valid(generator_secp256k1, ephemeral_pubkey.x(), ephemeral_pubkey.y()): raise Exception('invalid ciphertext: invalid ephemeral pubkey') - ecdh_key = (ephemeral_pubkey * self.privkey.secret_multiplier).x() - ecdh_key = ('%064x' % ecdh_key).decode('hex') + ecdh_key = point_to_ser(ephemeral_pubkey * self.privkey.secret_multiplier) key = hashlib.sha512(ecdh_key).digest() key_e, key_m = key[:32], key[32:] if mac != hmac.new(key_m, encrypted[:-32], hashlib.sha256).digest():