mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
zerobinpaste: seed sjcl prng from /dev/(u)random
This commit is contained in:
parent
353fac415a
commit
415516ee0c
@ -88,6 +88,22 @@ paste_file = (content, name) ->
|
|||||||
req.end()
|
req.end()
|
||||||
|
|
||||||
|
|
||||||
|
# Seed sjcl prng from /dev/(u)random
|
||||||
|
do (bytes=64) ->
|
||||||
|
for src in ['/dev/urandom', '/dev/random', null]
|
||||||
|
break if not src or fs.existsSync(src)
|
||||||
|
if not src
|
||||||
|
console.error( 'ERROR: Failed to seed PRNG -'\
|
||||||
|
+ ' /dev/(u)random is unavailable, relying only on sjcl entropy sources' )
|
||||||
|
return
|
||||||
|
fd = fs.openSync(src, 'r')
|
||||||
|
buff = new Buffer(bytes)
|
||||||
|
fs.readSync(fd, buff, 0, bytes)
|
||||||
|
fs.closeSync(fd)
|
||||||
|
sjcl.random.addEntropy(
|
||||||
|
(buff.readUInt32BE(n) for n in [0..bytes/4]), bytes * 8, src )
|
||||||
|
|
||||||
|
|
||||||
# Loop over file args or read stdin
|
# Loop over file args or read stdin
|
||||||
if not program.args or not program.args.length
|
if not program.args or not program.args.length
|
||||||
process.stdin.resume()
|
process.stdin.resume()
|
||||||
|
Loading…
Reference in New Issue
Block a user