mirror of
https://github.com/kepler155c/opus
synced 2024-11-15 21:24:49 +00:00
7224d441ca
* canvas overhaul * minor tweaks * list mode for overview * bugfixes + tweaks for editor 2.0 * minor tweaks * more editor work * refactor + new transitions * use layout() where appropriate and cleanup * mouse triple click + textEntry scroll ind * cleanup * cleanup + theme editor * color rework + cleanup * changes for deprecated ui methods * can now use named colors
40 lines
939 B
Lua
40 lines
939 B
Lua
local ECC = require('opus.crypto.ecc')
|
|
local Event = require('opus.event')
|
|
local Util = require('opus.util')
|
|
|
|
local network = _G.network
|
|
local os = _G.os
|
|
|
|
local keyPairs = { }
|
|
|
|
local function generateKeyPair()
|
|
local key = { }
|
|
for _ = 1, 32 do
|
|
table.insert(key, math.random(0, 0xFF))
|
|
end
|
|
local privateKey = setmetatable(key, Util.byteArrayMT)
|
|
return privateKey, ECC.publicKey(privateKey)
|
|
end
|
|
|
|
getmetatable(network).__index.getKeyPair = function()
|
|
local keys = table.remove(keyPairs)
|
|
os.queueEvent('generate_keypair')
|
|
if not keys then
|
|
return generateKeyPair()
|
|
end
|
|
return table.unpack(keys)
|
|
end
|
|
|
|
-- Generate key pairs in the background as this is a time-consuming process
|
|
Event.on('generate_keypair', function()
|
|
while true do
|
|
os.sleep(5)
|
|
local timer = Util.timer()
|
|
table.insert(keyPairs, { generateKeyPair() })
|
|
_G._syslog('Generated keypair in ' .. timer())
|
|
if #keyPairs >= 3 then
|
|
break
|
|
end
|
|
end
|
|
end)
|