-
Notifications
You must be signed in to change notification settings - Fork 75
Fix rejecting bad signatures / messages in DSA, ECDSA, ElGamal #233
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| {nbs,BigInteger} = require '../../lib/bn' | ||
|
|
||
| #================================================================= | ||
|
|
||
| exports.valid_mod_inverse_returns_inverse = (T, cb) -> | ||
| cases = [ | ||
| { a : '3', m : '257', inverse : '86' } | ||
| { a : '10', m : '17', inverse : '12' } | ||
| { a : '101', m : '257', inverse : '28' } | ||
| ] | ||
|
|
||
| for c in cases | ||
| a = nbs c.a | ||
| m = nbs c.m | ||
| inv = a.modInverse m | ||
| T.equal inv.toString(), c.inverse, "#{c.a}^-1 mod #{c.m}" | ||
| T.equal a.multiply(inv).mod(m).toString(), '1', "#{c.a} * inverse == 1 mod #{c.m}" | ||
| cb() | ||
|
|
||
| #================================================================= | ||
|
|
||
| exports.invalid_mod_inverse_returns_zero_when_gcd_is_not_one = (T, cb) -> | ||
|
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. I am kinda nervous at this function returning 0 when there is no inverse. Not saying we should change it in this PR, but if I were to write this again I would throw instead.
Contributor
Author
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. seems to be the bignum library doing that, maybe we should swap it to another one going forward long term. Initially I was going to monkey-patch it but that's kind of ugly. This is just a test to understand and lock in curreent behavior. |
||
| cases = [ | ||
| { a : '2', m : '4' } | ||
| { a : '6', m : '9' } | ||
| { a : '101', m : '101' } | ||
| { a : '202', m : '101' } | ||
| { a : '3', m : '0' } | ||
| ] | ||
|
|
||
| for c in cases | ||
| a = nbs c.a | ||
| m = nbs c.m | ||
| inv = a.modInverse m | ||
| T.equal inv.signum(), 0, "#{c.a}^-1 mod #{c.m} returned zero" | ||
| T.equal inv.toString(), '0' | ||
| unless m.signum() is 0 | ||
| T.assert not(a.gcd(m).equals(BigInteger.ONE)), "#{c.a} and #{c.m} are not coprime" | ||
| cb() | ||
|
|
||
| #================================================================= | ||
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.
@AMarcedone does this look good?
encryptreturns both valuesmod pso in principle honest ciphertext should be in that range