diff --git a/lib/namespaced.php b/lib/namespaced.php index eab91b64..93864ba5 100644 --- a/lib/namespaced.php +++ b/lib/namespaced.php @@ -1,4 +1,5 @@ = $unpadded_len) { $padded[$j] = "\0"; diff --git a/src/Core/AEGIS/State128L.php b/src/Core/AEGIS/State128L.php index c5c4585c..3e33cf74 100644 --- a/src/Core/AEGIS/State128L.php +++ b/src/Core/AEGIS/State128L.php @@ -1,4 +1,5 @@ > 8); + /** @psalm-suppress InvalidArrayOffset */ $tmp = (self::subWord($tmp) ^ self::Rcon[$k]) & self::U32_MAX; } elseif ($nk > 6 && $j === 4) { $tmp = self::subWord($tmp); diff --git a/src/Core/AES/Block.php b/src/Core/AES/Block.php index ac5524bb..ae39b82e 100644 --- a/src/Core/AES/Block.php +++ b/src/Core/AES/Block.php @@ -1,4 +1,5 @@ $fill) { # memcpy( S->buf + left, in, fill ); /* Fill buffer */ for ($i = $fill; $i--;) { - $ctx[3][$i + $left] = $p[$i + $offset]; + $ctx[3][$i + $left] = $p[(int) ($i + $offset)]; } # S->buflen += fill; @@ -477,7 +478,7 @@ public static function update(SplFixedArray $ctx, SplFixedArray $p, int $plen): $plen -= $fill; } else { for ($i = $plen; $i--;) { - $ctx[3][$i + $left] = $p[$i + $offset]; + $ctx[3][$i + $left] = $p[(int) ($i + $offset)]; } $ctx[4] += $plen; $offset += $plen; diff --git a/src/Core/Base64/Original.php b/src/Core/Base64/Original.php index ce6daa09..683e8f5f 100644 --- a/src/Core/Base64/Original.php +++ b/src/Core/Base64/Original.php @@ -1,4 +1,5 @@ + * @psalm-suppress MissingTemplateParam */ class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util implements ArrayAccess { diff --git a/src/Core/ChaCha20/IetfCtx.php b/src/Core/ChaCha20/IetfCtx.php index 3e5b9014..f75070a6 100644 --- a/src/Core/ChaCha20/IetfCtx.php +++ b/src/Core/ChaCha20/IetfCtx.php @@ -1,4 +1,5 @@ $chunk */ - $chunk = unpack('C', $bin_string[$i]); - /** - * Lower 16 bits - */ - $c = $chunk[1] & 0xf; - - /** - * Upper 16 bits - */ - $b = $chunk[1] >> 4; - - /** - * Use pack() and binary operators to turn the two integers - * into hexadecimal characters. We don't use chr() here, because - * it uses a lookup table internally and we want to avoid - * cache-timing side-channels. - */ - $hex .= pack( - 'CC', - (55 + $b + ((($b - 10) >> 8) & ~6)), - (55 + $c + ((($c - 10) >> 8) & ~6)) - ); - } - return $hex; - } - /** * Cache-timing-safe variant of ord() * @@ -191,85 +148,6 @@ public static function compare( return ($gt + $gt + $eq) - 1; } - /** - * If a variable does not match a given type, throw a TypeError. - * - * @param mixed $mixedVar - * @param string $type - * @param int $argumentIndex - * @throws TypeError - * @throws SodiumException - * @return void - */ - public static function declareScalarType( - #[SensitiveParameter] - mixed &$mixedVar = null, - string $type = 'void', - int $argumentIndex = 0 - ): void { - if (func_num_args() === 0) { - /* Tautology, by default */ - return; - } - if (func_num_args() === 1) { - throw new TypeError('Declared void, but passed a variable'); - } - $realType = strtolower(gettype($mixedVar)); - $type = strtolower($type); - switch ($type) { - case 'null': - if ($mixedVar !== null) { - throw new TypeError('Argument ' . $argumentIndex . ' must be null, ' . $realType . ' given.'); - } - break; - case 'integer': - case 'int': - $allow = array('int', 'integer'); - if (!in_array($type, $allow)) { - throw new TypeError('Argument ' . $argumentIndex . ' must be an integer, ' . $realType . ' given.'); - } - $mixedVar = (int) $mixedVar; - break; - case 'boolean': - case 'bool': - $allow = array('bool', 'boolean'); - if (!in_array($type, $allow)) { - throw new TypeError('Argument ' . $argumentIndex . ' must be a boolean, ' . $realType . ' given.'); - } - $mixedVar = (bool) $mixedVar; - break; - case 'string': - if (!is_string($mixedVar)) { - throw new TypeError('Argument ' . $argumentIndex . ' must be a string, ' . $realType . ' given.'); - } - break; - case 'decimal': - case 'double': - case 'float': - $allow = array('decimal', 'double', 'float'); - if (!in_array($type, $allow)) { - throw new TypeError('Argument ' . $argumentIndex . ' must be a float, ' . $realType . ' given.'); - } - $mixedVar = (float) $mixedVar; - break; - case 'object': - if (!is_object($mixedVar)) { - throw new TypeError('Argument ' . $argumentIndex . ' must be an object, ' . $realType . ' given.'); - } - break; - case 'array': - if (!is_array($mixedVar)) { - if ($mixedVar instanceof ArrayAccess) { - return; - } - throw new TypeError('Argument ' . $argumentIndex . ' must be an array, ' . $realType . ' given.'); - } - break; - default: - throw new SodiumException('Unknown type (' . $realType .') does not match expect type (' . $type . ')'); - } - } - /** * Evaluate whether or not two strings are equal (in constant-time) * @@ -570,6 +448,7 @@ public static function mul( * * @param int|float $num * @return array + * @psalm-suppress RedundantCastGivenDocblockType */ public static function numericTo64BitInteger(int|float $num): array { @@ -593,22 +472,7 @@ public static function numericTo64BitInteger(int|float $num): array * @var int $high * @var int $low */ - return array($high, $low); - } - - /** - * Store a 24-bit integer into a string, treating it as big-endian. - * - * @internal You should not use this directly from another application - * - * @param int $int - * @return string - * @throws TypeError - */ - public static function store_3(int $int): string - { - $packed = pack('N', $int); - return self::substr($packed, 1, 3); + return array((int) $high, (int) $low); } /** @@ -625,20 +489,6 @@ public static function store32_le(int $int): string return pack('V', $int); } - /** - * Store a 32-bit integer into a string, treating it as big-endian. - * - * @internal You should not use this directly from another application - * - * @param int $int - * @return string - * @throws TypeError - */ - public static function store_4(int $int): string - { - return pack('N', $int); - } - /** * Stores a 64-bit integer as an string, treating it as little-endian. * diff --git a/src/Core/X25519.php b/src/Core/X25519.php index 967d31fa..8090d43d 100644 --- a/src/Core/X25519.php +++ b/src/Core/X25519.php @@ -1,4 +1,5 @@ assertTrue(ParagonIE_Sodium_File::verify($sigA, 'test.txt', $public)); $this->assertTrue(sodium_crypto_sign_verify_detached($sigB, $message, $public)); + unlink('test.txt'); } }