src: seed V8's random number generator at startup
authorBen Noordhuis <info@bnoordhuis.nl>
Fri, 20 Sep 2013 20:01:49 +0000 (22:01 +0200)
committerFedor Indutny <fedor.indutny@gmail.com>
Wed, 26 Mar 2014 07:31:32 +0000 (11:31 +0400)
commit70f198ddb1ba464da97799f59ae9233320ecc49d
treec5071253be5fb2a6772c134a436aed6b0bab52fb
parentbd547d65983c190eb69ca44d633ea31aca2b7c98
src: seed V8's random number generator at startup

The default entropy source is /dev/urandom on UNIX platforms, which is
okay but we can do better by seeding it from OpenSSL's entropy pool.

On Windows we can certainly do better; on that platform, V8 seeds the
random number generator using only the current system time.

Fixes #6250.

NB: This is a back-port of commit 7ac2391 from the master branch that
for some reason never got back-ported to the v0.10 branch.

The default on UNIX platforms in v0.10 is different and arguably worse
than it is with master: if no entropy source is provided, V8 3.14 calls
srandom() with a xor of the PID and the current time in microseconds.

That means that on systems with a coarse system clock, the initial
state of the PRNG may be easily guessable.

The situation on Windows is even more dire because there the PRNG is
seeded with only the current time... in milliseconds.
src/node.cc
src/node_crypto.cc
src/node_crypto.h