summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2013-02-14 11:31:22 +0100
committerNiels Möller <nisse@lysator.liu.se>2013-02-14 11:31:22 +0100
commit42397bc9a7d749ed27fd18d9b067954397393749 (patch)
tree353cfead78ada50f7cb3ff82e953e8f969480004
parent39c037437d8807e2660baabe766fa391fa762a52 (diff)
downloadnettle-42397bc9a7d749ed27fd18d9b067954397393749.tar.gz
Added -s and -e options to examples/rsa-keygen.
-rw-r--r--ChangeLog6
-rw-r--r--examples/rsa-keygen.c38
2 files changed, 40 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index e1a0d6f5..9f651ccb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/examples/rsa-keygen.c b/examples/rsa-keygen.c
index eec7fd5a..b46239e2 100644
--- a/examples/rsa-keygen.c
+++ b/examples/rsa-keygen.c
@@ -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;