50int randomize(
unsigned char *buf,
size_t len);
61int main(
int argc,
char *argv[]) {
70 while ((opt = getopt(argc, argv,
"s")) != EOF) {
77 fprintf(stderr,
"Usage: randprime [-s] <bits> [<outfile>]\n");
84 "Error: You must specify the number of significant bits.\n");
85 fprintf(stderr,
"Usage: randprime [-s] <bits> [<outfile>]\n");
88 modbits = (int)strtol(argv[optind++], NULL, 0);
89 if (modbits < CHAR_BIT) {
90 fprintf(stderr,
"Error: Invalid value for number of significant bits.\n");
93 if (modbits % 2 == 1) ++modbits;
97 if ((ofp = fopen(argv[optind],
"wt")) == NULL) {
99 "Error: Unable to open output file for writing.\n"
102 argv[optind], strerror(errno));
110 "Error: Unable to generate random start value.\n"
115 fprintf(stderr,
"%c: ",
tag);
116 find_func(&value, stderr);
140 FILE *rnd = fopen(
"/dev/random",
"rb");
143 if (rnd == NULL)
return -1;
145 nr = fread(buf,
sizeof(*buf), len, rnd);
152 mp_size n_bytes = (n_bits + CHAR_BIT - 1) / CHAR_BIT;
156 if ((buf = malloc(n_bytes)) == NULL)
return MP_MEMORY;
164 if (n_bits % CHAR_BIT != 0) {
165 unsigned char b_mask = (1 << (n_bits % CHAR_BIT)) - 1;
166 unsigned char t_mask = (1 << (n_bits % CHAR_BIT)) >> 1;
173 buf[n_bytes - 1] |= 1;
178 memset(buf, 0, n_bytes);
197 if (fb != NULL && (
count % 50) == 0) {
205 if (
res ==
MP_TRUE && fb != NULL) fputc(
'+', fb);
225 if (fb != NULL) fputc(
'!', fb);
232 if (fb != NULL) fputc(
'x', fb);
static __isl_give isl_map * tag(__isl_take isl_map *Relation, __isl_take isl_id *TagId)
Tag the Relation domain with TagId.
static bool mp_int_is_even(mp_int z)
Reports whether z is even, having remainder 0 when divided by 2.
mp_result mp_int_is_prime(mp_int z)
static int count(int *con, unsigned len, int status)
int randomize(unsigned char *buf, size_t len)
mp_result find_strong_prime(mp_int seed, FILE *fb)
mp_result mp_int_randomize(mp_int a, mp_size n_bits)
mp_result find_prime(mp_int seed, FILE *fb)
mp_result(* find_f)(mp_int, FILE *)
#define mp_int_string_len
#define mp_int_read_unsigned