@@ -4816,6 +4816,24 @@ local function hmac(hash_func, key, message)
48164816 end
48174817end
48184818
4819+ local function strXOR (s1 , s2 )
4820+ local b3 = " "
4821+ for i = 1 ,# s1 do
4822+ b3 = b3 .. char (XOR (s1 :byte (i ),s2 :byte (i )))
4823+ end
4824+ return b3
4825+ end
4826+ local function pbkdf2 (hash_func , pw , salt , it )
4827+ local u = hex_to_bin (hmac (hash_func , pw , salt .. " \0\0\0\1 " ))
4828+ local t = u
4829+
4830+ for _ = 2 ,it do
4831+ u = hex_to_bin (hmac (hash_func , pw , u ))
4832+ t = strXOR (t , u )
4833+ end
4834+
4835+ return bin_to_hex (t )
4836+ end
48194837
48204838local function xor_blake2_salt (salt , letter , H_lo , H_hi )
48214839 -- salt: concatenation of "Salt"+"Personalization" fields
@@ -5621,6 +5639,8 @@ local sha = {
56215639 shake256 = function (digest_size_in_bytes , message ) return keccak ((1600 - 2 * 256 ) / 8 , digest_size_in_bytes , true , message ) end , -- SHAKE256
56225640 -- HMAC:
56235641 hmac = hmac , -- HMAC(hash_func, key, message) is applicable to any hash function from this module except SHAKE* and BLAKE*
5642+ -- PBKDF2:
5643+ pbkdf2 = pbkdf2 ,-- PBKDF2(hash_func, password, salt, iter_num) same limit with HMAC
56245644 -- misc utilities:
56255645 hex_to_bin = hex_to_bin , -- converts hexadecimal representation to binary string
56265646 bin_to_hex = bin_to_hex , -- converts binary string to hexadecimal representation
0 commit comments