Software / code / prosody
Comparison
util/random.lua @ 7083:ac920b0f9eae
util.random: Open /dev/urandom read-only, make seed() a noop
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 12 Jan 2016 23:48:16 +0100 |
| parent | 7050:ae044691de0f |
| child | 7114:51cf09bb74eb |
comparison
equal
deleted
inserted
replaced
| 7082:8b590fc77d91 | 7083:ac920b0f9eae |
|---|---|
| 4 -- | 4 -- |
| 5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
| 6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
| 7 -- | 7 -- |
| 8 | 8 |
| 9 local urandom = assert(io.open("/dev/urandom", "r+")); | 9 local urandom = assert(io.open("/dev/urandom", "r")); |
| 10 | 10 |
| 11 local function seed(x) | 11 local function seed() |
| 12 urandom:write(x); | |
| 13 urandom:flush(); | |
| 14 end | 12 end |
| 15 | 13 |
| 16 local function bytes(n) | 14 local function bytes(n) |
| 17 return urandom:read(n); | 15 return urandom:read(n); |
| 18 end | 16 end |