ParagonIE_Sodium_Core_Util
- Source
wp-includes/sodium_compat/src/Core/Util.php:10
Class ParagonIE_Sodium_Core_Util
Compatibility
- WordPress
- core
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Methods · 29
- abs()
- andStrings()
- bin2hex()Convert a binary string into a hexadecimal string without cache-timing leaks
- bin2hexUpper()Convert a binary string into a hexadecimal string without cache-timing leaks, returning uppercase letters (as per RFC 4648)
- chrToInt()Cache-timing-safe variant of ord()
- compare()Compares two strings.
- declareScalarType()If a variable does not match a given type, throw a TypeError.
- hashEquals()Evaluate whether or not two strings are equal (in constant-time)
- hash_update()Catch hash_update() failures and throw instead of silently proceeding
- hex2bin()Convert a hexadecimal string into a binary string without cache-timing leaks
- intArrayToString()Turn an array of integers into a string
- intToChr()Cache-timing-safe variant of ord()
- load_3()Load a 3 character substring into an integer
- load_4()Load a 4 character substring into an integer
- load64_le()Load a 8 character substring into an integer
- memcmp()
- mul()Multiply two integers in constant-time
- numericTo64BitInteger()Convert any arbitrary numbers into two 32-bit integers that represent a 64-bit integer.
- store_3()Store a 24-bit integer into a string, treating it as big-endian.
- store32_le()Store a 32-bit integer into a string, treating it as little-endian.
- store_4()Store a 32-bit integer into a string, treating it as big-endian.
- store64_le()Stores a 64-bit integer as an string, treating it as little-endian.
- strlen()Safe string length
- stringToIntArray()Turn a string into an array of integers
- substr()Safe substring
- verify_16()Compare a 16-character byte string in constant time.
- verify_32()Compare a 32-character byte string in constant time.
- xorStrings()Calculate $a ^ $b for two strings.
- isMbStringOverride()Returns whether or not mbstring.func_overload is in effect.
Source code
abstract class ParagonIE_Sodium_Core_Util{ const U32_MAX = 0xFFFFFFFF; /** * @param int $integer * @param int $size (16, 32, 64) * @return int */ public static function abs($integer, $size = 0) { /** @var int $realSize */ $realSize = (PHP_INT_SIZE << 3) - 1; if ($size) { --$size; } else { /** @var int $size */ $size = $realSize; } $negative = -(($integer >> $size) & 1); return (int) ( ($integer ^ $negative) + (($negative >> $realSize) & 1) ); } /** * @param string $a * @param string $b * @return string * @throws SodiumException */ public static function andStrings($a, $b) { /* Type checks: */ if (!is_string($a)) { throw new TypeError('Argument 1 must be a string'); } if (!is_string($b)) { throw new TypeError('Argument 2 must be a string'); } $len = self::strlen($a); if (self::strlen($b) !== $len) { throw new SodiumException('Both strings must be of equal length to combine with bitwise AND'); } return $a & $b; } /** * Convert a binary string into a hexadecimal string without cache-timing * leaks * * @internal You should not use this directly from another application * * @param string $binaryString (raw binary) * @return string * @throws TypeError */ public static function bin2hex($binaryString) { /* Type checks: */ if (!is_string($binaryString)) { throw new TypeError('Argument 1 must be a string, ' . gettype($binaryString) . ' given.'); } $hex = ''; $len = self::strlen($binaryString); for ($i = 0; $i < $len; ++$i) { /** @var array<int, int> $chunk */ $chunk = unpack('C', $binaryString[$i]); /** @var int $c */ $c = $chunk[1] & 0xf; /** @var int $b */ $b = $chunk[1] >> 4; $hex .= pack( 'CC', (87 + $b + ((($b - 10) >> 8) & ~38)), (87 + $c + ((($c - 10) >> 8) & ~38))Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/sodium_compat/src/Core/Util.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.