]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Factor out RNG reseeding in to a single function.
authorDarren Tucker <dtucker@dtucker.net>
Wed, 11 Feb 2026 22:36:42 +0000 (17:36 -0500)
committerDarren Tucker <dtucker@dtucker.net>
Wed, 11 Feb 2026 22:36:42 +0000 (17:36 -0500)
sshd and sshd-session both reseed the RNG after a fork.  Move the
existing reseed_prngs() function into entropy.c and use for both.
Clean up entropy.h too.  ok djm@

entropy.c
entropy.h
sshd-session.c
sshd.c

index 65ef922379a1d2121fb98f902bba779319ec200a..8bb3accbd3ad5e047d40a7273fd57a7138eb5510 100644 (file)
--- a/entropy.c
+++ b/entropy.c
@@ -108,3 +108,24 @@ seed_rng(void)
 }
 
 #endif /* WITH_OPENSSL */
+
+void
+reseed_prngs(void)
+{
+       u_int32_t rnd[256];
+
+#ifdef WITH_OPENSSL
+       RAND_poll();
+#endif
+       arc4random_stir(); /* noop on recent arc4random() implementations */
+       arc4random_buf(rnd, sizeof(rnd)); /* let arc4random notice PID change */
+
+#ifdef WITH_OPENSSL
+       RAND_seed(rnd, sizeof(rnd));
+       /* give libcrypto a chance to notice the PID change */
+       if ((RAND_bytes((u_char *)rnd, 1)) != 1)
+               fatal_f("RAND_bytes failed");
+#endif
+
+       explicit_bzero(rnd, sizeof(rnd));
+}
index 870164d30e90f18345c195cf4302749b135aa026..45d56a339363debcad0e8be9bd1b91fa08e60fba 100644 (file)
--- a/entropy.h
+++ b/entropy.h
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _RANDOMS_H
-#define _RANDOMS_H
+#ifndef _ENTROPY_H
+#define _ENTROPY_H
 
 struct sshbuf;
 
 void seed_rng(void);
-void rexec_send_rng_seed(struct sshbuf *);
-void rexec_recv_rng_seed(struct sshbuf *);
+void reseed_prngs(void);
 
-#endif /* _RANDOMS_H */
+#endif /* _ENTROPY_H */
index d8dfc7432cf06980eab8143bd2e1e63d1375456c..29de97fa619ace7461aa6df5cfefd57707136555 100644 (file)
@@ -262,27 +262,6 @@ demote_sensitive_data(void)
        }
 }
 
-static void
-reseed_prngs(void)
-{
-       u_int32_t rnd[256];
-
-#ifdef WITH_OPENSSL
-       RAND_poll();
-#endif
-       arc4random_stir(); /* noop on recent arc4random() implementations */
-       arc4random_buf(rnd, sizeof(rnd)); /* let arc4random notice PID change */
-
-#ifdef WITH_OPENSSL
-       RAND_seed(rnd, sizeof(rnd));
-       /* give libcrypto a chance to notice the PID change */
-       if ((RAND_bytes((u_char *)rnd, 1)) != 1)
-               fatal_f("RAND_bytes failed");
-#endif
-
-       explicit_bzero(rnd, sizeof(rnd));
-}
-
 struct sshbuf *
 pack_hostkeys(void)
 {
diff --git a/sshd.c b/sshd.c
index 0bea8892763e79e9a46341506c33c6b77bb93373..74d25fc73fbe46eb4c105506b64d39e49229e26d 100644 (file)
--- a/sshd.c
+++ b/sshd.c
@@ -922,7 +922,6 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s,
        struct early_child *child;
        struct sshbuf *buf;
        socklen_t fromlen;
-       u_char rnd[256];
        sigset_t nsigset, osigset;
 
        /* pipes connected to unauthenticated child sshd processes */
@@ -1219,14 +1218,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s,
                         * Ensure that our random state differs
                         * from that of the child
                         */
-                       arc4random_stir();
-                       arc4random_buf(rnd, sizeof(rnd));
-#ifdef WITH_OPENSSL
-                       RAND_seed(rnd, sizeof(rnd));
-                       if ((RAND_bytes((u_char *)rnd, 1)) != 1)
-                               fatal_f("RAND_bytes failed");
-#endif
-                       explicit_bzero(rnd, sizeof(rnd));
+                       reseed_prngs();
                }
        }
 }