aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-07-10 02:19:51 +0100
committerMatthew Wild <mwild1@gmail.com>2009-07-10 02:19:51 +0100
commitd37bfa0073f9a7aeedd370f76963beed535eb1d5 (patch)
tree446bd891aad011c7232e060fde4e366d5d0938d4 /util
parent502cab5ff5b5bdb4feaf3a8a0f81ae40db5485e8 (diff)
downloadprosody-d37bfa0073f9a7aeedd370f76963beed535eb1d5.tar.gz
prosody-d37bfa0073f9a7aeedd370f76963beed535eb1d5.zip
util.hmac: Convert spaces to tabs
Diffstat (limited to 'util')
-rw-r--r--util/hmac.lua66
1 files changed, 33 insertions, 33 deletions
diff --git a/util/hmac.lua b/util/hmac.lua
index 5f4467cf..d3163bb3 100644
--- a/util/hmac.lua
+++ b/util/hmac.lua
@@ -7,64 +7,64 @@ local s_char = string.char;
module "hmac"
local function arraystr(array)
- local t = {}
- for i = 1,#array do
- t_insert(t, s_char(array[i]))
- end
+ local t = {}
+ for i = 1,#array do
+ t_insert(t, s_char(array[i]))
+ end
- return t_concat(t)
+ return t_concat(t)
end
--[[
key
- the key to use in the hash
+ the key to use in the hash
message
- the message to hash
+ the message to hash
hash
- the hash function
+ the hash function
blocksize
- the blocksize for the hash function in bytes
+ the blocksize for the hash function in bytes
hex
return raw hash or hexadecimal string
--]]
function hmac(key, message, hash, blocksize, hex)
- local opad = {}
- local ipad = {}
-
- for i = 1,blocksize do
- opad[i] = 0x5c
- ipad[i] = 0x36
- end
+ local opad = {}
+ local ipad = {}
+
+ for i = 1,blocksize do
+ opad[i] = 0x5c
+ ipad[i] = 0x36
+ end
- if #key > blocksize then
- key = hash(key)
- end
+ if #key > blocksize then
+ key = hash(key)
+ end
- for i = 1,#key do
- ipad[i] = xor(ipad[i],key:sub(i,i):byte())
- opad[i] = xor(opad[i],key:sub(i,i):byte())
- end
+ for i = 1,#key do
+ ipad[i] = xor(ipad[i],key:sub(i,i):byte())
+ opad[i] = xor(opad[i],key:sub(i,i):byte())
+ end
- opad = arraystr(opad)
- ipad = arraystr(ipad)
+ opad = arraystr(opad)
+ ipad = arraystr(ipad)
- if hex then
- return hash(opad..hash(ipad..message), true)
- else
- return hash(opad..hash(ipad..message))
- end
+ if hex then
+ return hash(opad..hash(ipad..message), true)
+ else
+ return hash(opad..hash(ipad..message))
+ end
end
function md5(key, message, hex)
- return hmac(key, message, hashes.md5, 64, hex)
+ return hmac(key, message, hashes.md5, 64, hex)
end
function sha1(key, message, hex)
- return hmac(key, message, hashes.sha1, 64, hex)
+ return hmac(key, message, hashes.sha1, 64, hex)
end
function sha256(key, message, hex)
- return hmac(key, message, hashes.sha256, 64, hex)
+ return hmac(key, message, hashes.sha256, 64, hex)
end
return _M