-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
crypto/elliptic: different ecdsa.Verify result between p256 amd64 and generic implementations with a zero hash #20215
Comments
Saving others a click, code is: |
Verified the 386/amd64 difference is the same in Go 1.7, Go 1.8, and tip. |
CL https://golang.org/cl/42590 mentions this issue. |
(I believe the verification should have passed in both cases, rather than failed. I.e. the referenced test case appears to be a valid signature of a zero hash. That means that we're rejecting a valid signature rather than accepting an invalid signature, which is less of a problem at least.) |
(For my own reference in the future: there's an incomplete fix in https://go-review.googlesource.com/c/42611, but it'll need assembly changes and I'm not going to attempt that today; I'll only mess it up.) |
CL https://golang.org/cl/42611 mentions this issue. |
Per that comment, I'm going to mark this as Go 1.9 material and not Go 1.8.2. |
@agl, do you want this (your https://go-review.googlesource.com/c/42611/) in Go 1.9 or should we bump it to Go 1.10? |
The question here should also be "what should we do if we have a zero hash in ECDSA, knowing that this may partly breaks ECDSA"... A crafted signature would then validate since upon verification you compute:
Now, we should ask ourselves what we want to do when confronted to such a zero hash, or such a strange signature... So the zero hash does not permit us to ensure the authenticity of the signature since such forgeries are possible (note that there might be other less trivial forgeries). So far, I've done a few tests on the topic to see how other are handling it and have found that:
I must say that I'm not really sure what would be the best way around this issue. I believe that we should reject the signatures as soon as the values u1 or u2 are zero, or throw an error maybe. (This is fine since secret material is not involved in the verification process and signing the zero hash value does not leak secret material as long a the I don't know what is your opinion on that topic @agl ? |
Change https://golang.org/cl/62630 mentions this issue: |
Change https://golang.org/cl/62292 mentions this issue: |
This disables the s390x assembly. It will be re-enabled when #20215 is resolved on s390x. Change-Id: I789eca2dd478004956107359fae98ed012f04abb Reviewed-on: https://go-review.googlesource.com/62292 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Change https://golang.org/cl/64290 mentions this issue: |
This applies the amd64-specific changes from CL 42611 to the s390x P256 implementation. The s390x implementation was disabled in CL 62292 and this CL re-enables it. Adam Langley's commit message from CL 42611: The optimised P-256 includes a CombinedMult function, which doesn't do dual-scalar multiplication, but does avoid an affine conversion for ECDSA verification. However, it currently uses an assembly point addition function that doesn't handle exceptional cases. Fixes #20215. Change-Id: I2f6b532f495e85b8903475b4f64cc32a3b2f6769 Reviewed-on: https://go-review.googlesource.com/64290 Run-TryBot: Michael Munday <mike.munday@ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
What version of Go are you using (
go version
)?tip
What operating system and processor architecture are you using (
go env
)?GOARCH=386 and GOARCH=amd64
What did you do?
Code pulled from golang-nuts post https://groups.google.com/forum/#!topic/golang-nuts/M7tXCf8a4pk
What did you expect to see?
I assume the verification should have failed in both cases.
What did you see instead?
Verification passed for the 32 bit binary.
Cause
The difference is in the path taken in ecdsa.Verify:
The S390 and AMD64 versions of CombinedMult appear to always set the Z value to 1 regardless of X and Y.
(*curveParams).Add calls zForAffine which returns a Z value of 0 if X or Y are zero.
Modifying zForAffine to match the behavior of the optimized CombinedMults (Z=1 in all cases) causes TestInfinity to fail, but otherwise the generic and optimized CombinedMults give the same output for this case.
The text was updated successfully, but these errors were encountered: