security update round 2
This commit is contained in:
@@ -115,6 +115,7 @@ local function crypt(data, key, nonce, cntr, round)
|
||||
cntr = tonumber(cntr) or 1
|
||||
round = tonumber(round) or 20
|
||||
|
||||
local throttle = util.throttle()
|
||||
local out = {}
|
||||
local state = initState(key, nonce, cntr)
|
||||
local blockAmt = math.floor(#data/64)
|
||||
@@ -131,8 +132,9 @@ local function crypt(data, key, nonce, cntr, round)
|
||||
end
|
||||
|
||||
if i % 1000 == 0 then
|
||||
os.queueEvent("")
|
||||
os.pullEvent("")
|
||||
throttle()
|
||||
--os.queueEvent("")
|
||||
--os.pullEvent("")
|
||||
end
|
||||
end
|
||||
return setmetatable(out, mt)
|
||||
|
||||
@@ -162,12 +162,25 @@ local function hmac(data, key)
|
||||
return digest(padded_key)
|
||||
end
|
||||
|
||||
local function throttler()
|
||||
local ts = os.clock()
|
||||
local timeout = .095
|
||||
return function()
|
||||
local nts = os.clock()
|
||||
if nts > ts + timeout then
|
||||
os.sleep(0)
|
||||
ts = os.clock()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function pbkdf2(pass, salt, iter, dklen)
|
||||
salt = type(salt) == "table" and salt or {tostring(salt):byte(1,-1)}
|
||||
local hashlen = 32
|
||||
dklen = dklen or 32
|
||||
local block = 1
|
||||
local out = {}
|
||||
local throttle = throttler()
|
||||
|
||||
while dklen > 0 do
|
||||
local ikey = {}
|
||||
@@ -182,7 +195,10 @@ local function pbkdf2(pass, salt, iter, dklen)
|
||||
for j = 1, iter do
|
||||
isalt = hmac(isalt, pass)
|
||||
for k = 1, clen do ikey[k] = bxor(isalt[k], ikey[k] or 0) end
|
||||
if j % 200 == 0 then os.queueEvent("PBKDF2", j) coroutine.yield("PBKDF2") end
|
||||
if j % 200 == 0 then
|
||||
throttle()
|
||||
--os.queueEvent("PBKDF2", j) coroutine.yield("PBKDF2")
|
||||
end
|
||||
end
|
||||
dklen = dklen - clen
|
||||
block = block+1
|
||||
|
||||
Reference in New Issue
Block a user