-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto/elliptic: IsOnCurve returns false #51059
Comments
Related: #50974. Likely not directly caused by the fix for that issue (since it was resolved after beta2), but it sounds like this is the intended behavior going forward. |
cc @golang/security |
|
@tscholl2 I am curious though, how did this point get generated, and how is it used? P-256 on amd64/arm64 and P-224 on Go 1.17 will drop the sign when operating on it, so I'm surprised it worked. |
That explains more! It came up debugging a failed test. I think P-256 was passing, so that lines up with what you said. The library used a negative number when computing the negative of a point in Weierstrass form: https://github.com/schollz/pake/blob/master/pake.go#L196 |
The reason P-256 was passing and P-521 was failing with Go 1.18 is that P-521 (and P-384 and P-224) started returning random points when asked to operate on invalid points in Go 1.18, like at the line you linked. (We decided to make it an explicit panic in Go 1.19 to avoid painful debugging sessions like the one we caused you, sorry, but it was too late for Go 1.18.) P-256 instead accepts it but ignores the sign so you were not actually operating on (x, -y) as you'd expect but on (x, y). What I am curious about is how that worked in the first place. |
I only had to find where the API failed, you did a lot more work! That's a good question about how it was working. I am certain it was passing tests before, which Edit: I just realized the way the library works, it may be possible that if the curve arithmetic failed consistently, it may also have passed. EditEdit: If P256 was dropping the sign, shouldn't this fail? https://go.dev/play/p/UGFPYcqc5q9 |
Ah, I just realized why it's not dropping the sign: ScalarMult on amd64/arm64 will drop the sign, but Add falls back to the generic (slow, variable-time, big.Int based) implementation which will reduce the value modulo P. So yeah, it looks like that code got lucky that it only used operations that reduce the input. Still, it's undefined behavior, and it will break intentionally in Go 1.18 and Go 1.19. |
Ha! Lucky indeed. The library I referenced is already aware and either has patched or is about to. Thanks for figuring all that out and letting everyone know! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/xqk_POfNLOS?v=gotip
What did you expect to see?
This is what I select "GO release".
What did you see instead?
This is likely the cause of this real world issue: schollz/pake#7
Edit: fixed the output, I had copied it wrong.
The text was updated successfully, but these errors were encountered: