-
Notifications
You must be signed in to change notification settings - Fork 180
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
Crypto: check ECDSA signature length in verification #10
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abdfa0b
add check for signature length
5bd67de
add tests for invalid signature length
31aba75
include larger signature in the invalid length test
7c27630
do not return an error when a a signature length is invalid
3adaf3c
Merge branch 'master' into tarak/ecdsa-verify-sig-length
Kay-Zee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,9 +99,15 @@ func (sk *PrKeyECDSA) Sign(data []byte, alg hash.Hasher) (Signature, error) { | |
|
||
// verifyHash implements ECDSA signature verification | ||
func (pk *PubKeyECDSA) verifyHash(sig Signature, h hash.Hash) (bool, error) { | ||
Nlen := bitsToBytes((pk.alg.curve.Params().N).BitLen()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice fix 👍 |
||
|
||
if len(sig) != 2*Nlen { | ||
return false, fmt.Errorf("signature length is %d, must be %d", | ||
len(sig), 2*Nlen) | ||
} | ||
|
||
var r big.Int | ||
var s big.Int | ||
Nlen := bitsToBytes((pk.alg.curve.Params().N).BitLen()) | ||
r.SetBytes(sig[:Nlen]) | ||
s.SetBytes(sig[Nlen:]) | ||
return goecdsa.Verify(pk.goPubKey, h, &r, &s), nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Moving this check here is picked from another WIP branch:
https://github.com/onflow/flow-go/blob/tarak/4482-multi-sig-verification-distinct-msg/crypto/bls.go#L116
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.
This puts us in an odd position, because a signature of length 0 is an invalid signature (i.e. caused by the sig, not by other parts of the func), but returning the error here actually breaks the assumption that invalid signatures simply return
false, nil
and the error here is taken as a fatal error. I've addressed this in the deployed branch of testnet, but i'm not sure if that's what we wantThere 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.
I was thinking about this today when I made the change in ECDSA. The change in BLS here is only meant to match the change in ECDSA.
I think there is a fine line between checking the input format on one side, and verifying the signature against a key on the other. I'm also inclined not to return an error, although I think passing a signature with a wrong length generally happens when there is an implementation bug and it would be good to notify the developer about it, instead of returning
false
silently.I'm happy not to error in this case if the error can cause trouble behind.