libs/hashes.lua

changeset 398
b4ce2e524ed8
parent 389
bf3a4fcdcb76
child 414
2a5eff919f4a
equal deleted inserted replaced
397:918829f384d6 398:b4ce2e524ed8
33 local s_char = string.char; 33 local s_char = string.char;
34 local s_byte = string.byte; 34 local s_byte = string.byte;
35 local t_concat = table.concat; 35 local t_concat = table.concat;
36 36
37 local function hmac_sha1(key, message, hexres) 37 local function hmac_sha1(key, message, hexres)
38 if #key > 20 then 38 if #key > 64 then
39 key = sha1(key); 39 key = sha1(key);
40 elseif #key < 20 then 40 elseif #key < 64 then
41 key = key .. s_rep("\0", 20 - #key); 41 key = key .. s_rep("\0", 64 - #key);
42 end 42 end
43 local o_key_pad, i_key_pad = {}, {} 43 local o_key_pad, i_key_pad = {}, {}
44 for i = 1, 20 do 44 for i = 1, 64 do
45 local b = s_byte(key, i) 45 local b = s_byte(key, i)
46 o_key_pad[i] = s_char(bxor(b, 0x5c)); 46 o_key_pad[i] = s_char(bxor(b, 0x5c));
47 i_key_pad[i] = s_char(bxor(b, 0x36)); 47 i_key_pad[i] = s_char(bxor(b, 0x36));
48 end 48 end
49 o_key_pad = t_concat(o_key_pad); 49 o_key_pad = t_concat(o_key_pad);

mercurial