This is a paragraph from Andreas' book on compressed/uncompressed public keys.
Chapter 4 - Section - Key Formats
Whereas uncompressed public keys have a prefix of 04 ,compressed public keys start with either a 02 or a 03 prefix. Let’s look at why there are two possible prefixes: because the left side of the equation is y^2 , that means the solution for y is a square root, which can have a positive or negative value. Visually, this means that the resulting y coordinate can be above the x-axis or below the x-axis. As you can see from the graph of the elliptic curve in Figure 4-2, the curve is symmetric, meaning it is reflected like a mirror by the x-axis. So, while we can omit the y coordinate we have to store the sign of y (positive or negative), or in other words, we have to remember if it was above or below the x-axis because each of those options represents a different point and a different public key. When calculating the elliptic curve in binary arithmetic on the finite field of prime order p, the y coordinate is either even or odd, which corresponds to the positive/negative sign as explained earlier. Therefore, to distinguish between the two possible values of y, we store a compressed public key with the prefix 02 if the y is even, and 03 if it is odd, allowing the software to correctly deduce the y coordinate from the x coordinate and uncompress the public key to the full coordinates of the point. Public key compression is illustrated in Figure 4-7
What I don't get is that bold text.
Why an even or odd y coordinate corresponds to the positive / negative sign?
For example, are all even public keys below the x-axis?
y² mod p = (x³ + 7) mod p , for p = 5, x = 3
, i get 2 solutions as you explained, and it happens that you can find the odd/even solution (2² mod 5 = 3² mod 5
) fory²
. I had to force this to come up with2
and3
as square roots of4
although it makes sense as thereal
roots are2
and-2
, and-2 mod 5 = 3
. What ifx=4
? We get1² mod 5
and ...2.44948974² mod 5
. A fractional number can't be odd or even. – Souza Feb 15 '18 at 13:39x^2 mod p
. So we sayy
is the square root ofx mod p
iffy^2 mod p = x
. – Pieter Wuille Feb 15 '18 at 16:05and
v = 27 + ((y % 2) ^ (1 if is_high_s else 0))` ? – Souza Feb 20 '18 at 18:56