If Node crypto.PBKDF2 uses HMAC SHA-1, how can the key be longer than 20 bytes?
Here is what I understand (obviously wrong): crypto.PBKDF2(password, salt, iterations, keylen, callback) uses HMAC SHA-1 to hash the password with salt. Then he takes this hash and hashes it with the same salt. He repeats that for how many iterations you talk about it, and then it passes the result. The result is truncated to the number of bytes you specify in keylen .
SHA-1 outputs 160 bits or 20 bytes. However, I can request keylen more than 20 bytes from crypto.PBKDF2 , and after the 20th byte the data is not repeated. That doesn't make sense to me.
What i don't understand here?
Try:
c.pbkdf2('password', 'salt', 1, 21, function(err, key) { for (var i = 0; i < key.length; i++) { console.log(key[i].toString(36)); } });
I would expect to see some kind of pattern after the 20th byte, but I do not.
source share