Skip to content
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
merged 7 commits into from
Oct 22, 2015

Conversation

sipa
Copy link
Contributor

@sipa sipa commented Oct 12, 2015

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.

@sipa sipa force-pushed the strictder branch 4 times, most recently from 20e8d31 to 827b50c Compare October 14, 2015 15:53
@sipa
Copy link
Contributor Author

sipa commented Oct 14, 2015

Added a commit that introduces a snippet for lax DER parsing (tested!).

@sipa
Copy link
Contributor Author

sipa commented Oct 17, 2015

Addressed many comments.

@sipa sipa changed the title Rewrite ECDSA signature parsing code Overhaul ECDSA signature parsing: strict DER, compact sigs, tests, lower-S Oct 17, 2015
@sipa sipa force-pushed the strictder branch 4 times, most recently from 5f05975 to 7e68982 Compare October 19, 2015 16:00
@sipa
Copy link
Contributor Author

sipa commented Oct 19, 2015

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.
@gmaxwell
Copy link
Contributor

ACK

@sipa sipa merged commit 0c6ab2f into bitcoin-core:master Oct 22, 2015
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants