]> andersk Git - gssapi-openssh.git/blobdiff - openssh/entropy.c
Import of OpenSSH 4.3p1
[gssapi-openssh.git] / openssh / entropy.c
index 5e73495dde20416177b4eff669819a73db99f5f9..fc90c51aa70bcebf467a92f776fbf9c4d3b01138 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <openssl/rand.h>
 #include <openssl/crypto.h>
+#include <openssl/err.h>
 
 #include "ssh.h"
 #include "misc.h"
@@ -33,6 +34,8 @@
 #include "atomicio.h"
 #include "pathnames.h"
 #include "log.h"
+#include "buffer.h"
+#include "bufaux.h"
 
 /*
  * Portable OpenSSH PRNG seeding:
@@ -145,10 +148,35 @@ init_rng(void)
                    "have %lx", OPENSSL_VERSION_NUMBER, SSLeay());
 
 #ifndef OPENSSL_PRNG_ONLY
-       if ((original_uid = getuid()) == -1)
-               fatal("getuid: %s", strerror(errno));
-       if ((original_euid = geteuid()) == -1)
-               fatal("geteuid: %s", strerror(errno));
+       original_uid = getuid();
+       original_euid = geteuid();
 #endif
 }
 
+#ifndef OPENSSL_PRNG_ONLY
+void
+rexec_send_rng_seed(Buffer *m)
+{
+       u_char buf[RANDOM_SEED_SIZE];
+
+       if (RAND_bytes(buf, sizeof(buf)) <= 0) {
+               error("Couldn't obtain random bytes (error %ld)",
+                   ERR_get_error());
+               buffer_put_string(m, "", 0);
+       } else 
+               buffer_put_string(m, buf, sizeof(buf));
+}
+
+void
+rexec_recv_rng_seed(Buffer *m)
+{
+       u_char *buf;
+       u_int len;
+
+       buf = buffer_get_string_ret(m, &len);
+       if (buf != NULL) {
+               debug3("rexec_recv_rng_seed: seeding rng with %u bytes", len);
+               RAND_add(buf, len, len);
+       }
+}
+#endif
This page took 0.030316 seconds and 4 git commands to generate.