diff --git a/ChangeLog b/ChangeLog
index e1a0d6f5329bec8c45a95361d3674a4f60b6bef6..9f651ccba9c652100a33e738666a90a6061dc878 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 eec7fd5ad617e13bbb419763069c31e96a471038..b46239e251667b75581e72ef51941c68cb5c0ad2 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;