File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,6 @@ private function __construct()
3838 */
3939 public static function equals ($ knownString , $ userInput )
4040 {
41- if (function_exists ('hash_equals ' )) {
42- return hash_equals ($ knownString , $ userInput );
43- }
44-
4541 // Avoid making unnecessary duplications of secret data
4642 if (!is_string ($ knownString )) {
4743 $ knownString = (string ) $ knownString ;
@@ -51,16 +47,20 @@ public static function equals($knownString, $userInput)
5147 $ userInput = (string ) $ userInput ;
5248 }
5349
50+ if (function_exists ('hash_equals ' )) {
51+ return hash_equals ($ knownString , $ userInput );
52+ }
53+
5454 $ knownLen = self ::safeStrlen ($ knownString );
5555 $ userLen = self ::safeStrlen ($ userInput );
5656
57- // Set the result to the difference between the lengths
58- $ result = $ knownLen - $ userLen ;
57+ if ($ userLen != $ knownLen ) {
58+ return false ;
59+ }
5960
60- // Always iterate over the minimum length possible.
61- $ iterationLen = min ($ knownLen , $ userLen );
61+ $ result = 0 ;
6262
63- for ($ i = 0 ; $ i < $ iterationLen ; $ i ++) {
63+ for ($ i = 0 ; $ i < $ knownLen ; $ i ++) {
6464 $ result |= (ord ($ knownString [$ i ]) ^ ord ($ userInput [$ i ]));
6565 }
6666
You can’t perform that action at this time.
0 commit comments