ECDH result not matching #1444
-
Hi,
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I don't know how MBEDTLS defines the shared secret computation, but there is no reason to assume it is in any way similar to what libsecp256k1 does. |
Beta Was this translation helpful? Give feedback.
The "raw" shared secret is just a curve point (
P = PlainECDH(xG, yG) = xyG
), and the computation of this match on the same curve and same keys. But a curve point does not look like a uniform random byte string (and having a value that does is preferable). That's why implementations hash this value and return the hash as an actual shared secret, i.e., they returnH(P)
, and now the result depends on your choice of H and the encoding of P (e.g., compressed vs uncompressed).I don't know what mbedTLS does the hashing (perhaps similar to what is done in TLS?). What libsecp256k1 returns by default is
SHA256(compressed(P))
. If you need a different way of computing the hash, you can pass a functi…