Use the new, faster way for generating safe primes everywhere
This commit is contained in:
1 file changed
+5
-11
@@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ZERO = big.NewInt(0)
|
var ZERO = big.NewInt(0)
|
||||||
@@ -22,18 +23,11 @@ func Factorial(n int) *big.Int {
|
|||||||
|
|
||||||
// Returns 2 primes such that p = 2 * q + 1 and that the length of
|
// Returns 2 primes such that p = 2 * q + 1 and that the length of
|
||||||
// p is nbits. `p` is called a safe prime
|
// p is nbits. `p` is called a safe prime
|
||||||
|
//
|
||||||
|
// Deprecated: This function has been left here just for backward compatibility.
|
||||||
|
// Please use `GenerateSafePrime` from the `safe_prime_generator.go` directly.
|
||||||
func GenerateSafePrimes(nbits int, random io.Reader) (p, q *big.Int, err error) {
|
func GenerateSafePrimes(nbits int, random io.Reader) (p, q *big.Int, err error) {
|
||||||
for {
|
return GenerateSafePrime(nbits, 4, 120*time.Second)
|
||||||
q, err = rand.Prime(random, nbits-1)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p = (new(big.Int)).Mul(q, big.NewInt(2))
|
|
||||||
p = p.Add(p, big.NewInt(1))
|
|
||||||
if p.ProbablyPrime(50) { //a probability of 2**-100 of not being prime
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a random element in the group of all the elements in Z/nZ that
|
// Generate a random element in the group of all the elements in Z/nZ that
|
||||||
|
|||||||
Reference in new issue
Block a user