-
Hi, The function is simple: y^2 = x^3 +7 (a = 0, b = 7, so more than simple) Sorry gentlemen, but could someone explain me how can I get the Y coordinate across a concrete example? So.. for example: Private key: mpz_pow_ui(y, y, 2); mpz_pow_ui(x1, x1, 3); Result: At least they are equal, but .. I tried with every kind of SQR, INVERT woodo.. not even close to Y. (Sorry, If I messed up something..) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
To get the X coordinate from the Y coordinate, you need to solve x3 = y2 - 7 (mod p), or in other words, find the modular cube roots of y2 - 7. Due to the fact that p mod 3 = 1, this is particularly easy: x = (y2 - 7)(p + 2)/9 (mod p) to find one of the cube roots. They always come in triples (for any given Y coordinate on the curve there are 3 distinct X coordinates); the other two X's can be found by multiplying with the cube roots of 1 (namely 0x851695d49a83f8ef919bb86153cbcb16630fb68aed0a766a3ec693d68e6afa40 and 0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee). This seems mostly unrelated to libsecp256k1 though, as it has no functionality to compute X from Y. There may be better places to ask about this (In fact, I recently answered a very related question here: https://bitcoin.stackexchange.com/a/120051/208). |
Beta Was this translation helpful? Give feedback.
-
Hi sipa, |
Beta Was this translation helpful? Give feedback.
-
That's what I thought! This is the reason, why I just wanna store the Y coordinate. No even or odd, like from X.. just straight point coordinates. |
Beta Was this translation helpful? Give feedback.
I'm not sure what you're trying to do, but computing Y from X is a lot simpler than X from Y. That is what the compressed public key format is based on, which is supported by libsecp256k1.
For that, the relation is just y = +- sqrt(x^3 + 7) mod p.