Assume a standard ECC curve in a prime field $\mathbb F_p$ with $p\equiv3\pmod 4$, such as secp256k1; and code turning a bytestring for a compressed ECC public key into an Elliptic Curve point, that does as specified except in the following two emphasized spots:
2.1. Parse $M=Y\mathbin\|X$ as a single octet $Y$ followed by $\lceil(\log_2 q)/8\rceil$ octets $X$.
2.2. Convert $X$ to a field element $x_P$ of $\mathbb F_q$ using the conversion routine specified in Section 2.3.6. Output “invalid” and stop if the routine outputs “invalid”.
2.3. If $Y=\mathtt{02_{16}}$, set $\tilde y_p=0$, and if $Y=\mathtt{03_{16}}$, set $\tilde y_p=1$. Otherwise output “invalid” and stop.
2.4. Derive from $x_P$ and $\tilde y_p$ an elliptic curve point $P=(x_P,y_P)$, where:
- 2.4.1. If $q=p$ is an odd prime, compute the field element $\alpha={x_P}^3+a\,x_P+b\bmod p$, and compute a square root $\beta$ of $\alpha$ modulo $p$. Output “invalid” and stop if there are no square roots of $\alpha$ modulo $p$, otherwise set $y_P=\beta$ if $\beta\equiv\tilde y_p\pmod 2$, and set $y_P=p −\beta$ if $\beta\equiv\tilde y_p\pmod 2$.
Specifically, assume that, as in the code of this answer (on bitcoin-SE):
- in 2.2, $x_P\ge p$ is not caught;
- in 2.4.1, $\beta$ is computed as $\beta\gets\alpha^{(p+1)/4}\bmod p$, but it's checked neither that $\beta^2\bmod p=\alpha$ (direct check that the computed $\beta$ is a square root), nor that $\alpha^{(p-1)/2}\bmod p=1$ (Euler's criterion).
Therefore, when decompressing an invalid compressed public key, we can end up with $P=(x_P,y_P)$ not on the curve (even after reducing the coordinates modulo $p$), but still a very specific relation between $x_P$ and $y_P$. Also we can end up with $x_P=0$, or $x_P=p$, or $x_P>p$, or perhaps (I did not check) $y_P=0$ or $y_P=p$. A few more oddities are possible when $\log_2p\not\equiv7\pmod8$ (e.g. for secp521r1).
What can be the consequences, in various common primitives (ECDSA, ECIES, ECDH, ECMQV…), protocols, contexts? In particular
- Assuming a certification authority with that specific blunder, and no further sanity check of the public key, could a Certificate Signing Request for the invalid public key still pass the signature check of the CSR?
- Is there some protocol where these blunders could allow/has allowed an attack?