security updates
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
-- By Anavrins
|
||||
|
||||
local sha2 = require('opus.crypto.sha2')
|
||||
local util = require('opus.util')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local ROUNDS = 20 -- Adjust this for speed tradeoff
|
||||
|
||||
@@ -115,7 +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 throttle = Util.throttle()
|
||||
local out = {}
|
||||
local state = initState(key, nonce, cntr)
|
||||
local blockAmt = math.floor(#data/64)
|
||||
@@ -157,8 +157,8 @@ local function encrypt(data, key)
|
||||
end
|
||||
|
||||
local function decrypt(data, key)
|
||||
local nonce = util.hexToByteArray(data[1])
|
||||
data = util.hexToByteArray(data[2])
|
||||
local nonce = Util.hexToByteArray(data[1])
|
||||
data = Util.hexToByteArray(data[2])
|
||||
key = sha2.digest(key)
|
||||
local ptx = crypt(data, key, nonce, 1, ROUNDS)
|
||||
return textutils.unserialise(tostring(ptx))
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
-- Indistinguishability? No: The curve does not support indistinguishability maps.
|
||||
|
||||
local fp = require('opus.crypto.ecc.fp')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local eq = fp.eq
|
||||
local mul = fp.mul
|
||||
local sqr = fp.sqr
|
||||
@@ -31,6 +33,7 @@ local shr = fp.shr
|
||||
local mont = fp.mont
|
||||
local invMont = fp.invMont
|
||||
local sub192 = fp.sub192
|
||||
local unpack = table.unpack
|
||||
|
||||
local bits = 192
|
||||
local pMinusTwoBinary = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
@@ -203,20 +206,23 @@ local function scalarMul(s, P1)
|
||||
end
|
||||
|
||||
local Q = {{unpack(ZERO)}, {unpack(ONE)}, {unpack(ONE)}}
|
||||
for i = #naf, 1, -1 do
|
||||
for i = #naf, 1, -1 do -- can this loop be optimized ?
|
||||
local n = naf[i]
|
||||
Q = pointDouble(Q)
|
||||
if naf[i] > 0 then
|
||||
Q = pointAdd(Q, PTable[naf[i]])
|
||||
elseif naf[i] < 0 then
|
||||
Q = pointSub(Q, PTable[-naf[i]])
|
||||
if n > 0 then
|
||||
Q = pointAdd(Q, PTable[n])
|
||||
elseif n < 0 then
|
||||
Q = pointSub(Q, PTable[-n])
|
||||
end
|
||||
end
|
||||
|
||||
return Q
|
||||
end
|
||||
|
||||
local throttle = Util.throttle()
|
||||
for i = 2, 196 do
|
||||
GTable[i] = pointDouble(GTable[i - 1])
|
||||
throttle()
|
||||
end
|
||||
|
||||
local function scalarMulG(s)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
-- Fp Integer Arithmetic
|
||||
|
||||
local unpack = table.unpack
|
||||
|
||||
local n = 0xffff
|
||||
local m = 0x10000
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
-- Fq Integer Arithmetic
|
||||
|
||||
local unpack = table.unpack
|
||||
|
||||
local n = 0xffff
|
||||
local m = 0x10000
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ local elliptic = require('opus.crypto.ecc.elliptic')
|
||||
local sha256 = require('opus.crypto.sha2')
|
||||
|
||||
local os = _G.os
|
||||
local unpack = table.unpack
|
||||
|
||||
local q = {1372, 62520, 47765, 8105, 45059, 9616, 65535, 65535, 65535, 65535, 65535, 65532}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
-- SHA-256, HMAC and PBKDF2 functions in ComputerCraft
|
||||
-- By Anavrins
|
||||
local Util = require('opus.util')
|
||||
|
||||
local bit = _G.bit
|
||||
local os = _G.os
|
||||
local mod32 = 2^32
|
||||
local band = bit32 and bit32.band or bit.band
|
||||
local bnot = bit32 and bit32.bnot or bit.bnot
|
||||
@@ -162,25 +162,13 @@ 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()
|
||||
local throttle = Util.throttle()
|
||||
|
||||
while dklen > 0 do
|
||||
local ikey = {}
|
||||
|
||||
Reference in New Issue
Block a user