security update round 2

This commit is contained in:
kepler155c@gmail.com
2019-06-29 02:44:30 -04:00
parent d90aa0e2fd
commit 00293033c8
8 changed files with 91 additions and 159 deletions

View File

@@ -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)

View File

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