Commit 42397bc9 authored by Niels Möller's avatar Niels Möller

Added -s and -e options to examples/rsa-keygen.

parent 39c03743
2013-02-14 Niels Möller <nisse@lysator.liu.se>
* examples/rsa-keygen.c (uint_arg): New function.
(main): New options -s and -e, to specify key size and public
exponent. Increased default key size to 2048.
2013-02-12 Niels Möller <nisse@lysator.liu.se>
* armv7/memxor.asm (memxor): Optimized aligned case, using 3-way
......
......@@ -41,7 +41,7 @@
#include "getopt.h"
#define KEYSIZE 900
#define DEFAULT_KEYSIZE 2048
#define ESIZE 30
static void
......@@ -51,6 +51,22 @@ progress(void *ctx, int c)
fputc(c, stderr);
}
static unsigned long
uint_arg (char c, const char *arg)
{
unsigned long val;
char *end;
val = strtoul(arg, &end, 0);
if (*arg == '\0' || *end != '\0')
{
werror ("Invalid integer argument for -%c option.\n", c);
exit (EXIT_FAILURE);
}
return val;
}
int
main(int argc, char **argv)
{
......@@ -66,6 +82,9 @@ main(int argc, char **argv)
struct nettle_buffer pub_buffer;
struct nettle_buffer priv_buffer;
unsigned long key_size = DEFAULT_KEYSIZE;
unsigned long key_e = 0;
enum { OPT_HELP = 300 };
static const struct option options[] =
{
......@@ -75,9 +94,9 @@ main(int argc, char **argv)
{ NULL, 0, NULL, 0}
};
while ( (c = getopt_long(argc, argv, "o:r:", options, NULL)) != -1)
while ( (c = getopt_long(argc, argv, "o:r:e:s:", options, NULL)) != -1)
switch (c)
{
{
case 'o':
priv_name = optarg;
break;
......@@ -86,6 +105,14 @@ main(int argc, char **argv)
random_name = optarg;
break;
case 's':
key_size = uint_arg ('s', optarg);
break;
case 'e':
key_e = uint_arg ('e', optarg);
break;
case OPT_HELP:
printf("FIXME: Usage information.\n");
return EXIT_SUCCESS;
......@@ -119,11 +146,14 @@ main(int argc, char **argv)
rsa_public_key_init(&pub);
rsa_private_key_init(&priv);
if (key_e)
mpz_set_ui (pub.e, key_e);
if (!rsa_generate_keypair
(&pub, &priv,
(void *) &yarrow, (nettle_random_func *) yarrow256_random,
NULL, progress,
KEYSIZE, ESIZE))
key_size, key_e == 0 ? ESIZE : 0))
{
werror("Key generation failed.\n");
return EXIT_FAILURE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment