+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
#include "getopt.h"
-#define KEYSIZE 900
+#define DEFAULT_KEYSIZE 2048
#define ESIZE 30
static void
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)
{
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[] =
{
{ 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;
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;
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;