BitcoinPHP / BitcoinECDSA.php

PHP library to generate BTC addresses and signatures from private keys.
222 stars 106 forks source link

Diffie Hellman #31

Closed arik-so closed 8 years ago

arik-so commented 8 years ago

Hi! It would be super useful if you implemented a method to support Diffie Hellman. That is, given one keypair's public key and another keypair's private key, multiplying the two yields a very useful symmetric key.

rgex commented 8 years ago

Hi arik, this can be easily done using the mulPoint method. $bitcoinECDSA->mulPoint($k, $point); $k is your private key as a GMP resource, and $point an array with the format ['x'=>(GMP resource), 'y' => (GMP resource)]

If you give me an ECDH encoding standard (maybe DER) I can add a method that render it that way.

arik-so commented 8 years ago

Thanks, I found the mulPoint method and implemented Diffie Hellman. I'm applying a sha256 to the result (which is the new point in DER format) to restrict the output to 32 bytes so it can be used as an AES-256 key.