@@ -4816,6 +4816,24 @@ local function hmac(hash_func, key, message)
4816
4816
end
4817
4817
end
4818
4818
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
4819
4837
4820
4838
local function xor_blake2_salt (salt , letter , H_lo , H_hi )
4821
4839
-- salt: concatenation of "Salt"+"Personalization" fields
@@ -5621,6 +5639,8 @@ local sha = {
5621
5639
shake256 = function (digest_size_in_bytes , message ) return keccak ((1600 - 2 * 256 ) / 8 , digest_size_in_bytes , true , message ) end , -- SHAKE256
5622
5640
-- HMAC:
5623
5641
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
5624
5644
-- misc utilities:
5625
5645
hex_to_bin = hex_to_bin , -- converts hexadecimal representation to binary string
5626
5646
bin_to_hex = bin_to_hex , -- converts binary string to hexadecimal representation
0 commit comments