Created
February 9, 2016 22:23
-
-
Save paragonie-scott/697438aba38d8bed30d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scott@debian ~ $ php -dmbstring.func_overload=2 sammy_test.php | |
bool(true) | |
scott@debian ~ $ php sammy_test.php | |
bool(false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sammy_hash_equals($knownString, $userString) | |
{ | |
$kLen = strlen($knownString); | |
$uLen = strlen($userString); | |
if ($kLen !== $uLen) { | |
return false; | |
} | |
$result = 0; | |
for ($i = 0; $i < $kLen; $i++) { | |
$result |= (ord($knownString[$i]) ^ ord($userString[$i])); | |
} | |
// They are only identical strings if $result is exactly 0... | |
return 0 === $result; | |
} | |
// 4 chars but 16 bytes | |
$hashA = "\xF0\x9D\x92\xB3" . "\xF0\x9D\x92\xB3" . "\xF0\x9D\x92\xB3". "\xF0\x9D\x92\xB3"; | |
$hashB = "\xF0\x9D\x92\xB3" . "\xF0\x9D\x92\xB4" . "\xF0\x9D\x92\xB4" . "\xF0\x9D\x92\xB4"; | |
var_dump(sammy_hash_equals($hashA, $hashB)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment