X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Frandom.lua;h=574e2e1cdf384cf7d893530fdcd97c80843aaba7;hb=64a429222baa79fa17f87dbc90c7738c5caabb73;hp=05f36aba326d661fd93182d3875e13520e1b01c9;hpb=b564225035d20ba51ceff9f628635f42a4d68d98;p=prosody.git diff --git a/util/random.lua b/util/random.lua index 05f36aba..574e2e1c 100644 --- a/util/random.lua +++ b/util/random.lua @@ -6,7 +6,10 @@ -- 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 urandom, urandom_err = io.open("/dev/urandom", "r"); local function seed() end @@ -15,6 +18,12 @@ 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;