]> andersk Git - openssh.git/blobdiff - rsa.c
Update version
[openssh.git] / rsa.c
diff --git a/rsa.c b/rsa.c
index a802e593fab7af9da46790823c1c44ba3bbfa73e..8db61a9be39f876229f339cefb40bd1900cca3fc 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -40,14 +40,29 @@ RCSID("$Id$");
 #include "rsa.h"
 #include "ssh.h"
 #include "xmalloc.h"
+#include "random.h"
 
 int rsa_verbose = 1;
 
+/*
+ * Seed OpenSSL's random number generator
+ */
+void
+seed_rng()
+{
+       char buf[64];
+
+       get_random_bytes(buf, sizeof(buf));
+       RAND_seed(buf, sizeof(buf));
+       memset(buf, 0, sizeof(buf));
+}
+
 int
 rsa_alive()
 {
        RSA *key;
 
+       seed_rng();
        key = RSA_generate_key(32, 3, NULL, NULL);
        if (key == NULL)
                return (0);
@@ -55,20 +70,42 @@ rsa_alive()
        return (1);
 }
 
-/* Generates RSA public and private keys.  This initializes the data
-   structures; they should be freed with rsa_clear_private_key and
-   rsa_clear_public_key. */
+/*
+ * Key generation progress meter callback
+ */
+void
+keygen_progress(int p, int n, void *arg)
+{
+       const char progress_chars[] = ".o+O?";
+
+       if ((p < 0) || (p > (sizeof(progress_chars) - 2)))
+               p = sizeof(progress_chars) - 2;
+
+       putchar(progress_chars[p]);
+       fflush(stdout);
+}
+
+/*
+ * Generates RSA public and private keys.  This initializes the data
+ * structures; they should be freed with rsa_clear_private_key and
+ * rsa_clear_public_key.
+ */
 
 void
 rsa_generate_key(RSA *prv, RSA *pub, unsigned int bits)
 {
        RSA *key;
 
+       seed_rng();
+       
        if (rsa_verbose) {
                printf("Generating RSA keys:  ");
                fflush(stdout);
+               key = RSA_generate_key(bits, 35, keygen_progress, NULL);
+               printf("\n");
+       } else {
+               key = RSA_generate_key(bits, 35, NULL, NULL);
        }
-       key = RSA_generate_key(bits, 35, NULL, NULL);
        if (key == NULL)
                fatal("rsa_generate_key: key generation failed.");
 
This page took 0.038008 seconds and 4 git commands to generate.