From 555470a31d581f8b655cc2bbf2366e941f036f56 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Sat, 14 May 2016 01:12:23 +0000 Subject: [PATCH] timed(8): Use stronger random number generator. Using arc4random simplifies the code by not having to worry about seeds which ironically depend on the time. CID: 1300004 --- usr.sbin/timed/timed/timed.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/usr.sbin/timed/timed/timed.c b/usr.sbin/timed/timed/timed.c index 37e5607d4b87..2ac2b42fa6c4 100644 --- a/usr.sbin/timed/timed/timed.c +++ b/usr.sbin/timed/timed/timed.c @@ -229,12 +229,9 @@ main(int argc, char *argv[]) exit(1); } - /* choose a unique seed for random number generation */ + sequence = arc4random(); /* initial seq number */ + (void)gettimeofday(&ntime, NULL); - srandom(ntime.tv_sec + ntime.tv_usec); - - sequence = random(); /* initial seq number */ - /* rounds kernel variable time to multiple of 5 ms. */ ntime.tv_sec = 0; ntime.tv_usec = -((ntime.tv_usec/1000) % 5) * 1000;