4 ms·
(In this case a better way to do the compare is if the strings are not the same length, compare the attackers string against itself, and then return false.) Is
by nitrogen 12y ago
(In this case a better way to do the compare is if the strings are not the same length, compare the attackers string against itself, and then return false.)
Is there a reason for using the attacker's string rather than the valid string? Edit: it doesn't seem to me that using the valid string would leak its length unless the attacker knew quite a lot about the target machine.
- plorkyeran 12y agoHow long it takes to do the comparison reveals the length of the string being checked, so you have to check the string which the attacker knows the length of already.
- kentonv 12y ago> Edit: it doesn't seem to me that using the valid string would leak its length unless the attacker knew quite a lot about the target machine. It sounds like you are skeptical that timing attacks can be practically exploited. This is a reasonable skepticism that most people go through on initially learning about them. Unfortunately, there are in fact working exploits for this sort of thing.
- nitrogen 12y agoNo, I definitely realize the seriousness of timing attacks. I'm just curious about this particular implementation detail. I would have guessed that using the attacker's length would reveal more about the system than using a fixed length (unless the length of the valid string changed frequently). I'd like to understand why that isn't the case.
- kentonv 12y agoAh, I see, you're assuming the "valid" string is fixed-width across all requests. I guess in that specific case you might be right. But it's easy for that not to be the case: e.g. if there are several different resources an attacker can request that have different-length strings. For example, an attacker might scan for users with short (=bad) passwords by comparing the time it takes to complete an authentication check against various users. So the safe thing to go is to go with the attacker's string.