10 int byte_size = bit_len / 8;
11 void * buffer = malloc(byte_size);
13 FILE * dev = fopen(
"/dev/urandom",
"r");
14 int read = fread(buffer, 1, byte_size, dev);
15 while(read < byte_size) {
16 read += fread(buffer + read, 1, byte_size - read, dev);
20 mpz_import(rop, byte_size, 1, 1, 0, 0, buffer);
23 assert(mpz_sizeinbase(rop, 2) <= bit_len);
27 assert(bit_len > 0 && random != NULL);
34 mpz_nextprime(rop, r);
35 size = mpz_sizeinbase(rop, 2);
36 }
while (size > bit_len);
39 assert(mpz_sizeinbase(rop, 2) <= bit_len && mpz_probab_prime_p(rop, 25));
void random_prime(mpz_t rop, int bit_len, random_fn random)
void random_dev(mpz_t rop, int bit_len)
void(* random_fn)(mpz_t rop, int bit_len)