Repository navigation
Conversation
When the hash is longer than q (DSA-SHA256 with a 160-bit q, or SHA-384/512 with a 224/256-bit q), dsaVerify used the whole digest while dsaSign uses bits2int, so valid signatures from this package and from node were rejected. Fixes browserify#102
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #102.
dsaSignreduces the hash withbits2int(hash, q)(keep the leftmostNbits,N= bit length ofq), butdsaVerifyused the whole digest:new BN(hash).mul(w).mod(q). So when the hash is longer thanq, valid signatures were rejected, both the ones this package makes and the ones node makes:Now
dsaVerifydoes the same truncation before using the hash (FIPS 186-4, 4.7).Tests: a new test signs and verifies with both DSA fixtures (160-bit and 256-bit
q) for SHA-224/256/384/512, checks a wrong message is still rejected, and cross-checks with node in both directions. 12 of its asserts fail on main and pass with the fix.npm testis green (100% coverage), and I also ran tape on node 0.12, 16, 22 and 26.