-- 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;