Skip to content

Commit

Permalink
fixed stupid bug in safe prime test
Browse files Browse the repository at this point in the history
  • Loading branch information
opencoff committed Jun 1, 2019
1 parent 362fd5f commit d7f6334
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions prime.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ var smallPrimesProduct = new(big.Int).SetUint64(16294579238595022365)
// safePrime generates a safe prime; i.e., a prime 'p' such that 2p+1 is also prime.
func safePrime(bits int) (*big.Int, error) {

z := 0

p2 := new(big.Int)
a := new(big.Int)
for {
p, err := prime(bits)
if err != nil {
return nil, err
}
z++

// (p-1)/2 should also be prime
p2.Rsh(p, 1)
if p2.ProbablyPrime(20) {
// 2p+1
a = a.Lsh(p, 1)
a = a.Add(a, one)
if a.ProbablyPrime(20) {
return p, nil
}
}
Expand Down

0 comments on commit d7f6334

Please sign in to comment.