BigInt icon indicating copy to clipboard operation
BigInt copied to clipboard

README's `generatePrime(_ width: Int)` performances

Open nathanfallet opened this issue 4 years ago • 1 comments

The README's generatePrime(_ width: Int) function is very slow for big numbers (can take up to 10s to generate two primes for a RSA key)

func generatePrime(_ width: Int) -> BigUInt {
    while true {
        var random = BigUInt.randomInteger(withExactWidth: width)
        random |= BigUInt(1)
        if random.isPrime() {
            return random
        }
    }
}

Any way to generate primes quicker?

nathanfallet avatar Aug 28 '21 15:08 nathanfallet

The generatePrime(2048) method also take up to a few minutes to generate prime numbers for Paillier Homomorphic Encryption PrivateKey

kecson avatar Nov 15 '22 02:11 kecson