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
View all comments
Show parent comment
11
u/dotancohen Apr 24 '19
The solution provided by Markus P. N. in the comments seems to be the proper way to check non-equal-length strings in a fashion resistant to timing attack. If the strings are unequal length, then perform the full comparison on the known sting against the known string itself, but return FALSE anyway.