3 * Command line tool for prime generation.
7 /* nettle, low-level cryptographics library
9 * Copyright (C) 2010 Niels Möller
11 * The nettle library is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or (at your
14 * option) any later version.
16 * The nettle library is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 * License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with the nettle library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
45 fprintf(stderr, "Usage: random-prime [OPTIONS] bits\n\n"
47 " --help Display this message.\n"
48 " -v, --verbose Display timing information.\n"
49 " -r, --random FILE Random data to use for seeding.\n");
53 main(int argc, char **argv)
57 struct yarrow256_ctx yarrow;
60 const char *random_file = NULL;
68 static const struct option options[] =
70 /* Name, args, flag, val */
71 { "help", no_argument, NULL, '?' },
72 { "verbose", no_argument, NULL, 'v' },
73 { "random", required_argument, NULL, 'r' },
77 while ( (c = getopt_long(argc, argv, "v?r:", options, NULL)) != -1)
102 bits = strtol(argv[0], &arg_end, 0);
103 if (*arg_end || bits < 0)
105 fprintf(stderr, "Invalid number.\n");
111 fprintf(stderr, "Bitsize must be at least 3.\n");
115 /* NOTE: No sources */
116 yarrow256_init(&yarrow, 0, NULL);
118 /* Read some data to seed the generator */
119 if (!simple_random(&yarrow, random_file))
121 werror("Initialization of randomness generator failed.\n");
129 nettle_random_prime(p, bits, 0,
130 &yarrow, (nettle_random_func *) yarrow256_random,
135 mpz_out_str(stdout, 10, p);
139 fprintf(stderr, "time: %.3g s\n",
140 (double)(end - start) / CLOCKS_PER_SEC);