Fix a bug in factorization function causing infinite loops in rare cases #450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a small bug in factorization function when it gets to factors above 10M and starts calling
pollard_rho
. If it can't find a factor usingf(x)=x^2+c (mod n)
withc==1
it is supposed to updatec
to some other random value. But initialization accidentally got in the loop body and would always resetc
back to1
.Since
pollard_rho
is only called to get factors larger than 10M at the point, and the fact thatc=1
usually works it is quite rare for this bug to surface, but in the rare case whenc=1
doesn't work it causes the infinite loop. Example would begalois.GF(2400610585866217)
which requires factorization of2400610585866217 - 1 = 2^3 * 3 * 100025441077759 = 2^3 * 3 * 10000537 * 10002007
.