Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Large Prime Numbers with Py Crypto

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.

like image 998
winsticknova Avatar asked Feb 02 '16 21:02

winsticknova


People also ask

How are prime numbers generated in cryptography?

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.

How do I make a large prime number?

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.

How big are the prime numbers used in cryptography?

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.


1 Answers

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.

like image 165
Daffy Avatar answered Oct 18 '22 03:10

Daffy