wip
This commit is contained in:
@@ -181,6 +181,8 @@ abstract class ParagonIE_Sodium_Core_Util
|
||||
$len = max($leftLen, $rightLen);
|
||||
$left = str_pad($left, $len, "\x00", STR_PAD_RIGHT);
|
||||
$right = str_pad($right, $len, "\x00", STR_PAD_RIGHT);
|
||||
} elseif ($leftLen !== $rightLen) {
|
||||
throw new SodiumException("Argument #1 and argument #2 must have the same length");
|
||||
}
|
||||
|
||||
$gt = 0;
|
||||
@@ -336,7 +338,8 @@ abstract class ParagonIE_Sodium_Core_Util
|
||||
* @param string $ignore
|
||||
* @param bool $strictPadding
|
||||
* @return string (raw binary)
|
||||
* @throws RangeException
|
||||
*
|
||||
* @throws SodiumException
|
||||
* @throws TypeError
|
||||
*/
|
||||
public static function hex2bin($hexString, $ignore = '', $strictPadding = false)
|
||||
@@ -354,16 +357,6 @@ abstract class ParagonIE_Sodium_Core_Util
|
||||
$c_acc = 0;
|
||||
$hex_len = self::strlen($hexString);
|
||||
$state = 0;
|
||||
if (($hex_len & 1) !== 0) {
|
||||
if ($strictPadding) {
|
||||
throw new RangeException(
|
||||
'Expected an even number of hexadecimal characters'
|
||||
);
|
||||
} else {
|
||||
$hexString = '0' . $hexString;
|
||||
++$hex_len;
|
||||
}
|
||||
}
|
||||
|
||||
$chunk = unpack('C*', $hexString);
|
||||
while ($hex_pos < $hex_len) {
|
||||
@@ -390,6 +383,11 @@ abstract class ParagonIE_Sodium_Core_Util
|
||||
}
|
||||
$state ^= 1;
|
||||
}
|
||||
if ($strictPadding && $state !== 0) {
|
||||
throw new SodiumException(
|
||||
'Expected an even number of hexadecimal characters'
|
||||
);
|
||||
}
|
||||
return $bin;
|
||||
}
|
||||
|
||||
@@ -534,10 +532,8 @@ abstract class ParagonIE_Sodium_Core_Util
|
||||
*/
|
||||
public static function memcmp($left, $right)
|
||||
{
|
||||
if (self::hashEquals($left, $right)) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
$e = (int) !self::hashEquals($left, $right);
|
||||
return 0 - $e;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user