-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Erroneous comment and VERIFY_CHECK in ecdsa_sig_sign #720
Comments
Hm, this in indeed strange. I agree, this is not an issue. Both of these conditions are computationally unreachable, so this is not a problem and not at all exploitable. But we should still fix it. This was introduced by @apoelstra in 25e3cfb. As I read this commit message, I think he really had the secret nonce I think we should basically revert that commit, but then change the resulting code to fail late to be compliant with the new constant-time test (#710, #708). @apoelstra Can you comment on this? |
Yeah I have no idea what I was thinking here. These are cryptographically unreachable, and it doesn't make sense for the caller to have checked them. Possibly I ran into trouble with the exhaustive tests and put the comment in for that reason. Agree with Tim's solution. |
…dsa_sig_sign" This reverts commit 25e3cfb. The reverted commit was probably based on the assumption that this is about the touched checks cover the secret nonce k instead of r, which is the x-coord of the public nonce. A signature with a zero r is invalid by the spec, so we should return 0 to make the caller retry with a different nonce. Overflow is not an issue. Fixes bitcoin-core#720.
…dsa_sig_sign" This reverts commit 25e3cfb. The reverted commit was probably based on the assumption that this is about the touched checks cover the secret nonce k instead of r, which is the x-coord of the public nonce. A signature with a zero r is invalid by the spec, so we should return 0 to make the caller retry with a different nonce. Overflow is not an issue. Fixes bitcoin-core#720.
I've been following along the ECDSA signing code and have come across what I think is an incorrect comment. In
secp256k1_ecdsa_sig_sign
the code makes the following recommendation:secp256k1/src/ecdsa_impl.h
Lines 285 to 293 in 96d8ccb
However, these two conditions are not actually checked before calling. The main call doesn't:
secp256k1/src/secp256k1.c
Lines 491 to 510 in 96d8ccb
Note that
sigr
is the nonce (R)'s x coordinate reduced modulo q as a scalar. The caller is only checking properties of the secret nonce notsigr
(it doesn't even compute the point for R). Maybe this code was meant to check the secret nonce that's passed in instead?There doesn't seem to be any problem with
sigr
overlfowing (the verification algorithm actually accounts for this possibility by adding the curve order tosigr
if it doesn't work the first time!).sigr
being 0 is a problem but the probability of this happening is so low I wouldn't bother accounting for it. I think this comment and VERIFY_CHECKS can be removed.More generally there doesn't seem to be a problem with the secret nonce overflowing either but the while loop in the caller enforces that and that it's not 0.
The text was updated successfully, but these errors were encountered: