mirror of
https://github.com/kepler155c/opus
synced 2024-11-14 20:54:50 +00:00
Merge remote-tracking branch 'origin/develop-1.8' into ui-enhancements-2.0
This commit is contained in:
commit
613212e751
@ -164,6 +164,7 @@ local page = UI.Page {
|
|||||||
f = 'files',
|
f = 'files',
|
||||||
s = 'shell',
|
s = 'shell',
|
||||||
l = 'lua',
|
l = 'lua',
|
||||||
|
n = 'network',
|
||||||
[ 'control-n' ] = 'new',
|
[ 'control-n' ] = 'new',
|
||||||
delete = 'delete',
|
delete = 'delete',
|
||||||
},
|
},
|
||||||
@ -448,6 +449,9 @@ function page:eventHandler(event)
|
|||||||
elseif event.type == 'files' then
|
elseif event.type == 'files' then
|
||||||
shell.switchTab(shell.openTab(Alt.get('files')))
|
shell.switchTab(shell.openTab(Alt.get('files')))
|
||||||
|
|
||||||
|
elseif event.type == 'network' then
|
||||||
|
shell.switchTab(shell.openTab('network'))
|
||||||
|
|
||||||
elseif event.type == 'focus_change' then
|
elseif event.type == 'focus_change' then
|
||||||
if event.focused.parent.UIElement == 'Icon' then
|
if event.focused.parent.UIElement == 'Icon' then
|
||||||
event.focused.parent:scrollIntoView()
|
event.focused.parent:scrollIntoView()
|
||||||
|
@ -27,4 +27,4 @@ kernel.hook('kernel_focus', function(_, eventData)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
os.pullEventRaw('kernel_halt')
|
os.pullEventRaw('kernel_halt')
|
||||||
|
@ -10,30 +10,30 @@ local keyPairs = { }
|
|||||||
local function generateKeyPair()
|
local function generateKeyPair()
|
||||||
local key = { }
|
local key = { }
|
||||||
for _ = 1, 32 do
|
for _ = 1, 32 do
|
||||||
table.insert(key, ("%02x"):format(math.random(0, 0xFF)))
|
table.insert(key, math.random(0, 0xFF))
|
||||||
end
|
end
|
||||||
local privateKey = Util.hexToByteArray(table.concat(key))
|
local privateKey = setmetatable(key, Util.byteArrayMT)
|
||||||
return privateKey, ECC.publicKey(privateKey)
|
return privateKey, ECC.publicKey(privateKey)
|
||||||
end
|
end
|
||||||
|
|
||||||
getmetatable(network).__index.getKeyPair = function()
|
getmetatable(network).__index.getKeyPair = function()
|
||||||
local keys = table.remove(keyPairs)
|
local keys = table.remove(keyPairs)
|
||||||
os.queueEvent('generate_keypair')
|
os.queueEvent('generate_keypair')
|
||||||
if not keys then
|
if not keys then
|
||||||
return generateKeyPair()
|
return generateKeyPair()
|
||||||
end
|
end
|
||||||
return table.unpack(keys)
|
return table.unpack(keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Generate key pairs in the background as this is a time-consuming process
|
-- Generate key pairs in the background as this is a time-consuming process
|
||||||
Event.on('generate_keypair', function()
|
Event.on('generate_keypair', function()
|
||||||
while true do
|
while true do
|
||||||
os.sleep(5)
|
os.sleep(5)
|
||||||
local timer = Util.timer()
|
local timer = Util.timer()
|
||||||
table.insert(keyPairs, { generateKeyPair() })
|
table.insert(keyPairs, { generateKeyPair() })
|
||||||
_G._syslog('Generated keypair in ' .. timer())
|
_G._syslog('Generated keypair in ' .. timer())
|
||||||
if #keyPairs >= 3 then
|
if #keyPairs >= 3 then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -21,4 +21,4 @@ deleteIfExists('sys/autorun/apps.lua')
|
|||||||
deleteIfExists('sys/init/6.tl3.lua')
|
deleteIfExists('sys/init/6.tl3.lua')
|
||||||
|
|
||||||
-- remove this file
|
-- remove this file
|
||||||
--deleteIfExists('sys/autorun/upgraded.lua')
|
--deleteIfExists('sys/autorun/upgraded.lua')
|
||||||
|
@ -12,12 +12,11 @@ local band = bit32.band
|
|||||||
local blshift = bit32.lshift
|
local blshift = bit32.lshift
|
||||||
local brshift = bit32.arshift
|
local brshift = bit32.arshift
|
||||||
local textutils = _G.textutils
|
local textutils = _G.textutils
|
||||||
|
local mt = Util.byteArrayMT
|
||||||
|
|
||||||
local mod = 2^32
|
local mod = 2^32
|
||||||
local tau = {("expand 16-byte k"):byte(1,-1)}
|
local tau = {("expand 16-byte k"):byte(1,-1)}
|
||||||
local sigma = {("expand 32-byte k"):byte(1,-1)}
|
local sigma = {("expand 32-byte k"):byte(1,-1)}
|
||||||
local null32 = {("A"):rep(32):byte(1,-1)}
|
|
||||||
local null12 = {("A"):rep(12):byte(1,-1)}
|
|
||||||
|
|
||||||
local function rotl(n, b)
|
local function rotl(n, b)
|
||||||
local s = n/(2^(32-b))
|
local s = n/(2^(32-b))
|
||||||
@ -91,22 +90,6 @@ local function serialize(state)
|
|||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
local mt = {
|
|
||||||
__tostring = function(a) return string.char(table.unpack(a)) end,
|
|
||||||
__index = {
|
|
||||||
toHex = function(self) return ("%02x"):rep(#self):format(table.unpack(self)) end,
|
|
||||||
isEqual = function(self, t)
|
|
||||||
if type(t) ~= "table" then return false end
|
|
||||||
if #self ~= #t then return false end
|
|
||||||
local ret = 0
|
|
||||||
for i = 1, #self do
|
|
||||||
ret = bit32.bor(ret, bxor(self[i], t[i]))
|
|
||||||
end
|
|
||||||
return ret == 0
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local function crypt(data, key, nonce, cntr, round)
|
local function crypt(data, key, nonce, cntr, round)
|
||||||
assert(type(key) == "table", "ChaCha20: Invalid key format ("..type(key).."), must be table")
|
assert(type(key) == "table", "ChaCha20: Invalid key format ("..type(key).."), must be table")
|
||||||
assert(type(nonce) == "table", "ChaCha20: Invalid nonce format ("..type(nonce).."), must be table")
|
assert(type(nonce) == "table", "ChaCha20: Invalid nonce format ("..type(nonce).."), must be table")
|
||||||
@ -133,15 +116,12 @@ local function crypt(data, key, nonce, cntr, round)
|
|||||||
out[#out+1] = bxor(block[j], ks[j])
|
out[#out+1] = bxor(block[j], ks[j])
|
||||||
end
|
end
|
||||||
|
|
||||||
--if i % 1000 == 0 then
|
throttle()
|
||||||
throttle()
|
|
||||||
--os.queueEvent("")
|
|
||||||
--os.pullEvent("")
|
|
||||||
--end
|
|
||||||
end
|
end
|
||||||
return setmetatable(out, mt)
|
return setmetatable(out, mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Helper functions
|
||||||
local function genNonce(len)
|
local function genNonce(len)
|
||||||
local nonce = {}
|
local nonce = {}
|
||||||
for i = 1, len do
|
for i = 1, len do
|
||||||
@ -170,6 +150,9 @@ end
|
|||||||
local obj = {}
|
local obj = {}
|
||||||
local rng_mt = {['__index'] = obj}
|
local rng_mt = {['__index'] = obj}
|
||||||
|
|
||||||
|
-- PRNG object
|
||||||
|
local null32 = {("A"):rep(32):byte(1,-1)}
|
||||||
|
local null12 = {("A"):rep(12):byte(1,-1)}
|
||||||
function obj:nextInt(byte)
|
function obj:nextInt(byte)
|
||||||
if not byte or byte < 1 or byte > 6 then error("Can only return 1-6 bytes", 2) end
|
if not byte or byte < 1 or byte > 6 then error("Can only return 1-6 bytes", 2) end
|
||||||
local output = 0
|
local output = 0
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
local fq = require('opus.crypto.ecc.fq')
|
local fq = require('opus.crypto.ecc.fq')
|
||||||
local elliptic = require('opus.crypto.ecc.elliptic')
|
local elliptic = require('opus.crypto.ecc.elliptic')
|
||||||
local sha256 = require('opus.crypto.sha2')
|
local sha256 = require('opus.crypto.sha2')
|
||||||
|
local Util = require('opus.util')
|
||||||
|
|
||||||
|
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local unpack = table.unpack
|
local unpack = table.unpack
|
||||||
|
local mt = Util.byteArrayMT
|
||||||
|
|
||||||
local q = {1372, 62520, 47765, 8105, 45059, 9616, 65535, 65535, 65535, 65535, 65535, 65532}
|
local q = {1372, 62520, 47765, 8105, 45059, 9616, 65535, 65535, 65535, 65535, 65535, 65532}
|
||||||
|
|
||||||
@ -27,7 +30,7 @@ local function publicKey(sk)
|
|||||||
local Y = elliptic.scalarMulG(x)
|
local Y = elliptic.scalarMulG(x)
|
||||||
local pk = elliptic.pointEncode(Y)
|
local pk = elliptic.pointEncode(Y)
|
||||||
|
|
||||||
return pk
|
return setmetatable(pk, mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function exchange(sk, pk)
|
local function exchange(sk, pk)
|
||||||
@ -62,7 +65,7 @@ local function sign(sk, message)
|
|||||||
sig[#sig + 1] = s[i]
|
sig[#sig + 1] = s[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
return sig
|
return setmetatable(sig, mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function verify(pk, message, sig)
|
local function verify(pk, message, sig)
|
||||||
|
@ -9,6 +9,7 @@ local bnot = bit32 and bit32.bnot or bit.bnot
|
|||||||
local bxor = bit32 and bit32.bxor or bit.bxor
|
local bxor = bit32 and bit32.bxor or bit.bxor
|
||||||
local blshift = bit32 and bit32.lshift or bit.blshift
|
local blshift = bit32 and bit32.lshift or bit.blshift
|
||||||
local upack = unpack or table.unpack
|
local upack = unpack or table.unpack
|
||||||
|
local mt = Util.byteArrayMT
|
||||||
|
|
||||||
local function rrotate(n, b)
|
local function rrotate(n, b)
|
||||||
local s = n/(2^b)
|
local s = n/(2^b)
|
||||||
@ -68,17 +69,16 @@ end
|
|||||||
|
|
||||||
local function digestblock(w, C)
|
local function digestblock(w, C)
|
||||||
for j = 17, 64 do
|
for j = 17, 64 do
|
||||||
-- local v = w[j-15]
|
local s0 = bxor(rrotate(w[j-15], 7), rrotate(w[j-15], 18), brshift(w[j-15], 3))
|
||||||
local s0 = bxor(bxor(rrotate(w[j-15], 7), rrotate(w[j-15], 18)), brshift(w[j-15], 3))
|
local s1 = bxor(rrotate(w[j-2], 17), rrotate(w[j-2], 19), brshift(w[j-2], 10))
|
||||||
local s1 = bxor(bxor(rrotate(w[j-2], 17), rrotate(w[j-2], 19)), brshift(w[j-2], 10))
|
|
||||||
w[j] = (w[j-16] + s0 + w[j-7] + s1)%mod32
|
w[j] = (w[j-16] + s0 + w[j-7] + s1)%mod32
|
||||||
end
|
end
|
||||||
local a, b, c, d, e, f, g, h = upack(C)
|
local a, b, c, d, e, f, g, h = upack(C)
|
||||||
for j = 1, 64 do
|
for j = 1, 64 do
|
||||||
local S1 = bxor(bxor(rrotate(e, 6), rrotate(e, 11)), rrotate(e, 25))
|
local S1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
|
||||||
local ch = bxor(band(e, f), band(bnot(e), g))
|
local ch = bxor(band(e, f), band(bnot(e), g))
|
||||||
local temp1 = (h + S1 + ch + K[j] + w[j])%mod32
|
local temp1 = (h + S1 + ch + K[j] + w[j])%mod32
|
||||||
local S0 = bxor(bxor(rrotate(a, 2), rrotate(a, 13)), rrotate(a, 22))
|
local S0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
|
||||||
local maj = bxor(bxor(band(a, b), band(a, c)), band(b, c))
|
local maj = bxor(bxor(band(a, b), band(a, c)), band(b, c))
|
||||||
local temp2 = (S0 + maj)%mod32
|
local temp2 = (S0 + maj)%mod32
|
||||||
h, g, f, e, d, c, b, a = g, f, e, (d+temp1)%mod32, c, b, a, (temp1+temp2)%mod32
|
h, g, f, e, d, c, b, a = g, f, e, (d+temp1)%mod32, c, b, a, (temp1+temp2)%mod32
|
||||||
@ -94,22 +94,6 @@ local function digestblock(w, C)
|
|||||||
return C
|
return C
|
||||||
end
|
end
|
||||||
|
|
||||||
local mt = {
|
|
||||||
__tostring = function(a) return string.char(upack(a)) end,
|
|
||||||
__index = {
|
|
||||||
toHex = function(self) return ("%02x"):rep(#self):format(upack(self)) end,
|
|
||||||
isEqual = function(self, t)
|
|
||||||
if type(t) ~= "table" then return false end
|
|
||||||
if #self ~= #t then return false end
|
|
||||||
local ret = 0
|
|
||||||
for i = 1, #self do
|
|
||||||
ret = bit32.bor(ret, bxor(self[i], t[i]))
|
|
||||||
end
|
|
||||||
return ret == 0
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local function toBytes(t, n)
|
local function toBytes(t, n)
|
||||||
local b = {}
|
local b = {}
|
||||||
for i = 1, n do
|
for i = 1, n do
|
||||||
|
@ -139,7 +139,7 @@ function Socket.connect(host, port, options)
|
|||||||
dhost = socket.dhost,
|
dhost = socket.dhost,
|
||||||
t = Crypto.encrypt({ -- this is not that much data...
|
t = Crypto.encrypt({ -- this is not that much data...
|
||||||
ts = os.epoch('utc'),
|
ts = os.epoch('utc'),
|
||||||
pk = Util.byteArrayToHex(socket.pubKey),
|
pk = socket.pubKey:toHex(),
|
||||||
}, Util.hexToByteArray(identifier)),
|
}, Util.hexToByteArray(identifier)),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ function Socket.server(port, options)
|
|||||||
type = 'CONN',
|
type = 'CONN',
|
||||||
dhost = socket.dhost,
|
dhost = socket.dhost,
|
||||||
shost = socket.shost,
|
shost = socket.shost,
|
||||||
pk = Util.byteArrayToHex(socket.pubKey),
|
pk = socket.pubKey:toHex(),
|
||||||
options = socket.options.ENCRYPT and { ENCRYPT = true },
|
options = socket.options.ENCRYPT and { ENCRYPT = true },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -9,6 +9,39 @@ local textutils = _G.textutils
|
|||||||
local _sformat = string.format
|
local _sformat = string.format
|
||||||
local _srep = string.rep
|
local _srep = string.rep
|
||||||
local _ssub = string.sub
|
local _ssub = string.sub
|
||||||
|
local _unpack = table.unpack
|
||||||
|
local _bor = bit32.bor
|
||||||
|
local _bxor = bit32.bxor
|
||||||
|
|
||||||
|
byteArrayMT = {
|
||||||
|
__tostring = function(a) return string.char(_unpack(a)) end,
|
||||||
|
__index = {
|
||||||
|
toHex = function(self) return ("%02x"):rep(#self):format(_unpack(self)) end,
|
||||||
|
isEqual = function(self, t)
|
||||||
|
if type(t) ~= "table" then return false end
|
||||||
|
if #self ~= #t then return false end
|
||||||
|
local ret = 0
|
||||||
|
for i = 1, #self do
|
||||||
|
ret = _bor(ret, _bxor(self[i], t[i]))
|
||||||
|
end
|
||||||
|
return ret == 0
|
||||||
|
end,
|
||||||
|
sub = function(self, a, b)
|
||||||
|
local len = #self+1
|
||||||
|
local start = a%len
|
||||||
|
local stop = (b or len-1)%len
|
||||||
|
local ret = {}
|
||||||
|
local i = 1
|
||||||
|
for j = start, stop, start<stop and 1 or -1 do
|
||||||
|
ret[i] = self[j]
|
||||||
|
i = i+1
|
||||||
|
end
|
||||||
|
return setmetatable(ret, byteArrayMT)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.byteArrayMT = byteArrayMT
|
||||||
|
|
||||||
function Util.hexToByteArray(str)
|
function Util.hexToByteArray(str)
|
||||||
local r = {}
|
local r = {}
|
||||||
@ -16,12 +49,12 @@ function Util.hexToByteArray(str)
|
|||||||
for b in str:gmatch("%x%x?") do
|
for b in str:gmatch("%x%x?") do
|
||||||
r[#r+1] = tonumber(b, 16)
|
r[#r+1] = tonumber(b, 16)
|
||||||
end
|
end
|
||||||
return r
|
return setmetatable(r, byteArrayMT)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Util.byteArrayToHex(tbl)
|
function Util.byteArrayToHex(tbl)
|
||||||
if not tbl then error('byteArrayToHex: invalid table', 2) end
|
if not tbl then error('byteArrayToHex: invalid table', 2) end
|
||||||
return ("%02x"):rep(#tbl):format(table.unpack(tbl))
|
return ("%02x"):rep(#tbl):format(_unpack(tbl))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Util.tryTimed(timeout, f, ...)
|
function Util.tryTimed(timeout, f, ...)
|
||||||
@ -39,10 +72,10 @@ function Util.tryTimes(attempts, f, ...)
|
|||||||
for _ = 1, attempts do
|
for _ = 1, attempts do
|
||||||
result = { f(...) }
|
result = { f(...) }
|
||||||
if result[1] then
|
if result[1] then
|
||||||
return table.unpack(result)
|
return _unpack(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.unpack(result)
|
return _unpack(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Util.timer()
|
function Util.timer()
|
||||||
|
Loading…
Reference in New Issue
Block a user