From 10fca522903943d7fb09ca6edd6d109eb733265d Mon Sep 17 00:00:00 2001 From: xAnavrins Date: Mon, 6 May 2019 01:48:31 -0400 Subject: [PATCH] Fixes --- sys/apis/crypto/chacha20.lua | 4 ++-- sys/apis/crypto/ecc/ecc.lua | 2 +- sys/apis/crypto/sha2.lua | 14 ++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sys/apis/crypto/chacha20.lua b/sys/apis/crypto/chacha20.lua index 4d8f72d..3c05ae6 100644 --- a/sys/apis/crypto/chacha20.lua +++ b/sys/apis/crypto/chacha20.lua @@ -1,8 +1,8 @@ -- Chacha20 cipher in ComputerCraft -- By Anavrins -local sha2 = require("crypto.sha2") -local util = require("util") +local sha2 = require('crypto.sha2') +local util = require('util') local Crypto = {} local ROUNDS = 20 -- Adjust this for speed tradeoff diff --git a/sys/apis/crypto/ecc/ecc.lua b/sys/apis/crypto/ecc/ecc.lua index 030ce61..ffaf852 100644 --- a/sys/apis/crypto/ecc/ecc.lua +++ b/sys/apis/crypto/ecc/ecc.lua @@ -1,4 +1,4 @@ -local fq = require('crypto.ecc.fp') +local fq = require('crypto.ecc.fq') local elliptic = require('crypto.ecc.elliptic') local sha256 = require('crypto.sha2') diff --git a/sys/apis/crypto/sha2.lua b/sys/apis/crypto/sha2.lua index 6c1660b..162f5cb 100644 --- a/sys/apis/crypto/sha2.lua +++ b/sys/apis/crypto/sha2.lua @@ -1,8 +1,6 @@ -- SHA-256, HMAC and PBKDF2 functions in ComputerCraft -- By Anavrins -local sha2 = {} - local mod32 = 2^32 local band = bit32 and bit32.band or bit.band local bnot = bit32 and bit32.bnot or bit.bnot @@ -121,7 +119,7 @@ local function toBytes(t, n) return setmetatable(b, mt) end -function sha2.digest(data) +local function digest(data) local data = data or "" 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) 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 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) 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 hashlen = 32 local dklen = dklen or 32 @@ -192,4 +190,8 @@ function sha2.pbkdf2(pass, salt, iter, dklen) return setmetatable(out, mt) end -return sha2 \ No newline at end of file +return { + digest = digest, + hmac = hmac, + pbkdf2 = pbkdf2, +}