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., 51 Franklin Street, Fifth Floor, 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 enum { OPT_HELP
= 300 };
69 static const struct option options
[] =
71 /* Name, args, flag, val */
72 { "help", no_argument
, NULL
, OPT_HELP
},
73 { "verbose", no_argument
, NULL
, 'v' },
74 { "random", required_argument
, NULL
, 'r' },
78 while ( (c
= getopt_long(argc
, argv
, "vr:", options
, NULL
)) != -1)
105 bits
= strtol(argv
[0], &arg_end
, 0);
106 if (*arg_end
|| bits
< 0)
108 fprintf(stderr
, "Invalid number.\n");
114 fprintf(stderr
, "Bitsize must be at least 3.\n");
118 /* NOTE: No sources */
119 yarrow256_init(&yarrow
, 0, NULL
);
121 /* Read some data to seed the generator */
122 if (!simple_random(&yarrow
, random_file
))
124 werror("Initialization of randomness generator failed.\n");
132 nettle_random_prime(p
, bits
, 0,
133 &yarrow
, (nettle_random_func
*) yarrow256_random
,
138 mpz_out_str(stdout
, 10, p
);
142 fprintf(stderr
, "time: %.3g s\n",
143 (double)(end
- start
) / CLOCKS_PER_SEC
);