Skip to content

fix issue 854 partially#938

Merged
twiss merged 4 commits intoopenpgpjs:masterfrom
chesnokovilya:dsa-failure-fix
Aug 7, 2019
Merged

fix issue 854 partially#938
twiss merged 4 commits intoopenpgpjs:masterfrom
chesnokovilya:dsa-failure-fix

Conversation

@chesnokovilya
Copy link
Copy Markdown
Contributor

Solve #854
DSA signature elements are made constant length.

@chesnokovilya
Copy link
Copy Markdown
Contributor Author

brainpool bug is inside undutny/elliptic. Library makes incorrect verify calculations for some subset of signatures.

@chesnokovilya
Copy link
Copy Markdown
Contributor Author

@twiss I think we could merge as it is. At least it fixes dsa test failure.

@chesnokovilya chesnokovilya changed the title WIP: fix issue 854 fix issue 854 partialy Aug 1, 2019
@chesnokovilya chesnokovilya changed the title fix issue 854 partialy fix issue 854 partially Aug 1, 2019
Comment thread src/crypto/public_key/dsa.js Outdated
r: r.toArrayLike(Uint8Array),
s: s.toArrayLike(Uint8Array)
r: r.toArrayLike(Uint8Array, 'be', 32),
s: s.toArrayLike(Uint8Array, 'be', 32)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! 👍 I think these should be q.bitLength() / 32 instead of 32 (the signature size varies by key size).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. A bit unrelated but the two calls to util.getLeftNBits(hashed, q.bitLength())) could be replaced by hashed.subarray(0, q.bitLength() / 8); q's bit length must be a multiple of 8. Then getLeftNBits can be removed. You don't have to do that in this PR of course, only if you feel like it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! 👍 I think these should be q.bitLength() / 32 instead of 32 (the signature size varies by key size).

Is there a way to produce failure with the currently implemented code r.toArrayLike(Uint8Array, 'be', 32) ? If yes, it would be wise to add a test specifically for that (with appropriate key size), as this kind of thing would be easy to miss in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I think it would actually still work with this code, as 32 bytes is enough to fit every signature size. Nevertheless, I think we don't have any tests for that. I agree it would be nice to have one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not as crucial to have a test for this if it would not cause a hard failure (and is not a security concern). Thanks for the explanation 👍

@chesnokovilya
Copy link
Copy Markdown
Contributor Author

I will change to q.byteLength then. It should be equal to bitLength / 8 under condition that length is multiple of 8.

@twiss twiss merged commit a0e9c60 into openpgpjs:master Aug 7, 2019
@chesnokovilya chesnokovilya deleted the dsa-failure-fix branch October 16, 2019 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants