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

math/big: infinite loop in Int.ModSqrt for p = 1 #51747

Open
sylvainpelissier opened this issue Mar 17, 2022 · 5 comments
Open

math/big: infinite loop in Int.ModSqrt for p = 1 #51747

sylvainpelissier opened this issue Mar 17, 2022 · 5 comments
Labels
NeedsInvestigation
Milestone

Comments

@sylvainpelissier
Copy link

@sylvainpelissier sylvainpelissier commented Mar 17, 2022

When passing p=1 in ModSqrt function, the code goes in infinite loop:

for Jacobi(&n, p) != -1 {

The Jacobi symbol will gives one for ever.

For example: https://go.dev/play/p/37ExZ6Y-Hdp

@ALTree ALTree changed the title Possible infinite loop in Tonelli–Shanks algorithm math/big: infinite loop in Int.ModSqrt for p = 1 Mar 17, 2022
@ALTree ALTree added the NeedsInvestigation label Mar 17, 2022
@ALTree ALTree added this to the Go1.19 milestone Mar 17, 2022
@ALTree
Copy link
Member

@ALTree ALTree commented Mar 17, 2022

It does indeed go into an infinite loop. Thanks for reporting.

The method's documentation says

The modulus p must be an odd prime.

and 1 is not a prime, but going into an infinite loop is still not the best way to handle an invalid parameter.

@ALTree
Copy link
Member

@ALTree ALTree commented Mar 17, 2022

cc @griesemer @FiloSottile as per owners.

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 21, 2022

Change https://go.dev/cl/394077 mentions this issue: math/big: infinite loop in Int.ModSqrt for p = 1

@hopehook
Copy link
Contributor

@hopehook hopehook commented Apr 5, 2022

Other examples of causing infinite loop in Int.ModSqrt:

  • p = -1
  • p = -9
  • p = 9

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 27, 2022

Change https://go.dev/cl/402457 mentions this issue: math/big: limit search for non-square in ModSqrt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

4 participants