https://bugzilla.wikimedia.org/show_bug.cgi?id=28419

--- Comment #96 from [email protected] ---
> return md5( $salt.'-'.md5( $password ) ) == $realHash;
> return self::crypt( $password, $salt ) == $hash;
> return self::reallyOldCrypt( $password, $userId ) === $hash;

Can we swap out the == and === logic for one of the following:

- Constant time hash comparison code (see hash_equals() in PHP 5.6.0 and PHP
implementations, such as Taylor Hornby's PBKDF2 library)?
- "Double HMAC" with a random nonce

i.e.
+    /**
+     * A comparison of two strings, not vulnerable to timing attacks
+     * @param string $answer the secret string that you are comparing against.
+     * @param string $test compare this string to the $answer.
+     * @return bool True if the strings are the same, false otherwise
+     */
+    static function hash_equals( $answer, $test ) {
+        if (function_exists('hash_equals')) {
+            return hash_equals($answer, $test);
+        } //
+        if ( strlen( $answer ) !== strlen( $test ) ) {
+            $passwordCorrect = false;
+        } else {
+            $result = 0;
+            for ( $i = 0; $i < strlen( $answer ); $i++ ) {
+                $result |= ord( $answer[$i] ) ^ ord( $test[$i] );
+            } //
+            $passwordCorrect = ( $result === 0 );
+        } //
+        return $passwordCorrect;
+    } //

OR

+    /**
+     * A comparison of two strings, not vulnerable to timing attacks
+     * @param string $answer the secret string that you are comparing against.
+     * @param string $test compare this string to the $answer.
+     * @return bool True if the strings are the same, false otherwise
+     */
+    static function hash_equals( $answer, $test ) {
+        if (function_exists('hash_equals')) {
+            return hash_equals($answer, $test);
+        } //
+        $nonce = MWCryptRand::generate(16);
+        return hash_hmac('sha256', $test, $nonce) === hash_hmac('sha256',
$answer, $nonce);
+    } //

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to