-
Notifications
You must be signed in to change notification settings - Fork 109
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
Why is it necessary to ensure signature verified with the recovered key? #751
Comments
Computing the recovered key involves solving a system of linear equations. If the signature doesn’t verify, an attacker can trick you into recovering the wrong key. |
Can you elaborate a bit more on this? Would the system of linear equations not constrain that the recovered key verifies? A concrete example where |
It does not. An attacker can easily solve for whatever key they want if there is no requirement that the signature verifies. |
Are you saying that if an attacker has control over the input, then they can get |
I’m currently on vacation and don’t have time to put together a contrived example for you |
In Bitcoin's secp256k1 implementation, the recovery routine doesn't include verification of the recovered public key. You can see this in the Bitcoin secp256k1 code. If the recovered public key isn't correct, an error occurs when comparing it to the correct public key or public key hash. Therefore, we can skip this expensive verification. In https://www.secg.org/sec1-v2.pdf:
If Q is equal to expected pubkey(not verify again), we can stop immediately. |
I think it would be okay to add a separate |
https://github.com/RustCrypto/signatures/blob/8516671bb56abe998d3e88d941df7862b6d58985/ecdsa/src/recovery.rs#L313C9-L313C47
I'm not super familiar with the details of ECDSA, but for my workload this
verify_prehash
check doubles the runtime. Is there any situation where this check will actually fail?The text was updated successfully, but these errors were encountered: