@@ -34,6 +34,9 @@ class PasswordEncoder
34
34
const ALGORITHM_MAC = 'MAC ' ;
35
35
const ALGORITHM_HMAC = 'HMAC ' ;
36
36
37
+ private const ALL_ONE_BITS = (PHP_INT_SIZE > 4 ) ? 0xFFFFFFFF : -1 ;
38
+ private const HIGH_ORDER_BIT = (PHP_INT_SIZE > 4 ) ? 0x80000000 : PHP_INT_MIN ;
39
+
37
40
/**
38
41
* Mapping between algorithm name and algorithm ID.
39
42
*
@@ -128,7 +131,7 @@ public static function hashPassword($password, $algorithmName = self::ALGORITHM_
128
131
// build low-order word and hig-order word and combine them
129
132
$ combinedKey = self ::buildCombinedKey ($ byteChars );
130
133
// build reversed hexadecimal string
131
- $ hex = str_pad (strtoupper (dechex ($ combinedKey & 0xFFFFFFFF )), 8 , '0 ' , \STR_PAD_LEFT );
134
+ $ hex = str_pad (strtoupper (dechex ($ combinedKey & self :: ALL_ONE_BITS )), 8 , '0 ' , \STR_PAD_LEFT );
132
135
$ reversedHex = $ hex [6 ] . $ hex [7 ] . $ hex [4 ] . $ hex [5 ] . $ hex [2 ] . $ hex [3 ] . $ hex [0 ] . $ hex [1 ];
133
136
134
137
$ generatedKey = mb_convert_encoding ($ reversedHex , 'UCS-2LE ' , 'UTF-8 ' );
@@ -232,10 +235,10 @@ private static function buildCombinedKey($byteChars)
232
235
*/
233
236
private static function int32 ($ value )
234
237
{
235
- $ value = ( $ value & 0xFFFFFFFF ) ;
238
+ $ value = $ value & self :: ALL_ONE_BITS ;
236
239
237
- if ($ value & 0x80000000 ) {
238
- $ value = -((~$ value & 0xFFFFFFFF ) + 1 );
240
+ if ($ value & self :: HIGH_ORDER_BIT ) {
241
+ $ value = -((~$ value & self :: ALL_ONE_BITS ) + 1 );
239
242
}
240
243
241
244
return $ value ;
0 commit comments