I'm trying to generate a large prime number (2048 bits) using the crypto library in python in order to implement RSA. However, I do not really understand the syntax of the getPrime()
function. I currently have:
from Crypto.Util import number
n_length = 2048
primeNum = number.getPrime(n_length, randFunc)
I don't understand what the randFunc
is supposed to be in the getPrime
function.
For the large primes used in cryptography, provable primes can be generated based on variants of Pocklington primality test, while probable primes can be generated with probabilistic primality tests such as the Baillie–PSW primality test or the Miller–Rabin primality test.
Large Prime Generation Procedure:Ensure the chosen number is not divisible by the first few hundred primes (these are pre-generated) Apply a certain number of Rabin Miller Primality Test iterations, based on acceptable error rate, to get a number which is probably a prime.
Cryptographic algorithms often prescribe the use of primes whose length in bits is a power of 2. Recently, we proved that for m > 1, there is no prime number with 2m significant bits, exactly two of which are 0 bits.
n_length
is the "size" of the prime number. It will return a number around 2^n_length. randFunc
is a callable function that accepts a single argument N and then returns a string of N random bytes. (os.urandom
is an example of this). In most cases, randFunc
can (and should) be omitted, since the default is PyCrypto's own random number generator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With