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

big.ProbablyPrime returns false negatives #638

Closed
petar opened this issue Mar 3, 2010 · 7 comments
Closed

big.ProbablyPrime returns false negatives #638

petar opened this issue Mar 3, 2010 · 7 comments

Comments

@petar
Copy link
Contributor

petar commented Mar 3, 2010

Please read the end of this thread for background:

http://groups.google.com/group/golang-nuts/browse_thread/thread/acc7cc246ed79a78

What steps will reproduce the problem?

We've concluded that RSA key generation in GO is bad.
It takes 30 seconds (with a wide variance) for keys of 700bits.
This happens regardless of the random sources used:
RC4-based stream, /dev/random, or from package rand.Rand

What is the expected output? What do you see instead?

Under 1sec generation time.

What is your $GOOS?  $GOARCH?

darwin, amd64

Which revision are you using?  (hg identify)
b7663925130c+ tip

Please provide any additional information below.

It is suggested that Plan9's RSA generator should be 
the underlying implementation. Supposedly it runs in 0.1sec
for the same task.
@rsc
Copy link
Contributor

rsc commented Mar 4, 2010

Comment 1:

->agl for a closer look, if you have time.
Looks like this could be the root cause:
big.ProbablyPrime(18699199384836356663) = false, should be true.
---
package main
import "big"
func main() {
    z := big.NewInt(0)
    z.SetString("18699199384836356663", 10)
    println(z.String())
    println(big.ProbablyPrime(z, 20))  // prints false, both 8g and 6g
}
---
http://www.wolframalpha.com/input/?i=18699199384836356663
says that it is prime.

Labels changed: added packagebug.

Owner changed to a...@golang.org.

Status changed to Accepted.

@agl
Copy link
Contributor

agl commented Mar 4, 2010

Comment 2:

Noted that it's slow. On TODO list.

@mirtchovski
Copy link
Contributor

Comment 3:

I believe the slowness could be due to the incorrectness of the algorithm. I have a 
couple of examples in the 648-bit space where it takes 108k tries before a random 
is reached (all-in-all covering 216000 different numbers); another, in the 66-bit 
space and using the incremental algorithm, fails to find a prime in at least the 
12,630,912 numbers between 18699199384836273063 and 
18699199384848903975. 
p9p's probable_prime finds 4225 primes within that slice, and wolfram alpha 
confirms at least a dozen of (somewhat) random sampled finds from there.
let me know if you want the file with the odd numbers (stepping of 4) of that slice for 
testing.

@rsc
Copy link
Contributor

rsc commented Mar 4, 2010

Comment 4:

Right, the issue is that ProbablyPrime is returning false negatives.
Details in comment #1.

@mirtchovski
Copy link
Contributor

Comment 5:

sorry, i was originally responding to comment #2 above mine, which came a little bit 
later than your #1 so i thought i'd make sure the ProbablePrime issue was emphasized.

@agl
Copy link
Contributor

agl commented Mar 5, 2010

Comment 6:

(removing the RSA speed from consideration)
There were a couple of issues with probablyPrime. I've written a couple of test
programs that use GMP to verify ProbablyPrime and they've now run for several million
iterations of 512 bit numbers with no problems.
CL coming in a sec.

Attachments:

  1. driver.c (1735 bytes)
  2. t.go (324 bytes)

@agl
Copy link
Contributor

agl commented Mar 5, 2010

Comment 7:

This issue was closed by revision 308064f.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants