-
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
Overhaul ECDSA signature parsing: strict DER, compact sigs, tests, lower-S #334
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sipa
force-pushed
the
strictder
branch
4 times, most recently
from
October 14, 2015 15:53
20e8d31
to
827b50c
Compare
Added a commit that introduces a snippet for lax DER parsing (tested!). |
Addressed many comments. |
sipa
changed the title
Rewrite ECDSA signature parsing code
Overhaul ECDSA signature parsing: strict DER, compact sigs, tests, lower-S
Oct 17, 2015
sipa
force-pushed
the
strictder
branch
4 times, most recently
from
October 19, 2015 16:00
5f05975
to
7e68982
Compare
Added a certainly_not_der as output from the BER generator, and tests using it. |
This commit adds functions: * secp256k1_rand_bits, which works like secp256k1_rand32, but consumes less randomness * secp256k1_rand_int, which produces a uniform integer over any range * secp256k1_rand_bytes_test, which works like secp256k1_rand256_test but for arbitrary byte array
Update the unit tests to make use of the new RNG functions.
There are now 2 encoding formats supported: 64-byte "compact" and DER. The latter is strict: the data has to be exact DER, though the values inside don't need to be valid.
This shows a snippet of code to do lax DER parsing, without obeying to any particular standard.
ECDSA signature verification now requires normalized signatures (with S in the lower half of the range). In case the input cannot be guaranteed to provide this, a new function secp256k1_ecdsa_signature_normalize is provided to preprocess it.
ACK |
sipa
added a commit
that referenced
this pull request
Oct 22, 2015
0c6ab2f Introduce explicit lower-S normalization (Pieter Wuille) fea19e7 Add contrib/lax_der_parsing.h (Pieter Wuille) 3bb9c44 Rewrite ECDSA signature parsing code (Pieter Wuille) fa57f1b Use secp256k1_rand_int and secp256k1_rand_bits more (Pieter Wuille) 49b3749 Add new tests for the extra testrand functions (Pieter Wuille) f684d7d Faster secp256k1_rand_int implementation (Pieter Wuille) 251b1a6 Improve testrand: add extra random functions (Pieter Wuille)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are now 2 encoding formats supported: 64-byte "compact" and DER. The latter is strict: the data has to be exact DER, though the values inside don't need to be valid.
This means that applications that need more than strict DER as input, it needs to have a parser itself. I wish there was a better solution, but there really isn't. Any subset of BER to implement would be arbitrary, incompatible with many other applications anyway, or be very complex and nearly untestable. Despite that, a code snippet to do so (with extensive testing) is included in the contrib/ directory now.
Finally, by default, we now require non-malleable signatures (by requiring the lower-S form), but a separate function is provided to normalize a signature before verification if needed.