Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lockbox/cipher/des.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions lockbox/digest/md2.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lockbox/digest/md4.lua
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions lockbox/digest/md5.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions lockbox/digest/ripemd128.lua
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lockbox/digest/ripemd160.lua
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lockbox/digest/sha1.lua
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions lockbox/digest/sha2_224.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions lockbox/digest/sha2_256.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions lockbox/kdf/pbkdf2.lua
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -86,7 +85,7 @@ local PBKDF2 = function()
end

public.finish = function()
local blocks = Math.ceil(dKeyLen / blockLen);
local blocks = math.ceil(dKeyLen / blockLen);

dKey = {};

Expand Down
17 changes: 8 additions & 9 deletions lockbox/util/array.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

local String = require("string");
local Bit = require("lockbox.util.bit");
local Queue = require("lockbox.util.queue");

Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions lockbox/util/base64.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local String = require("string");
local Bit = require("lockbox.util.bit");

local Stream = require("lockbox.util.stream");
Expand Down Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions lockbox/util/stream.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local Queue = require("lockbox.util.queue");
local String = require("string");

local Stream = {};

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down