Skip to content

Fix rejecting bad signatures / messages in DSA, ECDSA, ElGamal - #233

Open
michalz-zoom wants to merge 3 commits into
masterfrom
modinverse-rejections
Open

Fix rejecting bad signatures / messages in DSA, ECDSA, ElGamal#233
michalz-zoom wants to merge 3 commits into
masterfrom
modinverse-rejections

Conversation

@michalz-zoom

Copy link
Copy Markdown
Contributor

No description provided.

@zoom-ua
zoom-ua self-requested a review July 28, 2026 16:24
Comment thread src/elgamal.iced Outdated

@AMarcedone AMarcedone left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changes make sense to me and match the formal algorithms descriptions.

Comment thread src/dsa.iced Outdated
Comment thread test/files/bn.iced

#=================================================================

exports.invalid_mod_inverse_returns_zero_when_gcd_is_not_one = (T, cb) ->

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

@michalz-zoom
michalz-zoom force-pushed the modinverse-rejections branch from 7124aa0 to 96f9726 Compare August 18, 2026 11:25
Comment thread src/elgamal.iced
ret = c[0].modPow(@x,p).modInverse(p).multiply(c[1]).mod(p)
cb null, ret
if ((c[0].signum() <= 0) or (c[0].compareTo(p) >= 0)) or
((c[1].signum() <= 0) or (c[1].compareTo(p) >= 0))

Copy link
Copy Markdown
Contributor Author

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? encrypt returns both values mod p so in principle honest ciphertext should be in that range

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