projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mod_http_files: send valid ETag header
[prosody.git]
/
util
/
random.lua
diff --git
a/util/random.lua
b/util/random.lua
index 4963e98c5645268f196c3d98858e1ccc5a7cc8bd..574e2e1cdf384cf7d893530fdcd97c80843aaba7 100644
(file)
--- a/
util/random.lua
+++ b/
util/random.lua
@@
-6,17
+6,24
@@
-- COPYING file in the source package for more information.
--
-- 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
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;
return {
seed = seed;
bytes = bytes;