summaryrefslogtreecommitdiff
path: root/rsa.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-01-29 20:40:22 +1100
committerDamien Miller <djm@mindrot.org>2000-01-29 20:40:22 +1100
commitf07390e90da683fecbf55849a3cee6dc9b79a3e3 (patch)
treec9c7ad28557e08ff024da1e9a5302fc78d4de4f7 /rsa.c
parent4e61b79d5bcb3c5ac3014fe55be55214e23b2927 (diff)
- Seed OpenSSL's random number generator before generating RSA keypairs
- Split random collector into seperate file
Diffstat (limited to 'rsa.c')
-rw-r--r--rsa.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/rsa.c b/rsa.c
index 5e7297be0..597d20fb8 100644
--- a/rsa.c
+++ b/rsa.c
@@ -35,11 +35,12 @@
35*/ 35*/
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$Id: rsa.c,v 1.6 1999/12/17 03:02:47 damien Exp $"); 38RCSID("$Id: rsa.c,v 1.7 2000/01/29 09:40:22 damien Exp $");
39 39
40#include "rsa.h" 40#include "rsa.h"
41#include "ssh.h" 41#include "ssh.h"
42#include "xmalloc.h" 42#include "xmalloc.h"
43#include "random.h"
43 44
44int rsa_verbose = 1; 45int rsa_verbose = 1;
45 46
@@ -64,13 +65,26 @@ keygen_progress(int p, int n, void *arg)
64 const char progress_chars[] = ".o+O?"; 65 const char progress_chars[] = ".o+O?";
65 66
66 if ((p < 0) || (p > (sizeof(progress_chars) - 2))) 67 if ((p < 0) || (p > (sizeof(progress_chars) - 2)))
67 p = 4; 68 p = sizeof(progress_chars) - 2;
68 69
69 printf("%c", progress_chars[p]); 70 putchar(progress_chars[p]);
70 fflush(stdout); 71 fflush(stdout);
71} 72}
72 73
73/* 74/*
75 * Seed OpenSSL's random number generator
76 */
77void
78seed_rng()
79{
80 char buf[32];
81
82 get_random_bytes(buf, sizeof(buf));
83 RAND_seed(buf, sizeof(buf));
84 memset(buf, 0, sizeof(buf));
85}
86
87/*
74 * Generates RSA public and private keys. This initializes the data 88 * Generates RSA public and private keys. This initializes the data
75 * structures; they should be freed with rsa_clear_private_key and 89 * structures; they should be freed with rsa_clear_private_key and
76 * rsa_clear_public_key. 90 * rsa_clear_public_key.
@@ -81,6 +95,8 @@ rsa_generate_key(RSA *prv, RSA *pub, unsigned int bits)
81{ 95{
82 RSA *key; 96 RSA *key;
83 97
98 seed_rng();
99
84 if (rsa_verbose) { 100 if (rsa_verbose) {
85 printf("Generating RSA keys: "); 101 printf("Generating RSA keys: ");
86 fflush(stdout); 102 fflush(stdout);