0%

crypto

1. ECDH

ECDH是用来交换密码的,Alice和Boc使用椭圆函数secp256k1,生成各自的公钥和私钥,然后用自己的私钥和对方的公钥,生成一个screate key, 这个screate key是一样的。

1.1 secp256k1

公钥分为压缩和非压缩的,这个看前缀,如果是0x04开头,是非压缩。
压缩的:只有x,因为y可以推断出。
非压缩:把椭圆曲线上的x和y相连,就是x+y的hex字符串相连,就是这么简单。有的地方如果接受64个字节,那么不要0x04前缀;有的地方接受65个字节,那么需要加上0x04前缀。

Actually the compressed form in hex is 02 + X_coordinate if Y coordinate is even, or 03 + X_coordinate if Y coordinate is odd; comparing to the uncompressed form is 04 + X_coordinate + Y_coordinate.

So to retrieve the coordinates from the compressed form, just calculate the Y coordinate by curve equation Y^2 = X^3 + a*X + b, there will be two Y values, then choose the correct one by the prefix which is 02 or 03.
You will get the actual coordinates of the point.

https://www.zhihu.com/question/22399196
https://zhuanlan.zhihu.com/p/69042756
https://bitcoin.stackexchange.com/questions/19666/why-do-keys-need-both-x-and-y-coordinates-if-x-can-be-solved-for-y-using-the-cu

https://bitcoin.stackexchange.com/questions/32634/ecdsa-x-y-coordinate-validity-verification-doesnt-seem-to-work

https://crypto.stackexchange.com/questions/90151/verify-that-a-point-belongs-to-secp256r1