What's the industry standard for an efficient finding large Sophie Germain primes?
As a part of request handling in my application, I need to generate Paillier key.
My current approach is to generate a pseudorandom probably prime number q
backed up by Miller-Rabin test, then setting p = 2q + 1
and checking if p
is also prime with Miller-Rabin and Baillie-PSW. This is repeated until p
is prime.
loop {
q <- randomPrime(nbits - 1) // generates probably prime number,
// performs Miller-Rabin tests on the result
p = 2q + 1
return if isPrime(p) //applying the Miller-Rabin & Baillie-PSW tests
}
For nbits = 1024
one loop step takes about 100ms on my laptop. Not that bad, but in order to find desired p
and q
I need to execute several loop steps. The best result so far was 156 retries (~16s), the worst one was 1616 retries (~160s).
It's a way above required latency so I wonder what's considered the correct approach nowadays.
2^{p-1} ≡ 1 (mod n)
instead of running expensiveisPrime(p)
? $\endgroup$