I had a discussion with a friend today about his password hash comparison. I argued that you can't return false on the first hash mismatch you have and I sent him a link to an article about a Java timing attack that happened in Java 6.
public static boolean isEqual(byte digesta[], byte digestb[]) {
for (int i = 0; i < digesta.length; i++) {
if (digesta[i] != digestb[i]) {
return false;
}
}
return true;
}
And my version, which I think is correct:
public static boolean isEqual(byte digesta[], byte digestb[]) {
boolean isEquals = true;
//this avoid a possible timing attack
for (int i = 0; i < digesta.length; i++) {
if (digesta[i] != digestb[i]) {
isEquals = false;
}
}
return isEquals;
}
Which, for me, indicates there is a possible timing attack that could be done because you return false if there is a mismatch in the hash. He argued that this would not be a risk in the application and that the important thing is that the password is salted and hashed and that will probably will not affect the security of the application.
Am I paranoid about the security of my application?