Skip to content

Commit 1a4eb51

Browse files
committed
Factor out RNG reseeding in to a single function.
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@
1 parent 8174618 commit 1a4eb51

File tree

4 files changed

+26
-35
lines changed

4 files changed

+26
-35
lines changed

entropy.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,24 @@ seed_rng(void)
108108
}
109109

110110
#endif /* WITH_OPENSSL */
111+
112+
void
113+
reseed_prngs(void)
114+
{
115+
u_int32_t rnd[256];
116+
117+
#ifdef WITH_OPENSSL
118+
RAND_poll();
119+
#endif
120+
arc4random_stir(); /* noop on recent arc4random() implementations */
121+
arc4random_buf(rnd, sizeof(rnd)); /* let arc4random notice PID change */
122+
123+
#ifdef WITH_OPENSSL
124+
RAND_seed(rnd, sizeof(rnd));
125+
/* give libcrypto a chance to notice the PID change */
126+
if ((RAND_bytes((u_char *)rnd, 1)) != 1)
127+
fatal_f("RAND_bytes failed");
128+
#endif
129+
130+
explicit_bzero(rnd, sizeof(rnd));
131+
}

entropy.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2323
*/
2424

25-
#ifndef _RANDOMS_H
26-
#define _RANDOMS_H
25+
#ifndef _ENTROPY_H
26+
#define _ENTROPY_H
2727

2828
struct sshbuf;
2929

3030
void seed_rng(void);
31-
void rexec_send_rng_seed(struct sshbuf *);
32-
void rexec_recv_rng_seed(struct sshbuf *);
31+
void reseed_prngs(void);
3332

34-
#endif /* _RANDOMS_H */
33+
#endif /* _ENTROPY_H */

sshd-session.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,6 @@ demote_sensitive_data(void)
262262
}
263263
}
264264

265-
static void
266-
reseed_prngs(void)
267-
{
268-
u_int32_t rnd[256];
269-
270-
#ifdef WITH_OPENSSL
271-
RAND_poll();
272-
#endif
273-
arc4random_stir(); /* noop on recent arc4random() implementations */
274-
arc4random_buf(rnd, sizeof(rnd)); /* let arc4random notice PID change */
275-
276-
#ifdef WITH_OPENSSL
277-
RAND_seed(rnd, sizeof(rnd));
278-
/* give libcrypto a chance to notice the PID change */
279-
if ((RAND_bytes((u_char *)rnd, 1)) != 1)
280-
fatal_f("RAND_bytes failed");
281-
#endif
282-
283-
explicit_bzero(rnd, sizeof(rnd));
284-
}
285-
286265
struct sshbuf *
287266
pack_hostkeys(void)
288267
{

sshd.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,6 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s,
922922
struct early_child *child;
923923
struct sshbuf *buf;
924924
socklen_t fromlen;
925-
u_char rnd[256];
926925
sigset_t nsigset, osigset;
927926

928927
/* 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,
12191218
* Ensure that our random state differs
12201219
* from that of the child
12211220
*/
1222-
arc4random_stir();
1223-
arc4random_buf(rnd, sizeof(rnd));
1224-
#ifdef WITH_OPENSSL
1225-
RAND_seed(rnd, sizeof(rnd));
1226-
if ((RAND_bytes((u_char *)rnd, 1)) != 1)
1227-
fatal_f("RAND_bytes failed");
1228-
#endif
1229-
explicit_bzero(rnd, sizeof(rnd));
1221+
reseed_prngs();
12301222
}
12311223
}
12321224
}

0 commit comments

Comments
 (0)