ecies: don't drop sign of ephemeral key

This commit is contained in:
ThomasV 2014-09-01 13:15:15 +02:00
parent 03e420b1c0
commit eed37c41b5
1 changed files with 2 additions and 4 deletions

View File

@ -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():