Download CUDAMCML - Atomic Physics

Transcript
While the Miller-Rabin primality test is probabilistic certain measures can be taken to make
sure the primes found are true primes. [13] (http://www.trnicely.net/misc/mpzspsp.html) provides
an analysis of the pseudo-prime problem of the Miller-Rabin algorithm, and the GNU GMP implementation in particular. It is shown that for numbers representable by a 64-bit unsigned integer
(< 264 ) the problem of pseudoprimes can be completely eliminated using a Miller-Rabin test of
order 13 or greater, that is, use the bases 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 and 41.
The Miller-Rabin test was used to find 150000 good multipliers a < 232 (base b = 232 ). The
results were stored in a file, safeprimes_base32.txt in ASCII format, provided along with the
CUDAMCML program. Each line of this file contains three numbers; first the multiplier a followed
by the two primes, a × b − 1 and (a × b − 2)/2. The reason for this format, is compatibility with the
list (and WMC implementation) by Steven Gratton [10]. Gratton also provides a list of suitable
multipliers, but this list only contains 16028 entries which are exactly the 16028 first entries in
safeprimes_base32.txt. While this makes the list file unnecessarily large, this will allow anyone
to verify the multipliers and their corresponding primes.
The program for finding the multipliers is provided below (Assuming the GNU GMP libraries
are properly installed):
#include
#include
#include
#include
<stdlib.h>
<string.h>
<stdio.h>
"gmp.h"
int main()
{
FILE* file;
mpz_t n1,n2,a;
unsigned long long i=0;
mpz_init(n1);
mpz_init(n2);
mpz_init(a);
mpz_set_str(a,"4294967118",0);
file = fopen("safeprimes_base32.txt","w");
while(i<150000)
{
mpz_mul_2exp(n2,a,32);
mpz_sub_ui(n2,n2,1lu);
if(isprime(n2))
{
mpz_sub_ui(n1,n2,1lu);
mpz_fdiv_q_2exp(n1,n1,1lu);
if(isprime(n1))
{
//We have found our safeprime, calculate a and print to file
mpz_out_str (file, 10, a);
27