bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
237 stars 122 forks source link

add normalize option for ecdsa signatures #10

Closed cheeseandcereal closed 4 years ago

cheeseandcereal commented 4 years ago

Related to this issue before the repository was moved: https://github.com/PointyCastle/pointycastle/issues/215

Adds option to normalize ecdsa signatures to their lower-s form, required by some ecdsa libraries in an effort to prevent signature malleability

See the above linked issue as well as this comment in libsecp256k1 for more information: https://github.com/bitcoin-core/secp256k1/blob/d644dda5c9dbdecee52d1aa259235510fdc2d4ee/include/secp256k1.h#L483-L513

I imlpemented the normalize function on ECSignature which requires the ECDomainParameters, as well as an optional named boolean parameter normalize on the generateSignature signer function as well

Also included tests to show the functionality working

mwcw commented 4 years ago

Thanks for the patch.

We have committed some updates for doing normalization based on this which avoid having to make ECSignature mutable and that should allow a Normalising Signer to be injected in place of one which does not do normalization.

We have also added optional enforcement of normalization on verification.

It has been added to "ecdsa_signer_test.dart".

Thanks again, any feedback please let us know.

MW