mirror of
https://github.com/kepler155c/opus
synced 2025-07-07 04:22:51 +00:00
Fixes
This commit is contained in:
parent
5296e134a6
commit
10fca52290
@ -1,8 +1,8 @@
|
|||||||
-- Chacha20 cipher in ComputerCraft
|
-- Chacha20 cipher in ComputerCraft
|
||||||
-- By Anavrins
|
-- By Anavrins
|
||||||
|
|
||||||
local sha2 = require("crypto.sha2")
|
local sha2 = require('crypto.sha2')
|
||||||
local util = require("util")
|
local util = require('util')
|
||||||
|
|
||||||
local Crypto = {}
|
local Crypto = {}
|
||||||
local ROUNDS = 20 -- Adjust this for speed tradeoff
|
local ROUNDS = 20 -- Adjust this for speed tradeoff
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local fq = require('crypto.ecc.fp')
|
local fq = require('crypto.ecc.fq')
|
||||||
local elliptic = require('crypto.ecc.elliptic')
|
local elliptic = require('crypto.ecc.elliptic')
|
||||||
local sha256 = require('crypto.sha2')
|
local sha256 = require('crypto.sha2')
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
-- SHA-256, HMAC and PBKDF2 functions in ComputerCraft
|
-- SHA-256, HMAC and PBKDF2 functions in ComputerCraft
|
||||||
-- By Anavrins
|
-- By Anavrins
|
||||||
|
|
||||||
local sha2 = {}
|
|
||||||
|
|
||||||
local mod32 = 2^32
|
local mod32 = 2^32
|
||||||
local band = bit32 and bit32.band or bit.band
|
local band = bit32 and bit32.band or bit.band
|
||||||
local bnot = bit32 and bit32.bnot or bit.bnot
|
local bnot = bit32 and bit32.bnot or bit.bnot
|
||||||
@ -121,7 +119,7 @@ local function toBytes(t, n)
|
|||||||
return setmetatable(b, mt)
|
return setmetatable(b, mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sha2.digest(data)
|
local function digest(data)
|
||||||
local data = data or ""
|
local data = data or ""
|
||||||
data = type(data) == "table" and {upack(data)} or {tostring(data):byte(1,-1)}
|
data = type(data) == "table" and {upack(data)} or {tostring(data):byte(1,-1)}
|
||||||
|
|
||||||
@ -131,7 +129,7 @@ function sha2.digest(data)
|
|||||||
return toBytes(C, 8)
|
return toBytes(C, 8)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sha2.hmac(data, key)
|
local function hmac(data, key)
|
||||||
local data = type(data) == "table" and {upack(data)} or {tostring(data):byte(1,-1)}
|
local data = type(data) == "table" and {upack(data)} or {tostring(data):byte(1,-1)}
|
||||||
local key = type(key) == "table" and {upack(key)} or {tostring(key):byte(1,-1)}
|
local key = type(key) == "table" and {upack(key)} or {tostring(key):byte(1,-1)}
|
||||||
|
|
||||||
@ -162,7 +160,7 @@ function sha2.hmac(data, key)
|
|||||||
return digest(padded_key)
|
return digest(padded_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sha2.pbkdf2(pass, salt, iter, dklen)
|
local function pbkdf2(pass, salt, iter, dklen)
|
||||||
local salt = type(salt) == "table" and salt or {tostring(salt):byte(1,-1)}
|
local salt = type(salt) == "table" and salt or {tostring(salt):byte(1,-1)}
|
||||||
local hashlen = 32
|
local hashlen = 32
|
||||||
local dklen = dklen or 32
|
local dklen = dklen or 32
|
||||||
@ -192,4 +190,8 @@ function sha2.pbkdf2(pass, salt, iter, dklen)
|
|||||||
return setmetatable(out, mt)
|
return setmetatable(out, mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
return sha2
|
return {
|
||||||
|
digest = digest,
|
||||||
|
hmac = hmac,
|
||||||
|
pbkdf2 = pbkdf2,
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user