Skip to content

Commit

Permalink
Remove type checks from hmac, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed Oct 2, 2018
1 parent 6d70238 commit 1d9c5fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sha1-scm-1.rockspec
Expand Up @@ -18,8 +18,8 @@ build = {
modules = {
sha1 = "src/sha1/init.lua",
["sha1.bit_ops"] = "src/sha1/bit_ops.lua",
["sha1.common"] = "src/sha1/common.lua",
["sha1.bit32_ops"] = "src/sha1/bit32_ops.lua",
["sha1.common"] = "src/sha1/common.lua",
["sha1.lua53_ops"] = "src/sha1/lua53_ops.lua",
["sha1.pure_lua_ops"] = "src/sha1/pure_lua_ops.lua"
}
Expand Down
12 changes: 5 additions & 7 deletions src/sha1/init.lua
Expand Up @@ -160,21 +160,19 @@ function sha1.binary(str)
return hex_to_binary(sha1.sha1(str))
end

-- building the lookuptables ahead of time (instead of littering the source code
-- with precalculated values)
-- Precalculate replacement tables.
local xor_with_0x5c = {}
local xor_with_0x36 = {}
for i=0,0xff do

for i = 0, 0xff do
xor_with_0x5c[schar(i)] = schar(byte_xor(0x5c, i))
xor_with_0x36[schar(i)] = schar(byte_xor(0x36, i))
end

local BLOCK_SIZE = 64 -- 512 bits
-- 512 bits.
local BLOCK_SIZE = 64

function sha1.hmac(key, text)
assert(type(key) == 'string', "key passed to sha1.hmac should be a string")
assert(type(text) == 'string', "text passed to sha1.hmac should be a string")

if #key > BLOCK_SIZE then
key = sha1.binary(key)
end
Expand Down
1 change: 0 additions & 1 deletion src/sha1/pure_lua_ops.lua
Expand Up @@ -5,7 +5,6 @@ local ops = {}
local bytes_to_uint32 = common.bytes_to_uint32
local uint32_to_bytes = common.uint32_to_bytes

-- shift the bits of a 32 bit word. con't use negative values for "bits"
function ops.uint32_lrot(a, bits)
local power = 2 ^ bits
local inv_power = 0x100000000 / power
Expand Down

0 comments on commit 1d9c5fe

Please sign in to comment.