X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Frandom.lua;h=5938a94f820ac4e3379c1f56594d3abe07810a15;hb=2dd0d237c85d7d6708a88873eced817b14aa7214;hp=ed5cdf4b8b2556ae20505eb06df1425e35d3f745;hpb=ad00f8769f2110e42bb7a7ce83b952abddc0aa19;p=prosody.git diff --git a/util/random.lua b/util/random.lua index ed5cdf4b..5938a94f 100644 --- a/util/random.lua +++ b/util/random.lua @@ -10,7 +10,7 @@ local tostring = tostring; local os_time = os.time; local os_clock = os.clock; local ceil = math.ceil; -local sha1 = require "util.hashes".sha1; +local H = require "util.hashes".sha512; local last_uniq_time = 0; local function uniq_time() @@ -21,7 +21,7 @@ local function uniq_time() end local function new_random(x) - return sha1(x..os_clock()..tostring({})); + return H(x..os_clock()..tostring({})); end local buffer = new_random(uniq_time()); @@ -31,8 +31,8 @@ local function seed(x) end local function bytes(n) - if #buffer < n then seed(uniq_time()); end - local r = buffer:sub(0, n); + if #buffer < n+4 then seed(uniq_time()); end + local r = buffer:sub(1, n); buffer = buffer:sub(n+1); return r; end