Patchwork [4/5] initscripts: Use current date as an additional source of entropy

login
register
mail settings
Submitter Ben Shelton
Date July 16, 2014, 8:59 p.m.
Message ID <ededa281cd9a9d240d92fd819d6d6ef44a325ce4.1405542432.git.ben.shelton@ni.com>
Download mbox | patch
Permalink /patch/75861/
State Accepted
Commit 82ef864f19b5712bed54b92ff369b4dc0693dc9a
Headers show

Comments

Ben Shelton - July 16, 2014, 8:59 p.m.
From: Ken Sharp <ken.sharp@ni.com>

If the seed file is empty or does not exist, the date is an extremely
poor backup source of entropy, but it is better than nothing.

Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
Signed-off-by: Ben Shelton <ben.shelton@ni.com>
---
 meta/recipes-core/initscripts/initscripts-1.0/urandom | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Patch

diff --git a/meta/recipes-core/initscripts/initscripts-1.0/urandom b/meta/recipes-core/initscripts/initscripts-1.0/urandom
index a0549de..ec4ef61 100755
--- a/meta/recipes-core/initscripts/initscripts-1.0/urandom
+++ b/meta/recipes-core/initscripts/initscripts-1.0/urandom
@@ -20,12 +20,11 @@  RANDOM_SEED_FILE=/var/lib/urandom/random-seed
 case "$1" in
 	start|"")
 		test "$VERBOSE" != no && echo "Initializing random number generator..."
-		# Load and then save 512 bytes,
-		# which is the size of the entropy pool
-		if test -f "$RANDOM_SEED_FILE"
-		then
-			cat "$RANDOM_SEED_FILE" >/dev/urandom
-		fi
+		# Load and then save 512 bytes, which is the size of the entropy
+		# pool. Also load the current date, in case the seed file is
+		# empty.
+		( date +%s.%N; [ -f "$RANDOM_SEED_FILE" ] && cat "$RANDOM_SEED_FILE" ) \
+			>/dev/urandom
 		rm -f "$RANDOM_SEED_FILE"
 		umask 077
 		dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \