from bitcoin import *
Alice_private = 1
Alice_public = privtopub(Alice_private)
Bob_private = 2
Bob_public = privtopub(Bob_private)
#they exchange publics
Alice_message=ecdsa_raw_sign(sha256('Hello'), Alice_private)
Bob_message = ecdsa_raw_sign(sha256('Hello back'), Bob_private)
Alice has her private key, her public key and she has Bob’s public key and the message from Bob.
But the bad guy also has Bob’s public key and Bob’s message.
Where does the magic happen, how do they secure communication from here?
This doesn’t work either:
from bitcoin import *
a = 10
b = 20
a1,a2 = privkey_to_pubkey(a)
b1,b2 = privkey_to_pubkey(b)
a3,a4 = b1*a, b2*a
b3,b4 = a1*b, a2*b
if a3 == b3:
print(True)
It looks like you are using https://github.com/vbuterin/pybitcointools.
What I think you are trying to do is Diffie Hellman key agreement, which is different from ECDSA.
You seem to have the right idea in your second example, but elliptic curve point multiplication isn’t as straightforward as what you are doing.
The library you are using does have a
multiply(pubkey, privkey)
function, which does what you want:The shared secret is a point on the curve, i.e. an (x, y) coordinate pair (a tuple in this library). You would usually take the X coordinate and hash it to derive a key for symmetric encryption.