clear

p       "password"
salt    "ftsafe"
iter    08

x       call script_pbkdf2_sha256$p$salt$iter20 )
y       pbkdf2_sha256$p$salt$iter20 )
if $x != $y
    
?
    
pause
endif

x       call script_pbkdf2_sha256$p$salt$iter70 )
y       pbkdf2_sha256$p$salt$iter70 )
if $x != $y
    
?
    
pause
endif

end


script_pbkdf2_sha256:
    
prompt off
    
local password
    
local salt
    
local iterations
    
local needlen
    
local count
    
local t
    
local u
    
local dk

    
password    getpara
    
salt        getpara
    
iterations  getpara
    
needlen     getpara


    
count       01
    
dk          ""

    
max         hex( ( 0x$needlen + 31 ) / 32 )

    
hfor i = 01 to $max
        
count   leftpack$count4 )
        
count   right$count4 )
        
u       hmac_sha256$salt $count$password )
        
t       $u
        
hfor j = 01 to hex0x$iterations - 1 )
            
u   hmac_sha256$u$password )
            
t   memxor$t00$u )
        
hnext j
        
dk      $dk $t
        
count   add$count01 )
    
hnext i

    
dk          hmid$dk00$needlen )
    
prompt on
return $dk