wp/wp-includes/sodium_compat/src/Core/Util.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
     7 /**
     7 /**
     8  * Class ParagonIE_Sodium_Core_Util
     8  * Class ParagonIE_Sodium_Core_Util
     9  */
     9  */
    10 abstract class ParagonIE_Sodium_Core_Util
    10 abstract class ParagonIE_Sodium_Core_Util
    11 {
    11 {
       
    12     const U32_MAX = 0xFFFFFFFF;
       
    13 
    12     /**
    14     /**
    13      * @param int $integer
    15      * @param int $integer
    14      * @param int $size (16, 32, 64)
    16      * @param int $size (16, 32, 64)
    15      * @return int
    17      * @return int
    16      */
    18      */
    29         return (int) (
    31         return (int) (
    30             ($integer ^ $negative)
    32             ($integer ^ $negative)
    31                 +
    33                 +
    32             (($negative >> $realSize) & 1)
    34             (($negative >> $realSize) & 1)
    33         );
    35         );
       
    36     }
       
    37 
       
    38     /**
       
    39      * @param string $a
       
    40      * @param string $b
       
    41      * @return string
       
    42      * @throws SodiumException
       
    43      */
       
    44     public static function andStrings($a, $b)
       
    45     {
       
    46         /* Type checks: */
       
    47         if (!is_string($a)) {
       
    48             throw new TypeError('Argument 1 must be a string');
       
    49         }
       
    50         if (!is_string($b)) {
       
    51             throw new TypeError('Argument 2 must be a string');
       
    52         }
       
    53         $len = self::strlen($a);
       
    54         if (self::strlen($b) !== $len) {
       
    55             throw new SodiumException('Both strings must be of equal length to combine with bitwise AND');
       
    56         }
       
    57         return $a & $b;
    34     }
    58     }
    35 
    59 
    36     /**
    60     /**
    37      * Convert a binary string into a hexadecimal string without cache-timing
    61      * Convert a binary string into a hexadecimal string without cache-timing
    38      * leaks
    62      * leaks