X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Frandom.lua;h=574e2e1cdf384cf7d893530fdcd97c80843aaba7;hb=87fd458b978eae310245ec4678ec1312e8da3f31;hp=4963e98c5645268f196c3d98858e1ccc5a7cc8bd;hpb=6d501b1f0624c4829a787898181bf8a47dc47b35;p=prosody.git diff --git a/util/random.lua b/util/random.lua index 4963e98c..574e2e1c 100644 --- a/util/random.lua +++ b/util/random.lua @@ -6,17 +6,24 @@ -- COPYING file in the source package for more information. -- -local urandom = assert(io.open("/dev/urandom", "r+")); +local ok, crand = pcall(require, "util.crand"); +if ok then return crand; end -local function seed(x) - urandom:write(x); - urandom:flush(); +local urandom, urandom_err = io.open("/dev/urandom", "r"); + +local function seed() end local function bytes(n) return urandom:read(n); end +if not urandom then + function bytes() + error("Unable to obtain a secure random number generator, please see https://prosody.im/doc/random ("..urandom_err..")"); + end +end + return { seed = seed; bytes = bytes;