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 · 6 comments
Open

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

sylvainpelissier opened this issue Mar 17, 2022 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@sylvainpelissier
Copy link

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 17, 2022
@ALTree ALTree added this to the Go1.19 milestone Mar 17, 2022
@ALTree
Copy link
Member

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 commented Mar 17, 2022

cc @griesemer @FiloSottile as per owners.

@gopherbot
Copy link

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

@hopehook
Copy link
Member

hopehook commented Apr 5, 2022

Other examples of causing infinite loop in Int.ModSqrt:

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

@gopherbot
Copy link

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

@ianlancetaylor
Copy link
Contributor

Rolling forward to 1.20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: No status
Development

No branches or pull requests

5 participants