ethereum / devp2p

Ethereum peer-to-peer networking specifications
984 stars 275 forks source link

Discv5: ECDH shared secret #134

Closed jannikluhn closed 4 years ago

jannikluhn commented 4 years ago

We seem to use both the x and y component of the curve point created by ECDH:

ecdh(pubkey, privkey) creates a secret through elliptic-curve Diffie-Hellman key agreement. The public key is multiplied by the private key to create a secret ephemeral key eph = pubkey * privkey. The 33-byte secret output is y || eph.x where y is 0x02 when eph.y is even or 0x03 when eph.y is odd.

Unfortunately, the crypto library used in Trinity just gives us the x component. I assume the same is the case for OpenSSL since the Python library is just a wrapper around it (I haven't confirmed this though). Given this assumption is correct, is there a reason for using both x and y?

fjl commented 4 years ago

Damn. We were actually using just x before this change, but then @AgeManning complained about this being hard to implement with their Rust wrapper around secp256k1. I don't care either way since the y coordinate doesn't add much to the security...

AgeManning commented 4 years ago

Oh no! Yeah, I figured the more general case was with the y co-ordinate as that was what the C library and subsequent rust library was using.

jannikluhn commented 4 years ago

Alright, I found another library that uses the y || x format, so I'm happy now.