I'm currently stuck at a problem, where I'm supposed to proove that the user public key of a returned u2f token corresponds to an elliptic curve equation (secp256r1). The token looks as follows:


At first I extracted the X and Y coordinates
and then SEC2v1 says that the elliptic curve looks like $y^2=x^3+a\,x+b$ and the $a$ and $b$ parameters are given there as well. So my thought was I just paste in $x$ into this equation to get $y^2$ and then take the square root of it. Unfortunately I keep getting wrong results.

What's wrong with my approach?

  • $\begingroup$ The curve's equation is not in the integers $\mathbb Z$ or the reals $\mathbb R$. Its in a finite field. It's specified which is the spec you linked. Also, to test an equality, the most natural method goes: compute both sides and compare. Your method with a square root will sometime reach a wrong conclusion (if we where in the field $\mathbb R$: when $y$ is negative; and there are analogs in other fields). $\endgroup$
    – fgrieu
    Commented Oct 26, 2020 at 7:34
  • $\begingroup$ Your token might not be uncompressed there is 02 in the front of the public key. This simply explains why they need 65-bytes in the standard, too. But still conflict since why did they need extra 32. $\endgroup$
    – kelalaka
    Commented Oct 26, 2020 at 7:54
  • $\begingroup$ @kelalaka Is there? I figured out the public key was 047d550bc2384fd76a47b8b0871165395e4e4d5ab9cb4ee286d1c60d074d7d60ef8cc6dd01e747ccb8bedaae6e7fb875d036ce7e4e6231b75b93993b15202829ac or am I wrong with that? Thanks a lot for your response though. :) $\endgroup$
    – Steven
    Commented Oct 26, 2020 at 8:27
  • $\begingroup$ @fgriue Thanks for your response, but isn't the eliptic curve inside of the field? Maybe I missunderstand something, but I thought that the eliptic curve lays inside of the finite field and if that's the case shouldnt my calculation lead to a true statement? I'm reallly sorry if i messed something up. $\endgroup$
    – Steven
    Commented Oct 26, 2020 at 8:43
  • $\begingroup$ The arithmetic of the equation is in the field $\mathbb F_p$ (that is, the integers modulo $p$) with $p$ the prime in the spec. Your task is to harness the right tools to compute both sides of the equation in that field (then compare). $\endgroup$
    – fgrieu
    Commented Oct 26, 2020 at 9:12

1 Answer 1


It is on the curve. Used the sageMath code supplied here for the NIST P-256 curve ( aka secp256r1). Test it online here

# Finite field prime
p256 = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF

# Curve parameters for the curve equation: y^2 = x^3 + a256*x +b256
a256 = p256 - 3
b256 = 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B

px = 0x7d550bc2384fd76a47b8b0871165395e4e4d5ab9cb4ee286d1c60d074d7d60ef
py = 0x8cc6dd01e747ccb8bedaae6e7fb875d036ce7e4e6231b75b93993b15202829ac

print("The x-coordinate =", px)
print("The y-coordinate =", py)
print(py^2 % p256 )
print((px^3 + a256*px + b256) % p256)



Note 1: The u2f standard can be found FIDO U2F Raw Message Formats

Note 2: there is no need to take the square root. Just compare both sides in the modulus of the curve. This eliminates extra square root calculations on the field.

A little elliptic curve;

In the finite field based Elliptic Curve, we take a finite field $F$ (prime field or finite field extension) and define a curve equation by $$y^2 + a_1xy + a_3y = x^3 + a_2x^2 + a_4x + a_6$$ This is Weierstrass equation.

If the field $F$ has characteristics different from 2 or 3 then the Weierstrass equation can be turned into the short form.

$$y^2 = x^3 + Ax +B$$

The equation is the standard short Weierstrass form. We don't want a singular curve so we check that the curve discriminant is non zero by $$2A^3-27B^2 \neq 0.$$

The points of the curve form an abelian group under the geometric interpretation with an identity element call $\mathcal{O}$, it can be the point at infinity like in secp256r1 or $(0,1)$ as the Edwards curves. The geometric interpretation of point addition turned into arithmetic over the field $F$.

  • $\begingroup$ Wow, thanks a lot for the effort! :) Unfortunately I'm supposed to figure it out "by hand". Do you know if the approach I've taken up there is wrong? All my research so far showed that this seems to be the most common method to check it out. But due to your confirmation I do atleast know that my calculation is wrong and I can be sure that my trial and error is not for nothing. :'D P.S: Thanks for the hint with the square root, I didn't think about it properly. $\endgroup$
    – Steven
    Commented Oct 26, 2020 at 8:53
  • $\begingroup$ Well, I don't know what do you mean by hand, however, the last 3 lines you need with $a$,$b$, and $p$. For the, you need a big number library where SageMath is helpful. $\endgroup$
    – kelalaka
    Commented Oct 26, 2020 at 8:56
  • $\begingroup$ I've simplified the code. now, it just calculates the arithmetic, $\endgroup$
    – kelalaka
    Commented Oct 26, 2020 at 9:02
  • $\begingroup$ Thank you, it became way more clear now! :) I still missunderstand something. Why do you calculate modulo the field? I've tested the online IDE aswell and tried if px^3+a256*px+b256 equals to py^2 but it doesn't, so I think my whole understanding is wrong... I'm really sorry for being so slow, but even with researching a lot I don't seem to understand it and that's really frustrating. $\endgroup$
    – Steven
    Commented Oct 26, 2020 at 9:15
  • 1
    $\begingroup$ Alright, thank you very much for your time and help. Things became much clearer! :) $\endgroup$
    – Steven
    Commented Oct 26, 2020 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.