-
Notifications
You must be signed in to change notification settings - Fork 93
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
Convert EC signature data and use unified verify #4
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4 +/- ##
==========================================
- Coverage 84.2% 83.83% -0.38%
==========================================
Files 150 150
Lines 5781 5771 -10
==========================================
- Hits 4868 4838 -30
- Misses 913 933 +20
Continue to review full report at Codecov.
|
|
||
// For byte >= 0x80 (first bit is 1), prefix 0x00 to make Security framework happy. | ||
if rBytes.first! >= UInt8(0x80) { | ||
rBytes = [0x00] + rBytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess this is doing the Signed big-endian encoding of minimal length
👍
Reference: https://crypto.stackexchange.com/a/1797 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on the implementation detail of the security framework/algorithm we are using. Here for Security.framework, we need to do so, otherwise, the signature is not accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to use subdata(in:) and insert(_:at:) to manipulate Data directly, but this is also very clear. LGTM~
This PR removes the workaround used for ECDSA verification. Previously, there was a mistake on extra bit prefixing (we thought we need to prefix 0x00 when the first bit is above than 0x70, but actually it should be 0x80).
It turns out that the
. ecdsaSignatureMessageX962SHA256
algorithm works well for the newSecKeyVerifySignature
API, as long as we convert the raw {r,s} signature data to DER-encoded format. So it is no need to make the verifying method seperated anymore.