Skip to content
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

Valid signature rejection not that negligible and possibly exploitable #39

Open
veorq opened this issue Mar 16, 2022 · 2 comments
Open

Comments

@veorq
Copy link

veorq commented Mar 16, 2022

crypto.signature.signature.verify() rejects signatures with an r, inverse s, or message (hash) greater than 2**251 < EC_ORDER:

assert 1 <= r < 2 ** N_ELEMENT_BITS_ECDSA, "r = %s" % r
assert 1 <= w < 2 ** N_ELEMENT_BITS_ECDSA, "w = %s" % w
assert 0 <= msg_hash < 2 ** N_ELEMENT_BITS_ECDSA, "msg_hash = %s" % msg_hash

There's a gap of ~2^196 values, thus a probability to hit an invalid r or s that is of the order of 2^(196-251)/2 = 2^-54, when generating an ECDSA sig for some fixed message using a standard algorithm (rather than Cairo's sign(), which enforces these constraints).

I can't think of a specific attack scenario at the moment, but I would expect to find applications where either

  1. that accidental failure rate would be unacceptably high, or
  2. adversaries could bruteforce invalid sigs to do some kind of DoS, or worse (with plausible deniability)

I probably miss some of the context, and you may have a good reason to verify sigs that way.

@veorq
Copy link
Author

veorq commented Apr 20, 2022

Any thoughts on this?

@JameWade
Copy link

Why is there no official reply to this question?I think is a good question

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

No branches or pull requests

2 participants