Repository navigation
Conversation
b54bb53 to
b4914db
Compare
allocz
left a comment
There was a problem hiding this comment.
I don't think losing part of the entropy worth the gains.
|
Grinding costs the nonce one bit of entropy, but not a secret bit: it is the top bit of R's x-coordinate, which the signature shows anyway. Each attempt is a fresh RFC6979 nonce, so the accepted k is uniform among the nonces with a low R. No known method relates R's x-coordinate to k's bits, so a lattice attack gets no bias in k to use. Bitcoin Core has signed this way by default since 0.17 (bitcoin/bitcoin#13666). |
Add SignLowR, which signs like Sign but searches for a signature whose R has its first byte below 0x80, so DER never pads it. It follows Bitcoin Core's CKey::Sign: the first attempt is the plain RFC6979 signature, and attempt i > 0 passes i as 32 little-endian bytes of extra entropy to the nonce. For any hash below the group order, the result is the signature Core makes. Sign is unchanged. Nothing in dcrd's secp256k1 signs with extra nonce data, so the signing step is written here on top of the exported nonce and curve functions. The tests hold signatures made by libsecp256k1, which also match btclib-ecc. They include a first attempt with a high R that is 70 bytes in DER, which a check on length alone would keep, and counters above 1. Fixes btcsuite#1349.
b4914db to
5c97e62
Compare
Change Description
I added
ecdsa.SignLowR, an opt-in signer that grinds for a low R (first byte below 0x80) as Bitcoin Core'sCKey::Signdoes, so DER never pads R.Signis unchanged. This fixes #1349 the second way it proposed: a new function, not a new default.The first attempt is the plain RFC6979 signature, and attempt
i > 0passesias 32 little-endian bytes of extra nonce data. For any hash below the group order, the result is Core's signature. dcrd's secp256k1 can derive such a nonce but cannot sign with one, so the signing step is written here on its exported nonce and curve functions.The tests hold signatures made by libsecp256k1 (through electrum-ecc) that also match btclib-ecc. They include a first attempt with a high R that is 70 bytes in DER, which a check on length alone would keep, and counters 2 and 5.
Steps to Test
Pull Request Checklist
Testing
Code Style and Documentation
Assisted-by: my usual tools (LLM, Internet, computer). Mistakes are mine.