summaryrefslogtreecommitdiff
path: root/entropy.c
diff options
context:
space:
mode:
Diffstat (limited to 'entropy.c')
-rw-r--r--entropy.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/entropy.c b/entropy.c
index 14b98f188..c178c00cf 100644
--- a/entropy.c
+++ b/entropy.c
@@ -53,7 +53,8 @@
53#include "atomicio.h" 53#include "atomicio.h"
54#include "pathnames.h" 54#include "pathnames.h"
55#include "log.h" 55#include "log.h"
56#include "buffer.h" 56#include "sshbuf.h"
57#include "ssherr.h"
57 58
58/* 59/*
59 * Portable OpenSSH PRNG seeding: 60 * Portable OpenSSH PRNG seeding:
@@ -181,29 +182,34 @@ seed_from_prngd(unsigned char *buf, size_t bytes)
181} 182}
182 183
183void 184void
184rexec_send_rng_seed(Buffer *m) 185rexec_send_rng_seed(struct sshbuf *m)
185{ 186{
186 u_char buf[RANDOM_SEED_SIZE]; 187 u_char buf[RANDOM_SEED_SIZE];
188 size_t len = sizeof(buf);
189 int r;
187 190
188 if (RAND_bytes(buf, sizeof(buf)) <= 0) { 191 if (RAND_bytes(buf, sizeof(buf)) <= 0) {
189 error("Couldn't obtain random bytes (error %ld)", 192 error("Couldn't obtain random bytes (error %ld)",
190 ERR_get_error()); 193 ERR_get_error());
191 buffer_put_string(m, "", 0); 194 len = 0;
192 } else 195 }
193 buffer_put_string(m, buf, sizeof(buf)); 196 if ((r = sshbuf_put_string(m, buf, len)) != 0)
197 fatal("%s: buffer error: %s", __func__, ssh_err(r));
198 explicit_bzero(buf, sizeof(buf));
194} 199}
195 200
196void 201void
197rexec_recv_rng_seed(Buffer *m) 202rexec_recv_rng_seed(struct sshbuf *m)
198{ 203{
199 u_char *buf; 204 u_char *buf = NULL;
200 u_int len; 205 size_t len = 0;
206 int r;
201 207
202 buf = buffer_get_string_ret(m, &len); 208 if ((r = sshbuf_get_string_direct(m, &buf, &len)) != 0
203 if (buf != NULL) { 209 fatal("%s: buffer error: %s", __func__, ssh_err(r));
204 debug3("rexec_recv_rng_seed: seeding rng with %u bytes", len); 210
205 RAND_add(buf, len, len); 211 debug3("rexec_recv_rng_seed: seeding rng with %u bytes", len);
206 } 212 RAND_add(buf, len, len);
207} 213}
208#endif /* OPENSSL_PRNG_ONLY */ 214#endif /* OPENSSL_PRNG_ONLY */
209 215