diff options
Diffstat (limited to 'entropy.c')
-rw-r--r-- | entropy.c | 38 |
1 files changed, 33 insertions, 5 deletions
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <openssl/rand.h> | 27 | #include <openssl/rand.h> |
28 | #include <openssl/crypto.h> | 28 | #include <openssl/crypto.h> |
29 | #include <openssl/err.h> | ||
29 | 30 | ||
30 | #include "ssh.h" | 31 | #include "ssh.h" |
31 | #include "misc.h" | 32 | #include "misc.h" |
@@ -33,6 +34,8 @@ | |||
33 | #include "atomicio.h" | 34 | #include "atomicio.h" |
34 | #include "pathnames.h" | 35 | #include "pathnames.h" |
35 | #include "log.h" | 36 | #include "log.h" |
37 | #include "buffer.h" | ||
38 | #include "bufaux.h" | ||
36 | 39 | ||
37 | /* | 40 | /* |
38 | * Portable OpenSSH PRNG seeding: | 41 | * Portable OpenSSH PRNG seeding: |
@@ -45,7 +48,7 @@ | |||
45 | * XXX: we should tell the child how many bytes we need. | 48 | * XXX: we should tell the child how many bytes we need. |
46 | */ | 49 | */ |
47 | 50 | ||
48 | RCSID("$Id: entropy.c,v 1.49 2005/07/17 07:26:44 djm Exp $"); | 51 | RCSID("$Id: entropy.c,v 1.52 2005/09/27 22:26:30 dtucker Exp $"); |
49 | 52 | ||
50 | #ifndef OPENSSL_PRNG_ONLY | 53 | #ifndef OPENSSL_PRNG_ONLY |
51 | #define RANDOM_SEED_SIZE 48 | 54 | #define RANDOM_SEED_SIZE 48 |
@@ -148,10 +151,35 @@ init_rng(void) | |||
148 | #endif | 151 | #endif |
149 | 152 | ||
150 | #ifndef OPENSSL_PRNG_ONLY | 153 | #ifndef OPENSSL_PRNG_ONLY |
151 | if ((original_uid = getuid()) == -1) | 154 | original_uid = getuid(); |
152 | fatal("getuid: %s", strerror(errno)); | 155 | original_euid = geteuid(); |
153 | if ((original_euid = geteuid()) == -1) | ||
154 | fatal("geteuid: %s", strerror(errno)); | ||
155 | #endif | 156 | #endif |
156 | } | 157 | } |
157 | 158 | ||
159 | #ifndef OPENSSL_PRNG_ONLY | ||
160 | void | ||
161 | rexec_send_rng_seed(Buffer *m) | ||
162 | { | ||
163 | u_char buf[RANDOM_SEED_SIZE]; | ||
164 | |||
165 | if (RAND_bytes(buf, sizeof(buf)) <= 0) { | ||
166 | error("Couldn't obtain random bytes (error %ld)", | ||
167 | ERR_get_error()); | ||
168 | buffer_put_string(m, "", 0); | ||
169 | } else | ||
170 | buffer_put_string(m, buf, sizeof(buf)); | ||
171 | } | ||
172 | |||
173 | void | ||
174 | rexec_recv_rng_seed(Buffer *m) | ||
175 | { | ||
176 | u_char *buf; | ||
177 | u_int len; | ||
178 | |||
179 | buf = buffer_get_string_ret(m, &len); | ||
180 | if (buf != NULL) { | ||
181 | debug3("rexec_recv_rng_seed: seeding rng with %u bytes", len); | ||
182 | RAND_add(buf, len, len); | ||
183 | } | ||
184 | } | ||
185 | #endif | ||