1
0
mirror of https://github.com/kepler155c/opus synced 2025-07-06 12:02:50 +00:00

unpack > table.unpack

This commit is contained in:
Kan18 2019-07-19 17:23:13 -04:00 committed by GitHub
parent 1c1d2151ea
commit f3315a6c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ local function quarterRound(s, a, b, c, d)
end end
local function hashBlock(state, rnd) local function hashBlock(state, rnd)
local s = {unpack(state)} local s = {table.unpack(state)}
for i = 1, rnd do for i = 1, rnd do
local r = i%2==1 local r = i%2==1
s = r and quarterRound(s, 1, 5, 9, 13) or quarterRound(s, 1, 6, 11, 16) s = r and quarterRound(s, 1, 5, 9, 13) or quarterRound(s, 1, 6, 11, 16)
@ -92,9 +92,9 @@ local function serialize(state)
end end
local mt = { local mt = {
__tostring = function(a) return string.char(unpack(a)) end, __tostring = function(a) return string.char(table.unpack(a)) end,
__index = { __index = {
toHex = function(self) return ("%02x"):rep(#self):format(unpack(self)) end, toHex = function(self) return ("%02x"):rep(#self):format(table.unpack(self)) end,
isEqual = function(self, t) isEqual = function(self, t)
if type(t) ~= "table" then return false end if type(t) ~= "table" then return false end
if #self ~= #t then return false end if #self ~= #t then return false end
@ -113,7 +113,7 @@ local function crypt(data, key, nonce, cntr, round)
assert(#key == 16 or #key == 32, "ChaCha20: Invalid key length ("..#key.."), must be 16 or 32") assert(#key == 16 or #key == 32, "ChaCha20: Invalid key length ("..#key.."), must be 16 or 32")
assert(#nonce == 12, "ChaCha20: Invalid nonce length ("..#nonce.."), must be 12") assert(#nonce == 12, "ChaCha20: Invalid nonce length ("..#nonce.."), must be 12")
data = type(data) == "table" and {unpack(data)} or {tostring(data):byte(1,-1)} data = type(data) == "table" and {table.unpack(data)} or {tostring(data):byte(1,-1)}
cntr = tonumber(cntr) or 1 cntr = tonumber(cntr) or 1
round = tonumber(round) or 20 round = tonumber(round) or 20