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
Fix, derToRaw does not handle r/s with leading 0s. #117
Conversation
…ading (excluded) zeros.
Codecov ReportBase: 92.94% // Head: 92.95% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #117 +/- ##
=======================================
Coverage 92.94% 92.95%
=======================================
Files 16 16
Lines 5984 5992 +8
=======================================
+ Hits 5562 5570 +8
Misses 422 422
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Thanks for your contribution! It'd be great if you could consider my comments and bring the changes and tests more in line with the existing codebase 👍 |
…ript native types for padding the array in derToRaw.
Thanks a lot for the updates - really clean and good solution! 💯 Do you want to do the celebratory version bump (to 3.3.5) in the package.json for the automated deployment? Happy new year to you, by the way! |
Sounds good. Thanks @JamesCullum! Happy new year to you as well! |
Fixes: 118
What Changed
Updating the derToRaw function to handle signature parts that have leading (excluded) zeros.
Details of the Issue
The R and S in ASN.1/DER are 32 byte signed numbers. There are two properties that need to hold true:
abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123000000
will be represented as00abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123000000
.000000abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123
will be represented as00abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123
(leading 00 because ab is negative).When converting the number, you need to be mindful of the actual length of the number, to avoid overflowing into the other number.
Raw/IEEE P1363 requires the r/s values to be non-minimized unsigned values (always 32 bytes), so we need to add back the leading zeros to the number to make it 32 bytes when we return the value.
A good explanation of ASN.1/Der can be found here: