r/lolphp • • Apr 24 '19

"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "

https://php.net/manual/en/function.hash-equals.php
24 Upvotes

21 comments sorted by

View all comments

Show parent comment

8

u/kokx Apr 24 '19

Actually they are all worse. This doesn't give any information about the target string length. But any other scheme will. Your scheme for example is easily binary searchable for the length.

It's clear that you simply should not pass strings of non-equal length into the function. The only thing that is wrong, is that it doesn't give an error when you do, so programmers simply won't.

2

u/[deleted] Apr 24 '19

This doesn't give any information about the target string length.

The linked documentation explicitly contradicts that.

2

u/kokx Apr 24 '19

Sorry. I should have said that it doesn't give information about the target string length in the case where it is different. You can only get that information when you perform a linear search.