diff --git a/lockbox/cipher/des.lua b/lockbox/cipher/des.lua index 5863f81..7a8f8ea 100644 --- a/lockbox/cipher/des.lua +++ b/lockbox/cipher/des.lua @@ -3,7 +3,6 @@ require("lockbox").insecure(); local Array = require("lockbox.util.array"); local Bit = require("lockbox.util.bit"); -local Math = require("math"); local AND = Bit.band; @@ -146,8 +145,8 @@ local packBytes = function(bits) local bytes = {} for k, _ in pairs(bits) do - local index = Math.floor((k - 1) / 8) + 1; - local shift = 7 - Math.fmod((k - 1), 8); + local index = math.floor((k - 1) / 8) + 1; + local shift = 7 - math.fmod((k - 1), 8); local bit = bits[k]; local byte = bytes[index]; diff --git a/lockbox/digest/md2.lua b/lockbox/digest/md2.lua index 71a5ee8..d0f6b61 100644 --- a/lockbox/digest/md2.lua +++ b/lockbox/digest/md2.lua @@ -1,7 +1,6 @@ require("lockbox").insecure(); local Bit = require("lockbox.util.bit"); -local String = require("string"); local Queue = require("lockbox.util.queue"); local SUBST = { @@ -123,7 +122,7 @@ local MD2 = function() end public.asHex = function() - return String.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + return string.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", X[ 0], X[ 1], X[ 2], X[ 3], X[ 4], X[ 5], X[ 6], X[ 7], X[ 8], X[ 9], X[10], X[11], X[12], X[13], X[14], X[15]); end diff --git a/lockbox/digest/md4.lua b/lockbox/digest/md4.lua index 0ab3479..bc32588 100644 --- a/lockbox/digest/md4.lua +++ b/lockbox/digest/md4.lua @@ -1,8 +1,6 @@ require("lockbox").insecure(); local Bit = require("lockbox.util.bit"); -local String = require("string"); -local Math = require("math"); local Queue = require("lockbox.util.queue"); local AND = Bit.band; @@ -32,7 +30,7 @@ local word2bytes = function(word) end local dword2bytes = function(i) - local b4, b5, b6, b7 = word2bytes(Math.floor(i / 0x100000000)); + local b4, b5, b6, b7 = word2bytes(math.floor(i / 0x100000000)); local b0, b1, b2, b3 = word2bytes(i); return b0, b1, b2, b3, b4, b5, b6, b7; end @@ -194,7 +192,7 @@ local MD4 = function() local b8, b9, b10, b11 = word2bytes(C); local b12, b13, b14, b15 = word2bytes(D); - return String.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + return string.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15); end diff --git a/lockbox/digest/md5.lua b/lockbox/digest/md5.lua index 6ce1df2..6264b84 100644 --- a/lockbox/digest/md5.lua +++ b/lockbox/digest/md5.lua @@ -1,8 +1,6 @@ require("lockbox").insecure(); local Bit = require("lockbox.util.bit"); -local String = require("string"); -local Math = require("math"); local Queue = require("lockbox.util.queue"); local SHIFT = { @@ -56,7 +54,7 @@ local word2bytes = function(word) end local dword2bytes = function(i) - local b4, b5, b6, b7 = word2bytes(Math.floor(i / 0x100000000)); + local b4, b5, b6, b7 = word2bytes(math.floor(i / 0x100000000)); local b0, b1, b2, b3 = word2bytes(i); return b0, b1, b2, b3, b4, b5, b6, b7; end @@ -178,7 +176,7 @@ local MD5 = function() local b8, b9, b10, b11 = word2bytes(C); local b12, b13, b14, b15 = word2bytes(D); - return String.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + return string.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15); end diff --git a/lockbox/digest/ripemd128.lua b/lockbox/digest/ripemd128.lua index ebc3e41..38a1fb1 100644 --- a/lockbox/digest/ripemd128.lua +++ b/lockbox/digest/ripemd128.lua @@ -1,8 +1,6 @@ require("lockbox").insecure(); local Bit = require("lockbox.util.bit"); -local String = require("string"); -local Math = require("math"); local Queue = require("lockbox.util.queue"); local AND = Bit.band; @@ -32,7 +30,7 @@ local word2bytes = function(word) end local dword2bytes = function(i) - local b4, b5, b6, b7 = word2bytes(Math.floor(i / 0x100000000)); + local b4, b5, b6, b7 = word2bytes(math.floor(i / 0x100000000)); local b0, b1, b2, b3 = word2bytes(i); return b0, b1, b2, b3, b4, b5, b6, b7; end @@ -330,7 +328,7 @@ local RIPEMD128 = function() local fmt = "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"; - return String.format(fmt, + return string.format(fmt, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15); end diff --git a/lockbox/digest/ripemd160.lua b/lockbox/digest/ripemd160.lua index 5b42d73..2ea5dcb 100644 --- a/lockbox/digest/ripemd160.lua +++ b/lockbox/digest/ripemd160.lua @@ -1,8 +1,6 @@ require("lockbox").insecure(); local Bit = require("lockbox.util.bit"); -local String = require("string"); -local Math = require("math"); local Queue = require("lockbox.util.queue"); local AND = Bit.band; @@ -32,7 +30,7 @@ local word2bytes = function(word) end local dword2bytes = function(i) - local b4, b5, b6, b7 = word2bytes(Math.floor(i / 0x100000000)); + local b4, b5, b6, b7 = word2bytes(math.floor(i / 0x100000000)); local b0, b1, b2, b3 = word2bytes(i); return b0, b1, b2, b3, b4, b5, b6, b7; end @@ -381,7 +379,7 @@ local RIPEMD160 = function() local fmt = "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"; - return String.format(fmt, + return string.format(fmt, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19); end diff --git a/lockbox/digest/sha1.lua b/lockbox/digest/sha1.lua index 3e429e8..5a6e2e8 100644 --- a/lockbox/digest/sha1.lua +++ b/lockbox/digest/sha1.lua @@ -1,8 +1,6 @@ require("lockbox").insecure(); local Bit = require("lockbox.util.bit"); -local String = require("string"); -local Math = require("math"); local Queue = require("lockbox.util.queue"); local AND = Bit.band; @@ -32,7 +30,7 @@ end local dword2bytes = function(i) local b4, b5, b6, b7 = word2bytes(i); - local b0, b1, b2, b3 = word2bytes(Math.floor(i / 0x100000000)); + local b0, b1, b2, b3 = word2bytes(math.floor(i / 0x100000000)); return b0, b1, b2, b3, b4, b5, b6, b7; end @@ -163,7 +161,7 @@ local SHA1 = function() local b12, b13, b14, b15 = word2bytes(h3); local b16, b17, b18, b19 = word2bytes(h4); - return String.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + return string.format("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19); end diff --git a/lockbox/digest/sha2_224.lua b/lockbox/digest/sha2_224.lua index 3897c26..6ee7245 100644 --- a/lockbox/digest/sha2_224.lua +++ b/lockbox/digest/sha2_224.lua @@ -1,6 +1,4 @@ local Bit = require("lockbox.util.bit"); -local String = require("string"); -local Math = require("math"); local Queue = require("lockbox.util.queue"); local CONSTANTS = { @@ -44,7 +42,7 @@ end local dword2bytes = function(i) local b4, b5, b6, b7 = word2bytes(i); - local b0, b1, b2, b3 = word2bytes(Math.floor(i / 0x100000000)); + local b0, b1, b2, b3 = word2bytes(math.floor(i / 0x100000000)); return b0, b1, b2, b3, b4, b5, b6, b7; end @@ -188,7 +186,7 @@ local SHA2_224 = function() local b20, b21, b22, b23 = word2bytes(h5); local b24, b25, b26, b27 = word2bytes(h6); - return String.format(fmt, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15 + return string.format(fmt, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15 , b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27); end diff --git a/lockbox/digest/sha2_256.lua b/lockbox/digest/sha2_256.lua index 4cd2f35..74136d7 100644 --- a/lockbox/digest/sha2_256.lua +++ b/lockbox/digest/sha2_256.lua @@ -1,6 +1,4 @@ local Bit = require("lockbox.util.bit"); -local String = require("string"); -local Math = require("math"); local Queue = require("lockbox.util.queue"); local CONSTANTS = { @@ -44,7 +42,7 @@ end local dword2bytes = function(i) local b4, b5, b6, b7 = word2bytes(i); - local b0, b1, b2, b3 = word2bytes(Math.floor(i / 0x100000000)); + local b0, b1, b2, b3 = word2bytes(math.floor(i / 0x100000000)); return b0, b1, b2, b3, b4, b5, b6, b7; end @@ -191,7 +189,7 @@ local SHA2_256 = function() local b24, b25, b26, b27 = word2bytes(h6); local b28, b29, b30, b31 = word2bytes(h7); - return String.format(fmt, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15 + return string.format(fmt, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15 , b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31); end diff --git a/lockbox/kdf/pbkdf2.lua b/lockbox/kdf/pbkdf2.lua index e13e57d..c9e4388 100644 --- a/lockbox/kdf/pbkdf2.lua +++ b/lockbox/kdf/pbkdf2.lua @@ -1,7 +1,6 @@ local Bit = require("lockbox.util.bit"); local Array = require("lockbox.util.array"); local Stream = require("lockbox.util.stream"); -local Math = require("math"); local AND = Bit.band; local RSHIFT = Bit.rshift; @@ -86,7 +85,7 @@ local PBKDF2 = function() end public.finish = function() - local blocks = Math.ceil(dKeyLen / blockLen); + local blocks = math.ceil(dKeyLen / blockLen); dKey = {}; diff --git a/lockbox/util/array.lua b/lockbox/util/array.lua index 899419d..61ed06e 100644 --- a/lockbox/util/array.lua +++ b/lockbox/util/array.lua @@ -1,5 +1,4 @@ -local String = require("string"); local Bit = require("lockbox.util.bit"); local Queue = require("lockbox.util.queue"); @@ -15,11 +14,11 @@ Array.fromString = function(string) local bytes = {}; local i = 1; - local byte = String.byte(string, i); + local byte = string.byte(string, i); while byte ~= nil do bytes[i] = byte; i = i + 1; - byte = String.byte(string, i); + byte = string.byte(string, i); end return bytes; @@ -32,7 +31,7 @@ Array.toString = function(bytes) local byte = bytes[i]; while byte ~= nil do - chars[i] = String.char(byte); + chars[i] = string.char(byte); i = i + 1; byte = bytes[i]; end @@ -89,15 +88,15 @@ end local fromHexTable = {}; for i = 0, 255 do - fromHexTable[String.format("%02X", i)] = i; - fromHexTable[String.format("%02x", i)] = i; + fromHexTable[string.format("%02X", i)] = i; + fromHexTable[string.format("%02x", i)] = i; end Array.fromHex = function(hex) local array = {}; - for i = 1, String.len(hex) / 2 do - local h = String.sub(hex, i * 2 - 1, i * 2); + for i = 1, string.len(hex) / 2 do + local h = string.sub(hex, i * 2 - 1, i * 2); array[i] = fromHexTable[h]; end @@ -107,7 +106,7 @@ end local toHexTable = {}; for i = 0, 255 do - toHexTable[i] = String.format("%02X", i); + toHexTable[i] = string.format("%02X", i); end Array.toHex = function(array) diff --git a/lockbox/util/base64.lua b/lockbox/util/base64.lua index 6f1743d..f1e4724 100644 --- a/lockbox/util/base64.lua +++ b/lockbox/util/base64.lua @@ -1,4 +1,3 @@ -local String = require("string"); local Bit = require("lockbox.util.bit"); local Stream = require("lockbox.util.stream"); @@ -81,7 +80,7 @@ Base64.toStream = function(base64) local yield = coroutine.yield; - for c in String.gmatch(base64, ".") do + for c in string.gmatch(base64, ".") do if (c == "=") then bits = RSHIFT(bits, 2); bitCount = bitCount - 2; else diff --git a/lockbox/util/stream.lua b/lockbox/util/stream.lua index f81a18c..a198d87 100644 --- a/lockbox/util/stream.lua +++ b/lockbox/util/stream.lua @@ -1,5 +1,4 @@ local Queue = require("lockbox.util.queue"); -local String = require("string"); local Stream = {}; @@ -8,7 +7,7 @@ Stream.fromString = function(string) local i = 0; return function() i = i + 1; - return String.byte(string, i); + return string.byte(string, i); end end @@ -19,7 +18,7 @@ Stream.toString = function(stream) local byte = stream(); while byte ~= nil do - array[i] = String.char(byte); + array[i] = string.char(byte); i = i + 1; byte = stream(); end @@ -60,15 +59,15 @@ end local fromHexTable = {}; for i = 0, 255 do - fromHexTable[String.format("%02X", i)] = i; - fromHexTable[String.format("%02x", i)] = i; + fromHexTable[string.format("%02X", i)] = i; + fromHexTable[string.format("%02x", i)] = i; end Stream.fromHex = function(hex) local queue = Queue(); - for i = 1, String.len(hex) / 2 do - local h = String.sub(hex, i * 2 - 1, i * 2); + for i = 1, string.len(hex) / 2 do + local h = string.sub(hex, i * 2 - 1, i * 2); queue.push(fromHexTable[h]); end @@ -79,7 +78,7 @@ end local toHexTable = {}; for i = 0, 255 do - toHexTable[i] = String.format("%02X", i); + toHexTable[i] = string.format("%02X", i); end Stream.toHex = function(stream)