To securely hash passwords, algorithms such as PBKDF2 do many iterations of a common hash such as SHA1. Are there certain ways that these iterations need to be done to be safe?
In particular, from password-hash.js:
function generateHash(algorithm, salt, password, iterations) {
iterations = iterations || 1;
try {
var hash = password;
for(var i=0; i<iterations; ++i) {
hash = crypto.createHmac(algorithm, salt).update(hash).digest('hex');
}
return algorithm + '$' + salt + '$' + iterations + '$' + hash;
} catch (e) {
throw new Error('Invalid message digest algorithm');
}
}
Is this a safe way to hash the password? I can imagine that if you have an algorithm such as this that does:
HMAC(HMAC(HMAC(password)))
then there exists some faster function
HMAC3(password)
that gives the same output. Is this the case?