In an answer to another question of mine, it was noted that a class using standard string comparison functions when checking the HMAC in authenticated encryption would make the class vulnerable to timing attacks against the HMAC.
I can't wrap my head around how this a timing attack against the HMAC of authenticated encryption be an issue?
First of all, the implementations should be considered known to the attacker (in this particular case the source is simply published), so the only thing secret would be the key. Following this line of reasoning, how would a constant-time comparison function in the implementation protect against anything? (I would expect the attacker to simply remove it, if he would even use the same code).
And second, if I would think about the implementation as a black-box, the comparison is against a HMAC of the data with a PBKDF2 derived key. Wouldn't trying a timing attack against the HMAC be a) just as slow as trying to brute-force a PBKDF2 protected password b) not really disclose any information helpful in any attempt to decrypt the data? (the HMAC even appended to the cipher text, available to everyone with access to the encrypted data).
So, what am I missing here, why are timing attacks in this scenario considered a risk that needs protecting against?
Quick update:
I understand how timing attacks work, but I do not understand what would be gained by employing a timing attack in a scenario where the decrypt function looks like:
/**
* @param binary $data Where $data = salt, IV, encrypted data, HMAC(salt, IV, encrypted data)
* @param string $password The decrypt-password
* @return string|null plain text if data was successfully decrypted, null otherwise
*/
function decrypt($data, $password) {
...
}