Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: ModSqrt entered infinite loop with p == 1
Thanks to Eric Cornelissen for discovering and responsibly reporting this vulnerability. The problem was that our tonelliShanks algorithm needed to calculate the number of least significant zeros in p - 1. This was done by shifting right until the LSB becomes 1. With p == 1, this process never ends, because p - 1 == 0, sending us into an infinite loop. This could be a potential vulnerability, because if a modulus can be controlled by an adversary, they can cause a process to deadlock. The fix is to simply check if p == 1, and return 0 in that case, which makes perfect sense mathematically. Checking the value of the modulus is also fine from a leakage perspective, because ModSqrt is explicitly allowed to leak the value of the modulus. Co-authored-by: Eric Cornelissen <ericornelissen@gmail.com>
- Loading branch information