diff --git a/.gitignore b/.gitignore index 2ce18fd0cee68..fea6b1c925bcc 100644 --- a/.gitignore +++ b/.gitignore @@ -89,6 +89,7 @@ Desktop.ini /libraries/vendor/joomla/*/composer.json /libraries/vendor/joomla/*/phpunit.xml.dist /libraries/vendor/joomla/*/README.md +/libraries/vendor/joomla/*/ruleset.xml /libraries/vendor/joomla/session/Joomla/Session/.github /libraries/vendor/joomla/session/Joomla/Session/_Tests /libraries/vendor/joomla/session/Joomla/Session/build @@ -121,8 +122,11 @@ Desktop.ini /libraries/vendor/paragonie/random_compat/psalm.xml /libraries/vendor/paragonie/random_compat/tests /libraries/vendor/paragonie/sodium_compat/.gitignore +/libraries/vendor/paragonie/sodium_compat/appveyor.yml +/libraries/vendor/paragonie/sodium_compat/build-phar.sh /libraries/vendor/paragonie/sodium_compat/composer.json /libraries/vendor/paragonie/sodium_compat/composer.lock +/libraries/vendor/paragonie/sodium_compat/dist /libraries/vendor/paragonie/sodium_compat/phpunit.xml.dist /libraries/vendor/paragonie/sodium_compat/README.md /libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/README.md @@ -142,10 +146,15 @@ Desktop.ini /libraries/vendor/phpmailer/phpmailer/UPGRADING.md /libraries/vendor/phpmailer/phpmailer/extras/README.md /libraries/vendor/phpmailer/phpmailer/get_oauth_token.php +/libraries/vendor/psr/container/.gitignore +/libraries/vendor/psr/container/composer.json +/libraries/vendor/psr/container/README.md /libraries/vendor/psr/log/Psr/Log/Test /libraries/vendor/psr/log/.gitignore /libraries/vendor/psr/log/composer.json /libraries/vendor/psr/log/README.md +/libraries/vendor/symfony/polyfill-ctype/composer.json +/libraries/vendor/symfony/polyfill-ctype/README.md /libraries/vendor/symfony/polyfill-php55/composer.json /libraries/vendor/symfony/polyfill-php55/README.md /libraries/vendor/symfony/polyfill-php56/composer.json @@ -154,7 +163,9 @@ Desktop.ini /libraries/vendor/symfony/polyfill-php73/README.md /libraries/vendor/symfony/polyfill-util/composer.json /libraries/vendor/symfony/polyfill-util/README.md +/libraries/vendor/symfony/polyfill-util/LegacyTestListener.php /libraries/vendor/symfony/polyfill-util/TestListener.php +/libraries/vendor/symfony/polyfill-util/TestListenerTrait.php /libraries/vendor/symfony/yaml/Tests /libraries/vendor/symfony/yaml/.gitignore /libraries/vendor/symfony/yaml/CHANGELOG.md diff --git a/composer.lock b/composer.lock index 1961a7ac1dd04..515df457e2c4d 100644 --- a/composer.lock +++ b/composer.lock @@ -50,16 +50,16 @@ }, { "name": "joomla/application", - "version": "1.9.0", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/joomla-framework/application.git", - "reference": "f32371fc988356bbf052396dcfd782effdd74b6d" + "reference": "a0360e578933e20e98da5c8e17cda72e2b5e2024" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/application/zipball/f32371fc988356bbf052396dcfd782effdd74b6d", - "reference": "f32371fc988356bbf052396dcfd782effdd74b6d", + "url": "https://api.github.com/repos/joomla-framework/application/zipball/a0360e578933e20e98da5c8e17cda72e2b5e2024", + "reference": "a0360e578933e20e98da5c8e17cda72e2b5e2024", "shasum": "" }, "require": { @@ -102,7 +102,7 @@ "framework", "joomla" ], - "time": "2018-05-20T15:35:58+00:00" + "time": "2018-05-28T15:32:35+00:00" }, { "name": "joomla/archive", @@ -244,24 +244,28 @@ }, { "name": "joomla/di", - "version": "1.4.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/joomla-framework/di.git", - "reference": "756c6eb4554b9007f69da66cf488a05308251ed8" + "reference": "33c66e4091e4433f33ddf4a0ac36604cf3b73c41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/di/zipball/756c6eb4554b9007f69da66cf488a05308251ed8", - "reference": "756c6eb4554b9007f69da66cf488a05308251ed8", + "url": "https://api.github.com/repos/joomla-framework/di/zipball/33c66e4091e4433f33ddf4a0ac36604cf3b73c41", + "reference": "33c66e4091e4433f33ddf4a0ac36604cf3b73c41", "shasum": "" }, "require": { - "php": "^5.3.10|~7.0" + "php": "^5.3.10|~7.0", + "psr/container": "~1.0" + }, + "provide": { + "psr/container-implementation": "~1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", - "squizlabs/php_codesniffer": "1.*" + "joomla/coding-standards": "~2.0@alpha", + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, "type": "joomla-package", "extra": { @@ -276,7 +280,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla DI Package", "homepage": "https://github.com/joomla-framework/di", @@ -288,7 +292,7 @@ "ioc", "joomla" ], - "time": "2017-11-12T15:35:19+00:00" + "time": "2018-02-25T16:30:45+00:00" }, { "name": "joomla/event", @@ -437,16 +441,16 @@ }, { "name": "joomla/image", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/image.git", - "reference": "d5a76037add34f95e970e9d8c8a449feeb781286" + "reference": "8885c6db5d5b3653ad30d4ad4f73607925a725a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/image/zipball/d5a76037add34f95e970e9d8c8a449feeb781286", - "reference": "d5a76037add34f95e970e9d8c8a449feeb781286", + "url": "https://api.github.com/repos/joomla-framework/image/zipball/8885c6db5d5b3653ad30d4ad4f73607925a725a5", + "reference": "8885c6db5d5b3653ad30d4ad4f73607925a725a5", "shasum": "" }, "require": { @@ -455,9 +459,9 @@ "psr/log": "~1.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/test": "~1.0", - "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", - "squizlabs/php_codesniffer": "1.*" + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, "type": "joomla-package", "extra": { @@ -472,7 +476,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Image Package", "homepage": "https://github.com/joomla-framework/image", @@ -481,30 +485,30 @@ "image", "joomla" ], - "time": "2017-06-28T14:14:15+00:00" + "time": "2018-05-25T02:29:30+00:00" }, { "name": "joomla/input", - "version": "1.2.0", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/joomla-framework/input.git", - "reference": "b6098276043e2d627221fe54d3c91232e6679d0f" + "reference": "ff97c08aa5fa0f48ccc3e7444827f7f9a6b904c8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/input/zipball/b6098276043e2d627221fe54d3c91232e6679d0f", - "reference": "b6098276043e2d627221fe54d3c91232e6679d0f", + "url": "https://api.github.com/repos/joomla-framework/input/zipball/ff97c08aa5fa0f48ccc3e7444827f7f9a6b904c8", + "reference": "ff97c08aa5fa0f48ccc3e7444827f7f9a6b904c8", "shasum": "" }, "require": { "joomla/filter": "~1.0", - "php": ">=5.3.10" + "php": "^5.3.10|~7.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/test": "~1.0", - "phpunit/phpunit": "4.*", - "squizlabs/php_codesniffer": "1.*" + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, "type": "joomla-package", "extra": { @@ -514,13 +518,12 @@ }, "autoload": { "psr-4": { - "Joomla\\Input\\": "src/", - "Joomla\\Input\\Tests\\": "Tests/" + "Joomla\\Input\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Input Package", "homepage": "https://github.com/joomla-framework/input", @@ -529,20 +532,20 @@ "input", "joomla" ], - "time": "2014-10-12T18:01:36+00:00" + "time": "2018-05-26T17:08:08+00:00" }, { "name": "joomla/ldap", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/ldap.git", - "reference": "4dce2db6a3d6d2b8c7847651ad011bb3ed7ba978" + "reference": "ef1010f8f5a13f804589d3fb8a4eddb65472a557" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/ldap/zipball/4dce2db6a3d6d2b8c7847651ad011bb3ed7ba978", - "reference": "4dce2db6a3d6d2b8c7847651ad011bb3ed7ba978", + "url": "https://api.github.com/repos/joomla-framework/ldap/zipball/ef1010f8f5a13f804589d3fb8a4eddb65472a557", + "reference": "ef1010f8f5a13f804589d3fb8a4eddb65472a557", "shasum": "" }, "require": { @@ -550,9 +553,9 @@ "php": "^5.3.10|~7.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/registry": "^1.4.5|~2.0", "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", - "squizlabs/php_codesniffer": "1.*", "symfony/polyfill-php56": "~1.0" }, "suggest": { @@ -571,7 +574,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla LDAP Package", "homepage": "https://github.com/joomla-framework/ldap", @@ -580,33 +583,33 @@ "joomla", "ldap" ], - "time": "2017-10-21T15:41:55+00:00" + "time": "2018-05-25T02:30:42+00:00" }, { "name": "joomla/registry", - "version": "1.5.2", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/joomla-framework/registry.git", - "reference": "bd3592c6f0554a72811df52aeaea98c7815f6e5a" + "reference": "9b7fe128204301bebdae9bd8f02868e8e2e36f74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/registry/zipball/bd3592c6f0554a72811df52aeaea98c7815f6e5a", - "reference": "bd3592c6f0554a72811df52aeaea98c7815f6e5a", + "url": "https://api.github.com/repos/joomla-framework/registry/zipball/9b7fe128204301bebdae9bd8f02868e8e2e36f74", + "reference": "9b7fe128204301bebdae9bd8f02868e8e2e36f74", "shasum": "" }, "require": { "joomla/compat": "~1.0", - "joomla/utilities": "~1.0", - "php": ">=5.3.10|>=7.0", + "joomla/utilities": "^1.4.1|~2.0", + "php": "^5.3.10|~7.0", "symfony/polyfill-php55": "~1.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/test": "~1.0", - "phpunit/phpunit": "~4.8|~5.0", - "squizlabs/php_codesniffer": "1.*", - "symfony/yaml": "~2.0|~3.0" + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", + "symfony/yaml": "~2.0|~3.0|~4.0" }, "suggest": { "symfony/yaml": "Install symfony/yaml if you require YAML support." @@ -624,7 +627,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Registry Package", "homepage": "https://github.com/joomla-framework/registry", @@ -633,7 +636,7 @@ "joomla", "registry" ], - "time": "2016-05-14T20:42:05+00:00" + "time": "2018-05-26T16:34:53+00:00" }, { "name": "joomla/session", @@ -790,25 +793,25 @@ }, { "name": "joomla/utilities", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/utilities.git", - "reference": "8913ca02aad7b929e0d52d78fd5a6961070bdbc6" + "reference": "7407add476590c1a8e68d804d50b8911aaa26bcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/utilities/zipball/8913ca02aad7b929e0d52d78fd5a6961070bdbc6", - "reference": "8913ca02aad7b929e0d52d78fd5a6961070bdbc6", + "url": "https://api.github.com/repos/joomla-framework/utilities/zipball/7407add476590c1a8e68d804d50b8911aaa26bcd", + "reference": "7407add476590c1a8e68d804d50b8911aaa26bcd", "shasum": "" }, "require": { - "joomla/string": "~1.3", + "joomla/string": "~1.3|~2.0", "php": "^5.3.10|~7.0" }, "require-dev": { - "phpunit/phpunit": "~4.8|~5.0", - "squizlabs/php_codesniffer": "1.*" + "joomla/coding-standards": "~2.0@alpha", + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, "type": "joomla-package", "extra": { @@ -823,7 +826,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Utilities Package", "homepage": "https://github.com/joomla-framework/utilities", @@ -832,7 +835,7 @@ "joomla", "utilities" ], - "time": "2016-12-10T17:09:33+00:00" + "time": "2018-03-15T00:42:47+00:00" }, { "name": "leafo/lessphp", @@ -877,16 +880,16 @@ }, { "name": "paragonie/random_compat", - "version": "v1.4.2", + "version": "v1.4.3", "source": { "type": "git", "url": "https://github.com/paragonie/random_compat.git", - "reference": "965cdeb01fdcab7653253aa81d40441d261f1e66" + "reference": "9b3899e3c3ddde89016f576edb8c489708ad64cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/965cdeb01fdcab7653253aa81d40441d261f1e66", - "reference": "965cdeb01fdcab7653253aa81d40441d261f1e66", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/9b3899e3c3ddde89016f576edb8c489708ad64cd", + "reference": "9b3899e3c3ddde89016f576edb8c489708ad64cd", "shasum": "" }, "require": { @@ -921,20 +924,20 @@ "pseudorandom", "random" ], - "time": "2017-03-13T16:22:52+00:00" + "time": "2018-04-04T21:48:54+00:00" }, { "name": "paragonie/sodium_compat", - "version": "v1.3.1", + "version": "v1.6.2", "source": { "type": "git", "url": "https://github.com/paragonie/sodium_compat.git", - "reference": "6b3a59ef127445564a00e261eb1e960b6292f494" + "reference": "22f564d068c093c3775552c700553209f9af60f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/6b3a59ef127445564a00e261eb1e960b6292f494", - "reference": "6b3a59ef127445564a00e261eb1e960b6292f494", + "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/22f564d068c093c3775552c700553209f9af60f8", + "reference": "22f564d068c093c3775552c700553209f9af60f8", "shasum": "" }, "require": { @@ -945,7 +948,8 @@ "phpunit/phpunit": "^3|^4|^5" }, "suggest": { - "ext-libsodium": "Better performance, password hashing (Argon2i), secure memory management (memzero), and better security." + "ext-libsodium": "PHP < 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security.", + "ext-sodium": "PHP >= 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security." }, "type": "library", "autoload": { @@ -1002,7 +1006,7 @@ "secret-key cryptography", "side-channel resistant" ], - "time": "2017-09-29T21:27:52+00:00" + "time": "2018-05-22T20:15:01+00:00" }, { "name": "phpmailer/phpmailer", @@ -1081,6 +1085,55 @@ "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "time": "2017-11-04T09:26:05+00:00" }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, { "name": "psr/log", "version": "1.0.2", @@ -1182,18 +1235,73 @@ ], "time": "2012-10-30T17:54:03+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-04-30T19:57:29+00:00" + }, { "name": "symfony/polyfill-php55", - "version": "v1.6.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php55.git", - "reference": "b64e7f0c37ecf144ecc16668936eef94e628fbfd" + "reference": "a39456128377a85f2c5707fcae458678560cba46" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php55/zipball/b64e7f0c37ecf144ecc16668936eef94e628fbfd", - "reference": "b64e7f0c37ecf144ecc16668936eef94e628fbfd", + "url": "https://api.github.com/repos/symfony/polyfill-php55/zipball/a39456128377a85f2c5707fcae458678560cba46", + "reference": "a39456128377a85f2c5707fcae458678560cba46", "shasum": "" }, "require": { @@ -1203,7 +1311,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -1236,20 +1344,20 @@ "portable", "shim" ], - "time": "2017-10-11T12:05:26+00:00" + "time": "2018-04-26T10:06:28+00:00" }, { "name": "symfony/polyfill-php56", - "version": "v1.6.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php56.git", - "reference": "265fc96795492430762c29be291a371494ba3a5b" + "reference": "af98553c84912459db3f636329567809d639a8f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/265fc96795492430762c29be291a371494ba3a5b", - "reference": "265fc96795492430762c29be291a371494ba3a5b", + "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/af98553c84912459db3f636329567809d639a8f6", + "reference": "af98553c84912459db3f636329567809d639a8f6", "shasum": "" }, "require": { @@ -1259,7 +1367,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -1292,7 +1400,7 @@ "portable", "shim" ], - "time": "2017-10-11T12:05:26+00:00" + "time": "2018-04-26T10:06:28+00:00" }, { "name": "symfony/polyfill-php73", @@ -1351,16 +1459,16 @@ }, { "name": "symfony/polyfill-util", - "version": "v1.6.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-util.git", - "reference": "6e719200c8e540e0c0effeb31f96bdb344b94176" + "reference": "1a5ad95d9436cbff3296034fe9f8d586dce3fb3a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/6e719200c8e540e0c0effeb31f96bdb344b94176", - "reference": "6e719200c8e540e0c0effeb31f96bdb344b94176", + "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/1a5ad95d9436cbff3296034fe9f8d586dce3fb3a", + "reference": "1a5ad95d9436cbff3296034fe9f8d586dce3fb3a", "shasum": "" }, "require": { @@ -1369,7 +1477,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -1399,24 +1507,25 @@ "polyfill", "shim" ], - "time": "2017-10-11T12:05:26+00:00" + "time": "2018-04-26T10:06:28+00:00" }, { "name": "symfony/yaml", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "d819bf267e901727141fe828ae888486fd21236e" + "reference": "51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/d819bf267e901727141fe828ae888486fd21236e", - "reference": "d819bf267e901727141fe828ae888486fd21236e", + "url": "https://api.github.com/repos/symfony/yaml/zipball/51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff", + "reference": "51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-ctype": "~1.8" }, "type": "library", "extra": { @@ -1448,7 +1557,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-05-01T22:52:40+00:00" } ], "packages-dev": [ @@ -1849,16 +1958,16 @@ }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "1.4.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", "shasum": "" }, "require": { @@ -1892,7 +2001,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -1986,16 +2095,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.4.11", + "version": "1.4.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", "shasum": "" }, "require": { @@ -2031,7 +2140,7 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27T10:12:30+00:00" + "time": "2017-12-04T08:55:13+00:00" }, { "name": "phpunit/phpunit", @@ -2610,16 +2719,16 @@ }, { "name": "symfony/console", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "89143ce2b463515a75b5f5e9650e6ecfb2684158" + "reference": "e8e59b74ad1274714dad2748349b55e3e6e630c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/89143ce2b463515a75b5f5e9650e6ecfb2684158", - "reference": "89143ce2b463515a75b5f5e9650e6ecfb2684158", + "url": "https://api.github.com/repos/symfony/console/zipball/e8e59b74ad1274714dad2748349b55e3e6e630c7", + "reference": "e8e59b74ad1274714dad2748349b55e3e6e630c7", "shasum": "" }, "require": { @@ -2633,7 +2742,7 @@ "symfony/process": "~2.1|~3.0.0" }, "suggest": { - "psr/log": "For using the console logger", + "psr/log-implementation": "For using the console logger", "symfony/event-dispatcher": "", "symfony/process": "" }, @@ -2667,20 +2776,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2017-11-07T14:08:47+00:00" + "time": "2018-05-15T21:17:45+00:00" }, { "name": "symfony/debug", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "a0a29e9867debabdace779a20a9385c623a23bbd" + "reference": "fe8838e11cf7dbaf324bd6f51d065d873ccf78a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/a0a29e9867debabdace779a20a9385c623a23bbd", - "reference": "a0a29e9867debabdace779a20a9385c623a23bbd", + "url": "https://api.github.com/repos/symfony/debug/zipball/fe8838e11cf7dbaf324bd6f51d065d873ccf78a2", + "reference": "fe8838e11cf7dbaf324bd6f51d065d873ccf78a2", "shasum": "" }, "require": { @@ -2724,20 +2833,20 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2017-10-24T13:48:52+00:00" + "time": "2018-05-15T21:17:45+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "b59aacf238fadda50d612c9de73b74751872a903" + "reference": "9b69aad7d4c086dc94ebade2d5eb9145da5dac8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b59aacf238fadda50d612c9de73b74751872a903", - "reference": "b59aacf238fadda50d612c9de73b74751872a903", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9b69aad7d4c086dc94ebade2d5eb9145da5dac8c", + "reference": "9b69aad7d4c086dc94ebade2d5eb9145da5dac8c", "shasum": "" }, "require": { @@ -2784,24 +2893,25 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-04-06T07:35:03+00:00" }, { "name": "symfony/filesystem", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "10507c5f24577b0ad971b0d22097c823b2b45dd3" + "reference": "1ed4b265550ec43d2ceaa0e9e57b0bc4eeb1b541" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/10507c5f24577b0ad971b0d22097c823b2b45dd3", - "reference": "10507c5f24577b0ad971b0d22097c823b2b45dd3", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/1ed4b265550ec43d2ceaa0e9e57b0bc4eeb1b541", + "reference": "1ed4b265550ec43d2ceaa0e9e57b0bc4eeb1b541", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-ctype": "~1.8" }, "type": "library", "extra": { @@ -2833,20 +2943,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2017-11-07T14:08:47+00:00" + "time": "2018-05-15T21:17:45+00:00" }, { "name": "symfony/finder", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "efeceae6a05a9b2fcb3391333f1d4a828ff44ab8" + "reference": "79764d21163db295f0daf8bd9d9b91f97e65db6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/efeceae6a05a9b2fcb3391333f1d4a828ff44ab8", - "reference": "efeceae6a05a9b2fcb3391333f1d4a828ff44ab8", + "url": "https://api.github.com/repos/symfony/finder/zipball/79764d21163db295f0daf8bd9d9b91f97e65db6a", + "reference": "79764d21163db295f0daf8bd9d9b91f97e65db6a", "shasum": "" }, "require": { @@ -2882,20 +2992,20 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-05-15T21:17:45+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.6.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296" + "reference": "3296adf6a6454a050679cde90f95350ad604b171" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", - "reference": "2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", + "reference": "3296adf6a6454a050679cde90f95350ad604b171", "shasum": "" }, "require": { @@ -2907,7 +3017,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -2941,20 +3051,20 @@ "portable", "shim" ], - "time": "2017-10-11T12:05:26+00:00" + "time": "2018-04-26T10:06:28+00:00" }, { "name": "symfony/process", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "d25449e031f600807949aab7cadbf267712f4eee" + "reference": "713952f2ccbcc8342ecdbe1cb313d3e2da8aad28" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/d25449e031f600807949aab7cadbf267712f4eee", - "reference": "d25449e031f600807949aab7cadbf267712f4eee", + "url": "https://api.github.com/repos/symfony/process/zipball/713952f2ccbcc8342ecdbe1cb313d3e2da8aad28", + "reference": "713952f2ccbcc8342ecdbe1cb313d3e2da8aad28", "shasum": "" }, "require": { @@ -2990,20 +3100,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2017-11-05T15:25:56+00:00" + "time": "2018-05-15T21:17:45+00:00" }, { "name": "symfony/stopwatch", - "version": "v2.8.29", + "version": "v2.8.41", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "533bb9d7c2da1c6d2da163ecf0f22043ea98f59b" + "reference": "57021208ad9830f8f8390c1a9d7bb390f32be89e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/533bb9d7c2da1c6d2da163ecf0f22043ea98f59b", - "reference": "533bb9d7c2da1c6d2da163ecf0f22043ea98f59b", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/57021208ad9830f8f8390c1a9d7bb390f32be89e", + "reference": "57021208ad9830f8f8390c1a9d7bb390f32be89e", "shasum": "" }, "require": { @@ -3039,7 +3149,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2017-11-10T18:59:36+00:00" + "time": "2018-01-03T07:36:31+00:00" } ], "aliases": [], diff --git a/libraries/vendor/composer/autoload_classmap.php b/libraries/vendor/composer/autoload_classmap.php index 2e6b35fa4a07c..e84c722fd21ed 100644 --- a/libraries/vendor/composer/autoload_classmap.php +++ b/libraries/vendor/composer/autoload_classmap.php @@ -31,6 +31,8 @@ 'Joomla\\DI\\ContainerAwareInterface' => $vendorDir . '/joomla/di/src/ContainerAwareInterface.php', 'Joomla\\DI\\ContainerAwareTrait' => $vendorDir . '/joomla/di/src/ContainerAwareTrait.php', 'Joomla\\DI\\Exception\\DependencyResolutionException' => $vendorDir . '/joomla/di/src/Exception/DependencyResolutionException.php', + 'Joomla\\DI\\Exception\\KeyNotFoundException' => $vendorDir . '/joomla/di/src/Exception/KeyNotFoundException.php', + 'Joomla\\DI\\Exception\\ProtectedKeyException' => $vendorDir . '/joomla/di/src/Exception/ProtectedKeyException.php', 'Joomla\\DI\\ServiceProviderInterface' => $vendorDir . '/joomla/di/src/ServiceProviderInterface.php', 'Joomla\\Data\\DataObject' => $vendorDir . '/joomla/data/src/DataObject.php', 'Joomla\\Data\\DataSet' => $vendorDir . '/joomla/data/src/DataSet.php', @@ -76,13 +78,6 @@ 'Joomla\\Input\\Files' => $vendorDir . '/joomla/input/src/Files.php', 'Joomla\\Input\\Input' => $vendorDir . '/joomla/input/src/Input.php', 'Joomla\\Input\\Json' => $vendorDir . '/joomla/input/src/Json.php', - 'Joomla\\Input\\Tests\\CliTest' => $vendorDir . '/joomla/input/Tests/CliTest.php', - 'Joomla\\Input\\Tests\\CookieTest' => $vendorDir . '/joomla/input/Tests/CookieTest.php', - 'Joomla\\Input\\Tests\\FilesTest' => $vendorDir . '/joomla/input/Tests/FilesTest.php', - 'Joomla\\Input\\Tests\\FilterInputMock' => $vendorDir . '/joomla/input/Tests/Stubs/FilterInputMock.php', - 'Joomla\\Input\\Tests\\InputMocker' => $vendorDir . '/joomla/input/Tests/InputMocker.php', - 'Joomla\\Input\\Tests\\InputTest' => $vendorDir . '/joomla/input/Tests/InputTest.php', - 'Joomla\\Input\\Tests\\JsonTest' => $vendorDir . '/joomla/input/Tests/JsonTest.php', 'Joomla\\Ldap\\LdapClient' => $vendorDir . '/joomla/ldap/src/LdapClient.php', 'Joomla\\Registry\\AbstractRegistryFormat' => $vendorDir . '/joomla/registry/src/AbstractRegistryFormat.php', 'Joomla\\Registry\\Factory' => $vendorDir . '/joomla/registry/src/Factory.php', @@ -125,6 +120,9 @@ 'PHPMailerOAuth' => $vendorDir . '/phpmailer/phpmailer/class.phpmaileroauth.php', 'PHPMailerOAuthGoogle' => $vendorDir . '/phpmailer/phpmailer/class.phpmaileroauthgoogle.php', 'POP3' => $vendorDir . '/phpmailer/phpmailer/class.pop3.php', + 'Psr\\Container\\ContainerExceptionInterface' => $vendorDir . '/psr/container/src/ContainerExceptionInterface.php', + 'Psr\\Container\\ContainerInterface' => $vendorDir . '/psr/container/src/ContainerInterface.php', + 'Psr\\Container\\NotFoundExceptionInterface' => $vendorDir . '/psr/container/src/NotFoundExceptionInterface.php', 'Psr\\Log\\AbstractLogger' => $vendorDir . '/psr/log/Psr/Log/AbstractLogger.php', 'Psr\\Log\\InvalidArgumentException' => $vendorDir . '/psr/log/Psr/Log/InvalidArgumentException.php', 'Psr\\Log\\LogLevel' => $vendorDir . '/psr/log/Psr/Log/LogLevel.php', @@ -177,6 +175,7 @@ 'Symfony\\Component\\Yaml\\Parser' => $vendorDir . '/symfony/yaml/Parser.php', 'Symfony\\Component\\Yaml\\Unescaper' => $vendorDir . '/symfony/yaml/Unescaper.php', 'Symfony\\Component\\Yaml\\Yaml' => $vendorDir . '/symfony/yaml/Yaml.php', + 'Symfony\\Polyfill\\Ctype\\Ctype' => $vendorDir . '/symfony/polyfill-ctype/Ctype.php', 'Symfony\\Polyfill\\Php55\\Php55' => $vendorDir . '/symfony/polyfill-php55/Php55.php', 'Symfony\\Polyfill\\Php55\\Php55ArrayColumn' => $vendorDir . '/symfony/polyfill-php55/Php55ArrayColumn.php', 'Symfony\\Polyfill\\Php56\\Php56' => $vendorDir . '/symfony/polyfill-php56/Php56.php', diff --git a/libraries/vendor/composer/autoload_files.php b/libraries/vendor/composer/autoload_files.php index 711d3b54a61ae..ced1fb56fe684 100644 --- a/libraries/vendor/composer/autoload_files.php +++ b/libraries/vendor/composer/autoload_files.php @@ -21,6 +21,7 @@ '05d739a990f75f0c44ebe1f032b33148' => $vendorDir . '/joomla/string/src/phputf8/ucwords.php', '4292e2fa66516089e6006723267587b4' => $vendorDir . '/joomla/string/src/phputf8/utils/ascii.php', '87465e33b7551b401bf051928f220e9a' => $vendorDir . '/joomla/string/src/phputf8/utils/validation.php', + '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php', 'e40631d46120a9c38ea139981f8dab26' => $vendorDir . '/ircmaxell/password-compat/lib/password.php', '5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php', 'edc6464955a37aa4d5fbf39d40fb6ee7' => $vendorDir . '/symfony/polyfill-php55/bootstrap.php', diff --git a/libraries/vendor/composer/autoload_psr4.php b/libraries/vendor/composer/autoload_psr4.php index de3e6f5bd5e1e..a08fa71cb6bd6 100644 --- a/libraries/vendor/composer/autoload_psr4.php +++ b/libraries/vendor/composer/autoload_psr4.php @@ -10,15 +10,16 @@ 'Symfony\\Polyfill\\Php73\\' => array($vendorDir . '/symfony/polyfill-php73'), 'Symfony\\Polyfill\\Php56\\' => array($vendorDir . '/symfony/polyfill-php56'), 'Symfony\\Polyfill\\Php55\\' => array($vendorDir . '/symfony/polyfill-php55'), + 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'), 'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'), 'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'), + 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'), 'Joomla\\Utilities\\' => array($vendorDir . '/joomla/utilities/src'), 'Joomla\\Uri\\Tests\\' => array($vendorDir . '/joomla/uri/Tests'), 'Joomla\\Uri\\' => array($vendorDir . '/joomla/uri/src'), 'Joomla\\String\\' => array($vendorDir . '/joomla/string/src'), 'Joomla\\Registry\\' => array($vendorDir . '/joomla/registry/src'), 'Joomla\\Ldap\\' => array($vendorDir . '/joomla/ldap/src'), - 'Joomla\\Input\\Tests\\' => array($vendorDir . '/joomla/input/Tests'), 'Joomla\\Input\\' => array($vendorDir . '/joomla/input/src'), 'Joomla\\Image\\' => array($vendorDir . '/joomla/image/src'), 'Joomla\\Filter\\' => array($vendorDir . '/joomla/filter/src'), diff --git a/libraries/vendor/composer/autoload_static.php b/libraries/vendor/composer/autoload_static.php index e9131afecc631..c58cb0b7606b2 100644 --- a/libraries/vendor/composer/autoload_static.php +++ b/libraries/vendor/composer/autoload_static.php @@ -22,6 +22,7 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe '05d739a990f75f0c44ebe1f032b33148' => __DIR__ . '/..' . '/joomla/string/src/phputf8/ucwords.php', '4292e2fa66516089e6006723267587b4' => __DIR__ . '/..' . '/joomla/string/src/phputf8/utils/ascii.php', '87465e33b7551b401bf051928f220e9a' => __DIR__ . '/..' . '/joomla/string/src/phputf8/utils/validation.php', + '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', 'e40631d46120a9c38ea139981f8dab26' => __DIR__ . '/..' . '/ircmaxell/password-compat/lib/password.php', '5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php', 'edc6464955a37aa4d5fbf39d40fb6ee7' => __DIR__ . '/..' . '/symfony/polyfill-php55/bootstrap.php', @@ -37,11 +38,13 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe 'Symfony\\Polyfill\\Php73\\' => 23, 'Symfony\\Polyfill\\Php56\\' => 23, 'Symfony\\Polyfill\\Php55\\' => 23, + 'Symfony\\Polyfill\\Ctype\\' => 23, 'Symfony\\Component\\Yaml\\' => 23, ), 'P' => array ( 'Psr\\Log\\' => 8, + 'Psr\\Container\\' => 14, ), 'J' => array ( @@ -51,7 +54,6 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe 'Joomla\\String\\' => 14, 'Joomla\\Registry\\' => 16, 'Joomla\\Ldap\\' => 12, - 'Joomla\\Input\\Tests\\' => 19, 'Joomla\\Input\\' => 13, 'Joomla\\Image\\' => 13, 'Joomla\\Filter\\' => 14, @@ -83,6 +85,10 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe array ( 0 => __DIR__ . '/..' . '/symfony/polyfill-php55', ), + 'Symfony\\Polyfill\\Ctype\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/polyfill-ctype', + ), 'Symfony\\Component\\Yaml\\' => array ( 0 => __DIR__ . '/..' . '/symfony/yaml', @@ -91,6 +97,10 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe array ( 0 => __DIR__ . '/..' . '/psr/log/Psr/Log', ), + 'Psr\\Container\\' => + array ( + 0 => __DIR__ . '/..' . '/psr/container/src', + ), 'Joomla\\Utilities\\' => array ( 0 => __DIR__ . '/..' . '/joomla/utilities/src', @@ -115,10 +125,6 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe array ( 0 => __DIR__ . '/..' . '/joomla/ldap/src', ), - 'Joomla\\Input\\Tests\\' => - array ( - 0 => __DIR__ . '/..' . '/joomla/input/Tests', - ), 'Joomla\\Input\\' => array ( 0 => __DIR__ . '/..' . '/joomla/input/src', @@ -208,6 +214,8 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe 'Joomla\\DI\\ContainerAwareInterface' => __DIR__ . '/..' . '/joomla/di/src/ContainerAwareInterface.php', 'Joomla\\DI\\ContainerAwareTrait' => __DIR__ . '/..' . '/joomla/di/src/ContainerAwareTrait.php', 'Joomla\\DI\\Exception\\DependencyResolutionException' => __DIR__ . '/..' . '/joomla/di/src/Exception/DependencyResolutionException.php', + 'Joomla\\DI\\Exception\\KeyNotFoundException' => __DIR__ . '/..' . '/joomla/di/src/Exception/KeyNotFoundException.php', + 'Joomla\\DI\\Exception\\ProtectedKeyException' => __DIR__ . '/..' . '/joomla/di/src/Exception/ProtectedKeyException.php', 'Joomla\\DI\\ServiceProviderInterface' => __DIR__ . '/..' . '/joomla/di/src/ServiceProviderInterface.php', 'Joomla\\Data\\DataObject' => __DIR__ . '/..' . '/joomla/data/src/DataObject.php', 'Joomla\\Data\\DataSet' => __DIR__ . '/..' . '/joomla/data/src/DataSet.php', @@ -253,13 +261,6 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe 'Joomla\\Input\\Files' => __DIR__ . '/..' . '/joomla/input/src/Files.php', 'Joomla\\Input\\Input' => __DIR__ . '/..' . '/joomla/input/src/Input.php', 'Joomla\\Input\\Json' => __DIR__ . '/..' . '/joomla/input/src/Json.php', - 'Joomla\\Input\\Tests\\CliTest' => __DIR__ . '/..' . '/joomla/input/Tests/CliTest.php', - 'Joomla\\Input\\Tests\\CookieTest' => __DIR__ . '/..' . '/joomla/input/Tests/CookieTest.php', - 'Joomla\\Input\\Tests\\FilesTest' => __DIR__ . '/..' . '/joomla/input/Tests/FilesTest.php', - 'Joomla\\Input\\Tests\\FilterInputMock' => __DIR__ . '/..' . '/joomla/input/Tests/Stubs/FilterInputMock.php', - 'Joomla\\Input\\Tests\\InputMocker' => __DIR__ . '/..' . '/joomla/input/Tests/InputMocker.php', - 'Joomla\\Input\\Tests\\InputTest' => __DIR__ . '/..' . '/joomla/input/Tests/InputTest.php', - 'Joomla\\Input\\Tests\\JsonTest' => __DIR__ . '/..' . '/joomla/input/Tests/JsonTest.php', 'Joomla\\Ldap\\LdapClient' => __DIR__ . '/..' . '/joomla/ldap/src/LdapClient.php', 'Joomla\\Registry\\AbstractRegistryFormat' => __DIR__ . '/..' . '/joomla/registry/src/AbstractRegistryFormat.php', 'Joomla\\Registry\\Factory' => __DIR__ . '/..' . '/joomla/registry/src/Factory.php', @@ -302,6 +303,9 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe 'PHPMailerOAuth' => __DIR__ . '/..' . '/phpmailer/phpmailer/class.phpmaileroauth.php', 'PHPMailerOAuthGoogle' => __DIR__ . '/..' . '/phpmailer/phpmailer/class.phpmaileroauthgoogle.php', 'POP3' => __DIR__ . '/..' . '/phpmailer/phpmailer/class.pop3.php', + 'Psr\\Container\\ContainerExceptionInterface' => __DIR__ . '/..' . '/psr/container/src/ContainerExceptionInterface.php', + 'Psr\\Container\\ContainerInterface' => __DIR__ . '/..' . '/psr/container/src/ContainerInterface.php', + 'Psr\\Container\\NotFoundExceptionInterface' => __DIR__ . '/..' . '/psr/container/src/NotFoundExceptionInterface.php', 'Psr\\Log\\AbstractLogger' => __DIR__ . '/..' . '/psr/log/Psr/Log/AbstractLogger.php', 'Psr\\Log\\InvalidArgumentException' => __DIR__ . '/..' . '/psr/log/Psr/Log/InvalidArgumentException.php', 'Psr\\Log\\LogLevel' => __DIR__ . '/..' . '/psr/log/Psr/Log/LogLevel.php', @@ -354,6 +358,7 @@ class ComposerStaticInit205c915b9c7d3e718e7c95793ee67ffe 'Symfony\\Component\\Yaml\\Parser' => __DIR__ . '/..' . '/symfony/yaml/Parser.php', 'Symfony\\Component\\Yaml\\Unescaper' => __DIR__ . '/..' . '/symfony/yaml/Unescaper.php', 'Symfony\\Component\\Yaml\\Yaml' => __DIR__ . '/..' . '/symfony/yaml/Yaml.php', + 'Symfony\\Polyfill\\Ctype\\Ctype' => __DIR__ . '/..' . '/symfony/polyfill-ctype/Ctype.php', 'Symfony\\Polyfill\\Php55\\Php55' => __DIR__ . '/..' . '/symfony/polyfill-php55/Php55.php', 'Symfony\\Polyfill\\Php55\\Php55ArrayColumn' => __DIR__ . '/..' . '/symfony/polyfill-php55/Php55ArrayColumn.php', 'Symfony\\Polyfill\\Php56\\Php56' => __DIR__ . '/..' . '/symfony/polyfill-php56/Php56.php', diff --git a/libraries/vendor/composer/installed.json b/libraries/vendor/composer/installed.json index a200f1ef5088c..fbc58dfad4bd0 100644 --- a/libraries/vendor/composer/installed.json +++ b/libraries/vendor/composer/installed.json @@ -45,17 +45,17 @@ }, { "name": "joomla/application", - "version": "1.9.0", - "version_normalized": "1.9.0.0", + "version": "1.9.1", + "version_normalized": "1.9.1.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/application.git", - "reference": "f32371fc988356bbf052396dcfd782effdd74b6d" + "reference": "a0360e578933e20e98da5c8e17cda72e2b5e2024" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/application/zipball/f32371fc988356bbf052396dcfd782effdd74b6d", - "reference": "f32371fc988356bbf052396dcfd782effdd74b6d", + "url": "https://api.github.com/repos/joomla-framework/application/zipball/a0360e578933e20e98da5c8e17cda72e2b5e2024", + "reference": "a0360e578933e20e98da5c8e17cda72e2b5e2024", "shasum": "" }, "require": { @@ -76,7 +76,7 @@ "joomla/session": "To use AbstractWebApplication with session support, install joomla/session", "joomla/uri": "To use AbstractWebApplication, install joomla/uri" }, - "time": "2018-05-20T15:35:58+00:00", + "time": "2018-05-28T15:32:35+00:00", "type": "joomla-package", "extra": { "branch-alias": { @@ -247,27 +247,31 @@ }, { "name": "joomla/di", - "version": "1.4.0", - "version_normalized": "1.4.0.0", + "version": "1.5.1", + "version_normalized": "1.5.1.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/di.git", - "reference": "756c6eb4554b9007f69da66cf488a05308251ed8" + "reference": "33c66e4091e4433f33ddf4a0ac36604cf3b73c41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/di/zipball/756c6eb4554b9007f69da66cf488a05308251ed8", - "reference": "756c6eb4554b9007f69da66cf488a05308251ed8", + "url": "https://api.github.com/repos/joomla-framework/di/zipball/33c66e4091e4433f33ddf4a0ac36604cf3b73c41", + "reference": "33c66e4091e4433f33ddf4a0ac36604cf3b73c41", "shasum": "" }, "require": { - "php": "^5.3.10|~7.0" + "php": "^5.3.10|~7.0", + "psr/container": "~1.0" + }, + "provide": { + "psr/container-implementation": "~1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", - "squizlabs/php_codesniffer": "1.*" + "joomla/coding-standards": "~2.0@alpha", + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, - "time": "2017-11-12T15:35:19+00:00", + "time": "2018-02-25T16:30:45+00:00", "type": "joomla-package", "extra": { "branch-alias": { @@ -282,7 +286,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla DI Package", "homepage": "https://github.com/joomla-framework/di", @@ -448,17 +452,17 @@ }, { "name": "joomla/image", - "version": "1.4.0", - "version_normalized": "1.4.0.0", + "version": "1.5.0", + "version_normalized": "1.5.0.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/image.git", - "reference": "d5a76037add34f95e970e9d8c8a449feeb781286" + "reference": "8885c6db5d5b3653ad30d4ad4f73607925a725a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/image/zipball/d5a76037add34f95e970e9d8c8a449feeb781286", - "reference": "d5a76037add34f95e970e9d8c8a449feeb781286", + "url": "https://api.github.com/repos/joomla-framework/image/zipball/8885c6db5d5b3653ad30d4ad4f73607925a725a5", + "reference": "8885c6db5d5b3653ad30d4ad4f73607925a725a5", "shasum": "" }, "require": { @@ -467,11 +471,11 @@ "psr/log": "~1.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/test": "~1.0", - "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", - "squizlabs/php_codesniffer": "1.*" + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, - "time": "2017-06-28T14:14:15+00:00", + "time": "2018-05-25T02:29:30+00:00", "type": "joomla-package", "extra": { "branch-alias": { @@ -486,7 +490,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Image Package", "homepage": "https://github.com/joomla-framework/image", @@ -498,29 +502,29 @@ }, { "name": "joomla/input", - "version": "1.2.0", - "version_normalized": "1.2.0.0", + "version": "1.2.3", + "version_normalized": "1.2.3.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/input.git", - "reference": "b6098276043e2d627221fe54d3c91232e6679d0f" + "reference": "ff97c08aa5fa0f48ccc3e7444827f7f9a6b904c8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/input/zipball/b6098276043e2d627221fe54d3c91232e6679d0f", - "reference": "b6098276043e2d627221fe54d3c91232e6679d0f", + "url": "https://api.github.com/repos/joomla-framework/input/zipball/ff97c08aa5fa0f48ccc3e7444827f7f9a6b904c8", + "reference": "ff97c08aa5fa0f48ccc3e7444827f7f9a6b904c8", "shasum": "" }, "require": { "joomla/filter": "~1.0", - "php": ">=5.3.10" + "php": "^5.3.10|~7.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/test": "~1.0", - "phpunit/phpunit": "4.*", - "squizlabs/php_codesniffer": "1.*" + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, - "time": "2014-10-12T18:01:36+00:00", + "time": "2018-05-26T17:08:08+00:00", "type": "joomla-package", "extra": { "branch-alias": { @@ -530,13 +534,12 @@ "installation-source": "dist", "autoload": { "psr-4": { - "Joomla\\Input\\": "src/", - "Joomla\\Input\\Tests\\": "Tests/" + "Joomla\\Input\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Input Package", "homepage": "https://github.com/joomla-framework/input", @@ -548,17 +551,17 @@ }, { "name": "joomla/ldap", - "version": "1.3.0", - "version_normalized": "1.3.0.0", + "version": "1.4.0", + "version_normalized": "1.4.0.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/ldap.git", - "reference": "4dce2db6a3d6d2b8c7847651ad011bb3ed7ba978" + "reference": "ef1010f8f5a13f804589d3fb8a4eddb65472a557" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/ldap/zipball/4dce2db6a3d6d2b8c7847651ad011bb3ed7ba978", - "reference": "4dce2db6a3d6d2b8c7847651ad011bb3ed7ba978", + "url": "https://api.github.com/repos/joomla-framework/ldap/zipball/ef1010f8f5a13f804589d3fb8a4eddb65472a557", + "reference": "ef1010f8f5a13f804589d3fb8a4eddb65472a557", "shasum": "" }, "require": { @@ -566,15 +569,15 @@ "php": "^5.3.10|~7.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/registry": "^1.4.5|~2.0", "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", - "squizlabs/php_codesniffer": "1.*", "symfony/polyfill-php56": "~1.0" }, "suggest": { "symfony/polyfill-php56": "If using PHP 5.5 or earlier to use ldap_escape() function" }, - "time": "2017-10-21T15:41:55+00:00", + "time": "2018-05-25T02:30:42+00:00", "type": "joomla-package", "extra": { "branch-alias": { @@ -589,7 +592,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla LDAP Package", "homepage": "https://github.com/joomla-framework/ldap", @@ -601,35 +604,35 @@ }, { "name": "joomla/registry", - "version": "1.5.2", - "version_normalized": "1.5.2.0", + "version": "1.6.1", + "version_normalized": "1.6.1.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/registry.git", - "reference": "bd3592c6f0554a72811df52aeaea98c7815f6e5a" + "reference": "9b7fe128204301bebdae9bd8f02868e8e2e36f74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/registry/zipball/bd3592c6f0554a72811df52aeaea98c7815f6e5a", - "reference": "bd3592c6f0554a72811df52aeaea98c7815f6e5a", + "url": "https://api.github.com/repos/joomla-framework/registry/zipball/9b7fe128204301bebdae9bd8f02868e8e2e36f74", + "reference": "9b7fe128204301bebdae9bd8f02868e8e2e36f74", "shasum": "" }, "require": { "joomla/compat": "~1.0", - "joomla/utilities": "~1.0", - "php": ">=5.3.10|>=7.0", + "joomla/utilities": "^1.4.1|~2.0", + "php": "^5.3.10|~7.0", "symfony/polyfill-php55": "~1.0" }, "require-dev": { + "joomla/coding-standards": "~2.0@alpha", "joomla/test": "~1.0", - "phpunit/phpunit": "~4.8|~5.0", - "squizlabs/php_codesniffer": "1.*", - "symfony/yaml": "~2.0|~3.0" + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", + "symfony/yaml": "~2.0|~3.0|~4.0" }, "suggest": { "symfony/yaml": "Install symfony/yaml if you require YAML support." }, - "time": "2016-05-14T20:42:05+00:00", + "time": "2018-05-26T16:34:53+00:00", "type": "joomla-package", "extra": { "branch-alias": { @@ -644,7 +647,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Registry Package", "homepage": "https://github.com/joomla-framework/registry", @@ -815,28 +818,28 @@ }, { "name": "joomla/utilities", - "version": "1.4.1", - "version_normalized": "1.4.1.0", + "version": "1.5.0", + "version_normalized": "1.5.0.0", "source": { "type": "git", "url": "https://github.com/joomla-framework/utilities.git", - "reference": "8913ca02aad7b929e0d52d78fd5a6961070bdbc6" + "reference": "7407add476590c1a8e68d804d50b8911aaa26bcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-framework/utilities/zipball/8913ca02aad7b929e0d52d78fd5a6961070bdbc6", - "reference": "8913ca02aad7b929e0d52d78fd5a6961070bdbc6", + "url": "https://api.github.com/repos/joomla-framework/utilities/zipball/7407add476590c1a8e68d804d50b8911aaa26bcd", + "reference": "7407add476590c1a8e68d804d50b8911aaa26bcd", "shasum": "" }, "require": { - "joomla/string": "~1.3", + "joomla/string": "~1.3|~2.0", "php": "^5.3.10|~7.0" }, "require-dev": { - "phpunit/phpunit": "~4.8|~5.0", - "squizlabs/php_codesniffer": "1.*" + "joomla/coding-standards": "~2.0@alpha", + "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0" }, - "time": "2016-12-10T17:09:33+00:00", + "time": "2018-03-15T00:42:47+00:00", "type": "joomla-package", "extra": { "branch-alias": { @@ -851,7 +854,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "description": "Joomla Utilities Package", "homepage": "https://github.com/joomla-framework/utilities", @@ -906,17 +909,17 @@ }, { "name": "paragonie/random_compat", - "version": "v1.4.2", - "version_normalized": "1.4.2.0", + "version": "v1.4.3", + "version_normalized": "1.4.3.0", "source": { "type": "git", "url": "https://github.com/paragonie/random_compat.git", - "reference": "965cdeb01fdcab7653253aa81d40441d261f1e66" + "reference": "9b3899e3c3ddde89016f576edb8c489708ad64cd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/965cdeb01fdcab7653253aa81d40441d261f1e66", - "reference": "965cdeb01fdcab7653253aa81d40441d261f1e66", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/9b3899e3c3ddde89016f576edb8c489708ad64cd", + "reference": "9b3899e3c3ddde89016f576edb8c489708ad64cd", "shasum": "" }, "require": { @@ -928,7 +931,7 @@ "suggest": { "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." }, - "time": "2017-03-13T16:22:52+00:00", + "time": "2018-04-04T21:48:54+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -956,17 +959,17 @@ }, { "name": "paragonie/sodium_compat", - "version": "v1.3.1", - "version_normalized": "1.3.1.0", + "version": "v1.6.2", + "version_normalized": "1.6.2.0", "source": { "type": "git", "url": "https://github.com/paragonie/sodium_compat.git", - "reference": "6b3a59ef127445564a00e261eb1e960b6292f494" + "reference": "22f564d068c093c3775552c700553209f9af60f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/6b3a59ef127445564a00e261eb1e960b6292f494", - "reference": "6b3a59ef127445564a00e261eb1e960b6292f494", + "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/22f564d068c093c3775552c700553209f9af60f8", + "reference": "22f564d068c093c3775552c700553209f9af60f8", "shasum": "" }, "require": { @@ -977,9 +980,10 @@ "phpunit/phpunit": "^3|^4|^5" }, "suggest": { - "ext-libsodium": "Better performance, password hashing (Argon2i), secure memory management (memzero), and better security." + "ext-libsodium": "PHP < 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security.", + "ext-sodium": "PHP >= 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security." }, - "time": "2017-09-29T21:27:52+00:00", + "time": "2018-05-22T20:15:01+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -1116,6 +1120,57 @@ ], "description": "PHPMailer is a full-featured email creation and transfer class for PHP" }, + { + "name": "psr/container", + "version": "1.0.0", + "version_normalized": "1.0.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "time": "2017-02-14T16:28:37+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ] + }, { "name": "psr/log", "version": "1.0.2", @@ -1221,30 +1276,87 @@ "rss" ] }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.8.0", + "version_normalized": "1.8.0.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2018-04-30T19:57:29+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ] + }, { "name": "symfony/polyfill-php55", - "version": "v1.6.0", - "version_normalized": "1.6.0.0", + "version": "v1.8.0", + "version_normalized": "1.8.0.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php55.git", - "reference": "b64e7f0c37ecf144ecc16668936eef94e628fbfd" + "reference": "a39456128377a85f2c5707fcae458678560cba46" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php55/zipball/b64e7f0c37ecf144ecc16668936eef94e628fbfd", - "reference": "b64e7f0c37ecf144ecc16668936eef94e628fbfd", + "url": "https://api.github.com/repos/symfony/polyfill-php55/zipball/a39456128377a85f2c5707fcae458678560cba46", + "reference": "a39456128377a85f2c5707fcae458678560cba46", "shasum": "" }, "require": { "ircmaxell/password-compat": "~1.0", "php": ">=5.3.3" }, - "time": "2017-10-11T12:05:26+00:00", + "time": "2018-04-26T10:06:28+00:00", "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "installation-source": "dist", @@ -1281,28 +1393,28 @@ }, { "name": "symfony/polyfill-php56", - "version": "v1.6.0", - "version_normalized": "1.6.0.0", + "version": "v1.8.0", + "version_normalized": "1.8.0.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php56.git", - "reference": "265fc96795492430762c29be291a371494ba3a5b" + "reference": "af98553c84912459db3f636329567809d639a8f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/265fc96795492430762c29be291a371494ba3a5b", - "reference": "265fc96795492430762c29be291a371494ba3a5b", + "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/af98553c84912459db3f636329567809d639a8f6", + "reference": "af98553c84912459db3f636329567809d639a8f6", "shasum": "" }, "require": { "php": ">=5.3.3", "symfony/polyfill-util": "~1.0" }, - "time": "2017-10-11T12:05:26+00:00", + "time": "2018-04-26T10:06:28+00:00", "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "installation-source": "dist", @@ -1396,27 +1508,27 @@ }, { "name": "symfony/polyfill-util", - "version": "v1.6.0", - "version_normalized": "1.6.0.0", + "version": "v1.8.0", + "version_normalized": "1.8.0.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-util.git", - "reference": "6e719200c8e540e0c0effeb31f96bdb344b94176" + "reference": "1a5ad95d9436cbff3296034fe9f8d586dce3fb3a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/6e719200c8e540e0c0effeb31f96bdb344b94176", - "reference": "6e719200c8e540e0c0effeb31f96bdb344b94176", + "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/1a5ad95d9436cbff3296034fe9f8d586dce3fb3a", + "reference": "1a5ad95d9436cbff3296034fe9f8d586dce3fb3a", "shasum": "" }, "require": { "php": ">=5.3.3" }, - "time": "2017-10-11T12:05:26+00:00", + "time": "2018-04-26T10:06:28+00:00", "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.8-dev" } }, "installation-source": "dist", @@ -1450,23 +1562,24 @@ }, { "name": "symfony/yaml", - "version": "v2.8.29", - "version_normalized": "2.8.29.0", + "version": "v2.8.41", + "version_normalized": "2.8.41.0", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "d819bf267e901727141fe828ae888486fd21236e" + "reference": "51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/d819bf267e901727141fe828ae888486fd21236e", - "reference": "d819bf267e901727141fe828ae888486fd21236e", + "url": "https://api.github.com/repos/symfony/yaml/zipball/51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff", + "reference": "51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-ctype": "~1.8" }, - "time": "2017-11-05T15:25:56+00:00", + "time": "2018-05-01T22:52:40+00:00", "type": "library", "extra": { "branch-alias": { diff --git a/libraries/vendor/joomla/application/src/Web/WebClient.php b/libraries/vendor/joomla/application/src/Web/WebClient.php index 80ec8aed52c2f..722653f6052c3 100644 --- a/libraries/vendor/joomla/application/src/Web/WebClient.php +++ b/libraries/vendor/joomla/application/src/Web/WebClient.php @@ -420,16 +420,29 @@ protected function detectEngine($userAgent) } elseif (stripos($userAgent, 'Opera') !== false || stripos($userAgent, 'Presto') !== false) { - $result = explode('/', stristr($userAgent, 'Opera')); - $version = explode(' ', $result[1]); + $version = false; - if ($version[0] >= 15) + if (preg_match('/Opera[\/| ]?([0-9.]+)/u', $userAgent, $match)) { - $this->engine = self::BLINK; + $version = floatval($match[1]); + } + + if (preg_match('/Version\/([0-9.]+)/u', $userAgent, $match)) + { + if (floatval($match[1]) >= 10) + { + $version = floatval($match[1]); + } } - // Sometimes Opera browsers don't say Presto. - $this->engine = self::PRESTO; + if ($version !== false && $version >= 15) + { + $this->engine = self::BLINK; + } + else + { + $this->engine = self::PRESTO; + } } elseif (stripos($userAgent, 'KHTML') !== false) { diff --git a/libraries/vendor/joomla/di/src/Container.php b/libraries/vendor/joomla/di/src/Container.php index cd3bfbf2625c6..7eee5a580e84b 100644 --- a/libraries/vendor/joomla/di/src/Container.php +++ b/libraries/vendor/joomla/di/src/Container.php @@ -2,25 +2,28 @@ /** * Part of the Joomla Framework DI Package * - * @copyright Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ namespace Joomla\DI; use Joomla\DI\Exception\DependencyResolutionException; +use Joomla\DI\Exception\KeyNotFoundException; +use Joomla\DI\Exception\ProtectedKeyException; +use Psr\Container\ContainerInterface; /** * The Container class. * * @since 1.0 */ -class Container +class Container implements ContainerInterface { /** * Holds the key aliases. * - * @var array $aliases + * @var array * @since 1.0 */ protected $aliases = array(); @@ -28,7 +31,7 @@ class Container /** * Holds the shared instances. * - * @var array $instances + * @var array * @since 1.0 */ protected $instances = array(); @@ -37,7 +40,7 @@ class Container * Holds the keys, their callbacks, and whether or not * the item is meant to be a shared resource. * - * @var array $dataStore + * @var array * @since 1.0 */ protected $dataStore = array(); @@ -45,19 +48,27 @@ class Container /** * Parent for hierarchical containers. * - * @var Container + * @var Container|ContainerInterface * @since 1.0 */ protected $parent; + /** + * Holds the service tag mapping. + * + * @var array + * @since 1.5.0 + */ + protected $tags = array(); + /** * Constructor for the DI Container * - * @param Container $parent Parent for hierarchical containers. + * @param ContainerInterface $parent Parent for hierarchical containers. * * @since 1.0 */ - public function __construct(Container $parent = null) + public function __construct(ContainerInterface $parent = null) { $this->parent = $parent; } @@ -103,6 +114,60 @@ protected function resolveAlias($key) return $key; } + /** + * Assign a tag to services. + * + * @param string $tag The tag name + * @param array $keys The service keys to tag + * + * @return Container This object for chaining. + * + * @since 1.5.0 + */ + public function tag($tag, array $keys) + { + foreach ($keys as $key) + { + $resolvedKey = $this->resolveAlias($key); + + if (!isset($this->tags[$tag])) + { + $this->tags[$tag] = array(); + } + + $this->tags[$tag][] = $resolvedKey; + } + + // Prune duplicates + $this->tags[$tag] = array_unique($this->tags[$tag]); + + return $this; + } + + /** + * Fetch all services registered to the given tag. + * + * @param string $tag The tag name + * + * @return array The resolved services for the given tag + * + * @since 1.5.0 + */ + public function getTagged($tag) + { + $services = array(); + + if (isset($this->tags[$tag])) + { + foreach ($this->tags[$tag] as $service) + { + $services[] = $this->get($service); + } + } + + return $services; + } + /** * Build an object of class $key; * @@ -116,22 +181,52 @@ protected function resolveAlias($key) */ public function buildObject($key, $shared = false) { + static $buildStack = array(); + + $resolvedKey = $this->resolveAlias($key); + + if (in_array($resolvedKey, $buildStack, true)) + { + $buildStack = array(); + + throw new DependencyResolutionException("Can't resolve circular dependency"); + } + + $buildStack[] = $resolvedKey; + + if ($this->has($resolvedKey)) + { + $resource = $this->get($resolvedKey); + array_pop($buildStack); + + return $resource; + } + try { - $reflection = new \ReflectionClass($key); + $reflection = new \ReflectionClass($resolvedKey); } catch (\ReflectionException $e) { + array_pop($buildStack); + return false; } + if (!$reflection->isInstantiable()) + { + $buildStack = array(); + + throw new DependencyResolutionException("$resolvedKey can not be instantiated."); + } + $constructor = $reflection->getConstructor(); // If there are no parameters, just return a new object. if ($constructor === null) { - $callback = function () use ($key) { - return new $key; + $callback = function () use ($resolvedKey) { + return new $resolvedKey; }; } else @@ -144,7 +239,12 @@ public function buildObject($key, $shared = false) }; } - return $this->set($key, $callback, $shared)->get($key); + $this->set($resolvedKey, $callback, $shared); + + $resource = $this->get($resolvedKey); + array_pop($buildStack); + + return $resource; } /** @@ -186,7 +286,7 @@ public function createChild() * @return void * * @since 1.0 - * @throws \InvalidArgumentException + * @throws KeyNotFoundException */ public function extend($key, \Closure $callable) { @@ -195,10 +295,10 @@ public function extend($key, \Closure $callable) if ($raw === null) { - throw new \InvalidArgumentException(sprintf('The requested key %s does not exist to extend.', $key)); + throw new KeyNotFoundException(sprintf('The requested key %s does not exist to extend.', $key)); } - $closure = function ($c) use($callable, $raw) { + $closure = function ($c) use ($callable, $raw) { return $callable($raw['callback']($c), $c); }; @@ -270,15 +370,14 @@ protected function getMethodArgs(\ReflectionMethod $method) * * @return Container This object for chaining. * - * @throws \OutOfBoundsException Thrown if the provided key is already set and is protected. - * * @since 1.0 + * @throws ProtectedKeyException Thrown if the provided key is already set and is protected. */ public function set($key, $value, $shared = false, $protected = false) { if (isset($this->dataStore[$key]) && $this->dataStore[$key]['protected'] === true) { - throw new \OutOfBoundsException(sprintf('Key %s is protected and can\'t be overwritten.', $key)); + throw new ProtectedKeyException(sprintf("Key %s is protected and can't be overwritten.", $key)); } // If the provided $value is not a closure, make it one now for easy resolution. @@ -301,33 +400,33 @@ public function set($key, $value, $shared = false, $protected = false) /** * Convenience method for creating protected keys. * - * @param string $key Name of dataStore key to set. - * @param callable $callback Callable function to run when requesting the specified $key. - * @param bool $shared True to create and store a shared instance. + * @param string $key Name of dataStore key to set. + * @param mixed $value Callable function to run or string to retrive when requesting the specified $key. + * @param boolean $shared True to create and store a shared instance. * * @return Container This object for chaining. * * @since 1.0 */ - public function protect($key, $callback, $shared = false) + public function protect($key, $value, $shared = false) { - return $this->set($key, $callback, $shared, true); + return $this->set($key, $value, $shared, true); } /** * Convenience method for creating shared keys. * - * @param string $key Name of dataStore key to set. - * @param callable $callback Callable function to run when requesting the specified $key. - * @param bool $protected True to create and store a shared instance. + * @param string $key Name of dataStore key to set. + * @param mixed $value Callable function to run or string to retrive when requesting the specified $key. + * @param boolean $protected True to protect this item from being overwritten. Useful for services. * * @return Container This object for chaining. * * @since 1.0 */ - public function share($key, $callback, $protected = false) + public function share($key, $value, $protected = false) { - return $this->set($key, $callback, true, $protected); + return $this->set($key, $value, true, $protected); } /** @@ -339,7 +438,7 @@ public function share($key, $callback, $protected = false) * @return mixed Results of running the $callback for the specified $key. * * @since 1.0 - * @throws \InvalidArgumentException + * @throws KeyNotFoundException */ public function get($key, $forceNew = false) { @@ -348,7 +447,7 @@ public function get($key, $forceNew = false) if ($raw === null) { - throw new \InvalidArgumentException(sprintf('Key %s has not been registered with the container.', $key)); + throw new KeyNotFoundException(sprintf('Key %s has not been registered with the container.', $key)); } if ($raw['shared']) @@ -371,13 +470,35 @@ public function get($key, $forceNew = false) * * @return boolean True for success * - * @since 1.0 + * @since 1.5.0 */ - public function exists($key) + public function has($key) { $key = $this->resolveAlias($key); - return (bool) $this->getRaw($key); + $exists = (bool) $this->getRaw($key); + + if ($exists === false && $this->parent instanceof ContainerInterface) + { + $exists = $this->parent->has($key); + } + + return $exists; + } + + /** + * Method to check if specified dataStore key exists. + * + * @param string $key Name of the dataStore key to check. + * + * @return boolean True for success + * + * @since 1.0 + * @deprecated 3.0 Use ContainerInterface::has() instead + */ + public function exists($key) + { + return $this->has($key); } /** @@ -408,6 +529,24 @@ protected function getRaw($key) return $this->parent->getRaw($key); } + if ($this->parent instanceof ContainerInterface && $this->parent->has($key)) + { + $callback = $this->parent->get($key); + + if (!is_callable($callback)) + { + $callback = function () use ($callback) { + return $callback; + }; + } + + return array( + 'callback' => $callback, + 'shared' => true, + 'protected' => true, + ); + } + return null; } @@ -441,4 +580,16 @@ public function registerServiceProvider(ServiceProviderInterface $provider) return $this; } + + /** + * Retrieve the keys for services assigned to this container. + * + * @return array + * + * @since 1.5.0 + */ + public function getKeys() + { + return array_unique(array_merge(array_keys($this->aliases), array_keys($this->dataStore))); + } } diff --git a/libraries/vendor/joomla/di/src/ContainerAwareInterface.php b/libraries/vendor/joomla/di/src/ContainerAwareInterface.php index e6b284b386f64..216122118f34d 100644 --- a/libraries/vendor/joomla/di/src/ContainerAwareInterface.php +++ b/libraries/vendor/joomla/di/src/ContainerAwareInterface.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework DI Package * - * @copyright Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ diff --git a/libraries/vendor/joomla/di/src/ContainerAwareTrait.php b/libraries/vendor/joomla/di/src/ContainerAwareTrait.php index b6b21aa6aee9b..a4dd2cf14b50f 100644 --- a/libraries/vendor/joomla/di/src/ContainerAwareTrait.php +++ b/libraries/vendor/joomla/di/src/ContainerAwareTrait.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework DI Package * - * @copyright Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ diff --git a/libraries/vendor/joomla/di/src/Exception/DependencyResolutionException.php b/libraries/vendor/joomla/di/src/Exception/DependencyResolutionException.php index d39763c894b18..1ed46f5f2ced9 100644 --- a/libraries/vendor/joomla/di/src/Exception/DependencyResolutionException.php +++ b/libraries/vendor/joomla/di/src/Exception/DependencyResolutionException.php @@ -2,17 +2,19 @@ /** * Part of the Joomla Framework DI Package * - * @copyright Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ namespace Joomla\DI\Exception; +use Psr\Container\ContainerExceptionInterface; + /** * Exception class for handling errors in resolving a dependency * * @since 1.0 */ -class DependencyResolutionException extends \Exception +class DependencyResolutionException extends \RuntimeException implements ContainerExceptionInterface { } diff --git a/libraries/vendor/joomla/di/src/Exception/KeyNotFoundException.php b/libraries/vendor/joomla/di/src/Exception/KeyNotFoundException.php new file mode 100644 index 0000000000000..975fb74e855ab --- /dev/null +++ b/libraries/vendor/joomla/di/src/Exception/KeyNotFoundException.php @@ -0,0 +1,20 @@ +args[] = $arg; diff --git a/libraries/vendor/joomla/input/src/Cookie.php b/libraries/vendor/joomla/input/src/Cookie.php index 0c9ba3611b0f8..e36b7ea66aa18 100644 --- a/libraries/vendor/joomla/input/src/Cookie.php +++ b/libraries/vendor/joomla/input/src/Cookie.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Input Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -25,7 +25,7 @@ class Cookie extends Input * * @since 1.0 */ - public function __construct(array $source = null, array $options = array()) + public function __construct($source = null, array $options = array()) { if (isset($options['filter'])) { diff --git a/libraries/vendor/joomla/input/src/Files.php b/libraries/vendor/joomla/input/src/Files.php index a5518c3086cf0..49533a5a801b1 100644 --- a/libraries/vendor/joomla/input/src/Files.php +++ b/libraries/vendor/joomla/input/src/Files.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Input Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -34,7 +34,7 @@ class Files extends Input * * @since 1.0 */ - public function __construct(array $source = null, array $options = array()) + public function __construct($source = null, array $options = array()) { if (isset($options['filter'])) { diff --git a/libraries/vendor/joomla/input/src/Input.php b/libraries/vendor/joomla/input/src/Input.php index c7a5f871635be..2c259d44ad161 100644 --- a/libraries/vendor/joomla/input/src/Input.php +++ b/libraries/vendor/joomla/input/src/Input.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Input Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -276,7 +276,7 @@ public function def($name, $value) /** * Check if a value name exists. * - * @param string $path Value name + * @param string $name Value name * * @return boolean * @@ -354,7 +354,7 @@ public function serialize() * * @param string $input The serialized input. * - * @return Input The input object. + * @return void * * @since 1.0 */ diff --git a/libraries/vendor/joomla/input/src/Json.php b/libraries/vendor/joomla/input/src/Json.php index 9f4280ac602f7..12a752497a86e 100644 --- a/libraries/vendor/joomla/input/src/Json.php +++ b/libraries/vendor/joomla/input/src/Json.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Input Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -34,7 +34,7 @@ class Json extends Input * * @since 1.0 */ - public function __construct(array $source = null, array $options = array()) + public function __construct($source = null, array $options = array()) { if (isset($options['filter'])) { diff --git a/libraries/vendor/joomla/ldap/src/LdapClient.php b/libraries/vendor/joomla/ldap/src/LdapClient.php index 4e407d63cc071..fd2459345c6e8 100644 --- a/libraries/vendor/joomla/ldap/src/LdapClient.php +++ b/libraries/vendor/joomla/ldap/src/LdapClient.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework LDAP Package * - * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -11,7 +11,8 @@ /** * LDAP client class * - * @since 1.0 + * @since 1.0 + * @deprecated The joomla/ldap package is deprecated */ class LdapClient { @@ -386,11 +387,11 @@ public function search(array $filters, $dnoverride = null, array $attributes = a $dn = $this->base_dn; } - foreach ($filters as $search_filter) + foreach ($filters as $searchFilter) { - $search_result = ldap_search($this->resource, $dn, $search_filter, $attributes); + $searchResult = ldap_search($this->resource, $dn, $searchFilter, $attributes); - if ($search_result && ($count = ldap_count_entries($this->resource, $search_result)) > 0) + if ($searchResult && ($count = ldap_count_entries($this->resource, $searchResult)) > 0) { for ($i = 0; $i < $count; $i++) { @@ -398,7 +399,7 @@ public function search(array $filters, $dnoverride = null, array $attributes = a if (!$i) { - $firstentry = ldap_first_entry($this->resource, $search_result); + $firstentry = ldap_first_entry($this->resource, $searchResult); } else { @@ -406,10 +407,10 @@ public function search(array $filters, $dnoverride = null, array $attributes = a } // Load user-specified attributes - $result_array = ldap_get_attributes($this->resource, $firstentry); + $attributeResult = ldap_get_attributes($this->resource, $firstentry); // LDAP returns an array of arrays, fit this into attributes result array - foreach ($result_array as $ki => $ai) + foreach ($attributeResult as $ki => $ai) { if (is_array($ai)) { @@ -719,7 +720,7 @@ public static function ipToNetAddress($ip) * @author Jay Burrell, Systems & Networks, Mississippi State University * @since 1.0 */ - public static function LdapNetAddr($networkaddress) + public static function ldapNetAddr($networkaddress) { $addr = ""; $addrtype = (int) substr($networkaddress, 0, 1); diff --git a/libraries/vendor/joomla/registry/src/AbstractRegistryFormat.php b/libraries/vendor/joomla/registry/src/AbstractRegistryFormat.php index 5ef0fcfa490fa..b08cb051af38d 100644 --- a/libraries/vendor/joomla/registry/src/AbstractRegistryFormat.php +++ b/libraries/vendor/joomla/registry/src/AbstractRegistryFormat.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ diff --git a/libraries/vendor/joomla/registry/src/Factory.php b/libraries/vendor/joomla/registry/src/Factory.php index 7300c335413cf..6de86a507a191 100644 --- a/libraries/vendor/joomla/registry/src/Factory.php +++ b/libraries/vendor/joomla/registry/src/Factory.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ diff --git a/libraries/vendor/joomla/registry/src/Format/Ini.php b/libraries/vendor/joomla/registry/src/Format/Ini.php index 0582f13592a93..1d96244f55525 100644 --- a/libraries/vendor/joomla/registry/src/Format/Ini.php +++ b/libraries/vendor/joomla/registry/src/Format/Ini.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -32,7 +32,7 @@ class Ini extends AbstractRegistryFormat ); /** - * A cache used by stringToobject. + * A cache used by stringToObject. * * @var array * @since 1.0 @@ -54,9 +54,10 @@ class Ini extends AbstractRegistryFormat */ public function objectToString($object, $options = array()) { - $options = array_merge(self::$options, $options); + $options = array_merge(self::$options, $options); + $supportArrayValues = $options['supportArrayValues']; - $local = array(); + $local = array(); $global = array(); $variables = get_object_vars($object); @@ -64,7 +65,7 @@ public function objectToString($object, $options = array()) $last = count($variables); // Assume that the first element is in section - $in_section = true; + $inSection = true; // Iterate over the object to set the properties. foreach ($variables as $key => $value) @@ -73,7 +74,7 @@ public function objectToString($object, $options = array()) if (is_object($value)) { // Add an empty line if previous string wasn't in a section - if (!$in_section) + if (!$inSection) { $local[] = ''; } @@ -84,14 +85,14 @@ public function objectToString($object, $options = array()) // Add the properties for this section. foreach (get_object_vars($value) as $k => $v) { - if (is_array($v) && $options['supportArrayValues']) + if (is_array($v) && $supportArrayValues) { $assoc = ArrayHelper::isAssociative($v); - foreach ($v as $array_key => $item) + foreach ($v as $arrayKey => $item) { - $array_key = ($assoc) ? $array_key : ''; - $local[] = $k . '[' . $array_key . ']=' . $this->getValueAsIni($item); + $arrayKey = $assoc ? $arrayKey : ''; + $local[] = $k . '[' . $arrayKey . ']=' . $this->getValueAsIni($item); } } else @@ -101,26 +102,26 @@ public function objectToString($object, $options = array()) } // Add empty line after section if it is not the last one - if (0 != --$last) + if (0 !== --$last) { $local[] = ''; } } - elseif (is_array($value) && $options['supportArrayValues']) + elseif (is_array($value) && $supportArrayValues) { $assoc = ArrayHelper::isAssociative($value); - foreach ($value as $array_key => $item) + foreach ($value as $arrayKey => $item) { - $array_key = ($assoc) ? $array_key : ''; - $global[] = $key . '[' . $array_key . ']=' . $this->getValueAsIni($item); + $arrayKey = $assoc ? $arrayKey : ''; + $global[] = $key . '[' . $arrayKey . ']=' . $this->getValueAsIni($item); } } else { // Not in a section so add the property to the global array. - $global[] = $key . '=' . $this->getValueAsIni($value); - $in_section = false; + $global[] = $key . '=' . $this->getValueAsIni($value); + $inSection = false; } } @@ -155,10 +156,10 @@ public function stringToObject($data, array $options = array()) return new stdClass; } - $obj = new stdClass; + $obj = new stdClass; $section = false; - $array = false; - $lines = explode("\n", $data); + $array = false; + $lines = explode("\n", $data); // Process the lines. foreach ($lines as $line) @@ -167,7 +168,7 @@ public function stringToObject($data, array $options = array()) $line = trim($line); // Ignore empty lines and comments. - if (empty($line) || ($line{0} == ';')) + if (empty($line) || ($line[0] === ';')) { continue; } @@ -177,14 +178,14 @@ public function stringToObject($data, array $options = array()) $length = strlen($line); // If we are processing sections and the line is a section add the object and continue. - if (($line[0] == '[') && ($line[$length - 1] == ']')) + if ($line[0] === '[' && ($line[$length - 1] === ']')) { - $section = substr($line, 1, $length - 2); + $section = substr($line, 1, $length - 2); $obj->$section = new stdClass; continue; } } - elseif ($line{0} == '[') + elseif ($line[0] === '[') { continue; } @@ -200,21 +201,21 @@ public function stringToObject($data, array $options = array()) list ($key, $value) = explode('=', $line, 2); // If we have an array item - if (substr($key, -1) == ']' && ($open_brace = strpos($key, '[', 1)) !== false) + if (substr($key, -1) === ']' && ($openBrace = strpos($key, '[', 1)) !== false) { if ($options['supportArrayValues']) { - $array = true; - $array_key = substr($key, $open_brace + 1, -1); + $array = true; + $arrayKey = substr($key, $openBrace + 1, -1); // If we have a multi-dimensional array or malformed key - if (strpos($array_key, '[') !== false || strpos($array_key, ']') !== false) + if (strpos($arrayKey, '[') !== false || strpos($arrayKey, ']') !== false) { // Maybe throw exception? continue; } - $key = substr($key, 0, $open_brace); + $key = substr($key, 0, $openBrace); } else { @@ -232,10 +233,10 @@ public function stringToObject($data, array $options = array()) // If the value is quoted then we assume it is a string. $length = strlen($value); - if ($length && ($value[0] == '"') && ($value[$length - 1] == '"')) + if ($length && ($value[0] === '"') && ($value[$length - 1] === '"')) { // Strip the quotes and Convert the new line characters. - $value = stripcslashes(substr($value, 1, ($length - 2))); + $value = stripcslashes(substr($value, 1, $length - 2)); $value = str_replace('\n', "\n", $value); } else @@ -243,22 +244,22 @@ public function stringToObject($data, array $options = array()) // If the value is not quoted, we assume it is not a string. // If the value is 'false' assume boolean false. - if ($value == 'false') + if ($value === 'false') { $value = false; } - elseif ($value == 'true') - // If the value is 'true' assume boolean true. + elseif ($value === 'true') + // If the value is 'true' assume boolean true. { $value = true; } - elseif ($options['parseBooleanWords'] && in_array(strtolower($value), array('yes', 'no'))) - // If the value is 'yes' or 'no' and option is enabled assume appropriate boolean + elseif ($options['parseBooleanWords'] && in_array(strtolower($value), array('yes', 'no'), true)) + // If the value is 'yes' or 'no' and option is enabled assume appropriate boolean { - $value = (strtolower($value) == 'yes'); + $value = (strtolower($value) === 'yes'); } elseif (is_numeric($value)) - // If the value is numeric than it is either a float or int. + // If the value is numeric than it is either a float or int. { // If there is a period then we assume a float. if (strpos($value, '.') !== false) @@ -282,9 +283,9 @@ public function stringToObject($data, array $options = array()) $obj->$section->$key = array(); } - if (!empty($array_key)) + if (!empty($arrayKey)) { - $obj->$section->{$key}[$array_key] = $value; + $obj->$section->{$key}[$arrayKey] = $value; } else { @@ -305,9 +306,9 @@ public function stringToObject($data, array $options = array()) $obj->$key = array(); } - if (!empty($array_key)) + if (!empty($arrayKey)) { - $obj->{$key}[$array_key] = $value; + $obj->{$key}[$arrayKey] = $value; } else { diff --git a/libraries/vendor/joomla/registry/src/Format/Json.php b/libraries/vendor/joomla/registry/src/Format/Json.php index 0aed96abb6e3a..2e67261fc40cc 100644 --- a/libraries/vendor/joomla/registry/src/Format/Json.php +++ b/libraries/vendor/joomla/registry/src/Format/Json.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -29,17 +29,17 @@ class Json extends AbstractRegistryFormat */ public function objectToString($object, $options = array()) { - $bitmask = isset($options['bitmask']) ? $options['bitmask'] : 0; + $bitMask = isset($options['bitmask']) ? $options['bitmask'] : 0; // The depth parameter is only present as of PHP 5.5 if (version_compare(PHP_VERSION, '5.5', '>=')) { $depth = isset($options['depth']) ? $options['depth'] : 512; - return json_encode($object, $bitmask, $depth); + return json_encode($object, $bitMask, $depth); } - return json_encode($object, $bitmask); + return json_encode($object, $bitMask); } /** @@ -59,7 +59,7 @@ public function stringToObject($data, array $options = array('processSections' = { $data = trim($data); - if ((substr($data, 0, 1) != '{') && (substr($data, -1, 1) != '}')) + if ($data !== '' && $data[0] !== '{') { return AbstractRegistryFormat::getInstance('Ini')->stringToObject($data, $options); } @@ -67,11 +67,11 @@ public function stringToObject($data, array $options = array('processSections' = $decoded = json_decode($data); // Check for an error decoding the data - if ($decoded === null) + if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) { throw new \RuntimeException(sprintf('Error decoding JSON data: %s', json_last_error_msg())); } - return $decoded; + return (object) $decoded; } } diff --git a/libraries/vendor/joomla/registry/src/Format/Php.php b/libraries/vendor/joomla/registry/src/Format/Php.php index 9f6004a70d3ef..06e2aded572be 100644 --- a/libraries/vendor/joomla/registry/src/Format/Php.php +++ b/libraries/vendor/joomla/registry/src/Format/Php.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -44,21 +44,21 @@ public function objectToString($object, $params = array()) } elseif (is_array($v) || is_object($v)) { - $vars .= "\tpublic $" . $k . " = " . $this->getArrayString((array) $v) . ";\n"; + $vars .= "\tpublic $" . $k . ' = ' . $this->getArrayString((array) $v) . ";\n"; } } $str = " $v) { - $s .= ($i) ? ', ' : ''; + $s .= $i ? ', ' : ''; $s .= '"' . $k . '" => '; if (is_array($v) || is_object($v)) diff --git a/libraries/vendor/joomla/registry/src/Format/Xml.php b/libraries/vendor/joomla/registry/src/Format/Xml.php index 874e5d54cf353..c168ff8c03452 100644 --- a/libraries/vendor/joomla/registry/src/Format/Xml.php +++ b/libraries/vendor/joomla/registry/src/Format/Xml.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -33,8 +33,8 @@ class Xml extends AbstractRegistryFormat */ public function objectToString($object, $options = array()) { - $rootName = (isset($options['name'])) ? $options['name'] : 'registry'; - $nodeName = (isset($options['nodeName'])) ? $options['nodeName'] : 'node'; + $rootName = isset($options['name']) ? $options['name'] : 'registry'; + $nodeName = isset($options['nodeName']) ? $options['nodeName'] : 'node'; // Create the root node. $root = simplexml_load_string('<' . $rootName . ' />'); diff --git a/libraries/vendor/joomla/registry/src/Format/Yaml.php b/libraries/vendor/joomla/registry/src/Format/Yaml.php index 18b3deb1c8399..86175f8b3c19c 100644 --- a/libraries/vendor/joomla/registry/src/Format/Yaml.php +++ b/libraries/vendor/joomla/registry/src/Format/Yaml.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -79,6 +79,6 @@ public function stringToObject($data, array $options = array()) { $array = $this->parser->parse(trim($data)); - return json_decode(json_encode($array)); + return (object) json_decode(json_encode($array)); } } diff --git a/libraries/vendor/joomla/registry/src/FormatInterface.php b/libraries/vendor/joomla/registry/src/FormatInterface.php index 03d3be3140665..94a704849b570 100644 --- a/libraries/vendor/joomla/registry/src/FormatInterface.php +++ b/libraries/vendor/joomla/registry/src/FormatInterface.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ diff --git a/libraries/vendor/joomla/registry/src/Registry.php b/libraries/vendor/joomla/registry/src/Registry.php index 8f753549e43b4..b0bc7004a3b36 100644 --- a/libraries/vendor/joomla/registry/src/Registry.php +++ b/libraries/vendor/joomla/registry/src/Registry.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Registry Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -20,7 +20,7 @@ class Registry implements \JsonSerializable, \ArrayAccess, \IteratorAggregate, \ /** * Registry Object * - * @var object + * @var \stdClass * @since 1.0 */ protected $data; @@ -36,7 +36,7 @@ class Registry implements \JsonSerializable, \ArrayAccess, \IteratorAggregate, \ /** * Registry instances container. * - * @var array + * @var Registry[] * @since 1.0 * @deprecated 2.0 Object caching will no longer be supported */ @@ -63,7 +63,11 @@ public function __construct($data = null) $this->data = new \stdClass; // Optionally load supplied data. - if (is_array($data) || is_object($data)) + if ($data instanceof Registry) + { + $this->merge($data); + } + elseif (is_array($data) || is_object($data)) { $this->bindData($this->data, $data); } @@ -76,7 +80,7 @@ public function __construct($data = null) /** * Magic function to clone the registry object. * - * @return Registry + * @return void * * @since 1.0 */ @@ -102,7 +106,7 @@ public function __toString() * * @return integer The custom count as an integer. * - * @link http://php.net/manual/en/countable.count.php + * @link https://secure.php.net/manual/en/countable.count.php * @since 1.3.0 */ public function count() @@ -163,7 +167,7 @@ public function exists($path) $nodes = explode($this->separator, $path); // Initialize the current node to be the registry root. - $node = $this->data; + $node = $this->data; $found = false; // Traverse the registry to find the correct node for the result. @@ -171,7 +175,7 @@ public function exists($path) { if (is_array($node) && isset($node[$n])) { - $node = $node[$n]; + $node = $node[$n]; $found = true; continue; } @@ -181,7 +185,7 @@ public function exists($path) return false; } - $node = $node->$n; + $node = $node->$n; $found = true; } @@ -215,7 +219,7 @@ public function get($path, $default = null) $nodes = explode($this->separator, trim($path)); // Initialize the current node to be the registry root. - $node = $this->data; + $node = $this->data; $found = false; // Traverse the registry to find the correct node for the result. @@ -223,7 +227,7 @@ public function get($path, $default = null) { if (is_array($node) && isset($node[$n])) { - $node = $node[$n]; + $node = $node[$n]; $found = true; continue; @@ -234,7 +238,7 @@ public function get($path, $default = null) return $default; } - $node = $node->$n; + $node = $node->$n; $found = true; } @@ -385,7 +389,7 @@ public function loadString($data, $format = 'JSON', $options = array()) * @param Registry $source Source Registry object to merge. * @param boolean $recursive True to support recursive merge the children values. * - * @return Registry Return this object to support chaining. + * @return Registry|false Return this object to support chaining or false if $source is not an instance of Registry. * * @since 1.0 */ @@ -414,7 +418,7 @@ public function extract($path) { $data = $this->get($path); - if (is_null($data)) + if ($data === null) { return null; } @@ -476,7 +480,7 @@ public function offsetSet($offset, $value) */ public function offsetUnset($offset) { - $this->set($offset, null); + $this->remove($offset); } /** @@ -497,7 +501,7 @@ public function set($path, $value, $separator = null) $separator = $this->separator; } - /** + /* * Explode the registry path into an array and remove empty * nodes that occur as a result of a double separator. ex: joomla..test * Finally, re-key the array so they are sequential. @@ -517,7 +521,7 @@ public function set($path, $value, $separator = null) { if (is_object($node)) { - if (!isset($node->{$nodes[$i]}) && ($i != $n)) + if (!isset($node->{$nodes[$i]}) && ($i !== $n)) { $node->{$nodes[$i]} = new \stdClass; } @@ -530,7 +534,7 @@ public function set($path, $value, $separator = null) if (is_array($node)) { - if (!isset($node[$nodes[$i]]) && ($i != $n)) + if (($i !== $n) && !isset($node[$nodes[$i]])) { $node[$nodes[$i]] = new \stdClass; } @@ -573,7 +577,7 @@ public function append($path, $value) { $result = null; - /** + /* * Explode the registry path into an array and remove empty * nodes that occur as a result of a double dot. ex: joomla..test * Finally, re-key the array so they are sequential. @@ -591,7 +595,7 @@ public function append($path, $value) { if (is_object($node)) { - if (!isset($node->{$nodes[$i]}) && ($i != $n)) + if (!isset($node->{$nodes[$i]}) && ($i !== $n)) { $node->{$nodes[$i]} = new \stdClass; } @@ -601,7 +605,7 @@ public function append($path, $value) } elseif (is_array($node)) { - if (!isset($node[$nodes[$i]]) && ($i != $n)) + if (($i !== $n) && !isset($node[$nodes[$i]])) { $node[$nodes[$i]] = new \stdClass; } @@ -612,18 +616,106 @@ public function append($path, $value) } if (!is_array($node)) - // Convert the node to array to make append possible + // Convert the node to array to make append possible { $node = get_object_vars($node); } - array_push($node, $value); + $node[] = $value; $result = $value; } return $result; } + /** + * Delete a registry value + * + * @param string $path Registry Path (e.g. joomla.content.showauthor) + * + * @return mixed The value of the removed node or null if not set + * + * @since 1.6.0 + */ + public function remove($path) + { + // Cheap optimisation to direct remove the node if there is no separator + if (!strpos($path, $this->separator)) + { + $result = (isset($this->data->$path) && $this->data->$path !== null && $this->data->$path !== '') ? $this->data->$path : null; + + unset($this->data->$path); + + return $result; + } + + /* + * Explode the registry path into an array and remove empty + * nodes that occur as a result of a double separator. ex: joomla..test + * Finally, re-key the array so they are sequential. + */ + $nodes = array_values(array_filter(explode($this->separator, $path), 'strlen')); + + if (!$nodes) + { + return null; + } + + // Initialize the current node to be the registry root. + $node = $this->data; + $parent = null; + + // Traverse the registry to find the correct node for the result. + for ($i = 0, $n = count($nodes) - 1; $i < $n; $i++) + { + if (is_object($node)) + { + if (!isset($node->{$nodes[$i]}) && ($i !== $n)) + { + continue; + } + + $parent = &$node; + $node = $node->{$nodes[$i]}; + + continue; + } + + if (is_array($node)) + { + if (($i !== $n) && !isset($node[$nodes[$i]])) + { + continue; + } + + $parent = &$node; + $node = $node[$nodes[$i]]; + + continue; + } + } + + // Get the old value if exists so we can return it + switch (true) + { + case (is_object($node)): + $result = isset($node->{$nodes[$i]}) ? $node->{$nodes[$i]} : null; + unset($parent->{$nodes[$i]}); + break; + + case (is_array($node)): + $result = isset($node[$nodes[$i]]) ? $node[$nodes[$i]] : null; + unset($parent[$nodes[$i]]); + break; + + default: + $result = null; + break; + } + + return $result; + } + /** * Transforms a namespace to an array * @@ -684,9 +776,7 @@ protected function bindData($parent, $data, $recursive = true, $allowNull = true $this->initialized = true; // Ensure the input data is an array. - $data = is_object($data) - ? get_object_vars($data) - : (array) $data; + $data = is_object($data) ? get_object_vars($data) : (array) $data; foreach ($data as $k => $v) { @@ -772,7 +862,7 @@ public function flatten($separator = null) * * @param string $separator The key separator. * @param array|object $data Data source of this scope. - * @param array &$array The result array, it is pass by reference. + * @param array $array The result array, it is passed by reference. * @param string $prefix Last level key prefix. * * @return void diff --git a/libraries/vendor/joomla/utilities/src/ArrayHelper.php b/libraries/vendor/joomla/utilities/src/ArrayHelper.php index b155ba3fd40f6..bd8a86d4f7c6f 100644 --- a/libraries/vendor/joomla/utilities/src/ArrayHelper.php +++ b/libraries/vendor/joomla/utilities/src/ArrayHelper.php @@ -2,7 +2,7 @@ /** * Part of the Joomla Framework Utilities Package * - * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. + * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ @@ -29,8 +29,8 @@ private function __construct() /** * Function to convert array to integer values * - * @param array $array The source array to convert - * @param mixed $default A default value (int|array) to assign if $array is not an array + * @param array $array The source array to convert + * @param int|array $default A default value to assign if $array is not an array * * @return array * @@ -90,15 +90,15 @@ public static function toObject(array $array, $class = 'stdClass', $recursive = * Utility function to map an array to a string. * * @param array $array The array to map. - * @param string $inner_glue The glue (optional, defaults to '=') between the key and the value. - * @param string $outer_glue The glue (optional, defaults to ' ') between array elements. + * @param string $innerGlue The glue (optional, defaults to '=') between the key and the value. + * @param string $outerGlue The glue (optional, defaults to ' ') between array elements. * @param boolean $keepOuterKey True if final key should be kept. * * @return string * * @since 1.0 */ - public static function toString(array $array, $inner_glue = '=', $outer_glue = ' ', $keepOuterKey = false) + public static function toString(array $array, $innerGlue = '=', $outerGlue = ' ', $keepOuterKey = false) { $output = array(); @@ -112,21 +112,21 @@ public static function toString(array $array, $inner_glue = '=', $outer_glue = ' } // This is value is an array, go and do it again! - $output[] = static::toString($item, $inner_glue, $outer_glue, $keepOuterKey); + $output[] = static::toString($item, $innerGlue, $outerGlue, $keepOuterKey); } else { - $output[] = $key . $inner_glue . '"' . $item . '"'; + $output[] = $key . $innerGlue . '"' . $item . '"'; } } - return implode($outer_glue, $output); + return implode($outerGlue, $output); } /** * Utility function to map an object to an array * - * @param object $p_obj The source object + * @param object $source The source object * @param boolean $recurse True to recurse through multi-level objects * @param string $regex An optional regular expression to match on field names * @@ -134,11 +134,11 @@ public static function toString(array $array, $inner_glue = '=', $outer_glue = ' * * @since 1.0 */ - public static function fromObject($p_obj, $recurse = true, $regex = null) + public static function fromObject($source, $recurse = true, $regex = null) { - if (is_object($p_obj) || is_array($p_obj)) + if (is_object($source) || is_array($source)) { - return self::arrayFromObject($p_obj, $recurse, $regex); + return self::arrayFromObject($source, $recurse, $regex); } return array(); @@ -194,6 +194,100 @@ private static function arrayFromObject($item, $recurse, $regex) return $item; } + /** + * Adds a column to an array of arrays or objects + * + * @param array $array The source array + * @param array $column The array to be used as new column + * @param string $colName The index of the new column or name of the new object property + * @param string $keyCol The index of the column or name of object property to be used for mapping with the new column + * + * @return array An array with the new column added to the source array + * + * @since 1.5.0 + * @see https://secure.php.net/manual/en/language.types.array.php + */ + public static function addColumn(array $array, array $column, $colName, $keyCol = null) + { + $result = array(); + + foreach ($array as $i => $item) + { + $value = null; + + if (!isset($keyCol)) + { + $value = static::getValue($column, $i); + } + else + { + // Convert object to array + $subject = is_object($item) ? static::fromObject($item) : $item; + + if (isset($subject[$keyCol]) && is_scalar($subject[$keyCol])) + { + $value = static::getValue($column, $subject[$keyCol]); + } + } + + // Add the column + if (is_object($item)) + { + if (isset($colName)) + { + $item->$colName = $value; + } + } + else + { + if (isset($colName)) + { + $item[$colName] = $value; + } + else + { + $item[] = $value; + } + } + + $result[$i] = $item; + } + + return $result; + } + + /** + * Remove a column from an array of arrays or objects + * + * @param array $array The source array + * @param string $colName The index of the column or name of object property to be removed + * + * @return array Column of values from the source array + * + * @since 1.5.0 + * @see https://secure.php.net/manual/en/language.types.array.php + */ + public static function dropColumn(array $array, $colName) + { + $result = array(); + + foreach ($array as $i => $item) + { + if (is_object($item) && isset($item->$colName)) + { + unset($item->$colName); + } + elseif (is_array($item) && isset($item[$colName])) + { + unset($item[$colName]); + } + + $result[$i] = $item; + } + + return $result; + } + /** * Extracts a column from an array of arrays or objects * @@ -206,11 +300,17 @@ private static function arrayFromObject($item, $recurse, $regex) * @return array Column of values from the source array * * @since 1.0 - * @see http://php.net/manual/en/language.types.array.php - * @see http://php.net/manual/en/function.array-column.php + * @see https://secure.php.net/manual/en/language.types.array.php + * @see https://secure.php.net/manual/en/function.array-column.php */ public static function getColumn(array $array, $valueCol, $keyCol = null) { + // As of PHP 7, array_column() supports an array of objects so we'll use that + if (PHP_VERSION_ID >= 70000) + { + return array_column($array, $valueCol, $keyCol); + } + $result = array(); foreach ($array as $item) @@ -247,7 +347,7 @@ public static function getColumn(array $array, $valueCol, $keyCol = null) * Utility function to return a value from a named array or a specified default * * @param array|\ArrayAccess $array A named array or object that implements ArrayAccess - * @param string $name The key to search for + * @param string $name The key to search for (this can be an array index or a dot separated key sequence as in Registry) * @param mixed $default The default value to give if no key found * @param string $type Return type for the variable (INT, FLOAT, STRING, WORD, BOOLEAN, ARRAY) * @@ -269,6 +369,15 @@ public static function getValue($array, $name, $default = null, $type = '') { $result = $array[$name]; } + elseif (strpos($name, '.')) + { + list($name, $subset) = explode('.', $name, 2); + + if (isset($array[$name]) && is_array($array[$name])) + { + return static::getValue($array[$name], $subset, $default, $type); + } + } // Handle the default case if (is_null($result)) @@ -559,7 +668,7 @@ public static function sortObjects(array $a, $k, $direction = 1, $caseSensitive * * @return array * - * @see http://php.net/manual/en/function.array-unique.php + * @see https://secure.php.net/manual/en/function.array-unique.php * @since 1.0 */ public static function arrayUnique(array $array) diff --git a/libraries/vendor/paragonie/random_compat/lib/random.php b/libraries/vendor/paragonie/random_compat/lib/random.php index 30fb90c45b54d..8a29adc9b5d90 100644 --- a/libraries/vendor/paragonie/random_compat/lib/random.php +++ b/libraries/vendor/paragonie/random_compat/lib/random.php @@ -3,8 +3,8 @@ * Random_* Compatibility Library * for using the new PHP 7 random_* API in PHP 5 projects * - * @version 2.0.4 - * @released 2016-11-07 + * @version 1.4.3 + * @released 2018-04-04 * * The MIT License (MIT) * diff --git a/libraries/vendor/paragonie/sodium_compat/LICENSE b/libraries/vendor/paragonie/sodium_compat/LICENSE index b97a56059df9c..532a3cf52707f 100644 --- a/libraries/vendor/paragonie/sodium_compat/LICENSE +++ b/libraries/vendor/paragonie/sodium_compat/LICENSE @@ -1,10 +1,10 @@ /* * ISC License * - * Copyright (c) 2016-2017 + * Copyright (c) 2016-2018 * Paragon Initiative Enterprises * - * Copyright (c) 2013-2017 + * Copyright (c) 2013-2018 * Frank Denis * * Permission to use, copy, modify, and/or distribute this software for any diff --git a/libraries/vendor/paragonie/sodium_compat/autoload.php b/libraries/vendor/paragonie/sodium_compat/autoload.php index 5827eff7db726..de2683daee522 100644 --- a/libraries/vendor/paragonie/sodium_compat/autoload.php +++ b/libraries/vendor/paragonie/sodium_compat/autoload.php @@ -8,7 +8,7 @@ * * @return bool Stop autoloading? */ - function sodiumCompatAutoader($class) + function sodiumCompatAutoloader($class) { $namespace = 'ParagonIE_Sodium_'; // Does the class use the namespace prefix? @@ -34,9 +34,10 @@ function sodiumCompatAutoader($class) } // Now that we have an autoloader, let's register it! - spl_autoload_register('sodiumCompatAutoader'); + spl_autoload_register('sodiumCompatAutoloader'); } +require_once dirname(__FILE__) . '/src/SodiumException.php'; if (PHP_VERSION_ID >= 50300) { // Namespaces didn't exist before 5.3.0, so don't even try to use this // unless PHP >= 5.3.0 diff --git a/libraries/vendor/paragonie/sodium_compat/lib/constants.php b/libraries/vendor/paragonie/sodium_compat/lib/constants.php index e60d0f01c1415..8ddb6a4879c36 100644 --- a/libraries/vendor/paragonie/sodium_compat/lib/constants.php +++ b/libraries/vendor/paragonie/sodium_compat/lib/constants.php @@ -3,6 +3,10 @@ use ParagonIE_Sodium_Compat; +const CRYPTO_AEAD_AES256GCM_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_KEYBYTES; +const CRYPTO_AEAD_AES256GCM_NSECBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_NSECBYTES; +const CRYPTO_AEAD_AES256GCM_NPUBBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_NPUBBYTES; +const CRYPTO_AEAD_AES256GCM_ABYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_AES256GCM_ABYTES; const CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES; const CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES = ParagonIE_Sodium_Compat::CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES; @@ -21,6 +25,7 @@ const CRYPTO_BOX_NONCEBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_NONCEBYTES; const CRYPTO_BOX_SEEDBYTES = ParagonIE_Sodium_Compat::CRYPTO_BOX_SEEDBYTES; const CRYPTO_KX_BYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_BYTES; +const CRYPTO_KX_SEEDBYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_SEEDBYTES; const CRYPTO_KX_PUBLICKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_PUBLICKEYBYTES; const CRYPTO_KX_SECRETKEYBYTES = ParagonIE_Sodium_Compat::CRYPTO_KX_SECRETKEYBYTES; const CRYPTO_GENERICHASH_BYTES = ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES; diff --git a/libraries/vendor/paragonie/sodium_compat/lib/php72compat.php b/libraries/vendor/paragonie/sodium_compat/lib/php72compat.php index 1f0906e3b73fd..6f22f342d7f2a 100644 --- a/libraries/vendor/paragonie/sodium_compat/lib/php72compat.php +++ b/libraries/vendor/paragonie/sodium_compat/lib/php72compat.php @@ -12,6 +12,10 @@ 'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_ABYTES', + 'CRYPTO_AEAD_AES256GCM_KEYBYTES', + 'CRYPTO_AEAD_AES256GCM_NSECBYTES', + 'CRYPTO_AEAD_AES256GCM_NPUBBYTES', + 'CRYPTO_AEAD_AES256GCM_ABYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES', 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES', @@ -26,6 +30,7 @@ 'CRYPTO_BOX_NONCEBYTES', 'CRYPTO_BOX_SEEDBYTES', 'CRYPTO_KX_BYTES', + 'CRYPTO_KX_SEEDBYTES', 'CRYPTO_KX_PUBLICKEYBYTES', 'CRYPTO_KX_SECRETKEYBYTES', 'CRYPTO_GENERICHASH_BYTES', @@ -36,6 +41,8 @@ 'CRYPTO_GENERICHASH_KEYBYTES_MAX', 'CRYPTO_PWHASH_SALTBYTES', 'CRYPTO_PWHASH_STRPREFIX', + 'CRYPTO_PWHASH_ALG_ARGON2I13', + 'CRYPTO_PWHASH_ALG_ARGON2ID13', 'CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE', 'CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE', 'CRYPTO_PWHASH_MEMLIMIT_MODERATE', @@ -65,8 +72,11 @@ if (!is_callable('sodium_bin2hex')) { /** + * @see ParagonIE_Sodium_Compat::hex2bin() * @param string $string * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_bin2hex($string) { @@ -75,17 +85,67 @@ function sodium_bin2hex($string) } if (!is_callable('sodium_compare')) { /** + * @see ParagonIE_Sodium_Compat::compare() * @param string $a * @param string $b * @return int + * @throws SodiumException + * @throws TypeError */ function sodium_compare($a, $b) { return ParagonIE_Sodium_Compat::compare($a, $b); } } +if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() + * @param string $message + * @param string $assocData + * @param string $nonce + * @param string $key + * @return string + */ + function sodium_crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) + { + try { + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); + } catch (Error $ex) { + return false; + } catch (Exception $ex) { + return false; + } + } +} +if (!is_callable('sodium_crypto_aead_aes256gcm_encrypt')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() + * @param string $message + * @param string $assocData + * @param string $nonce + * @param string $key + * @return string + * @throws SodiumException + * @throws TypeError + */ + function sodium_crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key) + { + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key); + } +} +if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() + * @return bool + */ + function sodium_crypto_aead_aes256gcm_is_available() + { + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); + } +} if (!is_callable('sodium_crypto_aead_chacha20poly1305_decrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() * @param string $message * @param string $assocData * @param string $nonce @@ -105,19 +165,33 @@ function sodium_crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonc } if (!is_callable('sodium_crypto_aead_chacha20poly1305_encrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key) { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key); } } +if (!is_callable('sodium_crypto_aead_chacha20poly1305_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen() + * @return string + */ + function sodium_crypto_aead_chacha20poly1305_keygen() + { + return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen(); + } +} if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_decrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() * @param string $message * @param string $assocData * @param string $nonce @@ -137,19 +211,33 @@ function sodium_crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, } if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_encrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) { return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key); } } +if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen() + * @return string + */ + function sodium_crypto_aead_chacha20poly1305_ietf_keygen() + { + return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen(); + } +} if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt() * @param string $message * @param string $assocData * @param string $nonce @@ -169,34 +257,63 @@ function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, } if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) { return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key); } } +if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen() + * @return string + */ + function sodium_crypto_aead_xchacha20poly1305_ietf_keygen() + { + return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen(); + } +} if (!is_callable('sodium_crypto_auth')) { /** + * @see ParagonIE_Sodium_Compat::crypto_auth() * @param string $message * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_auth($message, $key) { return ParagonIE_Sodium_Compat::crypto_auth($message, $key); } } +if (!is_callable('sodium_crypto_auth_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_auth_keygen() + * @return string + */ + function sodium_crypto_auth_keygen() + { + return ParagonIE_Sodium_Compat::crypto_auth_keygen(); + } +} if (!is_callable('sodium_crypto_auth_verify')) { /** + * @see ParagonIE_Sodium_Compat::crypto_auth_verify() * @param string $mac * @param string $message * @param string $key * @return bool + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_auth_verify($mac, $message, $key) { @@ -205,10 +322,13 @@ function sodium_crypto_auth_verify($mac, $message, $key) } if (!is_callable('sodium_crypto_box')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box() * @param string $message * @param string $nonce * @param string $kp * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box($message, $nonce, $kp) { @@ -217,7 +337,10 @@ function sodium_crypto_box($message, $nonce, $kp) } if (!is_callable('sodium_crypto_box_keypair')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_keypair() * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box_keypair() { @@ -226,9 +349,12 @@ function sodium_crypto_box_keypair() } if (!is_callable('sodium_crypto_box_keypair_from_secretkey_and_publickey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() * @param string $sk * @param string $pk * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) { @@ -237,6 +363,7 @@ function sodium_crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) } if (!is_callable('sodium_crypto_box_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_open() * @param string $message * @param string $nonce * @param string $kp @@ -255,8 +382,11 @@ function sodium_crypto_box_open($message, $nonce, $kp) } if (!is_callable('sodium_crypto_box_publickey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_publickey() * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box_publickey($keypair) { @@ -265,8 +395,11 @@ function sodium_crypto_box_publickey($keypair) } if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box_publickey_from_secretkey($sk) { @@ -275,9 +408,12 @@ function sodium_crypto_box_publickey_from_secretkey($sk) } if (!is_callable('sodium_crypto_box_seal')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_seal() * @param string $message * @param string $publicKey * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box_seal($message, $publicKey) { @@ -286,6 +422,7 @@ function sodium_crypto_box_seal($message, $publicKey) } if (!is_callable('sodium_crypto_box_seal_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() * @param string $message * @param string $kp * @return string|bool @@ -303,8 +440,11 @@ function sodium_crypto_box_seal_open($message, $kp) } if (!is_callable('sodium_crypto_box_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box_secretkey($keypair) { @@ -313,8 +453,11 @@ function sodium_crypto_box_secretkey($keypair) } if (!is_callable('sodium_crypto_box_seed_keypair')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_seed_keypair() * @param string $seed * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_box_seed_keypair($seed) { @@ -323,10 +466,13 @@ function sodium_crypto_box_seed_keypair($seed) } if (!is_callable('sodium_crypto_generichash')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash() * @param string $message * @param string|null $key * @param int $outLen * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_generichash($message, $key = null, $outLen = 32) { @@ -335,9 +481,12 @@ function sodium_crypto_generichash($message, $key = null, $outLen = 32) } if (!is_callable('sodium_crypto_generichash_final')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash_final() * @param string|null $ctx * @param int $outputLength * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_generichash_final(&$ctx, $outputLength = 32) { @@ -346,20 +495,36 @@ function sodium_crypto_generichash_final(&$ctx, $outputLength = 32) } if (!is_callable('sodium_crypto_generichash_init')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash_init() * @param string|null $key * @param int $outLen * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_generichash_init($key = null, $outLen = 32) { return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen); } } +if (!is_callable('sodium_crypto_generichash_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen() + * @return string + */ + function sodium_crypto_generichash_keygen() + { + return ParagonIE_Sodium_Compat::crypto_generichash_keygen(); + } +} if (!is_callable('sodium_crypto_generichash_update')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash_update() * @param string|null $ctx * @param string $message * @return void + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_generichash_update(&$ctx, $message = '') { @@ -368,11 +533,14 @@ function sodium_crypto_generichash_update(&$ctx, $message = '') } if (!is_callable('sodium_crypto_kx')) { /** + * @see ParagonIE_Sodium_Compat::crypto_kx() * @param string $my_secret * @param string $their_public * @param string $client_public * @param string $server_public * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_kx($my_secret, $their_public, $client_public, $server_public) { @@ -386,24 +554,31 @@ function sodium_crypto_kx($my_secret, $their_public, $client_public, $server_pub } if (!is_callable('sodium_crypto_pwhash')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash() * @param int $outlen * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit + * @param int|null $algo * @return string + * @throws SodiumException + * @throws TypeError */ - function sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit) + function sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo = null) { - return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit); + return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo); } } if (!is_callable('sodium_crypto_pwhash_str')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_pwhash_str($passwd, $opslimit, $memlimit) { @@ -412,9 +587,12 @@ function sodium_crypto_pwhash_str($passwd, $opslimit, $memlimit) } if (!is_callable('sodium_crypto_pwhash_str_verify')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() * @param string $passwd * @param string $hash * @return bool + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_pwhash_str_verify($passwd, $hash) { @@ -423,12 +601,15 @@ function sodium_crypto_pwhash_str_verify($passwd, $hash) } if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() * @param int $outlen * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit) { @@ -437,10 +618,13 @@ function sodium_crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $ops } if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit) { @@ -449,9 +633,12 @@ function sodium_crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $meml } if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str_verify')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify() * @param string $passwd * @param string $hash * @return bool + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) { @@ -460,9 +647,12 @@ function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) } if (!is_callable('sodium_crypto_scalarmult')) { /** + * @see ParagonIE_Sodium_Compat::crypto_scalarmult() * @param string $n * @param string $p * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_scalarmult($n, $p) { @@ -471,8 +661,11 @@ function sodium_crypto_scalarmult($n, $p) } if (!is_callable('sodium_crypto_scalarmult_base')) { /** + * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() * @param string $n * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_scalarmult_base($n) { @@ -481,18 +674,32 @@ function sodium_crypto_scalarmult_base($n) } if (!is_callable('sodium_crypto_secretbox')) { /** + * @see ParagonIE_Sodium_Compat::crypto_secretbox() * @param string $message * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_secretbox($message, $nonce, $key) { return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key); } } +if (!is_callable('sodium_crypto_secretbox_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_secretbox_keygen() + * @return string + */ + function sodium_crypto_secretbox_keygen() + { + return ParagonIE_Sodium_Compat::crypto_secretbox_keygen(); + } +} if (!is_callable('sodium_crypto_secretbox_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() * @param string $message * @param string $nonce * @param string $key @@ -511,20 +718,36 @@ function sodium_crypto_secretbox_open($message, $nonce, $key) } if (!is_callable('sodium_crypto_shorthash')) { /** + * @see ParagonIE_Sodium_Compat::crypto_shorthash() * @param string $message * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_shorthash($message, $key = '') { return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key); } } +if (!is_callable('sodium_crypto_shorthash_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_shorthash_keygen() + * @return string + */ + function sodium_crypto_shorthash_keygen() + { + return ParagonIE_Sodium_Compat::crypto_shorthash_keygen(); + } +} if (!is_callable('sodium_crypto_sign')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign() * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign($message, $sk) { @@ -533,9 +756,12 @@ function sodium_crypto_sign($message, $sk) } if (!is_callable('sodium_crypto_sign_detached')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_detached() * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign_detached($message, $sk) { @@ -544,7 +770,10 @@ function sodium_crypto_sign_detached($message, $sk) } if (!is_callable('sodium_crypto_sign_keypair')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign_keypair() { @@ -553,6 +782,7 @@ function sodium_crypto_sign_keypair() } if (!is_callable('sodium_crypto_sign_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_open() * @param string $signedMessage * @param string $pk * @return string|bool @@ -570,8 +800,11 @@ function sodium_crypto_sign_open($signedMessage, $pk) } if (!is_callable('sodium_crypto_sign_publickey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign_publickey($keypair) { @@ -580,8 +813,11 @@ function sodium_crypto_sign_publickey($keypair) } if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign_publickey_from_secretkey($sk) { @@ -590,8 +826,11 @@ function sodium_crypto_sign_publickey_from_secretkey($sk) } if (!is_callable('sodium_crypto_sign_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign_secretkey($keypair) { @@ -600,8 +839,11 @@ function sodium_crypto_sign_secretkey($keypair) } if (!is_callable('sodium_crypto_sign_seed_keypair')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() * @param string $seed * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign_seed_keypair($seed) { @@ -610,34 +852,79 @@ function sodium_crypto_sign_seed_keypair($seed) } if (!is_callable('sodium_crypto_sign_verify_detached')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() * @param string $signature * @param string $message * @param string $pk * @return bool + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_sign_verify_detached($signature, $message, $pk) { return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk); } } +if (!is_callable('sodium_crypto_sign_ed25519_pk_to_curve25519')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() + * @param string $pk + * @return string + * @throws SodiumException + * @throws TypeError + */ + function sodium_crypto_sign_ed25519_pk_to_curve25519($pk) + { + return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk); + } +} +if (!is_callable('sodium_crypto_sign_ed25519_sk_to_curve25519')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() + * @param string $sk + * @return string + * @throws SodiumException + * @throws TypeError + */ + function sodium_crypto_sign_ed25519_sk_to_curve25519($sk) + { + return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk); + } +} if (!is_callable('sodium_crypto_stream')) { /** + * @see ParagonIE_Sodium_Compat::crypto_stream() * @param int $len * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_stream($len, $nonce, $key) { return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key); } } +if (!is_callable('sodium_crypto_stream_keygen')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_stream_keygen() + * @return string + */ + function sodium_crypto_stream_keygen() + { + return ParagonIE_Sodium_Compat::crypto_stream_keygen(); + } +} if (!is_callable('sodium_crypto_stream_xor')) { /** + * @see ParagonIE_Sodium_Compat::crypto_stream_xor() * @param string $message * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_crypto_stream_xor($message, $nonce, $key) { @@ -646,8 +933,11 @@ function sodium_crypto_stream_xor($message, $nonce, $key) } if (!is_callable('sodium_hex2bin')) { /** + * @see ParagonIE_Sodium_Compat::hex2bin() * @param string $string * @return string + * @throws SodiumException + * @throws TypeError */ function sodium_hex2bin($string) { @@ -656,8 +946,11 @@ function sodium_hex2bin($string) } if (!is_callable('sodium_increment')) { /** + * @see ParagonIE_Sodium_Compat::increment() * @param &string $string * @return void + * @throws SodiumException + * @throws TypeError */ function sodium_increment(&$string) { @@ -666,6 +959,7 @@ function sodium_increment(&$string) } if (!is_callable('sodium_library_version_major')) { /** + * @see ParagonIE_Sodium_Compat::library_version_major() * @return int */ function sodium_library_version_major() @@ -675,6 +969,7 @@ function sodium_library_version_major() } if (!is_callable('sodium_library_version_minor')) { /** + * @see ParagonIE_Sodium_Compat::library_version_minor() * @return int */ function sodium_library_version_minor() @@ -684,6 +979,7 @@ function sodium_library_version_minor() } if (!is_callable('sodium_version_string')) { /** + * @see ParagonIE_Sodium_Compat::version_string() * @return string */ function sodium_version_string() @@ -693,9 +989,12 @@ function sodium_version_string() } if (!is_callable('sodium_memcmp')) { /** + * @see ParagonIE_Sodium_Compat::memcmp() * @param string $a * @param string $b * @return int + * @throws SodiumException + * @throws TypeError */ function sodium_memcmp($a, $b) { @@ -704,8 +1003,11 @@ function sodium_memcmp($a, $b) } if (!is_callable('sodium_memzero')) { /** + * @see ParagonIE_Sodium_Compat::memzero() * @param string &$str * @return void + * @throws SodiumException + * @throws TypeError */ function sodium_memzero(&$str) { @@ -714,8 +1016,10 @@ function sodium_memzero(&$str) } if (!is_callable('sodium_randombytes_buf')) { /** + * @see ParagonIE_Sodium_Compat::randombytes_buf() * @param int $amount * @return string + * @throws Exception */ function sodium_randombytes_buf($amount) { @@ -725,8 +1029,10 @@ function sodium_randombytes_buf($amount) if (!is_callable('sodium_randombytes_uniform')) { /** + * @see ParagonIE_Sodium_Compat::randombytes_uniform() * @param int $upperLimit * @return int + * @throws Exception */ function sodium_randombytes_uniform($upperLimit) { @@ -736,6 +1042,7 @@ function sodium_randombytes_uniform($upperLimit) if (!is_callable('sodium_randombytes_random16')) { /** + * @see ParagonIE_Sodium_Compat::randombytes_random16() * @return int */ function sodium_randombytes_random16() diff --git a/libraries/vendor/paragonie/sodium_compat/lib/sodium_compat.php b/libraries/vendor/paragonie/sodium_compat/lib/sodium_compat.php index 5124853d5c0d6..1799bb57e3ac3 100644 --- a/libraries/vendor/paragonie/sodium_compat/lib/sodium_compat.php +++ b/libraries/vendor/paragonie/sodium_compat/lib/sodium_compat.php @@ -12,8 +12,11 @@ */ if (!is_callable('\\Sodium\\bin2hex')) { /** + * @see ParagonIE_Sodium_Compat::bin2hex() * @param string $string * @return string + * @throws \SodiumException + * @throws \TypeError */ function bin2hex($string) { @@ -22,22 +25,76 @@ function bin2hex($string) } if (!is_callable('\\Sodium\\compare')) { /** + * @see ParagonIE_Sodium_Compat::compare() * @param string $a * @param string $b * @return int + * @throws \SodiumException + * @throws \TypeError */ function compare($a, $b) { return ParagonIE_Sodium_Compat::compare($a, $b); } } +if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_decrypt')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() + * @param string $message + * @param string $assocData + * @param string $nonce + * @param string $key + * @return string|bool + * @throws \SodiumException + * @throws \TypeError + */ + function crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) + { + try { + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); + } catch (Error $ex) { + return false; + } catch (Exception $ex) { + return false; + } + } +} +if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_encrypt')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() + * @param string $message + * @param string $assocData + * @param string $nonce + * @param string $key + * @return string + * @throws \SodiumException + * @throws \TypeError + */ + function crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key) + { + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key); + } +} +if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_is_available')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() + * @return bool + */ + function crypto_aead_aes256gcm_is_available() + { + return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); + } +} if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_decrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string|bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key) { @@ -52,11 +109,14 @@ function crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key } if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_encrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key) { @@ -65,11 +125,14 @@ function crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key } if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_decrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string|bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) { @@ -84,11 +147,14 @@ function crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, } if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_encrypt')) { /** + * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() * @param string $message * @param string $assocData * @param string $nonce * @param string $key * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) { @@ -97,9 +163,12 @@ function crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, } if (!is_callable('\\Sodium\\crypto_auth')) { /** + * @see ParagonIE_Sodium_Compat::crypto_auth() * @param string $message * @param string $key * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_auth($message, $key) { @@ -108,10 +177,13 @@ function crypto_auth($message, $key) } if (!is_callable('\\Sodium\\crypto_auth_verify')) { /** + * @see ParagonIE_Sodium_Compat::crypto_auth_verify() * @param string $mac * @param string $message * @param string $key * @return bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_auth_verify($mac, $message, $key) { @@ -120,10 +192,13 @@ function crypto_auth_verify($mac, $message, $key) } if (!is_callable('\\Sodium\\crypto_box')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box() * @param string $message * @param string $nonce * @param string $kp * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_box($message, $nonce, $kp) { @@ -132,7 +207,10 @@ function crypto_box($message, $nonce, $kp) } if (!is_callable('\\Sodium\\crypto_box_keypair')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_keypair() * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_box_keypair() { @@ -141,9 +219,12 @@ function crypto_box_keypair() } if (!is_callable('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() * @param string $sk * @param string $pk * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) { @@ -152,10 +233,13 @@ function crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) } if (!is_callable('\\Sodium\\crypto_box_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_open() * @param string $message * @param string $nonce * @param string $kp * @return string|bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_box_open($message, $nonce, $kp) { @@ -170,8 +254,11 @@ function crypto_box_open($message, $nonce, $kp) } if (!is_callable('\\Sodium\\crypto_box_publickey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_publickey() * @param string $keypair * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_box_publickey($keypair) { @@ -180,8 +267,11 @@ function crypto_box_publickey($keypair) } if (!is_callable('\\Sodium\\crypto_box_publickey_from_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() * @param string $sk * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_box_publickey_from_secretkey($sk) { @@ -190,9 +280,12 @@ function crypto_box_publickey_from_secretkey($sk) } if (!is_callable('\\Sodium\\crypto_box_seal')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() * @param string $message * @param string $publicKey * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_box_seal($message, $publicKey) { @@ -201,9 +294,11 @@ function crypto_box_seal($message, $publicKey) } if (!is_callable('\\Sodium\\crypto_box_seal_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() * @param string $message * @param string $kp * @return string|bool + * @throws \TypeError */ function crypto_box_seal_open($message, $kp) { @@ -218,8 +313,11 @@ function crypto_box_seal_open($message, $kp) } if (!is_callable('\\Sodium\\crypto_box_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() * @param string $keypair * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_box_secretkey($keypair) { @@ -228,10 +326,13 @@ function crypto_box_secretkey($keypair) } if (!is_callable('\\Sodium\\crypto_generichash')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash() * @param string $message * @param string|null $key * @param int $outLen * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_generichash($message, $key = null, $outLen = 32) { @@ -240,9 +341,12 @@ function crypto_generichash($message, $key = null, $outLen = 32) } if (!is_callable('\\Sodium\\crypto_generichash_final')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash_final() * @param string|null $ctx * @param int $outputLength * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_generichash_final(&$ctx, $outputLength = 32) { @@ -251,9 +355,12 @@ function crypto_generichash_final(&$ctx, $outputLength = 32) } if (!is_callable('\\Sodium\\crypto_generichash_init')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash_init() * @param string|null $key * @param int $outLen * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_generichash_init($key = null, $outLen = 32) { @@ -262,9 +369,12 @@ function crypto_generichash_init($key = null, $outLen = 32) } if (!is_callable('\\Sodium\\crypto_generichash_update')) { /** + * @see ParagonIE_Sodium_Compat::crypto_generichash_update() * @param string|null $ctx * @param string $message * @return void + * @throws \SodiumException + * @throws \TypeError */ function crypto_generichash_update(&$ctx, $message = '') { @@ -273,11 +383,14 @@ function crypto_generichash_update(&$ctx, $message = '') } if (!is_callable('\\Sodium\\crypto_kx')) { /** + * @see ParagonIE_Sodium_Compat::crypto_kx() * @param string $my_secret * @param string $their_public * @param string $client_public * @param string $server_public * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_kx($my_secret, $their_public, $client_public, $server_public) { @@ -291,12 +404,15 @@ function crypto_kx($my_secret, $their_public, $client_public, $server_public) } if (!is_callable('\\Sodium\\crypto_pwhash')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash() * @param int $outlen * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit) { @@ -305,10 +421,13 @@ function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit) } if (!is_callable('\\Sodium\\crypto_pwhash_str')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_pwhash_str($passwd, $opslimit, $memlimit) { @@ -317,9 +436,12 @@ function crypto_pwhash_str($passwd, $opslimit, $memlimit) } if (!is_callable('\\Sodium\\crypto_pwhash_str_verify')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() * @param string $passwd * @param string $hash * @return bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_pwhash_str_verify($passwd, $hash) { @@ -328,12 +450,15 @@ function crypto_pwhash_str_verify($passwd, $hash) } if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() * @param int $outlen * @param string $passwd * @param string $salt * @param int $opslimit * @param int $memlimit * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit) { @@ -342,10 +467,13 @@ function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, } if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit) { @@ -354,9 +482,12 @@ function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit) } if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str_verify')) { /** + * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify() * @param string $passwd * @param string $hash * @return bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) { @@ -365,9 +496,12 @@ function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) } if (!is_callable('\\Sodium\\crypto_scalarmult')) { /** + * @see ParagonIE_Sodium_Compat::crypto_scalarmult() * @param string $n * @param string $p * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_scalarmult($n, $p) { @@ -376,8 +510,11 @@ function crypto_scalarmult($n, $p) } if (!is_callable('\\Sodium\\crypto_scalarmult_base')) { /** + * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() * @param string $n * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_scalarmult_base($n) { @@ -386,10 +523,13 @@ function crypto_scalarmult_base($n) } if (!is_callable('\\Sodium\\crypto_secretbox')) { /** + * @see ParagonIE_Sodium_Compat::crypto_secretbox() * @param string $message * @param string $nonce * @param string $key * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_secretbox($message, $nonce, $key) { @@ -398,10 +538,13 @@ function crypto_secretbox($message, $nonce, $key) } if (!is_callable('\\Sodium\\crypto_secretbox_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() * @param string $message * @param string $nonce * @param string $key * @return string|bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_secretbox_open($message, $nonce, $key) { @@ -416,9 +559,12 @@ function crypto_secretbox_open($message, $nonce, $key) } if (!is_callable('\\Sodium\\crypto_shorthash')) { /** + * @see ParagonIE_Sodium_Compat::crypto_shorthash() * @param string $message * @param string $key * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_shorthash($message, $key = '') { @@ -427,9 +573,12 @@ function crypto_shorthash($message, $key = '') } if (!is_callable('\\Sodium\\crypto_sign')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign() * @param string $message * @param string $sk * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign($message, $sk) { @@ -438,9 +587,12 @@ function crypto_sign($message, $sk) } if (!is_callable('\\Sodium\\crypto_sign_detached')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_detached() * @param string $message * @param string $sk * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_detached($message, $sk) { @@ -449,7 +601,10 @@ function crypto_sign_detached($message, $sk) } if (!is_callable('\\Sodium\\crypto_sign_keypair')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_keypair() { @@ -458,6 +613,7 @@ function crypto_sign_keypair() } if (!is_callable('\\Sodium\\crypto_sign_open')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_open() * @param string $signedMessage * @param string $pk * @return string|bool @@ -475,8 +631,11 @@ function crypto_sign_open($signedMessage, $pk) } if (!is_callable('\\Sodium\\crypto_sign_publickey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() * @param string $keypair * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_publickey($keypair) { @@ -485,8 +644,11 @@ function crypto_sign_publickey($keypair) } if (!is_callable('\\Sodium\\crypto_sign_publickey_from_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() * @param string $sk * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_publickey_from_secretkey($sk) { @@ -495,8 +657,11 @@ function crypto_sign_publickey_from_secretkey($sk) } if (!is_callable('\\Sodium\\crypto_sign_secretkey')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() * @param string $keypair * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_secretkey($keypair) { @@ -505,8 +670,11 @@ function crypto_sign_secretkey($keypair) } if (!is_callable('\\Sodium\\crypto_sign_seed_keypair')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() * @param string $seed * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_seed_keypair($seed) { @@ -515,20 +683,39 @@ function crypto_sign_seed_keypair($seed) } if (!is_callable('\\Sodium\\crypto_sign_verify_detached')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() * @param string $signature * @param string $message * @param string $pk * @return bool + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_verify_detached($signature, $message, $pk) { return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk); } } +if (!is_callable('\\Sodium\\crypto_sign_ed25519_pk_to_curve25519')) { + /** + * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() + * @param string $pk + * @return string + * @throws \SodiumException + * @throws \TypeError + */ + function crypto_sign_ed25519_pk_to_curve25519($pk) + { + return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk); + } +} if (!is_callable('\\Sodium\\crypto_sign_ed25519_sk_to_curve25519')) { /** + * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() * @param string $sk * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_sign_ed25519_sk_to_curve25519($sk) { @@ -537,10 +724,13 @@ function crypto_sign_ed25519_sk_to_curve25519($sk) } if (!is_callable('\\Sodium\\crypto_stream')) { /** + * @see ParagonIE_Sodium_Compat::crypto_stream() * @param int $len * @param string $nonce * @param string $key * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_stream($len, $nonce, $key) { @@ -549,10 +739,13 @@ function crypto_stream($len, $nonce, $key) } if (!is_callable('\\Sodium\\crypto_stream_xor')) { /** + * @see ParagonIE_Sodium_Compat::crypto_stream_xor() * @param string $message * @param string $nonce * @param string $key * @return string + * @throws \SodiumException + * @throws \TypeError */ function crypto_stream_xor($message, $nonce, $key) { @@ -561,8 +754,11 @@ function crypto_stream_xor($message, $nonce, $key) } if (!is_callable('\\Sodium\\hex2bin')) { /** + * @see ParagonIE_Sodium_Compat::hex2bin() * @param string $string * @return string + * @throws \SodiumException + * @throws \TypeError */ function hex2bin($string) { @@ -571,9 +767,12 @@ function hex2bin($string) } if (!is_callable('\\Sodium\\memcmp')) { /** + * @see ParagonIE_Sodium_Compat::memcmp() * @param string $a * @param string $b * @return int + * @throws \SodiumException + * @throws \TypeError */ function memcmp($a, $b) { @@ -582,8 +781,11 @@ function memcmp($a, $b) } if (!is_callable('\\Sodium\\memzero')) { /** + * @see ParagonIE_Sodium_Compat::memzero() * @param string $str * @return void + * @throws \SodiumException + * @throws \TypeError */ function memzero(&$str) { @@ -592,8 +794,10 @@ function memzero(&$str) } if (!is_callable('\\Sodium\\randombytes_buf')) { /** + * @see ParagonIE_Sodium_Compat::randombytes_buf() * @param int $amount * @return string + * @throws \TypeError */ function randombytes_buf($amount) { @@ -603,8 +807,11 @@ function randombytes_buf($amount) if (!is_callable('\\Sodium\\randombytes_uniform')) { /** + * @see ParagonIE_Sodium_Compat::randombytes_uniform() * @param int $upperLimit * @return int + * @throws \Exception + * @throws \Error */ function randombytes_uniform($upperLimit) { @@ -614,6 +821,7 @@ function randombytes_uniform($upperLimit) if (!is_callable('\\Sodium\\randombytes_random16')) { /** + * @see ParagonIE_Sodium_Compat::randombytes_random16() * @return int */ function randombytes_random16() diff --git a/libraries/vendor/paragonie/sodium_compat/src/Compat.php b/libraries/vendor/paragonie/sodium_compat/src/Compat.php index 064d7e7db8b4a..0082d3397e8bb 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Compat.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Compat.php @@ -49,6 +49,10 @@ class ParagonIE_Sodium_Compat const VERSION_STRING = 'polyfill-1.0.8'; // From libsodium + const CRYPTO_AEAD_AES256GCM_KEYBYTES = 32; + const CRYPTO_AEAD_AES256GCM_NSECBYTES = 0; + const CRYPTO_AEAD_AES256GCM_NPUBBYTES = 12; + const CRYPTO_AEAD_AES256GCM_ABYTES = 16; const CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES = 32; const CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES = 0; const CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES = 8; @@ -71,6 +75,7 @@ class ParagonIE_Sodium_Compat const CRYPTO_BOX_NONCEBYTES = 24; const CRYPTO_BOX_SEEDBYTES = 32; const CRYPTO_KX_BYTES = 32; + const CRYPTO_KX_SEEDBYTES = 32; const CRYPTO_KX_PUBLICKEYBYTES = 32; const CRYPTO_KX_SECRETKEYBYTES = 32; const CRYPTO_GENERICHASH_BYTES = 32; @@ -81,6 +86,8 @@ class ParagonIE_Sodium_Compat const CRYPTO_GENERICHASH_KEYBYTES_MAX = 64; const CRYPTO_PWHASH_SALTBYTES = 16; const CRYPTO_PWHASH_STRPREFIX = '$argon2i$'; + const CRYPTO_PWHASH_ALG_ARGON2I13 = 1; + const CRYPTO_PWHASH_ALG_ARGON2ID13 = 2; const CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE = 33554432; const CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE = 4; const CRYPTO_PWHASH_MEMLIMIT_MODERATE = 134217728; @@ -113,18 +120,20 @@ class ParagonIE_Sodium_Compat * * @param string $string A string (probably raw binary) * @return string A hexadecimal-encoded string + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function bin2hex($string) { /* Type checks: */ ParagonIE_Sodium_Core_Util::declareScalarType($string, 'string', 1); - if (self::isPhp72OrGreater()) { - return bin2hex($string); + if (self::useNewSodiumAPI()) { + return (string) sodium_bin2hex($string); } if (self::use_fallback('bin2hex')) { - return call_user_func('\\Sodium\\bin2hex', $string); + return (string) call_user_func('\\Sodium\\bin2hex', $string); } return ParagonIE_Sodium_Core_Util::bin2hex($string); } @@ -136,9 +145,11 @@ public static function bin2hex($string) * @param string $left The left operand; must be a string * @param string $right The right operand; must be a string * @return int < 0 if the left operand is less than the right - * 0 if both strings are equal + * = 0 if both strings are equal * > 0 if the right operand is less than the left + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function compare($left, $right) { @@ -146,15 +157,166 @@ public static function compare($left, $right) ParagonIE_Sodium_Core_Util::declareScalarType($left, 'string', 1); ParagonIE_Sodium_Core_Util::declareScalarType($right, 'string', 2); - if (self::isPhp72OrGreater()) { - return sodium_compare($left, $right); + if (self::useNewSodiumAPI()) { + return (int) sodium_compare($left, $right); } if (self::use_fallback('compare')) { - return call_user_func('\\Sodium\\compare', $left, $right); + return (int) call_user_func('\\Sodium\\compare', $left, $right); } return ParagonIE_Sodium_Core_Util::compare($left, $right); } + /** + * Is AES-256-GCM even available to use? + * + * @return bool + * @psalm-suppress UndefinedFunction + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement + */ + public static function crypto_aead_aes256gcm_is_available() + { + if (self::useNewSodiumAPI()) { + return sodium_crypto_aead_aes256gcm_is_available(); + } + if (self::use_fallback('crypto_aead_aes256gcm_is_available')) { + return call_user_func('\\Sodium\\crypto_aead_aes256gcm_is_available'); + } + if (PHP_VERSION_ID < 70100) { + // OpenSSL doesn't support AEAD before 7.1.0 + return false; + } + if (!is_callable('openssl_encrypt') || !is_callable('openssl_decrypt')) { + // OpenSSL isn't installed + return false; + } + return (bool) in_array('aes-256-gcm', openssl_get_cipher_methods()); + } + + /** + * Authenticated Encryption with Associated Data: Decryption + * + * Algorithm: + * AES-256-GCM + * + * This mode uses a 64-bit random nonce with a 64-bit counter. + * IETF mode uses a 96-bit random nonce with a 32-bit counter. + * + * @param string $ciphertext Encrypted message (with Poly1305 MAC appended) + * @param string $assocData Authenticated Associated Data (unencrypted) + * @param string $nonce Number to be used only Once; must be 8 bytes + * @param string $key Encryption key + * + * @return string|bool The original plaintext message + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement + */ + public static function crypto_aead_aes256gcm_decrypt( + $ciphertext = '', + $assocData = '', + $nonce = '', + $key = '' + ) { + if (!self::crypto_aead_aes256gcm_is_available()) { + throw new SodiumException('AES-256-GCM is not available'); + } + ParagonIE_Sodium_Core_Util::declareScalarType($ciphertext, 'string', 1); + ParagonIE_Sodium_Core_Util::declareScalarType($assocData, 'string', 2); + ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 3); + ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 4); + + /* Input validation: */ + if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_AES256GCM_NPUBBYTES) { + throw new SodiumException('Nonce must be CRYPTO_AEAD_AES256GCM_NPUBBYTES long'); + } + if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_AES256GCM_KEYBYTES) { + throw new SodiumException('Key must be CRYPTO_AEAD_AES256GCM_KEYBYTES long'); + } + if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_AEAD_AES256GCM_ABYTES) { + throw new SodiumException('Message must be at least CRYPTO_AEAD_AES256GCM_ABYTES long'); + } + + if (!self::crypto_aead_aes256gcm_is_available()) { + throw new SodiumException('AES-256-GCM is not available'); + } + $ctext = ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, -self::CRYPTO_AEAD_AES256GCM_ABYTES); + $authTag = ParagonIE_Sodium_Core_Util::substr($ciphertext, -self::CRYPTO_AEAD_AES256GCM_ABYTES, 16); + return openssl_decrypt( + $ctext, + 'aes-256-gcm', + $key, + OPENSSL_RAW_DATA, + $nonce, + $authTag, + $assocData + ); + } + + /** + * Authenticated Encryption with Associated Data: Encryption + * + * Algorithm: + * AES-256-GCM + * + * @param string $plaintext Message to be encrypted + * @param string $assocData Authenticated Associated Data (unencrypted) + * @param string $nonce Number to be used only Once; must be 8 bytes + * @param string $key Encryption key + * + * @return string Ciphertext with a 16-byte GCM message + * authentication code appended + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + */ + public static function crypto_aead_aes256gcm_encrypt( + $plaintext = '', + $assocData = '', + $nonce = '', + $key = '' + ) { + if (!self::crypto_aead_aes256gcm_is_available()) { + throw new SodiumException('AES-256-GCM is not available'); + } + ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1); + ParagonIE_Sodium_Core_Util::declareScalarType($assocData, 'string', 2); + ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 3); + ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 4); + + /* Input validation: */ + if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_AES256GCM_NPUBBYTES) { + throw new SodiumException('Nonce must be CRYPTO_AEAD_AES256GCM_NPUBBYTES long'); + } + if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_AES256GCM_KEYBYTES) { + throw new SodiumException('Key must be CRYPTO_AEAD_AES256GCM_KEYBYTES long'); + } + $authTag = ''; + $ciphertext = openssl_encrypt( + $plaintext, + 'aes-256-gcm', + $key, + OPENSSL_RAW_DATA, + $nonce, + $authTag, + $assocData + ); + return $ciphertext . $authTag; + } + + /** + * Return a secure random key for use with the AES-256-GCM + * symmetric AEAD interface. + * + * @return string + */ + public static function crypto_aead_aes256gcm_keygen() + { + return random_bytes(self::CRYPTO_AEAD_AES256GCM_KEYBYTES); + } + /** * Authenticated Encryption with Associated Data: Decryption * @@ -170,8 +332,11 @@ public static function compare($left, $right) * @param string $key Encryption key * * @return string The original plaintext message - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_aead_chacha20poly1305_decrypt( $ciphertext = '', @@ -187,16 +352,20 @@ public static function crypto_aead_chacha20poly1305_decrypt( /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES) { - throw new Error('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES long'); + throw new SodiumException('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES) { - throw new Error('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); + throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_AEAD_CHACHA20POLY1305_ABYTES) { - throw new Error('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_ABYTES long'); + throw new SodiumException('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_ABYTES long'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress FalsableReturnStatement + */ return sodium_crypto_aead_chacha20poly1305_decrypt( $ciphertext, $assocData, @@ -245,8 +414,9 @@ public static function crypto_aead_chacha20poly1305_decrypt( * * @return string Ciphertext with a 16-byte Poly1305 message * authentication code appended - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_aead_chacha20poly1305_encrypt( $plaintext = '', @@ -262,14 +432,14 @@ public static function crypto_aead_chacha20poly1305_encrypt( /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES) { - throw new Error('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES long'); + throw new SodiumException('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES) { - throw new Error('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); + throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_aead_chacha20poly1305_encrypt( + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_aead_chacha20poly1305_encrypt( $plaintext, $assocData, $nonce, @@ -277,7 +447,7 @@ public static function crypto_aead_chacha20poly1305_encrypt( ); } if (self::use_fallback('crypto_aead_chacha20poly1305_encrypt')) { - return call_user_func( + return (string) call_user_func( '\\Sodium\\crypto_aead_chacha20poly1305_encrypt', $plaintext, $assocData, @@ -316,8 +486,11 @@ public static function crypto_aead_chacha20poly1305_encrypt( * @param string $key Encryption key * * @return string The original plaintext message - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_aead_chacha20poly1305_ietf_decrypt( $ciphertext = '', @@ -333,16 +506,20 @@ public static function crypto_aead_chacha20poly1305_ietf_decrypt( /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES) { - throw new Error('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES long'); + throw new SodiumException('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES) { - throw new Error('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); + throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_AEAD_CHACHA20POLY1305_ABYTES) { - throw new Error('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_ABYTES long'); + throw new SodiumException('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_ABYTES long'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress FalsableReturnStatement + */ return sodium_crypto_aead_chacha20poly1305_ietf_decrypt( $ciphertext, $assocData, @@ -375,6 +552,17 @@ public static function crypto_aead_chacha20poly1305_ietf_decrypt( ); } + /** + * Return a secure random key for use with the ChaCha20-Poly1305 + * symmetric AEAD interface. + * + * @return string + */ + public static function crypto_aead_chacha20poly1305_keygen() + { + return random_bytes(self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES); + } + /** * Authenticated Encryption with Associated Data * @@ -391,8 +579,9 @@ public static function crypto_aead_chacha20poly1305_ietf_decrypt( * * @return string Ciphertext with a 16-byte Poly1305 message * authentication code appended - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_aead_chacha20poly1305_ietf_encrypt( $plaintext = '', @@ -408,14 +597,14 @@ public static function crypto_aead_chacha20poly1305_ietf_encrypt( /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES) { - throw new Error('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES long'); + throw new SodiumException('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES) { - throw new Error('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); + throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_aead_chacha20poly1305_ietf_encrypt( + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_aead_chacha20poly1305_ietf_encrypt( $plaintext, $assocData, $nonce, @@ -423,7 +612,7 @@ public static function crypto_aead_chacha20poly1305_ietf_encrypt( ); } if (self::use_fallback('crypto_aead_chacha20poly1305_ietf_encrypt')) { - return call_user_func( + return (string) call_user_func( '\\Sodium\\crypto_aead_chacha20poly1305_ietf_encrypt', $plaintext, $assocData, @@ -447,6 +636,17 @@ public static function crypto_aead_chacha20poly1305_ietf_encrypt( ); } + /** + * Return a secure random key for use with the ChaCha20-Poly1305 + * symmetric AEAD interface. (IETF version) + * + * @return string + */ + public static function crypto_aead_chacha20poly1305_ietf_keygen() + { + return random_bytes(self::CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES); + } + /** * Authenticated Encryption with Associated Data: Decryption * @@ -462,8 +662,9 @@ public static function crypto_aead_chacha20poly1305_ietf_encrypt( * @param string $key Encryption key * * @return string The original plaintext message - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_aead_xchacha20poly1305_ietf_decrypt( $ciphertext = '', @@ -479,13 +680,13 @@ public static function crypto_aead_xchacha20poly1305_ietf_decrypt( /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES) { - throw new Error('Nonce must be CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES long'); + throw new SodiumException('Nonce must be CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES) { - throw new Error('Key must be CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES long'); + throw new SodiumException('Key must be CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES) { - throw new Error('Message must be at least CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES long'); + throw new SodiumException('Message must be at least CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES long'); } if (PHP_INT_SIZE === 4) { @@ -520,8 +721,9 @@ public static function crypto_aead_xchacha20poly1305_ietf_decrypt( * * @return string Ciphertext with a 16-byte Poly1305 message * authentication code appended - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_aead_xchacha20poly1305_ietf_encrypt( $plaintext = '', @@ -537,10 +739,10 @@ public static function crypto_aead_xchacha20poly1305_ietf_encrypt( /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES) { - throw new Error('Nonce must be CRYPTO_AEAD_XCHACHA20POLY1305_NPUBBYTES long'); + throw new SodiumException('Nonce must be CRYPTO_AEAD_XCHACHA20POLY1305_NPUBBYTES long'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES) { - throw new Error('Key must be CRYPTO_AEAD_XCHACHA20POLY1305_KEYBYTES long'); + throw new SodiumException('Key must be CRYPTO_AEAD_XCHACHA20POLY1305_KEYBYTES long'); } if (PHP_INT_SIZE === 4) { @@ -559,6 +761,17 @@ public static function crypto_aead_xchacha20poly1305_ietf_encrypt( ); } + /** + * Return a secure random key for use with the XChaCha20-Poly1305 + * symmetric AEAD interface. + * + * @return string + */ + public static function crypto_aead_xchacha20poly1305_ietf_keygen() + { + return random_bytes(self::CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES); + } + /** * Authenticate a message. Uses symmetric-key cryptography. * @@ -572,8 +785,9 @@ public static function crypto_aead_xchacha20poly1305_ietf_encrypt( * @param string $message Message to be authenticated * @param string $key Symmetric authentication key * @return string Message authentication code - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_auth($message, $key) { @@ -583,14 +797,14 @@ public static function crypto_auth($message, $key) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AUTH_KEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_AUTH_KEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_AUTH_KEYBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_auth($message, $key); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_auth($message, $key); } if (self::use_fallback('crypto_auth')) { - return call_user_func('\\Sodium\\crypto_auth', $message, $key); + return (string) call_user_func('\\Sodium\\crypto_auth', $message, $key); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::auth($message, $key); @@ -598,6 +812,14 @@ public static function crypto_auth($message, $key) return ParagonIE_Sodium_Crypto::auth($message, $key); } + /** + * @return string + */ + public static function crypto_auth_keygen() + { + return random_bytes(self::CRYPTO_AUTH_KEYBYTES); + } + /** * Verify the MAC of a message previously authenticated with crypto_auth. * @@ -606,8 +828,9 @@ public static function crypto_auth($message, $key) * verify (with a given MAC and key) * @param string $key Symmetric authentication key * @return bool TRUE if authenticated, FALSE otherwise - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_auth_verify($mac, $message, $key) { @@ -618,17 +841,17 @@ public static function crypto_auth_verify($mac, $message, $key) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($mac) !== self::CRYPTO_AUTH_BYTES) { - throw new Error('Argument 1 must be CRYPTO_AUTH_BYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_AUTH_BYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AUTH_KEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_AUTH_KEYBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_AUTH_KEYBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_auth_verify($mac, $message, $key); + if (self::useNewSodiumAPI()) { + return (bool) sodium_crypto_auth_verify($mac, $message, $key); } if (self::use_fallback('crypto_auth_verify')) { - return call_user_func('\\Sodium\\crypto_auth_verify', $mac, $message, $key); + return (bool) call_user_func('\\Sodium\\crypto_auth_verify', $mac, $message, $key); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::auth_verify($mac, $message, $key); @@ -649,8 +872,9 @@ public static function crypto_auth_verify($mac, $message, $key) * @param string $nonce A Number to only be used Once; must be 24 bytes * @param string $keypair Your secret key and your recipient's public key * @return string Ciphertext with 16-byte Poly1305 MAC - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_box($plaintext, $nonce, $keypair) { @@ -661,17 +885,17 @@ public static function crypto_box($plaintext, $nonce, $keypair) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_BOX_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) { - throw new Error('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_box($plaintext, $nonce, $keypair); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box($plaintext, $nonce, $keypair); } if (self::use_fallback('crypto_box')) { - return call_user_func('\\Sodium\\crypto_box', $plaintext, $nonce, $keypair); + return (string) call_user_func('\\Sodium\\crypto_box', $plaintext, $nonce, $keypair); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::box($plaintext, $nonce, $keypair); @@ -692,8 +916,9 @@ public static function crypto_box($plaintext, $nonce, $keypair) * @param string $publicKey Your recipient's public key * @return string Sealed message that only your recipient can * decrypt - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_box_seal($plaintext, $publicKey) { @@ -703,14 +928,14 @@ public static function crypto_box_seal($plaintext, $publicKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_BOX_PUBLICKEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_box_seal($plaintext, $publicKey); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box_seal($plaintext, $publicKey); } if (self::use_fallback('crypto_box_seal')) { - return call_user_func('\\Sodium\\crypto_box_seal', $plaintext, $publicKey); + return (string) call_user_func('\\Sodium\\crypto_box_seal', $plaintext, $publicKey); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::box_seal($plaintext, $publicKey); @@ -727,8 +952,11 @@ public static function crypto_box_seal($plaintext, $publicKey) * @param string $ciphertext Sealed message to be opened * @param string $keypair Your crypto_box keypair * @return string The original plaintext message - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_box_seal_open($ciphertext, $keypair) { @@ -738,10 +966,14 @@ public static function crypto_box_seal_open($ciphertext, $keypair) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) { - throw new Error('Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress FalsableReturnStatement + */ return sodium_crypto_box_seal_open($ciphertext, $keypair); } if (self::use_fallback('crypto_box_seal_open')) { @@ -760,14 +992,17 @@ public static function crypto_box_seal_open($ciphertext, $keypair) * the last 32 are your public key. crypto_box_secretkey() * and crypto_box_publickey() exist to separate them so you * don't accidentally get them mixed up! + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_box_keypair() { - if (self::isPhp72OrGreater()) { - return sodium_crypto_box_keypair(); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box_keypair(); } if (self::use_fallback('crypto_box_keypair')) { - return call_user_func('\\Sodium\\crypto_box_keypair'); + return (string) call_user_func('\\Sodium\\crypto_box_keypair'); } return ParagonIE_Sodium_Crypto::box_keypair(); } @@ -779,8 +1014,9 @@ public static function crypto_box_keypair() * @param string $secretKey Secret key * @param string $publicKey Public key * @return string Keypair - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey) { @@ -790,17 +1026,17 @@ public static function crypto_box_keypair_from_secretkey_and_publickey($secretKe /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) { - throw new Error('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_BOX_PUBLICKEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey); } if (self::use_fallback('crypto_box_keypair_from_secretkey_and_publickey')) { - return call_user_func('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey', $secretKey, $publicKey); + return (string) call_user_func('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey', $secretKey, $publicKey); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::box_keypair_from_secretkey_and_publickey($secretKey, $publicKey); @@ -815,8 +1051,11 @@ public static function crypto_box_keypair_from_secretkey_and_publickey($secretKe * @param string $nonce Number to only be used Once; must be 24 bytes * @param string $keypair Your secret key and the sender's public key * @return string The original plaintext message - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_box_open($ciphertext, $nonce, $keypair) { @@ -827,16 +1066,20 @@ public static function crypto_box_open($ciphertext, $nonce, $keypair) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($ciphertext) < self::CRYPTO_BOX_MACBYTES) { - throw new Error('Argument 1 must be at least CRYPTO_BOX_MACBYTES long.'); + throw new SodiumException('Argument 1 must be at least CRYPTO_BOX_MACBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_BOX_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) { - throw new Error('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress FalsableReturnStatement + */ return sodium_crypto_box_open($ciphertext, $nonce, $keypair); } if (self::use_fallback('crypto_box_open')) { @@ -853,8 +1096,9 @@ public static function crypto_box_open($ciphertext, $nonce, $keypair) * * @param string $keypair * @return string Your crypto_box public key - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_box_publickey($keypair) { @@ -863,14 +1107,14 @@ public static function crypto_box_publickey($keypair) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) { - throw new Error('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_box_publickey($keypair); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box_publickey($keypair); } if (self::use_fallback('crypto_box_publickey')) { - return call_user_func('\\Sodium\\crypto_box_publickey', $keypair); + return (string) call_user_func('\\Sodium\\crypto_box_publickey', $keypair); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::box_publickey($keypair); @@ -883,8 +1127,9 @@ public static function crypto_box_publickey($keypair) * * @param string $secretKey Any X25519 secret key * @return string The corresponding X25519 public key - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_box_publickey_from_secretkey($secretKey) { @@ -893,14 +1138,14 @@ public static function crypto_box_publickey_from_secretkey($secretKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) { - throw new Error('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_box_publickey_from_secretkey($secretKey); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box_publickey_from_secretkey($secretKey); } if (self::use_fallback('crypto_box_publickey_from_secretkey')) { - return call_user_func('\\Sodium\\crypto_box_publickey_from_secretkey', $secretKey); + return (string) call_user_func('\\Sodium\\crypto_box_publickey_from_secretkey', $secretKey); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::box_publickey_from_secretkey($secretKey); @@ -913,8 +1158,9 @@ public static function crypto_box_publickey_from_secretkey($secretKey) * * @param string $keypair * @return string Your crypto_box secret key - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_box_secretkey($keypair) { @@ -923,14 +1169,14 @@ public static function crypto_box_secretkey($keypair) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) { - throw new Error('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_BOX_KEYPAIRBYTES long.'); } - if (self::isPhp72OrGreater()) { - return sodium_crypto_box_secretkey($keypair); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box_secretkey($keypair); } if (self::use_fallback('crypto_box_secretkey')) { - return call_user_func('\\Sodium\\crypto_box_secretkey', $keypair); + return (string) call_user_func('\\Sodium\\crypto_box_secretkey', $keypair); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::box_secretkey($keypair); @@ -943,17 +1189,24 @@ public static function crypto_box_secretkey($keypair) * * @param string $seed * @return string + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress UndefinedFunction */ public static function crypto_box_seed_keypair($seed) { /* Type checks: */ ParagonIE_Sodium_Core_Util::declareScalarType($seed, 'string', 1); - if (self::isPhp72OrGreater()) { - return sodium_crypto_box_seed_keypair($seed); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_box_seed_keypair($seed); } if (self::use_fallback('crypto_box_seed_keypair')) { - return call_user_func('\\Sodium\\crypto_box_seed_keypair', $seed); + return (string) call_user_func('\\Sodium\\crypto_box_seed_keypair', $seed); + } + if (PHP_INT_SIZE === 4) { + return ParagonIE_Sodium_Crypto32::box_seed_keypair($seed); } return ParagonIE_Sodium_Crypto::box_seed_keypair($seed); } @@ -961,14 +1214,15 @@ public static function crypto_box_seed_keypair($seed) /** * Calculates a BLAKE2b hash, with an optional key. * - * @param string $message The message to be hashed - * @param string $key If specified, must be a string between 16 and 64 - * bytes long - * @param int $length Output length in bytes; must be between 16 and 64 - * (default = 32) - * @return string Raw binary - * @throws Error + * @param string $message The message to be hashed + * @param string|null $key If specified, must be a string between 16 + * and 64 bytes long + * @param int $length Output length in bytes; must be between 16 + * and 64 (default = 32) + * @return string Raw binary + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_generichash($message, $key = '', $length = self::CRYPTO_GENERICHASH_BYTES) { @@ -983,18 +1237,18 @@ public static function crypto_generichash($message, $key = '', $length = self::C /* Input validation: */ if (!empty($key)) { if (ParagonIE_Sodium_Core_Util::strlen($key) < self::CRYPTO_GENERICHASH_KEYBYTES_MIN) { - throw new Error('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.'); + throw new SodiumException('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.'); } if (ParagonIE_Sodium_Core_Util::strlen($key) > self::CRYPTO_GENERICHASH_KEYBYTES_MAX) { - throw new Error('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.'); + throw new SodiumException('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.'); } } - if (self::isPhp72OrGreater()) { - return sodium_crypto_generichash($message, $key, $length); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_generichash($message, $key, $length); } if (self::use_fallback('crypto_generichash')) { - return call_user_func('\\Sodium\\crypto_generichash', $message, $key, $length); + return (string) call_user_func('\\Sodium\\crypto_generichash', $message, $key, $length); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::generichash($message, $key, $length); @@ -1008,8 +1262,9 @@ public static function crypto_generichash($message, $key = '', $length = self::C * @param string &$ctx BLAKE2 hashing context. Generated by crypto_generichash_init(). * @param int $length Hash output size. * @return string Final BLAKE2b hash. - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_generichash_final(&$ctx, $length = self::CRYPTO_GENERICHASH_BYTES) { @@ -1017,12 +1272,12 @@ public static function crypto_generichash_final(&$ctx, $length = self::CRYPTO_GE ParagonIE_Sodium_Core_Util::declareScalarType($ctx, 'string', 1); ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 2); - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_generichash_final($ctx, $length); } if (self::use_fallback('crypto_generichash_final')) { $func = '\\Sodium\\crypto_generichash_final'; - return $func($ctx, $length); + return (string) $func($ctx, $length); } if (PHP_INT_SIZE === 4) { $result = ParagonIE_Sodium_Crypto32::generichash_final($ctx, $length); @@ -1031,7 +1286,7 @@ public static function crypto_generichash_final(&$ctx, $length = self::CRYPTO_GE } try { self::memzero($ctx); - } catch (Error $ex) { + } catch (SodiumException $ex) { unset($ctx); } return $result; @@ -1040,12 +1295,13 @@ public static function crypto_generichash_final(&$ctx, $length = self::CRYPTO_GE /** * Initialize a BLAKE2b hashing context, for use in a streaming interface. * - * @param string $key If specified must be a string between 16 and 64 bytes - * @param int $length The size of the desired hash output - * @return string A BLAKE2 hashing context, encoded as a string - * (To be 100% compatible with ext/libsodium) - * @throws Error + * @param string|null $key If specified must be a string between 16 and 64 bytes + * @param int $length The size of the desired hash output + * @return string A BLAKE2 hashing context, encoded as a string + * (To be 100% compatible with ext/libsodium) + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_generichash_init($key = '', $length = self::CRYPTO_GENERICHASH_BYTES) { @@ -1059,18 +1315,18 @@ public static function crypto_generichash_init($key = '', $length = self::CRYPTO /* Input validation: */ if (!empty($key)) { if (ParagonIE_Sodium_Core_Util::strlen($key) < self::CRYPTO_GENERICHASH_KEYBYTES_MIN) { - throw new Error('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.'); + throw new SodiumException('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.'); } if (ParagonIE_Sodium_Core_Util::strlen($key) > self::CRYPTO_GENERICHASH_KEYBYTES_MAX) { - throw new Error('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.'); + throw new SodiumException('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.'); } } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_generichash_init($key, $length); } if (self::use_fallback('crypto_generichash_init')) { - return call_user_func('\\Sodium\\crypto_generichash_init', $key, $length); + return (string) call_user_func('\\Sodium\\crypto_generichash_init', $key, $length); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::generichash_init($key, $length); @@ -1085,7 +1341,9 @@ public static function crypto_generichash_init($key = '', $length = self::CRYPTO * $ctx is passed by reference and gets updated in-place. * @param string $message The message to append to the existing hash state. * @return void + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_generichash_update(&$ctx, $message) { @@ -1093,7 +1351,7 @@ public static function crypto_generichash_update(&$ctx, $message) ParagonIE_Sodium_Core_Util::declareScalarType($ctx, 'string', 1); ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 2); - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { sodium_crypto_generichash_update($ctx, $message); return; } @@ -1109,6 +1367,14 @@ public static function crypto_generichash_update(&$ctx, $message) } } + /** + * @return string + */ + public static function crypto_generichash_keygen() + { + return random_bytes(self::CRYPTO_GENERICHASH_KEYBYTES); + } + /** * Perform a key exchange, between a designated client and a server. * @@ -1134,8 +1400,9 @@ public static function crypto_generichash_update(&$ctx, $message) * @param string $client_public * @param string $server_public * @return string - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_kx($my_secret, $their_public, $client_public, $server_public) { @@ -1147,21 +1414,21 @@ public static function crypto_kx($my_secret, $their_public, $client_public, $ser /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($my_secret) !== self::CRYPTO_BOX_SECRETKEYBYTES) { - throw new Error('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($their_public) !== self::CRYPTO_BOX_PUBLICKEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($client_public) !== self::CRYPTO_BOX_PUBLICKEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($server_public) !== self::CRYPTO_BOX_PUBLICKEYBYTES) { - throw new Error('Argument 4 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 4 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { if (is_callable('sodium_crypto_kx')) { - return sodium_crypto_kx( + return (string) sodium_crypto_kx( $my_secret, $their_public, $client_public, @@ -1170,7 +1437,7 @@ public static function crypto_kx($my_secret, $their_public, $client_public, $ser } } if (self::use_fallback('crypto_kx')) { - return call_user_func( + return (string) call_user_func( '\\Sodium\\crypto_kx', $my_secret, $their_public, @@ -1200,10 +1467,13 @@ public static function crypto_kx($my_secret, $their_public, $client_public, $ser * @param string $salt * @param int $opslimit * @param int $memlimit + * @param int|null $alg * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument */ - public static function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit) + public static function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $alg = null) { ParagonIE_Sodium_Core_Util::declareScalarType($outlen, 'int', 1); ParagonIE_Sodium_Core_Util::declareScalarType($passwd, 'string', 2); @@ -1211,24 +1481,49 @@ public static function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlim ParagonIE_Sodium_Core_Util::declareScalarType($opslimit, 'int', 4); ParagonIE_Sodium_Core_Util::declareScalarType($memlimit, 'int', 5); - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { + if (!is_null($alg)) { + ParagonIE_Sodium_Core_Util::declareScalarType($alg, 'int', 6); + return sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $alg); + } return sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit); } if (self::use_fallback('crypto_pwhash')) { - return call_user_func('\\Sodium\\crypto_pwhash', $outlen, $passwd, $salt, $opslimit, $memlimit); + return (string) call_user_func('\\Sodium\\crypto_pwhash', $outlen, $passwd, $salt, $opslimit, $memlimit); } // This is the best we can do. - throw new Error( + throw new SodiumException( 'This is not implemented, as it is not possible to implement Argon2i with acceptable performance in pure-PHP' ); } + /** + * !Exclusive to sodium_compat! + * + * This returns TRUE if the native crypto_pwhash API is available by libsodium. + * This returns FALSE if only sodium_compat is available. + * + * @return bool + */ + public static function crypto_pwhash_is_available() + { + if (self::useNewSodiumAPI()) { + return true; + } + if (self::use_fallback('crypto_pwhash')) { + return true; + } + return false; + } + /** * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_pwhash_str($passwd, $opslimit, $memlimit) { @@ -1236,14 +1531,14 @@ public static function crypto_pwhash_str($passwd, $opslimit, $memlimit) ParagonIE_Sodium_Core_Util::declareScalarType($opslimit, 'int', 2); ParagonIE_Sodium_Core_Util::declareScalarType($memlimit, 'int', 3); - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_pwhash_str($passwd, $opslimit, $memlimit); } if (self::use_fallback('crypto_pwhash_str')) { - return call_user_func('\\Sodium\\crypto_pwhash_str', $passwd, $opslimit, $memlimit); + return (string) call_user_func('\\Sodium\\crypto_pwhash_str', $passwd, $opslimit, $memlimit); } // This is the best we can do. - throw new Error( + throw new SodiumException( 'This is not implemented, as it is not possible to implement Argon2i with acceptable performance in pure-PHP' ); } @@ -1252,21 +1547,23 @@ public static function crypto_pwhash_str($passwd, $opslimit, $memlimit) * @param string $passwd * @param string $hash * @return bool - * @throws Error + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_pwhash_str_verify($passwd, $hash) { ParagonIE_Sodium_Core_Util::declareScalarType($passwd, 'string', 1); ParagonIE_Sodium_Core_Util::declareScalarType($hash, 'string', 2); - if (self::isPhp72OrGreater()) { - return sodium_crypto_pwhash_str_verify($passwd, $hash); + if (self::useNewSodiumAPI()) { + return (bool) sodium_crypto_pwhash_str_verify($passwd, $hash); } if (self::use_fallback('crypto_pwhash_str_verify')) { - return call_user_func('\\Sodium\\crypto_pwhash_str_verify', $passwd, $hash); + return (bool) call_user_func('\\Sodium\\crypto_pwhash_str_verify', $passwd, $hash); } // This is the best we can do. - throw new Error( + throw new SodiumException( 'This is not implemented, as it is not possible to implement Argon2i with acceptable performance in pure-PHP' ); } @@ -1278,7 +1575,8 @@ public static function crypto_pwhash_str_verify($passwd, $hash) * @param int $opslimit * @param int $memlimit * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit) { @@ -1288,24 +1586,44 @@ public static function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $sal ParagonIE_Sodium_Core_Util::declareScalarType($opslimit, 'int', 4); ParagonIE_Sodium_Core_Util::declareScalarType($memlimit, 'int', 5); - if (self::isPhp72OrGreater()) { - return sodium_crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit); } if (self::use_fallback('crypto_pwhash_scryptsalsa208sha256')) { - return call_user_func('\\Sodium\\crypto_pwhash_scryptsalsa208sha256', $outlen, $passwd, $salt, $opslimit, $memlimit); + return (string) call_user_func('\\Sodium\\crypto_pwhash_scryptsalsa208sha256', $outlen, $passwd, $salt, $opslimit, $memlimit); } // This is the best we can do. - throw new Error( + throw new SodiumException( 'This is not implemented, as it is not possible to implement Scrypt with acceptable performance in pure-PHP' ); } + /** + * !Exclusive to sodium_compat! + * + * This returns TRUE if the native crypto_pwhash API is available by libsodium. + * This returns FALSE if only sodium_compat is available. + * + * @return bool + */ + public static function crypto_pwhash_scryptsalsa208sha256_is_available() + { + if (self::useNewSodiumAPI()) { + return true; + } + if (self::use_fallback('crypto_pwhash_scryptsalsa208sha256')) { + return true; + } + return false; + } + /** * @param string $passwd * @param int $opslimit * @param int $memlimit * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit) { @@ -1313,14 +1631,14 @@ public static function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit ParagonIE_Sodium_Core_Util::declareScalarType($opslimit, 'int', 2); ParagonIE_Sodium_Core_Util::declareScalarType($memlimit, 'int', 3); - if (self::isPhp72OrGreater()) { - return sodium_crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit); + if (self::useNewSodiumAPI()) { + return (string) sodium_crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit); } if (self::use_fallback('crypto_pwhash_scryptsalsa208sha256_str')) { - return call_user_func('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str', $passwd, $opslimit, $memlimit); + return (string) call_user_func('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str', $passwd, $opslimit, $memlimit); } // This is the best we can do. - throw new Error( + throw new SodiumException( 'This is not implemented, as it is not possible to implement Scrypt with acceptable performance in pure-PHP' ); } @@ -1329,21 +1647,22 @@ public static function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit * @param string $passwd * @param string $hash * @return bool - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) { ParagonIE_Sodium_Core_Util::declareScalarType($passwd, 'string', 1); ParagonIE_Sodium_Core_Util::declareScalarType($hash, 'string', 2); - if (self::isPhp72OrGreater()) { - return sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash); + if (self::useNewSodiumAPI()) { + return (bool) sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash); } if (self::use_fallback('crypto_pwhash_scryptsalsa208sha256_str_verify')) { - return call_user_func('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str_verify', $passwd, $hash); + return (bool) call_user_func('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str_verify', $passwd, $hash); } // This is the best we can do. - throw new Error( + throw new SodiumException( 'This is not implemented, as it is not possible to implement Scrypt with acceptable performance in pure-PHP' ); } @@ -1357,8 +1676,9 @@ public static function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $h * @param string $secretKey * @param string $publicKey * @return string - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_scalarmult($secretKey, $publicKey) { @@ -1368,25 +1688,25 @@ public static function crypto_scalarmult($secretKey, $publicKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) { - throw new Error('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_BOX_PUBLICKEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_BOX_PUBLICKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_scalarmult($secretKey, $publicKey); } if (self::use_fallback('crypto_scalarmult')) { - return call_user_func('\\Sodium\\crypto_scalarmult', $secretKey, $publicKey); + return (string) call_user_func('\\Sodium\\crypto_scalarmult', $secretKey, $publicKey); } /* Output validation: Forbid all-zero keys */ if (ParagonIE_Sodium_Core_Util::hashEquals($secretKey, str_repeat("\0", self::CRYPTO_BOX_SECRETKEYBYTES))) { - throw new Error('Zero secret key is not allowed'); + throw new SodiumException('Zero secret key is not allowed'); } if (ParagonIE_Sodium_Core_Util::hashEquals($publicKey, str_repeat("\0", self::CRYPTO_BOX_PUBLICKEYBYTES))) { - throw new Error('Zero public key is not allowed'); + throw new SodiumException('Zero public key is not allowed'); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::scalarmult($secretKey, $publicKey); @@ -1399,8 +1719,10 @@ public static function crypto_scalarmult($secretKey, $publicKey) * * @param string $secretKey * @return string - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress TooFewArguments + * @psalm-suppress MixedArgument */ public static function crypto_scalarmult_base($secretKey) { @@ -1409,17 +1731,17 @@ public static function crypto_scalarmult_base($secretKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_BOX_SECRETKEYBYTES) { - throw new Error('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_BOX_SECRETKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_scalarmult_base($secretKey); } if (self::use_fallback('crypto_scalarmult_base')) { - return call_user_func('\\Sodium\\crypto_scalarmult_base', $secretKey); + return (string) call_user_func('\\Sodium\\crypto_scalarmult_base', $secretKey); } if (ParagonIE_Sodium_Core_Util::hashEquals($secretKey, str_repeat("\0", self::CRYPTO_BOX_SECRETKEYBYTES))) { - throw new Error('Zero secret key is not allowed'); + throw new SodiumException('Zero secret key is not allowed'); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::scalarmult_base($secretKey); @@ -1436,8 +1758,9 @@ public static function crypto_scalarmult_base($secretKey) * @param string $nonce A Number to be used Once; must be 24 bytes * @param string $key Symmetric encryption key * @return string Ciphertext with Poly1305 MAC - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_secretbox($plaintext, $nonce, $key) { @@ -1448,17 +1771,17 @@ public static function crypto_secretbox($plaintext, $nonce, $key) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_SECRETBOX_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SECRETBOX_KEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_secretbox($plaintext, $nonce, $key); } if (self::use_fallback('crypto_secretbox')) { - return call_user_func('\\Sodium\\crypto_secretbox', $plaintext, $nonce, $key); + return (string) call_user_func('\\Sodium\\crypto_secretbox', $plaintext, $nonce, $key); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::secretbox($plaintext, $nonce, $key); @@ -1473,8 +1796,11 @@ public static function crypto_secretbox($plaintext, $nonce, $key) * @param string $nonce A Number to be used Once; must be 24 bytes * @param string $key Symmetric encryption key * @return string Original plaintext message - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_secretbox_open($ciphertext, $nonce, $key) { @@ -1485,13 +1811,17 @@ public static function crypto_secretbox_open($ciphertext, $nonce, $key) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_SECRETBOX_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SECRETBOX_KEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress FalsableReturnStatement + */ return sodium_crypto_secretbox_open($ciphertext, $nonce, $key); } if (self::use_fallback('crypto_secretbox_open')) { @@ -1503,6 +1833,16 @@ public static function crypto_secretbox_open($ciphertext, $nonce, $key) return ParagonIE_Sodium_Crypto::secretbox_open($ciphertext, $nonce, $key); } + /** + * Return a secure random key for use with crypto_secretbox + * + * @return string + */ + public static function crypto_secretbox_keygen() + { + return random_bytes(self::CRYPTO_SECRETBOX_KEYBYTES); + } + /** * Authenticated symmetric-key encryption. * @@ -1512,8 +1852,9 @@ public static function crypto_secretbox_open($ciphertext, $nonce, $key) * @param string $nonce A Number to be used Once; must be 24 bytes * @param string $key Symmetric encryption key * @return string Ciphertext with Poly1305 MAC - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_secretbox_xchacha20poly1305($plaintext, $nonce, $key) { @@ -1524,10 +1865,10 @@ public static function crypto_secretbox_xchacha20poly1305($plaintext, $nonce, $k /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_SECRETBOX_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SECRETBOX_KEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::secretbox_xchacha20poly1305($plaintext, $nonce, $key); @@ -1541,8 +1882,9 @@ public static function crypto_secretbox_xchacha20poly1305($plaintext, $nonce, $k * @param string $nonce A Number to be used Once; must be 24 bytes * @param string $key Symmetric encryption key * @return string Original plaintext message - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) { @@ -1553,10 +1895,10 @@ public static function crypto_secretbox_xchacha20poly1305_open($ciphertext, $non /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_SECRETBOX_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SECRETBOX_KEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); } if (PHP_INT_SIZE === 4) { @@ -1571,8 +1913,11 @@ public static function crypto_secretbox_xchacha20poly1305_open($ciphertext, $non * @param string $message Input message * @param string $key SipHash-2-4 key * @return string Hash - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_shorthash($message, $key) { @@ -1582,14 +1927,14 @@ public static function crypto_shorthash($message, $key) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SHORTHASH_KEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_SHORTHASH_KEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SHORTHASH_KEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_shorthash($message, $key); } if (self::use_fallback('crypto_shorthash')) { - return call_user_func('\\Sodium\\crypto_shorthash', $message, $key); + return (string) call_user_func('\\Sodium\\crypto_shorthash', $message, $key); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Core32_SipHash::sipHash24($message, $key); @@ -1598,89 +1943,13 @@ public static function crypto_shorthash($message, $key) } /** - * Expand a key and nonce into a keystream of pseudorandom bytes. + * Return a secure random key for use with crypto_shorthash * - * @param int $len Number of bytes desired - * @param string $nonce Number to be used Once; must be 24 bytes - * @param string $key XSalsa20 key - * @return string Pseudorandom stream that can be XORed with messages - * to provide encryption (but not authentication; see - * Poly1305 or crypto_auth() for that, which is not - * optional for security) - * @throws Error - * @throws TypeError - */ - public static function crypto_stream($len, $nonce, $key) - { - /* Type checks: */ - ParagonIE_Sodium_Core_Util::declareScalarType($len, 'int', 1); - ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2); - ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3); - - /* Input validation: */ - if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); - } - if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_KEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_STREAM_KEYBYTES long.'); - } - - if (self::isPhp72OrGreater()) { - return sodium_crypto_stream($len, $nonce, $key); - } - if (self::use_fallback('crypto_stream')) { - return call_user_func('\\Sodium\\crypto_stream', $len, $nonce, $key); - } - if (PHP_INT_SIZE === 4) { - return ParagonIE_Sodium_Core32_XSalsa20::xsalsa20($len, $nonce, $key); - } - return ParagonIE_Sodium_Core_XSalsa20::xsalsa20($len, $nonce, $key); - } - - /** - * DANGER! UNAUTHENTICATED ENCRYPTION! - * - * Unless you are following expert advice, do not used this feature. - * - * Algorithm: XSalsa20 - * - * This DOES NOT provide ciphertext integrity. - * - * @param string $message Plaintext message - * @param string $nonce Number to be used Once; must be 24 bytes - * @param string $key Encryption key - * @return string Encrypted text which is vulnerable to chosen- - * ciphertext attacks unless you implement some - * other mitigation to the ciphertext (i.e. - * Encrypt then MAC) - * @throws Error - * @throws TypeError + * @return string */ - public static function crypto_stream_xor($message, $nonce, $key) + public static function crypto_shorthash_keygen() { - /* Type checks: */ - ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1); - ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2); - ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3); - - /* Input validation: */ - if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_NONCEBYTES) { - throw new Error('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); - } - if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_KEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); - } - - if (self::isPhp72OrGreater()) { - return sodium_crypto_stream_xor($message, $nonce, $key); - } - if (self::use_fallback('crypto_stream_xor')) { - return call_user_func('\\Sodium\\crypto_stream_xor', $message, $nonce, $key); - } - if (PHP_INT_SIZE === 4) { - return ParagonIE_Sodium_Core32_XSalsa20::xsalsa20_xor($message, $nonce, $key); - } - return ParagonIE_Sodium_Core_XSalsa20::xsalsa20_xor($message, $nonce, $key); + return random_bytes(self::CRYPTO_SHORTHASH_KEYBYTES); } /** @@ -1692,8 +1961,11 @@ public static function crypto_stream_xor($message, $nonce, $key) * @param string $message Message to be signed. * @param string $secretKey Secret signing key. * @return string Signed message (signature is prefixed). - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_sign($message, $secretKey) { @@ -1703,14 +1975,14 @@ public static function crypto_sign($message, $secretKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_SIGN_SECRETKEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign($message, $secretKey); } if (self::use_fallback('crypto_sign')) { - return call_user_func('\\Sodium\\crypto_sign', $message, $secretKey); + return (string) call_user_func('\\Sodium\\crypto_sign', $message, $secretKey); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::sign($message, $secretKey); @@ -1725,8 +1997,11 @@ public static function crypto_sign($message, $secretKey) * @param string $publicKey A public key * @return string The original message (if the signature is * valid for this public key) - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ public static function crypto_sign_open($signedMessage, $publicKey) { @@ -1736,13 +2011,17 @@ public static function crypto_sign_open($signedMessage, $publicKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($signedMessage) < self::CRYPTO_SIGN_BYTES) { - throw new Error('Argument 1 must be at least CRYPTO_SIGN_BYTES long.'); + throw new SodiumException('Argument 1 must be at least CRYPTO_SIGN_BYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_SIGN_PUBLICKEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_SIGN_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SIGN_PUBLICKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { + /** + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress FalsableReturnStatement + */ return sodium_crypto_sign_open($signedMessage, $publicKey); } if (self::use_fallback('crypto_sign_open')) { @@ -1758,16 +2037,16 @@ public static function crypto_sign_open($signedMessage, $publicKey) * Generate a new random Ed25519 keypair. * * @return string + * @throws SodiumException + * @throws TypeError */ public static function crypto_sign_keypair() { - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign_keypair(); } if (self::use_fallback('crypto_sign_keypair')) { - return call_user_func( - '\\Sodium\\crypto_sign_keypair' - ); + return (string) call_user_func('\\Sodium\\crypto_sign_keypair'); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Core32_Ed25519::keypair(); @@ -1780,16 +2059,19 @@ public static function crypto_sign_keypair() * * @param string $seed Input seed * @return string Keypair + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_sign_seed_keypair($seed) { ParagonIE_Sodium_Core_Util::declareScalarType($seed, 'string', 1); - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign_seed_keypair($seed); } if (self::use_fallback('crypto_sign_keypair')) { - return call_user_func('\\Sodium\\crypto_sign_seed_keypair', $seed); + return (string) call_user_func('\\Sodium\\crypto_sign_seed_keypair', $seed); } $publicKey = ''; $secretKey = ''; @@ -1806,8 +2088,9 @@ public static function crypto_sign_seed_keypair($seed) * * @param string $keypair Keypair * @return string Public key - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_sign_publickey($keypair) { @@ -1816,14 +2099,14 @@ public static function crypto_sign_publickey($keypair) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_SIGN_KEYPAIRBYTES) { - throw new Error('Argument 1 must be CRYPTO_SIGN_KEYPAIRBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_SIGN_KEYPAIRBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign_publickey($keypair); } if (self::use_fallback('crypto_sign_publickey')) { - return call_user_func('\\Sodium\\crypto_sign_publickey', $keypair); + return (string) call_user_func('\\Sodium\\crypto_sign_publickey', $keypair); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Core32_Ed25519::publickey($keypair); @@ -1836,8 +2119,9 @@ public static function crypto_sign_publickey($keypair) * * @param string $secretKey Your Ed25519 secret key * @return string The corresponding Ed25519 public key - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_sign_publickey_from_secretkey($secretKey) { @@ -1846,14 +2130,14 @@ public static function crypto_sign_publickey_from_secretkey($secretKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_SIGN_SECRETKEYBYTES) { - throw new Error('Argument 1 must be CRYPTO_SIGN_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_SIGN_SECRETKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign_publickey_from_secretkey($secretKey); } if (self::use_fallback('crypto_sign_publickey_from_secretkey')) { - return call_user_func('\\Sodium\\crypto_sign_publickey_from_secretkey', $secretKey); + return (string) call_user_func('\\Sodium\\crypto_sign_publickey_from_secretkey', $secretKey); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Core32_Ed25519::publickey_from_secretkey($secretKey); @@ -1866,8 +2150,9 @@ public static function crypto_sign_publickey_from_secretkey($secretKey) * * @param string $keypair Keypair * @return string Secret key - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_sign_secretkey($keypair) { @@ -1876,14 +2161,14 @@ public static function crypto_sign_secretkey($keypair) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_SIGN_KEYPAIRBYTES) { - throw new Error('Argument 1 must be CRYPTO_SIGN_KEYPAIRBYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_SIGN_KEYPAIRBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign_secretkey($keypair); } if (self::use_fallback('crypto_sign_secretkey')) { - return call_user_func('\\Sodium\\crypto_sign_secretkey', $keypair); + return (string) call_user_func('\\Sodium\\crypto_sign_secretkey', $keypair); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Core32_Ed25519::secretkey($keypair); @@ -1899,8 +2184,9 @@ public static function crypto_sign_secretkey($keypair) * @param string $message Message to be signed * @param string $secretKey Secret signing key * @return string Digital signature - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_sign_detached($message, $secretKey) { @@ -1910,14 +2196,14 @@ public static function crypto_sign_detached($message, $secretKey) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($secretKey) !== self::CRYPTO_SIGN_SECRETKEYBYTES) { - throw new Error('Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES long.'); + throw new SodiumException('Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign_detached($message, $secretKey); } if (self::use_fallback('crypto_sign_detached')) { - return call_user_func('\\Sodium\\crypto_sign_detached', $message, $secretKey); + return (string) call_user_func('\\Sodium\\crypto_sign_detached', $message, $secretKey); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::sign_detached($message, $secretKey); @@ -1933,8 +2219,9 @@ public static function crypto_sign_detached($message, $secretKey) * @param string $publicKey Public key * @return bool TRUE if this signature is good for this public key; * FALSE otherwise - * @throws Error + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_sign_verify_detached($signature, $message, $publicKey) { @@ -1945,17 +2232,17 @@ public static function crypto_sign_verify_detached($signature, $message, $public /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($signature) !== self::CRYPTO_SIGN_BYTES) { - throw new Error('Argument 1 must be CRYPTO_SIGN_BYTES long.'); + throw new SodiumException('Argument 1 must be CRYPTO_SIGN_BYTES long.'); } if (ParagonIE_Sodium_Core_Util::strlen($publicKey) !== self::CRYPTO_SIGN_PUBLICKEYBYTES) { - throw new Error('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES long.'); + throw new SodiumException('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_crypto_sign_verify_detached($signature, $message, $publicKey); } if (self::use_fallback('crypto_sign_verify_detached')) { - return call_user_func('\\Sodium\\crypto_sign_verify_detached', $signature, $message, $publicKey); + return (bool) call_user_func('\\Sodium\\crypto_sign_verify_detached', $signature, $message, $publicKey); } if (PHP_INT_SIZE === 4) { return ParagonIE_Sodium_Crypto32::sign_verify_detached($signature, $message, $publicKey); @@ -1963,12 +2250,46 @@ public static function crypto_sign_verify_detached($signature, $message, $public return ParagonIE_Sodium_Crypto::sign_verify_detached($signature, $message, $publicKey); } + /** + * Convert an Ed25519 public key to a Curve25519 public key + * + * @param string $pk + * @return string + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + */ + public static function crypto_sign_ed25519_pk_to_curve25519($pk) + { + /* Type checks: */ + ParagonIE_Sodium_Core_Util::declareScalarType($pk, 'string', 1); + + /* Input validation: */ + if (ParagonIE_Sodium_Core_Util::strlen($pk) < self::CRYPTO_SIGN_PUBLICKEYBYTES) { + throw new SodiumException('Argument 1 must be at least CRYPTO_SIGN_PUBLICKEYBYTES long.'); + } + if (self::useNewSodiumAPI()) { + if (is_callable('crypto_sign_ed25519_pk_to_curve25519')) { + return (string) sodium_crypto_sign_ed25519_pk_to_curve25519($pk); + } + } + if (self::use_fallback('crypto_sign_ed25519_pk_to_curve25519')) { + return (string) call_user_func('\\Sodium\\crypto_sign_ed25519_pk_to_curve25519', $pk); + } + if (PHP_INT_SIZE === 4) { + return ParagonIE_Sodium_Core32_Ed25519::pk_to_curve25519($pk); + } + return ParagonIE_Sodium_Core_Ed25519::pk_to_curve25519($pk); + } + /** * Convert an Ed25519 secret key to a Curve25519 secret key * * @param string $sk * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument */ public static function crypto_sign_ed25519_sk_to_curve25519($sk) { @@ -1977,15 +2298,15 @@ public static function crypto_sign_ed25519_sk_to_curve25519($sk) /* Input validation: */ if (ParagonIE_Sodium_Core_Util::strlen($sk) < self::CRYPTO_SIGN_SEEDBYTES) { - throw new Error('Argument 1 must be at least CRYPTO_SIGN_SEEDBYTES long.'); + throw new SodiumException('Argument 1 must be at least CRYPTO_SIGN_SEEDBYTES long.'); } - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { if (is_callable('crypto_sign_ed25519_sk_to_curve25519')) { return sodium_crypto_sign_ed25519_sk_to_curve25519($sk); } } if (self::use_fallback('crypto_sign_ed25519_sk_to_curve25519')) { - return call_user_func('\\Sodium\\crypto_sign_ed25519_sk_to_curve25519', $sk); + return (string) call_user_func('\\Sodium\\crypto_sign_ed25519_sk_to_curve25519', $sk); } $h = hash('sha512', ParagonIE_Sodium_Core_Util::substr($sk, 0, 32), true); @@ -1998,23 +2319,126 @@ public static function crypto_sign_ed25519_sk_to_curve25519($sk) return ParagonIE_Sodium_Core_Util::substr($h, 0, 32); } + /** + * Expand a key and nonce into a keystream of pseudorandom bytes. + * + * @param int $len Number of bytes desired + * @param string $nonce Number to be used Once; must be 24 bytes + * @param string $key XSalsa20 key + * @return string Pseudorandom stream that can be XORed with messages + * to provide encryption (but not authentication; see + * Poly1305 or crypto_auth() for that, which is not + * optional for security) + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + */ + public static function crypto_stream($len, $nonce, $key) + { + /* Type checks: */ + ParagonIE_Sodium_Core_Util::declareScalarType($len, 'int', 1); + ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2); + ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3); + + /* Input validation: */ + if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_NONCEBYTES) { + throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); + } + if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_KEYBYTES) { + throw new SodiumException('Argument 3 must be CRYPTO_STREAM_KEYBYTES long.'); + } + + if (self::useNewSodiumAPI()) { + return sodium_crypto_stream($len, $nonce, $key); + } + if (self::use_fallback('crypto_stream')) { + return (string) call_user_func('\\Sodium\\crypto_stream', $len, $nonce, $key); + } + if (PHP_INT_SIZE === 4) { + return ParagonIE_Sodium_Core32_XSalsa20::xsalsa20($len, $nonce, $key); + } + return ParagonIE_Sodium_Core_XSalsa20::xsalsa20($len, $nonce, $key); + } + + /** + * DANGER! UNAUTHENTICATED ENCRYPTION! + * + * Unless you are following expert advice, do not used this feature. + * + * Algorithm: XSalsa20 + * + * This DOES NOT provide ciphertext integrity. + * + * @param string $message Plaintext message + * @param string $nonce Number to be used Once; must be 24 bytes + * @param string $key Encryption key + * @return string Encrypted text which is vulnerable to chosen- + * ciphertext attacks unless you implement some + * other mitigation to the ciphertext (i.e. + * Encrypt then MAC) + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + */ + public static function crypto_stream_xor($message, $nonce, $key) + { + /* Type checks: */ + ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1); + ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2); + ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3); + + /* Input validation: */ + if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_NONCEBYTES) { + throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.'); + } + if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_KEYBYTES) { + throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long.'); + } + + if (self::useNewSodiumAPI()) { + return sodium_crypto_stream_xor($message, $nonce, $key); + } + if (self::use_fallback('crypto_stream_xor')) { + return (string) call_user_func('\\Sodium\\crypto_stream_xor', $message, $nonce, $key); + } + if (PHP_INT_SIZE === 4) { + return ParagonIE_Sodium_Core32_XSalsa20::xsalsa20_xor($message, $nonce, $key); + } + return ParagonIE_Sodium_Core_XSalsa20::xsalsa20_xor($message, $nonce, $key); + } + + /** + * Return a secure random key for use with crypto_stream + * + * @return string + */ + public static function crypto_stream_keygen() + { + return random_bytes(self::CRYPTO_STREAM_KEYBYTES); + } + /** * Cache-timing-safe implementation of hex2bin(). * * @param string $string Hexadecimal string * @return string Raw binary string + * @throws SodiumException * @throws TypeError + * @psalm-suppress TooFewArguments + * @psalm-suppress MixedArgument */ public static function hex2bin($string) { /* Type checks: */ ParagonIE_Sodium_Core_Util::declareScalarType($string, 'string', 1); - if (self::isPhp72OrGreater()) { - return sodium_hex2bin($string); + if (self::useNewSodiumAPI()) { + if (is_callable('sodium_hex2bin')) { + return (string) sodium_hex2bin($string); + } } if (self::use_fallback('hex2bin')) { - return call_user_func('\\Sodium\\hex2bin', $string); + return (string) call_user_func('\\Sodium\\hex2bin', $string); } return ParagonIE_Sodium_Core_Util::hex2bin($string); } @@ -2025,14 +2449,16 @@ public static function hex2bin($string) * @param string $var * * @return void - * @throws Error (Unless libsodium is installed) + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument */ public static function increment(&$var) { /* Type checks: */ ParagonIE_Sodium_Core_Util::declareScalarType($var, 'string', 1); - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { sodium_increment($var); return; } @@ -2059,10 +2485,12 @@ public static function increment(&$var) * with (sans pwhash and memzero). * * @return int + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress UndefinedFunction */ public static function library_version_major() { - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_library_version_major(); } if (self::use_fallback('library_version_major')) { @@ -2076,10 +2504,12 @@ public static function library_version_major() * with (sans pwhash and memzero). * * @return int + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress UndefinedFunction */ public static function library_version_minor() { - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { return sodium_library_version_minor(); } if (self::use_fallback('library_version_minor')) { @@ -2094,7 +2524,9 @@ public static function library_version_minor() * @param string $left * @param string $right * @return int + * @throws SodiumException * @throws TypeError + * @psalm-suppress MixedArgument */ public static function memcmp($left, $right) { @@ -2103,8 +2535,10 @@ public static function memcmp($left, $right) ParagonIE_Sodium_Core_Util::declareScalarType($right, 'string', 2); if (self::use_fallback('memcmp')) { - return call_user_func('\\Sodium\\memcmp', $left, $right); + return (int) call_user_func('\\Sodium\\memcmp', $left, $right); } + /** @var string $left */ + /** @var string $right */ return ParagonIE_Sodium_Core_Util::memcmp($left, $right); } @@ -2115,14 +2549,16 @@ public static function memcmp($left, $right) * @param string|null $var * * @return void - * @throws Error (Unless libsodium is installed) + * @throws SodiumException (Unless libsodium is installed) + * @throws TypeError + * @psalm-suppress TooFewArguments */ public static function memzero(&$var) { /* Type checks: */ ParagonIE_Sodium_Core_Util::declareScalarType($var, 'string', 1); - if (self::isPhp72OrGreater()) { + if (self::useNewSodiumAPI()) { sodium_memzero($var); return; } @@ -2131,8 +2567,9 @@ public static function memzero(&$var) return; } // This is the best we can do. - throw new Error( - 'This is not implemented, as it is not possible to securely wipe memory from PHP' + throw new SodiumException( + 'This is not implemented in sodium_compat, as it is not possible to securely wipe memory from PHP. ' . + 'To fix this error, make sure libsodium is installed and the PHP extension is enabled.' ); } @@ -2149,13 +2586,13 @@ public static function randombytes_buf($numBytes) /* Type checks: */ if (!is_int($numBytes)) { if (is_numeric($numBytes)) { - $numBytes = (int)$numBytes; + $numBytes = (int) $numBytes; } else { throw new TypeError('Argument 1 must be an integer, ' . gettype($numBytes) . ' given.'); } } if (self::use_fallback('randombytes_buf')) { - return call_user_func('\\Sodium\\randombytes_buf', $numBytes); + return (string) call_user_func('\\Sodium\\randombytes_buf', $numBytes); } return random_bytes($numBytes); } @@ -2201,16 +2638,18 @@ public static function randombytes_random16() * prefixed with 'polyfill-'. * * @return string + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress UndefinedFunction */ public static function version_string() { - if (self::isPhp72OrGreater()) { - return sodium_version_string(); + if (self::useNewSodiumAPI()) { + return (string) sodium_version_string(); } if (self::use_fallback('version_string')) { return (string) call_user_func('\\Sodium\\version_string'); } - return self::VERSION_STRING; + return (string) self::VERSION_STRING; } /** @@ -2231,23 +2670,6 @@ protected static function use_fallback($sodium_func_name = '') if ($res === null) { $res = extension_loaded('libsodium') && PHP_VERSION_ID >= 50300; } - if (PHP_INT_SIZE === 4) { - if ($res && is_callable('\\Sodium\\' . $sodium_func_name)) { - // We can safely just offload to the PECL extension - return true; - } - /* - if (DIRECTORY_SEPARATOR === '\\' && PHP_VERSION_ID < 70000) { - throw new RuntimeException( - 'Sodium_compat produces incorrect results on systems that do not support 64-bit integers. ' . - 'Please upgrade to PHP 7 or newer for Windows x64 support.' - ); - } - throw new RuntimeException( - 'Sodium_compat produces incorrect results on systems that do not support 64-bit integers.' - ); - */ - } if ($res === false) { // No libsodium installed return false; @@ -2264,20 +2686,21 @@ protected static function use_fallback($sodium_func_name = '') /** * Libsodium as implemented in PHP 7.2 + * and/or ext/sodium (via PECL) * * @ref https://wiki.php.net/rfc/libsodium * @return bool */ - protected static function isPhp72OrGreater() + protected static function useNewSodiumAPI() { static $res = null; if ($res === null) { - $res = PHP_VERSION_ID >= 70200 && extension_loaded('sodium'); + $res = PHP_VERSION_ID >= 70000 && extension_loaded('sodium'); } if (self::$disableFallbackForUnitTests) { // Don't fallback. Use the PHP implementation. return false; } - return $res; + return (bool) $res; } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/BLAKE2b.php b/libraries/vendor/paragonie/sodium_compat/src/Core/BLAKE2b.php index 4e09f99b05709..c1a232b310274 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/BLAKE2b.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/BLAKE2b.php @@ -17,7 +17,7 @@ abstract class ParagonIE_Sodium_Core_BLAKE2b extends ParagonIE_Sodium_Core_Util protected static $iv; /** - * @var int[][] + * @var array> */ protected static $sigma = array( array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), @@ -46,6 +46,7 @@ abstract class ParagonIE_Sodium_Core_BLAKE2b extends ParagonIE_Sodium_Core_Util * @param int $high * @param int $low * @return SplFixedArray + * @psalm-suppress MixedAssignment */ public static function new64($high, $low) { @@ -79,6 +80,9 @@ protected static function to64($num) * @param SplFixedArray $x * @param SplFixedArray $y * @return SplFixedArray + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedOperand */ protected static function add64($x, $y) { @@ -110,21 +114,22 @@ protected static function add364($x, $y, $z) * @param SplFixedArray $x * @param SplFixedArray $y * @return SplFixedArray - * @throws Exception + * @throws SodiumException + * @throws TypeError */ protected static function xor64(SplFixedArray $x, SplFixedArray $y) { if (!is_numeric($x[0])) { - throw new Exception('x[0] is not an integer'); + throw new SodiumException('x[0] is not an integer'); } if (!is_numeric($x[1])) { - throw new Exception('x[1] is not an integer'); + throw new SodiumException('x[1] is not an integer'); } if (!is_numeric($y[0])) { - throw new Exception('y[0] is not an integer'); + throw new SodiumException('y[0] is not an integer'); } if (!is_numeric($y[1])) { - throw new Exception('y[1] is not an integer'); + throw new SodiumException('y[1] is not an integer'); } return self::new64($x[0] ^ $y[0], $x[1] ^ $y[1]); } @@ -135,6 +140,7 @@ protected static function xor64(SplFixedArray $x, SplFixedArray $y) * @param SplFixedArray $x * @param int $c * @return SplFixedArray + * @psalm-suppress MixedAssignment */ public static function rotr64($x, $c) { @@ -142,6 +148,7 @@ public static function rotr64($x, $c) $c %= 64; } if ($c >= 32) { + /** @var int $tmp */ $tmp = $x[0]; $x[0] = $x[1]; $x[1] = $tmp; @@ -155,6 +162,7 @@ public static function rotr64($x, $c) $c = 64 - $c; if ($c < 32) { + /** @var int $h0 */ $h0 = ($x[0] << $c) | ( ( $x[1] & ((1 << $c) - 1) @@ -162,8 +170,10 @@ public static function rotr64($x, $c) (32 - $c) ) >> (32 - $c) ); + /** @var int $l0 */ $l0 = $x[1] << $c; } else { + /** @var int $h0 */ $h0 = $x[1] << ($c - 32); } @@ -171,9 +181,12 @@ public static function rotr64($x, $c) $c1 = 64 - $c; if ($c1 < 32) { + /** @var int $h1 */ $h1 = $x[0] >> $c1; + /** @var int $l1 */ $l1 = ($x[1] >> $c1) | ($x[0] & ((1 << $c1) - 1)) << (32 - $c1); } else { + /** @var int $l1 */ $l1 = $x[0] >> ($c1 - 32); } @@ -185,10 +198,11 @@ public static function rotr64($x, $c) * * @param SplFixedArray $x * @return int + * @psalm-suppress MixedOperand */ protected static function flatten64($x) { - return ($x[0] * 4294967296 + $x[1]); + return (int) ($x[0] * 4294967296 + $x[1]); } /** @@ -197,10 +211,14 @@ protected static function flatten64($x) * @param SplFixedArray $x * @param int $i * @return SplFixedArray + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayOffset */ protected static function load64(SplFixedArray $x, $i) { + /** @var int $l */ $l = $x[$i] | ($x[$i+1]<<8) | ($x[$i+2]<<16) | ($x[$i+3]<<24); + /** @var int $h */ $h = $x[$i+4] | ($x[$i+5]<<8) | ($x[$i+6]<<16) | ($x[$i+7]<<24); return self::new64($h, $l); } @@ -212,6 +230,7 @@ protected static function load64(SplFixedArray $x, $i) * @param int $i * @param SplFixedArray $u * @return void + * @psalm-suppress MixedAssignment */ protected static function store64(SplFixedArray $x, $i, SplFixedArray $u) { @@ -222,6 +241,7 @@ protected static function store64(SplFixedArray $x, $i, SplFixedArray $u) ... becomes ... [0, 0, 0, 0, 1, 1, 1, 1] */ + /** @var int $uIdx */ $uIdx = ((7 - $j) & 4) >> 2; $x[$i] = ($u[$uIdx] & 0xff); if (++$i > $maxLength) { @@ -263,6 +283,9 @@ public static function pseudoConstructor() * @internal You should not use this directly from another application * * @return SplFixedArray + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment */ protected static function context() { @@ -295,6 +318,13 @@ protected static function context() * @param SplFixedArray $ctx * @param SplFixedArray $buf * @return void + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset */ protected static function compress(SplFixedArray $ctx, SplFixedArray $buf) { @@ -349,6 +379,10 @@ protected static function compress(SplFixedArray $ctx, SplFixedArray $buf) * @param SplFixedArray $v * @param SplFixedArray $m * @return SplFixedArray + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayOffset */ public static function G($r, $i, $a, $b, $c, $d, SplFixedArray $v, SplFixedArray $m) { @@ -369,12 +403,15 @@ public static function G($r, $i, $a, $b, $c, $d, SplFixedArray $v, SplFixedArray * @param SplFixedArray $ctx * @param int $inc * @return void - * @throws Error + * @throws SodiumException + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment */ public static function increment_counter($ctx, $inc) { if ($inc < 0) { - throw new Error('Increasing by a negative number makes no sense.'); + throw new SodiumException('Increasing by a negative number makes no sense.'); } $t = self::to64($inc); # S->t is $ctx[1] in our implementation @@ -395,6 +432,14 @@ public static function increment_counter($ctx, $inc) * @param SplFixedArray $p * @param int $plen * @return void + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset + * @psalm-suppress MixedOperand */ public static function update(SplFixedArray $ctx, SplFixedArray $p, $plen) { @@ -450,7 +495,14 @@ public static function update(SplFixedArray $ctx, SplFixedArray $p, $plen) * @param SplFixedArray $ctx * @param SplFixedArray $out * @return SplFixedArray - * @throws Error + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset + * @psalm-suppress MixedOperand */ public static function finish(SplFixedArray $ctx, SplFixedArray $out) { @@ -460,7 +512,7 @@ public static function finish(SplFixedArray $ctx, SplFixedArray $out) self::compress($ctx, $ctx[3]); $ctx[4] -= 128; if ($ctx[4] > 128) { - throw new Error('Failed to assert that buflen <= 128 bytes'); + throw new SodiumException('Failed to assert that buflen <= 128 bytes'); } for ($i = $ctx[4]; $i--;) { $ctx[3][$i] = $ctx[3][$i + 128]; @@ -489,7 +541,13 @@ public static function finish(SplFixedArray $ctx, SplFixedArray $out) * @param SplFixedArray|null $key * @param int $outlen * @return SplFixedArray - * @throws Exception + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset */ public static function init($key = null, $outlen = 64) { @@ -498,13 +556,13 @@ public static function init($key = null, $outlen = 64) if ($key !== null) { if (count($key) > 64) { - throw new Exception('Invalid key size'); + throw new SodiumException('Invalid key size'); } $klen = count($key); } if ($outlen > 64) { - throw new Exception('Invalid output size'); + throw new SodiumException('Invalid output size'); } $ctx = self::context(); @@ -559,6 +617,7 @@ public static function stringToSplFixedArray($str = '') * * @param SplFixedArray $a * @return string + * @throws TypeError */ public static function SplFixedArrayToString(SplFixedArray $a) { @@ -568,7 +627,7 @@ public static function SplFixedArrayToString(SplFixedArray $a) $arr = $a->toArray(); $c = $a->count(); array_unshift($arr, str_repeat('C', $c)); - return call_user_func_array('pack', $arr); + return (string) (call_user_func_array('pack', $arr)); } /** @@ -576,10 +635,18 @@ public static function SplFixedArrayToString(SplFixedArray $a) * * @param SplFixedArray[SplFixedArray] $ctx * @return string + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset + * @psalm-suppress MixedMethodCall */ public static function contextToString(SplFixedArray $ctx) { $str = ''; + /** @var array> $ctxA */ $ctxA = $ctx[0]->toArray(); # uint64_t h[8]; @@ -624,6 +691,9 @@ public static function contextToString(SplFixedArray $ctx) * * @param string $string * @return SplFixedArray + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArrayAssignment */ public static function stringToContext($string) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20.php b/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20.php index cb07e37b2775c..806010c7fbf8a 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20.php @@ -22,10 +22,12 @@ public static function rotate($v, $n) { $v &= 0xffffffff; $n &= 31; - return 0xffffffff & ( - ($v << $n) - | - ($v >> (32 - $n)) + return (int) ( + 0xffffffff & ( + ($v << $n) + | + ($v >> (32 - $n)) + ) ); } @@ -43,18 +45,22 @@ public static function rotate($v, $n) protected static function quarterRound($a, $b, $c, $d) { # a = PLUS(a,b); d = ROTATE(XOR(d,a),16); + /** @var int $a */ $a = ($a + $b) & 0xffffffff; $d = self::rotate($d ^ $a, 16); # c = PLUS(c,d); b = ROTATE(XOR(b,c),12); + /** @var int $c */ $c = ($c + $d) & 0xffffffff; $b = self::rotate($b ^ $c, 12); # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); + /** @var int $a */ $a = ($a + $b) & 0xffffffff; $d = self::rotate($d ^ $a, 8); # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); + /** @var int $c */ $c = ($c + $d) & 0xffffffff; $b = self::rotate($b ^ $c, 7); return array((int) $a, (int) $b, (int) $c, (int) $d); @@ -67,7 +73,8 @@ protected static function quarterRound($a, $b, $c, $d) * @param string $message * * @return string - * @throws Exception + * @throws TypeError + * @throws SodiumException */ public static function encryptBytes( ParagonIE_Sodium_Core_ChaCha20_Ctx $ctx, @@ -177,21 +184,37 @@ public static function encryptBytes( x14 = PLUS(x14, j14); x15 = PLUS(x15, j15); */ + /** @var int $x0 */ $x0 = ($x0 & 0xffffffff) + $j0; + /** @var int $x1 */ $x1 = ($x1 & 0xffffffff) + $j1; + /** @var int $x2 */ $x2 = ($x2 & 0xffffffff) + $j2; + /** @var int $x3 */ $x3 = ($x3 & 0xffffffff) + $j3; + /** @var int $x4 */ $x4 = ($x4 & 0xffffffff) + $j4; + /** @var int $x5 */ $x5 = ($x5 & 0xffffffff) + $j5; + /** @var int $x6 */ $x6 = ($x6 & 0xffffffff) + $j6; + /** @var int $x7 */ $x7 = ($x7 & 0xffffffff) + $j7; + /** @var int $x8 */ $x8 = ($x8 & 0xffffffff) + $j8; + /** @var int $x9 */ $x9 = ($x9 & 0xffffffff) + $j9; + /** @var int $x10 */ $x10 = ($x10 & 0xffffffff) + $j10; + /** @var int $x11 */ $x11 = ($x11 & 0xffffffff) + $j11; + /** @var int $x12 */ $x12 = ($x12 & 0xffffffff) + $j12; + /** @var int $x13 */ $x13 = ($x13 & 0xffffffff) + $j13; + /** @var int $x14 */ $x14 = ($x14 & 0xffffffff) + $j14; + /** @var int $x15 */ $x15 = ($x15 & 0xffffffff) + $j15; /* @@ -237,7 +260,7 @@ public static function encryptBytes( */ ++$j12; if ($j12 & 0xf0000000) { - throw new Exception('Overflow'); + throw new SodiumException('Overflow'); } /* @@ -303,6 +326,8 @@ public static function encryptBytes( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function stream($len = 64, $nonce = '', $key = '') { @@ -319,6 +344,8 @@ public static function stream($len = 64, $nonce = '', $key = '') * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function ietfStream($len, $nonce = '', $key = '') { @@ -336,6 +363,8 @@ public static function ietfStream($len, $nonce = '', $key = '') * @param string $key * @param string $ic * @return string + * @throws SodiumException + * @throws TypeError */ public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') { @@ -353,6 +382,8 @@ public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = ' * @param string $key * @param string $ic * @return string + * @throws SodiumException + * @throws TypeError */ public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/Ctx.php b/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/Ctx.php index bdbbb59998f40..b29ab90054df7 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/Ctx.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/Ctx.php @@ -10,7 +10,7 @@ class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util implements ArrayAccess { /** - * @var SplFixedArray + * @var SplFixedArray internally, */ protected $container; @@ -24,6 +24,7 @@ class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util impl * @param string $counter The initial counter value. * Defaults to 8 0x00 bytes. * @throws InvalidArgumentException + * @throws TypeError */ public function __construct($key = '', $iv = '', $counter = '') { @@ -66,6 +67,7 @@ public function __construct($key = '', $iv = '', $counter = '') * @param int $offset * @param int $value * @return void + * @psalm-suppress MixedArrayOffset */ public function offsetSet($offset, $value) { @@ -83,6 +85,7 @@ public function offsetSet($offset, $value) * * @param mixed $offset * @return bool + * @psalm-suppress MixedArrayOffset */ public function offsetExists($offset) { @@ -94,6 +97,7 @@ public function offsetExists($offset) * * @param mixed $offset * @return void + * @psalm-suppress MixedArrayOffset */ public function offsetUnset($offset) { @@ -105,6 +109,7 @@ public function offsetUnset($offset) * * @param mixed $offset * @return mixed|null + * @psalm-suppress MixedArrayOffset */ public function offsetGet($offset) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/IetfCtx.php b/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/IetfCtx.php index 72b7676061b1e..4d63b9004d00a 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/IetfCtx.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/ChaCha20/IetfCtx.php @@ -19,6 +19,7 @@ class ParagonIE_Sodium_Core_ChaCha20_IetfCtx extends ParagonIE_Sodium_Core_ChaCh * @param string $counter The initial counter value. * Defaults to 4 0x00 bytes. * @throws InvalidArgumentException + * @throws TypeError */ public function __construct($key = '', $iv = '', $counter = '') { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519.php index 022c2801dc83c..dedf7a4d71e3f 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519.php @@ -51,11 +51,14 @@ public static function fe_1() * @param ParagonIE_Sodium_Core_Curve25519_Fe $f * @param ParagonIE_Sodium_Core_Curve25519_Fe $g * @return ParagonIE_Sodium_Core_Curve25519_Fe + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedOperand */ public static function fe_add( ParagonIE_Sodium_Core_Curve25519_Fe $f, ParagonIE_Sodium_Core_Curve25519_Fe $g ) { + /** @var array $arr */ $arr = array(); for ($i = 0; $i < 10; ++$i) { $arr[$i] = (int) ($f[$i] + $g[$i]); @@ -72,17 +75,20 @@ public static function fe_add( * @param ParagonIE_Sodium_Core_Curve25519_Fe $g * @param int $b * @return ParagonIE_Sodium_Core_Curve25519_Fe + * @psalm-suppress MixedAssignment */ public static function fe_cmov( ParagonIE_Sodium_Core_Curve25519_Fe $f, ParagonIE_Sodium_Core_Curve25519_Fe $g, $b = 0 ) { + /** @var array $h */ $h = array(); $b *= -1; for ($i = 0; $i < 10; ++$i) { + /** @var int $x */ $x = (($f[$i] ^ $g[$i]) & $b); - $h[$i] = $f[$i] ^ $x; + $h[$i] = (int) ($f[$i] ^ $x); } return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h); } @@ -110,51 +116,72 @@ public static function fe_copy(ParagonIE_Sodium_Core_Curve25519_Fe $f) * @param string $s * @return ParagonIE_Sodium_Core_Curve25519_Fe * @throws RangeException + * @throws TypeError */ public static function fe_frombytes($s) { if (self::strlen($s) !== 32) { throw new RangeException('Expected a 32-byte string.'); } + /** @var int $h0 */ $h0 = self::load_4($s); + /** @var int $h1 */ $h1 = self::load_3(self::substr($s, 4, 3)) << 6; + /** @var int $h2 */ $h2 = self::load_3(self::substr($s, 7, 3)) << 5; + /** @var int $h3 */ $h3 = self::load_3(self::substr($s, 10, 3)) << 3; + /** @var int $h4 */ $h4 = self::load_3(self::substr($s, 13, 3)) << 2; + /** @var int $h5 */ $h5 = self::load_4(self::substr($s, 16, 4)); + /** @var int $h6 */ $h6 = self::load_3(self::substr($s, 20, 3)) << 7; + /** @var int $h7 */ $h7 = self::load_3(self::substr($s, 23, 3)) << 5; + /** @var int $h8 */ $h8 = self::load_3(self::substr($s, 26, 3)) << 4; + /** @var int $h9 */ $h9 = (self::load_3(self::substr($s, 29, 3)) & 8388607) << 2; + /** @var int $carry9 */ $carry9 = ($h9 + (1 << 24)) >> 25; $h0 += self::mul($carry9, 19, 5); $h9 -= $carry9 << 25; + /** @var int $carry1 */ $carry1 = ($h1 + (1 << 24)) >> 25; $h2 += $carry1; $h1 -= $carry1 << 25; + /** @var int $carry3 */ $carry3 = ($h3 + (1 << 24)) >> 25; $h4 += $carry3; $h3 -= $carry3 << 25; + /** @var int $carry5 */ $carry5 = ($h5 + (1 << 24)) >> 25; $h6 += $carry5; $h5 -= $carry5 << 25; + /** @var int $carry7 */ $carry7 = ($h7 + (1 << 24)) >> 25; $h8 += $carry7; $h7 -= $carry7 << 25; + /** @var int $carry0 */ $carry0 = ($h0 + (1 << 25)) >> 26; $h1 += $carry0; $h0 -= $carry0 << 26; + /** @var int $carry2 */ $carry2 = ($h2 + (1 << 25)) >> 26; $h3 += $carry2; $h2 -= $carry2 << 26; + /** @var int $carry4 */ $carry4 = ($h4 + (1 << 25)) >> 26; $h5 += $carry4; $h4 -= $carry4 << 26; + /** @var int $carry6 */ $carry6 = ($h6 + (1 << 25)) >> 26; $h7 += $carry6; $h6 -= $carry6 << 26; + /** @var int $carry8 */ $carry8 = ($h8 + (1 << 25)) >> 26; $h9 += $carry8; $h8 -= $carry8 << 26; @@ -185,97 +212,128 @@ public static function fe_frombytes($s) */ public static function fe_tobytes(ParagonIE_Sodium_Core_Curve25519_Fe $h) { - $h[0] = (int) $h[0]; - $h[1] = (int) $h[1]; - $h[2] = (int) $h[2]; - $h[3] = (int) $h[3]; - $h[4] = (int) $h[4]; - $h[5] = (int) $h[5]; - $h[6] = (int) $h[6]; - $h[7] = (int) $h[7]; - $h[8] = (int) $h[8]; - $h[9] = (int) $h[9]; - - $q = (self::mul($h[9], 19, 5) + (1 << 24)) >> 25; - $q = ($h[0] + $q) >> 26; - $q = ($h[1] + $q) >> 25; - $q = ($h[2] + $q) >> 26; - $q = ($h[3] + $q) >> 25; - $q = ($h[4] + $q) >> 26; - $q = ($h[5] + $q) >> 25; - $q = ($h[6] + $q) >> 26; - $q = ($h[7] + $q) >> 25; - $q = ($h[8] + $q) >> 26; - $q = ($h[9] + $q) >> 25; - - $h[0] += self::mul($q, 19, 5); - - $carry0 = $h[0] >> 26; - $h[1] += $carry0; - $h[0] -= $carry0 << 26; - $carry1 = $h[1] >> 25; - $h[2] += $carry1; - $h[1] -= $carry1 << 25; - $carry2 = $h[2] >> 26; - $h[3] += $carry2; - $h[2] -= $carry2 << 26; - $carry3 = $h[3] >> 25; - $h[4] += $carry3; - $h[3] -= $carry3 << 25; - $carry4 = $h[4] >> 26; - $h[5] += $carry4; - $h[4] -= $carry4 << 26; - $carry5 = $h[5] >> 25; - $h[6] += $carry5; - $h[5] -= $carry5 << 25; - $carry6 = $h[6] >> 26; - $h[7] += $carry6; - $h[6] -= $carry6 << 26; - $carry7 = $h[7] >> 25; - $h[8] += $carry7; - $h[7] -= $carry7 << 25; - $carry8 = $h[8] >> 26; - $h[9] += $carry8; - $h[8] -= $carry8 << 26; - $carry9 = $h[9] >> 25; - $h[9] -= $carry9 << 25; + /** @var int $h0 */ + $h0 = (int) $h[0]; + /** @var int $h1 */ + $h1 = (int) $h[1]; + /** @var int $h2 */ + $h2 = (int) $h[2]; + /** @var int $h3 */ + $h3 = (int) $h[3]; + /** @var int $h4 */ + $h4 = (int) $h[4]; + /** @var int $h5 */ + $h5 = (int) $h[5]; + /** @var int $h6 */ + $h6 = (int) $h[6]; + /** @var int $h7 */ + $h7 = (int) $h[7]; + /** @var int $h8 */ + $h8 = (int) $h[8]; + /** @var int $h9 */ + $h9 = (int) $h[9]; + + /** @var int $q */ + $q = (self::mul($h9, 19, 5) + (1 << 24)) >> 25; + /** @var int $q */ + $q = ($h0 + $q) >> 26; + /** @var int $q */ + $q = ($h1 + $q) >> 25; + /** @var int $q */ + $q = ($h2 + $q) >> 26; + /** @var int $q */ + $q = ($h3 + $q) >> 25; + /** @var int $q */ + $q = ($h4 + $q) >> 26; + /** @var int $q */ + $q = ($h5 + $q) >> 25; + /** @var int $q */ + $q = ($h6 + $q) >> 26; + /** @var int $q */ + $q = ($h7 + $q) >> 25; + /** @var int $q */ + $q = ($h8 + $q) >> 26; + /** @var int $q */ + $q = ($h9 + $q) >> 25; + + $h0 += self::mul($q, 19, 5); + + /** @var int $carry0 */ + $carry0 = $h0 >> 26; + $h1 += $carry0; + $h0 -= $carry0 << 26; + /** @var int $carry1 */ + $carry1 = $h1 >> 25; + $h2 += $carry1; + $h1 -= $carry1 << 25; + /** @var int $carry2 */ + $carry2 = $h2 >> 26; + $h3 += $carry2; + $h2 -= $carry2 << 26; + /** @var int $carry3 */ + $carry3 = $h3 >> 25; + $h4 += $carry3; + $h3 -= $carry3 << 25; + /** @var int $carry4 */ + $carry4 = $h4 >> 26; + $h5 += $carry4; + $h4 -= $carry4 << 26; + /** @var int $carry5 */ + $carry5 = $h5 >> 25; + $h6 += $carry5; + $h5 -= $carry5 << 25; + /** @var int $carry6 */ + $carry6 = $h6 >> 26; + $h7 += $carry6; + $h6 -= $carry6 << 26; + /** @var int $carry7 */ + $carry7 = $h7 >> 25; + $h8 += $carry7; + $h7 -= $carry7 << 25; + /** @var int $carry8 */ + $carry8 = $h8 >> 26; + $h9 += $carry8; + $h8 -= $carry8 << 26; + /** @var int $carry9 */ + $carry9 = $h9 >> 25; + $h9 -= $carry9 << 25; /** * @var array */ $s = array( - (int) (($h[0] >> 0) & 0xff), - (int) (($h[0] >> 8) & 0xff), - (int) (($h[0] >> 16) & 0xff), - (int) ((($h[0] >> 24) | ($h[1] << 2)) & 0xff), - (int) (($h[1] >> 6) & 0xff), - (int) (($h[1] >> 14) & 0xff), - (int) ((($h[1] >> 22) | ($h[2] << 3)) & 0xff), - (int) (($h[2] >> 5) & 0xff), - (int) (($h[2] >> 13) & 0xff), - (int) ((($h[2] >> 21) | ($h[3] << 5)) & 0xff), - (int) (($h[3] >> 3) & 0xff), - (int) (($h[3] >> 11) & 0xff), - (int) ((($h[3] >> 19) | ($h[4] << 6)) & 0xff), - (int) (($h[4] >> 2) & 0xff), - (int) (($h[4] >> 10) & 0xff), - (int) (($h[4] >> 18) & 0xff), - (int) (($h[5] >> 0) & 0xff), - (int) (($h[5] >> 8) & 0xff), - (int) (($h[5] >> 16) & 0xff), - (int) ((($h[5] >> 24) | ($h[6] << 1)) & 0xff), - (int) (($h[6] >> 7) & 0xff), - (int) (($h[6] >> 15) & 0xff), - (int) ((($h[6] >> 23) | ($h[7] << 3)) & 0xff), - (int) (($h[7] >> 5) & 0xff), - (int) (($h[7] >> 13) & 0xff), - (int) ((($h[7] >> 21) | ($h[8] << 4)) & 0xff), - (int) (($h[8] >> 4) & 0xff), - (int) (($h[8] >> 12) & 0xff), - (int) ((($h[8] >> 20) | ($h[9] << 6)) & 0xff), - (int) (($h[9] >> 2) & 0xff), - (int) (($h[9] >> 10) & 0xff), - (int) (($h[9] >> 18) & 0xff) + (int) (($h0 >> 0) & 0xff), + (int) (($h0 >> 8) & 0xff), + (int) (($h0 >> 16) & 0xff), + (int) ((($h0 >> 24) | ($h1 << 2)) & 0xff), + (int) (($h1 >> 6) & 0xff), + (int) (($h1 >> 14) & 0xff), + (int) ((($h1 >> 22) | ($h2 << 3)) & 0xff), + (int) (($h2 >> 5) & 0xff), + (int) (($h2 >> 13) & 0xff), + (int) ((($h2 >> 21) | ($h3 << 5)) & 0xff), + (int) (($h3 >> 3) & 0xff), + (int) (($h3 >> 11) & 0xff), + (int) ((($h3 >> 19) | ($h4 << 6)) & 0xff), + (int) (($h4 >> 2) & 0xff), + (int) (($h4 >> 10) & 0xff), + (int) (($h4 >> 18) & 0xff), + (int) (($h5 >> 0) & 0xff), + (int) (($h5 >> 8) & 0xff), + (int) (($h5 >> 16) & 0xff), + (int) ((($h5 >> 24) | ($h6 << 1)) & 0xff), + (int) (($h6 >> 7) & 0xff), + (int) (($h6 >> 15) & 0xff), + (int) ((($h6 >> 23) | ($h7 << 3)) & 0xff), + (int) (($h7 >> 5) & 0xff), + (int) (($h7 >> 13) & 0xff), + (int) ((($h7 >> 21) | ($h8 << 4)) & 0xff), + (int) (($h8 >> 4) & 0xff), + (int) (($h8 >> 12) & 0xff), + (int) ((($h8 >> 20) | ($h9 << 6)) & 0xff), + (int) (($h9 >> 2) & 0xff), + (int) (($h9 >> 10) & 0xff), + (int) (($h9 >> 18) & 0xff) ); return self::intArrayToString($s); } @@ -287,11 +345,13 @@ public static function fe_tobytes(ParagonIE_Sodium_Core_Curve25519_Fe $h) * * @param ParagonIE_Sodium_Core_Curve25519_Fe $f * @return int + * @throws SodiumException + * @throws TypeError */ public static function fe_isnegative(ParagonIE_Sodium_Core_Curve25519_Fe $f) { $str = self::fe_tobytes($f); - return self::chrToInt($str[0]) & 1; + return (int) (self::chrToInt($str[0]) & 1); } /** @@ -301,6 +361,8 @@ public static function fe_isnegative(ParagonIE_Sodium_Core_Curve25519_Fe $f) * * @param ParagonIE_Sodium_Core_Curve25519_Fe $f * @return bool + * @throws SodiumException + * @throws TypeError */ public static function fe_isnonzero(ParagonIE_Sodium_Core_Curve25519_Fe $f) { @@ -308,8 +370,10 @@ public static function fe_isnonzero(ParagonIE_Sodium_Core_Curve25519_Fe $f) if ($zero === null) { $zero = str_repeat("\x00", 32); } + /** @var string $zero */ + /** @var string $str */ $str = self::fe_tobytes($f); - return !self::verify_32($str, $zero); + return !self::verify_32($str, (string) $zero); } /** @@ -330,25 +394,45 @@ public static function fe_mul( ParagonIE_Sodium_Core_Curve25519_Fe $f, ParagonIE_Sodium_Core_Curve25519_Fe $g ) { + /** @var int $f0 */ $f0 = $f[0]; + /** @var int $f1 */ $f1 = $f[1]; + /** @var int $f2 */ $f2 = $f[2]; + /** @var int $f3 */ $f3 = $f[3]; + /** @var int $f4 */ $f4 = $f[4]; + /** @var int $f5 */ $f5 = $f[5]; + /** @var int $f6 */ $f6 = $f[6]; + /** @var int $f7 */ $f7 = $f[7]; + /** @var int $f8 */ $f8 = $f[8]; + /** @var int $f9 */ $f9 = $f[9]; + /** @var int $g0 */ $g0 = $g[0]; + /** @var int $g1 */ $g1 = $g[1]; + /** @var int $g2 */ $g2 = $g[2]; + /** @var int $g3 */ $g3 = $g[3]; + /** @var int $g4 */ $g4 = $g[4]; + /** @var int $g5 */ $g5 = $g[5]; + /** @var int $g6 */ $g6 = $g[6]; + /** @var int $g7 */ $g7 = $g[7]; + /** @var int $g8 */ $g8 = $g[8]; + /** @var int $g9 */ $g9 = $g[9]; $g1_19 = self::mul($g1, 19, 5); $g2_19 = self::mul($g2, 19, 5); @@ -359,111 +443,116 @@ public static function fe_mul( $g7_19 = self::mul($g7, 19, 5); $g8_19 = self::mul($g8, 19, 5); $g9_19 = self::mul($g9, 19, 5); + /** @var int $f1_2 */ $f1_2 = $f1 << 1; + /** @var int $f3_2 */ $f3_2 = $f3 << 1; + /** @var int $f5_2 */ $f5_2 = $f5 << 1; + /** @var int $f7_2 */ $f7_2 = $f7 << 1; + /** @var int $f9_2 */ $f9_2 = $f9 << 1; - $f0g0 = self::mul($f0, $g0); - $f0g1 = self::mul($f0, $g1); - $f0g2 = self::mul($f0, $g2); - $f0g3 = self::mul($f0, $g3); - $f0g4 = self::mul($f0, $g4); - $f0g5 = self::mul($f0, $g5); - $f0g6 = self::mul($f0, $g6); - $f0g7 = self::mul($f0, $g7); - $f0g8 = self::mul($f0, $g8); - $f0g9 = self::mul($f0, $g9); - $f1g0 = self::mul($f1, $g0); - $f1g1_2 = self::mul($f1_2, $g1); - $f1g2 = self::mul($f1, $g2); - $f1g3_2 = self::mul($f1_2, $g3); - $f1g4 = self::mul($f1, $g4); - $f1g5_2 = self::mul($f1_2, $g5); - $f1g6 = self::mul($f1, $g6); - $f1g7_2 = self::mul($f1_2, $g7); - $f1g8 = self::mul($f1, $g8); - $f1g9_38 = self::mul($f1_2, $g9_19); - $f2g0 = self::mul($f2, $g0); - $f2g1 = self::mul($f2, $g1); - $f2g2 = self::mul($f2, $g2); - $f2g3 = self::mul($f2, $g3); - $f2g4 = self::mul($f2, $g4); - $f2g5 = self::mul($f2, $g5); - $f2g6 = self::mul($f2, $g6); - $f2g7 = self::mul($f2, $g7); - $f2g8_19 = self::mul($f2, $g8_19); - $f2g9_19 = self::mul($f2, $g9_19); - $f3g0 = self::mul($f3, $g0); - $f3g1_2 = self::mul($f3_2, $g1); - $f3g2 = self::mul($f3, $g2); - $f3g3_2 = self::mul($f3_2, $g3); - $f3g4 = self::mul($f3, $g4); - $f3g5_2 = self::mul($f3_2, $g5); - $f3g6 = self::mul($f3, $g6); - $f3g7_38 = self::mul($f3_2, $g7_19); - $f3g8_19 = self::mul($f3, $g8_19); - $f3g9_38 = self::mul($f3_2, $g9_19); - $f4g0 = self::mul($f4, $g0); - $f4g1 = self::mul($f4, $g1); - $f4g2 = self::mul($f4, $g2); - $f4g3 = self::mul($f4, $g3); - $f4g4 = self::mul($f4, $g4); - $f4g5 = self::mul($f4, $g5); - $f4g6_19 = self::mul($f4, $g6_19); - $f4g7_19 = self::mul($f4, $g7_19); - $f4g8_19 = self::mul($f4, $g8_19); - $f4g9_19 = self::mul($f4, $g9_19); - $f5g0 = self::mul($f5, $g0); - $f5g1_2 = self::mul($f5_2, $g1); - $f5g2 = self::mul($f5, $g2); - $f5g3_2 = self::mul($f5_2, $g3); - $f5g4 = self::mul($f5, $g4); - $f5g5_38 = self::mul($f5_2, $g5_19); - $f5g6_19 = self::mul($f5, $g6_19); - $f5g7_38 = self::mul($f5_2, $g7_19); - $f5g8_19 = self::mul($f5, $g8_19); - $f5g9_38 = self::mul($f5_2, $g9_19); - $f6g0 = self::mul($f6, $g0); - $f6g1 = self::mul($f6, $g1); - $f6g2 = self::mul($f6, $g2); - $f6g3 = self::mul($f6, $g3); - $f6g4_19 = self::mul($f6, $g4_19); - $f6g5_19 = self::mul($f6, $g5_19); - $f6g6_19 = self::mul($f6, $g6_19); - $f6g7_19 = self::mul($f6, $g7_19); - $f6g8_19 = self::mul($f6, $g8_19); - $f6g9_19 = self::mul($f6, $g9_19); - $f7g0 = self::mul($f7, $g0); - $f7g1_2 = self::mul($f7_2, $g1); - $f7g2 = self::mul($f7, $g2); - $f7g3_38 = self::mul($f7_2, $g3_19); - $f7g4_19 = self::mul($f7, $g4_19); - $f7g5_38 = self::mul($f7_2, $g5_19); - $f7g6_19 = self::mul($f7, $g6_19); - $f7g7_38 = self::mul($f7_2, $g7_19); - $f7g8_19 = self::mul($f7, $g8_19); - $f7g9_38 = self::mul($f7_2, $g9_19); - $f8g0 = self::mul($f8, $g0); - $f8g1 = self::mul($f8, $g1); - $f8g2_19 = self::mul($f8, $g2_19); - $f8g3_19 = self::mul($f8, $g3_19); - $f8g4_19 = self::mul($f8, $g4_19); - $f8g5_19 = self::mul($f8, $g5_19); - $f8g6_19 = self::mul($f8, $g6_19); - $f8g7_19 = self::mul($f8, $g7_19); - $f8g8_19 = self::mul($f8, $g8_19); - $f8g9_19 = self::mul($f8, $g9_19); - $f9g0 = self::mul($f9, $g0); - $f9g1_38 = self::mul($f9_2, $g1_19); - $f9g2_19 = self::mul($f9, $g2_19); - $f9g3_38 = self::mul($f9_2, $g3_19); - $f9g4_19 = self::mul($f9, $g4_19); - $f9g5_38 = self::mul($f9_2, $g5_19); - $f9g6_19 = self::mul($f9, $g6_19); - $f9g7_38 = self::mul($f9_2, $g7_19); - $f9g8_19 = self::mul($f9, $g8_19); - $f9g9_38 = self::mul($f9_2, $g9_19); + $f0g0 = self::mul($f0, $g0, 27); + $f0g1 = self::mul($f0, $g1, 26); + $f0g2 = self::mul($f0, $g2, 27); + $f0g3 = self::mul($f0, $g3, 26); + $f0g4 = self::mul($f0, $g4, 27); + $f0g5 = self::mul($f0, $g5, 26); + $f0g6 = self::mul($f0, $g6, 27); + $f0g7 = self::mul($f0, $g7, 26); + $f0g8 = self::mul($f0, $g8, 27); + $f0g9 = self::mul($f0, $g9, 27); + $f1g0 = self::mul($f1, $g0, 27); + $f1g1_2 = self::mul($f1_2, $g1, 26); + $f1g2 = self::mul($f1, $g2, 27); + $f1g3_2 = self::mul($f1_2, $g3, 26); + $f1g4 = self::mul($f1, $g4, 27); + $f1g5_2 = self::mul($f1_2, $g5, 26); + $f1g6 = self::mul($f1, $g6, 27); + $f1g7_2 = self::mul($f1_2, $g7, 26); + $f1g8 = self::mul($f1, $g8, 27); + $f1g9_38 = self::mul($g9_19, $f1_2, 27); + $f2g0 = self::mul($f2, $g0, 27); + $f2g1 = self::mul($f2, $g1, 26); + $f2g2 = self::mul($f2, $g2, 27); + $f2g3 = self::mul($f2, $g3, 26); + $f2g4 = self::mul($f2, $g4, 27); + $f2g5 = self::mul($f2, $g5, 26); + $f2g6 = self::mul($f2, $g6, 27); + $f2g7 = self::mul($f2, $g7, 26); + $f2g8_19 = self::mul($g8_19, $f2, 27); + $f2g9_19 = self::mul($g9_19, $f2, 27); + $f3g0 = self::mul($f3, $g0, 27); + $f3g1_2 = self::mul($f3_2, $g1, 26); + $f3g2 = self::mul($f3, $g2, 27); + $f3g3_2 = self::mul($f3_2, $g3, 26); + $f3g4 = self::mul($f3, $g4, 27); + $f3g5_2 = self::mul($f3_2, $g5, 26); + $f3g6 = self::mul($f3, $g6, 27); + $f3g7_38 = self::mul($g7_19, $f3_2, 27); + $f3g8_19 = self::mul($g8_19, $f3, 27); + $f3g9_38 = self::mul($g9_19, $f3_2, 27); + $f4g0 = self::mul($f4, $g0, 27); + $f4g1 = self::mul($f4, $g1, 26); + $f4g2 = self::mul($f4, $g2, 27); + $f4g3 = self::mul($f4, $g3, 26); + $f4g4 = self::mul($f4, $g4, 27); + $f4g5 = self::mul($f4, $g5, 26); + $f4g6_19 = self::mul($g6_19, $f4, 27); + $f4g7_19 = self::mul($g7_19, $f4, 27); + $f4g8_19 = self::mul($g8_19, $f4, 27); + $f4g9_19 = self::mul($g9_19, $f4, 27); + $f5g0 = self::mul($f5, $g0, 27); + $f5g1_2 = self::mul($f5_2, $g1, 26); + $f5g2 = self::mul($f5, $g2, 27); + $f5g3_2 = self::mul($f5_2, $g3, 26); + $f5g4 = self::mul($f5, $g4, 27); + $f5g5_38 = self::mul($g5_19, $f5_2, 27); + $f5g6_19 = self::mul($g6_19, $f5, 26); + $f5g7_38 = self::mul($g7_19, $f5_2, 27); + $f5g8_19 = self::mul($g8_19, $f5, 26); + $f5g9_38 = self::mul($g9_19, $f5_2, 27); + $f6g0 = self::mul($f6, $g0, 27); + $f6g1 = self::mul($f6, $g1, 26); + $f6g2 = self::mul($f6, $g2, 27); + $f6g3 = self::mul($f6, $g3, 26); + $f6g4_19 = self::mul($g4_19, $f6, 27); + $f6g5_19 = self::mul($g5_19, $f6, 27); + $f6g6_19 = self::mul($g6_19, $f6, 27); + $f6g7_19 = self::mul($g7_19, $f6, 27); + $f6g8_19 = self::mul($g8_19, $f6, 27); + $f6g9_19 = self::mul($g9_19, $f6, 27); + $f7g0 = self::mul($f7, $g0, 27); + $f7g1_2 = self::mul($f7_2, $g1, 26); + $f7g2 = self::mul($f7, $g2, 27); + $f7g3_38 = self::mul($g3_19, $f7_2, 27); + $f7g4_19 = self::mul($g4_19, $f7, 27); + $f7g5_38 = self::mul($g5_19, $f7_2, 27); + $f7g6_19 = self::mul($g6_19, $f7, 27); + $f7g7_38 = self::mul($g7_19, $f7_2, 27); + $f7g8_19 = self::mul($g8_19, $f7, 27); + $f7g9_38 = self::mul($g9_19,$f7_2, 27); + $f8g0 = self::mul($f8, $g0, 27); + $f8g1 = self::mul($f8, $g1, 26); + $f8g2_19 = self::mul($g2_19, $f8, 27); + $f8g3_19 = self::mul($g3_19, $f8, 27); + $f8g4_19 = self::mul($g4_19, $f8, 27); + $f8g5_19 = self::mul($g5_19, $f8, 27); + $f8g6_19 = self::mul($g6_19, $f8, 27); + $f8g7_19 = self::mul($g7_19, $f8, 27); + $f8g8_19 = self::mul($g8_19, $f8, 27); + $f8g9_19 = self::mul($g9_19, $f8, 27); + $f9g0 = self::mul($f9, $g0, 27); + $f9g1_38 = self::mul($g1_19, $f9_2, 27); + $f9g2_19 = self::mul($g2_19, $f9, 27); + $f9g3_38 = self::mul($g3_19, $f9_2, 27); + $f9g4_19 = self::mul($g4_19, $f9, 27); + $f9g5_38 = self::mul($g5_19, $f9_2, 27); + $f9g6_19 = self::mul($g6_19, $f9, 27); + $f9g7_38 = self::mul($g7_19, $f9_2, 27); + $f9g8_19 = self::mul($g8_19, $f9, 27); + $f9g9_38 = self::mul($g9_19, $f9_2, 27); $h0 = $f0g0 + $f1g9_38 + $f2g8_19 + $f3g7_38 + $f4g6_19 + $f5g5_38 + $f6g4_19 + $f7g3_38 + $f8g2_19 + $f9g1_38; $h1 = $f0g1 + $f1g0 + $f2g9_19 + $f3g8_19 + $f4g7_19 + $f5g6_19 + $f6g5_19 + $f7g4_19 + $f8g3_19 + $f9g2_19; $h2 = $f0g2 + $f1g1_2 + $f2g0 + $f3g9_38 + $f4g8_19 + $f5g7_38 + $f6g6_19 + $f7g5_38 + $f8g4_19 + $f9g3_38; @@ -475,45 +564,57 @@ public static function fe_mul( $h8 = $f0g8 + $f1g7_2 + $f2g6 + $f3g5_2 + $f4g4 + $f5g3_2 + $f6g2 + $f7g1_2 + $f8g0 + $f9g9_38; $h9 = $f0g9 + $f1g8 + $f2g7 + $f3g6 + $f4g5 + $f5g4 + $f6g3 + $f7g2 + $f8g1 + $f9g0 ; + /** @var int $carry0 */ $carry0 = ($h0 + (1 << 25)) >> 26; $h1 += $carry0; $h0 -= $carry0 << 26; + /** @var int $carry4 */ $carry4 = ($h4 + (1 << 25)) >> 26; $h5 += $carry4; $h4 -= $carry4 << 26; + /** @var int $carry1 */ $carry1 = ($h1 + (1 << 24)) >> 25; $h2 += $carry1; $h1 -= $carry1 << 25; + /** @var int $carry5 */ $carry5 = ($h5 + (1 << 24)) >> 25; $h6 += $carry5; $h5 -= $carry5 << 25; + /** @var int $carry2 */ $carry2 = ($h2 + (1 << 25)) >> 26; $h3 += $carry2; $h2 -= $carry2 << 26; + /** @var int $carry6 */ $carry6 = ($h6 + (1 << 25)) >> 26; $h7 += $carry6; $h6 -= $carry6 << 26; + /** @var int $carry3 */ $carry3 = ($h3 + (1 << 24)) >> 25; $h4 += $carry3; $h3 -= $carry3 << 25; + /** @var int $carry7 */ $carry7 = ($h7 + (1 << 24)) >> 25; $h8 += $carry7; $h7 -= $carry7 << 25; + /** @var int $carry4 */ $carry4 = ($h4 + (1 << 25)) >> 26; $h5 += $carry4; $h4 -= $carry4 << 26; + /** @var int $carry8 */ $carry8 = ($h8 + (1 << 25)) >> 26; $h9 += $carry8; $h8 -= $carry8 << 26; + /** @var int $carry9 */ $carry9 = ($h9 + (1 << 24)) >> 25; $h0 += self::mul($carry9, 19, 5); $h9 -= $carry9 << 25; + /** @var int $carry0 */ $carry0 = ($h0 + (1 << 25)) >> 26; $h1 += $carry0; $h0 -= $carry0 << 26; @@ -543,6 +644,7 @@ public static function fe_mul( * * @param ParagonIE_Sodium_Core_Curve25519_Fe $f * @return ParagonIE_Sodium_Core_Curve25519_Fe + * @psalm-suppress MixedAssignment */ public static function fe_neg(ParagonIE_Sodium_Core_Curve25519_Fe $f) { @@ -576,74 +678,82 @@ public static function fe_sq(ParagonIE_Sodium_Core_Curve25519_Fe $f) $f8 = (int) $f[8]; $f9 = (int) $f[9]; + /** @var int $f0_2 */ $f0_2 = $f0 << 1; + /** @var int $f1_2 */ $f1_2 = $f1 << 1; + /** @var int $f2_2 */ $f2_2 = $f2 << 1; + /** @var int $f3_2 */ $f3_2 = $f3 << 1; + /** @var int $f4_2 */ $f4_2 = $f4 << 1; + /** @var int $f5_2 */ $f5_2 = $f5 << 1; + /** @var int $f6_2 */ $f6_2 = $f6 << 1; + /** @var int $f7_2 */ $f7_2 = $f7 << 1; $f5_38 = self::mul($f5, 38, 6); $f6_19 = self::mul($f6, 19, 5); $f7_38 = self::mul($f7, 38, 6); $f8_19 = self::mul($f8, 19, 5); $f9_38 = self::mul($f9, 38, 6); - $f0f0 = self::mul($f0, $f0); - $f0f1_2 = self::mul($f0_2, $f1); - $f0f2_2 = self::mul($f0_2, $f2); - $f0f3_2 = self::mul($f0_2, $f3); - $f0f4_2 = self::mul($f0_2, $f4); - $f0f5_2 = self::mul($f0_2, $f5); - $f0f6_2 = self::mul($f0_2, $f6); - $f0f7_2 = self::mul($f0_2, $f7); - $f0f8_2 = self::mul($f0_2, $f8); - $f0f9_2 = self::mul($f0_2, $f9); - $f1f1_2 = self::mul($f1_2, $f1); - $f1f2_2 = self::mul($f1_2, $f2); - $f1f3_4 = self::mul($f1_2, $f3_2); - $f1f4_2 = self::mul($f1_2, $f4); - $f1f5_4 = self::mul($f1_2, $f5_2); - $f1f6_2 = self::mul($f1_2, $f6); - $f1f7_4 = self::mul($f1_2, $f7_2); - $f1f8_2 = self::mul($f1_2, $f8); - $f1f9_76 = self::mul($f1_2, $f9_38); - $f2f2 = self::mul($f2, $f2); - $f2f3_2 = self::mul($f2_2, $f3); - $f2f4_2 = self::mul($f2_2, $f4); - $f2f5_2 = self::mul($f2_2, $f5); - $f2f6_2 = self::mul($f2_2, $f6); - $f2f7_2 = self::mul($f2_2, $f7); - $f2f8_38 = self::mul($f2_2, $f8_19); - $f2f9_38 = self::mul($f2, $f9_38); - $f3f3_2 = self::mul($f3_2, $f3); - $f3f4_2 = self::mul($f3_2, $f4); - $f3f5_4 = self::mul($f3_2, $f5_2); - $f3f6_2 = self::mul($f3_2, $f6); - $f3f7_76 = self::mul($f3_2, $f7_38); - $f3f8_38 = self::mul($f3_2, $f8_19); - $f3f9_76 = self::mul($f3_2, $f9_38); - $f4f4 = self::mul($f4, $f4); - $f4f5_2 = self::mul($f4_2, $f5); - $f4f6_38 = self::mul($f4_2, $f6_19); - $f4f7_38 = self::mul($f4, $f7_38); - $f4f8_38 = self::mul($f4_2, $f8_19); - $f4f9_38 = self::mul($f4, $f9_38); - $f5f5_38 = self::mul($f5, $f5_38); - $f5f6_38 = self::mul($f5_2, $f6_19); - $f5f7_76 = self::mul($f5_2, $f7_38); - $f5f8_38 = self::mul($f5_2, $f8_19); - $f5f9_76 = self::mul($f5_2, $f9_38); - $f6f6_19 = self::mul($f6, $f6_19); - $f6f7_38 = self::mul($f6, $f7_38); - $f6f8_38 = self::mul($f6_2, $f8_19); - $f6f9_38 = self::mul($f6, $f9_38); - $f7f7_38 = self::mul($f7, $f7_38); - $f7f8_38 = self::mul($f7_2, $f8_19); - $f7f9_76 = self::mul($f7_2, $f9_38); - $f8f8_19 = self::mul($f8, $f8_19); - $f8f9_38 = self::mul($f8, $f9_38); - $f9f9_38 = self::mul($f9, $f9_38); + $f0f0 = self::mul($f0, $f0, 26); + $f0f1_2 = self::mul($f0_2, $f1, 26); + $f0f2_2 = self::mul($f0_2, $f2, 26); + $f0f3_2 = self::mul($f0_2, $f3, 26); + $f0f4_2 = self::mul($f0_2, $f4, 26); + $f0f5_2 = self::mul($f0_2, $f5, 26); + $f0f6_2 = self::mul($f0_2, $f6, 26); + $f0f7_2 = self::mul($f0_2, $f7, 26); + $f0f8_2 = self::mul($f0_2, $f8, 26); + $f0f9_2 = self::mul($f0_2, $f9, 26); + $f1f1_2 = self::mul($f1_2, $f1, 26); + $f1f2_2 = self::mul($f1_2, $f2, 26); + $f1f3_4 = self::mul($f1_2, $f3_2, 26); + $f1f4_2 = self::mul($f1_2, $f4, 26); + $f1f5_4 = self::mul($f1_2, $f5_2, 27); + $f1f6_2 = self::mul($f1_2, $f6, 26); + $f1f7_4 = self::mul($f1_2, $f7_2, 26); + $f1f8_2 = self::mul($f1_2, $f8, 26); + $f1f9_76 = self::mul($f9_38, $f1_2, 26); + $f2f2 = self::mul($f2, $f2, 26); + $f2f3_2 = self::mul($f2_2, $f3, 26); + $f2f4_2 = self::mul($f2_2, $f4, 26); + $f2f5_2 = self::mul($f2_2, $f5, 26); + $f2f6_2 = self::mul($f2_2, $f6, 26); + $f2f7_2 = self::mul($f2_2, $f7, 26); + $f2f8_38 = self::mul($f8_19, $f2_2, 27); + $f2f9_38 = self::mul($f9_38, $f2, 26); + $f3f3_2 = self::mul($f3_2, $f3, 26); + $f3f4_2 = self::mul($f3_2, $f4, 26); + $f3f5_4 = self::mul($f3_2, $f5_2, 27); + $f3f6_2 = self::mul($f3_2, $f6, 26); + $f3f7_76 = self::mul($f7_38, $f3_2, 26); + $f3f8_38 = self::mul($f8_19, $f3_2, 26); + $f3f9_76 = self::mul($f9_38, $f3_2, 26); + $f4f4 = self::mul($f4, $f4, 26); + $f4f5_2 = self::mul($f4_2, $f5, 26); + $f4f6_38 = self::mul($f6_19, $f4_2, 27); + $f4f7_38 = self::mul($f7_38, $f4, 26); + $f4f8_38 = self::mul($f8_19, $f4_2, 27); + $f4f9_38 = self::mul($f9_38, $f4, 26); + $f5f5_38 = self::mul($f5_38, $f5, 26); + $f5f6_38 = self::mul($f6_19, $f5_2, 27); + $f5f7_76 = self::mul($f7_38, $f5_2, 27); + $f5f8_38 = self::mul($f8_19, $f5_2, 27); + $f5f9_76 = self::mul($f9_38, $f5_2, 27); + $f6f6_19 = self::mul($f6_19, $f6, 26); + $f6f7_38 = self::mul($f7_38, $f6, 26); + $f6f8_38 = self::mul($f8_19, $f6_2, 27); + $f6f9_38 = self::mul($f9_38, $f6, 26); + $f7f7_38 = self::mul($f7_38, $f7, 26); + $f7f8_38 = self::mul($f8_19, $f7_2, 27); + $f7f9_76 = self::mul($f9_38, $f7_2, 27); + $f8f8_19 = self::mul($f8_19, $f8, 26); + $f8f9_38 = self::mul($f9_38, $f8, 26); + $f9f9_38 = self::mul($f9_38, $f9, 27); $h0 = $f0f0 + $f1f9_76 + $f2f8_38 + $f3f7_76 + $f4f6_38 + $f5f5_38; $h1 = $f0f1_2 + $f2f9_38 + $f3f8_38 + $f4f7_38 + $f5f6_38; $h2 = $f0f2_2 + $f1f1_2 + $f3f9_76 + $f4f8_38 + $f5f7_76 + $f6f6_19; @@ -655,45 +765,57 @@ public static function fe_sq(ParagonIE_Sodium_Core_Curve25519_Fe $f) $h8 = $f0f8_2 + $f1f7_4 + $f2f6_2 + $f3f5_4 + $f4f4 + $f9f9_38; $h9 = $f0f9_2 + $f1f8_2 + $f2f7_2 + $f3f6_2 + $f4f5_2; + /** @var int $carry0 */ $carry0 = ($h0 + (1 << 25)) >> 26; $h1 += $carry0; $h0 -= $carry0 << 26; + /** @var int $carry4 */ $carry4 = ($h4 + (1 << 25)) >> 26; $h5 += $carry4; $h4 -= $carry4 << 26; + /** @var int $carry1 */ $carry1 = ($h1 + (1 << 24)) >> 25; $h2 += $carry1; $h1 -= $carry1 << 25; + /** @var int $carry5 */ $carry5 = ($h5 + (1 << 24)) >> 25; $h6 += $carry5; $h5 -= $carry5 << 25; + /** @var int $carry2 */ $carry2 = ($h2 + (1 << 25)) >> 26; $h3 += $carry2; $h2 -= $carry2 << 26; + /** @var int $carry6 */ $carry6 = ($h6 + (1 << 25)) >> 26; $h7 += $carry6; $h6 -= $carry6 << 26; + /** @var int $carry3 */ $carry3 = ($h3 + (1 << 24)) >> 25; $h4 += $carry3; $h3 -= $carry3 << 25; + /** @var int $carry7 */ $carry7 = ($h7 + (1 << 24)) >> 25; $h8 += $carry7; $h7 -= $carry7 << 25; + /** @var int $carry4 */ $carry4 = ($h4 + (1 << 25)) >> 26; $h5 += $carry4; $h4 -= $carry4 << 26; + /** @var int $carry8 */ $carry8 = ($h8 + (1 << 25)) >> 26; $h9 += $carry8; $h8 -= $carry8 << 26; + /** @var int $carry9 */ $carry9 = ($h9 + (1 << 24)) >> 25; $h0 += self::mul($carry9, 19, 5); $h9 -= $carry9 << 25; + /** @var int $carry0 */ $carry0 = ($h0 + (1 << 25)) >> 26; $h1 += $carry0; $h0 -= $carry0 << 26; @@ -738,136 +860,155 @@ public static function fe_sq2(ParagonIE_Sodium_Core_Curve25519_Fe $f) $f8 = (int) $f[8]; $f9 = (int) $f[9]; + /** @var int $f0_2 */ $f0_2 = $f0 << 1; + /** @var int $f1_2 */ $f1_2 = $f1 << 1; + /** @var int $f2_2 */ $f2_2 = $f2 << 1; + /** @var int $f3_2 */ $f3_2 = $f3 << 1; + /** @var int $f4_2 */ $f4_2 = $f4 << 1; + /** @var int $f5_2 */ $f5_2 = $f5 << 1; + /** @var int $f6_2 */ $f6_2 = $f6 << 1; + /** @var int $f7_2 */ $f7_2 = $f7 << 1; $f5_38 = self::mul($f5, 38, 6); /* 1.959375*2^30 */ $f6_19 = self::mul($f6, 19, 5); /* 1.959375*2^30 */ $f7_38 = self::mul($f7, 38, 6); /* 1.959375*2^30 */ $f8_19 = self::mul($f8, 19, 5); /* 1.959375*2^30 */ $f9_38 = self::mul($f9, 38, 6); /* 1.959375*2^30 */ - $f0f0 = self::mul($f0, (int) $f0); - $f0f1_2 = self::mul($f0_2, (int) $f1); - $f0f2_2 = self::mul($f0_2, (int) $f2); - $f0f3_2 = self::mul($f0_2, (int) $f3); - $f0f4_2 = self::mul($f0_2, (int) $f4); - $f0f5_2 = self::mul($f0_2, (int) $f5); - $f0f6_2 = self::mul($f0_2, (int) $f6); - $f0f7_2 = self::mul($f0_2, (int) $f7); - $f0f8_2 = self::mul($f0_2, (int) $f8); - $f0f9_2 = self::mul($f0_2, (int) $f9); - $f1f1_2 = self::mul($f1_2, (int) $f1); - $f1f2_2 = self::mul($f1_2, (int) $f2); - $f1f3_4 = self::mul($f1_2, (int) $f3_2); - $f1f4_2 = self::mul($f1_2, (int) $f4); - $f1f5_4 = self::mul($f1_2, (int) $f5_2); - $f1f6_2 = self::mul($f1_2, (int) $f6); - $f1f7_4 = self::mul($f1_2, (int) $f7_2); - $f1f8_2 = self::mul($f1_2, (int) $f8); - $f1f9_76 = self::mul($f1_2, (int) $f9_38); - $f2f2 = self::mul($f2, (int) $f2); - $f2f3_2 = self::mul($f2_2, (int) $f3); - $f2f4_2 = self::mul($f2_2, (int) $f4); - $f2f5_2 = self::mul($f2_2, (int) $f5); - $f2f6_2 = self::mul($f2_2, (int) $f6); - $f2f7_2 = self::mul($f2_2, (int) $f7); - $f2f8_38 = self::mul($f2_2, (int) $f8_19); - $f2f9_38 = self::mul($f2, (int) $f9_38); - $f3f3_2 = self::mul($f3_2, (int) $f3); - $f3f4_2 = self::mul($f3_2, (int) $f4); - $f3f5_4 = self::mul($f3_2, (int) $f5_2); - $f3f6_2 = self::mul($f3_2, (int) $f6); - $f3f7_76 = self::mul($f3_2, (int) $f7_38); - $f3f8_38 = self::mul($f3_2, (int) $f8_19); - $f3f9_76 = self::mul($f3_2, (int) $f9_38); - $f4f4 = self::mul($f4, (int) $f4); - $f4f5_2 = self::mul($f4_2, (int) $f5); - $f4f6_38 = self::mul($f4_2, (int) $f6_19); - $f4f7_38 = self::mul($f4, (int) $f7_38); - $f4f8_38 = self::mul($f4_2, (int) $f8_19); - $f4f9_38 = self::mul($f4, (int) $f9_38); - $f5f5_38 = self::mul($f5, (int) $f5_38); - $f5f6_38 = self::mul($f5_2, (int) $f6_19); - $f5f7_76 = self::mul($f5_2, (int) $f7_38); - $f5f8_38 = self::mul($f5_2, (int) $f8_19); - $f5f9_76 = self::mul($f5_2, (int) $f9_38); - $f6f6_19 = self::mul($f6, (int) $f6_19); - $f6f7_38 = self::mul($f6, (int) $f7_38); - $f6f8_38 = self::mul($f6_2, (int) $f8_19); - $f6f9_38 = self::mul($f6, (int) $f9_38); - $f7f7_38 = self::mul($f7, (int) $f7_38); - $f7f8_38 = self::mul($f7_2, (int) $f8_19); - $f7f9_76 = self::mul($f7_2, (int) $f9_38); - $f8f8_19 = self::mul($f8, (int) $f8_19); - $f8f9_38 = self::mul($f8, (int) $f9_38); - $f9f9_38 = self::mul($f9, (int) $f9_38); - - $h0 = (int) ($f0f0 + $f1f9_76 + $f2f8_38 + $f3f7_76 + $f4f6_38 + $f5f5_38); - $h1 = (int) ($f0f1_2 + $f2f9_38 + $f3f8_38 + $f4f7_38 + $f5f6_38); - $h2 = (int) ($f0f2_2 + $f1f1_2 + $f3f9_76 + $f4f8_38 + $f5f7_76 + $f6f6_19); - $h3 = (int) ($f0f3_2 + $f1f2_2 + $f4f9_38 + $f5f8_38 + $f6f7_38); - $h4 = (int) ($f0f4_2 + $f1f3_4 + $f2f2 + $f5f9_76 + $f6f8_38 + $f7f7_38); - $h5 = (int) ($f0f5_2 + $f1f4_2 + $f2f3_2 + $f6f9_38 + $f7f8_38); - $h6 = (int) ($f0f6_2 + $f1f5_4 + $f2f4_2 + $f3f3_2 + $f7f9_76 + $f8f8_19); - $h7 = (int) ($f0f7_2 + $f1f6_2 + $f2f5_2 + $f3f4_2 + $f8f9_38); - $h8 = (int) ($f0f8_2 + $f1f7_4 + $f2f6_2 + $f3f5_4 + $f4f4 + $f9f9_38); - $h9 = (int) ($f0f9_2 + $f1f8_2 + $f2f7_2 + $f3f6_2 + $f4f5_2); - - $h0 = (int) ($h0 + $h0); - $h1 = (int) ($h1 + $h1); - $h2 = (int) ($h2 + $h2); - $h3 = (int) ($h3 + $h3); - $h4 = (int) ($h4 + $h4); - $h5 = (int) ($h5 + $h5); - $h6 = (int) ($h6 + $h6); - $h7 = (int) ($h7 + $h7); - $h8 = (int) ($h8 + $h8); - $h9 = (int) ($h9 + $h9); - + $f0f0 = self::mul($f0, $f0, 26); + $f0f1_2 = self::mul($f0_2, $f1, 26); + $f0f2_2 = self::mul($f0_2, $f2, 26); + $f0f3_2 = self::mul($f0_2, $f3, 26); + $f0f4_2 = self::mul($f0_2, $f4, 26); + $f0f5_2 = self::mul($f0_2, $f5, 26); + $f0f6_2 = self::mul($f0_2, $f6, 26); + $f0f7_2 = self::mul($f0_2, $f7, 26); + $f0f8_2 = self::mul($f0_2, $f8, 26); + $f0f9_2 = self::mul($f0_2, $f9, 26); + $f1f1_2 = self::mul($f1_2, $f1, 26); + $f1f2_2 = self::mul($f1_2, $f2, 26); + $f1f3_4 = self::mul($f1_2, $f3_2, 27); + $f1f4_2 = self::mul($f1_2, $f4, 26); + $f1f5_4 = self::mul($f1_2, $f5_2, 27); + $f1f6_2 = self::mul($f1_2, $f6, 26); + $f1f7_4 = self::mul($f1_2, $f7_2, 27); + $f1f8_2 = self::mul($f1_2, $f8, 26); + $f1f9_76 = self::mul($f9_38, $f1_2, 27); + $f2f2 = self::mul($f2, $f2, 26); + $f2f3_2 = self::mul($f2_2, $f3, 26); + $f2f4_2 = self::mul($f2_2, $f4, 26); + $f2f5_2 = self::mul($f2_2, $f5, 26); + $f2f6_2 = self::mul($f2_2, $f6, 26); + $f2f7_2 = self::mul($f2_2, $f7, 26); + $f2f8_38 = self::mul($f8_19, $f2_2, 27); + $f2f9_38 = self::mul($f9_38, $f2, 26); + $f3f3_2 = self::mul($f3_2, $f3, 26); + $f3f4_2 = self::mul($f3_2, $f4, 26); + $f3f5_4 = self::mul($f3_2, $f5_2, 27); + $f3f6_2 = self::mul($f3_2, $f6, 27); + $f3f7_76 = self::mul($f7_38, $f3_2, 27); + $f3f8_38 = self::mul($f8_19, $f3_2, 27); + $f3f9_76 = self::mul($f9_38, $f3_2, 27); + $f4f4 = self::mul($f4, $f4, 26); + $f4f5_2 = self::mul($f4_2, $f5, 26); + $f4f6_38 = self::mul($f6_19, $f4_2, 27); + $f4f7_38 = self::mul($f7_38, $f4, 27); + $f4f8_38 = self::mul($f8_19, $f4_2, 27); + $f4f9_38 = self::mul($f9_38, $f4, 27); + $f5f5_38 = self::mul($f5_38, $f5, 26); + $f5f6_38 = self::mul($f6_19, $f5_2, 27); + $f5f7_76 = self::mul($f7_38, $f5_2, 27); + $f5f8_38 = self::mul($f8_19, $f5_2, 27); + $f5f9_76 = self::mul($f9_38, $f5_2, 27); + $f6f6_19 = self::mul($f6_19, $f6, 26); + $f6f7_38 = self::mul($f7_38, $f6, 26); + $f6f8_38 = self::mul($f8_19, $f6_2, 27); + $f6f9_38 = self::mul($f9_38, $f6, 26); + $f7f7_38 = self::mul($f7_38, $f7, 26); + $f7f8_38 = self::mul($f8_19, $f7_2, 27); + $f7f9_76 = self::mul($f9_38, $f7_2, 27); + $f8f8_19 = self::mul($f8_19, $f8, 26); + $f8f9_38 = self::mul($f9_38, $f8, 26); + $f9f9_38 = self::mul($f9_38, $f9, 27); + + /** @var int $h0 */ + $h0 = (int) ($f0f0 + $f1f9_76 + $f2f8_38 + $f3f7_76 + $f4f6_38 + $f5f5_38) << 1; + /** @var int $h1 */ + $h1 = (int) ($f0f1_2 + $f2f9_38 + $f3f8_38 + $f4f7_38 + $f5f6_38) << 1; + /** @var int $h2 */ + $h2 = (int) ($f0f2_2 + $f1f1_2 + $f3f9_76 + $f4f8_38 + $f5f7_76 + $f6f6_19) << 1; + /** @var int $h3 */ + $h3 = (int) ($f0f3_2 + $f1f2_2 + $f4f9_38 + $f5f8_38 + $f6f7_38) << 1; + /** @var int $h4 */ + $h4 = (int) ($f0f4_2 + $f1f3_4 + $f2f2 + $f5f9_76 + $f6f8_38 + $f7f7_38) << 1; + /** @var int $h5 */ + $h5 = (int) ($f0f5_2 + $f1f4_2 + $f2f3_2 + $f6f9_38 + $f7f8_38) << 1; + /** @var int $h6 */ + $h6 = (int) ($f0f6_2 + $f1f5_4 + $f2f4_2 + $f3f3_2 + $f7f9_76 + $f8f8_19) << 1; + /** @var int $h7 */ + $h7 = (int) ($f0f7_2 + $f1f6_2 + $f2f5_2 + $f3f4_2 + $f8f9_38) << 1; + /** @var int $h8 */ + $h8 = (int) ($f0f8_2 + $f1f7_4 + $f2f6_2 + $f3f5_4 + $f4f4 + $f9f9_38) << 1; + /** @var int $h9 */ + $h9 = (int) ($f0f9_2 + $f1f8_2 + $f2f7_2 + $f3f6_2 + $f4f5_2) << 1; + + /** @var int $carry0 */ $carry0 = ($h0 + (1 << 25)) >> 26; $h1 += $carry0; $h0 -= $carry0 << 26; + /** @var int $carry4 */ $carry4 = ($h4 + (1 << 25)) >> 26; $h5 += $carry4; $h4 -= $carry4 << 26; + /** @var int $carry1 */ $carry1 = ($h1 + (1 << 24)) >> 25; $h2 += $carry1; $h1 -= $carry1 << 25; + /** @var int $carry5 */ $carry5 = ($h5 + (1 << 24)) >> 25; $h6 += $carry5; $h5 -= $carry5 << 25; + /** @var int $carry2 */ $carry2 = ($h2 + (1 << 25)) >> 26; $h3 += $carry2; $h2 -= $carry2 << 26; + /** @var int $carry6 */ $carry6 = ($h6 + (1 << 25)) >> 26; $h7 += $carry6; $h6 -= $carry6 << 26; + /** @var int $carry3 */ $carry3 = ($h3 + (1 << 24)) >> 25; $h4 += $carry3; $h3 -= $carry3 << 25; + /** @var int $carry7 */ $carry7 = ($h7 + (1 << 24)) >> 25; $h8 += $carry7; $h7 -= $carry7 << 25; + /** @var int $carry4 */ $carry4 = ($h4 + (1 << 25)) >> 26; $h5 += $carry4; $h4 -= $carry4 << 26; + /** @var int $carry8 */ $carry8 = ($h8 + (1 << 25)) >> 26; $h9 += $carry8; $h8 -= $carry8 << 26; + /** @var int $carry9 */ $carry9 = ($h9 + (1 << 24)) >> 25; $h0 += self::mul($carry9, 19, 5); $h9 -= $carry9 << 25; + /** @var int $carry0 */ $carry0 = ($h0 + (1 << 25)) >> 26; $h1 += $carry0; $h0 -= $carry0 << 26; @@ -1079,6 +1220,7 @@ public static function fe_pow22523(ParagonIE_Sodium_Core_Curve25519_Fe $z) * @param ParagonIE_Sodium_Core_Curve25519_Fe $f * @param ParagonIE_Sodium_Core_Curve25519_Fe $g * @return ParagonIE_Sodium_Core_Curve25519_Fe + * @psalm-suppress MixedOperand */ public static function fe_sub(ParagonIE_Sodium_Core_Curve25519_Fe $f, ParagonIE_Sodium_Core_Curve25519_Fe $g) { @@ -1134,6 +1276,8 @@ public static function ge_add( * @ref https://github.com/jedisct1/libsodium/blob/157c4a80c13b117608aeae12178b2d38825f9f8f/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c#L1185-L1215 * @param string $a * @return array + * @throws SodiumException + * @throws TypeError */ public static function slide($a) { @@ -1142,13 +1286,18 @@ public static function slide($a) $a = str_pad($a, 256, '0', STR_PAD_RIGHT); } } + /** @var array $r */ $r = array(); + + /** @var int $i */ for ($i = 0; $i < 256; ++$i) { - $r[$i] = 1 & ( - self::chrToInt($a[$i >> 3]) + $r[$i] = (int) ( + 1 & ( + self::chrToInt($a[(int) ($i >> 3)]) >> ($i & 7) - ); + ) + ); } for ($i = 0;$i < 256;++$i) { @@ -1182,6 +1331,8 @@ public static function slide($a) * * @param string $s * @return ParagonIE_Sodium_Core_Curve25519_Ge_P3 + * @throws SodiumException + * @throws TypeError */ public static function ge_frombytes_negate_vartime($s) { @@ -1203,6 +1354,7 @@ public static function ge_frombytes_negate_vartime($s) # fe_sub(u,u,h->Z); /* u = y^2-1 */ # fe_add(v,v,h->Z); /* v = dy^2+1 */ $u = self::fe_sq($h->Y); + /** @var ParagonIE_Sodium_Core_Curve25519_Fe $d */ $v = self::fe_mul($u, $d); $u = self::fe_sub($u, $h->Z); /* u = y^2 - 1 */ $v = self::fe_add($v, $h->Z); /* v = dy^2 + 1 */ @@ -1415,6 +1567,7 @@ public static function ge_p3_to_cached(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $p if ($d2 === null) { $d2 = ParagonIE_Sodium_Core_Curve25519_Fe::fromArray(self::$d2); } + /** @var ParagonIE_Sodium_Core_Curve25519_Fe $d2 */ $r = new ParagonIE_Sodium_Core_Curve25519_Ge_Cached(); $r->YplusX = self::fe_add($p->Y, $p->X); $r->YminusX = self::fe_sub($p->Y, $p->X); @@ -1443,6 +1596,8 @@ public static function ge_p3_to_p2(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $p) * * @param ParagonIE_Sodium_Core_Curve25519_Ge_P3 $h * @return string + * @throws SodiumException + * @throws TypeError */ public static function ge_p3_tobytes(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $h) { @@ -1489,14 +1644,16 @@ public static function ge_precomp_0() */ public static function equal($b, $c) { - return (($b ^ $c) - 1 & 0xffffffff) >> 31; + return (int) ((($b ^ $c) - 1 & 0xffffffff) >> 31); } /** * @internal You should not use this directly from another application * - * @param int $char + * @param int|string $char * @return int (1 = yes, 0 = no) + * @throws SodiumException + * @throws TypeError */ public static function negative($char) { @@ -1504,10 +1661,7 @@ public static function negative($char) return $char < 0 ? 1 : 0; } $x = self::chrToInt(self::substr($char, 0, 1)); - if (PHP_INT_SIZE === 8) { - return $x >> 63; - } - return $x >> 31; + return (int) ($x >> 63); } /** @@ -1541,12 +1695,18 @@ public static function cmov( * @param int $pos * @param int $b * @return ParagonIE_Sodium_Core_Curve25519_Ge_Precomp + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayOffset */ public static function ge_select($pos = 0, $b = 0) { static $base = null; if ($base === null) { $base = array(); + /** @var int $i */ foreach (self::$base as $i => $bas) { for ($j = 0; $j < 8; ++$j) { $base[$i][$j] = new ParagonIE_Sodium_Core_Curve25519_Ge_Precomp( @@ -1557,6 +1717,7 @@ public static function ge_select($pos = 0, $b = 0) } } } + /** @var array> $base */ if (!is_int($pos)) { throw new InvalidArgumentException('Position must be an integer'); } @@ -1564,7 +1725,9 @@ public static function ge_select($pos = 0, $b = 0) throw new RangeException('Position is out of range [0, 31]'); } + /** @var int $bnegative */ $bnegative = self::negative($b); + /** @var int $babs */ $babs = $b - (((-$bnegative) & $b) << 1); $t = self::ge_precomp_0(); @@ -1620,6 +1783,8 @@ public static function ge_sub( * * @param ParagonIE_Sodium_Core_Curve25519_Ge_P2 $h * @return string + * @throws SodiumException + * @throws TypeError */ public static function ge_tobytes(ParagonIE_Sodium_Core_Curve25519_Ge_P2 $h) { @@ -1640,20 +1805,20 @@ public static function ge_tobytes(ParagonIE_Sodium_Core_Curve25519_Ge_P2 $h) * @param ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A * @param string $b * @return ParagonIE_Sodium_Core_Curve25519_Ge_P2 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayAccess */ public static function ge_double_scalarmult_vartime( $a, ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A, $b ) { - /** - * @var ParagonIE_Sodium_Core_Curve25519_Ge_Cached[] - */ + /** @var array $Ai */ $Ai = array(); - /** - * @var ParagonIE_Sodium_Core_Curve25519_Ge_Precomp[] - */ + /** @var array $Bi */ static $Bi = array(); if (!$Bi) { for ($i = 0; $i < 8; ++$i) { @@ -1737,24 +1902,20 @@ public static function ge_double_scalarmult_vartime( # if (bslide[i] > 0) { if ($bslide[$i] > 0) { + /** @var int $index */ + $index = (int) floor($bslide[$i] / 2); # ge_p1p1_to_p3(&u,&t); # ge_madd(&t,&u,&Bi[bslide[i]/2]); $u = self::ge_p1p1_to_p3($t); - $t = self::ge_madd( - $t, - $u, - $Bi[(int) floor($bslide[$i] / 2)] - ); + $t = self::ge_madd($t, $u, $Bi[$index]); # } else if (bslide[i] < 0) { } elseif ($bslide[$i] < 0) { + /** @var int $index */ + $index = (int) floor(-$bslide[$i] / 2); # ge_p1p1_to_p3(&u,&t); # ge_msub(&t,&u,&Bi[(-bslide[i])/2]); $u = self::ge_p1p1_to_p3($t); - $t = self::ge_msub( - $t, - $u, - $Bi[(int) floor(-$bslide[$i] / 2)] - ); + $t = self::ge_msub($t, $u, $Bi[$index]); } # ge_p1p1_to_p2(r,&t); $r = self::ge_p1p1_to_p2($t); @@ -1767,30 +1928,41 @@ public static function ge_double_scalarmult_vartime( * * @param string $a * @return ParagonIE_Sodium_Core_Curve25519_Ge_P3 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedOperand */ public static function ge_scalarmult_base($a) { + /** @var array $e */ $e = array(); $r = new ParagonIE_Sodium_Core_Curve25519_Ge_P1p1(); for ($i = 0; $i < 32; ++$i) { - $e[$i << 1] = self::chrToInt($a[$i]) & 15; - $e[($i << 1) + 1] = (self::chrToInt($a[$i]) >> 4) & 15; + /** @var int $dbl */ + $dbl = (int) $i << 1; + $e[$dbl] = (int) self::chrToInt($a[$i]) & 15; + $e[$dbl + 1] = (int) (self::chrToInt($a[$i]) >> 4) & 15; } + /** @var int $carry */ $carry = 0; for ($i = 0; $i < 63; ++$i) { $e[$i] += $carry; + /** @var int $carry */ $carry = $e[$i] + 8; + /** @var int $carry */ $carry >>= 4; $e[$i] -= $carry << 4; } - $e[63] += $carry; + /** @var array $e */ + $e[63] += (int) $carry; $h = self::ge_p3_0(); for ($i = 1; $i < 64; $i += 2) { - $t = self::ge_select((int) floor($i / 2), $e[$i]); + $t = self::ge_select((int) floor($i / 2), (int) $e[$i]); $r = self::ge_madd($r, $h, $t); $h = self::ge_p1p1_to_p3($r); } @@ -1807,7 +1979,7 @@ public static function ge_scalarmult_base($a) $h = self::ge_p1p1_to_p3($r); for ($i = 0; $i < 64; $i += 2) { - $t = self::ge_select($i >> 1, $e[$i]); + $t = self::ge_select($i >> 1, (int) $e[$i]); $r = self::ge_madd($r, $h, $t); $h = self::ge_p1p1_to_p3($r); } @@ -1824,139 +1996,201 @@ public static function ge_scalarmult_base($a) * @param string $b * @param string $c * @return string + * @throws TypeError */ public static function sc_muladd($a, $b, $c) { + /** @var int $a0 */ $a0 = 2097151 & self::load_3(self::substr($a, 0, 3)); + /** @var int $a1 */ $a1 = 2097151 & (self::load_4(self::substr($a, 2, 4)) >> 5); + /** @var int $a2 */ $a2 = 2097151 & (self::load_3(self::substr($a, 5, 3)) >> 2); + /** @var int $a3 */ $a3 = 2097151 & (self::load_4(self::substr($a, 7, 4)) >> 7); + /** @var int $a4 */ $a4 = 2097151 & (self::load_4(self::substr($a, 10, 4)) >> 4); + /** @var int $a5 */ $a5 = 2097151 & (self::load_3(self::substr($a, 13, 3)) >> 1); + /** @var int $a6 */ $a6 = 2097151 & (self::load_4(self::substr($a, 15, 4)) >> 6); + /** @var int $a7 */ $a7 = 2097151 & (self::load_3(self::substr($a, 18, 3)) >> 3); + /** @var int $a8 */ $a8 = 2097151 & self::load_3(self::substr($a, 21, 3)); + /** @var int $a9 */ $a9 = 2097151 & (self::load_4(self::substr($a, 23, 4)) >> 5); + /** @var int $a10 */ $a10 = 2097151 & (self::load_3(self::substr($a, 26, 3)) >> 2); + /** @var int $a11 */ $a11 = (self::load_4(self::substr($a, 28, 4)) >> 7); + + /** @var int $b0 */ $b0 = 2097151 & self::load_3(self::substr($b, 0, 3)); + /** @var int $b1 */ $b1 = 2097151 & (self::load_4(self::substr($b, 2, 4)) >> 5); + /** @var int $b2 */ $b2 = 2097151 & (self::load_3(self::substr($b, 5, 3)) >> 2); + /** @var int $b3 */ $b3 = 2097151 & (self::load_4(self::substr($b, 7, 4)) >> 7); + /** @var int $b4 */ $b4 = 2097151 & (self::load_4(self::substr($b, 10, 4)) >> 4); + /** @var int $b5 */ $b5 = 2097151 & (self::load_3(self::substr($b, 13, 3)) >> 1); + /** @var int $b6 */ $b6 = 2097151 & (self::load_4(self::substr($b, 15, 4)) >> 6); + /** @var int $b7 */ $b7 = 2097151 & (self::load_3(self::substr($b, 18, 3)) >> 3); + /** @var int $b8 */ $b8 = 2097151 & self::load_3(self::substr($b, 21, 3)); + /** @var int $b9 */ $b9 = 2097151 & (self::load_4(self::substr($b, 23, 4)) >> 5); + /** @var int $b10 */ $b10 = 2097151 & (self::load_3(self::substr($b, 26, 3)) >> 2); + /** @var int $b11 */ $b11 = (self::load_4(self::substr($b, 28, 4)) >> 7); + + /** @var int $c0 */ $c0 = 2097151 & self::load_3(self::substr($c, 0, 3)); + /** @var int $c1 */ $c1 = 2097151 & (self::load_4(self::substr($c, 2, 4)) >> 5); + /** @var int $c2 */ $c2 = 2097151 & (self::load_3(self::substr($c, 5, 3)) >> 2); + /** @var int $c3 */ $c3 = 2097151 & (self::load_4(self::substr($c, 7, 4)) >> 7); + /** @var int $c4 */ $c4 = 2097151 & (self::load_4(self::substr($c, 10, 4)) >> 4); + /** @var int $c5 */ $c5 = 2097151 & (self::load_3(self::substr($c, 13, 3)) >> 1); + /** @var int $c6 */ $c6 = 2097151 & (self::load_4(self::substr($c, 15, 4)) >> 6); + /** @var int $c7 */ $c7 = 2097151 & (self::load_3(self::substr($c, 18, 3)) >> 3); + /** @var int $c8 */ $c8 = 2097151 & self::load_3(self::substr($c, 21, 3)); + /** @var int $c9 */ $c9 = 2097151 & (self::load_4(self::substr($c, 23, 4)) >> 5); + /** @var int $c10 */ $c10 = 2097151 & (self::load_3(self::substr($c, 26, 3)) >> 2); + /** @var int $c11 */ $c11 = (self::load_4(self::substr($c, 28, 4)) >> 7); /* Can't really avoid the pyramid here: */ - $s0 = $c0 + self::mul($a0, $b0); - $s1 = $c1 + self::mul($a0, $b1) + self::mul($a1, $b0); - $s2 = $c2 + self::mul($a0, $b2) + self::mul($a1, $b1) + self::mul($a2, $b0); - $s3 = $c3 + self::mul($a0, $b3) + self::mul($a1, $b2) + self::mul($a2, $b1) + self::mul($a3, $b0); - $s4 = $c4 + self::mul($a0, $b4) + self::mul($a1, $b3) + self::mul($a2, $b2) + self::mul($a3, $b1) + self::mul($a4, $b0); - $s5 = $c5 + self::mul($a0, $b5) + self::mul($a1, $b4) + self::mul($a2, $b3) + self::mul($a3, $b2) + self::mul($a4, $b1) + self::mul($a5, $b0); - $s6 = $c6 + self::mul($a0, $b6) + self::mul($a1, $b5) + self::mul($a2, $b4) + self::mul($a3, $b3) + self::mul($a4, $b2) + self::mul($a5, $b1) + self::mul($a6, $b0); - $s7 = $c7 + self::mul($a0, $b7) + self::mul($a1, $b6) + self::mul($a2, $b5) + self::mul($a3, $b4) + self::mul($a4, $b3) + self::mul($a5, $b2) + self::mul($a6, $b1) + self::mul($a7, $b0); - $s8 = $c8 + self::mul($a0, $b8) + self::mul($a1, $b7) + self::mul($a2, $b6) + self::mul($a3, $b5) + self::mul($a4, $b4) + self::mul($a5, $b3) + self::mul($a6, $b2) + self::mul($a7, $b1) + self::mul($a8, $b0); - $s9 = $c9 + self::mul($a0, $b9) + self::mul($a1, $b8) + self::mul($a2, $b7) + self::mul($a3, $b6) + self::mul($a4, $b5) + self::mul($a5, $b4) + self::mul($a6, $b3) + self::mul($a7, $b2) + self::mul($a8, $b1) + self::mul($a9, $b0); - $s10 = $c10 + self::mul($a0, $b10) + self::mul($a1, $b9) + self::mul($a2, $b8) + self::mul($a3, $b7) + self::mul($a4, $b6) + self::mul($a5, $b5) + self::mul($a6, $b4) + self::mul($a7, $b3) + self::mul($a8, $b2) + self::mul($a9, $b1) + self::mul($a10, $b0); - $s11 = $c11 + self::mul($a0, $b11) + self::mul($a1, $b10) + self::mul($a2, $b9) + self::mul($a3, $b8) + self::mul($a4, $b7) + self::mul($a5, $b6) + self::mul($a6, $b5) + self::mul($a7, $b4) + self::mul($a8, $b3) + self::mul($a9, $b2) + self::mul($a10, $b1) + self::mul($a11, $b0); - $s12 = self::mul($a1, $b11) + self::mul($a2, $b10) + self::mul($a3, $b9) + self::mul($a4, $b8) + self::mul($a5, $b7) + self::mul($a6, $b6) + self::mul($a7, $b5) + self::mul($a8, $b4) + self::mul($a9, $b3) + self::mul($a10, $b2) + self::mul($a11, $b1); - $s13 = self::mul($a2, $b11) + self::mul($a3, $b10) + self::mul($a4, $b9) + self::mul($a5, $b8) + self::mul($a6, $b7) + self::mul($a7, $b6) + self::mul($a8, $b5) + self::mul($a9, $b4) + self::mul($a10, $b3) + self::mul($a11, $b2); - $s14 = self::mul($a3, $b11) + self::mul($a4, $b10) + self::mul($a5, $b9) + self::mul($a6, $b8) + self::mul($a7, $b7) + self::mul($a8, $b6) + self::mul($a9, $b5) + self::mul($a10, $b4) + self::mul($a11, $b3); - $s15 = self::mul($a4, $b11) + self::mul($a5, $b10) + self::mul($a6, $b9) + self::mul($a7, $b8) + self::mul($a8, $b7) + self::mul($a9, $b6) + self::mul($a10, $b5) + self::mul($a11, $b4); - $s16 = self::mul($a5, $b11) + self::mul($a6, $b10) + self::mul($a7, $b9) + self::mul($a8, $b8) + self::mul($a9, $b7) + self::mul($a10, $b6) + self::mul($a11, $b5); - $s17 = self::mul($a6, $b11) + self::mul($a7, $b10) + self::mul($a8, $b9) + self::mul($a9, $b8) + self::mul($a10, $b7) + self::mul($a11, $b6); - $s18 = self::mul($a7, $b11) + self::mul($a8, $b10) + self::mul($a9, $b9) + self::mul($a10, $b8) + self::mul($a11, $b7); - $s19 = self::mul($a8, $b11) + self::mul($a9, $b10) + self::mul($a10, $b9) + self::mul($a11, $b8); - $s20 = self::mul($a9, $b11) + self::mul($a10, $b10) + self::mul($a11, $b9); - $s21 = self::mul($a10, $b11) + self::mul($a11, $b10); - $s22 = self::mul($a11, $b11); + $s0 = $c0 + self::mul($a0, $b0, 24); + $s1 = $c1 + self::mul($a0, $b1, 24) + self::mul($a1, $b0, 24); + $s2 = $c2 + self::mul($a0, $b2, 24) + self::mul($a1, $b1, 24) + self::mul($a2, $b0, 24); + $s3 = $c3 + self::mul($a0, $b3, 24) + self::mul($a1, $b2, 24) + self::mul($a2, $b1, 24) + self::mul($a3, $b0, 24); + $s4 = $c4 + self::mul($a0, $b4, 24) + self::mul($a1, $b3, 24) + self::mul($a2, $b2, 24) + self::mul($a3, $b1, 24) + self::mul($a4, $b0, 24); + $s5 = $c5 + self::mul($a0, $b5, 24) + self::mul($a1, $b4, 24) + self::mul($a2, $b3, 24) + self::mul($a3, $b2, 24) + self::mul($a4, $b1, 24) + self::mul($a5, $b0, 24); + $s6 = $c6 + self::mul($a0, $b6, 24) + self::mul($a1, $b5, 24) + self::mul($a2, $b4, 24) + self::mul($a3, $b3, 24) + self::mul($a4, $b2, 24) + self::mul($a5, $b1, 24) + self::mul($a6, $b0, 24); + $s7 = $c7 + self::mul($a0, $b7, 24) + self::mul($a1, $b6, 24) + self::mul($a2, $b5, 24) + self::mul($a3, $b4, 24) + self::mul($a4, $b3, 24) + self::mul($a5, $b2, 24) + self::mul($a6, $b1, 24) + self::mul($a7, $b0, 24); + $s8 = $c8 + self::mul($a0, $b8, 24) + self::mul($a1, $b7, 24) + self::mul($a2, $b6, 24) + self::mul($a3, $b5, 24) + self::mul($a4, $b4, 24) + self::mul($a5, $b3, 24) + self::mul($a6, $b2, 24) + self::mul($a7, $b1, 24) + self::mul($a8, $b0, 24); + $s9 = $c9 + self::mul($a0, $b9, 24) + self::mul($a1, $b8, 24) + self::mul($a2, $b7, 24) + self::mul($a3, $b6, 24) + self::mul($a4, $b5, 24) + self::mul($a5, $b4, 24) + self::mul($a6, $b3, 24) + self::mul($a7, $b2, 24) + self::mul($a8, $b1, 24) + self::mul($a9, $b0, 24); + $s10 = $c10 + self::mul($a0, $b10, 24) + self::mul($a1, $b9, 24) + self::mul($a2, $b8, 24) + self::mul($a3, $b7, 24) + self::mul($a4, $b6, 24) + self::mul($a5, $b5, 24) + self::mul($a6, $b4, 24) + self::mul($a7, $b3, 24) + self::mul($a8, $b2, 24) + self::mul($a9, $b1, 24) + self::mul($a10, $b0, 24); + $s11 = $c11 + self::mul($a0, $b11, 24) + self::mul($a1, $b10, 24) + self::mul($a2, $b9, 24) + self::mul($a3, $b8, 24) + self::mul($a4, $b7, 24) + self::mul($a5, $b6, 24) + self::mul($a6, $b5, 24) + self::mul($a7, $b4, 24) + self::mul($a8, $b3, 24) + self::mul($a9, $b2, 24) + self::mul($a10, $b1, 24) + self::mul($a11, $b0, 24); + $s12 = self::mul($a1, $b11, 24) + self::mul($a2, $b10, 24) + self::mul($a3, $b9, 24) + self::mul($a4, $b8, 24) + self::mul($a5, $b7, 24) + self::mul($a6, $b6, 24) + self::mul($a7, $b5, 24) + self::mul($a8, $b4, 24) + self::mul($a9, $b3, 24) + self::mul($a10, $b2, 24) + self::mul($a11, $b1, 24); + $s13 = self::mul($a2, $b11, 24) + self::mul($a3, $b10, 24) + self::mul($a4, $b9, 24) + self::mul($a5, $b8, 24) + self::mul($a6, $b7, 24) + self::mul($a7, $b6, 24) + self::mul($a8, $b5, 24) + self::mul($a9, $b4, 24) + self::mul($a10, $b3, 24) + self::mul($a11, $b2, 24); + $s14 = self::mul($a3, $b11, 24) + self::mul($a4, $b10, 24) + self::mul($a5, $b9, 24) + self::mul($a6, $b8, 24) + self::mul($a7, $b7, 24) + self::mul($a8, $b6, 24) + self::mul($a9, $b5, 24) + self::mul($a10, $b4, 24) + self::mul($a11, $b3, 24); + $s15 = self::mul($a4, $b11, 24) + self::mul($a5, $b10, 24) + self::mul($a6, $b9, 24) + self::mul($a7, $b8, 24) + self::mul($a8, $b7, 24) + self::mul($a9, $b6, 24) + self::mul($a10, $b5, 24) + self::mul($a11, $b4, 24); + $s16 = self::mul($a5, $b11, 24) + self::mul($a6, $b10, 24) + self::mul($a7, $b9, 24) + self::mul($a8, $b8, 24) + self::mul($a9, $b7, 24) + self::mul($a10, $b6, 24) + self::mul($a11, $b5, 24); + $s17 = self::mul($a6, $b11, 24) + self::mul($a7, $b10, 24) + self::mul($a8, $b9, 24) + self::mul($a9, $b8, 24) + self::mul($a10, $b7, 24) + self::mul($a11, $b6, 24); + $s18 = self::mul($a7, $b11, 24) + self::mul($a8, $b10, 24) + self::mul($a9, $b9, 24) + self::mul($a10, $b8, 24) + self::mul($a11, $b7, 24); + $s19 = self::mul($a8, $b11, 24) + self::mul($a9, $b10, 24) + self::mul($a10, $b9, 24) + self::mul($a11, $b8, 24); + $s20 = self::mul($a9, $b11, 24) + self::mul($a10, $b10, 24) + self::mul($a11, $b9, 24); + $s21 = self::mul($a10, $b11, 24) + self::mul($a11, $b10, 24); + $s22 = self::mul($a11, $b11, 24); $s23 = 0; + /** @var int $carry0 */ $carry0 = ($s0 + (1 << 20)) >> 21; $s1 += $carry0; $s0 -= $carry0 << 21; + /** @var int $carry2 */ $carry2 = ($s2 + (1 << 20)) >> 21; $s3 += $carry2; $s2 -= $carry2 << 21; + /** @var int $carry4 */ $carry4 = ($s4 + (1 << 20)) >> 21; $s5 += $carry4; $s4 -= $carry4 << 21; + /** @var int $carry6 */ $carry6 = ($s6 + (1 << 20)) >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry8 */ $carry8 = ($s8 + (1 << 20)) >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry10 */ $carry10 = ($s10 + (1 << 20)) >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; + /** @var int $carry12 */ $carry12 = ($s12 + (1 << 20)) >> 21; $s13 += $carry12; $s12 -= $carry12 << 21; + /** @var int $carry14 */ $carry14 = ($s14 + (1 << 20)) >> 21; $s15 += $carry14; $s14 -= $carry14 << 21; + /** @var int $carry16 */ $carry16 = ($s16 + (1 << 20)) >> 21; $s17 += $carry16; $s16 -= $carry16 << 21; + /** @var int $carry18 */ $carry18 = ($s18 + (1 << 20)) >> 21; $s19 += $carry18; $s18 -= $carry18 << 21; + /** @var int $carry20 */ $carry20 = ($s20 + (1 << 20)) >> 21; $s21 += $carry20; $s20 -= $carry20 << 21; + /** @var int $carry22 */ $carry22 = ($s22 + (1 << 20)) >> 21; $s23 += $carry22; $s22 -= $carry22 << 21; + /** @var int $carry1 */ $carry1 = ($s1 + (1 << 20)) >> 21; $s2 += $carry1; $s1 -= $carry1 << 21; + /** @var int $carry3 */ $carry3 = ($s3 + (1 << 20)) >> 21; $s4 += $carry3; $s3 -= $carry3 << 21; + /** @var int $carry5 */ $carry5 = ($s5 + (1 << 20)) >> 21; $s6 += $carry5; $s5 -= $carry5 << 21; + /** @var int $carry7 */ $carry7 = ($s7 + (1 << 20)) >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry9 */ $carry9 = ($s9 + (1 << 20)) >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry11 */ $carry11 = ($s11 + (1 << 20)) >> 21; $s12 += $carry11; $s11 -= $carry11 << 21; + /** @var int $carry13 */ $carry13 = ($s13 + (1 << 20)) >> 21; $s14 += $carry13; $s13 -= $carry13 << 21; + /** @var int $carry15 */ $carry15 = ($s15 + (1 << 20)) >> 21; $s16 += $carry15; $s15 -= $carry15 << 21; + /** @var int $carry17 */ $carry17 = ($s17 + (1 << 20)) >> 21; $s18 += $carry17; $s17 -= $carry17 << 21; + /** @var int $carry19 */ $carry19 = ($s19 + (1 << 20)) >> 21; $s20 += $carry19; $s19 -= $carry19 << 21; + /** @var int $carry21 */ $carry21 = ($s21 + (1 << 20)) >> 21; $s22 += $carry21; $s21 -= $carry21 << 21; @@ -2003,37 +2237,48 @@ public static function sc_muladd($a, $b, $c) $s10 += self::mul($s18, 136657, 18); $s11 -= self::mul($s18, 683901, 20); + /** @var int $carry6 */ $carry6 = ($s6 + (1 << 20)) >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry8 */ $carry8 = ($s8 + (1 << 20)) >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry10 */ $carry10 = ($s10 + (1 << 20)) >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; + /** @var int $carry12 */ $carry12 = ($s12 + (1 << 20)) >> 21; $s13 += $carry12; $s12 -= $carry12 << 21; + /** @var int $carry14 */ $carry14 = ($s14 + (1 << 20)) >> 21; $s15 += $carry14; $s14 -= $carry14 << 21; + /** @var int $carry16 */ $carry16 = ($s16 + (1 << 20)) >> 21; $s17 += $carry16; $s16 -= $carry16 << 21; + /** @var int $carry7 */ $carry7 = ($s7 + (1 << 20)) >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry9 */ $carry9 = ($s9 + (1 << 20)) >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry11 */ $carry11 = ($s11 + (1 << 20)) >> 21; $s12 += $carry11; $s11 -= $carry11 << 21; + /** @var int $carry13 */ $carry13 = ($s13 + (1 << 20)) >> 21; $s14 += $carry13; $s13 -= $carry13 << 21; + /** @var int $carry15 */ $carry15 = ($s15 + (1 << 20)) >> 21; $s16 += $carry15; $s15 -= $carry15 << 21; @@ -2081,40 +2326,52 @@ public static function sc_muladd($a, $b, $c) $s5 -= self::mul($s12, 683901, 20); $s12 = 0; + /** @var int $carry0 */ $carry0 = ($s0 + (1 << 20)) >> 21; $s1 += $carry0; $s0 -= $carry0 << 21; + /** @var int $carry2 */ $carry2 = ($s2 + (1 << 20)) >> 21; $s3 += $carry2; $s2 -= $carry2 << 21; + /** @var int $carry4 */ $carry4 = ($s4 + (1 << 20)) >> 21; $s5 += $carry4; $s4 -= $carry4 << 21; + /** @var int $carry6 */ $carry6 = ($s6 + (1 << 20)) >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry8 */ $carry8 = ($s8 + (1 << 20)) >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry10 */ $carry10 = ($s10 + (1 << 20)) >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; + /** @var int $carry1 */ $carry1 = ($s1 + (1 << 20)) >> 21; $s2 += $carry1; $s1 -= $carry1 << 21; + /** @var int $carry3 */ $carry3 = ($s3 + (1 << 20)) >> 21; $s4 += $carry3; $s3 -= $carry3 << 21; + /** @var int $carry5 */ $carry5 = ($s5 + (1 << 20)) >> 21; $s6 += $carry5; $s5 -= $carry5 << 21; + /** @var int $carry7 */ $carry7 = ($s7 + (1 << 20)) >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry9 */ $carry9 = ($s9 + (1 << 20)) >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry11 */ $carry11 = ($s11 + (1 << 20)) >> 21; $s12 += $carry11; $s11 -= $carry11 << 21; @@ -2127,39 +2384,51 @@ public static function sc_muladd($a, $b, $c) $s5 -= self::mul($s12, 683901, 20); $s12 = 0; + /** @var int $carry0 */ $carry0 = $s0 >> 21; $s1 += $carry0; $s0 -= $carry0 << 21; + /** @var int $carry1 */ $carry1 = $s1 >> 21; $s2 += $carry1; $s1 -= $carry1 << 21; + /** @var int $carry2 */ $carry2 = $s2 >> 21; $s3 += $carry2; $s2 -= $carry2 << 21; + /** @var int $carry3 */ $carry3 = $s3 >> 21; $s4 += $carry3; $s3 -= $carry3 << 21; + /** @var int $carry4 */ $carry4 = $s4 >> 21; $s5 += $carry4; $s4 -= $carry4 << 21; + /** @var int $carry5 */ $carry5 = $s5 >> 21; $s6 += $carry5; $s5 -= $carry5 << 21; + /** @var int $carry6 */ $carry6 = $s6 >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry7 */ $carry7 = $s7 >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry8 */ $carry8 = $s8 >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry9 */ $carry9 = $s9 >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry10 */ $carry10 = $s10 >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; + /** @var int $carry11 */ $carry11 = $s11 >> 21; $s12 += $carry11; $s11 -= $carry11 << 21; @@ -2171,36 +2440,47 @@ public static function sc_muladd($a, $b, $c) $s4 += self::mul($s12, 136657, 18); $s5 -= self::mul($s12, 683901, 20); + /** @var int $carry0 */ $carry0 = $s0 >> 21; $s1 += $carry0; $s0 -= $carry0 << 21; + /** @var int $carry1 */ $carry1 = $s1 >> 21; $s2 += $carry1; $s1 -= $carry1 << 21; + /** @var int $carry2 */ $carry2 = $s2 >> 21; $s3 += $carry2; $s2 -= $carry2 << 21; + /** @var int $carry3 */ $carry3 = $s3 >> 21; $s4 += $carry3; $s3 -= $carry3 << 21; + /** @var int $carry4 */ $carry4 = $s4 >> 21; $s5 += $carry4; $s4 -= $carry4 << 21; + /** @var int $carry5 */ $carry5 = $s5 >> 21; $s6 += $carry5; $s5 -= $carry5 << 21; + /** @var int $carry6 */ $carry6 = $s6 >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry7 */ $carry7 = $s7 >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry8 */ $carry8 = $s8 >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry9 */ $carry9 = $s9 >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry10 */ $carry10 = $s10 >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; @@ -2250,32 +2530,57 @@ public static function sc_muladd($a, $b, $c) * * @param string $s * @return string + * @throws TypeError */ public static function sc_reduce($s) { + /** @var int $s0 */ $s0 = 2097151 & self::load_3(self::substr($s, 0, 3)); + /** @var int $s1 */ $s1 = 2097151 & (self::load_4(self::substr($s, 2, 4)) >> 5); + /** @var int $s2 */ $s2 = 2097151 & (self::load_3(self::substr($s, 5, 3)) >> 2); + /** @var int $s3 */ $s3 = 2097151 & (self::load_4(self::substr($s, 7, 4)) >> 7); + /** @var int $s4 */ $s4 = 2097151 & (self::load_4(self::substr($s, 10, 4)) >> 4); + /** @var int $s5 */ $s5 = 2097151 & (self::load_3(self::substr($s, 13, 3)) >> 1); + /** @var int $s6 */ $s6 = 2097151 & (self::load_4(self::substr($s, 15, 4)) >> 6); + /** @var int $s7 */ $s7 = 2097151 & (self::load_3(self::substr($s, 18, 4)) >> 3); + /** @var int $s8 */ $s8 = 2097151 & self::load_3(self::substr($s, 21, 3)); + /** @var int $s9 */ $s9 = 2097151 & (self::load_4(self::substr($s, 23, 4)) >> 5); + /** @var int $s10 */ $s10 = 2097151 & (self::load_3(self::substr($s, 26, 3)) >> 2); + /** @var int $s11 */ $s11 = 2097151 & (self::load_4(self::substr($s, 28, 4)) >> 7); + /** @var int $s12 */ $s12 = 2097151 & (self::load_4(self::substr($s, 31, 4)) >> 4); + /** @var int $s13 */ $s13 = 2097151 & (self::load_3(self::substr($s, 34, 3)) >> 1); + /** @var int $s14 */ $s14 = 2097151 & (self::load_4(self::substr($s, 36, 4)) >> 6); + /** @var int $s15 */ $s15 = 2097151 & (self::load_3(self::substr($s, 39, 4)) >> 3); + /** @var int $s16 */ $s16 = 2097151 & self::load_3(self::substr($s, 42, 3)); + /** @var int $s17 */ $s17 = 2097151 & (self::load_4(self::substr($s, 44, 4)) >> 5); + /** @var int $s18 */ $s18 = 2097151 & (self::load_3(self::substr($s, 47, 3)) >> 2); + /** @var int $s19 */ $s19 = 2097151 & (self::load_4(self::substr($s, 49, 4)) >> 7); + /** @var int $s20 */ $s20 = 2097151 & (self::load_4(self::substr($s, 52, 4)) >> 4); + /** @var int $s21 */ $s21 = 2097151 & (self::load_3(self::substr($s, 55, 3)) >> 1); + /** @var int $s22 */ $s22 = 2097151 & (self::load_4(self::substr($s, 57, 4)) >> 6); + /** @var int $s23 */ $s23 = (self::load_4(self::substr($s, 60, 4)) >> 3); $s11 += self::mul($s23, 666643, 20); @@ -2320,37 +2625,48 @@ public static function sc_reduce($s) $s10 += self::mul($s18, 136657, 18); $s11 -= self::mul($s18, 683901, 20); + /** @var int $carry6 */ $carry6 = ($s6 + (1 << 20)) >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry8 */ $carry8 = ($s8 + (1 << 20)) >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry10 */ $carry10 = ($s10 + (1 << 20)) >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; + /** @var int $carry12 */ $carry12 = ($s12 + (1 << 20)) >> 21; $s13 += $carry12; $s12 -= $carry12 << 21; + /** @var int $carry14 */ $carry14 = ($s14 + (1 << 20)) >> 21; $s15 += $carry14; $s14 -= $carry14 << 21; + /** @var int $carry16 */ $carry16 = ($s16 + (1 << 20)) >> 21; $s17 += $carry16; $s16 -= $carry16 << 21; + /** @var int $carry7 */ $carry7 = ($s7 + (1 << 20)) >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry9 */ $carry9 = ($s9 + (1 << 20)) >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry11 */ $carry11 = ($s11 + (1 << 20)) >> 21; $s12 += $carry11; $s11 -= $carry11 << 21; + /** @var int $carry13 */ $carry13 = ($s13 + (1 << 20)) >> 21; $s14 += $carry13; $s13 -= $carry13 << 21; + /** @var int $carry15 */ $carry15 = ($s15 + (1 << 20)) >> 21; $s16 += $carry15; $s15 -= $carry15 << 21; @@ -2398,40 +2714,52 @@ public static function sc_reduce($s) $s5 -= self::mul($s12, 683901, 20); $s12 = 0; + /** @var int $carry0 */ $carry0 = ($s0 + (1 << 20)) >> 21; $s1 += $carry0; $s0 -= $carry0 << 21; + /** @var int $carry2 */ $carry2 = ($s2 + (1 << 20)) >> 21; $s3 += $carry2; $s2 -= $carry2 << 21; + /** @var int $carry4 */ $carry4 = ($s4 + (1 << 20)) >> 21; $s5 += $carry4; $s4 -= $carry4 << 21; + /** @var int $carry6 */ $carry6 = ($s6 + (1 << 20)) >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry8 */ $carry8 = ($s8 + (1 << 20)) >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry10 */ $carry10 = ($s10 + (1 << 20)) >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; + /** @var int $carry1 */ $carry1 = ($s1 + (1 << 20)) >> 21; $s2 += $carry1; $s1 -= $carry1 << 21; + /** @var int $carry3 */ $carry3 = ($s3 + (1 << 20)) >> 21; $s4 += $carry3; $s3 -= $carry3 << 21; + /** @var int $carry5 */ $carry5 = ($s5 + (1 << 20)) >> 21; $s6 += $carry5; $s5 -= $carry5 << 21; + /** @var int $carry7 */ $carry7 = ($s7 + (1 << 20)) >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry9 */ $carry9 = ($s9 + (1 << 20)) >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry11 */ $carry11 = ($s11 + (1 << 20)) >> 21; $s12 += $carry11; $s11 -= $carry11 << 21; @@ -2444,39 +2772,51 @@ public static function sc_reduce($s) $s5 -= self::mul($s12, 683901, 20); $s12 = 0; + /** @var int $carry0 */ $carry0 = $s0 >> 21; $s1 += $carry0; $s0 -= $carry0 << 21; + /** @var int $carry1 */ $carry1 = $s1 >> 21; $s2 += $carry1; $s1 -= $carry1 << 21; + /** @var int $carry2 */ $carry2 = $s2 >> 21; $s3 += $carry2; $s2 -= $carry2 << 21; + /** @var int $carry3 */ $carry3 = $s3 >> 21; $s4 += $carry3; $s3 -= $carry3 << 21; + /** @var int $carry4 */ $carry4 = $s4 >> 21; $s5 += $carry4; $s4 -= $carry4 << 21; + /** @var int $carry5 */ $carry5 = $s5 >> 21; $s6 += $carry5; $s5 -= $carry5 << 21; + /** @var int $carry6 */ $carry6 = $s6 >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry7 */ $carry7 = $s7 >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry8 */ $carry8 = $s8 >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry9 */ $carry9 = $s9 >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry10 */ $carry10 = $s10 >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; + /** @var int $carry11 */ $carry11 = $s11 >> 21; $s12 += $carry11; $s11 -= $carry11 << 21; @@ -2488,36 +2828,47 @@ public static function sc_reduce($s) $s4 += self::mul($s12, 136657, 18); $s5 -= self::mul($s12, 683901, 20); + /** @var int $carry0 */ $carry0 = $s0 >> 21; $s1 += $carry0; $s0 -= $carry0 << 21; + /** @var int $carry1 */ $carry1 = $s1 >> 21; $s2 += $carry1; $s1 -= $carry1 << 21; + /** @var int $carry2 */ $carry2 = $s2 >> 21; $s3 += $carry2; $s2 -= $carry2 << 21; + /** @var int $carry3 */ $carry3 = $s3 >> 21; $s4 += $carry3; $s3 -= $carry3 << 21; + /** @var int $carry4 */ $carry4 = $s4 >> 21; $s5 += $carry4; $s4 -= $carry4 << 21; + /** @var int $carry5 */ $carry5 = $s5 >> 21; $s6 += $carry5; $s5 -= $carry5 << 21; + /** @var int $carry6 */ $carry6 = $s6 >> 21; $s7 += $carry6; $s6 -= $carry6 << 21; + /** @var int $carry7 */ $carry7 = $s7 >> 21; $s8 += $carry7; $s7 -= $carry7 << 21; + /** @var int $carry8 */ $carry8 = $s8 >> 21; $s9 += $carry8; $s8 -= $carry8 << 21; + /** @var int $carry9 */ $carry9 = $s9 >> 21; $s10 += $carry9; $s9 -= $carry9 << 21; + /** @var int $carry10 */ $carry10 = $s10 >> 21; $s11 += $carry10; $s10 -= $carry10 << 21; @@ -2561,4 +2912,67 @@ public static function sc_reduce($s) ); return self::intArrayToString($arr); } + + /** + * multiply by the order of the main subgroup l = 2^252+27742317777372353535851937790883648493 + * + * @param ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A + * @return ParagonIE_Sodium_Core_Curve25519_Ge_P3 + */ + public static function ge_mul_l(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A) + { + /** @var array $aslide */ + $aslide = array( + 13, 0, 0, 0, 0, -1, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, + 0, 0, 0, -3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 3, 0, + 0, 0, 0, -13, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, + 0, 0, 11, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, -1, + 0, 0, 0, 0, 3, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, + 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 5, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 + ); + + /** @var array $Ai size 8 */ + $Ai = array(); + + # ge_p3_to_cached(&Ai[0], A); + $Ai[0] = self::ge_p3_to_cached($A); + # ge_p3_dbl(&t, A); + $t = self::ge_p3_dbl($A); + # ge_p1p1_to_p3(&A2, &t); + $A2 = self::ge_p1p1_to_p3($t); + + for ($i = 1; $i < 8; ++$i) { + # ge_add(&t, &A2, &Ai[0]); + $t = self::ge_add($A2, $Ai[$i - 1]); + # ge_p1p1_to_p3(&u, &t); + $u = self::ge_p1p1_to_p3($t); + # ge_p3_to_cached(&Ai[i], &u); + $Ai[$i] = self::ge_p3_to_cached($u); + } + + $r = self::ge_p3_0(); + for ($i = 252; $i >= 0; --$i) { + $t = self::ge_p3_dbl($r); + if ($aslide[$i] > 0) { + # ge_p1p1_to_p3(&u, &t); + $u = self::ge_p1p1_to_p3($t); + # ge_add(&t, &u, &Ai[aslide[i] / 2]); + $t = self::ge_add($u, $Ai[(int)($aslide[$i] / 2)]); + } elseif ($aslide[$i] < 0) { + # ge_p1p1_to_p3(&u, &t); + $u = self::ge_p1p1_to_p3($t); + # ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]); + $t = self::ge_sub($u, $Ai[(int)(-$aslide[$i] / 2)]); + } + } + + # ge_p1p1_to_p3(r, &t); + return self::ge_p1p1_to_p3($t); + } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/Fe.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/Fe.php index fb66315f00f77..5cb711844976d 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/Fe.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/Fe.php @@ -66,6 +66,7 @@ public static function fromArray($array, $save_indexes = null) * @param mixed $offset * @param mixed $value * @return void + * @psalm-suppress MixedArrayOffset */ public function offsetSet($offset, $value) { @@ -84,6 +85,7 @@ public function offsetSet($offset, $value) * * @param mixed $offset * @return bool + * @psalm-suppress MixedArrayOffset */ public function offsetExists($offset) { @@ -95,6 +97,7 @@ public function offsetExists($offset) * * @param mixed $offset * @return void + * @psalm-suppress MixedArrayOffset */ public function offsetUnset($offset) { @@ -106,6 +109,7 @@ public function offsetUnset($offset) * * @param mixed $offset * @return mixed|null + * @psalm-suppress MixedArrayOffset */ public function offsetGet($offset) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/H.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/H.php index c371be50255d7..37ad497dc38d6 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/H.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Curve25519/H.php @@ -14,7 +14,7 @@ class ParagonIE_Sodium_Core_Curve25519_H extends ParagonIE_Sodium_Core_Util /** * See: libsodium's crypto_core/curve25519/ref10/base.h * - * @var array Basically, int[32][8][3][10] + * @var array>>> Basically, int[32][8][3][10] */ protected static $base = array( array( @@ -1414,7 +1414,7 @@ class ParagonIE_Sodium_Core_Curve25519_H extends ParagonIE_Sodium_Core_Util /** * 37095705934669439343138083508754565189542113879843219016388785533085940283555 * - * @var int[] + * @var array */ protected static $d = array( -10913610, @@ -1432,7 +1432,7 @@ class ParagonIE_Sodium_Core_Curve25519_H extends ParagonIE_Sodium_Core_Util /** * 2 * d = 16295367250680780974490674513165176452449235426866156013048779062215315747161 * - * @var int[] + * @var array */ protected static $d2 = array( -21827239, @@ -1450,7 +1450,7 @@ class ParagonIE_Sodium_Core_Curve25519_H extends ParagonIE_Sodium_Core_Util /** * sqrt(-1) * - * @var int[] + * @var array */ protected static $sqrtm1 = array( -32595792, diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Ed25519.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Ed25519.php index 40805a12cb4c6..4514dc8a32371 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Ed25519.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Ed25519.php @@ -16,6 +16,8 @@ abstract class ParagonIE_Sodium_Core_Ed25519 extends ParagonIE_Sodium_Core_Curve * @internal You should not use this directly from another application * * @return string (96 bytes) + * @throws SodiumException + * @throws TypeError */ public static function keypair() { @@ -33,6 +35,8 @@ public static function keypair() * @param string $sk * @param string $seed * @return string + * @throws SodiumException + * @throws TypeError */ public static function seed_keypair(&$pk, &$sk, $seed) { @@ -51,6 +55,7 @@ public static function seed_keypair(&$pk, &$sk, $seed) * * @param string $keypair * @return string + * @throws TypeError */ public static function secretkey($keypair) { @@ -65,6 +70,7 @@ public static function secretkey($keypair) * * @param string $keypair * @return string + * @throws TypeError */ public static function publickey($keypair) { @@ -79,6 +85,8 @@ public static function publickey($keypair) * * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function publickey_from_secretkey($sk) { @@ -93,11 +101,52 @@ public static function publickey_from_secretkey($sk) return self::sk_to_pk($sk); } + /** + * @param string $pk + * @return string + * @throws SodiumException + * @throws TypeError + */ + public static function pk_to_curve25519($pk) + { + if (self::small_order($pk)) { + throw new SodiumException('Public key is on a small order'); + } + $A = self::ge_frombytes_negate_vartime(self::substr($pk, 0, 32)); + $p1 = self::ge_mul_l($A); + if (!self::fe_isnonzero($p1->X)) { + throw new SodiumException('Unexpected zero result'); + } + + # fe_1(one_minus_y); + # fe_sub(one_minus_y, one_minus_y, A.Y); + # fe_invert(one_minus_y, one_minus_y); + $one_minux_y = self::fe_invert( + self::fe_sub( + self::fe_1(), + $A->Y + ) + ); + + # fe_1(x); + # fe_add(x, x, A.Y); + # fe_mul(x, x, one_minus_y); + $x = self::fe_mul( + self::fe_add(self::fe_1(), $A->Y), + $one_minux_y + ); + + # fe_tobytes(curve25519_pk, x); + return self::fe_tobytes($x); + } + /** * @internal You should not use this directly from another application * * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sk_to_pk($sk) { @@ -114,6 +163,8 @@ public static function sk_to_pk($sk) * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign($message, $sk) { @@ -128,7 +179,8 @@ public static function sign($message, $sk) * @param string $message A signed message * @param string $pk Public key * @return string Message (without signature) - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function sign_open($message, $pk) { @@ -141,7 +193,7 @@ public static function sign_open($message, $pk) if (self::verify_detached($signature, $message, $pk)) { return $message; } - throw new Exception('Invalid signature'); + throw new SodiumException('Invalid signature'); } /** @@ -150,6 +202,8 @@ public static function sign_open($message, $pk) * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign_detached($message, $sk) { @@ -200,7 +254,7 @@ public static function sign_detached($message, $sk) try { ParagonIE_Sodium_Compat::memzero($az); - } catch (Error $ex) { + } catch (SodiumException $ex) { $az = null; } return $sig; @@ -213,28 +267,29 @@ public static function sign_detached($message, $sk) * @param string $message * @param string $pk * @return bool - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function verify_detached($sig, $message, $pk) { if (self::strlen($sig) < 64) { - throw new Exception('Signature is too short'); + throw new SodiumException('Signature is too short'); } if (self::check_S_lt_L(self::substr($sig, 32, 32))) { - throw new Exception('S < L - Invalid signature'); + throw new SodiumException('S < L - Invalid signature'); } if (self::small_order($sig)) { - throw new Exception('Signature is on too small of an order'); + throw new SodiumException('Signature is on too small of an order'); } if ((self::chrToInt($sig[63]) & 224) !== 0) { - throw new Exception('Invalid signature'); + throw new SodiumException('Invalid signature'); } $d = 0; for ($i = 0; $i < 32; ++$i) { $d |= self::chrToInt($pk[$i]); } if ($d === 0) { - throw new Exception('All zero public key'); + throw new SodiumException('All zero public key'); } /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */ @@ -279,14 +334,15 @@ public static function verify_detached($sig, $message, $pk) * * @param string $S * @return bool - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function check_S_lt_L($S) { if (self::strlen($S) < 32) { - throw new Exception('Signature must be 32 bytes'); + throw new SodiumException('Signature must be 32 bytes'); } - static $L = array( + $L = array( 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -296,6 +352,7 @@ public static function check_S_lt_L($S) $n = 1; $i = 32; + /** @var array $L */ do { --$i; $x = self::chrToInt($S[$i]); @@ -313,10 +370,13 @@ public static function check_S_lt_L($S) /** * @param string $R * @return bool + * @throws SodiumException + * @throws TypeError */ public static function small_order($R) { - static $blacklist = array( + /** @var array> $blacklist */ + $blacklist = array( /* 0 (order 4) */ array( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -402,12 +462,13 @@ public static function small_order($R) 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ) ); + /** @var int $countBlacklist */ $countBlacklist = count($blacklist); for ($i = 0; $i < $countBlacklist; ++$i) { $c = 0; for ($j = 0; $j < 32; ++$j) { - $c |= self::chrToInt($R[$j]) ^ $blacklist[$i][$j]; + $c |= self::chrToInt($R[$j]) ^ (int) $blacklist[$i][$j]; } if ($c === 0) { return true; diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/HChaCha20.php b/libraries/vendor/paragonie/sodium_compat/src/Core/HChaCha20.php index b6cf92996e65c..947df10fbff2b 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/HChaCha20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/HChaCha20.php @@ -14,6 +14,7 @@ class ParagonIE_Sodium_Core_HChaCha20 extends ParagonIE_Sodium_Core_ChaCha20 * @param string $key * @param string|null $c * @return string + * @throws TypeError */ public static function hChaCha20($in = '', $key = '', $c = null) { @@ -48,6 +49,7 @@ public static function hChaCha20($in = '', $key = '', $c = null) /** * @param array $ctx * @return string + * @throws TypeError */ protected static function hChaCha20Bytes(array $ctx) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/HSalsa20.php b/libraries/vendor/paragonie/sodium_compat/src/Core/HSalsa20.php index b7ef5e05de6f6..35ee79edb839d 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/HSalsa20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/HSalsa20.php @@ -21,6 +21,7 @@ abstract class ParagonIE_Sodium_Core_HSalsa20 extends ParagonIE_Sodium_Core_Sals * @param string $k * @param string|null $c * @return string + * @throws TypeError */ public static function hsalsa20($in, $k, $c = null) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305.php index be3b83da7c7dc..330182177e32e 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305.php @@ -17,6 +17,8 @@ abstract class ParagonIE_Sodium_Core_Poly1305 extends ParagonIE_Sodium_Core_Util * @param string $m * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function onetimeauth($m, $key) { @@ -40,6 +42,8 @@ public static function onetimeauth($m, $key) * @param string $m * @param string $key * @return bool + * @throws SodiumException + * @throws TypeError */ public static function onetimeauth_verify($mac, $m, $key) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305/State.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305/State.php index 33c459323aa48..1fa93101bf1be 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305/State.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Poly1305/State.php @@ -46,6 +46,7 @@ class ParagonIE_Sodium_Core_Poly1305_State extends ParagonIE_Sodium_Core_Util * * @param string $key * @throws InvalidArgumentException + * @throws TypeError */ public function __construct($key = '') { @@ -83,6 +84,8 @@ public function __construct($key = '') * * @param string $message * @return self + * @throws SodiumException + * @throws TypeError */ public function update($message = '') { @@ -116,6 +119,7 @@ public function update($message = '') /* process full blocks */ if ($bytes >= ParagonIE_Sodium_Core_Poly1305::BLOCK_SIZE) { + /** @var int $want */ $want = $bytes & ~(ParagonIE_Sodium_Core_Poly1305::BLOCK_SIZE - 1); if ($want >= ParagonIE_Sodium_Core_Poly1305::BLOCK_SIZE) { $block = self::substr($message, 0, $want); @@ -144,12 +148,14 @@ public function update($message = '') * @param string $message * @param int $bytes * @return self + * @throws TypeError */ public function blocks($message, $bytes) { if (self::strlen($message) < 16) { $message = str_pad($message, 16, "\x00", STR_PAD_RIGHT); } + /** @var int $hibit */ $hibit = $this->final ? 0 : 1 << 24; /* 1 << 128 */ $r0 = (int) $this->r[0]; $r1 = (int) $this->r[1]; @@ -178,62 +184,79 @@ public function blocks($message, $bytes) /* h *= r */ $d0 = ( - self::mul($h0, $r0) + - self::mul($h1, $s4) + - self::mul($h2, $s3) + - self::mul($h3, $s2) + - self::mul($h4, $s1) + self::mul($h0, $r0, 31) + + self::mul($h1, $s4, 31) + + self::mul($h2, $s3, 31) + + self::mul($h3, $s2, 31) + + self::mul($h4, $s1, 31) ); $d1 = ( - self::mul($h0, $r1) + - self::mul($h1, $r0) + - self::mul($h2, $s4) + - self::mul($h3, $s3) + - self::mul($h4, $s2) + self::mul($h0, $r1, 31) + + self::mul($h1, $r0, 31) + + self::mul($h2, $s4, 31) + + self::mul($h3, $s3, 31) + + self::mul($h4, $s2, 31) ); $d2 = ( - self::mul($h0, $r2) + - self::mul($h1, $r1) + - self::mul($h2, $r0) + - self::mul($h3, $s4) + - self::mul($h4, $s3) + self::mul($h0, $r2, 31) + + self::mul($h1, $r1, 31) + + self::mul($h2, $r0, 31) + + self::mul($h3, $s4, 31) + + self::mul($h4, $s3, 31) ); $d3 = ( - self::mul($h0, $r3) + - self::mul($h1, $r2) + - self::mul($h2, $r1) + - self::mul($h3, $r0) + - self::mul($h4, $s4) + self::mul($h0, $r3, 31) + + self::mul($h1, $r2, 31) + + self::mul($h2, $r1, 31) + + self::mul($h3, $r0, 31) + + self::mul($h4, $s4, 31) ); $d4 = ( - self::mul($h0, $r4) + - self::mul($h1, $r3) + - self::mul($h2, $r2) + - self::mul($h3, $r1) + - self::mul($h4, $r0) + self::mul($h0, $r4, 31) + + self::mul($h1, $r3, 31) + + self::mul($h2, $r2, 31) + + self::mul($h3, $r1, 31) + + self::mul($h4, $r0, 31) ); /* (partial) h %= p */ + /** @var int $c */ $c = $d0 >> 26; + /** @var int $h0 */ $h0 = $d0 & 0x3ffffff; $d1 += $c; + + /** @var int $c */ $c = $d1 >> 26; + /** @var int $h1 */ $h1 = $d1 & 0x3ffffff; $d2 += $c; + + /** @var int $c */ $c = $d2 >> 26; + /** @var int $h2 */ $h2 = $d2 & 0x3ffffff; $d3 += $c; + + /** @var int $c */ $c = $d3 >> 26; + /** @var int $h3 */ $h3 = $d3 & 0x3ffffff; $d4 += $c; + + /** @var int $c */ $c = $d4 >> 26; + /** @var int $h4 */ $h4 = $d4 & 0x3ffffff; $h0 += (int) self::mul($c, 5, 3); + + /** @var int $c */ $c = $h0 >> 26; + /** @var int $h0 */ $h0 &= 0x3ffffff; $h1 += $c; @@ -259,6 +282,7 @@ public function blocks($message, $bytes) * @internal You should not use this directly from another application * * @return string + * @throws TypeError */ public function finish() { @@ -286,38 +310,66 @@ public function finish() $h3 = (int) $this->h[3]; $h4 = (int) $this->h[4]; + /** @var int $c */ $c = $h1 >> 26; + /** @var int $h1 */ $h1 &= 0x3ffffff; + /** @var int $h2 */ $h2 += $c; + /** @var int $c */ $c = $h2 >> 26; + /** @var int $h2 */ $h2 &= 0x3ffffff; $h3 += $c; + /** @var int $c */ $c = $h3 >> 26; $h3 &= 0x3ffffff; $h4 += $c; + /** @var int $c */ $c = $h4 >> 26; $h4 &= 0x3ffffff; + /** @var int $h0 */ $h0 += self::mul($c, 5, 3); + /** @var int $c */ $c = $h0 >> 26; + /** @var int $h0 */ $h0 &= 0x3ffffff; + /** @var int $h1 */ $h1 += $c; /* compute h + -p */ + /** @var int $g0 */ $g0 = $h0 + 5; + /** @var int $c */ $c = $g0 >> 26; + /** @var int $g0 */ $g0 &= 0x3ffffff; + + /** @var int $g1 */ $g1 = $h1 + $c; + /** @var int $c */ $c = $g1 >> 26; $g1 &= 0x3ffffff; + + /** @var int $g2 */ $g2 = $h2 + $c; + /** @var int $c */ $c = $g2 >> 26; + /** @var int $g2 */ $g2 &= 0x3ffffff; + + /** @var int $g3 */ $g3 = $h3 + $c; + /** @var int $c */ $c = $g3 >> 26; + /** @var int $g3 */ $g3 &= 0x3ffffff; + + /** @var int $g4 */ $g4 = ($h4 + $c - (1 << 26)) & 0xffffffff; /* select h if h < p, or h + -p if h >= p */ + /** @var int $mask */ $mask = ($g4 >> 31) - 1; $g0 &= $mask; @@ -326,27 +378,37 @@ public function finish() $g3 &= $mask; $g4 &= $mask; + /** @var int $mask */ $mask = ~$mask & 0xffffffff; + /** @var int $h0 */ $h0 = ($h0 & $mask) | $g0; + /** @var int $h1 */ $h1 = ($h1 & $mask) | $g1; + /** @var int $h2 */ $h2 = ($h2 & $mask) | $g2; + /** @var int $h3 */ $h3 = ($h3 & $mask) | $g3; + /** @var int $h4 */ $h4 = ($h4 & $mask) | $g4; /* h = h % (2^128) */ + /** @var int $h0 */ $h0 = (($h0) | ($h1 << 26)) & 0xffffffff; + /** @var int $h1 */ $h1 = (($h1 >> 6) | ($h2 << 20)) & 0xffffffff; + /** @var int $h2 */ $h2 = (($h2 >> 12) | ($h3 << 14)) & 0xffffffff; + /** @var int $h3 */ $h3 = (($h3 >> 18) | ($h4 << 8)) & 0xffffffff; /* mac = (h + pad) % (2^128) */ - $f = ($h0 + $this->pad[0]); + $f = (int) ($h0 + $this->pad[0]); $h0 = (int) $f; - $f = ($h1 + $this->pad[1] + ($f >> 32)); + $f = (int) ($h1 + $this->pad[1] + ($f >> 32)); $h1 = (int) $f; - $f = ($h2 + $this->pad[2] + ($f >> 32)); + $f = (int) ($h2 + $this->pad[2] + ($f >> 32)); $h2 = (int) $f; - $f = ($h3 + $this->pad[3] + ($f >> 32)); + $f = (int) ($h3 + $this->pad[3] + ($f >> 32)); $h3 = (int) $f; return self::store32_le($h0 & 0xffffffff) . diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Salsa20.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Salsa20.php index afb70cf0ddac5..515ccad605cce 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Salsa20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Salsa20.php @@ -20,6 +20,7 @@ abstract class ParagonIE_Sodium_Core_Salsa20 extends ParagonIE_Sodium_Core_Util * @param string $k * @param string|null $c * @return string + * @throws TypeError */ public static function core_salsa20($in, $k, $c = null) { @@ -134,6 +135,8 @@ public static function core_salsa20($in, $k, $c = null) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function salsa20($len, $nonce, $key) { @@ -163,7 +166,7 @@ public static function salsa20($len, $nonce, $key) } try { ParagonIE_Sodium_Compat::memzero($kcopy); - } catch (Error $ex) { + } catch (SodiumException $ex) { $kcopy = null; } return $c; @@ -177,6 +180,8 @@ public static function salsa20($len, $nonce, $key) * @param int $ic * @param string $k * @return string + * @throws SodiumException + * @throws TypeError */ public static function salsa20_xor_ic($m, $n, $ic, $k) { @@ -217,7 +222,7 @@ public static function salsa20_xor_ic($m, $n, $ic, $k) try { ParagonIE_Sodium_Compat::memzero($block); ParagonIE_Sodium_Compat::memzero($kcopy); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block = null; $kcopy = null; } @@ -232,6 +237,8 @@ public static function salsa20_xor_ic($m, $n, $ic, $k) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function salsa20_xor($message, $nonce, $key) { @@ -256,10 +263,11 @@ public static function rotate($u, $c) { $u &= 0xffffffff; $c %= 32; - return 0xffffffff & ( - ($u << $c) - | - ($u >> (32 - $c)) + return (int) (0xffffffff & ( + ($u << $c) + | + ($u >> (32 - $c)) + ) ); } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/SipHash.php b/libraries/vendor/paragonie/sodium_compat/src/Core/SipHash.php index 592ad7a4d521a..7d3981620efaa 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/SipHash.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/SipHash.php @@ -33,7 +33,7 @@ public static function sipRound(array $v) $v[3] ^= $v[1]; # v0=ROTL(v0,32); - list($v[0], $v[1]) = self::rotl_64($v[0], $v[1], 32); + list($v[0], $v[1]) = self::rotl_64((int) $v[0], (int) $v[1], 32); # v2 += v3; list($v[4], $v[5]) = self::add( @@ -50,12 +50,12 @@ public static function sipRound(array $v) # v0 += v3; list($v[0], $v[1]) = self::add( - array($v[0], $v[1]), - array($v[6], $v[7]) + array((int) $v[0], (int) $v[1]), + array((int) $v[6], (int) $v[7]) ); # v3=ROTL(v3,21); - list($v[6], $v[7]) = self::rotl_64($v[6], $v[7], 21); + list($v[6], $v[7]) = self::rotl_64((int) $v[6], (int) $v[7], 21); # v3 ^= v0; $v[6] ^= $v[0]; @@ -63,19 +63,19 @@ public static function sipRound(array $v) # v2 += v1; list($v[4], $v[5]) = self::add( - array($v[4], $v[5]), - array($v[2], $v[3]) + array((int) $v[4], (int) $v[5]), + array((int) $v[2], (int) $v[3]) ); # v1=ROTL(v1,17); - list($v[2], $v[3]) = self::rotl_64($v[2], $v[3], 17); + list($v[2], $v[3]) = self::rotl_64((int) $v[2], (int) $v[3], 17); # v1 ^= v2;; $v[2] ^= $v[4]; $v[3] ^= $v[5]; # v2=ROTL(v2,32) - list($v[4], $v[5]) = self::rotl_64($v[4], $v[5], 32); + list($v[4], $v[5]) = self::rotl_64((int) $v[4], (int) $v[5], 32); return $v; } @@ -91,8 +91,11 @@ public static function sipRound(array $v) */ public static function add(array $a, array $b) { + /** @var int $x1 */ $x1 = $a[1] + $b[1]; + /** @var int $c */ $c = $x1 >> 32; // Carry if ($a + $b) > 0xffffffff + /** @var int $x0 */ $x0 = $a[0] + $b[0] + $c; return array( $x0 & 0xffffffff, @@ -153,6 +156,8 @@ public static function rotl_64($int0, $int1, $c) * @param string $in * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function sipHash24($in, $key) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Util.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Util.php index e18851efd27ff..9c8e41e29689b 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Util.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Util.php @@ -9,6 +9,30 @@ */ abstract class ParagonIE_Sodium_Core_Util { + /** + * @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) + ); + } + /** * Convert a binary string into a hexadecimal string without cache-timing * leaks @@ -29,8 +53,11 @@ public static function bin2hex($binaryString) $hex = ''; $len = self::strlen($binaryString); for ($i = 0; $i < $len; ++$i) { - $chunk = unpack('C', self::substr($binaryString, $i, 2)); + /** @var array $chunk */ + $chunk = unpack('C', $binaryString[$i]); + /** @var int $c */ $c = $chunk[1] & 0xf; + /** @var int $b */ $b = $chunk[1] >> 4; $hex .= pack( 'CC', @@ -49,23 +76,25 @@ public static function bin2hex($binaryString) * * @param string $bin_string (raw binary) * @return string + * @throws TypeError */ public static function bin2hexUpper($bin_string) { $hex = ''; $len = self::strlen($bin_string); for ($i = 0; $i < $len; ++$i) { - $chunk = unpack('C', self::substr($bin_string, $i, 2)); + /** @var array $chunk */ + $chunk = unpack('C', $bin_string[$i]); /** * Lower 16 bits * - * @var int + * @var int $c */ $c = $chunk[1] & 0xf; /** * Upper 16 bits - * @var int + * @var int $b */ $b = $chunk[1] >> 4; @@ -91,7 +120,8 @@ public static function bin2hexUpper($bin_string) * * @param string $chr * @return int - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function chrToInt($chr) { @@ -100,10 +130,11 @@ public static function chrToInt($chr) throw new TypeError('Argument 1 must be a string, ' . gettype($chr) . ' given.'); } if (self::strlen($chr) !== 1) { - throw new Error('chrToInt() expects a string that is exactly 1 character long'); + throw new SodiumException('chrToInt() expects a string that is exactly 1 character long'); } + /** @var array $chunk */ $chunk = unpack('C', $chr); - return $chunk[1]; + return (int) ($chunk[1]); } /** @@ -115,6 +146,8 @@ public static function chrToInt($chr) * @param string $right * @param int $len * @return int + * @throws SodiumException + * @throws TypeError */ public static function compare($left, $right, $len = null) { @@ -144,7 +177,7 @@ public static function compare($left, $right, $len = null) * @param string $type * @param int $argumentIndex * @throws TypeError - * @throws Error + * @throws SodiumException * @return void */ public static function declareScalarType(&$mixedVar = null, $type = 'void', $argumentIndex = 0) @@ -211,7 +244,7 @@ public static function declareScalarType(&$mixedVar = null, $type = 'void', $arg } break; default: - throw new Error('Unknown type (' . $realType .') does not match expect type (' . $type . ')'); + throw new SodiumException('Unknown type (' . $realType .') does not match expect type (' . $type . ')'); } } @@ -221,6 +254,7 @@ public static function declareScalarType(&$mixedVar = null, $type = 'void', $arg * @param string $left * @param string $right * @return bool + * @throws SodiumException * @throws TypeError */ public static function hashEquals($left, $right) @@ -237,6 +271,7 @@ public static function hashEquals($left, $right) return hash_equals($left, $right); } $d = 0; + /** @var int $len */ $len = self::strlen($left); if ($len !== self::strlen($right)) { return false; @@ -270,10 +305,15 @@ public static function hex2bin($hexString, $strictPadding = false) throw new TypeError('Argument 1 must be a string, ' . gettype($hexString) . ' given.'); } + /** @var int $hex_pos */ $hex_pos = 0; + /** @var string $bin */ $bin = ''; + /** @var int $c_acc */ $c_acc = 0; + /** @var int $hex_len */ $hex_len = self::strlen($hexString); + /** @var int $state */ $state = 0; if (($hex_len & 1) !== 0) { if ($strictPadding) { @@ -289,16 +329,22 @@ public static function hex2bin($hexString, $strictPadding = false) $chunk = unpack('C*', $hexString); while ($hex_pos < $hex_len) { ++$hex_pos; + /** @var int $c */ $c = $chunk[$hex_pos]; + /** @var int $c_num */ $c_num = $c ^ 48; + /** @var int $c_num0 */ $c_num0 = ($c_num - 10) >> 8; + /** @var int $c_alpha */ $c_alpha = ($c & ~32) - 55; + /** @var int $c_alpha0 */ $c_alpha0 = (($c_alpha - 10) ^ ($c_alpha - 16)) >> 8; if (($c_num0 | $c_alpha0) === 0) { throw new RangeException( 'hex2bin() only expects hexadecimal characters' ); } + /** @var int $c_val */ $c_val = ($c_num0 & $c_num) | ($c_alpha & $c_alpha0); if ($state === 0) { $c_acc = $c_val * 16; @@ -320,12 +366,13 @@ public static function hex2bin($hexString, $strictPadding = false) */ public static function intArrayToString(array $ints) { + /** @var array $args */ $args = $ints; foreach ($args as $i => $v) { - $args[$i] = $v & 0xff; + $args[$i] = (int) ($v & 0xff); } array_unshift($args, str_repeat('C', count($ints))); - return call_user_func_array('pack', $args); + return (string) (call_user_func_array('pack', $args)); } /** @@ -365,10 +412,9 @@ public static function load_3($string) 'String must be 3 bytes or more; ' . self::strlen($string) . ' given.' ); } - $result = self::chrToInt($string[0]); - $result |= self::chrToInt($string[1]) << 8; - $result |= self::chrToInt($string[2]) << 16; - return $result & 0xffffff; + /** @var array $unpacked */ + $unpacked = unpack('V', $string . "\0"); + return (int) ($unpacked[1] & 0xffffff); } /** @@ -394,11 +440,9 @@ public static function load_4($string) 'String must be 4 bytes or more; ' . self::strlen($string) . ' given.' ); } - $result = (self::chrToInt($string[0]) & 0xff); - $result |= (self::chrToInt($string[1]) & 0xff) << 8; - $result |= (self::chrToInt($string[2]) & 0xff) << 16; - $result |= (self::chrToInt($string[3]) & 0xff) << 24; - return $result & 0xffffffff; + /** @var array $unpacked */ + $unpacked = unpack('V', $string); + return (int) ($unpacked[1] & 0xffffffff); } /** @@ -409,6 +453,7 @@ public static function load_4($string) * @param string $string * @return int * @throws RangeException + * @throws SodiumException * @throws TypeError */ public static function load64_le($string) @@ -424,6 +469,13 @@ public static function load64_le($string) 'String must be 4 bytes or more; ' . self::strlen($string) . ' given.' ); } + if (PHP_VERSION_ID >= 50603 && PHP_INT_SIZE === 8) { + /** @var array $unpacked */ + $unpacked = unpack('P', $string); + return (int) $unpacked[1]; + } + + /** @var int $result */ $result = (self::chrToInt($string[0]) & 0xff); $result |= (self::chrToInt($string[1]) & 0xff) << 8; $result |= (self::chrToInt($string[2]) & 0xff) << 16; @@ -441,6 +493,8 @@ public static function load64_le($string) * @param string $left * @param string $right * @return int + * @throws SodiumException + * @throws TypeError */ public static function memcmp($left, $right) { @@ -474,12 +528,16 @@ public static function mul($a, $b, $size = 0) } static $defaultSize = null; + /** @var int $defaultSize */ if (!$defaultSize) { + /** @var int $defaultSize */ $defaultSize = (PHP_INT_SIZE << 3) - 1; } if ($size < 1) { + /** @var int $size */ $size = $defaultSize; } + /** @var int $size */ $c = 0; @@ -491,15 +549,19 @@ public static function mul($a, $b, $size = 0) * * @var int */ - $mask = -(($b >> $size) & 1); + $mask = -(($b >> $defaultSize) & 1); /** * Ensure $b is a positive integer, without creating * a branching side-channel + * + * @var int $b */ $b = ($b & ~$mask) | ($mask & -$b); /** + * Unless $size is provided: + * * This loop always runs 32 times when PHP_INT_SIZE is 4. * This loop always runs 64 times when PHP_INT_SIZE is 8. */ @@ -533,12 +595,15 @@ public static function mul($a, $b, $size = 0) public static function numericTo64BitInteger($num) { $high = 0; + /** @var int $low */ $low = $num & 0xffffffff; if ((+(abs($num))) >= 1) { if ($num > 0) { + /** @var int $high */ $high = min((+(floor($num/4294967296))), 4294967295); } else { + /** @var int $high */ $high = ~~((+(ceil(($num - (+((~~($num)))))/4294967296)))); } } @@ -564,10 +629,9 @@ public static function store_3($int) throw new TypeError('Argument 1 must be an integer, ' . gettype($int) . ' given.'); } } - - return self::intToChr(($int >> 16) & 0xff) . - self::intToChr(($int >> 8) & 0xff) . - self::intToChr($int & 0xff); + /** @var string $packed */ + $packed = pack('N', $int); + return self::substr($packed, 1, 3); } /** @@ -590,10 +654,9 @@ public static function store32_le($int) } } - return self::intToChr($int & 0xff) . - self::intToChr(($int >> 8) & 0xff) . - self::intToChr(($int >> 16) & 0xff) . - self::intToChr(($int >> 24) & 0xff); + /** @var string $packed */ + $packed = pack('V', $int); + return $packed; } /** @@ -616,10 +679,9 @@ public static function store_4($int) } } - return self::intToChr(($int >> 24) & 0xff) . - self::intToChr(($int >> 16) & 0xff) . - self::intToChr(($int >> 8) & 0xff) . - self::intToChr($int & 0xff); + /** @var string $packed */ + $packed = pack('N', $int); + return $packed; } /** @@ -643,6 +705,11 @@ public static function store64_le($int) } if (PHP_INT_SIZE === 8) { + if (PHP_VERSION_ID >= 50603) { + /** @var string $packed */ + $packed = pack('P', $int); + return $packed; + } return self::intToChr($int & 0xff) . self::intToChr(($int >> 8) & 0xff) . self::intToChr(($int >> 16) & 0xff) . @@ -764,6 +831,7 @@ public static function substr($str, $start = 0, $length = null) * @param string $a * @param string $b * @return bool + * @throws SodiumException * @throws TypeError */ public static function verify_16($a, $b) @@ -789,6 +857,7 @@ public static function verify_16($a, $b) * @param string $a * @param string $b * @return bool + * @throws SodiumException * @throws TypeError */ public static function verify_32($a, $b) @@ -826,7 +895,7 @@ public static function xorStrings($a, $b) throw new TypeError('Argument 2 must be a string'); } - return $a ^ $b; + return (string) ($a ^ $b); } /** @@ -845,6 +914,7 @@ protected static function isMbStringOverride() && (ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING); } + /** @var bool $mbstring */ return $mbstring; } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/X25519.php b/libraries/vendor/paragonie/sodium_compat/src/Core/X25519.php index 70de64c33617b..732bb65e96824 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/X25519.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/X25519.php @@ -18,6 +18,7 @@ abstract class ParagonIE_Sodium_Core_X25519 extends ParagonIE_Sodium_Core_Curve2 * @param ParagonIE_Sodium_Core_Curve25519_Fe $g * @param int $b * @return void + * @psalm-suppress MixedAssignment */ public static function fe_cswap( ParagonIE_Sodium_Core_Curve25519_Fe $f, @@ -86,46 +87,56 @@ public static function fe_cswap( public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) { $h = array( - self::mul($f[0], 121666, 17), - self::mul($f[1], 121666, 17), - self::mul($f[2], 121666, 17), - self::mul($f[3], 121666, 17), - self::mul($f[4], 121666, 17), - self::mul($f[5], 121666, 17), - self::mul($f[6], 121666, 17), - self::mul($f[7], 121666, 17), - self::mul($f[8], 121666, 17), - self::mul($f[9], 121666, 17) + self::mul((int) $f[0], 121666, 17), + self::mul((int) $f[1], 121666, 17), + self::mul((int) $f[2], 121666, 17), + self::mul((int) $f[3], 121666, 17), + self::mul((int) $f[4], 121666, 17), + self::mul((int) $f[5], 121666, 17), + self::mul((int) $f[6], 121666, 17), + self::mul((int) $f[7], 121666, 17), + self::mul((int) $f[8], 121666, 17), + self::mul((int) $f[9], 121666, 17) ); + /** @var int $carry9 */ $carry9 = ($h[9] + (1 << 24)) >> 25; $h[0] += self::mul($carry9, 19, 5); $h[9] -= $carry9 << 25; + /** @var int $carry1 */ $carry1 = ($h[1] + (1 << 24)) >> 25; $h[2] += $carry1; $h[1] -= $carry1 << 25; + /** @var int $carry3 */ $carry3 = ($h[3] + (1 << 24)) >> 25; $h[4] += $carry3; $h[3] -= $carry3 << 25; + /** @var int $carry5 */ $carry5 = ($h[5] + (1 << 24)) >> 25; $h[6] += $carry5; $h[5] -= $carry5 << 25; + /** @var int $carry7 */ $carry7 = ($h[7] + (1 << 24)) >> 25; $h[8] += $carry7; $h[7] -= $carry7 << 25; + /** @var int $carry0 */ $carry0 = ($h[0] + (1 << 25)) >> 26; $h[1] += $carry0; $h[0] -= $carry0 << 26; + /** @var int $carry2 */ $carry2 = ($h[2] + (1 << 25)) >> 26; $h[3] += $carry2; $h[2] -= $carry2 << 26; + /** @var int $carry4 */ $carry4 = ($h[4] + (1 << 25)) >> 26; $h[5] += $carry4; $h[4] -= $carry4 << 26; + /** @var int $carry6 */ $carry6 = ($h[6] + (1 << 25)) >> 26; $h[7] += $carry6; $h[6] -= $carry6 << 26; + /** @var int $carry8 */ $carry8 = ($h[8] + (1 << 25)) >> 26; $h[9] += $carry8; $h[8] -= $carry8 << 26; @@ -144,6 +155,8 @@ public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) * @param string $n * @param string $p * @return string + * @throws SodiumException + * @throws TypeError */ public static function crypto_scalarmult_curve25519_ref10($n, $p) { @@ -170,11 +183,13 @@ public static function crypto_scalarmult_curve25519_ref10($n, $p) $z3 = self::fe_1(); # swap = 0; + /** @var int $swap */ $swap = 0; # for (pos = 254;pos >= 0;--pos) { for ($pos = 254; $pos >= 0; --$pos) { # b = e[pos / 8] >> (pos & 7); + /** @var int $b */ $b = self::chrToInt( $e[(int) floor($pos / 8)] ) >> ($pos & 7); @@ -279,6 +294,7 @@ public static function edwards_to_montgomery( * * @param string $n * @return string + * @throws SodiumException * @throws TypeError */ public static function crypto_scalarmult_curve25519_ref10_base($n) diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/XChaCha20.php b/libraries/vendor/paragonie/sodium_compat/src/Core/XChaCha20.php index e7a25337bcb15..a9b203ce57765 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/XChaCha20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/XChaCha20.php @@ -16,12 +16,13 @@ class ParagonIE_Sodium_Core_XChaCha20 extends ParagonIE_Sodium_Core_HChaCha20 * @param string $nonce * @param string $key * @return string - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function stream($len = 64, $nonce = '', $key = '') { if (self::strlen($nonce) !== 24) { - throw new Exception('Nonce must be 24 bytes long'); + throw new SodiumException('Nonce must be 24 bytes long'); } return self::encryptBytes( new ParagonIE_Sodium_Core_ChaCha20_Ctx( @@ -43,12 +44,13 @@ public static function stream($len = 64, $nonce = '', $key = '') * @param string $key * @param string $ic * @return string - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') { if (self::strlen($nonce) !== 24) { - throw new Exception('Nonce must be 24 bytes long'); + throw new SodiumException('Nonce must be 24 bytes long'); } return self::encryptBytes( new ParagonIE_Sodium_Core_ChaCha20_Ctx( diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core/Xsalsa20.php b/libraries/vendor/paragonie/sodium_compat/src/Core/Xsalsa20.php index 1fa652878db63..9ef989eecadaf 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core/Xsalsa20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core/Xsalsa20.php @@ -18,6 +18,8 @@ abstract class ParagonIE_Sodium_Core_XSalsa20 extends ParagonIE_Sodium_Core_HSal * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function xsalsa20($len, $nonce, $key) { @@ -38,6 +40,8 @@ public static function xsalsa20($len, $nonce, $key) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function xsalsa20_xor($message, $nonce, $key) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/BLAKE2b.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/BLAKE2b.php index 06471ba6c3896..88bc98d6c0f12 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/BLAKE2b.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/BLAKE2b.php @@ -17,7 +17,7 @@ abstract class ParagonIE_Sodium_Core32_BLAKE2b extends ParagonIE_Sodium_Core_Uti public static $iv; /** - * @var int[][] + * @var array> */ public static $sigma = array( array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), @@ -46,6 +46,8 @@ abstract class ParagonIE_Sodium_Core32_BLAKE2b extends ParagonIE_Sodium_Core_Uti * @param int $high * @param int $low * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException + * @throws TypeError */ public static function new64($high, $low) { @@ -60,6 +62,8 @@ public static function new64($high, $low) * * @param int $num * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException + * @throws TypeError */ protected static function to64($num) { @@ -101,7 +105,7 @@ public static function add364($x, $y, $z) * @param ParagonIE_Sodium_Core32_Int64 $x * @param ParagonIE_Sodium_Core32_Int64 $y * @return ParagonIE_Sodium_Core32_Int64 - * @throws Exception + * @throws TypeError */ public static function xor64(ParagonIE_Sodium_Core32_Int64 $x, ParagonIE_Sodium_Core32_Int64 $y) { @@ -114,6 +118,8 @@ public static function xor64(ParagonIE_Sodium_Core32_Int64 $x, ParagonIE_Sodium_ * @param ParagonIE_Sodium_Core32_Int64 $x * @param int $c * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException + * @throws TypeError */ public static function rotr64(ParagonIE_Sodium_Core32_Int64 $x, $c) { @@ -126,10 +132,14 @@ public static function rotr64(ParagonIE_Sodium_Core32_Int64 $x, $c) * @param SplFixedArray $x * @param int $i * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException + * @throws TypeError */ public static function load64($x, $i) { + /** @var int $l */ $l = $x[$i] | ($x[$i+1]<<8) | ($x[$i+2]<<16) | ($x[$i+3]<<24); + /** @var int $h */ $h = $x[$i+4] | ($x[$i+5]<<8) | ($x[$i+6]<<16) | ($x[$i+7]<<24); return self::new64($h, $l); } @@ -141,6 +151,12 @@ public static function load64($x, $i) * @param int $i * @param ParagonIE_Sodium_Core32_Int64 $u * @return void + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset */ public static function store64(SplFixedArray $x, $i, ParagonIE_Sodium_Core32_Int64 $u) { @@ -162,6 +178,8 @@ public static function store64(SplFixedArray $x, $i, ParagonIE_Sodium_Core32_Int * @internal You should not use this directly from another application * * @return void + * @throws SodiumException + * @throws TypeError */ public static function pseudoConstructor() { @@ -188,6 +206,14 @@ public static function pseudoConstructor() * @internal You should not use this directly from another application * * @return SplFixedArray + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset + * @throws SodiumException + * @throws TypeError */ protected static function context() { @@ -220,6 +246,12 @@ protected static function context() * @param SplFixedArray $ctx * @param SplFixedArray $buf * @return void + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedAssignment */ protected static function compress(SplFixedArray $ctx, SplFixedArray $buf) { @@ -274,6 +306,10 @@ protected static function compress(SplFixedArray $ctx, SplFixedArray $buf) * @param SplFixedArray $v * @param SplFixedArray $m * @return SplFixedArray + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayOffset */ public static function G($r, $i, $a, $b, $c, $d, SplFixedArray $v, SplFixedArray $m) { @@ -294,12 +330,16 @@ public static function G($r, $i, $a, $b, $c, $d, SplFixedArray $v, SplFixedArray * @param SplFixedArray $ctx * @param int $inc * @return void - * @throws Error + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment */ public static function increment_counter($ctx, $inc) { if ($inc < 0) { - throw new Error('Increasing by a negative number makes no sense.'); + throw new SodiumException('Increasing by a negative number makes no sense.'); } $t = self::to64($inc); # S->t is $ctx[1] in our implementation @@ -325,6 +365,15 @@ public static function increment_counter($ctx, $inc) * @param SplFixedArray $p * @param int $plen * @return void + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset + * @psalm-suppress MixedMethodCall + * @psalm-suppress MixedOperand */ public static function update(SplFixedArray $ctx, SplFixedArray $p, $plen) { @@ -380,7 +429,15 @@ public static function update(SplFixedArray $ctx, SplFixedArray $p, $plen) * @param SplFixedArray $ctx * @param SplFixedArray $out * @return SplFixedArray - * @throws Error + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedArrayOffset + * @psalm-suppress MixedMethodCall + * @psalm-suppress MixedOperand */ public static function finish(SplFixedArray $ctx, SplFixedArray $out) { @@ -390,7 +447,7 @@ public static function finish(SplFixedArray $ctx, SplFixedArray $out) self::compress($ctx, $ctx[3]); $ctx[4] -= 128; if ($ctx[4] > 128) { - throw new Error('Failed to assert that buflen <= 128 bytes'); + throw new SodiumException('Failed to assert that buflen <= 128 bytes'); } for ($i = $ctx[4]; $i--;) { $ctx[3][$i] = $ctx[3][$i + 128]; @@ -401,7 +458,8 @@ public static function finish(SplFixedArray $ctx, SplFixedArray $out) $ctx[2][0] = self::new64(0xffffffff, 0xffffffff); for ($i = 256 - $ctx[4]; $i--;) { - $ctx[3][$i+$ctx[4]] = 0; + /** @var int $i */ + $ctx[3][$i + $ctx[4]] = 0; } self::compress($ctx, $ctx[3]); @@ -419,7 +477,13 @@ public static function finish(SplFixedArray $ctx, SplFixedArray $out) * @param SplFixedArray|null $key * @param int $outlen * @return SplFixedArray - * @throws Exception + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedMethodCall */ public static function init($key = null, $outlen = 64) { @@ -428,13 +492,13 @@ public static function init($key = null, $outlen = 64) if ($key !== null) { if (count($key) > 64) { - throw new Exception('Invalid key size'); + throw new SodiumException('Invalid key size'); } $klen = count($key); } if ($outlen > 64) { - throw new Exception('Invalid output size'); + throw new SodiumException('Invalid output size'); } $ctx = self::context(); @@ -498,7 +562,7 @@ public static function SplFixedArrayToString(SplFixedArray $a) $arr = $a->toArray(); $c = $a->count(); array_unshift($arr, str_repeat('C', $c)); - return call_user_func_array('pack', $arr); + return (string) (call_user_func_array('pack', $arr)); } /** @@ -507,10 +571,15 @@ public static function SplFixedArrayToString(SplFixedArray $a) * @param SplFixedArray[SplFixedArray] $ctx * @return string * @throws TypeError + * @psalm-suppress MixedArgument + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment + * @psalm-suppress MixedMethodCall */ public static function contextToString(SplFixedArray $ctx) { $str = ''; + /** @var array $ctxA */ $ctxA = $ctx[0]->toArray(); # uint64_t h[8]; @@ -526,6 +595,7 @@ public static function contextToString(SplFixedArray $ctx) # uint64_t t[2]; # uint64_t f[2]; for ($i = 1; $i < 3; ++$i) { + /** @var array $ctxA */ $ctxA = $ctx[$i]->toArray(); /** @var ParagonIE_Sodium_Core32_Int64 $ctxA1 */ $ctxA1 = $ctxA[0]; @@ -562,6 +632,10 @@ public static function contextToString(SplFixedArray $ctx) * * @param string $string * @return SplFixedArray + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayAssignment */ public static function stringToContext($string) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20.php index fcf9766ced3fd..6f8c0bff9f11a 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20.php @@ -19,6 +19,8 @@ class ParagonIE_Sodium_Core32_ChaCha20 extends ParagonIE_Sodium_Core32_Util * @param ParagonIE_Sodium_Core32_Int32 $c * @param ParagonIE_Sodium_Core32_Int32 $d * @return array + * @throws SodiumException + * @throws TypeError */ protected static function quarterRound( ParagonIE_Sodium_Core32_Int32 $a, @@ -57,7 +59,8 @@ protected static function quarterRound( * @param string $message * * @return string - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function encryptBytes( ParagonIE_Sodium_Core32_ChaCha20_Ctx $ctx, @@ -65,24 +68,22 @@ public static function encryptBytes( ) { $bytes = self::strlen($message); - /** - * @var ParagonIE_Sodium_Core32_Int32 $x0 - * @var ParagonIE_Sodium_Core32_Int32 $x1 - * @var ParagonIE_Sodium_Core32_Int32 $x2 - * @var ParagonIE_Sodium_Core32_Int32 $x3 - * @var ParagonIE_Sodium_Core32_Int32 $x4 - * @var ParagonIE_Sodium_Core32_Int32 $x5 - * @var ParagonIE_Sodium_Core32_Int32 $x6 - * @var ParagonIE_Sodium_Core32_Int32 $x7 - * @var ParagonIE_Sodium_Core32_Int32 $x8 - * @var ParagonIE_Sodium_Core32_Int32 $x9 - * @var ParagonIE_Sodium_Core32_Int32 $x10 - * @var ParagonIE_Sodium_Core32_Int32 $x11 - * @var ParagonIE_Sodium_Core32_Int32 $x12 - * @var ParagonIE_Sodium_Core32_Int32 $x13 - * @var ParagonIE_Sodium_Core32_Int32 $x14 - * @var ParagonIE_Sodium_Core32_Int32 $x15 - */ + /** @var ParagonIE_Sodium_Core32_Int32 $x0 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x1 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x2 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x3 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x4 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x5 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x6 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x7 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x8 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x9 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x10 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x11 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x12 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x13 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x14 */ + /** @var ParagonIE_Sodium_Core32_Int32 $x15 */ /* j0 = ctx->input[0]; @@ -102,21 +103,37 @@ public static function encryptBytes( j14 = ctx->input[14]; j15 = ctx->input[15]; */ + /** @var ParagonIE_Sodium_Core32_Int32 $j0 */ $j0 = $ctx[0]; + /** @var ParagonIE_Sodium_Core32_Int32 $j1 */ $j1 = $ctx[1]; + /** @var ParagonIE_Sodium_Core32_Int32 $j2 */ $j2 = $ctx[2]; + /** @var ParagonIE_Sodium_Core32_Int32 $j3 */ $j3 = $ctx[3]; + /** @var ParagonIE_Sodium_Core32_Int32 $j4 */ $j4 = $ctx[4]; + /** @var ParagonIE_Sodium_Core32_Int32 $j5 */ $j5 = $ctx[5]; + /** @var ParagonIE_Sodium_Core32_Int32 $j6 */ $j6 = $ctx[6]; + /** @var ParagonIE_Sodium_Core32_Int32 $j7 */ $j7 = $ctx[7]; + /** @var ParagonIE_Sodium_Core32_Int32 $j8 */ $j8 = $ctx[8]; + /** @var ParagonIE_Sodium_Core32_Int32 $j9 */ $j9 = $ctx[9]; + /** @var ParagonIE_Sodium_Core32_Int32 $j10 */ $j10 = $ctx[10]; + /** @var ParagonIE_Sodium_Core32_Int32 $j11 */ $j11 = $ctx[11]; + /** @var ParagonIE_Sodium_Core32_Int32 $j12 */ $j12 = $ctx[12]; + /** @var ParagonIE_Sodium_Core32_Int32 $j13 */ $j13 = $ctx[13]; + /** @var ParagonIE_Sodium_Core32_Int32 $j14 */ $j14 = $ctx[14]; + /** @var ParagonIE_Sodium_Core32_Int32 $j15 */ $j15 = $ctx[15]; $c = ''; @@ -314,6 +331,8 @@ public static function encryptBytes( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function stream($len = 64, $nonce = '', $key = '') { @@ -330,6 +349,8 @@ public static function stream($len = 64, $nonce = '', $key = '') * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function ietfStream($len, $nonce = '', $key = '') { @@ -347,6 +368,8 @@ public static function ietfStream($len, $nonce = '', $key = '') * @param string $key * @param string $ic * @return string + * @throws SodiumException + * @throws TypeError */ public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') { @@ -364,6 +387,8 @@ public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = ' * @param string $key * @param string $ic * @return string + * @throws SodiumException + * @throws TypeError */ public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/Ctx.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/Ctx.php index c4c46ae986bd4..996acf23e5cfc 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/Ctx.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/Ctx.php @@ -10,7 +10,7 @@ class ParagonIE_Sodium_Core32_ChaCha20_Ctx extends ParagonIE_Sodium_Core32_Util implements ArrayAccess { /** - * @var SplFixedArray + * @var SplFixedArray internally, */ protected $container; @@ -24,6 +24,8 @@ class ParagonIE_Sodium_Core32_ChaCha20_Ctx extends ParagonIE_Sodium_Core32_Util * @param string $counter The initial counter value. * Defaults to 8 0x00 bytes. * @throws InvalidArgumentException + * @throws SodiumException + * @throws TypeError */ public function __construct($key = '', $iv = '', $counter = '') { @@ -89,6 +91,7 @@ public function offsetSet($offset, $value) * * @param mixed $offset * @return bool + * @psalm-suppress MixedArrayOffset */ public function offsetExists($offset) { @@ -100,6 +103,7 @@ public function offsetExists($offset) * * @param mixed $offset * @return void + * @psalm-suppress MixedArrayOffset */ public function offsetUnset($offset) { @@ -111,6 +115,7 @@ public function offsetUnset($offset) * * @param mixed $offset * @return mixed|null + * @psalm-suppress MixedArrayOffset */ public function offsetGet($offset) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/IetfCtx.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/IetfCtx.php index b8a281a7696e1..eea08de85b0b3 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/IetfCtx.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/ChaCha20/IetfCtx.php @@ -19,6 +19,8 @@ class ParagonIE_Sodium_Core32_ChaCha20_IetfCtx extends ParagonIE_Sodium_Core32_C * @param string $counter The initial counter value. * Defaults to 4 0x00 bytes. * @throws InvalidArgumentException + * @throws SodiumException + * @throws TypeError */ public function __construct($key = '', $iv = '', $counter = '') { @@ -28,10 +30,10 @@ public function __construct($key = '', $iv = '', $counter = '') parent::__construct($key, self::substr($iv, 0, 8), $counter); if (!empty($counter)) { - $this->container[12] = ParagonIE_Sodium_Core32_Int32::fromString(self::substr($counter, 0, 4)); + $this->container[12] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($counter, 0, 4)); } - $this->container[13] = ParagonIE_Sodium_Core32_Int32::fromString(self::substr($iv, 0, 4)); - $this->container[14] = ParagonIE_Sodium_Core32_Int32::fromString(self::substr($iv, 4, 4)); - $this->container[15] = ParagonIE_Sodium_Core32_Int32::fromString(self::substr($iv, 4, 4)); + $this->container[13] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($iv, 0, 4)); + $this->container[14] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($iv, 4, 4)); + $this->container[15] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($iv, 8, 4)); } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519.php index ae879facddcdf..351a2f291f204 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519.php @@ -21,6 +21,8 @@ abstract class ParagonIE_Sodium_Core32_Curve25519 extends ParagonIE_Sodium_Core3 * @internal You should not use this directly from another application * * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError */ public static function fe_0() { @@ -46,6 +48,8 @@ public static function fe_0() * @internal You should not use this directly from another application * * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError */ public static function fe_1() { @@ -73,6 +77,10 @@ public static function fe_1() * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @param ParagonIE_Sodium_Core32_Curve25519_Fe $g * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedMethodCall */ public static function fe_add( ParagonIE_Sodium_Core32_Curve25519_Fe $f, @@ -82,6 +90,7 @@ public static function fe_add( for ($i = 0; $i < 10; ++$i) { $arr[$i] = $f[$i]->addInt32($g[$i]); } + /** @var array $arr */ return ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray($arr); } @@ -95,21 +104,28 @@ public static function fe_add( * @param int $b * @return ParagonIE_Sodium_Core32_Curve25519_Fe * @throws TypeError + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedMethodCall */ public static function fe_cmov( ParagonIE_Sodium_Core32_Curve25519_Fe $f, ParagonIE_Sodium_Core32_Curve25519_Fe $g, $b = 0 ) { + /** @var array $h */ $h = array(); for ($i = 0; $i < 10; ++$i) { - if (!($f[$i] instanceof ParagonIE_Sodium_Core32_Int32)) { - throw new TypeError(); + if (!($f[$i] instanceof ParagonIE_Sodium_Core32_Int32)) { + throw new TypeError('Expected Int32'); + } + if (!($g[$i] instanceof ParagonIE_Sodium_Core32_Int32)) { + throw new TypeError('Expected Int32'); } $h[$i] = $f[$i]->xorInt32( $f[$i]->xorInt32($g[$i])->mask($b) ); } + /** @var array $h */ return ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray($h); } @@ -136,6 +152,9 @@ public static function fe_copy(ParagonIE_Sodium_Core32_Curve25519_Fe $f) * @param string $s * @return ParagonIE_Sodium_Core32_Curve25519_Fe * @throws RangeException + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedMethodCall */ public static function fe_frombytes($s) { @@ -184,7 +203,7 @@ public static function fe_frombytes($s) ); $carry9 = $h9->addInt(1 << 24)->shiftRight(25); - $h0 = $h0->addInt32($carry9->mulInt(19)); + $h0 = $h0->addInt32($carry9->mulInt(19, 5)); $h9 = $h9->subInt32($carry9->shiftLeft(25)); $carry1 = $h1->addInt(1 << 24)->shiftRight(25); @@ -235,6 +254,10 @@ public static function fe_frombytes($s) * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $h * @return string + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedMethodCall */ public static function fe_tobytes(ParagonIE_Sodium_Core32_Curve25519_Fe $h) { @@ -260,22 +283,6 @@ public static function fe_tobytes(ParagonIE_Sodium_Core32_Curve25519_Fe $h) ->addInt64($f[8])->shiftRight(26) ->addInt64($f[9])->shiftRight(25); - - /* - $q = (self::mul(19, $f[9]) + (1 << 24)) >> 25; - $q = ($f[0] + $q) >> 26; - $q = ($f[1] + $q) >> 25; - $q = ($f[2] + $q) >> 26; - $q = ($f[3] + $q) >> 25; - $q = ($f[4] + $q) >> 26; - $q = ($f[5] + $q) >> 25; - $q = ($f[6] + $q) >> 26; - $q = ($f[7] + $q) >> 25; - $q = ($f[8] + $q) >> 26; - $q = ($f[9] + $q) >> 25; - - $f[0] += self::mul(19, $q); - */ $f[0] = $f[0]->addInt64($q->mulInt(19, 5)); $carry0 = $f[0]->shiftRight(26); @@ -317,27 +324,25 @@ public static function fe_tobytes(ParagonIE_Sodium_Core32_Curve25519_Fe $h) $carry9 = $f[9]->shiftRight(25); $f[9] = $f[9]->subInt64($carry9->shiftLeft(25)); - /** - * @var int $h0 - * @var int $h1 - * @var int $h2 - * @var int $h3 - * @var int $h4 - * @var int $h5 - * @var int $h6 - * @var int $h7 - * @var int $h8 - * @var int $h9 - */ + /** @var int $h0 */ $h0 = $f[0]->toInt32()->toInt(); + /** @var int $h1 */ $h1 = $f[1]->toInt32()->toInt(); + /** @var int $h2 */ $h2 = $f[2]->toInt32()->toInt(); + /** @var int $h3 */ $h3 = $f[3]->toInt32()->toInt(); + /** @var int $h4 */ $h4 = $f[4]->toInt32()->toInt(); + /** @var int $h5 */ $h5 = $f[5]->toInt32()->toInt(); + /** @var int $h6 */ $h6 = $f[6]->toInt32()->toInt(); + /** @var int $h7 */ $h7 = $f[7]->toInt32()->toInt(); + /** @var int $h8 */ $h8 = $f[8]->toInt32()->toInt(); + /** @var int $h9 */ $h9 = $f[9]->toInt32()->toInt(); /** @@ -387,11 +392,13 @@ public static function fe_tobytes(ParagonIE_Sodium_Core32_Curve25519_Fe $h) * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @return int + * @throws SodiumException + * @throws TypeError */ public static function fe_isnegative(ParagonIE_Sodium_Core32_Curve25519_Fe $f) { $str = self::fe_tobytes($f); - return self::chrToInt($str[0]) & 1; + return (int) (self::chrToInt($str[0]) & 1); } /** @@ -401,6 +408,8 @@ public static function fe_isnegative(ParagonIE_Sodium_Core32_Curve25519_Fe $f) * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @return bool + * @throws SodiumException + * @throws TypeError */ public static function fe_isnonzero(ParagonIE_Sodium_Core32_Curve25519_Fe $f) { @@ -408,7 +417,9 @@ public static function fe_isnonzero(ParagonIE_Sodium_Core32_Curve25519_Fe $f) if ($zero === null) { $zero = str_repeat("\x00", 32); } + /** @var string $str */ $str = self::fe_tobytes($f); + /** @var string $zero */ return !self::verify_32($str, $zero); } @@ -425,6 +436,8 @@ public static function fe_isnonzero(ParagonIE_Sodium_Core32_Curve25519_Fe $f) * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @param ParagonIE_Sodium_Core32_Curve25519_Fe $g * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError */ public static function fe_mul( ParagonIE_Sodium_Core32_Curve25519_Fe $f, @@ -493,106 +506,106 @@ public static function fe_mul( $f7_2 = $f7->shiftLeft(1); /** @var ParagonIE_Sodium_Core32_Int64 $f9_2 */ $f9_2 = $f9->shiftLeft(1); - $f0g0 = $f0->mulInt64($g0); - $f0g1 = $f0->mulInt64($g1); - $f0g2 = $f0->mulInt64($g2); - $f0g3 = $f0->mulInt64($g3); - $f0g4 = $f0->mulInt64($g4); - $f0g5 = $f0->mulInt64($g5); - $f0g6 = $f0->mulInt64($g6); - $f0g7 = $f0->mulInt64($g7); - $f0g8 = $f0->mulInt64($g8); - $f0g9 = $f0->mulInt64($g9); - $f1g0 = $f1->mulInt64($g0); - $f1g1_2 = $f1_2->mulInt64($g1); - $f1g2 = $f1->mulInt64($g2); - $f1g3_2 = $f1_2->mulInt64($g3); - $f1g4 = $f1->mulInt64($g4); - $f1g5_2 = $f1_2->mulInt64($g5); - $f1g6 = $f1->mulInt64($g6); - $f1g7_2 = $f1_2->mulInt64($g7); - $f1g8 = $f1->mulInt64($g8); - $f1g9_38 = $f1_2->mulInt64($g9_19); - $f2g0 = $f2->mulInt64($g0); - $f2g1 = $f2->mulInt64($g1); - $f2g2 = $f2->mulInt64($g2); - $f2g3 = $f2->mulInt64($g3); - $f2g4 = $f2->mulInt64($g4); - $f2g5 = $f2->mulInt64($g5); - $f2g6 = $f2->mulInt64($g6); - $f2g7 = $f2->mulInt64($g7); - $f2g8_19 = $f2->mulInt64($g8_19); - $f2g9_19 = $f2->mulInt64($g9_19); - $f3g0 = $f3->mulInt64($g0); - $f3g1_2 = $f3_2->mulInt64($g1); - $f3g2 = $f3->mulInt64($g2); - $f3g3_2 = $f3_2->mulInt64($g3); - $f3g4 = $f3->mulInt64($g4); - $f3g5_2 = $f3_2->mulInt64($g5); - $f3g6 = $f3->mulInt64($g6); - $f3g7_38 = $f3_2->mulInt64($g7_19); - $f3g8_19 = $f3->mulInt64($g8_19); - $f3g9_38 = $f3_2->mulInt64($g9_19); - $f4g0 = $f4->mulInt64($g0); - $f4g1 = $f4->mulInt64($g1); - $f4g2 = $f4->mulInt64($g2); - $f4g3 = $f4->mulInt64($g3); - $f4g4 = $f4->mulInt64($g4); - $f4g5 = $f4->mulInt64($g5); - $f4g6_19 = $f4->mulInt64($g6_19); - $f4g7_19 = $f4->mulInt64($g7_19); - $f4g8_19 = $f4->mulInt64($g8_19); - $f4g9_19 = $f4->mulInt64($g9_19); - $f5g0 = $f5->mulInt64($g0); - $f5g1_2 = $f5_2->mulInt64($g1); - $f5g2 = $f5->mulInt64($g2); - $f5g3_2 = $f5_2->mulInt64($g3); - $f5g4 = $f5->mulInt64($g4); - $f5g5_38 = $f5_2->mulInt64($g5_19); - $f5g6_19 = $f5->mulInt64($g6_19); - $f5g7_38 = $f5_2->mulInt64($g7_19); - $f5g8_19 = $f5->mulInt64($g8_19); - $f5g9_38 = $f5_2->mulInt64($g9_19); - $f6g0 = $f6->mulInt64($g0); - $f6g1 = $f6->mulInt64($g1); - $f6g2 = $f6->mulInt64($g2); - $f6g3 = $f6->mulInt64($g3); - $f6g4_19 = $f6->mulInt64($g4_19); - $f6g5_19 = $f6->mulInt64($g5_19); - $f6g6_19 = $f6->mulInt64($g6_19); - $f6g7_19 = $f6->mulInt64($g7_19); - $f6g8_19 = $f6->mulInt64($g8_19); - $f6g9_19 = $f6->mulInt64($g9_19); - $f7g0 = $f7->mulInt64($g0); - $f7g1_2 = $f7_2->mulInt64($g1); - $f7g2 = $f7->mulInt64($g2); - $f7g3_38 = $f7_2->mulInt64($g3_19); - $f7g4_19 = $f7->mulInt64($g4_19); - $f7g5_38 = $f7_2->mulInt64($g5_19); - $f7g6_19 = $f7->mulInt64($g6_19); - $f7g7_38 = $f7_2->mulInt64($g7_19); - $f7g8_19 = $f7->mulInt64($g8_19); - $f7g9_38 = $f7_2->mulInt64($g9_19); - $f8g0 = $f8->mulInt64($g0); - $f8g1 = $f8->mulInt64($g1); - $f8g2_19 = $f8->mulInt64($g2_19); - $f8g3_19 = $f8->mulInt64($g3_19); - $f8g4_19 = $f8->mulInt64($g4_19); - $f8g5_19 = $f8->mulInt64($g5_19); - $f8g6_19 = $f8->mulInt64($g6_19); - $f8g7_19 = $f8->mulInt64($g7_19); - $f8g8_19 = $f8->mulInt64($g8_19); - $f8g9_19 = $f8->mulInt64($g9_19); - $f9g0 = $f9->mulInt64($g0); - $f9g1_38 = $f9_2->mulInt64($g1_19); - $f9g2_19 = $f9->mulInt64($g2_19); - $f9g3_38 = $f9_2->mulInt64($g3_19); - $f9g4_19 = $f9->mulInt64($g4_19); - $f9g5_38 = $f9_2->mulInt64($g5_19); - $f9g6_19 = $f9->mulInt64($g6_19); - $f9g7_38 = $f9_2->mulInt64($g7_19); - $f9g8_19 = $f9->mulInt64($g8_19); - $f9g9_38 = $f9_2->mulInt64($g9_19); + $f0g0 = $f0->mulInt64($g0, 31); + $f0g1 = $f0->mulInt64($g1, 31); + $f0g2 = $f0->mulInt64($g2, 31); + $f0g3 = $f0->mulInt64($g3, 31); + $f0g4 = $f0->mulInt64($g4, 31); + $f0g5 = $f0->mulInt64($g5, 31); + $f0g6 = $f0->mulInt64($g6, 31); + $f0g7 = $f0->mulInt64($g7, 31); + $f0g8 = $f0->mulInt64($g8, 31); + $f0g9 = $f0->mulInt64($g9, 31); + $f1g0 = $f1->mulInt64($g0, 31); + $f1g1_2 = $f1_2->mulInt64($g1, 31); + $f1g2 = $f1->mulInt64($g2, 31); + $f1g3_2 = $f1_2->mulInt64($g3, 31); + $f1g4 = $f1->mulInt64($g4, 31); + $f1g5_2 = $f1_2->mulInt64($g5, 31); + $f1g6 = $f1->mulInt64($g6, 31); + $f1g7_2 = $f1_2->mulInt64($g7, 31); + $f1g8 = $f1->mulInt64($g8, 31); + $f1g9_38 = $g9_19->mulInt64($f1_2, 31); + $f2g0 = $f2->mulInt64($g0, 31); + $f2g1 = $f2->mulInt64($g1, 31); + $f2g2 = $f2->mulInt64($g2, 31); + $f2g3 = $f2->mulInt64($g3, 31); + $f2g4 = $f2->mulInt64($g4, 31); + $f2g5 = $f2->mulInt64($g5, 31); + $f2g6 = $f2->mulInt64($g6, 31); + $f2g7 = $f2->mulInt64($g7, 31); + $f2g8_19 = $g8_19->mulInt64($f2, 31); + $f2g9_19 = $g9_19->mulInt64($f2, 31); + $f3g0 = $f3->mulInt64($g0, 31); + $f3g1_2 = $f3_2->mulInt64($g1, 31); + $f3g2 = $f3->mulInt64($g2, 31); + $f3g3_2 = $f3_2->mulInt64($g3, 31); + $f3g4 = $f3->mulInt64($g4, 31); + $f3g5_2 = $f3_2->mulInt64($g5, 31); + $f3g6 = $f3->mulInt64($g6, 31); + $f3g7_38 = $g7_19->mulInt64($f3_2, 31); + $f3g8_19 = $g8_19->mulInt64($f3, 31); + $f3g9_38 = $g9_19->mulInt64($f3_2, 31); + $f4g0 = $f4->mulInt64($g0, 31); + $f4g1 = $f4->mulInt64($g1, 31); + $f4g2 = $f4->mulInt64($g2, 31); + $f4g3 = $f4->mulInt64($g3, 31); + $f4g4 = $f4->mulInt64($g4, 31); + $f4g5 = $f4->mulInt64($g5, 31); + $f4g6_19 = $g6_19->mulInt64($f4, 31); + $f4g7_19 = $g7_19->mulInt64($f4, 31); + $f4g8_19 = $g8_19->mulInt64($f4, 31); + $f4g9_19 = $g9_19->mulInt64($f4, 31); + $f5g0 = $f5->mulInt64($g0, 31); + $f5g1_2 = $f5_2->mulInt64($g1, 31); + $f5g2 = $f5->mulInt64($g2, 31); + $f5g3_2 = $f5_2->mulInt64($g3, 31); + $f5g4 = $f5->mulInt64($g4, 31); + $f5g5_38 = $g5_19->mulInt64($f5_2, 31); + $f5g6_19 = $g6_19->mulInt64($f5, 31); + $f5g7_38 = $g7_19->mulInt64($f5_2, 31); + $f5g8_19 = $g8_19->mulInt64($f5, 31); + $f5g9_38 = $g9_19->mulInt64($f5_2, 31); + $f6g0 = $f6->mulInt64($g0, 31); + $f6g1 = $f6->mulInt64($g1, 31); + $f6g2 = $f6->mulInt64($g2, 31); + $f6g3 = $f6->mulInt64($g3, 31); + $f6g4_19 = $g4_19->mulInt64($f6, 31); + $f6g5_19 = $g5_19->mulInt64($f6, 31); + $f6g6_19 = $g6_19->mulInt64($f6, 31); + $f6g7_19 = $g7_19->mulInt64($f6, 31); + $f6g8_19 = $g8_19->mulInt64($f6, 31); + $f6g9_19 = $g9_19->mulInt64($f6, 31); + $f7g0 = $f7->mulInt64($g0, 31); + $f7g1_2 = $g1->mulInt64($f7_2, 31); + $f7g2 = $f7->mulInt64($g2, 31); + $f7g3_38 = $g3_19->mulInt64($f7_2, 31); + $f7g4_19 = $g4_19->mulInt64($f7, 31); + $f7g5_38 = $g5_19->mulInt64($f7_2, 31); + $f7g6_19 = $g6_19->mulInt64($f7, 31); + $f7g7_38 = $g7_19->mulInt64($f7_2, 31); + $f7g8_19 = $g8_19->mulInt64($f7, 31); + $f7g9_38 = $g9_19->mulInt64($f7_2, 31); + $f8g0 = $f8->mulInt64($g0, 31); + $f8g1 = $f8->mulInt64($g1, 31); + $f8g2_19 = $f8->mulInt64($g2_19, 31); + $f8g3_19 = $f8->mulInt64($g3_19, 31); + $f8g4_19 = $f8->mulInt64($g4_19, 31); + $f8g5_19 = $f8->mulInt64($g5_19, 31); + $f8g6_19 = $f8->mulInt64($g6_19, 31); + $f8g7_19 = $f8->mulInt64($g7_19, 31); + $f8g8_19 = $f8->mulInt64($g8_19, 31); + $f8g9_19 = $f8->mulInt64($g9_19, 31); + $f9g0 = $f9->mulInt64($g0, 31); + $f9g1_38 = $f9_2->mulInt64($g1_19, 31); + $f9g2_19 = $f9->mulInt64($g2_19, 31); + $f9g3_38 = $f9_2->mulInt64($g3_19, 31); + $f9g4_19 = $f9->mulInt64($g4_19, 31); + $f9g5_38 = $f9_2->mulInt64($g5_19, 31); + $f9g6_19 = $f9->mulInt64($g6_19, 31); + $f9g7_38 = $f9_2->mulInt64($g7_19, 31); + $f9g8_19 = $f9->mulInt64($g8_19, 31); + $f9g9_38 = $f9_2->mulInt64($g9_19, 31); // $h0 = $f0g0 + $f1g9_38 + $f2g8_19 + $f3g7_38 + $f4g6_19 + $f5g5_38 + $f6g4_19 + $f7g3_38 + $f8g2_19 + $f9g1_38; $h0 = $f0g0->addInt64($f1g9_38)->addInt64($f2g8_19)->addInt64($f3g7_38) @@ -734,6 +747,8 @@ public static function fe_mul( * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedMethodCall */ public static function fe_neg(ParagonIE_Sodium_Core32_Curve25519_Fe $f) { @@ -753,30 +768,31 @@ public static function fe_neg(ParagonIE_Sodium_Core32_Curve25519_Fe $f) * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedMethodCall */ public static function fe_sq(ParagonIE_Sodium_Core32_Curve25519_Fe $f) { - /** - * @var ParagonIE_Sodium_Core32_Int64 $f0 - * @var ParagonIE_Sodium_Core32_Int64 $f1 - * @var ParagonIE_Sodium_Core32_Int64 $f2 - * @var ParagonIE_Sodium_Core32_Int64 $f3 - * @var ParagonIE_Sodium_Core32_Int64 $f4 - * @var ParagonIE_Sodium_Core32_Int64 $f5 - * @var ParagonIE_Sodium_Core32_Int64 $f6 - * @var ParagonIE_Sodium_Core32_Int64 $f7 - * @var ParagonIE_Sodium_Core32_Int64 $f8 - * @var ParagonIE_Sodium_Core32_Int64 $f9 - */ + /** @var ParagonIE_Sodium_Core32_Int64 $f0 */ $f0 = $f[0]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f1 */ $f1 = $f[1]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f2 */ $f2 = $f[2]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f3 */ $f3 = $f[3]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f4 */ $f4 = $f[4]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f5 */ $f5 = $f[5]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f6 */ $f6 = $f[6]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f7 */ $f7 = $f[7]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f8 */ $f8 = $f[8]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f9 */ $f9 = $f[9]->toInt64(); /** @var ParagonIE_Sodium_Core32_Int64 $f0_2 */ @@ -794,61 +810,70 @@ public static function fe_sq(ParagonIE_Sodium_Core32_Curve25519_Fe $f) $f8_19 = $f8->mulInt(19, 5); $f9_38 = $f9->mulInt(38, 6); /** @var ParagonIE_Sodium_Core32_Int64 $f0f0*/ - $f0f0 = $f0->mulInt64($f0); - $f0f1_2 = $f0_2->mulInt64($f1); - $f0f2_2 = $f0_2->mulInt64($f2); - $f0f3_2 = $f0_2->mulInt64($f3); - $f0f4_2 = $f0_2->mulInt64($f4); - $f0f5_2 = $f0_2->mulInt64($f5); - $f0f6_2 = $f0_2->mulInt64($f6); - $f0f7_2 = $f0_2->mulInt64($f7); - $f0f8_2 = $f0_2->mulInt64($f8); - $f0f9_2 = $f0_2->mulInt64($f9); - $f1f1_2 = $f1_2->mulInt64($f1); - $f1f2_2 = $f1_2->mulInt64($f2); - $f1f3_4 = $f1_2->mulInt64($f3_2); - $f1f4_2 = $f1_2->mulInt64($f4); - $f1f5_4 = $f1_2->mulInt64($f5_2); - $f1f6_2 = $f1_2->mulInt64($f6); - $f1f7_4 = $f1_2->mulInt64($f7_2); - $f1f8_2 = $f1_2->mulInt64($f8); - $f1f9_76 = $f1_2->mulInt64($f9_38); - $f2f2 = $f2->mulInt64($f2); - $f2f3_2 = $f2_2->mulInt64($f3); - $f2f4_2 = $f2_2->mulInt64($f4); - $f2f5_2 = $f2_2->mulInt64($f5); - $f2f6_2 = $f2_2->mulInt64($f6); - $f2f7_2 = $f2_2->mulInt64($f7); - $f2f8_38 = $f2_2->mulInt64($f8_19); - $f2f9_38 = $f2->mulInt64($f9_38); - $f3f3_2 = $f3_2->mulInt64($f3); - $f3f4_2 = $f3_2->mulInt64($f4); - $f3f5_4 = $f3_2->mulInt64($f5_2); - $f3f6_2 = $f3_2->mulInt64($f6); - $f3f7_76 = $f3_2->mulInt64($f7_38); - $f3f8_38 = $f3_2->mulInt64($f8_19); - $f3f9_76 = $f3_2->mulInt64($f9_38); - $f4f4 = $f4->mulInt64($f4); - $f4f5_2 = $f4_2->mulInt64($f5); - $f4f6_38 = $f4_2->mulInt64($f6_19); - $f4f7_38 = $f4->mulInt64($f7_38); - $f4f8_38 = $f4_2->mulInt64($f8_19); - $f4f9_38 = $f4->mulInt64($f9_38); - $f5f5_38 = $f5->mulInt64($f5_38); - $f5f6_38 = $f5_2->mulInt64($f6_19); - $f5f7_76 = $f5_2->mulInt64($f7_38); - $f5f8_38 = $f5_2->mulInt64($f8_19); - $f5f9_76 = $f5_2->mulInt64($f9_38); - $f6f6_19 = $f6->mulInt64($f6_19); - $f6f7_38 = $f6->mulInt64($f7_38); - $f6f8_38 = $f6_2->mulInt64($f8_19); - $f6f9_38 = $f6->mulInt64($f9_38); - $f7f7_38 = $f7->mulInt64($f7_38); - $f7f8_38 = $f7_2->mulInt64($f8_19); - $f7f9_76 = $f7_2->mulInt64($f9_38); - $f8f8_19 = $f8->mulInt64($f8_19); - $f8f9_38 = $f8->mulInt64($f9_38); - $f9f9_38 = $f9->mulInt64($f9_38); + $f0f0 = $f0->mulInt64($f0, 31); + $f0f1_2 = $f0_2->mulInt64($f1, 31); + $f0f2_2 = $f0_2->mulInt64($f2, 31); + $f0f3_2 = $f0_2->mulInt64($f3, 31); + $f0f4_2 = $f0_2->mulInt64($f4, 31); + $f0f5_2 = $f0_2->mulInt64($f5, 31); + $f0f6_2 = $f0_2->mulInt64($f6, 31); + $f0f7_2 = $f0_2->mulInt64($f7, 31); + $f0f8_2 = $f0_2->mulInt64($f8, 31); + $f0f9_2 = $f0_2->mulInt64($f9, 31); + + $f1f1_2 = $f1_2->mulInt64($f1, 31); + $f1f2_2 = $f1_2->mulInt64($f2, 31); + $f1f3_4 = $f1_2->mulInt64($f3_2, 31); + $f1f4_2 = $f1_2->mulInt64($f4, 31); + $f1f5_4 = $f1_2->mulInt64($f5_2, 31); + $f1f6_2 = $f1_2->mulInt64($f6, 31); + $f1f7_4 = $f1_2->mulInt64($f7_2, 31); + $f1f8_2 = $f1_2->mulInt64($f8, 31); + $f1f9_76 = $f1_2->mulInt64($f9_38, 31); + + $f2f2 = $f2->mulInt64($f2, 31); + $f2f3_2 = $f2_2->mulInt64($f3, 31); + $f2f4_2 = $f2_2->mulInt64($f4, 31); + $f2f5_2 = $f2_2->mulInt64($f5, 31); + $f2f6_2 = $f2_2->mulInt64($f6, 31); + $f2f7_2 = $f2_2->mulInt64($f7, 31); + $f2f8_38 = $f8_19->mulInt64($f2_2, 31); + $f2f9_38 = $f9_38->mulInt64($f2, 31); + + $f3f3_2 = $f3_2->mulInt64($f3, 31); + $f3f4_2 = $f3_2->mulInt64($f4, 31); + $f3f5_4 = $f3_2->mulInt64($f5_2, 31); + $f3f6_2 = $f3_2->mulInt64($f6, 31); + $f3f7_76 = $f7_38->mulInt64($f3_2, 31); + $f3f8_38 = $f8_19->mulInt64($f3_2, 31); + $f3f9_76 = $f9_38->mulInt64($f3_2, 31); + + $f4f4 = $f4->mulInt64($f4, 31); + $f4f5_2 = $f4_2->mulInt64($f5, 31); + $f4f6_38 = $f4_2->mulInt64($f6_19, 31); + $f4f7_38 = $f7_38->mulInt64($f4, 31); + $f4f8_38 = $f8_19->mulInt64($f4_2, 31); + $f4f9_38 = $f9_38->mulInt64($f4, 31); + + $f5f5_38 = $f5_38->mulInt64($f5, 31); + $f5f6_38 = $f6_19->mulInt64($f5_2, 31); + $f5f7_76 = $f7_38->mulInt64($f5_2, 31); + $f5f8_38 = $f8_19->mulInt64($f5_2, 31); + $f5f9_76 = $f9_38->mulInt64($f5_2, 31); + + $f6f6_19 = $f6_19->mulInt64($f6, 31); + $f6f7_38 = $f7_38->mulInt64($f6, 31); + $f6f8_38 = $f8_19->mulInt64($f6_2, 31); + $f6f9_38 = $f6->mulInt64($f9_38, 31); + + $f7f7_38 = $f7->mulInt64($f7_38, 31); + $f7f8_38 = $f7_2->mulInt64($f8_19, 31); + $f7f9_76 = $f7_2->mulInt64($f9_38, 31); + + $f8f8_19 = $f8->mulInt64($f8_19, 31); + $f8f9_38 = $f8->mulInt64($f9_38, 31); + + $f9f9_38 = $f9->mulInt64($f9_38, 31); $h0 = $f0f0->addInt64($f1f9_76)->addInt64($f2f8_38)->addInt64($f3f7_76)->addInt64($f4f6_38)->addInt64($f5f5_38); $h1 = $f0f1_2->addInt64($f2f9_38)->addInt64($f3f8_38)->addInt64($f4f7_38)->addInt64($f5f6_38); @@ -947,31 +972,31 @@ public static function fe_sq(ParagonIE_Sodium_Core32_Curve25519_Fe $f) * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedMethodCall */ public static function fe_sq2(ParagonIE_Sodium_Core32_Curve25519_Fe $f) { - /** - * @var ParagonIE_Sodium_Core32_Int64 $f0 - * @var ParagonIE_Sodium_Core32_Int64 $f1 - * @var ParagonIE_Sodium_Core32_Int64 $f2 - * @var ParagonIE_Sodium_Core32_Int64 $f3 - * @var ParagonIE_Sodium_Core32_Int64 $f4 - * @var ParagonIE_Sodium_Core32_Int64 $f5 - * @var ParagonIE_Sodium_Core32_Int64 $f6 - * @var ParagonIE_Sodium_Core32_Int64 $f7 - * @var ParagonIE_Sodium_Core32_Int64 $f8 - * @var ParagonIE_Sodium_Core32_Int64 $f9 - * @var ParagonIE_Sodium_Core32_Int64 $h0 - */ + /** @var ParagonIE_Sodium_Core32_Int64 $f0 */ $f0 = $f[0]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f1 */ $f1 = $f[1]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f2 */ $f2 = $f[2]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f3 */ $f3 = $f[3]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f4 */ $f4 = $f[4]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f5 */ $f5 = $f[5]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f6 */ $f6 = $f[6]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f7 */ $f7 = $f[7]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f8 */ $f8 = $f[8]->toInt64(); + /** @var ParagonIE_Sodium_Core32_Int64 $f9 */ $f9 = $f[9]->toInt64(); $f0_2 = $f0->shiftLeft(1); @@ -987,61 +1012,61 @@ public static function fe_sq2(ParagonIE_Sodium_Core32_Curve25519_Fe $f) $f7_38 = $f7->mulInt(38, 6); /* 1.959375*2^30 */ $f8_19 = $f8->mulInt(19, 5); /* 1.959375*2^30 */ $f9_38 = $f9->mulInt(38, 6); /* 1.959375*2^30 */ - $f0f0 = $f0->mulInt64($f0); - $f0f1_2 = $f0_2->mulInt64($f1); - $f0f2_2 = $f0_2->mulInt64($f2); - $f0f3_2 = $f0_2->mulInt64($f3); - $f0f4_2 = $f0_2->mulInt64($f4); - $f0f5_2 = $f0_2->mulInt64($f5); - $f0f6_2 = $f0_2->mulInt64($f6); - $f0f7_2 = $f0_2->mulInt64($f7); - $f0f8_2 = $f0_2->mulInt64($f8); - $f0f9_2 = $f0_2->mulInt64($f9); - $f1f1_2 = $f1_2->mulInt64($f1); - $f1f2_2 = $f1_2->mulInt64($f2); - $f1f3_4 = $f1_2->mulInt64($f3_2); - $f1f4_2 = $f1_2->mulInt64($f4); - $f1f5_4 = $f1_2->mulInt64($f5_2); - $f1f6_2 = $f1_2->mulInt64($f6); - $f1f7_4 = $f1_2->mulInt64($f7_2); - $f1f8_2 = $f1_2->mulInt64($f8); - $f1f9_76 = $f1_2->mulInt64($f9_38); - $f2f2 = $f2->mulInt64($f2); - $f2f3_2 = $f2_2->mulInt64($f3); - $f2f4_2 = $f2_2->mulInt64($f4); - $f2f5_2 = $f2_2->mulInt64($f5); - $f2f6_2 = $f2_2->mulInt64($f6); - $f2f7_2 = $f2_2->mulInt64($f7); - $f2f8_38 = $f2_2->mulInt64($f8_19); - $f2f9_38 = $f2->mulInt64($f9_38); - $f3f3_2 = $f3_2->mulInt64($f3); - $f3f4_2 = $f3_2->mulInt64($f4); - $f3f5_4 = $f3_2->mulInt64($f5_2); - $f3f6_2 = $f3_2->mulInt64($f6); - $f3f7_76 = $f3_2->mulInt64($f7_38); - $f3f8_38 = $f3_2->mulInt64($f8_19); - $f3f9_76 = $f3_2->mulInt64($f9_38); - $f4f4 = $f4->mulInt64($f4); - $f4f5_2 = $f4_2->mulInt64($f5); - $f4f6_38 = $f4_2->mulInt64($f6_19); - $f4f7_38 = $f4->mulInt64($f7_38); - $f4f8_38 = $f4_2->mulInt64($f8_19); - $f4f9_38 = $f4->mulInt64($f9_38); - $f5f5_38 = $f5->mulInt64($f5_38); - $f5f6_38 = $f5_2->mulInt64($f6_19); - $f5f7_76 = $f5_2->mulInt64($f7_38); - $f5f8_38 = $f5_2->mulInt64($f8_19); - $f5f9_76 = $f5_2->mulInt64($f9_38); - $f6f6_19 = $f6->mulInt64($f6_19); - $f6f7_38 = $f6->mulInt64($f7_38); - $f6f8_38 = $f6_2->mulInt64($f8_19); - $f6f9_38 = $f6->mulInt64($f9_38); - $f7f7_38 = $f7->mulInt64($f7_38); - $f7f8_38 = $f7_2->mulInt64($f8_19); - $f7f9_76 = $f7_2->mulInt64($f9_38); - $f8f8_19 = $f8->mulInt64($f8_19); - $f8f9_38 = $f8->mulInt64($f9_38); - $f9f9_38 = $f9->mulInt64($f9_38); + $f0f0 = $f0->mulInt64($f0, 31); + $f0f1_2 = $f0_2->mulInt64($f1, 31); + $f0f2_2 = $f0_2->mulInt64($f2, 31); + $f0f3_2 = $f0_2->mulInt64($f3, 31); + $f0f4_2 = $f0_2->mulInt64($f4, 31); + $f0f5_2 = $f0_2->mulInt64($f5, 31); + $f0f6_2 = $f0_2->mulInt64($f6, 31); + $f0f7_2 = $f0_2->mulInt64($f7, 31); + $f0f8_2 = $f0_2->mulInt64($f8, 31); + $f0f9_2 = $f0_2->mulInt64($f9, 31); + $f1f1_2 = $f1_2->mulInt64($f1, 31); + $f1f2_2 = $f1_2->mulInt64($f2, 31); + $f1f3_4 = $f1_2->mulInt64($f3_2, 31); + $f1f4_2 = $f1_2->mulInt64($f4, 31); + $f1f5_4 = $f1_2->mulInt64($f5_2, 31); + $f1f6_2 = $f1_2->mulInt64($f6, 31); + $f1f7_4 = $f1_2->mulInt64($f7_2, 31); + $f1f8_2 = $f1_2->mulInt64($f8, 31); + $f1f9_76 = $f1_2->mulInt64($f9_38, 31); + $f2f2 = $f2->mulInt64($f2, 31); + $f2f3_2 = $f2_2->mulInt64($f3, 31); + $f2f4_2 = $f2_2->mulInt64($f4, 31); + $f2f5_2 = $f2_2->mulInt64($f5, 31); + $f2f6_2 = $f2_2->mulInt64($f6, 31); + $f2f7_2 = $f2_2->mulInt64($f7, 31); + $f2f8_38 = $f2_2->mulInt64($f8_19, 31); + $f2f9_38 = $f2->mulInt64($f9_38, 31); + $f3f3_2 = $f3_2->mulInt64($f3, 31); + $f3f4_2 = $f3_2->mulInt64($f4, 31); + $f3f5_4 = $f3_2->mulInt64($f5_2, 31); + $f3f6_2 = $f3_2->mulInt64($f6, 31); + $f3f7_76 = $f3_2->mulInt64($f7_38, 31); + $f3f8_38 = $f3_2->mulInt64($f8_19, 31); + $f3f9_76 = $f3_2->mulInt64($f9_38, 31); + $f4f4 = $f4->mulInt64($f4, 31); + $f4f5_2 = $f4_2->mulInt64($f5, 31); + $f4f6_38 = $f4_2->mulInt64($f6_19, 31); + $f4f7_38 = $f4->mulInt64($f7_38, 31); + $f4f8_38 = $f4_2->mulInt64($f8_19, 31); + $f4f9_38 = $f4->mulInt64($f9_38, 31); + $f5f5_38 = $f5->mulInt64($f5_38, 31); + $f5f6_38 = $f5_2->mulInt64($f6_19, 31); + $f5f7_76 = $f5_2->mulInt64($f7_38, 31); + $f5f8_38 = $f5_2->mulInt64($f8_19, 31); + $f5f9_76 = $f5_2->mulInt64($f9_38, 31); + $f6f6_19 = $f6->mulInt64($f6_19, 31); + $f6f7_38 = $f6->mulInt64($f7_38, 31); + $f6f8_38 = $f6_2->mulInt64($f8_19, 31); + $f6f9_38 = $f6->mulInt64($f9_38, 31); + $f7f7_38 = $f7->mulInt64($f7_38, 31); + $f7f8_38 = $f7_2->mulInt64($f8_19, 31); + $f7f9_76 = $f7_2->mulInt64($f9_38, 31); + $f8f8_19 = $f8->mulInt64($f8_19, 31); + $f8f9_38 = $f8->mulInt64($f9_38, 31); + $f9f9_38 = $f9->mulInt64($f9_38, 31); $h0 = $f0f0->addInt64($f1f9_76)->addInt64($f2f8_38)->addInt64($f3f7_76)->addInt64($f4f6_38)->addInt64($f5f5_38); $h1 = $f0f1_2->addInt64($f2f9_38)->addInt64($f3f8_38)->addInt64($f4f7_38)->addInt64($f5f6_38); @@ -1140,11 +1165,6 @@ public static function fe_sq2(ParagonIE_Sodium_Core32_Curve25519_Fe $f) $h9->toInt32() ) ); -/* - return ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( - array($h0, $h1, $h2, $h3, $h4, $h5, $h6, $h7, $h8, $h9) - ); -*/ } /** @@ -1152,6 +1172,8 @@ public static function fe_sq2(ParagonIE_Sodium_Core32_Curve25519_Fe $f) * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $Z * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError */ public static function fe_invert(ParagonIE_Sodium_Core32_Curve25519_Fe $Z) { @@ -1212,6 +1234,8 @@ public static function fe_invert(ParagonIE_Sodium_Core32_Curve25519_Fe $Z) * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $z * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError */ public static function fe_pow22523(ParagonIE_Sodium_Core32_Curve25519_Fe $z) { @@ -1338,6 +1362,10 @@ public static function fe_pow22523(ParagonIE_Sodium_Core32_Curve25519_Fe $z) * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @param ParagonIE_Sodium_Core32_Curve25519_Fe $g * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedMethodCall + * @psalm-suppress MixedTypeCoercion */ public static function fe_sub(ParagonIE_Sodium_Core32_Curve25519_Fe $f, ParagonIE_Sodium_Core32_Curve25519_Fe $g) { @@ -1367,6 +1395,8 @@ public static function fe_sub(ParagonIE_Sodium_Core32_Curve25519_Fe $f, ParagonI * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p * @param ParagonIE_Sodium_Core32_Curve25519_Ge_Cached $q * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 + * @throws SodiumException + * @throws TypeError */ public static function ge_add( ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p, @@ -1393,6 +1423,9 @@ public static function ge_add( * @ref https://github.com/jedisct1/libsodium/blob/157c4a80c13b117608aeae12178b2d38825f9f8f/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c#L1185-L1215 * @param string $a * @return array + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArrayOffset */ public static function slide($a) { @@ -1401,12 +1434,15 @@ public static function slide($a) $a = str_pad($a, 256, '0', STR_PAD_RIGHT); } } + /** @var array $r */ $r = array(); for ($i = 0; $i < 256; ++$i) { - $r[$i] = 1 & ( - self::chrToInt($a[$i >> 3]) - >> - ($i & 7) + $r[$i] = (int) (1 & + ( + self::chrToInt($a[$i >> 3]) + >> + ($i & 7) + ) ); } @@ -1441,11 +1477,14 @@ public static function slide($a) * * @param string $s * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P3 + * @throws SodiumException + * @throws TypeError */ public static function ge_frombytes_negate_vartime($s) { static $d = null; if (!$d) { + /** @var ParagonIE_Sodium_Core32_Curve25519_Fe $d */ $d = ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( array( ParagonIE_Sodium_Core32_Int32::fromInt(self::$d[0]), @@ -1475,6 +1514,7 @@ public static function ge_frombytes_negate_vartime($s) # fe_sub(u,u,h->Z); /* u = y^2-1 */ # fe_add(v,v,h->Z); /* v = dy^2+1 */ $u = self::fe_sq($h->Y); + /** @var ParagonIE_Sodium_Core32_Curve25519_Fe $d */ $v = self::fe_mul($u, $d); $u = self::fe_sub($u, $h->Z); /* u = y^2 - 1 */ $v = self::fe_add($v, $h->Z); /* v = dy^2 + 1 */ @@ -1518,7 +1558,7 @@ public static function ge_frombytes_negate_vartime($s) } $h->X = self::fe_mul( $h->X, - ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray(self::$sqrtm1) + ParagonIE_Sodium_Core32_Curve25519_Fe::fromIntArray(self::$sqrtm1) ); } @@ -1542,6 +1582,8 @@ public static function ge_frombytes_negate_vartime($s) * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p * @param ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp $q * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 + * @throws SodiumException + * @throws TypeError */ public static function ge_madd( ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 $R, @@ -1570,6 +1612,8 @@ public static function ge_madd( * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p * @param ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp $q * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 + * @throws SodiumException + * @throws TypeError */ public static function ge_msub( ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 $R, @@ -1597,6 +1641,8 @@ public static function ge_msub( * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 $p * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P2 + * @throws SodiumException + * @throws TypeError */ public static function ge_p1p1_to_p2(ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 $p) { @@ -1612,6 +1658,8 @@ public static function ge_p1p1_to_p2(ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 $p * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P3 + * @throws SodiumException + * @throws TypeError */ public static function ge_p1p1_to_p3(ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 $p) { @@ -1627,6 +1675,8 @@ public static function ge_p1p1_to_p3(ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 * @internal You should not use this directly from another application * * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P2 + * @throws SodiumException + * @throws TypeError */ public static function ge_p2_0() { @@ -1642,6 +1692,8 @@ public static function ge_p2_0() * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $p * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 + * @throws SodiumException + * @throws TypeError */ public static function ge_p2_dbl(ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $p) { @@ -1664,6 +1716,8 @@ public static function ge_p2_dbl(ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $p) * @internal You should not use this directly from another application * * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P3 + * @throws SodiumException + * @throws TypeError */ public static function ge_p3_0() { @@ -1680,6 +1734,8 @@ public static function ge_p3_0() * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p * @return ParagonIE_Sodium_Core32_Curve25519_Ge_Cached + * @throws SodiumException + * @throws TypeError */ public static function ge_p3_to_cached(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p) { @@ -1700,6 +1756,7 @@ public static function ge_p3_to_cached(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 ) ); } + /** @var ParagonIE_Sodium_Core32_Curve25519_Fe $d2 */ $r = new ParagonIE_Sodium_Core32_Curve25519_Ge_Cached(); $r->YplusX = self::fe_add($p->Y, $p->X); $r->YminusX = self::fe_sub($p->Y, $p->X); @@ -1728,6 +1785,8 @@ public static function ge_p3_to_p2(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p) * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $h * @return string + * @throws SodiumException + * @throws TypeError */ public static function ge_p3_tobytes(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $h) { @@ -1746,6 +1805,8 @@ public static function ge_p3_tobytes(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $h * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 + * @throws SodiumException + * @throws TypeError */ public static function ge_p3_dbl(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p) { @@ -1755,6 +1816,8 @@ public static function ge_p3_dbl(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p) /** * @return ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp + * @throws SodiumException + * @throws TypeError */ public static function ge_precomp_0() { @@ -1771,28 +1834,30 @@ public static function ge_precomp_0() * @param int $b * @param int $c * @return int + * @psalm-suppress MixedReturnStatement */ public static function equal($b, $c) { - return (($b ^ $c) - 1 & 0xffffffff) >> 31; + return (int) ((($b ^ $c) - 1 & 0xffffffff) >> 31); } /** * @internal You should not use this directly from another application * - * @param int $char + * @param string|int $char * @return int (1 = yes, 0 = no) + * @throws SodiumException + * @throws TypeError */ public static function negative($char) { if (is_int($char)) { return $char < 0 ? 1 : 0; } + /** @var string $char */ + /** @var int $x */ $x = self::chrToInt(self::substr($char, 0, 1)); - if (PHP_INT_SIZE === 8) { - return $x >> 63; - } - return $x >> 31; + return (int) ($x >> 31); } /** @@ -1804,6 +1869,8 @@ public static function negative($char) * @param ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp $u * @param int $b * @return ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp + * @throws SodiumException + * @throws TypeError */ public static function cmov( ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp $t, @@ -1826,6 +1893,11 @@ public static function cmov( * @param int $pos * @param int $b * @return ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArrayAccess + * @psalm-suppress MixedArrayOffset + * @psalm-suppress MixedArgument */ public static function ge_select($pos = 0, $b = 0) { @@ -1889,6 +1961,7 @@ public static function ge_select($pos = 0, $b = 0) } $bnegative = self::negative($b); + /** @var int $babs */ $babs = $b - (((-$bnegative) & $b) << 1); $t = self::ge_precomp_0(); @@ -1917,6 +1990,8 @@ public static function ge_select($pos = 0, $b = 0) * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p * @param ParagonIE_Sodium_Core32_Curve25519_Ge_Cached $q * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 + * @throws SodiumException + * @throws TypeError */ public static function ge_sub( ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $p, @@ -1944,6 +2019,8 @@ public static function ge_sub( * * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $h * @return string + * @throws SodiumException + * @throws TypeError */ public static function ge_tobytes(ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $h) { @@ -1964,24 +2041,22 @@ public static function ge_tobytes(ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $h) * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $A * @param string $b * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P2 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArrayAccess */ public static function ge_double_scalarmult_vartime( $a, ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $A, $b ) { - /** - * @var ParagonIE_Sodium_Core32_Curve25519_Ge_Cached[] - */ + /** @var array $Ai */ $Ai = array(); - /** - * @var ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp[] - */ static $Bi = array(); + /** @var array $Bi */ if (!$Bi) { for ($i = 0; $i < 8; ++$i) { - $Bi[$i] = new ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp( ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray( array( @@ -2028,6 +2103,7 @@ public static function ge_double_scalarmult_vartime( ); } } + for ($i = 0; $i < 8; ++$i) { $Ai[$i] = new ParagonIE_Sodium_Core32_Curve25519_Ge_Cached( self::fe_0(), @@ -2036,6 +2112,7 @@ public static function ge_double_scalarmult_vartime( self::fe_0() ); } + /** @var array $Ai */ # slide(aslide,a); # slide(bslide,b); @@ -2098,27 +2175,30 @@ public static function ge_double_scalarmult_vartime( $Ai[(int) floor(-$aslide[$i] / 2)] ); } + /** @var array $Bi */ # if (bslide[i] > 0) { if ($bslide[$i] > 0) { # ge_p1p1_to_p3(&u,&t); # ge_madd(&t,&u,&Bi[bslide[i]/2]); $u = self::ge_p1p1_to_p3($t); - $t = self::ge_madd( - $t, - $u, - $Bi[(int) floor($bslide[$i] / 2)] - ); + /** @var int $index */ + $index = (int) floor($bslide[$i] / 2); + /** @var ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp $thisB */ + $thisB = $Bi[$index]; + $t = self::ge_madd($t, $u, $thisB); # } else if (bslide[i] < 0) { } elseif ($bslide[$i] < 0) { # ge_p1p1_to_p3(&u,&t); # ge_msub(&t,&u,&Bi[(-bslide[i])/2]); $u = self::ge_p1p1_to_p3($t); - $t = self::ge_msub( - $t, - $u, - $Bi[(int) floor(-$bslide[$i] / 2)] - ); + + /** @var int $index */ + $index = (int) floor(-$bslide[$i] / 2); + + /** @var ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp $thisB */ + $thisB = $Bi[$index]; + $t = self::ge_msub($t, $u, $thisB); } # ge_p1p1_to_p2(r,&t); $r = self::ge_p1p1_to_p2($t); @@ -2131,30 +2211,42 @@ public static function ge_double_scalarmult_vartime( * * @param string $a * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P3 + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedOperand + * @throws SodiumException + * @throws TypeError */ public static function ge_scalarmult_base($a) { + /** @var array $e */ $e = array(); $r = new ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1(); for ($i = 0; $i < 32; ++$i) { - $e[$i << 1] = self::chrToInt($a[$i]) & 15; - $e[($i << 1) + 1] = (self::chrToInt($a[$i]) >> 4) & 15; + /** @var int $dbl */ + $dbl = (int) $i << 1; + $e[$dbl] = (int) self::chrToInt($a[$i]) & 15; + $e[$dbl + 1] = (int) (self::chrToInt($a[$i]) >> 4) & 15; } + /** @var int $carry */ $carry = 0; for ($i = 0; $i < 63; ++$i) { $e[$i] += $carry; + /** @var int $carry */ $carry = $e[$i] + 8; + /** @var int $carry */ $carry >>= 4; $e[$i] -= $carry << 4; } - $e[63] += $carry; + + /** @var array $e */ + $e[63] += (int) $carry; $h = self::ge_p3_0(); for ($i = 1; $i < 64; $i += 2) { - $t = self::ge_select((int) floor($i / 2), $e[$i]); + $t = self::ge_select((int) floor($i / 2), (int) $e[$i]); $r = self::ge_madd($r, $h, $t); $h = self::ge_p1p1_to_p3($r); } @@ -2171,7 +2263,7 @@ public static function ge_scalarmult_base($a) $h = self::ge_p1p1_to_p3($r); for ($i = 0; $i < 64; $i += 2) { - $t = self::ge_select($i >> 1, $e[$i]); + $t = self::ge_select($i >> 1, (int) $e[$i]); $r = self::ge_madd($r, $h, $t); $h = self::ge_p1p1_to_p3($r); } @@ -2188,6 +2280,8 @@ public static function ge_scalarmult_base($a) * @param string $b * @param string $c * @return string + * @throws SodiumException + * @throws TypeError */ public static function sc_muladd($a, $b, $c) { @@ -2256,40 +2350,40 @@ public static function sc_muladd($a, $b, $c) * @var ParagonIE_Sodium_Core32_Int64 $s23 */ - $s0 = $c0->addInt64($a0->mulInt64($b0)); - $s1 = $c1->addInt64($a0->mulInt64($b1))->addInt64($a1->mulInt64($b0)); - $s2 = $c2->addInt64($a0->mulInt64($b2))->addInt64($a1->mulInt64($b1))->addInt64($a2->mulInt64($b0)); - $s3 = $c3->addInt64($a0->mulInt64($b3))->addInt64($a1->mulInt64($b2))->addInt64($a2->mulInt64($b1))->addInt64($a3->mulInt64($b0)); - $s4 = $c4->addInt64($a0->mulInt64($b4))->addInt64($a1->mulInt64($b3))->addInt64($a2->mulInt64($b2))->addInt64($a3->mulInt64($b1))->addInt64($a4->mulInt64($b0)); - $s5 = $c5->addInt64($a0->mulInt64($b5))->addInt64($a1->mulInt64($b4))->addInt64($a2->mulInt64($b3))->addInt64($a3->mulInt64($b2))->addInt64($a4->mulInt64($b1))->addInt64($a5->mulInt64($b0)); - $s6 = $c6->addInt64($a0->mulInt64($b6))->addInt64($a1->mulInt64($b5))->addInt64($a2->mulInt64($b4))->addInt64($a3->mulInt64($b3))->addInt64($a4->mulInt64($b2))->addInt64($a5->mulInt64($b1)) - ->addInt64($a6->mulInt64($b0)); - $s7 = $c7->addInt64($a0->mulInt64($b7))->addInt64($a1->mulInt64($b6))->addInt64($a2->mulInt64($b5))->addInt64($a3->mulInt64($b4))->addInt64($a4->mulInt64($b3))->addInt64($a5->mulInt64($b2)) - ->addInt64($a6->mulInt64($b1))->addInt64($a7->mulInt64($b0)); - $s8 = $c8->addInt64($a0->mulInt64($b8))->addInt64($a1->mulInt64($b7))->addInt64($a2->mulInt64($b6))->addInt64($a3->mulInt64($b5))->addInt64($a4->mulInt64($b4))->addInt64($a5->mulInt64($b3)) - ->addInt64($a6->mulInt64($b2))->addInt64($a7->mulInt64($b1))->addInt64($a8->mulInt64($b0)); - $s9 = $c9->addInt64($a0->mulInt64($b9))->addInt64($a1->mulInt64($b8))->addInt64($a2->mulInt64($b7))->addInt64($a3->mulInt64($b6))->addInt64($a4->mulInt64($b5))->addInt64($a5->mulInt64($b4)) - ->addInt64($a6->mulInt64($b3))->addInt64($a7->mulInt64($b2))->addInt64($a8->mulInt64($b1))->addInt64($a9->mulInt64($b0)); - $s10 = $c10->addInt64($a0->mulInt64($b10))->addInt64($a1->mulInt64($b9))->addInt64($a2->mulInt64($b8))->addInt64($a3->mulInt64($b7))->addInt64($a4->mulInt64($b6))->addInt64($a5->mulInt64($b5)) - ->addInt64($a6->mulInt64($b4))->addInt64($a7->mulInt64($b3))->addInt64($a8->mulInt64($b2))->addInt64($a9->mulInt64($b1))->addInt64($a10->mulInt64($b0)); - $s11 = $c11->addInt64($a0->mulInt64($b11))->addInt64($a1->mulInt64($b10))->addInt64($a2->mulInt64($b9))->addInt64($a3->mulInt64($b8))->addInt64($a4->mulInt64($b7))->addInt64($a5->mulInt64($b6)) - ->addInt64($a6->mulInt64($b5))->addInt64($a7->mulInt64($b4))->addInt64($a8->mulInt64($b3))->addInt64($a9->mulInt64($b2))->addInt64($a10->mulInt64($b1))->addInt64($a11->mulInt64($b0)); - $s12 = $a1->mulInt64($b11)->addInt64($a2->mulInt64($b10))->addInt64($a3->mulInt64($b9))->addInt64($a4->mulInt64($b8))->addInt64($a5->mulInt64($b7))->addInt64($a6->mulInt64($b6)) - ->addInt64($a7->mulInt64($b5))->addInt64($a8->mulInt64($b4))->addInt64($a9->mulInt64($b3))->addInt64($a10->mulInt64($b2))->addInt64($a11->mulInt64($b1)); - $s13 = $a2->mulInt64($b11)->addInt64($a3->mulInt64($b10))->addInt64($a4->mulInt64($b9))->addInt64($a5->mulInt64($b8))->addInt64($a6->mulInt64($b7))->addInt64($a7->mulInt64($b6)) - ->addInt64($a8->mulInt64($b5))->addInt64($a9->mulInt64($b4))->addInt64($a10->mulInt64($b3))->addInt64($a11->mulInt64($b2)); - $s14 = $a3->mulInt64($b11)->addInt64($a4->mulInt64($b10))->addInt64($a5->mulInt64($b9))->addInt64($a6->mulInt64($b8))->addInt64($a7->mulInt64($b7))->addInt64($a8->mulInt64($b6)) - ->addInt64($a9->mulInt64($b5))->addInt64($a10->mulInt64($b4))->addInt64($a11->mulInt64($b3)); - $s15 = $a4->mulInt64($b11)->addInt64($a5->mulInt64($b10))->addInt64($a6->mulInt64($b9))->addInt64($a7->mulInt64($b8))->addInt64($a8->mulInt64($b7))->addInt64($a9->mulInt64($b6)) - ->addInt64($a10->mulInt64($b5))->addInt64($a11->mulInt64($b4)); - $s16 = $a5->mulInt64($b11)->addInt64($a6->mulInt64($b10))->addInt64($a7->mulInt64($b9))->addInt64($a8->mulInt64($b8))->addInt64($a9->mulInt64($b7))->addInt64($a10->mulInt64($b6)) - ->addInt64($a11->mulInt64($b5)); - $s17 = $a6->mulInt64($b11)->addInt64($a7->mulInt64($b10))->addInt64($a8->mulInt64($b9))->addInt64($a9->mulInt64($b8))->addInt64($a10->mulInt64($b7))->addInt64($a11->mulInt64($b6)); - $s18 = $a7->mulInt64($b11)->addInt64($a8->mulInt64($b10))->addInt64($a9->mulInt64($b9))->addInt64($a10->mulInt64($b8))->addInt64($a11->mulInt64($b7)); - $s19 = $a8->mulInt64($b11)->addInt64($a9->mulInt64($b10))->addInt64($a10->mulInt64($b9))->addInt64($a11->mulInt64($b8)); - $s20 = $a9->mulInt64($b11)->addInt64($a10->mulInt64($b10))->addInt64($a11->mulInt64($b9)); - $s21 = $a10->mulInt64($b11)->addInt64($a11->mulInt64($b10)); - $s22 = $a11->mulInt64($b11); + $s0 = $c0->addInt64($a0->mulInt64($b0, 24)); + $s1 = $c1->addInt64($a0->mulInt64($b1, 24))->addInt64($a1->mulInt64($b0, 24)); + $s2 = $c2->addInt64($a0->mulInt64($b2, 24))->addInt64($a1->mulInt64($b1, 24))->addInt64($a2->mulInt64($b0, 24)); + $s3 = $c3->addInt64($a0->mulInt64($b3, 24))->addInt64($a1->mulInt64($b2, 24))->addInt64($a2->mulInt64($b1, 24))->addInt64($a3->mulInt64($b0, 24)); + $s4 = $c4->addInt64($a0->mulInt64($b4, 24))->addInt64($a1->mulInt64($b3, 24))->addInt64($a2->mulInt64($b2, 24))->addInt64($a3->mulInt64($b1, 24))->addInt64($a4->mulInt64($b0, 24)); + $s5 = $c5->addInt64($a0->mulInt64($b5, 24))->addInt64($a1->mulInt64($b4, 24))->addInt64($a2->mulInt64($b3, 24))->addInt64($a3->mulInt64($b2, 24))->addInt64($a4->mulInt64($b1, 24))->addInt64($a5->mulInt64($b0, 24)); + $s6 = $c6->addInt64($a0->mulInt64($b6, 24))->addInt64($a1->mulInt64($b5, 24))->addInt64($a2->mulInt64($b4, 24))->addInt64($a3->mulInt64($b3, 24))->addInt64($a4->mulInt64($b2, 24))->addInt64($a5->mulInt64($b1, 24)) + ->addInt64($a6->mulInt64($b0, 24)); + $s7 = $c7->addInt64($a0->mulInt64($b7, 24))->addInt64($a1->mulInt64($b6, 24))->addInt64($a2->mulInt64($b5, 24))->addInt64($a3->mulInt64($b4, 24))->addInt64($a4->mulInt64($b3, 24))->addInt64($a5->mulInt64($b2, 24)) + ->addInt64($a6->mulInt64($b1, 24))->addInt64($a7->mulInt64($b0, 24)); + $s8 = $c8->addInt64($a0->mulInt64($b8, 24))->addInt64($a1->mulInt64($b7, 24))->addInt64($a2->mulInt64($b6, 24))->addInt64($a3->mulInt64($b5, 24))->addInt64($a4->mulInt64($b4, 24))->addInt64($a5->mulInt64($b3, 24)) + ->addInt64($a6->mulInt64($b2, 24))->addInt64($a7->mulInt64($b1, 24))->addInt64($a8->mulInt64($b0, 24)); + $s9 = $c9->addInt64($a0->mulInt64($b9, 24))->addInt64($a1->mulInt64($b8, 24))->addInt64($a2->mulInt64($b7, 24))->addInt64($a3->mulInt64($b6, 24))->addInt64($a4->mulInt64($b5, 24))->addInt64($a5->mulInt64($b4, 24)) + ->addInt64($a6->mulInt64($b3, 24))->addInt64($a7->mulInt64($b2, 24))->addInt64($a8->mulInt64($b1, 24))->addInt64($a9->mulInt64($b0, 24)); + $s10 = $c10->addInt64($a0->mulInt64($b10, 24))->addInt64($a1->mulInt64($b9, 24))->addInt64($a2->mulInt64($b8, 24))->addInt64($a3->mulInt64($b7, 24))->addInt64($a4->mulInt64($b6, 24))->addInt64($a5->mulInt64($b5, 24)) + ->addInt64($a6->mulInt64($b4, 24))->addInt64($a7->mulInt64($b3, 24))->addInt64($a8->mulInt64($b2, 24))->addInt64($a9->mulInt64($b1, 24))->addInt64($a10->mulInt64($b0, 24)); + $s11 = $c11->addInt64($a0->mulInt64($b11, 24))->addInt64($a1->mulInt64($b10, 24))->addInt64($a2->mulInt64($b9, 24))->addInt64($a3->mulInt64($b8, 24))->addInt64($a4->mulInt64($b7, 24))->addInt64($a5->mulInt64($b6, 24)) + ->addInt64($a6->mulInt64($b5, 24))->addInt64($a7->mulInt64($b4, 24))->addInt64($a8->mulInt64($b3, 24))->addInt64($a9->mulInt64($b2, 24))->addInt64($a10->mulInt64($b1, 24))->addInt64($a11->mulInt64($b0, 24)); + $s12 = $a1->mulInt64($b11, 24)->addInt64($a2->mulInt64($b10, 24))->addInt64($a3->mulInt64($b9, 24))->addInt64($a4->mulInt64($b8, 24))->addInt64($a5->mulInt64($b7, 24))->addInt64($a6->mulInt64($b6, 24)) + ->addInt64($a7->mulInt64($b5, 24))->addInt64($a8->mulInt64($b4, 24))->addInt64($a9->mulInt64($b3, 24))->addInt64($a10->mulInt64($b2, 24))->addInt64($a11->mulInt64($b1, 24)); + $s13 = $a2->mulInt64($b11, 24)->addInt64($a3->mulInt64($b10, 24))->addInt64($a4->mulInt64($b9, 24))->addInt64($a5->mulInt64($b8, 24))->addInt64($a6->mulInt64($b7, 24))->addInt64($a7->mulInt64($b6, 24)) + ->addInt64($a8->mulInt64($b5, 24))->addInt64($a9->mulInt64($b4, 24))->addInt64($a10->mulInt64($b3, 24))->addInt64($a11->mulInt64($b2, 24)); + $s14 = $a3->mulInt64($b11, 24)->addInt64($a4->mulInt64($b10, 24))->addInt64($a5->mulInt64($b9, 24))->addInt64($a6->mulInt64($b8, 24))->addInt64($a7->mulInt64($b7, 24))->addInt64($a8->mulInt64($b6, 24)) + ->addInt64($a9->mulInt64($b5, 24))->addInt64($a10->mulInt64($b4, 24))->addInt64($a11->mulInt64($b3, 24)); + $s15 = $a4->mulInt64($b11, 24)->addInt64($a5->mulInt64($b10, 24))->addInt64($a6->mulInt64($b9, 24))->addInt64($a7->mulInt64($b8, 24))->addInt64($a8->mulInt64($b7, 24))->addInt64($a9->mulInt64($b6, 24)) + ->addInt64($a10->mulInt64($b5, 24))->addInt64($a11->mulInt64($b4, 24)); + $s16 = $a5->mulInt64($b11, 24)->addInt64($a6->mulInt64($b10, 24))->addInt64($a7->mulInt64($b9, 24))->addInt64($a8->mulInt64($b8, 24))->addInt64($a9->mulInt64($b7, 24))->addInt64($a10->mulInt64($b6, 24)) + ->addInt64($a11->mulInt64($b5, 24)); + $s17 = $a6->mulInt64($b11, 24)->addInt64($a7->mulInt64($b10, 24))->addInt64($a8->mulInt64($b9, 24))->addInt64($a9->mulInt64($b8, 24))->addInt64($a10->mulInt64($b7, 24))->addInt64($a11->mulInt64($b6, 24)); + $s18 = $a7->mulInt64($b11, 24)->addInt64($a8->mulInt64($b10, 24))->addInt64($a9->mulInt64($b9, 24))->addInt64($a10->mulInt64($b8, 24))->addInt64($a11->mulInt64($b7, 24)); + $s19 = $a8->mulInt64($b11, 24)->addInt64($a9->mulInt64($b10, 24))->addInt64($a10->mulInt64($b9, 24))->addInt64($a11->mulInt64($b8, 24)); + $s20 = $a9->mulInt64($b11, 24)->addInt64($a10->mulInt64($b10, 24))->addInt64($a11->mulInt64($b9, 24)); + $s21 = $a10->mulInt64($b11, 24)->addInt64($a11->mulInt64($b10, 24)); + $s22 = $a11->mulInt64($b11, 24); $s23 = new ParagonIE_Sodium_Core32_Int64(); $carry0 = $s0->addInt(1 << 20)->shiftRight(21); @@ -2363,47 +2457,47 @@ public static function sc_muladd($a, $b, $c) $s22 = $s22->addInt64($carry21); $s21 = $s21->subInt64($carry21->shiftLeft(21)); - $s11 = $s11->addInt64($s23->mulInt(666643)); - $s12 = $s12->addInt64($s23->mulInt(470296)); - $s13 = $s13->addInt64($s23->mulInt(654183)); - $s14 = $s14->subInt64($s23->mulInt(997805)); - $s15 = $s15->addInt64($s23->mulInt(136657)); - $s16 = $s16->subInt64($s23->mulInt(683901)); - - $s10 = $s10->addInt64($s22->mulInt(666643)); - $s11 = $s11->addInt64($s22->mulInt(470296)); - $s12 = $s12->addInt64($s22->mulInt(654183)); - $s13 = $s13->subInt64($s22->mulInt(997805)); - $s14 = $s14->addInt64($s22->mulInt(136657)); - $s15 = $s15->subInt64($s22->mulInt(683901)); - - $s9 = $s9->addInt64($s21->mulInt(666643)); - $s10 = $s10->addInt64($s21->mulInt(470296)); - $s11 = $s11->addInt64($s21->mulInt(654183)); - $s12 = $s12->subInt64($s21->mulInt(997805)); - $s13 = $s13->addInt64($s21->mulInt(136657)); - $s14 = $s14->subInt64($s21->mulInt(683901)); - - $s8 = $s8->addInt64($s20->mulInt(666643)); - $s9 = $s9->addInt64($s20->mulInt(470296)); - $s10 = $s10->addInt64($s20->mulInt(654183)); - $s11 = $s11->subInt64($s20->mulInt(997805)); - $s12 = $s12->addInt64($s20->mulInt(136657)); - $s13 = $s13->subInt64($s20->mulInt(683901)); - - $s7 = $s7->addInt64($s19->mulInt(666643)); - $s8 = $s8->addInt64($s19->mulInt(470296)); - $s9 = $s9->addInt64($s19->mulInt(654183)); - $s10 = $s10->subInt64($s19->mulInt(997805)); - $s11 = $s11->addInt64($s19->mulInt(136657)); - $s12 = $s12->subInt64($s19->mulInt(683901)); - - $s6 = $s6->addInt64($s18->mulInt(666643)); - $s7 = $s7->addInt64($s18->mulInt(470296)); - $s8 = $s8->addInt64($s18->mulInt(654183)); - $s9 = $s9->subInt64($s18->mulInt(997805)); - $s10 = $s10->addInt64($s18->mulInt(136657)); - $s11 = $s11->subInt64($s18->mulInt(683901)); + $s11 = $s11->addInt64($s23->mulInt(666643, 20)); + $s12 = $s12->addInt64($s23->mulInt(470296, 19)); + $s13 = $s13->addInt64($s23->mulInt(654183, 20)); + $s14 = $s14->subInt64($s23->mulInt(997805, 20)); + $s15 = $s15->addInt64($s23->mulInt(136657, 18)); + $s16 = $s16->subInt64($s23->mulInt(683901, 20)); + + $s10 = $s10->addInt64($s22->mulInt(666643, 20)); + $s11 = $s11->addInt64($s22->mulInt(470296, 19)); + $s12 = $s12->addInt64($s22->mulInt(654183, 20)); + $s13 = $s13->subInt64($s22->mulInt(997805, 20)); + $s14 = $s14->addInt64($s22->mulInt(136657, 18)); + $s15 = $s15->subInt64($s22->mulInt(683901, 20)); + + $s9 = $s9->addInt64($s21->mulInt(666643, 20)); + $s10 = $s10->addInt64($s21->mulInt(470296, 19)); + $s11 = $s11->addInt64($s21->mulInt(654183, 20)); + $s12 = $s12->subInt64($s21->mulInt(997805, 20)); + $s13 = $s13->addInt64($s21->mulInt(136657, 18)); + $s14 = $s14->subInt64($s21->mulInt(683901, 20)); + + $s8 = $s8->addInt64($s20->mulInt(666643, 20)); + $s9 = $s9->addInt64($s20->mulInt(470296, 19)); + $s10 = $s10->addInt64($s20->mulInt(654183, 20)); + $s11 = $s11->subInt64($s20->mulInt(997805, 20)); + $s12 = $s12->addInt64($s20->mulInt(136657, 18)); + $s13 = $s13->subInt64($s20->mulInt(683901, 20)); + + $s7 = $s7->addInt64($s19->mulInt(666643, 20)); + $s8 = $s8->addInt64($s19->mulInt(470296, 19)); + $s9 = $s9->addInt64($s19->mulInt(654183, 20)); + $s10 = $s10->subInt64($s19->mulInt(997805, 20)); + $s11 = $s11->addInt64($s19->mulInt(136657, 18)); + $s12 = $s12->subInt64($s19->mulInt(683901, 20)); + + $s6 = $s6->addInt64($s18->mulInt(666643, 20)); + $s7 = $s7->addInt64($s18->mulInt(470296, 19)); + $s8 = $s8->addInt64($s18->mulInt(654183, 20)); + $s9 = $s9->subInt64($s18->mulInt(997805, 20)); + $s10 = $s10->addInt64($s18->mulInt(136657, 18)); + $s11 = $s11->subInt64($s18->mulInt(683901, 20)); $carry6 = $s6->addInt(1 << 20)->shiftRight(21); $s7 = $s7->addInt64($carry6); @@ -2440,47 +2534,47 @@ public static function sc_muladd($a, $b, $c) $s16 = $s16->addInt64($carry15); $s15 = $s15->subInt64($carry15->shiftLeft(21)); - $s5 = $s5->addInt64($s17->mulInt(666643)); - $s6 = $s6->addInt64($s17->mulInt(470296)); - $s7 = $s7->addInt64($s17->mulInt(654183)); - $s8 = $s8->subInt64($s17->mulInt(997805)); - $s9 = $s9->addInt64($s17->mulInt(136657)); - $s10 = $s10->subInt64($s17->mulInt(683901)); - - $s4 = $s4->addInt64($s16->mulInt(666643)); - $s5 = $s5->addInt64($s16->mulInt(470296)); - $s6 = $s6->addInt64($s16->mulInt(654183)); - $s7 = $s7->subInt64($s16->mulInt(997805)); - $s8 = $s8->addInt64($s16->mulInt(136657)); - $s9 = $s9->subInt64($s16->mulInt(683901)); - - $s3 = $s3->addInt64($s15->mulInt(666643)); - $s4 = $s4->addInt64($s15->mulInt(470296)); - $s5 = $s5->addInt64($s15->mulInt(654183)); - $s6 = $s6->subInt64($s15->mulInt(997805)); - $s7 = $s7->addInt64($s15->mulInt(136657)); - $s8 = $s8->subInt64($s15->mulInt(683901)); - - $s2 = $s2->addInt64($s14->mulInt(666643)); - $s3 = $s3->addInt64($s14->mulInt(470296)); - $s4 = $s4->addInt64($s14->mulInt(654183)); - $s5 = $s5->subInt64($s14->mulInt(997805)); - $s6 = $s6->addInt64($s14->mulInt(136657)); - $s7 = $s7->subInt64($s14->mulInt(683901)); - - $s1 = $s1->addInt64($s13->mulInt(666643)); - $s2 = $s2->addInt64($s13->mulInt(470296)); - $s3 = $s3->addInt64($s13->mulInt(654183)); - $s4 = $s4->subInt64($s13->mulInt(997805)); - $s5 = $s5->addInt64($s13->mulInt(136657)); - $s6 = $s6->subInt64($s13->mulInt(683901)); - - $s0 = $s0->addInt64($s12->mulInt(666643)); - $s1 = $s1->addInt64($s12->mulInt(470296)); - $s2 = $s2->addInt64($s12->mulInt(654183)); - $s3 = $s3->subInt64($s12->mulInt(997805)); - $s4 = $s4->addInt64($s12->mulInt(136657)); - $s5 = $s5->subInt64($s12->mulInt(683901)); + $s5 = $s5->addInt64($s17->mulInt(666643, 20)); + $s6 = $s6->addInt64($s17->mulInt(470296, 19)); + $s7 = $s7->addInt64($s17->mulInt(654183, 20)); + $s8 = $s8->subInt64($s17->mulInt(997805, 20)); + $s9 = $s9->addInt64($s17->mulInt(136657, 18)); + $s10 = $s10->subInt64($s17->mulInt(683901, 20)); + + $s4 = $s4->addInt64($s16->mulInt(666643, 20)); + $s5 = $s5->addInt64($s16->mulInt(470296, 19)); + $s6 = $s6->addInt64($s16->mulInt(654183, 20)); + $s7 = $s7->subInt64($s16->mulInt(997805, 20)); + $s8 = $s8->addInt64($s16->mulInt(136657, 18)); + $s9 = $s9->subInt64($s16->mulInt(683901, 20)); + + $s3 = $s3->addInt64($s15->mulInt(666643, 20)); + $s4 = $s4->addInt64($s15->mulInt(470296, 19)); + $s5 = $s5->addInt64($s15->mulInt(654183, 20)); + $s6 = $s6->subInt64($s15->mulInt(997805, 20)); + $s7 = $s7->addInt64($s15->mulInt(136657, 18)); + $s8 = $s8->subInt64($s15->mulInt(683901, 20)); + + $s2 = $s2->addInt64($s14->mulInt(666643, 20)); + $s3 = $s3->addInt64($s14->mulInt(470296, 19)); + $s4 = $s4->addInt64($s14->mulInt(654183, 20)); + $s5 = $s5->subInt64($s14->mulInt(997805, 20)); + $s6 = $s6->addInt64($s14->mulInt(136657, 18)); + $s7 = $s7->subInt64($s14->mulInt(683901, 20)); + + $s1 = $s1->addInt64($s13->mulInt(666643, 20)); + $s2 = $s2->addInt64($s13->mulInt(470296, 19)); + $s3 = $s3->addInt64($s13->mulInt(654183, 20)); + $s4 = $s4->subInt64($s13->mulInt(997805, 20)); + $s5 = $s5->addInt64($s13->mulInt(136657, 18)); + $s6 = $s6->subInt64($s13->mulInt(683901, 20)); + + $s0 = $s0->addInt64($s12->mulInt(666643, 20)); + $s1 = $s1->addInt64($s12->mulInt(470296, 19)); + $s2 = $s2->addInt64($s12->mulInt(654183, 20)); + $s3 = $s3->subInt64($s12->mulInt(997805, 20)); + $s4 = $s4->addInt64($s12->mulInt(136657, 18)); + $s5 = $s5->subInt64($s12->mulInt(683901, 20)); $s12 = new ParagonIE_Sodium_Core32_Int64(); $carry0 = $s0->addInt(1 << 20)->shiftRight(21); @@ -2521,12 +2615,12 @@ public static function sc_muladd($a, $b, $c) $s12 = $s12->addInt64($carry11); $s11 = $s11->subInt64($carry11->shiftLeft(21)); - $s0 = $s0->addInt64($s12->mulInt(666643)); - $s1 = $s1->addInt64($s12->mulInt(470296)); - $s2 = $s2->addInt64($s12->mulInt(654183)); - $s3 = $s3->subInt64($s12->mulInt(997805)); - $s4 = $s4->addInt64($s12->mulInt(136657)); - $s5 = $s5->subInt64($s12->mulInt(683901)); + $s0 = $s0->addInt64($s12->mulInt(666643, 20)); + $s1 = $s1->addInt64($s12->mulInt(470296, 19)); + $s2 = $s2->addInt64($s12->mulInt(654183, 20)); + $s3 = $s3->subInt64($s12->mulInt(997805, 20)); + $s4 = $s4->addInt64($s12->mulInt(136657, 18)); + $s5 = $s5->subInt64($s12->mulInt(683901, 20)); $s12 = new ParagonIE_Sodium_Core32_Int64(); $carry0 = $s0->shiftRight(21); @@ -2566,12 +2660,12 @@ public static function sc_muladd($a, $b, $c) $s12 = $s12->addInt64($carry11); $s11 = $s11->subInt64($carry11->shiftLeft(21)); - $s0 = $s0->addInt64($s12->mulInt(666643)); - $s1 = $s1->addInt64($s12->mulInt(470296)); - $s2 = $s2->addInt64($s12->mulInt(654183)); - $s3 = $s3->subInt64($s12->mulInt(997805)); - $s4 = $s4->addInt64($s12->mulInt(136657)); - $s5 = $s5->subInt64($s12->mulInt(683901)); + $s0 = $s0->addInt64($s12->mulInt(666643, 20)); + $s1 = $s1->addInt64($s12->mulInt(470296, 19)); + $s2 = $s2->addInt64($s12->mulInt(654183, 20)); + $s3 = $s3->subInt64($s12->mulInt(997805, 20)); + $s4 = $s4->addInt64($s12->mulInt(136657, 18)); + $s5 = $s5->subInt64($s12->mulInt(683901, 20)); $carry0 = $s0->shiftRight(21); $s1 = $s1->addInt64($carry0); @@ -2619,40 +2713,40 @@ public static function sc_muladd($a, $b, $c) $S9 = $s9->toInt32()->toInt(); $S10 = $s10->toInt32()->toInt(); $S11 = $s11->toInt32()->toInt(); - + /** * @var array */ $arr = array( (int) (0xff & ($S0 >> 0)), (int) (0xff & ($S0 >> 8)), - (int) (0xff & (($S0 >> 16) | self::mul($S1, 1 << 5))), + (int) (0xff & (($S0 >> 16) | ($S1 << 5))), (int) (0xff & ($S1 >> 3)), (int) (0xff & ($S1 >> 11)), - (int) (0xff & (($S1 >> 19) | self::mul($S2, 1 << 2))), + (int) (0xff & (($S1 >> 19) | ($S2 << 2))), (int) (0xff & ($S2 >> 6)), - (int) (0xff & (($S2 >> 14) | self::mul($S3, 1 << 7))), + (int) (0xff & (($S2 >> 14) | ($S3 << 7))), (int) (0xff & ($S3 >> 1)), (int) (0xff & ($S3 >> 9)), - (int) (0xff & (($S3 >> 17) | self::mul($S4, 1 << 4))), + (int) (0xff & (($S3 >> 17) | ($S4 << 4))), (int) (0xff & ($S4 >> 4)), (int) (0xff & ($S4 >> 12)), - (int) (0xff & (($S4 >> 20) | self::mul($S5, 1 << 1))), + (int) (0xff & (($S4 >> 20) | ($S5 << 1))), (int) (0xff & ($S5 >> 7)), - (int) (0xff & (($S5 >> 15) | self::mul($S6, 1 << 6))), + (int) (0xff & (($S5 >> 15) | ($S6 << 6))), (int) (0xff & ($S6 >> 2)), (int) (0xff & ($S6 >> 10)), - (int) (0xff & (($S6 >> 18) | self::mul($S7, 1 << 3))), + (int) (0xff & (($S6 >> 18) | ($S7 << 3))), (int) (0xff & ($S7 >> 5)), (int) (0xff & ($S7 >> 13)), (int) (0xff & ($S8 >> 0)), (int) (0xff & ($S8 >> 8)), - (int) (0xff & (($S8 >> 16) | self::mul($S9, 1 << 5))), + (int) (0xff & (($S8 >> 16) | ($S9 << 5))), (int) (0xff & ($S9 >> 3)), (int) (0xff & ($S9 >> 11)), - (int) (0xff & (($S9 >> 19) | self::mul($S10, 1 << 2))), + (int) (0xff & (($S9 >> 19) | ($S10 << 2))), (int) (0xff & ($S10 >> 6)), - (int) (0xff & (($S10 >> 14) | self::mul($S11, 1 << 7))), + (int) (0xff & (($S10 >> 14) | ($S11 << 7))), (int) (0xff & ($S11 >> 1)), (int) (0xff & ($S11 >> 9)), (int) (0xff & ($S11 >> 17)) @@ -2665,6 +2759,8 @@ public static function sc_muladd($a, $b, $c) * * @param string $s * @return string + * @throws SodiumException + * @throws TypeError */ public static function sc_reduce($s) { @@ -2719,47 +2815,47 @@ public static function sc_reduce($s) $s22 = ParagonIE_Sodium_Core32_Int32::fromInt(2097151 & (self::load_4(self::substr($s, 57, 4)) >> 6))->toInt64(); $s23 = ParagonIE_Sodium_Core32_Int32::fromInt(0x1fffffff & (self::load_4(self::substr($s, 60, 4)) >> 3))->toInt64(); - $s11 = $s11->addInt64($s23->mulInt(666643)); - $s12 = $s12->addInt64($s23->mulInt(470296)); - $s13 = $s13->addInt64($s23->mulInt(654183)); - $s14 = $s14->subInt64($s23->mulInt(997805)); - $s15 = $s15->addInt64($s23->mulInt(136657)); - $s16 = $s16->subInt64($s23->mulInt(683901)); - - $s10 = $s10->addInt64($s22->mulInt(666643)); - $s11 = $s11->addInt64($s22->mulInt(470296)); - $s12 = $s12->addInt64($s22->mulInt(654183)); - $s13 = $s13->subInt64($s22->mulInt(997805)); - $s14 = $s14->addInt64($s22->mulInt(136657)); - $s15 = $s15->subInt64($s22->mulInt(683901)); - - $s9 = $s9->addInt64($s21->mulInt(666643)); - $s10 = $s10->addInt64($s21->mulInt(470296)); - $s11 = $s11->addInt64($s21->mulInt(654183)); - $s12 = $s12->subInt64($s21->mulInt(997805)); - $s13 = $s13->addInt64($s21->mulInt(136657)); - $s14 = $s14->subInt64($s21->mulInt(683901)); - - $s8 = $s8->addInt64($s20->mulInt(666643)); - $s9 = $s9->addInt64($s20->mulInt(470296)); - $s10 = $s10->addInt64($s20->mulInt(654183)); - $s11 = $s11->subInt64($s20->mulInt(997805)); - $s12 = $s12->addInt64($s20->mulInt(136657)); - $s13 = $s13->subInt64($s20->mulInt(683901)); - - $s7 = $s7->addInt64($s19->mulInt(666643)); - $s8 = $s8->addInt64($s19->mulInt(470296)); - $s9 = $s9->addInt64($s19->mulInt(654183)); - $s10 = $s10->subInt64($s19->mulInt(997805)); - $s11 = $s11->addInt64($s19->mulInt(136657)); - $s12 = $s12->subInt64($s19->mulInt(683901)); - - $s6 = $s6->addInt64($s18->mulInt(666643)); - $s7 = $s7->addInt64($s18->mulInt(470296)); - $s8 = $s8->addInt64($s18->mulInt(654183)); - $s9 = $s9->subInt64($s18->mulInt(997805)); - $s10 = $s10->addInt64($s18->mulInt(136657)); - $s11 = $s11->subInt64($s18->mulInt(683901)); + $s11 = $s11->addInt64($s23->mulInt(666643, 20)); + $s12 = $s12->addInt64($s23->mulInt(470296, 19)); + $s13 = $s13->addInt64($s23->mulInt(654183, 20)); + $s14 = $s14->subInt64($s23->mulInt(997805, 20)); + $s15 = $s15->addInt64($s23->mulInt(136657, 18)); + $s16 = $s16->subInt64($s23->mulInt(683901, 20)); + + $s10 = $s10->addInt64($s22->mulInt(666643, 20)); + $s11 = $s11->addInt64($s22->mulInt(470296, 19)); + $s12 = $s12->addInt64($s22->mulInt(654183, 20)); + $s13 = $s13->subInt64($s22->mulInt(997805, 20)); + $s14 = $s14->addInt64($s22->mulInt(136657, 18)); + $s15 = $s15->subInt64($s22->mulInt(683901, 20)); + + $s9 = $s9->addInt64($s21->mulInt(666643, 20)); + $s10 = $s10->addInt64($s21->mulInt(470296, 19)); + $s11 = $s11->addInt64($s21->mulInt(654183, 20)); + $s12 = $s12->subInt64($s21->mulInt(997805, 20)); + $s13 = $s13->addInt64($s21->mulInt(136657, 18)); + $s14 = $s14->subInt64($s21->mulInt(683901, 20)); + + $s8 = $s8->addInt64($s20->mulInt(666643, 20)); + $s9 = $s9->addInt64($s20->mulInt(470296, 19)); + $s10 = $s10->addInt64($s20->mulInt(654183, 20)); + $s11 = $s11->subInt64($s20->mulInt(997805, 20)); + $s12 = $s12->addInt64($s20->mulInt(136657, 18)); + $s13 = $s13->subInt64($s20->mulInt(683901, 20)); + + $s7 = $s7->addInt64($s19->mulInt(666643, 20)); + $s8 = $s8->addInt64($s19->mulInt(470296, 19)); + $s9 = $s9->addInt64($s19->mulInt(654183, 20)); + $s10 = $s10->subInt64($s19->mulInt(997805, 20)); + $s11 = $s11->addInt64($s19->mulInt(136657, 18)); + $s12 = $s12->subInt64($s19->mulInt(683901, 20)); + + $s6 = $s6->addInt64($s18->mulInt(666643, 20)); + $s7 = $s7->addInt64($s18->mulInt(470296, 19)); + $s8 = $s8->addInt64($s18->mulInt(654183, 20)); + $s9 = $s9->subInt64($s18->mulInt(997805, 20)); + $s10 = $s10->addInt64($s18->mulInt(136657, 18)); + $s11 = $s11->subInt64($s18->mulInt(683901, 20)); $carry6 = $s6->addInt(1 << 20)->shiftRight(21); $s7 = $s7->addInt64($carry6); @@ -2796,47 +2892,47 @@ public static function sc_reduce($s) $s16 = $s16->addInt64($carry15); $s15 = $s15->subInt64($carry15->shiftLeft(21)); - $s5 = $s5->addInt64($s17->mulInt(666643)); - $s6 = $s6->addInt64($s17->mulInt(470296)); - $s7 = $s7->addInt64($s17->mulInt(654183)); - $s8 = $s8->subInt64($s17->mulInt(997805)); - $s9 = $s9->addInt64($s17->mulInt(136657)); - $s10 = $s10->subInt64($s17->mulInt(683901)); - - $s4 = $s4->addInt64($s16->mulInt(666643)); - $s5 = $s5->addInt64($s16->mulInt(470296)); - $s6 = $s6->addInt64($s16->mulInt(654183)); - $s7 = $s7->subInt64($s16->mulInt(997805)); - $s8 = $s8->addInt64($s16->mulInt(136657)); - $s9 = $s9->subInt64($s16->mulInt(683901)); - - $s3 = $s3->addInt64($s15->mulInt(666643)); - $s4 = $s4->addInt64($s15->mulInt(470296)); - $s5 = $s5->addInt64($s15->mulInt(654183)); - $s6 = $s6->subInt64($s15->mulInt(997805)); - $s7 = $s7->addInt64($s15->mulInt(136657)); - $s8 = $s8->subInt64($s15->mulInt(683901)); - - $s2 = $s2->addInt64($s14->mulInt(666643)); - $s3 = $s3->addInt64($s14->mulInt(470296)); - $s4 = $s4->addInt64($s14->mulInt(654183)); - $s5 = $s5->subInt64($s14->mulInt(997805)); - $s6 = $s6->addInt64($s14->mulInt(136657)); - $s7 = $s7->subInt64($s14->mulInt(683901)); - - $s1 = $s1->addInt64($s13->mulInt(666643)); - $s2 = $s2->addInt64($s13->mulInt(470296)); - $s3 = $s3->addInt64($s13->mulInt(654183)); - $s4 = $s4->subInt64($s13->mulInt(997805)); - $s5 = $s5->addInt64($s13->mulInt(136657)); - $s6 = $s6->subInt64($s13->mulInt(683901)); - - $s0 = $s0->addInt64($s12->mulInt(666643)); - $s1 = $s1->addInt64($s12->mulInt(470296)); - $s2 = $s2->addInt64($s12->mulInt(654183)); - $s3 = $s3->subInt64($s12->mulInt(997805)); - $s4 = $s4->addInt64($s12->mulInt(136657)); - $s5 = $s5->subInt64($s12->mulInt(683901)); + $s5 = $s5->addInt64($s17->mulInt(666643, 20)); + $s6 = $s6->addInt64($s17->mulInt(470296, 19)); + $s7 = $s7->addInt64($s17->mulInt(654183, 20)); + $s8 = $s8->subInt64($s17->mulInt(997805, 20)); + $s9 = $s9->addInt64($s17->mulInt(136657, 18)); + $s10 = $s10->subInt64($s17->mulInt(683901, 20)); + + $s4 = $s4->addInt64($s16->mulInt(666643, 20)); + $s5 = $s5->addInt64($s16->mulInt(470296, 19)); + $s6 = $s6->addInt64($s16->mulInt(654183, 20)); + $s7 = $s7->subInt64($s16->mulInt(997805, 20)); + $s8 = $s8->addInt64($s16->mulInt(136657, 18)); + $s9 = $s9->subInt64($s16->mulInt(683901, 20)); + + $s3 = $s3->addInt64($s15->mulInt(666643, 20)); + $s4 = $s4->addInt64($s15->mulInt(470296, 19)); + $s5 = $s5->addInt64($s15->mulInt(654183, 20)); + $s6 = $s6->subInt64($s15->mulInt(997805, 20)); + $s7 = $s7->addInt64($s15->mulInt(136657, 18)); + $s8 = $s8->subInt64($s15->mulInt(683901, 20)); + + $s2 = $s2->addInt64($s14->mulInt(666643, 20)); + $s3 = $s3->addInt64($s14->mulInt(470296, 19)); + $s4 = $s4->addInt64($s14->mulInt(654183, 20)); + $s5 = $s5->subInt64($s14->mulInt(997805, 20)); + $s6 = $s6->addInt64($s14->mulInt(136657, 18)); + $s7 = $s7->subInt64($s14->mulInt(683901, 20)); + + $s1 = $s1->addInt64($s13->mulInt(666643, 20)); + $s2 = $s2->addInt64($s13->mulInt(470296, 19)); + $s3 = $s3->addInt64($s13->mulInt(654183, 20)); + $s4 = $s4->subInt64($s13->mulInt(997805, 20)); + $s5 = $s5->addInt64($s13->mulInt(136657, 18)); + $s6 = $s6->subInt64($s13->mulInt(683901, 20)); + + $s0 = $s0->addInt64($s12->mulInt(666643, 20)); + $s1 = $s1->addInt64($s12->mulInt(470296, 19)); + $s2 = $s2->addInt64($s12->mulInt(654183, 20)); + $s3 = $s3->subInt64($s12->mulInt(997805, 20)); + $s4 = $s4->addInt64($s12->mulInt(136657, 18)); + $s5 = $s5->subInt64($s12->mulInt(683901, 20)); $s12 = new ParagonIE_Sodium_Core32_Int64(); $carry0 = $s0->addInt(1 << 20)->shiftRight(21); @@ -2876,12 +2972,12 @@ public static function sc_reduce($s) $s12 = $s12->addInt64($carry11); $s11 = $s11->subInt64($carry11->shiftLeft(21)); - $s0 = $s0->addInt64($s12->mulInt(666643)); - $s1 = $s1->addInt64($s12->mulInt(470296)); - $s2 = $s2->addInt64($s12->mulInt(654183)); - $s3 = $s3->subInt64($s12->mulInt(997805)); - $s4 = $s4->addInt64($s12->mulInt(136657)); - $s5 = $s5->subInt64($s12->mulInt(683901)); + $s0 = $s0->addInt64($s12->mulInt(666643, 20)); + $s1 = $s1->addInt64($s12->mulInt(470296, 19)); + $s2 = $s2->addInt64($s12->mulInt(654183, 20)); + $s3 = $s3->subInt64($s12->mulInt(997805, 20)); + $s4 = $s4->addInt64($s12->mulInt(136657, 18)); + $s5 = $s5->subInt64($s12->mulInt(683901, 20)); $s12 = new ParagonIE_Sodium_Core32_Int64(); $carry0 = $s0->shiftRight(21); @@ -2921,12 +3017,12 @@ public static function sc_reduce($s) $s12 = $s12->addInt64($carry11); $s11 = $s11->subInt64($carry11->shiftLeft(21)); - $s0 = $s0->addInt64($s12->mulInt(666643)); - $s1 = $s1->addInt64($s12->mulInt(470296)); - $s2 = $s2->addInt64($s12->mulInt(654183)); - $s3 = $s3->subInt64($s12->mulInt(997805)); - $s4 = $s4->addInt64($s12->mulInt(136657)); - $s5 = $s5->subInt64($s12->mulInt(683901)); + $s0 = $s0->addInt64($s12->mulInt(666643, 20)); + $s1 = $s1->addInt64($s12->mulInt(470296, 19)); + $s2 = $s2->addInt64($s12->mulInt(654183, 20)); + $s3 = $s3->subInt64($s12->mulInt(997805, 20)); + $s4 = $s4->addInt64($s12->mulInt(136657, 18)); + $s5 = $s5->subInt64($s12->mulInt(683901, 20)); $carry0 = $s0->shiftRight(21); $s1 = $s1->addInt64($carry0); @@ -2981,33 +3077,33 @@ public static function sc_reduce($s) $arr = array( (int) ($S0 >> 0), (int) ($S0 >> 8), - (int) (($S0 >> 16) | self::mul($S1, 1 << 5)), + (int) (($S0 >> 16) | ($S1 << 5)), (int) ($S1 >> 3), (int) ($S1 >> 11), - (int) (($S1 >> 19) | self::mul($S2, 1 << 2)), + (int) (($S1 >> 19) | ($S2 << 2)), (int) ($S2 >> 6), - (int) (($S2 >> 14) | self::mul($S3, 1 << 7)), + (int) (($S2 >> 14) | ($S3 << 7)), (int) ($S3 >> 1), (int) ($S3 >> 9), - (int) (($S3 >> 17) | self::mul($S4, 1 << 4)), + (int) (($S3 >> 17) | ($S4 << 4)), (int) ($S4 >> 4), (int) ($S4 >> 12), - (int) (($S4 >> 20) | self::mul($S5, 1 << 1)), + (int) (($S4 >> 20) | ($S5 << 1)), (int) ($S5 >> 7), - (int) (($S5 >> 15) | self::mul($S6, 1 << 6)), + (int) (($S5 >> 15) | ($S6 << 6)), (int) ($S6 >> 2), (int) ($S6 >> 10), - (int) (($S6 >> 18) | self::mul($S7, 1 << 3)), + (int) (($S6 >> 18) | ($S7 << 3)), (int) ($S7 >> 5), (int) ($S7 >> 13), (int) ($S8 >> 0), (int) ($S8 >> 8), - (int) (($S8 >> 16) | self::mul($S9, 1 << 5)), + (int) (($S8 >> 16) | ($S9 << 5)), (int) ($S9 >> 3), (int) ($S9 >> 11), - (int) (($S9 >> 19) | self::mul($S10, 1 << 2)), + (int) (($S9 >> 19) | ($S10 << 2)), (int) ($S10 >> 6), - (int) (($S10 >> 14) | self::mul($S11, 1 << 7)), + (int) (($S10 >> 14) | ($S11 << 7)), (int) ($S11 >> 1), (int) ($S11 >> 9), (int) $S11 >> 17 @@ -3020,6 +3116,8 @@ public static function sc_reduce($s) * * @param string $s * @return string + * @throws SodiumException + * @throws TypeError */ public static function sc_reduce_old($s) { @@ -3074,47 +3172,47 @@ public static function sc_reduce_old($s) $s22 = ParagonIE_Sodium_Core32_Int32::fromInt(2097151 & (self::load_4(self::substr($s, 57, 4)) >> 6)); $s23 = ParagonIE_Sodium_Core32_Int32::fromInt(self::load_4(self::substr($s, 60, 4)) >> 3); - $s11 = $s11->addInt32($s23->mulInt(666643)); - $s12 = $s12->addInt32($s23->mulInt(470296)); - $s13 = $s13->addInt32($s23->mulInt(654183)); - $s14 = $s14->subInt32($s23->mulInt(997805)); - $s15 = $s15->addInt32($s23->mulInt(136657)); - $s16 = $s16->subInt32($s23->mulInt(683901)); - - $s10 = $s10->addInt32($s22->mulInt(666643)); - $s11 = $s11->addInt32($s22->mulInt(470296)); - $s12 = $s12->addInt32($s22->mulInt(654183)); - $s13 = $s13->subInt32($s22->mulInt(997805)); - $s14 = $s14->addInt32($s22->mulInt(136657)); - $s15 = $s15->subInt32($s22->mulInt(683901)); - - $s9 = $s9->addInt32($s21->mulInt(666643)); - $s10 = $s10->addInt32($s21->mulInt(470296)); - $s11 = $s11->addInt32($s21->mulInt(654183)); - $s12 = $s12->subInt32($s21->mulInt(997805)); - $s13 = $s13->addInt32($s21->mulInt(136657)); - $s14 = $s14->subInt32($s21->mulInt(683901)); - - $s8 = $s8->addInt32($s20->mulInt(666643)); - $s9 = $s9->addInt32($s20->mulInt(470296)); - $s10 = $s10->addInt32($s20->mulInt(654183)); - $s11 = $s11->subInt32($s20->mulInt(997805)); - $s12 = $s12->addInt32($s20->mulInt(136657)); - $s13 = $s13->subInt32($s20->mulInt(683901)); - - $s7 = $s7->addInt32($s19->mulInt(666643)); - $s8 = $s8->addInt32($s19->mulInt(470296)); - $s9 = $s9->addInt32($s19->mulInt(654183)); - $s10 = $s10->subInt32($s19->mulInt(997805)); - $s11 = $s11->addInt32($s19->mulInt(136657)); - $s12 = $s12->subInt32($s19->mulInt(683901)); - - $s6 = $s6->addInt32($s18->mulInt(666643)); - $s7 = $s7->addInt32($s18->mulInt(470296)); - $s8 = $s8->addInt32($s18->mulInt(654183)); - $s9 = $s9->subInt32($s18->mulInt(997805)); - $s10 = $s10->addInt32($s18->mulInt(136657)); - $s11 = $s11->subInt32($s18->mulInt(683901)); + $s11 = $s11->addInt32($s23->mulInt(666643, 20)); + $s12 = $s12->addInt32($s23->mulInt(470296, 19)); + $s13 = $s13->addInt32($s23->mulInt(654183, 20)); + $s14 = $s14->subInt32($s23->mulInt(997805, 20)); + $s15 = $s15->addInt32($s23->mulInt(136657, 18)); + $s16 = $s16->subInt32($s23->mulInt(683901, 20)); + + $s10 = $s10->addInt32($s22->mulInt(666643, 20)); + $s11 = $s11->addInt32($s22->mulInt(470296, 19)); + $s12 = $s12->addInt32($s22->mulInt(654183, 20)); + $s13 = $s13->subInt32($s22->mulInt(997805, 20)); + $s14 = $s14->addInt32($s22->mulInt(136657, 18)); + $s15 = $s15->subInt32($s22->mulInt(683901, 20)); + + $s9 = $s9->addInt32($s21->mulInt(666643, 20)); + $s10 = $s10->addInt32($s21->mulInt(470296, 19)); + $s11 = $s11->addInt32($s21->mulInt(654183, 20)); + $s12 = $s12->subInt32($s21->mulInt(997805, 20)); + $s13 = $s13->addInt32($s21->mulInt(136657, 18)); + $s14 = $s14->subInt32($s21->mulInt(683901, 20)); + + $s8 = $s8->addInt32($s20->mulInt(666643, 20)); + $s9 = $s9->addInt32($s20->mulInt(470296, 19)); + $s10 = $s10->addInt32($s20->mulInt(654183, 20)); + $s11 = $s11->subInt32($s20->mulInt(997805, 20)); + $s12 = $s12->addInt32($s20->mulInt(136657, 18)); + $s13 = $s13->subInt32($s20->mulInt(683901, 20)); + + $s7 = $s7->addInt32($s19->mulInt(666643, 20)); + $s8 = $s8->addInt32($s19->mulInt(470296, 19)); + $s9 = $s9->addInt32($s19->mulInt(654183, 20)); + $s10 = $s10->subInt32($s19->mulInt(997805, 20)); + $s11 = $s11->addInt32($s19->mulInt(136657, 18)); + $s12 = $s12->subInt32($s19->mulInt(683901, 20)); + + $s6 = $s6->addInt32($s18->mulInt(666643, 20)); + $s7 = $s7->addInt32($s18->mulInt(470296, 19)); + $s8 = $s8->addInt32($s18->mulInt(654183, 20)); + $s9 = $s9->subInt32($s18->mulInt(997805, 20)); + $s10 = $s10->addInt32($s18->mulInt(136657, 18)); + $s11 = $s11->subInt32($s18->mulInt(683901, 20)); $carry6 = $s6->addInt(1 << 20)->shiftRight(21); $s7 = $s7->addInt32($carry6); @@ -3160,47 +3258,47 @@ public static function sc_reduce_old($s) $s16 = $s16->addInt32($carry15); $s15 = $s15->subInt32($carry15->shiftLeft(21)); - $s5 = $s5->addInt32($s17->mulInt(666643)); - $s6 = $s6->addInt32($s17->mulInt(470296)); - $s7 = $s7->addInt32($s17->mulInt(654183)); - $s8 = $s8->subInt32($s17->mulInt(997805)); - $s9 = $s9->addInt32($s17->mulInt(136657)); - $s10 = $s10->subInt32($s17->mulInt(683901)); - - $s4 = $s4->addInt32($s16->mulInt(666643)); - $s5 = $s5->addInt32($s16->mulInt(470296)); - $s6 = $s6->addInt32($s16->mulInt(654183)); - $s7 = $s7->subInt32($s16->mulInt(997805)); - $s8 = $s8->addInt32($s16->mulInt(136657)); - $s9 = $s9->subInt32($s16->mulInt(683901)); - - $s3 = $s3->addInt32($s15->mulInt(666643)); - $s4 = $s4->addInt32($s15->mulInt(470296)); - $s5 = $s5->addInt32($s15->mulInt(654183)); - $s6 = $s6->subInt32($s15->mulInt(997805)); - $s7 = $s7->addInt32($s15->mulInt(136657)); - $s8 = $s8->subInt32($s15->mulInt(683901)); - - $s2 = $s2->addInt32($s14->mulInt(666643)); - $s3 = $s3->addInt32($s14->mulInt(470296)); - $s4 = $s4->addInt32($s14->mulInt(654183)); - $s5 = $s5->subInt32($s14->mulInt(997805)); - $s6 = $s6->addInt32($s14->mulInt(136657)); - $s7 = $s7->subInt32($s14->mulInt(683901)); - - $s1 = $s1->addInt32($s13->mulInt(666643)); - $s2 = $s2->addInt32($s13->mulInt(470296)); - $s3 = $s3->addInt32($s13->mulInt(654183)); - $s4 = $s4->subInt32($s13->mulInt(997805)); - $s5 = $s5->addInt32($s13->mulInt(136657)); - $s6 = $s6->subInt32($s13->mulInt(683901)); - - $s0 = $s0->addInt32($s12->mulInt(666643)); - $s1 = $s1->addInt32($s12->mulInt(470296)); - $s2 = $s2->addInt32($s12->mulInt(654183)); - $s3 = $s3->subInt32($s12->mulInt(997805)); - $s4 = $s4->addInt32($s12->mulInt(136657)); - $s5 = $s5->subInt32($s12->mulInt(683901)); + $s5 = $s5->addInt32($s17->mulInt(666643, 20)); + $s6 = $s6->addInt32($s17->mulInt(470296, 19)); + $s7 = $s7->addInt32($s17->mulInt(654183, 20)); + $s8 = $s8->subInt32($s17->mulInt(997805, 20)); + $s9 = $s9->addInt32($s17->mulInt(136657, 18)); + $s10 = $s10->subInt32($s17->mulInt(683901, 20)); + + $s4 = $s4->addInt32($s16->mulInt(666643, 20)); + $s5 = $s5->addInt32($s16->mulInt(470296, 19)); + $s6 = $s6->addInt32($s16->mulInt(654183, 20)); + $s7 = $s7->subInt32($s16->mulInt(997805, 20)); + $s8 = $s8->addInt32($s16->mulInt(136657, 18)); + $s9 = $s9->subInt32($s16->mulInt(683901, 20)); + + $s3 = $s3->addInt32($s15->mulInt(666643, 20)); + $s4 = $s4->addInt32($s15->mulInt(470296, 19)); + $s5 = $s5->addInt32($s15->mulInt(654183, 20)); + $s6 = $s6->subInt32($s15->mulInt(997805, 20)); + $s7 = $s7->addInt32($s15->mulInt(136657, 18)); + $s8 = $s8->subInt32($s15->mulInt(683901, 20)); + + $s2 = $s2->addInt32($s14->mulInt(666643, 20)); + $s3 = $s3->addInt32($s14->mulInt(470296, 19)); + $s4 = $s4->addInt32($s14->mulInt(654183, 20)); + $s5 = $s5->subInt32($s14->mulInt(997805, 20)); + $s6 = $s6->addInt32($s14->mulInt(136657, 18)); + $s7 = $s7->subInt32($s14->mulInt(683901, 20)); + + $s1 = $s1->addInt32($s13->mulInt(666643, 20)); + $s2 = $s2->addInt32($s13->mulInt(470296, 19)); + $s3 = $s3->addInt32($s13->mulInt(654183, 20)); + $s4 = $s4->subInt32($s13->mulInt(997805, 20)); + $s5 = $s5->addInt32($s13->mulInt(136657, 18)); + $s6 = $s6->subInt32($s13->mulInt(683901, 20)); + + $s0 = $s0->addInt32($s12->mulInt(666643, 20)); + $s1 = $s1->addInt32($s12->mulInt(470296, 19)); + $s2 = $s2->addInt32($s12->mulInt(654183, 20)); + $s3 = $s3->subInt32($s12->mulInt(997805, 20)); + $s4 = $s4->addInt32($s12->mulInt(136657, 18)); + $s5 = $s5->subInt32($s12->mulInt(683901, 20)); $s12 = new ParagonIE_Sodium_Core32_Int32(); $carry0 = $s0->addInt(1 << 20)->shiftRight(21); @@ -3240,12 +3338,12 @@ public static function sc_reduce_old($s) $s12 = $s12->addInt32($carry11); $s11 = $s11->subInt32($carry11->shiftLeft(21)); - $s0 = $s0->addInt32($s12->mulInt(666643)); - $s1 = $s1->addInt32($s12->mulInt(470296)); - $s2 = $s2->addInt32($s12->mulInt(654183)); - $s3 = $s3->subInt32($s12->mulInt(997805)); - $s4 = $s4->addInt32($s12->mulInt(136657)); - $s5 = $s5->subInt32($s12->mulInt(683901)); + $s0 = $s0->addInt32($s12->mulInt(666643, 20)); + $s1 = $s1->addInt32($s12->mulInt(470296, 19)); + $s2 = $s2->addInt32($s12->mulInt(654183, 20)); + $s3 = $s3->subInt32($s12->mulInt(997805, 20)); + $s4 = $s4->addInt32($s12->mulInt(136657, 18)); + $s5 = $s5->subInt32($s12->mulInt(683901, 20)); $s12 = new ParagonIE_Sodium_Core32_Int32(); $carry0 = $s0->shiftRight(21); @@ -3285,12 +3383,12 @@ public static function sc_reduce_old($s) $s12 = $s12->addInt32($carry11); $s11 = $s11->subInt32($carry11->shiftLeft(21)); - $s0 = $s0->addInt32($s12->mulInt(666643)); - $s1 = $s1->addInt32($s12->mulInt(470296)); - $s2 = $s2->addInt32($s12->mulInt(654183)); - $s3 = $s3->subInt32($s12->mulInt(997805)); - $s4 = $s4->addInt32($s12->mulInt(136657)); - $s5 = $s5->subInt32($s12->mulInt(683901)); + $s0 = $s0->addInt32($s12->mulInt(666643, 20)); + $s1 = $s1->addInt32($s12->mulInt(470296, 19)); + $s2 = $s2->addInt32($s12->mulInt(654183, 20)); + $s3 = $s3->subInt32($s12->mulInt(997805, 20)); + $s4 = $s4->addInt32($s12->mulInt(136657, 18)); + $s5 = $s5->subInt32($s12->mulInt(683901, 20)); $carry0 = $s0->shiftRight(21); $s1 = $s1->addInt32($carry0); @@ -3345,37 +3443,101 @@ public static function sc_reduce_old($s) $arr = array( (int) ($S0 >> 0), (int) ($S0 >> 8), - (int) (($S0 >> 16) | self::mul($S1, 1 << 5)), + (int) (($S0 >> 16) | ($S1 << 5)), (int) ($S1 >> 3), (int) ($S1 >> 11), - (int) (($S1 >> 19) | self::mul($S2, 1 << 2)), + (int) (($S1 >> 19) | ($S2 << 2)), (int) ($S2 >> 6), - (int) (($S2 >> 14) | self::mul($S3, 1 << 7)), + (int) (($S2 >> 14) | ($S3 << 7)), (int) ($S3 >> 1), (int) ($S3 >> 9), - (int) (($S3 >> 17) | self::mul($S4, 1 << 4)), + (int) (($S3 >> 17) | ($S4 << 4)), (int) ($S4 >> 4), (int) ($S4 >> 12), - (int) (($S4 >> 20) | self::mul($S5, 1 << 1)), + (int) (($S4 >> 20) | ($S5 << 1)), (int) ($S5 >> 7), - (int) (($S5 >> 15) | self::mul($S6, 1 << 6)), + (int) (($S5 >> 15) | ($S6 << 6)), (int) ($S6 >> 2), (int) ($S6 >> 10), - (int) (($S6 >> 18) | self::mul($S7, 1 << 3)), + (int) (($S6 >> 18) | ($S7 << 3)), (int) ($S7 >> 5), (int) ($S7 >> 13), (int) ($S8 >> 0), (int) ($S8 >> 8), - (int) (($S8 >> 16) | self::mul($S9, 1 << 5)), + (int) (($S8 >> 16) | ($S9 << 5)), (int) ($S9 >> 3), (int) ($S9 >> 11), - (int) (($S9 >> 19) | self::mul($S10, 1 << 2)), + (int) (($S9 >> 19) | ($S10 << 2)), (int) ($S10 >> 6), - (int) (($S10 >> 14) | self::mul($S11, 1 << 7)), + (int) (($S10 >> 14) | ($S11 << 7)), (int) ($S11 >> 1), (int) ($S11 >> 9), (int) $S11 >> 17 ); return self::intArrayToString($arr); } + + /** + * multiply by the order of the main subgroup l = 2^252+27742317777372353535851937790883648493 + * + * @param ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $A + * @return ParagonIE_Sodium_Core32_Curve25519_Ge_P3 + * @throws SodiumException + * @throws TypeError + */ + public static function ge_mul_l(ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $A) + { + /** @var array $aslide */ + $aslide = array( + 13, 0, 0, 0, 0, -1, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, + 0, 0, 0, -3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 3, 0, + 0, 0, 0, -13, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, + 0, 0, 11, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, -1, + 0, 0, 0, 0, 3, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, + 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 5, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 + ); + + /** @var array $Ai size 8 */ + $Ai = array(); + + # ge_p3_to_cached(&Ai[0], A); + $Ai[0] = self::ge_p3_to_cached($A); + # ge_p3_dbl(&t, A); + $t = self::ge_p3_dbl($A); + # ge_p1p1_to_p3(&A2, &t); + $A2 = self::ge_p1p1_to_p3($t); + + for ($i = 1; $i < 8; ++$i) { + # ge_add(&t, &A2, &Ai[0]); + $t = self::ge_add($A2, $Ai[$i - 1]); + # ge_p1p1_to_p3(&u, &t); + $u = self::ge_p1p1_to_p3($t); + # ge_p3_to_cached(&Ai[i], &u); + $Ai[$i] = self::ge_p3_to_cached($u); + } + + $r = self::ge_p3_0(); + for ($i = 252; $i >= 0; --$i) { + $t = self::ge_p3_dbl($r); + if ($aslide[$i] > 0) { + # ge_p1p1_to_p3(&u, &t); + $u = self::ge_p1p1_to_p3($t); + # ge_add(&t, &u, &Ai[aslide[i] / 2]); + $t = self::ge_add($u, $Ai[(int)($aslide[$i] / 2)]); + } elseif ($aslide[$i] < 0) { + # ge_p1p1_to_p3(&u, &t); + $u = self::ge_p1p1_to_p3($t); + # ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]); + $t = self::ge_sub($u, $Ai[(int)(-$aslide[$i] / 2)]); + } + } + # ge_p1p1_to_p3(r, &t); + return self::ge_p1p1_to_p3($t); + } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Fe.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Fe.php index b0ce63132ad57..45f0807a6ae07 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Fe.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Fe.php @@ -33,9 +33,11 @@ public function __construct($size = 10) /** * @internal You should not use this directly from another application * - * @param array $array + * @param array $array * @param bool $save_indexes * @return self + * @throws SodiumException + * @throws TypeError */ public static function fromArray($array, $save_indexes = null) { @@ -65,9 +67,11 @@ public static function fromArray($array, $save_indexes = null) /** * @internal You should not use this directly from another application * - * @param array $array + * @param array $array * @param bool $save_indexes * @return self + * @throws SodiumException + * @throws TypeError */ public static function fromIntArray($array, $save_indexes = null) { @@ -79,6 +83,8 @@ public static function fromIntArray($array, $save_indexes = null) } $array = array_values($array); $set = array(); + /** @var int $i */ + /** @var int $v */ foreach ($array as $i => $v) { $set[$i] = ParagonIE_Sodium_Core32_Int32::fromInt($v); } @@ -104,6 +110,8 @@ public static function fromIntArray($array, $save_indexes = null) * @param mixed $offset * @param mixed $value * @return void + * @throws SodiumException + * @throws TypeError */ public function offsetSet($offset, $value) { @@ -123,6 +131,7 @@ public function offsetSet($offset, $value) * * @param mixed $offset * @return bool + * @psalm-suppress MixedArrayOffset */ public function offsetExists($offset) { @@ -134,6 +143,7 @@ public function offsetExists($offset) * * @param mixed $offset * @return void + * @psalm-suppress MixedArrayOffset */ public function offsetUnset($offset) { @@ -144,14 +154,17 @@ public function offsetUnset($offset) * @internal You should not use this directly from another application * * @param mixed $offset - * @return mixed|null + * @return ParagonIE_Sodium_Core32_Int32 + * @psalm-suppress MixedArrayOffset */ public function offsetGet($offset) { if (!isset($this->container[$offset])) { $this->container[(int) $offset] = new ParagonIE_Sodium_Core32_Int32(); } - return $this->container[$offset]; + /** @var ParagonIE_Sodium_Core32_Int32 $get */ + $get = $this->container[$offset]; + return $get; } /** diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/P1p1.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/P1p1.php index aa938348cafc2..ff10b1d7075f6 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/P1p1.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/P1p1.php @@ -37,6 +37,9 @@ class ParagonIE_Sodium_Core32_Curve25519_Ge_P1p1 * @param ParagonIE_Sodium_Core32_Curve25519_Fe|null $y * @param ParagonIE_Sodium_Core32_Curve25519_Fe|null $z * @param ParagonIE_Sodium_Core32_Curve25519_Fe|null $t + * + * @throws SodiumException + * @throws TypeError */ public function __construct( ParagonIE_Sodium_Core32_Curve25519_Fe $x = null, diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/Precomp.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/Precomp.php index 93b399855b894..b590b75de2b96 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/Precomp.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/Ge/Precomp.php @@ -32,6 +32,8 @@ class ParagonIE_Sodium_Core32_Curve25519_Ge_Precomp * @param ParagonIE_Sodium_Core32_Curve25519_Fe $yplusx * @param ParagonIE_Sodium_Core32_Curve25519_Fe $yminusx * @param ParagonIE_Sodium_Core32_Curve25519_Fe $xy2d + * @throws SodiumException + * @throws TypeError */ public function __construct( ParagonIE_Sodium_Core32_Curve25519_Fe $yplusx = null, diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/H.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/H.php index 6083e32794390..48c999a9f3a97 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/H.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Curve25519/H.php @@ -14,7 +14,7 @@ class ParagonIE_Sodium_Core32_Curve25519_H extends ParagonIE_Sodium_Core32_Util /** * See: libsodium's crypto_core/curve25519/ref10/base.h * - * @var array Basically, int[32][8][3][10] + * @var array>>> Basically, int[32][8][3][10] */ protected static $base = array( array( @@ -1366,7 +1366,7 @@ class ParagonIE_Sodium_Core32_Curve25519_H extends ParagonIE_Sodium_Core32_Util /** * See: libsodium's crypto_core/curve25519/ref10/base2.h * - * @var array basically int[8][3] + * @var array>> basically int[8][3] */ protected static $base2 = array( array( @@ -1414,7 +1414,7 @@ class ParagonIE_Sodium_Core32_Curve25519_H extends ParagonIE_Sodium_Core32_Util /** * 37095705934669439343138083508754565189542113879843219016388785533085940283555 * - * @var int[] + * @var array */ protected static $d = array( -10913610, @@ -1432,7 +1432,7 @@ class ParagonIE_Sodium_Core32_Curve25519_H extends ParagonIE_Sodium_Core32_Util /** * 2 * d = 16295367250680780974490674513165176452449235426866156013048779062215315747161 * - * @var int[] + * @var array */ protected static $d2 = array( -21827239, @@ -1450,7 +1450,7 @@ class ParagonIE_Sodium_Core32_Curve25519_H extends ParagonIE_Sodium_Core32_Util /** * sqrt(-1) * - * @var int[] + * @var array */ protected static $sqrtm1 = array( -32595792, diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Ed25519.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Ed25519.php index 0b42db8a3116b..0128d8e0b189b 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Ed25519.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Ed25519.php @@ -16,6 +16,8 @@ abstract class ParagonIE_Sodium_Core32_Ed25519 extends ParagonIE_Sodium_Core32_C * @internal You should not use this directly from another application * * @return string (96 bytes) + * @throws SodiumException + * @throws TypeError */ public static function keypair() { @@ -33,6 +35,8 @@ public static function keypair() * @param string $sk * @param string $seed * @return string + * @throws SodiumException + * @throws TypeError */ public static function seed_keypair(&$pk, &$sk, $seed) { @@ -51,6 +55,7 @@ public static function seed_keypair(&$pk, &$sk, $seed) * * @param string $keypair * @return string + * @throws TypeError */ public static function secretkey($keypair) { @@ -65,6 +70,8 @@ public static function secretkey($keypair) * * @param string $keypair * @return string + * @throws RangeException + * @throws TypeError */ public static function publickey($keypair) { @@ -79,6 +86,8 @@ public static function publickey($keypair) * * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function publickey_from_secretkey($sk) { @@ -93,11 +102,53 @@ public static function publickey_from_secretkey($sk) return self::sk_to_pk($sk); } + /** + * @param string $pk + * @return string + * @throws SodiumException + * @throws TypeError + */ + public static function pk_to_curve25519($pk) + { + if (self::small_order($pk)) { + throw new SodiumException('Public key is on a small order'); + } + $A = self::ge_frombytes_negate_vartime($pk); + $p1 = self::ge_mul_l($A); + if (!self::fe_isnonzero($p1->X)) { + throw new SodiumException('Unexpected zero result'); + } + + # fe_1(one_minus_y); + # fe_sub(one_minus_y, one_minus_y, A.Y); + # fe_invert(one_minus_y, one_minus_y); + $one_minux_y = self::fe_invert( + self::fe_sub( + self::fe_1(), + $A->Y + ) + ); + + + # fe_1(x); + # fe_add(x, x, A.Y); + # fe_mul(x, x, one_minus_y); + $x = self::fe_mul( + self::fe_add(self::fe_1(), $A->Y), + $one_minux_y + ); + + # fe_tobytes(curve25519_pk, x); + return self::fe_tobytes($x); + } + /** * @internal You should not use this directly from another application * * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sk_to_pk($sk) { @@ -114,6 +165,8 @@ public static function sk_to_pk($sk) * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign($message, $sk) { @@ -128,7 +181,8 @@ public static function sign($message, $sk) * @param string $message A signed message * @param string $pk Public key * @return string Message (without signature) - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function sign_open($message, $pk) { @@ -141,7 +195,7 @@ public static function sign_open($message, $pk) if (self::verify_detached($signature, $message, $pk)) { return $message; } - throw new Exception('Invalid signature'); + throw new SodiumException('Invalid signature'); } /** @@ -150,6 +204,8 @@ public static function sign_open($message, $pk) * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign_detached($message, $sk) { @@ -200,7 +256,7 @@ public static function sign_detached($message, $sk) try { ParagonIE_Sodium_Compat::memzero($az); - } catch (Error $ex) { + } catch (SodiumException $ex) { $az = null; } return $sig; @@ -213,28 +269,29 @@ public static function sign_detached($message, $sk) * @param string $message * @param string $pk * @return bool - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function verify_detached($sig, $message, $pk) { if (self::strlen($sig) < 64) { - throw new Exception('Signature is too short'); + throw new SodiumException('Signature is too short'); } if (self::check_S_lt_L(self::substr($sig, 32, 32))) { - throw new Exception('S < L - Invalid signature'); + throw new SodiumException('S < L - Invalid signature'); } if (self::small_order($sig)) { - throw new Exception('Signature is on too small of an order'); + throw new SodiumException('Signature is on too small of an order'); } if ((self::chrToInt($sig[63]) & 224) !== 0) { - throw new Exception('Invalid signature'); + throw new SodiumException('Invalid signature'); } $d = 0; for ($i = 0; $i < 32; ++$i) { $d |= self::chrToInt($pk[$i]); } if ($d === 0) { - throw new Exception('All zero public key'); + throw new SodiumException('All zero public key'); } /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */ @@ -279,12 +336,13 @@ public static function verify_detached($sig, $message, $pk) * * @param string $S * @return bool - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function check_S_lt_L($S) { if (self::strlen($S) < 32) { - throw new Exception('Signature must be 32 bytes'); + throw new SodiumException('Signature must be 32 bytes'); } static $L = array( 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, @@ -292,6 +350,7 @@ public static function check_S_lt_L($S) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 ); + /** @var array $L */ $c = 0; $n = 1; $i = 32; @@ -313,6 +372,8 @@ public static function check_S_lt_L($S) /** * @param string $R * @return bool + * @throws SodiumException + * @throws TypeError */ public static function small_order($R) { @@ -402,6 +463,7 @@ public static function small_order($R) 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ) ); + /** @var array> $blacklist */ $countBlacklist = count($blacklist); for ($i = 0; $i < $countBlacklist; ++$i) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/HChaCha20.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/HChaCha20.php index edc4a54ebdae7..551d995e439f3 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/HChaCha20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/HChaCha20.php @@ -14,6 +14,8 @@ class ParagonIE_Sodium_Core32_HChaCha20 extends ParagonIE_Sodium_Core32_ChaCha20 * @param string $key * @param string|null $c * @return string + * @throws SodiumException + * @throws TypeError */ public static function hChaCha20($in = '', $key = '', $c = null) { @@ -49,34 +51,42 @@ public static function hChaCha20($in = '', $key = '', $c = null) /** * @param array $ctx * @return string + * @throws SodiumException + * @throws TypeError */ protected static function hChaCha20Bytes(array $ctx) { - /** - * @var ParagonIE_Sodium_Core32_Int32 $x0 - * @var ParagonIE_Sodium_Core32_Int32 $x1 - * @var ParagonIE_Sodium_Core32_Int32 $x2 - * @var ParagonIE_Sodium_Core32_Int32 $x3 - * @var ParagonIE_Sodium_Core32_Int32 $x12 - * @var ParagonIE_Sodium_Core32_Int32 $x13 - * @var ParagonIE_Sodium_Core32_Int32 $x14 - * @var ParagonIE_Sodium_Core32_Int32 $x15 - */ + /** @var ParagonIE_Sodium_Core32_Int32 $x0 */ $x0 = $ctx[0]; + /** @var ParagonIE_Sodium_Core32_Int32 $x1 */ $x1 = $ctx[1]; + /** @var ParagonIE_Sodium_Core32_Int32 $x2 */ $x2 = $ctx[2]; + /** @var ParagonIE_Sodium_Core32_Int32 $x3 */ $x3 = $ctx[3]; + /** @var ParagonIE_Sodium_Core32_Int32 $x4 */ $x4 = $ctx[4]; + /** @var ParagonIE_Sodium_Core32_Int32 $x5 */ $x5 = $ctx[5]; + /** @var ParagonIE_Sodium_Core32_Int32 $x6 */ $x6 = $ctx[6]; + /** @var ParagonIE_Sodium_Core32_Int32 $x7 */ $x7 = $ctx[7]; + /** @var ParagonIE_Sodium_Core32_Int32 $x8 */ $x8 = $ctx[8]; + /** @var ParagonIE_Sodium_Core32_Int32 $x9 */ $x9 = $ctx[9]; + /** @var ParagonIE_Sodium_Core32_Int32 $x10 */ $x10 = $ctx[10]; + /** @var ParagonIE_Sodium_Core32_Int32 $x11 */ $x11 = $ctx[11]; + /** @var ParagonIE_Sodium_Core32_Int32 $x12 */ $x12 = $ctx[12]; + /** @var ParagonIE_Sodium_Core32_Int32 $x13 */ $x13 = $ctx[13]; + /** @var ParagonIE_Sodium_Core32_Int32 $x14 */ $x14 = $ctx[14]; + /** @var ParagonIE_Sodium_Core32_Int32 $x15 */ $x15 = $ctx[15]; for ($i = 0; $i < 10; ++$i) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/HSalsa20.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/HSalsa20.php index 75762d1d53e99..39287f2d31792 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/HSalsa20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/HSalsa20.php @@ -21,6 +21,8 @@ abstract class ParagonIE_Sodium_Core32_HSalsa20 extends ParagonIE_Sodium_Core32_ * @param string $k * @param string|null $c * @return string + * @throws SodiumException + * @throws TypeError */ public static function hsalsa20($in, $k, $c = null) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Int32.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Int32.php index db92970fd9d24..c5c8058cdf53d 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Int32.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Int32.php @@ -22,17 +22,24 @@ class ParagonIE_Sodium_Core32_Int32 */ public $overflow = 0; + /** + * @var bool + */ + public $unsignedInt = false; + /** * ParagonIE_Sodium_Core32_Int32 constructor. * @param array $array + * @param bool $unsignedInt */ - public function __construct($array = array(0, 0)) + public function __construct($array = array(0, 0), $unsignedInt = false) { $this->limbs = array( (int) $array[0], (int) $array[1] ); $this->overflow = 0; + $this->unsignedInt = $unsignedInt; } /** @@ -44,13 +51,18 @@ public function __construct($array = array(0, 0)) public function addInt32(ParagonIE_Sodium_Core32_Int32 $addend) { $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $tmp */ $tmp = $this->limbs[1] + $addend->limbs[1]; + /** @var int $carry */ $carry = $tmp >> 16; $return->limbs[1] = (int) ($tmp & 0xffff); + /** @var int $tmp */ $tmp = $this->limbs[0] + $addend->limbs[0] + $carry; $return->limbs[0] = (int) ($tmp & 0xffff); + /** @var int overflow */ $return->overflow = $this->overflow + $addend->overflow + ($tmp >> 16); return $return; @@ -61,20 +73,27 @@ public function addInt32(ParagonIE_Sodium_Core32_Int32 $addend) * * @param int $int * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError */ public function addInt($int) { ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; - $tmp = $this->limbs[1] + ($int & 0xffff); + /** @var int $tmp */ + $tmp = ($this->limbs[1] & 0xffff) + ($int & 0xffff); + /** @var int $carry */ $carry = $tmp >> 16; $return->limbs[1] = (int) ($tmp & 0xffff); + /** @var int $tmp */ $tmp = $this->limbs[0] + (($int >> 16) & 0xffff) + $carry; $return->limbs[0] = (int) ($tmp & 0xffff); - $return->overflow = $this->overflow + $tmp >> 16; + /** @var int overflow */ + $return->overflow = $this->overflow + ($tmp >> 16); return $return; } @@ -91,9 +110,13 @@ public function compareInt($b = 0) $j = 0; while ($i > 0) { --$i; + /** @var int $x1 */ $x1 = $this->limbs[$i]; + /** @var int $x2 */ $x2 = ($b >> ($j << 4)) & 0xffff; + /** @var int $gt */ $gt |= (($x2 - $x1) >> 8) & $eq; + /** @var int $eq */ $eq &= (($x2 ^ $x1) - 1) >> 8; } return ($gt + $gt - $eq) + 1; @@ -105,13 +128,16 @@ public function compareInt($b = 0) */ public function mask($m = 0) { + /** @var int $hi */ $hi = ($m >> 16) & 0xffff; + /** @var int $lo */ $lo = ($m & 0xffff); return new ParagonIE_Sodium_Core32_Int32( array( (int) ($this->limbs[0] & $hi), (int) ($this->limbs[1] & $lo) - ) + ), + $this->unsignedInt ); } @@ -119,6 +145,8 @@ public function mask($m = 0) * @param int $int * @param int $size * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError */ public function mulInt($int = 0, $size = 0) { @@ -127,9 +155,11 @@ public function mulInt($int = 0, $size = 0) if (!$size) { $size = 31; } + /** @var int $size */ $a = clone $this; $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; for ($i = $size; $i >= 0; --$i) { $m = (int) (-($int & 1)); @@ -144,6 +174,8 @@ public function mulInt($int = 0, $size = 0) * @param ParagonIE_Sodium_Core32_Int32 $int * @param int $size * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError */ public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0) { @@ -151,11 +183,14 @@ public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0) if (!$size) { $size = 31; } + /** @var int $size */ $a = clone $this; $b = clone $int; $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $i */ for ($i = $size; $i >= 0; --$i) { $m = (int) (-($b->limbs[1] & 1)); $return = $return->addInt32($a->mask($m)); @@ -174,10 +209,12 @@ public function mulInt32(ParagonIE_Sodium_Core32_Int32 $int, $size = 0) public function orInt32(ParagonIE_Sodium_Core32_Int32 $b) { $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; $return->limbs = array( (int) ($this->limbs[0] | $b->limbs[0]), (int) ($this->limbs[1] | $b->limbs[1]) ); + /** @var int overflow */ $return->overflow = $this->overflow | $b->overflow; return $return; } @@ -203,28 +240,45 @@ public function isLessThanInt($b = 0) /** * @param int $c * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArrayAccess */ public function rotateLeft($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; $c &= 31; if ($c === 0) { // NOP, but we want a copy. $return->limbs = $this->limbs; } else { + /** @var int $c */ + + /** @var int $idx_shift */ $idx_shift = ($c >> 4) & 1; + + /** @var int $sub_shift */ $sub_shift = $c & 15; + /** @var array $limbs */ + $limbs =& $return->limbs; + + /** @var array $myLimbs */ + $myLimbs =& $this->limbs; + for ($i = 1; $i >= 0; --$i) { + /** @var int $j */ $j = ($i + $idx_shift) & 1; + /** @var int $k */ $k = ($i + $idx_shift + 1) & 1; - $return->limbs[$i] = (int) ( + $limbs[$i] = (int) ( ( - ($this->limbs[$j] << $sub_shift) + ($myLimbs[$j] << $sub_shift) | - ($this->limbs[$k] >> (16 - $sub_shift)) + ($myLimbs[$k] >> (16 - $sub_shift)) ) & 0xffff ); } @@ -237,28 +291,46 @@ public function rotateLeft($c = 0) * * @param int $c * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedArrayAccess */ public function rotateRight($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; $c &= 31; + /** @var int $c */ if ($c === 0) { // NOP, but we want a copy. $return->limbs = $this->limbs; } else { + /** @var int $c */ + + /** @var int $idx_shift */ $idx_shift = ($c >> 4) & 1; + + /** @var int $sub_shift */ $sub_shift = $c & 15; + /** @var array $limbs */ + $limbs =& $return->limbs; + + /** @var array $myLimbs */ + $myLimbs =& $this->limbs; + for ($i = 1; $i >= 0; --$i) { + /** @var int $j */ $j = ($i - $idx_shift) & 1; + /** @var int $k */ $k = ($i - $idx_shift - 1) & 1; - $return->limbs[$i] = (int) ( + $limbs[$i] = (int) ( ( - ($this->limbs[$j] >> ($sub_shift)) + ($myLimbs[$j] >> (int) ($sub_shift)) | - ($this->limbs[$k] << (16 - $sub_shift)) + ($myLimbs[$k] << (16 - (int) ($sub_shift))) ) & 0xffff ); } @@ -266,24 +338,43 @@ public function rotateRight($c = 0) return $return; } + /** + * @param bool $bool + * @return self + */ + public function setUnsignedInt($bool = false) + { + $this->unsignedInt = !empty($bool); + return $this; + } + /** * @param int $c * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError */ public function shiftLeft($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; $c &= 63; + /** @var int $c */ if ($c === 0) { $return->limbs = $this->limbs; } elseif ($c < 0) { + /** @var int $c */ return $this->shiftRight(-$c); } else { + /** @var int $c */ + /** @var int $tmp */ $tmp = $this->limbs[1] << $c; $return->limbs[1] = (int)($tmp & 0xffff); + /** @var int $carry */ $carry = $tmp >> 16; + /** @var int $tmp */ $tmp = ($this->limbs[0] << $c) | ($carry & 0xffff); $return->limbs[0] = (int) ($tmp & 0xffff); } @@ -293,29 +384,40 @@ public function shiftLeft($c = 0) /** * @param int $c * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedOperand */ public function shiftRight($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; $c &= 63; + /** @var int $c */ if ($c >= 16) { $return->limbs = array( - 0, - $this->limbs[0] + (int) ($this->overflow & 0xffff), + (int) ($this->limbs[0]) ); + $return->overflow = $this->overflow >> 16; return $return->shiftRight($c & 15); } if ($c === 0) { $return->limbs = $this->limbs; } elseif ($c < 0) { + /** @var int $c */ return $this->shiftLeft(-$c); } else { if (is_null($c)) { throw new TypeError(); } + /** @var int $c */ + // $return->limbs[0] = (int) (($this->limbs[0] >> $c) & 0xffff); + $carryLeft = (int) ($this->overflow & ((1 << ($c + 1)) - 1)); + $return->limbs[0] = (int) ((($this->limbs[0] >> $c) | ($carryLeft << (16 - $c))) & 0xffff); $carryRight = (int) ($this->limbs[0] & ((1 << ($c + 1)) - 1)); - $return->limbs[0] = (int) (($this->limbs[0] >> $c) & 0xffff); $return->limbs[1] = (int) ((($this->limbs[1] >> $c) | ($carryRight << (16 - $c))) & 0xffff); $return->overflow >>= $c; } @@ -327,17 +429,23 @@ public function shiftRight($c = 0) * * @param int $int * @return ParagonIE_Sodium_Core32_Int32 + * @throws SodiumException + * @throws TypeError */ public function subInt($int) { ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $tmp */ $tmp = $this->limbs[1] - ($int & 0xffff); + /** @var int $carry */ $carry = $tmp >> 16; $return->limbs[1] = (int) ($tmp & 0xffff); + /** @var int $tmp */ $tmp = $this->limbs[0] - (($int >> 16) & 0xffff) + $carry; $return->limbs[0] = (int) ($tmp & 0xffff); return $return; @@ -352,11 +460,15 @@ public function subInt($int) public function subInt32(ParagonIE_Sodium_Core32_Int32 $b) { $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $tmp */ $tmp = $this->limbs[1] - ($b->limbs[1] & 0xffff); + /** @var int $carry */ $carry = $tmp >> 16; $return->limbs[1] = (int) ($tmp & 0xffff); + /** @var int $tmp */ $tmp = $this->limbs[0] - ($b->limbs[0] & 0xffff) + $carry; $return->limbs[0] = (int) ($tmp & 0xffff); return $return; @@ -371,6 +483,7 @@ public function subInt32(ParagonIE_Sodium_Core32_Int32 $b) public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b) { $return = new ParagonIE_Sodium_Core32_Int32(); + $return->unsignedInt = $this->unsignedInt; $return->limbs = array( (int) ($this->limbs[0] ^ $b->limbs[0]), (int) ($this->limbs[1] ^ $b->limbs[1]) @@ -381,6 +494,8 @@ public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b) /** * @param int $signed * @return self + * @throws SodiumException + * @throws TypeError */ public static function fromInt($signed) { @@ -397,6 +512,8 @@ public static function fromInt($signed) /** * @param string $string * @return self + * @throws SodiumException + * @throws TypeError */ public static function fromString($string) { @@ -419,6 +536,8 @@ public static function fromString($string) /** * @param string $string * @return self + * @throws SodiumException + * @throws TypeError */ public static function fromReverseString($string) { @@ -448,6 +567,7 @@ public function toArray() /** * @return string + * @throws TypeError */ public function toString() { @@ -478,6 +598,8 @@ public function toInt32() $return = new ParagonIE_Sodium_Core32_Int32(); $return->limbs[0] = (int) ($this->limbs[0] & 0xffff); $return->limbs[1] = (int) ($this->limbs[1] & 0xffff); + $return->unsignedInt = $this->unsignedInt; + $return->overflow = (int) ($this->overflow & 0x7fffffff); return $return; } @@ -487,9 +609,15 @@ public function toInt32() public function toInt64() { $return = new ParagonIE_Sodium_Core32_Int64(); - $neg = -(($this->limbs[0] >> 15) & 1); - $return->limbs[0] = (int) ($neg & 0xffff); - $return->limbs[1] = (int) ($neg & 0xffff); + $return->unsignedInt = $this->unsignedInt; + if ($this->unsignedInt) { + $return->limbs[0] += (($this->overflow >> 16) & 0xffff); + $return->limbs[1] += (($this->overflow) & 0xffff); + } else { + $neg = -(($this->limbs[0] >> 15) & 1); + $return->limbs[0] = (int)($neg & 0xffff); + $return->limbs[1] = (int)($neg & 0xffff); + } $return->limbs[2] = (int) ($this->limbs[0] & 0xffff); $return->limbs[3] = (int) ($this->limbs[1] & 0xffff); return $return; @@ -497,6 +625,7 @@ public function toInt64() /** * @return string + * @throws TypeError */ public function toReverseString() { @@ -511,6 +640,11 @@ public function toReverseString() */ public function __toString() { - return $this->toString(); + try { + return $this->toString(); + } catch (TypeError $ex) { + // PHP engine can't handle exceptions from __toString() + return ''; + } } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Int64.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Int64.php index ecaf2632a2228..f7a9975395a8f 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Int64.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Int64.php @@ -19,11 +19,17 @@ class ParagonIE_Sodium_Core32_Int64 */ public $overflow = 0; + /** + * @var bool + */ + public $unsignedInt = false; + /** * ParagonIE_Sodium_Core32_Int64 constructor. * @param array $array + * @param bool $unsignedInt */ - public function __construct($array = array(0, 0, 0, 0)) + public function __construct($array = array(0, 0, 0, 0), $unsignedInt = false) { $this->limbs = array( (int) $array[0], @@ -32,6 +38,7 @@ public function __construct($array = array(0, 0, 0, 0)) (int) $array[3] ); $this->overflow = 0; + $this->unsignedInt = $unsignedInt; } /** @@ -43,9 +50,13 @@ public function __construct($array = array(0, 0, 0, 0)) public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend) { $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $carry */ $carry = 0; for ($i = 3; $i >= 0; --$i) { + /** @var int $tmp */ $tmp = $this->limbs[$i] + $addend->limbs[$i] + $carry; + /** @var int $carry */ $carry = $tmp >> 16; $return->limbs[$i] = (int) ($tmp & 0xffff); } @@ -58,24 +69,34 @@ public function addInt64(ParagonIE_Sodium_Core32_Int64 $addend) * * @param int $int * @return ParagonIE_Sodium_Core32_Int64 + * @throws TypeError */ public function addInt($int) { ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $carry */ $carry = 0; for ($i = 3; $i >= 0; --$i) { + /** @var int $step */ $step = (3 - $i) << 4; // 0, 16, 32, 48 if ($i < 2) { + /** @var int $toAdd */ $toAdd = 0; } else { + /** @var int $toAdd */ $toAdd = (($int >> $step) & 0xffff); } + /** @var int $tmp */ $tmp = $this->limbs[$i] + $toAdd + $carry; + + /** @var int $carry */ $carry = $tmp >> 16; $return->limbs[$i] = (int) ($tmp & 0xffff); } + /** @var int overflow */ $return->overflow = $carry; return $return; } @@ -93,9 +114,13 @@ public function compareInt($b = 0) $j = 0; while ($i > 0) { --$i; + /** @var int $x1 */ $x1 = $this->limbs[$i]; + /** @var int $x2 */ $x2 = ($b >> ($j << 4)) & 0xffff; + /** int */ $gt |= (($x2 - $x1) >> 8) & $eq; + /** int */ $eq &= (($x2 ^ $x1) - 1) >> 8; } return ($gt + $gt - $eq) + 1; @@ -119,7 +144,6 @@ public function isLessThanInt($b = 0) return $this->compareInt($b) < 0; } - /** * @param int $hi * @param int $lo @@ -127,9 +151,13 @@ public function isLessThanInt($b = 0) */ public function mask64($hi = 0, $lo = 0) { + /** @var int $a */ $a = ($hi >> 16) & 0xffff; + /** @var int $b */ $b = ($hi) & 0xffff; + /** @var int $c */ $c = ($lo >> 16) & 0xffff; + /** @var int $d */ $d = ($lo & 0xffff); return new ParagonIE_Sodium_Core32_Int64( array( @@ -137,7 +165,8 @@ public function mask64($hi = 0, $lo = 0) $this->limbs[1] & $b, $this->limbs[2] & $c, $this->limbs[3] & $d - ) + ), + $this->unsignedInt ); } @@ -145,6 +174,9 @@ public function mask64($hi = 0, $lo = 0) * @param int $int * @param int $size * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedAssignment */ public function mulInt($int = 0, $size = 0) { @@ -156,6 +188,7 @@ public function mulInt($int = 0, $size = 0) $a = clone $this; $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; for ($i = $size; $i >= 0; --$i) { $return = $return->addInt64( @@ -170,10 +203,54 @@ public function mulInt($int = 0, $size = 0) return $return; } + /** + * @param ParagonIE_Sodium_Core32_Int64 $A + * @param ParagonIE_Sodium_Core32_Int64 $B + * @return array + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedInferredReturnType + */ + public static function ctSelect( + ParagonIE_Sodium_Core32_Int64 $A, + ParagonIE_Sodium_Core32_Int64 $B + ) { + $a = clone $A; + $b = clone $B; + /** @var int $aNeg */ + $aNeg = ($a->limbs[0] >> 15) & 1; + /** @var int $bNeg */ + $bNeg = ($b->limbs[0] >> 15) & 1; + /** @var int $m */ + $m = (-($aNeg & $bNeg)) | 1; + /** @var int $swap */ + $swap = $bNeg & ~$aNeg; + /** @var int $d */ + $d = -$swap; + + /* + if ($bNeg && !$aNeg) { + $a = clone $int; + $b = clone $this; + } elseif($bNeg && $aNeg) { + $a = $this->mulInt(-1); + $b = $int->mulInt(-1); + } + */ + $x = $a->xorInt64($b)->mask64($d, $d); + return array( + $a->xorInt64($x)->mulInt($m), + $b->xorInt64($x)->mulInt($m) + ); + } + /** * @param ParagonIE_Sodium_Core32_Int64 $int * @param int $size * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedAssignment */ public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0) { @@ -181,17 +258,14 @@ public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0) if (!$size) { $size = 63; } + list($a, $b) = self::ctSelect($this, $int); - $a = clone $this; - $b = clone $int; $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $size $i */ + /** @var int $i */ for ($i = $size; $i >= 0; --$i) { - /* - $c += (int) ($a & -($b & 1)); - $a <<= 1; - $b >>= 1; - */ $return = $return->addInt64( $a->mask64( (int) (-($b->limbs[3] & 1)), @@ -213,6 +287,7 @@ public function mulInt64(ParagonIE_Sodium_Core32_Int64 $int, $size = 0) public function orInt64(ParagonIE_Sodium_Core32_Int64 $b) { $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; $return->limbs = array( (int) ($this->limbs[0] | $b->limbs[0]), (int) ($this->limbs[1] | $b->limbs[1]), @@ -225,28 +300,41 @@ public function orInt64(ParagonIE_Sodium_Core32_Int64 $b) /** * @param int $c * @return ParagonIE_Sodium_Core32_Int64 + * @throws TypeError + * @psalm-suppress MixedArrayAccess */ public function rotateLeft($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; $c &= 63; if ($c === 0) { // NOP, but we want a copy. $return->limbs = $this->limbs; } else { + /** @var array $limbs */ + $limbs =& $return->limbs; + + /** @var array $myLimbs */ + $myLimbs =& $this->limbs; + + /** @var int $idx_shift */ $idx_shift = ($c >> 4) & 3; + /** @var int $sub_shift */ $sub_shift = $c & 15; for ($i = 3; $i >= 0; --$i) { + /** @var int $j */ $j = ($i + $idx_shift) & 3; + /** @var int $k */ $k = ($i + $idx_shift + 1) & 3; - $return->limbs[$i] = (int) ( + $limbs[$i] = (int) ( ( - ($this->limbs[$j] << $sub_shift) + ($myLimbs[$j] << $sub_shift) | - ($this->limbs[$k] >> (16 - $sub_shift)) + ($myLimbs[$k] >> (16 - $sub_shift)) ) & 0xffff ); } @@ -259,28 +347,43 @@ public function rotateLeft($c = 0) * * @param int $c * @return ParagonIE_Sodium_Core32_Int64 + * @throws TypeError + * @psalm-suppress MixedArrayAccess */ public function rotateRight($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); + /** @var ParagonIE_Sodium_Core32_Int64 $return */ $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; $c &= 63; + /** @var int $c */ if ($c === 0) { // NOP, but we want a copy. $return->limbs = $this->limbs; } else { + /** @var array $limbs */ + $limbs =& $return->limbs; + + /** @var array $myLimbs */ + $myLimbs =& $this->limbs; + + /** @var int $idx_shift */ $idx_shift = ($c >> 4) & 3; + /** @var int $sub_shift */ $sub_shift = $c & 15; for ($i = 3; $i >= 0; --$i) { + /** @var int $j */ $j = ($i - $idx_shift) & 3; + /** @var int $k */ $k = ($i - $idx_shift - 1) & 3; - $return->limbs[$i] = (int) ( + $limbs[$i] = (int) ( ( - ($this->limbs[$j] >> ($sub_shift)) + ($myLimbs[$j] >> (int) ($sub_shift)) | - ($this->limbs[$k] << (16 - $sub_shift)) + ($myLimbs[$k] << (16 - (int) ($sub_shift))) ) & 0xffff ); } @@ -290,13 +393,16 @@ public function rotateRight($c = 0) /** * @param int $c * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException * @throws TypeError */ public function shiftLeft($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; $c &= 63; + /** @var int $c */ if ($c >= 16) { if ($c >= 48) { @@ -317,15 +423,19 @@ public function shiftLeft($c = 0) if ($c === 0) { $return->limbs = $this->limbs; } elseif ($c < 0) { + /** @var int $c */ return $this->shiftRight(-$c); } else { if (is_null($c)) { throw new TypeError(); } + /** @var int $carry */ $carry = 0; for ($i = 3; $i >= 0; --$i) { + /** @var int $tmp */ $tmp = ($this->limbs[$i] << $c) | ($carry & 0xffff); $return->limbs[$i] = (int) ($tmp & 0xffff); + /** @var int $carry */ $carry = $tmp >> 16; } } @@ -335,13 +445,16 @@ public function shiftLeft($c = 0) /** * @param int $c * @return ParagonIE_Sodium_Core32_Int64 + * @throws SodiumException * @throws TypeError */ public function shiftRight($c = 0) { ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; $c &= 63; + /** @var int $c */ $negative = -(($this->limbs[0] >> 15) & 1); if ($c >= 16) { @@ -375,9 +488,10 @@ public function shiftRight($c = 0) } elseif ($c < 0) { return $this->shiftLeft(-$c); } else { - if (is_null($c)) { + if (!is_int($c)) { throw new TypeError(); } + /** @var int $carryRight */ $carryRight = ($negative & 0xffff); $mask = (int) (((1 << ($c + 1)) - 1) & 0xffff); for ($i = 0; $i < 4; ++$i) { @@ -396,16 +510,21 @@ public function shiftRight($c = 0) * * @param int $int * @return ParagonIE_Sodium_Core32_Int64 + * @throws TypeError */ public function subInt($int) { ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1); $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $carry */ $carry = 0; for ($i = 3; $i >= 0; --$i) { + /** @var int $tmp */ $tmp = $this->limbs[$i] - (($int >> 16) & 0xffff) + $carry; + /** @var int $carry */ $carry = $tmp >> 16; $return->limbs[$i] = (int) ($tmp & 0xffff); } @@ -421,12 +540,15 @@ public function subInt($int) public function subInt64(ParagonIE_Sodium_Core32_Int64 $b) { $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; + /** @var int $carry */ $carry = 0; for ($i = 3; $i >= 0; --$i) { + /** @var int $tmp */ $tmp = $this->limbs[$i] - $b->limbs[$i] + $carry; + /** @var int $carry */ $carry = ($tmp >> 16); $return->limbs[$i] = (int) ($tmp & 0xffff); - } return $return; } @@ -440,6 +562,7 @@ public function subInt64(ParagonIE_Sodium_Core32_Int64 $b) public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b) { $return = new ParagonIE_Sodium_Core32_Int64(); + $return->unsignedInt = $this->unsignedInt; $return->limbs = array( (int) ($this->limbs[0] ^ $b->limbs[0]), (int) ($this->limbs[1] ^ $b->limbs[1]), @@ -453,6 +576,7 @@ public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b) * @param int $low * @param int $high * @return self + * @throws TypeError */ public static function fromInts($low, $high) { @@ -472,6 +596,7 @@ public static function fromInts($low, $high) /** * @param string $string * @return self + * @throws TypeError */ public static function fromString($string) { @@ -498,6 +623,7 @@ public static function fromString($string) /** * @param string $string * @return self + * @throws TypeError */ public static function fromReverseString($string) { @@ -540,6 +666,8 @@ public function toInt32() $return = new ParagonIE_Sodium_Core32_Int32(); $return->limbs[0] = (int) ($this->limbs[2]); $return->limbs[1] = (int) ($this->limbs[3]); + $return->unsignedInt = $this->unsignedInt; + $return->overflow = (int) (ParagonIE_Sodium_Core32_Util::abs($this->limbs[1], 16) & 0xffff); return $return; } @@ -553,11 +681,24 @@ public function toInt64() $return->limbs[1] = (int) ($this->limbs[1]); $return->limbs[2] = (int) ($this->limbs[2]); $return->limbs[3] = (int) ($this->limbs[3]); + $return->unsignedInt = $this->unsignedInt; + $return->overflow = ParagonIE_Sodium_Core32_Util::abs($this->overflow); return $return; } + /** + * @param bool $bool + * @return self + */ + public function setUnsignedInt($bool = false) + { + $this->unsignedInt = !empty($bool); + return $this; + } + /** * @return string + * @throws TypeError */ public function toString() { @@ -573,6 +714,7 @@ public function toString() /** * @return string + * @throws TypeError */ public function toReverseString() { @@ -591,6 +733,11 @@ public function toReverseString() */ public function __toString() { - return $this->toString(); + try { + return $this->toString(); + } catch (TypeError $ex) { + // PHP engine can't handle exceptions from __toString() + return ''; + } } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305.php index dc93773819bef..b9dfaf3c09ebb 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305.php @@ -17,6 +17,8 @@ abstract class ParagonIE_Sodium_Core32_Poly1305 extends ParagonIE_Sodium_Core32_ * @param string $m * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function onetimeauth($m, $key) { @@ -40,6 +42,8 @@ public static function onetimeauth($m, $key) * @param string $m * @param string $key * @return bool + * @throws SodiumException + * @throws TypeError */ public static function onetimeauth_verify($mac, $m, $key) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305/State.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305/State.php index 5f126e16fb37c..08a5399e419ca 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305/State.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Poly1305/State.php @@ -46,6 +46,8 @@ class ParagonIE_Sodium_Core32_Poly1305_State extends ParagonIE_Sodium_Core32_Uti * * @param string $key * @throws InvalidArgumentException + * @throws SodiumException + * @throws TypeError */ public function __construct($key = '') { @@ -58,40 +60,49 @@ public function __construct($key = '') $this->r = array( // st->r[0] = ... ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 0, 4)) + ->setUnsignedInt(true) ->mask(0x3ffffff), // st->r[1] = ... ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 3, 4)) + ->setUnsignedInt(true) ->shiftRight(2) ->mask(0x3ffff03), // st->r[2] = ... ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 6, 4)) + ->setUnsignedInt(true) ->shiftRight(4) ->mask(0x3ffc0ff), // st->r[3] = ... ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 9, 4)) + ->setUnsignedInt(true) ->shiftRight(6) ->mask(0x3f03fff), // st->r[4] = ... ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 12, 4)) + ->setUnsignedInt(true) ->shiftRight(8) ->mask(0x00fffff) ); /* h = 0 */ $this->h = array( - new ParagonIE_Sodium_Core32_Int32(), - new ParagonIE_Sodium_Core32_Int32(), - new ParagonIE_Sodium_Core32_Int32(), - new ParagonIE_Sodium_Core32_Int32(), - new ParagonIE_Sodium_Core32_Int32() + new ParagonIE_Sodium_Core32_Int32(array(0, 0), true), + new ParagonIE_Sodium_Core32_Int32(array(0, 0), true), + new ParagonIE_Sodium_Core32_Int32(array(0, 0), true), + new ParagonIE_Sodium_Core32_Int32(array(0, 0), true), + new ParagonIE_Sodium_Core32_Int32(array(0, 0), true) ); /* save pad for later */ $this->pad = array( - ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4))->toInt64(), - ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4))->toInt64(), - ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4))->toInt64(), - ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4))->toInt64(), + ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 16, 4)) + ->setUnsignedInt(true)->toInt64(), + ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 20, 4)) + ->setUnsignedInt(true)->toInt64(), + ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 24, 4)) + ->setUnsignedInt(true)->toInt64(), + ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($key, 28, 4)) + ->setUnsignedInt(true)->toInt64(), ); $this->leftover = 0; @@ -103,6 +114,8 @@ public function __construct($key = '') * * @param string $message * @return self + * @throws SodiumException + * @throws TypeError */ public function update($message = '') { @@ -110,6 +123,7 @@ public function update($message = '') /* handle leftover */ if ($this->leftover) { + /** @var int $want */ $want = ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - $this->leftover; if ($want > $bytes) { $want = $bytes; @@ -136,8 +150,10 @@ public function update($message = '') /* process full blocks */ if ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) { + /** @var int $want */ $want = $bytes & ~(ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE - 1); if ($want >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) { + /** @var string $block */ $block = self::substr($message, 0, $want); if (self::strlen($block) >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) { $this->blocks($block, $want); @@ -164,14 +180,17 @@ public function update($message = '') * @param string $message * @param int $bytes * @return self + * @throws SodiumException + * @throws TypeError */ public function blocks($message, $bytes) { if (self::strlen($message) < 16) { $message = str_pad($message, 16, "\x00", STR_PAD_RIGHT); } - $hibit = ParagonIE_Sodium_Core32_Int32::fromInt($this->final ? 0 : 1 << 24); /* 1 << 128 */ - $zero = new ParagonIE_Sodium_Core32_Int64(); + $hibit = ParagonIE_Sodium_Core32_Int32::fromInt((int) ($this->final ? 0 : 1 << 24)); /* 1 << 128 */ + $hibit->setUnsignedInt(true); + $zero = new ParagonIE_Sodium_Core32_Int64(array(0, 0, 0, 0), true); /** * @var ParagonIE_Sodium_Core32_Int64 $d0 * @var ParagonIE_Sodium_Core32_Int64 $d1 @@ -289,7 +308,7 @@ public function blocks($message, $bytes) $c = $d4->shiftRight(26); $h4 = $d4->toInt32()->mask(0x3ffffff); - $h0 = $h0->addInt32($c->toInt32()->mulInt(5)); + $h0 = $h0->addInt32($c->toInt32()->mulInt(5, 3)); $c = $h0->shiftRight(26); $h0 = $h0->mask(0x3ffffff); @@ -312,6 +331,8 @@ public function blocks($message, $bytes) * @internal You should not use this directly from another application * * @return string + * @throws SodiumException + * @throws TypeError */ public function finish() { @@ -397,6 +418,7 @@ public function finish() $g3 = $g3->mask($mask); $g4 = $g4->mask($mask); + /** @var int $mask */ $mask = (~$mask) & 0xffffffff; $h0 = $h0->mask($mask)->orInt32($g0); diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Salsa20.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Salsa20.php index 08f84a4027a45..d8c8073ce7894 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Salsa20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Salsa20.php @@ -20,6 +20,8 @@ abstract class ParagonIE_Sodium_Core32_Salsa20 extends ParagonIE_Sodium_Core32_U * @param string $k * @param string|null $c * @return string + * @throws SodiumException + * @throws TypeError */ public static function core_salsa20($in, $k, $c = null) { @@ -185,6 +187,8 @@ public static function core_salsa20($in, $k, $c = null) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function salsa20($len, $nonce, $key) { @@ -214,7 +218,7 @@ public static function salsa20($len, $nonce, $key) } try { ParagonIE_Sodium_Compat::memzero($kcopy); - } catch (Error $ex) { + } catch (SodiumException $ex) { $kcopy = null; } return $c; @@ -228,6 +232,8 @@ public static function salsa20($len, $nonce, $key) * @param int $ic * @param string $k * @return string + * @throws SodiumException + * @throws TypeError */ public static function salsa20_xor_ic($m, $n, $ic, $k) { @@ -268,7 +274,7 @@ public static function salsa20_xor_ic($m, $n, $ic, $k) try { ParagonIE_Sodium_Compat::memzero($block); ParagonIE_Sodium_Compat::memzero($kcopy); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block = null; $kcopy = null; } @@ -283,6 +289,8 @@ public static function salsa20_xor_ic($m, $n, $ic, $k) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function salsa20_xor($message, $nonce, $key) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/SipHash.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/SipHash.php index bcf0401840387..6d43602a45bd0 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/SipHash.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/SipHash.php @@ -70,6 +70,8 @@ public static function sipRound(array $v) * @param string $in * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function sipHash24($in, $key) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/Util.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/Util.php index 343688d6457f9..f32e5adc61aae 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/Util.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/Util.php @@ -7,6 +7,7 @@ /** * Class ParagonIE_Sodium_Core_Util */ -abstract class ParagonIE_Sodium_Core32_Util extends ParagonIE_Sodium_Core_Util { +abstract class ParagonIE_Sodium_Core32_Util extends ParagonIE_Sodium_Core_Util +{ } diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/X25519.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/X25519.php index 1ff6bfc82ff66..4e594b1e31cb3 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/X25519.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/X25519.php @@ -18,6 +18,9 @@ abstract class ParagonIE_Sodium_Core32_X25519 extends ParagonIE_Sodium_Core32_Cu * @param ParagonIE_Sodium_Core32_Curve25519_Fe $g * @param int $b * @return void + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedMethodCall */ public static function fe_cswap( ParagonIE_Sodium_Core32_Curve25519_Fe $f, @@ -45,15 +48,25 @@ public static function fe_cswap( $g8 = (int) $g[8]->toInt(); $g9 = (int) $g[9]->toInt(); $b = -$b; + /** @var int $x0 */ $x0 = ($f0 ^ $g0) & $b; + /** @var int $x1 */ $x1 = ($f1 ^ $g1) & $b; + /** @var int $x2 */ $x2 = ($f2 ^ $g2) & $b; + /** @var int $x3 */ $x3 = ($f3 ^ $g3) & $b; + /** @var int $x4 */ $x4 = ($f4 ^ $g4) & $b; + /** @var int $x5 */ $x5 = ($f5 ^ $g5) & $b; + /** @var int $x6 */ $x6 = ($f6 ^ $g6) & $b; + /** @var int $x7 */ $x7 = ($f7 ^ $g7) & $b; + /** @var int $x8 */ $x8 = ($f8 ^ $g8) & $b; + /** @var int $x9 */ $x9 = ($f9 ^ $g9) & $b; $f[0] = ParagonIE_Sodium_Core32_Int32::fromInt($f0 ^ $x0); $f[1] = ParagonIE_Sodium_Core32_Int32::fromInt($f1 ^ $x1); @@ -82,100 +95,73 @@ public static function fe_cswap( * * @param ParagonIE_Sodium_Core32_Curve25519_Fe $f * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError + * @psalm-suppress MixedAssignment + * @psalm-suppress MixedMethodCall */ public static function fe_mul121666(ParagonIE_Sodium_Core32_Curve25519_Fe $f) { - /** @var ParagonIE_Sodium_Core32_Int32[] $h */ - $h = array( - $f[0]->mulInt(121666), - $f[1]->mulInt(121666), - $f[2]->mulInt(121666), - $f[3]->mulInt(121666), - $f[4]->mulInt(121666), - $f[5]->mulInt(121666), - $f[6]->mulInt(121666), - $f[7]->mulInt(121666), - $f[8]->mulInt(121666), - $f[9]->mulInt(121666), - ); + /** @var array $h */ + $h = array(); + for ($i = 0; $i < 10; ++$i) { + $h[$i] = $f[$i]->toInt64()->mulInt(121666, 17); + } /** @var ParagonIE_Sodium_Core32_Int32 $carry9 */ $carry9 = $h[9]->addInt(1 << 24)->shiftRight(25); - $h[0] = $carry9->mulInt(19); - $h[9] = $h[9]->subInt32($carry9->shiftLeft(25)); + $h[0] = $h[0]->addInt64($carry9->mulInt(19, 5)); + $h[9] = $h[9]->subInt64($carry9->shiftLeft(25)); + /** @var ParagonIE_Sodium_Core32_Int32 $carry1 */ $carry1 = $h[1]->addInt(1 << 24)->shiftRight(25); - $h[2] = $h[2]->addInt32($carry1); - $h[1] = $h[1]->subInt32($carry1->shiftLeft(25)); + $h[2] = $h[2]->addInt64($carry1); + $h[1] = $h[1]->subInt64($carry1->shiftLeft(25)); + /** @var ParagonIE_Sodium_Core32_Int32 $carry3 */ $carry3 = $h[3]->addInt(1 << 24)->shiftRight(25); - $h[4] = $h[4]->addInt32($carry3); - $h[3] = $h[3]->subInt32($carry3->shiftLeft(25)); - - $carry5 = $h[3]->addInt(1 << 24)->shiftRight(25); - $h[6] = $h[6]->addInt32($carry5); - $h[5] = $h[5]->subInt32($carry5->shiftLeft(25)); - - $carry7 = $h[3]->addInt(1 << 24)->shiftRight(25); - $h[8] = $h[8]->addInt32($carry7); - $h[7] = $h[7]->subInt32($carry7->shiftLeft(25)); - - /* - $carry9 = ($h[9] + (1 << 24)) >> 25; - $h[0] += self::mul($carry9, 19); - $h[9] -= $carry9 << 25; - $carry1 = ($h[1] + (1 << 24)) >> 25; - $h[2] += $carry1; - $h[1] -= $carry1 << 25; - $carry3 = ($h[3] + (1 << 24)) >> 25; - $h[4] += $carry3; - $h[3] -= $carry3 << 25; - $carry5 = ($h[5] + (1 << 24)) >> 25; - $h[6] += $carry5; - $h[5] -= $carry5 << 25; - $carry7 = ($h[7] + (1 << 24)) >> 25; - $h[8] += $carry7; - $h[7] -= $carry7 << 25; - */ + $h[4] = $h[4]->addInt64($carry3); + $h[3] = $h[3]->subInt64($carry3->shiftLeft(25)); + + /** @var ParagonIE_Sodium_Core32_Int32 $carry5 */ + $carry5 = $h[5]->addInt(1 << 24)->shiftRight(25); + $h[6] = $h[6]->addInt64($carry5); + $h[5] = $h[5]->subInt64($carry5->shiftLeft(25)); + /** @var ParagonIE_Sodium_Core32_Int32 $carry7 */ + $carry7 = $h[7]->addInt(1 << 24)->shiftRight(25); + $h[8] = $h[8]->addInt64($carry7); + $h[7] = $h[7]->subInt64($carry7->shiftLeft(25)); + + /** @var ParagonIE_Sodium_Core32_Int32 $carry0 */ $carry0 = $h[0]->addInt(1 << 25)->shiftRight(26); - $h[1] = $h[1]->addInt32($carry0); - $h[0] = $h[0]->subInt32($carry0->shiftLeft(26)); + $h[1] = $h[1]->addInt64($carry0); + $h[0] = $h[0]->subInt64($carry0->shiftLeft(26)); + /** @var ParagonIE_Sodium_Core32_Int32 $carry2 */ $carry2 = $h[2]->addInt(1 << 25)->shiftRight(26); - $h[3] = $h[3]->addInt32($carry2); - $h[2] = $h[2]->subInt32($carry2->shiftLeft(26)); + $h[3] = $h[3]->addInt64($carry2); + $h[2] = $h[2]->subInt64($carry2->shiftLeft(26)); + /** @var ParagonIE_Sodium_Core32_Int32 $carry4 */ $carry4 = $h[4]->addInt(1 << 25)->shiftRight(26); - $h[5] = $h[5]->addInt32($carry4); - $h[4] = $h[4]->subInt32($carry4->shiftLeft(26)); + $h[5] = $h[5]->addInt64($carry4); + $h[4] = $h[4]->subInt64($carry4->shiftLeft(26)); + /** @var ParagonIE_Sodium_Core32_Int32 $carry6 */ $carry6 = $h[6]->addInt(1 << 25)->shiftRight(26); - $h[7] = $h[7]->addInt32($carry6); - $h[6] = $h[6]->subInt32($carry6->shiftLeft(26)); + $h[7] = $h[7]->addInt64($carry6); + $h[6] = $h[6]->subInt64($carry6->shiftLeft(26)); + /** @var ParagonIE_Sodium_Core32_Int32 $carry8 */ $carry8 = $h[8]->addInt(1 << 25)->shiftRight(26); - $h[9] = $h[9]->addInt32($carry8); - $h[8] = $h[8]->subInt32($carry8->shiftLeft(26)); - - /* - $carry0 = ($h[0] + (1 << 25)) >> 26; - $h[1] += $carry0; - $h[0] -= $carry0 << 26; - $carry2 = ($h[2] + (1 << 25)) >> 26; - $h[3] += $carry2; - $h[2] -= $carry2 << 26; - $carry4 = ($h[4] + (1 << 25)) >> 26; - $h[5] += $carry4; - $h[4] -= $carry4 << 26; - $carry6 = ($h[6] + (1 << 25)) >> 26; - $h[7] += $carry6; - $h[6] -= $carry6 << 26; - $carry8 = ($h[8] + (1 << 25)) >> 26; - $h[9] += $carry8; - $h[8] -= $carry8 << 26; - */ + $h[9] = $h[9]->addInt64($carry8); + $h[8] = $h[8]->subInt64($carry8->shiftLeft(26)); + for ($i = 0; $i < 10; ++$i) { + $h[$i] = $h[$i]->toInt32(); + } + /** @var array $h */ return ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray($h); } @@ -187,6 +173,8 @@ public static function fe_mul121666(ParagonIE_Sodium_Core32_Curve25519_Fe $f) * @param string $n * @param string $p * @return string + * @throws SodiumException + * @throws TypeError */ public static function crypto_scalarmult_curve25519_ref10($n, $p) { @@ -213,11 +201,13 @@ public static function crypto_scalarmult_curve25519_ref10($n, $p) $z3 = self::fe_1(); # swap = 0; + /** @var int $swap */ $swap = 0; # for (pos = 254;pos >= 0;--pos) { for ($pos = 254; $pos >= 0; --$pos) { # b = e[pos / 8] >> (pos & 7); + /** @var int $b */ $b = self::chrToInt( $e[(int) floor($pos / 8)] ) >> ($pos & 7); @@ -230,6 +220,7 @@ public static function crypto_scalarmult_curve25519_ref10($n, $p) # fe_cswap(z2,z3,swap); self::fe_cswap($z2, $z3, $swap); # swap = b; + /** @var int $swap */ $swap = $b; # fe_sub(tmp0,x3,z3); $tmp0 = self::fe_sub($x3, $z3); @@ -297,7 +288,7 @@ public static function crypto_scalarmult_curve25519_ref10($n, $p) # fe_mul(x2,x2,z2); $x2 = self::fe_mul($x2, $z2); # fe_tobytes(q,x2); - return self::fe_tobytes($x2); + return (string) self::fe_tobytes($x2); } /** @@ -306,6 +297,8 @@ public static function crypto_scalarmult_curve25519_ref10($n, $p) * @param ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsY * @param ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsZ * @return ParagonIE_Sodium_Core32_Curve25519_Fe + * @throws SodiumException + * @throws TypeError */ public static function edwards_to_montgomery( ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsY, @@ -322,6 +315,7 @@ public static function edwards_to_montgomery( * * @param string $n * @return string + * @throws SodiumException * @throws TypeError */ public static function crypto_scalarmult_curve25519_ref10_base($n) diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/XChaCha20.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/XChaCha20.php index 9004ec4f0edec..1dfc8591d7faf 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/XChaCha20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/XChaCha20.php @@ -16,12 +16,13 @@ class ParagonIE_Sodium_Core32_XChaCha20 extends ParagonIE_Sodium_Core32_HChaCha2 * @param string $nonce * @param string $key * @return string - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function stream($len = 64, $nonce = '', $key = '') { if (self::strlen($nonce) !== 24) { - throw new Exception('Nonce must be 24 bytes long'); + throw new SodiumException('Nonce must be 24 bytes long'); } return self::encryptBytes( new ParagonIE_Sodium_Core32_ChaCha20_Ctx( @@ -43,12 +44,13 @@ public static function stream($len = 64, $nonce = '', $key = '') * @param string $key * @param string $ic * @return string - * @throws Exception + * @throws SodiumException + * @throws TypeError */ public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') { if (self::strlen($nonce) !== 24) { - throw new Exception('Nonce must be 24 bytes long'); + throw new SodiumException('Nonce must be 24 bytes long'); } return self::encryptBytes( new ParagonIE_Sodium_Core32_ChaCha20_Ctx( diff --git a/libraries/vendor/paragonie/sodium_compat/src/Core32/XSalsa20.php b/libraries/vendor/paragonie/sodium_compat/src/Core32/XSalsa20.php index 9100ce6f807eb..a16b93bc1573b 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Core32/XSalsa20.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Core32/XSalsa20.php @@ -18,6 +18,8 @@ abstract class ParagonIE_Sodium_Core32_XSalsa20 extends ParagonIE_Sodium_Core32_ * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function xsalsa20($len, $nonce, $key) { @@ -38,6 +40,8 @@ public static function xsalsa20($len, $nonce, $key) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function xsalsa20_xor($message, $nonce, $key) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Crypto.php b/libraries/vendor/paragonie/sodium_compat/src/Crypto.php index 39ce5171de7d4..15b24c682c004 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Crypto.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Crypto.php @@ -65,7 +65,8 @@ abstract class ParagonIE_Sodium_Crypto * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_decrypt( $message = '', @@ -103,7 +104,7 @@ public static function aead_chacha20poly1305_decrypt( $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } $state->update($ad); @@ -114,7 +115,7 @@ public static function aead_chacha20poly1305_decrypt( /* Compare the given MAC with the recalculated MAC: */ if (!ParagonIE_Sodium_Core_Util::verify_16($computed_mac, $mac)) { - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } // Here, we know that the MAC is valid, so we decrypt and return the plaintext @@ -136,6 +137,8 @@ public static function aead_chacha20poly1305_decrypt( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_encrypt( $message = '', @@ -158,7 +161,7 @@ public static function aead_chacha20poly1305_encrypt( $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } @@ -187,7 +190,8 @@ public static function aead_chacha20poly1305_encrypt( * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_ietf_decrypt( $message = '', @@ -229,7 +233,7 @@ public static function aead_chacha20poly1305_ietf_decrypt( $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } $state->update($ad); @@ -242,7 +246,7 @@ public static function aead_chacha20poly1305_ietf_decrypt( /* Compare the given MAC with the recalculated MAC: */ if (!ParagonIE_Sodium_Core_Util::verify_16($computed_mac, $mac)) { - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } // Here, we know that the MAC is valid, so we decrypt and return the plaintext @@ -264,6 +268,8 @@ public static function aead_chacha20poly1305_ietf_decrypt( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_ietf_encrypt( $message = '', @@ -286,7 +292,7 @@ public static function aead_chacha20poly1305_ietf_encrypt( $state = new ParagonIE_Sodium_Core_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } @@ -317,7 +323,8 @@ public static function aead_chacha20poly1305_ietf_encrypt( * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function aead_xchacha20poly1305_ietf_decrypt( $message = '', @@ -345,6 +352,8 @@ public static function aead_xchacha20poly1305_ietf_decrypt( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function aead_xchacha20poly1305_ietf_encrypt( $message = '', @@ -370,6 +379,7 @@ public static function aead_xchacha20poly1305_ietf_encrypt( * @param string $message * @param string $key * @return string + * @throws TypeError */ public static function auth($message, $key) { @@ -389,6 +399,8 @@ public static function auth($message, $key) * @param string $message * @param string $key * @return bool + * @throws SodiumException + * @throws TypeError */ public static function auth_verify($mac, $message, $key) { @@ -407,6 +419,8 @@ public static function auth_verify($mac, $message, $key) * @param string $nonce * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ public static function box($plaintext, $nonce, $keypair) { @@ -429,6 +443,8 @@ public static function box($plaintext, $nonce, $keypair) * @param string $message * @param string $publicKey * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_seal($message, $publicKey) { @@ -457,7 +473,7 @@ public static function box_seal($message, $publicKey) ParagonIE_Sodium_Compat::memzero($ephemeralKeypair); ParagonIE_Sodium_Compat::memzero($ephemeralSK); ParagonIE_Sodium_Compat::memzero($nonce); - } catch (Error $ex) { + } catch (SodiumException $ex) { $ephemeralKeypair = null; $ephemeralSK = null; $nonce = null; @@ -473,6 +489,8 @@ public static function box_seal($message, $publicKey) * @param string $message * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_seal_open($message, $keypair) { @@ -504,7 +522,7 @@ public static function box_seal_open($message, $keypair) ParagonIE_Sodium_Compat::memzero($secretKey); ParagonIE_Sodium_Compat::memzero($ephemeralPK); ParagonIE_Sodium_Compat::memzero($nonce); - } catch (Error $ex) { + } catch (SodiumException $ex) { $secretKey = null; $ephemeralPK = null; $nonce = null; @@ -520,6 +538,8 @@ public static function box_seal_open($message, $keypair) * @param string $sk * @param string $pk * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_beforenm($sk, $pk) { @@ -533,6 +553,8 @@ public static function box_beforenm($sk, $pk) * @internal Do not use this directly. Use ParagonIE_Sodium_Compat. * * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_keypair() { @@ -544,6 +566,8 @@ public static function box_keypair() /** * @param string $seed * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_seed_keypair($seed) { @@ -562,6 +586,7 @@ public static function box_seed_keypair($seed) * @param string $sKey * @param string $pKey * @return string + * @throws TypeError */ public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) { @@ -575,6 +600,7 @@ public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) * @param string $keypair * @return string * @throws RangeException + * @throws TypeError */ public static function box_secretkey($keypair) { @@ -590,6 +616,7 @@ public static function box_secretkey($keypair) * @param string $keypair * @return string * @throws RangeException + * @throws TypeError */ public static function box_publickey($keypair) { @@ -605,6 +632,8 @@ public static function box_publickey($keypair) * @param string $sKey * @return string * @throws RangeException + * @throws SodiumException + * @throws TypeError */ public static function box_publickey_from_secretkey($sKey) { @@ -621,9 +650,10 @@ public static function box_publickey_from_secretkey($sKey) * * @param string $ciphertext * @param string $nonce - * @param string $nonce * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_open($ciphertext, $nonce, $keypair) { @@ -647,6 +677,8 @@ public static function box_open($ciphertext, $nonce, $keypair) * @param int $outlen * @return string * @throws RangeException + * @throws SodiumException + * @throws TypeError */ public static function generichash($message, $key = '', $outlen = 32) { @@ -686,6 +718,7 @@ public static function generichash($message, $key = '', $outlen = 32) * @param string $ctx * @param int $outlen * @return string + * @throws SodiumException * @throws TypeError */ public static function generichash_final($ctx, $outlen = 32) @@ -715,6 +748,8 @@ public static function generichash_final($ctx, $outlen = 32) * @param int $outputLength * @return string * @throws RangeException + * @throws SodiumException + * @throws TypeError */ public static function generichash_init($key = '', $outputLength = 32) { @@ -743,6 +778,8 @@ public static function generichash_init($key = '', $outputLength = 32) * @param string $ctx * @param string $message * @return string + * @throws SodiumException + * @throws TypeError */ public static function generichash_update($ctx, $message) { @@ -770,6 +807,8 @@ public static function generichash_update($ctx, $message) * @param string $client_pk * @param string $server_pk * @return string + * @throws SodiumException + * @throws TypeError */ public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) { @@ -789,7 +828,8 @@ public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) * @param string $pKey * @return string * - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function scalarmult($sKey, $pKey) { @@ -805,7 +845,8 @@ public static function scalarmult($sKey, $pKey) * @param string $secret * @return string * - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function scalarmult_base($secret) { @@ -819,7 +860,8 @@ public static function scalarmult_base($secret) * * @param string $q * @return void - * @throws Error + * @throws SodiumException + * @throws TypeError */ protected static function scalarmult_throw_if_zero($q) { @@ -830,7 +872,7 @@ protected static function scalarmult_throw_if_zero($q) /* branch-free variant of === 0 */ if (-(1 & (($d - 1) >> 8))) { - throw new Error('Zero public key is not allowed'); + throw new SodiumException('Zero public key is not allowed'); } } @@ -843,6 +885,8 @@ protected static function scalarmult_throw_if_zero($q) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function secretbox($plaintext, $nonce, $key) { @@ -893,7 +937,7 @@ public static function secretbox($plaintext, $nonce, $key) try { ParagonIE_Sodium_Compat::memzero($block0); ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; $subkey = null; } @@ -916,7 +960,8 @@ public static function secretbox($plaintext, $nonce, $key) * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function secretbox_open($ciphertext, $nonce, $key) { @@ -953,10 +998,10 @@ public static function secretbox_open($ciphertext, $nonce, $key) if (!$verified) { try { ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $subkey = null; } - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } /** @var string $m - Decrypted message */ @@ -973,7 +1018,7 @@ public static function secretbox_open($ciphertext, $nonce, $key) ), ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), 1, - $subkey + (string) $subkey ); } return $m; @@ -988,6 +1033,8 @@ public static function secretbox_open($ciphertext, $nonce, $key) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) { @@ -1042,7 +1089,7 @@ public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) try { ParagonIE_Sodium_Compat::memzero($block0); ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; $subkey = null; } @@ -1065,7 +1112,8 @@ public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) { @@ -1103,10 +1151,10 @@ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $ke if (!$verified) { try { ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $subkey = null; } - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } /** @var string $m - Decrypted message */ @@ -1123,7 +1171,7 @@ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $ke self::secretbox_xchacha20poly1305_ZEROBYTES ), ParagonIE_Sodium_Core_Util::substr($nonce, 16, 8), - $subkey, + (string) $subkey, ParagonIE_Sodium_Core_Util::store64_le(1) ); } @@ -1138,6 +1186,8 @@ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $ke * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign_detached($message, $sk) { @@ -1152,6 +1202,8 @@ public static function sign_detached($message, $sk) * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign($message, $sk) { @@ -1166,6 +1218,8 @@ public static function sign($message, $sk) * @param string $signedMessage * @param string $pk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign_open($signedMessage, $pk) { @@ -1181,6 +1235,8 @@ public static function sign_open($signedMessage, $pk) * @param string $message * @param string $pk * @return bool + * @throws SodiumException + * @throws TypeError */ public static function sign_verify_detached($signature, $message, $pk) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/Crypto32.php b/libraries/vendor/paragonie/sodium_compat/src/Crypto32.php index a31aaf38605bc..cd4e266114ae2 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/Crypto32.php +++ b/libraries/vendor/paragonie/sodium_compat/src/Crypto32.php @@ -65,7 +65,8 @@ abstract class ParagonIE_Sodium_Crypto32 * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_decrypt( $message = '', @@ -103,7 +104,7 @@ public static function aead_chacha20poly1305_decrypt( $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } $state->update($ad); @@ -114,7 +115,7 @@ public static function aead_chacha20poly1305_decrypt( /* Compare the given MAC with the recalculated MAC: */ if (!ParagonIE_Sodium_Core32_Util::verify_16($computed_mac, $mac)) { - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } // Here, we know that the MAC is valid, so we decrypt and return the plaintext @@ -136,6 +137,8 @@ public static function aead_chacha20poly1305_decrypt( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_encrypt( $message = '', @@ -158,7 +161,7 @@ public static function aead_chacha20poly1305_encrypt( $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } @@ -187,7 +190,8 @@ public static function aead_chacha20poly1305_encrypt( * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_ietf_decrypt( $message = '', @@ -229,7 +233,7 @@ public static function aead_chacha20poly1305_ietf_decrypt( $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } $state->update($ad); @@ -242,7 +246,7 @@ public static function aead_chacha20poly1305_ietf_decrypt( /* Compare the given MAC with the recalculated MAC: */ if (!ParagonIE_Sodium_Core32_Util::verify_16($computed_mac, $mac)) { - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } // Here, we know that the MAC is valid, so we decrypt and return the plaintext @@ -264,6 +268,8 @@ public static function aead_chacha20poly1305_ietf_decrypt( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function aead_chacha20poly1305_ietf_encrypt( $message = '', @@ -286,7 +292,7 @@ public static function aead_chacha20poly1305_ietf_encrypt( $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; } @@ -317,7 +323,8 @@ public static function aead_chacha20poly1305_ietf_encrypt( * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function aead_xchacha20poly1305_ietf_decrypt( $message = '', @@ -345,6 +352,8 @@ public static function aead_xchacha20poly1305_ietf_decrypt( * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function aead_xchacha20poly1305_ietf_encrypt( $message = '', @@ -370,6 +379,7 @@ public static function aead_xchacha20poly1305_ietf_encrypt( * @param string $message * @param string $key * @return string + * @throws TypeError */ public static function auth($message, $key) { @@ -389,6 +399,8 @@ public static function auth($message, $key) * @param string $message * @param string $key * @return bool + * @throws SodiumException + * @throws TypeError */ public static function auth_verify($mac, $message, $key) { @@ -407,10 +419,12 @@ public static function auth_verify($mac, $message, $key) * @param string $nonce * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ public static function box($plaintext, $nonce, $keypair) { - $c = self::secretbox( + return self::secretbox( $plaintext, $nonce, self::box_beforenm( @@ -418,7 +432,6 @@ public static function box($plaintext, $nonce, $keypair) self::box_publickey($keypair) ) ); - return $c; } /** @@ -429,6 +442,8 @@ public static function box($plaintext, $nonce, $keypair) * @param string $message * @param string $publicKey * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_seal($message, $publicKey) { @@ -457,7 +472,7 @@ public static function box_seal($message, $publicKey) ParagonIE_Sodium_Compat::memzero($ephemeralKeypair); ParagonIE_Sodium_Compat::memzero($ephemeralSK); ParagonIE_Sodium_Compat::memzero($nonce); - } catch (Error $ex) { + } catch (SodiumException $ex) { $ephemeralKeypair = null; $ephemeralSK = null; $nonce = null; @@ -473,6 +488,8 @@ public static function box_seal($message, $publicKey) * @param string $message * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_seal_open($message, $keypair) { @@ -504,7 +521,7 @@ public static function box_seal_open($message, $keypair) ParagonIE_Sodium_Compat::memzero($secretKey); ParagonIE_Sodium_Compat::memzero($ephemeralPK); ParagonIE_Sodium_Compat::memzero($nonce); - } catch (Error $ex) { + } catch (SodiumException $ex) { $secretKey = null; $ephemeralPK = null; $nonce = null; @@ -520,6 +537,8 @@ public static function box_seal_open($message, $keypair) * @param string $sk * @param string $pk * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_beforenm($sk, $pk) { @@ -533,6 +552,8 @@ public static function box_beforenm($sk, $pk) * @internal Do not use this directly. Use ParagonIE_Sodium_Compat. * * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_keypair() { @@ -541,12 +562,30 @@ public static function box_keypair() return $sKey . $pKey; } + /** + * @param string $seed + * @return string + * @throws SodiumException + * @throws TypeError + */ + public static function box_seed_keypair($seed) + { + $sKey = ParagonIE_Sodium_Core32_Util::substr( + hash('sha512', $seed, true), + 0, + 32 + ); + $pKey = self::scalarmult_base($sKey); + return $sKey . $pKey; + } + /** * @internal Do not use this directly. Use ParagonIE_Sodium_Compat. * * @param string $sKey * @param string $pKey * @return string + * @throws TypeError */ public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) { @@ -560,6 +599,7 @@ public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) * @param string $keypair * @return string * @throws RangeException + * @throws TypeError */ public static function box_secretkey($keypair) { @@ -575,6 +615,7 @@ public static function box_secretkey($keypair) * @param string $keypair * @return string * @throws RangeException + * @throws TypeError */ public static function box_publickey($keypair) { @@ -590,6 +631,8 @@ public static function box_publickey($keypair) * @param string $sKey * @return string * @throws RangeException + * @throws SodiumException + * @throws TypeError */ public static function box_publickey_from_secretkey($sKey) { @@ -606,9 +649,10 @@ public static function box_publickey_from_secretkey($sKey) * * @param string $ciphertext * @param string $nonce - * @param string $nonce * @param string $keypair * @return string + * @throws SodiumException + * @throws TypeError */ public static function box_open($ciphertext, $nonce, $keypair) { @@ -632,6 +676,8 @@ public static function box_open($ciphertext, $nonce, $keypair) * @param int $outlen * @return string * @throws RangeException + * @throws SodiumException + * @throws TypeError */ public static function generichash($message, $key = '', $outlen = 32) { @@ -671,6 +717,7 @@ public static function generichash($message, $key = '', $outlen = 32) * @param string $ctx * @param int $outlen * @return string + * @throws SodiumException * @throws TypeError */ public static function generichash_final($ctx, $outlen = 32) @@ -700,6 +747,8 @@ public static function generichash_final($ctx, $outlen = 32) * @param int $outputLength * @return string * @throws RangeException + * @throws SodiumException + * @throws TypeError */ public static function generichash_init($key = '', $outputLength = 32) { @@ -728,6 +777,8 @@ public static function generichash_init($key = '', $outputLength = 32) * @param string $ctx * @param string $message * @return string + * @throws SodiumException + * @throws TypeError */ public static function generichash_update($ctx, $message) { @@ -755,6 +806,8 @@ public static function generichash_update($ctx, $message) * @param string $client_pk * @param string $server_pk * @return string + * @throws SodiumException + * @throws TypeError */ public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) { @@ -774,7 +827,8 @@ public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) * @param string $pKey * @return string * - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function scalarmult($sKey, $pKey) { @@ -790,7 +844,8 @@ public static function scalarmult($sKey, $pKey) * @param string $secret * @return string * - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function scalarmult_base($secret) { @@ -804,7 +859,8 @@ public static function scalarmult_base($secret) * * @param string $q * @return void - * @throws Error + * @throws SodiumException + * @throws TypeError */ protected static function scalarmult_throw_if_zero($q) { @@ -815,7 +871,7 @@ protected static function scalarmult_throw_if_zero($q) /* branch-free variant of === 0 */ if (-(1 & (($d - 1) >> 8))) { - throw new Error('Zero public key is not allowed'); + throw new SodiumException('Zero public key is not allowed'); } } @@ -828,6 +884,8 @@ protected static function scalarmult_throw_if_zero($q) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function secretbox($plaintext, $nonce, $key) { @@ -878,7 +936,7 @@ public static function secretbox($plaintext, $nonce, $key) try { ParagonIE_Sodium_Compat::memzero($block0); ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; $subkey = null; } @@ -901,7 +959,8 @@ public static function secretbox($plaintext, $nonce, $key) * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function secretbox_open($ciphertext, $nonce, $key) { @@ -938,10 +997,10 @@ public static function secretbox_open($ciphertext, $nonce, $key) if (!$verified) { try { ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $subkey = null; } - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } /** @var string $m - Decrypted message */ @@ -958,7 +1017,7 @@ public static function secretbox_open($ciphertext, $nonce, $key) ), ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8), 1, - $subkey + (string) $subkey ); } return $m; @@ -973,6 +1032,8 @@ public static function secretbox_open($ciphertext, $nonce, $key) * @param string $nonce * @param string $key * @return string + * @throws SodiumException + * @throws TypeError */ public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) { @@ -1027,7 +1088,7 @@ public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) try { ParagonIE_Sodium_Compat::memzero($block0); ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; $subkey = null; } @@ -1050,7 +1111,8 @@ public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) * @param string $nonce * @param string $key * @return string - * @throws Error + * @throws SodiumException + * @throws TypeError */ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) { @@ -1088,10 +1150,10 @@ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $ke if (!$verified) { try { ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $subkey = null; } - throw new Error('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } /** @var string $m - Decrypted message */ @@ -1108,7 +1170,7 @@ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $ke self::secretbox_xchacha20poly1305_ZEROBYTES ), ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8), - $subkey, + (string) $subkey, ParagonIE_Sodium_Core32_Util::store64_le(1) ); } @@ -1123,6 +1185,8 @@ public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $ke * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign_detached($message, $sk) { @@ -1137,6 +1201,8 @@ public static function sign_detached($message, $sk) * @param string $message * @param string $sk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign($message, $sk) { @@ -1151,6 +1217,8 @@ public static function sign($message, $sk) * @param string $signedMessage * @param string $pk * @return string + * @throws SodiumException + * @throws TypeError */ public static function sign_open($signedMessage, $pk) { @@ -1166,6 +1234,8 @@ public static function sign_open($signedMessage, $pk) * @param string $message * @param string $pk * @return bool + * @throws SodiumException + * @throws TypeError */ public static function sign_verify_detached($signature, $message, $pk) { diff --git a/libraries/vendor/paragonie/sodium_compat/src/File.php b/libraries/vendor/paragonie/sodium_compat/src/File.php index 3bfcd883454b2..0f066533983fd 100644 --- a/libraries/vendor/paragonie/sodium_compat/src/File.php +++ b/libraries/vendor/paragonie/sodium_compat/src/File.php @@ -22,7 +22,7 @@ class ParagonIE_Sodium_File extends ParagonIE_Sodium_Core_Util * @param string $keyPair ECDH secret key and ECDH public key concatenated * * @return bool - * @throws Error + * @throws SodiumException * @throws TypeError */ public static function box($inputFile, $outputFile, $nonce, $keyPair) @@ -52,20 +52,20 @@ public static function box($inputFile, $outputFile, $nonce, $keyPair) /** @var int $size */ $size = filesize($inputFile); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $ifp */ $ifp = fopen($inputFile, 'rb'); if (!is_resource($ifp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var resource $ofp */ $ofp = fopen($outputFile, 'wb'); if (!is_resource($ofp)) { fclose($ifp); - throw new Error('Could not open output file for writing'); + throw new SodiumException('Could not open output file for writing'); } $res = self::box_encrypt($ifp, $ofp, $size, $nonce, $keyPair); @@ -88,7 +88,7 @@ public static function box($inputFile, $outputFile, $nonce, $keyPair) * @param string $nonce * @param string $keypair * @return bool - * @throws Error + * @throws SodiumException * @throws TypeError */ public static function box_open($inputFile, $outputFile, $nonce, $keypair) @@ -118,20 +118,20 @@ public static function box_open($inputFile, $outputFile, $nonce, $keypair) /** @var int $size */ $size = filesize($inputFile); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $ifp */ $ifp = fopen($inputFile, 'rb'); if (!is_resource($ifp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var resource $ofp */ $ofp = fopen($outputFile, 'wb'); if (!is_resource($ofp)) { fclose($ifp); - throw new Error('Could not open output file for writing'); + throw new SodiumException('Could not open output file for writing'); } $res = self::box_decrypt($ifp, $ofp, $size, $nonce, $keypair); @@ -140,7 +140,7 @@ public static function box_open($inputFile, $outputFile, $nonce, $keypair) try { ParagonIE_Sodium_Compat::memzero($nonce); ParagonIE_Sodium_Compat::memzero($ephKeypair); - } catch (Error $ex) { + } catch (SodiumException $ex) { unset($ephKeypair); } return $res; @@ -156,7 +156,7 @@ public static function box_open($inputFile, $outputFile, $nonce, $keypair) * @param string $publicKey ECDH public key * * @return bool - * @throws Error + * @throws SodiumException * @throws TypeError */ public static function box_seal($inputFile, $outputFile, $publicKey) @@ -180,20 +180,20 @@ public static function box_seal($inputFile, $outputFile, $publicKey) /** @var int $size */ $size = filesize($inputFile); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $ifp */ $ifp = fopen($inputFile, 'rb'); if (!is_resource($ifp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var resource $ofp */ $ofp = fopen($outputFile, 'wb'); if (!is_resource($ofp)) { fclose($ifp); - throw new Error('Could not open output file for writing'); + throw new SodiumException('Could not open output file for writing'); } /** @var string $ephKeypair */ @@ -225,13 +225,13 @@ public static function box_seal($inputFile, $outputFile, $publicKey) fclose($ifp); fclose($ofp); ParagonIE_Sodium_Compat::memzero($ephKeypair); - throw new Error('Could not write to output file'); + throw new SodiumException('Could not write to output file'); } if ($firstWrite !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES) { ParagonIE_Sodium_Compat::memzero($ephKeypair); fclose($ifp); fclose($ofp); - throw new Error('Error writing public key to output file'); + throw new SodiumException('Error writing public key to output file'); } $res = self::box_encrypt($ifp, $ofp, $size, $nonce, $msgKeypair); @@ -240,7 +240,7 @@ public static function box_seal($inputFile, $outputFile, $publicKey) try { ParagonIE_Sodium_Compat::memzero($nonce); ParagonIE_Sodium_Compat::memzero($ephKeypair); - } catch (Error $ex) { + } catch (SodiumException $ex) { unset($ephKeypair); } return $res; @@ -259,7 +259,7 @@ public static function box_seal($inputFile, $outputFile, $publicKey) * @param string $outputFile * @param string $ecdhKeypair * @return bool - * @throws Error + * @throws SodiumException * @throws TypeError */ public static function box_seal_open($inputFile, $outputFile, $ecdhKeypair) @@ -285,30 +285,30 @@ public static function box_seal_open($inputFile, $outputFile, $ecdhKeypair) /** @var int $size */ $size = filesize($inputFile); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $ifp */ $ifp = fopen($inputFile, 'rb'); if (!is_resource($ifp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var resource $ofp */ $ofp = fopen($outputFile, 'wb'); if (!is_resource($ofp)) { fclose($ifp); - throw new Error('Could not open output file for writing'); + throw new SodiumException('Could not open output file for writing'); } $ephemeralPK = fread($ifp, ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES); if (!is_string($ephemeralPK)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } if (self::strlen($ephemeralPK) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES) { fclose($ifp); fclose($ofp); - throw new Error('Could not read public key from sealed file'); + throw new SodiumException('Could not read public key from sealed file'); } $nonce = ParagonIE_Sodium_Compat::crypto_generichash( @@ -327,7 +327,7 @@ public static function box_seal_open($inputFile, $outputFile, $ecdhKeypair) try { ParagonIE_Sodium_Compat::memzero($nonce); ParagonIE_Sodium_Compat::memzero($ephKeypair); - } catch (Error $ex) { + } catch (SodiumException $ex) { unset($ephKeypair); } return $res; @@ -341,7 +341,7 @@ public static function box_seal_open($inputFile, $outputFile, $ecdhKeypair) * @param int $outputLength Length of hash output * * @return string BLAKE2b hash - * @throws Error + * @throws SodiumException * @throws TypeError * @psalm-suppress FailedTypeResolution */ @@ -375,22 +375,22 @@ public static function generichash($filePath, $key = '', $outputLength = 32) } } if ($outputLength < ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MIN) { - throw new Error('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MIN'); + throw new SodiumException('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MIN'); } if ($outputLength > ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MAX) { - throw new Error('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MAX'); + throw new SodiumException('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MAX'); } /** @var int $size */ $size = filesize($filePath); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $fp */ $fp = fopen($filePath, 'rb'); if (!is_resource($fp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } $ctx = ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outputLength); while ($size > 0) { @@ -399,7 +399,7 @@ public static function generichash($filePath, $key = '', $outputLength = 32) : $size; $read = fread($fp, $blockSize); if (!is_string($read)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $read); $size -= $blockSize; @@ -420,7 +420,7 @@ public static function generichash($filePath, $key = '', $outputLength = 32) * @param string $key Encryption key * * @return bool - * @throws Error + * @throws SodiumException * @throws TypeError */ public static function secretbox($inputFile, $outputFile, $nonce, $key) @@ -450,20 +450,20 @@ public static function secretbox($inputFile, $outputFile, $nonce, $key) /** @var int $size */ $size = filesize($inputFile); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $ifp */ $ifp = fopen($inputFile, 'rb'); if (!is_resource($ifp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var resource $ofp */ $ofp = fopen($outputFile, 'wb'); if (!is_resource($ofp)) { fclose($ifp); - throw new Error('Could not open output file for writing'); + throw new SodiumException('Could not open output file for writing'); } $res = self::secretbox_encrypt($ifp, $ofp, $size, $nonce, $key); @@ -485,7 +485,7 @@ public static function secretbox($inputFile, $outputFile, $nonce, $key) * @param string $nonce * @param string $key * @return bool - * @throws Error + * @throws SodiumException * @throws TypeError */ public static function secretbox_open($inputFile, $outputFile, $nonce, $key) @@ -515,20 +515,20 @@ public static function secretbox_open($inputFile, $outputFile, $nonce, $key) /** @var int $size */ $size = filesize($inputFile); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $ifp */ $ifp = fopen($inputFile, 'rb'); if (!is_resource($ifp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var resource $ofp */ $ofp = fopen($outputFile, 'wb'); if (!is_resource($ofp)) { fclose($ifp); - throw new Error('Could not open output file for writing'); + throw new SodiumException('Could not open output file for writing'); } $res = self::secretbox_decrypt($ifp, $ofp, $size, $nonce, $key); @@ -536,7 +536,7 @@ public static function secretbox_open($inputFile, $outputFile, $nonce, $key) fclose($ofp); try { ParagonIE_Sodium_Compat::memzero($key); - } catch (Error $ex) { + } catch (SodiumException $ex) { unset($key); } return $res; @@ -551,7 +551,7 @@ public static function secretbox_open($inputFile, $outputFile, $nonce, $key) * @param string $secretKey Secret signing key * * @return string Ed25519 signature - * @throws Error + * @throws SodiumException * @throws TypeError */ public static function sign($filePath, $secretKey) @@ -568,17 +568,20 @@ public static function sign($filePath, $secretKey) if (self::strlen($secretKey) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_SECRETKEYBYTES) { throw new TypeError('Argument 2 must be CRYPTO_SIGN_SECRETKEYBYTES bytes'); } + if (PHP_INT_SIZE === 4) { + return self::sign_core32($filePath, $secretKey); + } /** @var int $size */ $size = filesize($filePath); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $fp */ $fp = fopen($filePath, 'rb'); if (!is_resource($fp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var string $az */ @@ -590,6 +593,7 @@ public static function sign($filePath, $secretKey) /** @var resource $hs */ $hs = hash_init('sha512'); hash_update($hs, self::substr($az, 32, 32)); + /** @var resource $hs */ $hs = self::updateHashWithFile($hs, $fp, $size); /** @var string $nonceHash */ @@ -610,6 +614,7 @@ public static function sign($filePath, $secretKey) $hs = hash_init('sha512'); hash_update($hs, self::substr($sig, 0, 32)); hash_update($hs, self::substr($pk, 0, 32)); + /** @var resource $hs */ $hs = self::updateHashWithFile($hs, $fp, $size); /** @var string $hramHash */ @@ -626,7 +631,7 @@ public static function sign($filePath, $secretKey) try { ParagonIE_Sodium_Compat::memzero($az); - } catch (Error $ex) { + } catch (SodiumException $ex) { $az = null; } fclose($fp); @@ -643,7 +648,8 @@ public static function sign($filePath, $secretKey) * @param string $publicKey Signing public key * * @return bool - * @throws Error + * @throws SodiumException + * @throws TypeError * @throws Exception */ public static function verify($sig, $filePath, $publicKey) @@ -667,37 +673,41 @@ public static function verify($sig, $filePath, $publicKey) throw new TypeError('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES bytes'); } if (self::strlen($sig) < 64) { - throw new Exception('Signature is too short'); + throw new SodiumException('Signature is too short'); + } + + if (PHP_INT_SIZE === 4) { + return self::verify_core32($sig, $filePath, $publicKey); } /* Security checks */ if (ParagonIE_Sodium_Core_Ed25519::check_S_lt_L(self::substr($sig, 32, 32))) { - throw new Exception('S < L - Invalid signature'); + throw new SodiumException('S < L - Invalid signature'); } if (ParagonIE_Sodium_Core_Ed25519::small_order($sig)) { - throw new Exception('Signature is on too small of an order'); + throw new SodiumException('Signature is on too small of an order'); } if ((self::chrToInt($sig[63]) & 224) !== 0) { - throw new Exception('Invalid signature'); + throw new SodiumException('Invalid signature'); } $d = 0; for ($i = 0; $i < 32; ++$i) { $d |= self::chrToInt($publicKey[$i]); } if ($d === 0) { - throw new Exception('All zero public key'); + throw new SodiumException('All zero public key'); } /** @var int $size */ $size = filesize($filePath); if (!is_int($size)) { - throw new Error('Could not obtain the file size'); + throw new SodiumException('Could not obtain the file size'); } /** @var resource $fp */ $fp = fopen($filePath, 'rb'); if (!is_resource($fp)) { - throw new Error('Could not open input file for reading'); + throw new SodiumException('Could not open input file for reading'); } /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */ @@ -713,6 +723,7 @@ public static function verify($sig, $filePath, $publicKey) $hs = hash_init('sha512'); hash_update($hs, self::substr($sig, 0, 32)); hash_update($hs, self::substr($publicKey, 0, 32)); + /** @var resource $hs */ $hs = self::updateHashWithFile($hs, $fp, $size); /** @var string $hDigest */ $hDigest = hash_final($hs, true); @@ -745,6 +756,8 @@ public static function verify($sig, $filePath, $publicKey) * @param string $nonce * @param string $boxKeypair * @return bool + * @throws SodiumException + * @throws TypeError */ protected static function box_encrypt($ifp, $ofp, $mlen, $nonce, $boxKeypair) { @@ -768,6 +781,8 @@ protected static function box_encrypt($ifp, $ofp, $mlen, $nonce, $boxKeypair) * @param string $nonce * @param string $boxKeypair * @return bool + * @throws SodiumException + * @throws TypeError */ protected static function box_decrypt($ifp, $ofp, $mlen, $nonce, $boxKeypair) { @@ -792,13 +807,18 @@ protected static function box_decrypt($ifp, $ofp, $mlen, $nonce, $boxKeypair) * @param string $nonce * @param string $key * @return bool - * @throws Error + * @throws SodiumException + * @throws TypeError */ protected static function secretbox_encrypt($ifp, $ofp, $mlen, $nonce, $key) { + if (PHP_INT_SIZE === 4) { + return self::secretbox_encrypt_core32($ifp, $ofp, $mlen, $nonce, $key); + } + $plaintext = fread($ifp, 32); if (!is_string($plaintext)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } $first32 = ftell($ifp); @@ -864,7 +884,7 @@ protected static function secretbox_encrypt($ifp, $ofp, $mlen, $nonce, $key) : $mlen; $plaintext = fread($ifp, $blockSize); if (!is_string($plaintext)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } $cBlock = ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic( $plaintext, @@ -881,7 +901,7 @@ protected static function secretbox_encrypt($ifp, $ofp, $mlen, $nonce, $key) try { ParagonIE_Sodium_Compat::memzero($block0); ParagonIE_Sodium_Compat::memzero($subkey); - } catch (Error $ex) { + } catch (SodiumException $ex) { $block0 = null; $subkey = null; } @@ -908,14 +928,17 @@ protected static function secretbox_encrypt($ifp, $ofp, $mlen, $nonce, $key) * @param string $nonce * @param string $key * @return bool - * @throws Error - * @throws Exception + * @throws SodiumException + * @throws TypeError */ protected static function secretbox_decrypt($ifp, $ofp, $mlen, $nonce, $key) { + if (PHP_INT_SIZE === 4) { + return self::secretbox_decrypt_core32($ifp, $ofp, $mlen, $nonce, $key); + } $tag = fread($ifp, 16); if (!is_string($tag)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } /** @var string $subkey */ @@ -934,7 +957,7 @@ protected static function secretbox_decrypt($ifp, $ofp, $mlen, $nonce, $key) /* Verify the Poly1305 MAC -before- attempting to decrypt! */ $state = new ParagonIE_Sodium_Core_Poly1305_State(self::substr($block0, 0, 32)); if (!self::onetimeauth_verify($state, $ifp, $tag, $mlen)) { - throw new Exception('Invalid MAC'); + throw new SodiumException('Invalid MAC'); } /* @@ -943,7 +966,7 @@ protected static function secretbox_decrypt($ifp, $ofp, $mlen, $nonce, $key) */ $first32 = fread($ifp, 32); if (!is_string($first32)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } $first32len = self::strlen($first32); fwrite( @@ -968,7 +991,7 @@ protected static function secretbox_decrypt($ifp, $ofp, $mlen, $nonce, $key) : $mlen; $ciphertext = fread($ifp, $blockSize); if (!is_string($ciphertext)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } $pBlock = ParagonIE_Sodium_Core_Salsa20::salsa20_xor_ic( $ciphertext, @@ -989,7 +1012,8 @@ protected static function secretbox_decrypt($ifp, $ofp, $mlen, $nonce, $key) * @param string $tag * @param int $mlen * @return bool - * @throws Error + * @throws SodiumException + * @throws TypeError */ protected static function onetimeauth_verify(ParagonIE_Sodium_Core_Poly1305_State $state, $ifp, $tag = '', $mlen = 0) { @@ -1008,7 +1032,7 @@ protected static function onetimeauth_verify(ParagonIE_Sodium_Core_Poly1305_Stat : $mlen; $ciphertext = fread($ifp, $blockSize); if (!is_string($ciphertext)) { - throw new Error('Could not read input file'); + throw new SodiumException('Could not read input file'); } $state->update($ciphertext); $mlen -= $blockSize; @@ -1028,7 +1052,7 @@ protected static function onetimeauth_verify(ParagonIE_Sodium_Core_Poly1305_Stat * @param resource $fp * @param int $size * @return mixed (resource on PHP < 7.2, object on PHP >= 7.2) - * @throws Error + * @throws SodiumException * @throws TypeError * @psalm-suppress PossiblyInvalidArgument * PHP 7.2 changes from a resource to an object, @@ -1060,7 +1084,7 @@ public static function updateHashWithFile($hash, $fp, $size = 0) // Move file pointer to beginning of file fseek($fp, 0, SEEK_SET); for ($i = 0; $i < $size; $i += self::BUFFER_SIZE) { - /** @var string $message */ + /** @var string|bool $message */ $message = fread( $fp, ($size - $i) > self::BUFFER_SIZE @@ -1068,8 +1092,9 @@ public static function updateHashWithFile($hash, $fp, $size = 0) : self::BUFFER_SIZE ); if (!is_string($message)) { - throw new Error('Unexpected error reading from file.'); + throw new SodiumException('Unexpected error reading from file.'); } + /** @var string $message */ /** @psalm-suppress InvalidArgument */ hash_update($hash, $message); } @@ -1077,4 +1102,414 @@ public static function updateHashWithFile($hash, $fp, $size = 0) fseek($fp, $originalPosition, SEEK_SET); return $hash; } + + /** + * Sign a file (rather than a string). Uses less memory than + * ParagonIE_Sodium_Compat::crypto_sign_detached(), but produces + * the same result. (32-bit) + * + * @param string $filePath Absolute path to a file on the filesystem + * @param string $secretKey Secret signing key + * + * @return string Ed25519 signature + * @throws SodiumException + * @throws TypeError + */ + private static function sign_core32($filePath, $secretKey) + { + /** @var int|bool $size */ + $size = filesize($filePath); + if (!is_int($size)) { + throw new SodiumException('Could not obtain the file size'); + } + /** @var int $size */ + + /** @var resource|bool $fp */ + $fp = fopen($filePath, 'rb'); + if (!is_resource($fp)) { + throw new SodiumException('Could not open input file for reading'); + } + /** @var resource $fp */ + + /** @var string $az */ + $az = hash('sha512', self::substr($secretKey, 0, 32), true); + + $az[0] = self::intToChr(self::chrToInt($az[0]) & 248); + $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64); + + /** @var resource $hs */ + $hs = hash_init('sha512'); + hash_update($hs, self::substr($az, 32, 32)); + /** @var resource $hs */ + $hs = self::updateHashWithFile($hs, $fp, $size); + + /** @var string $nonceHash */ + $nonceHash = hash_final($hs, true); + + /** @var string $pk */ + $pk = self::substr($secretKey, 32, 32); + + /** @var string $nonce */ + $nonce = ParagonIE_Sodium_Core32_Ed25519::sc_reduce($nonceHash) . self::substr($nonceHash, 32); + + /** @var string $sig */ + $sig = ParagonIE_Sodium_Core32_Ed25519::ge_p3_tobytes( + ParagonIE_Sodium_Core32_Ed25519::ge_scalarmult_base($nonce) + ); + + /** @var resource $hs */ + $hs = hash_init('sha512'); + hash_update($hs, self::substr($sig, 0, 32)); + hash_update($hs, self::substr($pk, 0, 32)); + /** @var resource $hs */ + $hs = self::updateHashWithFile($hs, $fp, $size); + + /** @var string $hramHash */ + $hramHash = hash_final($hs, true); + + /** @var string $hram */ + $hram = ParagonIE_Sodium_Core32_Ed25519::sc_reduce($hramHash); + + /** @var string $sigAfter */ + $sigAfter = ParagonIE_Sodium_Core32_Ed25519::sc_muladd($hram, $az, $nonce); + + /** @var string $sig */ + $sig = self::substr($sig, 0, 32) . self::substr($sigAfter, 0, 32); + + try { + ParagonIE_Sodium_Compat::memzero($az); + } catch (SodiumException $ex) { + $az = null; + } + fclose($fp); + return $sig; + } + + /** + * + * Verify a file (rather than a string). Uses less memory than + * ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but + * produces the same result. (32-bit) + * + * @param string $sig Ed25519 signature + * @param string $filePath Absolute path to a file on the filesystem + * @param string $publicKey Signing public key + * + * @return bool + * @throws SodiumException + * @throws Exception + */ + public static function verify_core32($sig, $filePath, $publicKey) + { + /* Security checks */ + if (ParagonIE_Sodium_Core32_Ed25519::check_S_lt_L(self::substr($sig, 32, 32))) { + throw new SodiumException('S < L - Invalid signature'); + } + if (ParagonIE_Sodium_Core32_Ed25519::small_order($sig)) { + throw new SodiumException('Signature is on too small of an order'); + } + if ((self::chrToInt($sig[63]) & 224) !== 0) { + throw new SodiumException('Invalid signature'); + } + $d = 0; + for ($i = 0; $i < 32; ++$i) { + $d |= self::chrToInt($publicKey[$i]); + } + if ($d === 0) { + throw new SodiumException('All zero public key'); + } + + /** @var int|bool $size */ + $size = filesize($filePath); + if (!is_int($size)) { + throw new SodiumException('Could not obtain the file size'); + } + /** @var int $size */ + + /** @var resource|bool $fp */ + $fp = fopen($filePath, 'rb'); + if (!is_resource($fp)) { + throw new SodiumException('Could not open input file for reading'); + } + /** @var resource $fp */ + + /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */ + $orig = ParagonIE_Sodium_Compat::$fastMult; + + // Set ParagonIE_Sodium_Compat::$fastMult to true to speed up verification. + ParagonIE_Sodium_Compat::$fastMult = true; + + /** @var ParagonIE_Sodium_Core32_Curve25519_Ge_P3 $A */ + $A = ParagonIE_Sodium_Core32_Ed25519::ge_frombytes_negate_vartime($publicKey); + + /** @var resource $hs */ + $hs = hash_init('sha512'); + hash_update($hs, self::substr($sig, 0, 32)); + hash_update($hs, self::substr($publicKey, 0, 32)); + /** @var resource $hs */ + $hs = self::updateHashWithFile($hs, $fp, $size); + /** @var string $hDigest */ + $hDigest = hash_final($hs, true); + + /** @var string $h */ + $h = ParagonIE_Sodium_Core32_Ed25519::sc_reduce($hDigest) . self::substr($hDigest, 32); + + /** @var ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $R */ + $R = ParagonIE_Sodium_Core32_Ed25519::ge_double_scalarmult_vartime( + $h, + $A, + self::substr($sig, 32) + ); + + /** @var string $rcheck */ + $rcheck = ParagonIE_Sodium_Core32_Ed25519::ge_tobytes($R); + + // Close the file handle + fclose($fp); + + // Reset ParagonIE_Sodium_Compat::$fastMult to what it was before. + ParagonIE_Sodium_Compat::$fastMult = $orig; + return self::verify_32($rcheck, self::substr($sig, 0, 32)); + } + + /** + * Encrypt a file (32-bit) + * + * @param resource $ifp + * @param resource $ofp + * @param int $mlen + * @param string $nonce + * @param string $key + * @return bool + * @throws SodiumException + * @throws TypeError + */ + protected static function secretbox_encrypt_core32($ifp, $ofp, $mlen, $nonce, $key) + { + $plaintext = fread($ifp, 32); + if (!is_string($plaintext)) { + throw new SodiumException('Could not read input file'); + } + $first32 = ftell($ifp); + + /** @var string $subkey */ + $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20($nonce, $key); + + /** @var string $realNonce */ + $realNonce = ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8); + + /** @var string $block0 */ + $block0 = str_repeat("\x00", 32); + + /** @var int $mlen - Length of the plaintext message */ + $mlen0 = $mlen; + if ($mlen0 > 64 - ParagonIE_Sodium_Crypto::secretbox_xsalsa20poly1305_ZEROBYTES) { + $mlen0 = 64 - ParagonIE_Sodium_Crypto::secretbox_xsalsa20poly1305_ZEROBYTES; + } + $block0 .= ParagonIE_Sodium_Core32_Util::substr($plaintext, 0, $mlen0); + + /** @var string $block0 */ + $block0 = ParagonIE_Sodium_Core32_Salsa20::salsa20_xor( + $block0, + $realNonce, + $subkey + ); + + $state = new ParagonIE_Sodium_Core32_Poly1305_State( + ParagonIE_Sodium_Core32_Util::substr( + $block0, + 0, + ParagonIE_Sodium_Crypto::onetimeauth_poly1305_KEYBYTES + ) + ); + + // Pre-write 16 blank bytes for the Poly1305 tag + $start = ftell($ofp); + fwrite($ofp, str_repeat("\x00", 16)); + + /** @var string $c */ + $cBlock = ParagonIE_Sodium_Core32_Util::substr( + $block0, + ParagonIE_Sodium_Crypto::secretbox_xsalsa20poly1305_ZEROBYTES + ); + $state->update($cBlock); + fwrite($ofp, $cBlock); + $mlen -= 32; + + /** @var int $iter */ + $iter = 1; + + /** @var int $incr */ + $incr = self::BUFFER_SIZE >> 6; + + /* + * Set the cursor to the end of the first half-block. All future bytes will + * generated from salsa20_xor_ic, starting from 1 (second block). + */ + fseek($ifp, $first32, SEEK_SET); + + while ($mlen > 0) { + $blockSize = $mlen > self::BUFFER_SIZE + ? self::BUFFER_SIZE + : $mlen; + $plaintext = fread($ifp, $blockSize); + if (!is_string($plaintext)) { + throw new SodiumException('Could not read input file'); + } + $cBlock = ParagonIE_Sodium_Core32_Salsa20::salsa20_xor_ic( + $plaintext, + $realNonce, + $iter, + $subkey + ); + fwrite($ofp, $cBlock, $blockSize); + $state->update($cBlock); + + $mlen -= $blockSize; + $iter += $incr; + } + try { + ParagonIE_Sodium_Compat::memzero($block0); + ParagonIE_Sodium_Compat::memzero($subkey); + } catch (SodiumException $ex) { + $block0 = null; + $subkey = null; + } + $end = ftell($ofp); + + /* + * Write the Poly1305 authentication tag that provides integrity + * over the ciphertext (encrypt-then-MAC) + */ + fseek($ofp, $start, SEEK_SET); + fwrite($ofp, $state->finish(), ParagonIE_Sodium_Compat::CRYPTO_SECRETBOX_MACBYTES); + fseek($ofp, $end, SEEK_SET); + unset($state); + + return true; + } + + /** + * Decrypt a file (32-bit) + * + * @param resource $ifp + * @param resource $ofp + * @param int $mlen + * @param string $nonce + * @param string $key + * @return bool + * @throws SodiumException + * @throws TypeError + */ + protected static function secretbox_decrypt_core32($ifp, $ofp, $mlen, $nonce, $key) + { + $tag = fread($ifp, 16); + if (!is_string($tag)) { + throw new SodiumException('Could not read input file'); + } + + /** @var string $subkey */ + $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20($nonce, $key); + + /** @var string $realNonce */ + $realNonce = ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8); + + /** @var string $block0 */ + $block0 = ParagonIE_Sodium_Core32_Salsa20::salsa20( + 64, + ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8), + $subkey + ); + + /* Verify the Poly1305 MAC -before- attempting to decrypt! */ + $state = new ParagonIE_Sodium_Core32_Poly1305_State(self::substr($block0, 0, 32)); + if (!self::onetimeauth_verify_core32($state, $ifp, $tag, $mlen)) { + throw new SodiumException('Invalid MAC'); + } + + /* + * Set the cursor to the end of the first half-block. All future bytes will + * generated from salsa20_xor_ic, starting from 1 (second block). + */ + $first32 = fread($ifp, 32); + if (!is_string($first32)) { + throw new SodiumException('Could not read input file'); + } + $first32len = self::strlen($first32); + fwrite( + $ofp, + self::xorStrings( + self::substr($block0, 32, $first32len), + self::substr($first32, 0, $first32len) + ) + ); + $mlen -= 32; + + /** @var int $iter */ + $iter = 1; + + /** @var int $incr */ + $incr = self::BUFFER_SIZE >> 6; + + /* Decrypts ciphertext, writes to output file. */ + while ($mlen > 0) { + $blockSize = $mlen > self::BUFFER_SIZE + ? self::BUFFER_SIZE + : $mlen; + $ciphertext = fread($ifp, $blockSize); + if (!is_string($ciphertext)) { + throw new SodiumException('Could not read input file'); + } + $pBlock = ParagonIE_Sodium_Core32_Salsa20::salsa20_xor_ic( + $ciphertext, + $realNonce, + $iter, + $subkey + ); + fwrite($ofp, $pBlock, $blockSize); + $mlen -= $blockSize; + $iter += $incr; + } + return true; + } + + /** + * One-time message authentication for 32-bit systems + * + * @param ParagonIE_Sodium_Core32_Poly1305_State $state + * @param resource $ifp + * @param string $tag + * @param int $mlen + * @return bool + * @throws SodiumException + * @throws TypeError + */ + protected static function onetimeauth_verify_core32(ParagonIE_Sodium_Core32_Poly1305_State $state, $ifp, $tag = '', $mlen = 0) + { + /** @var int $pos */ + $pos = ftell($ifp); + + /** @var int $iter */ + $iter = 1; + + /** @var int $incr */ + $incr = self::BUFFER_SIZE >> 6; + + while ($mlen > 0) { + $blockSize = $mlen > self::BUFFER_SIZE + ? self::BUFFER_SIZE + : $mlen; + $ciphertext = fread($ifp, $blockSize); + if (!is_string($ciphertext)) { + throw new SodiumException('Could not read input file'); + } + $state->update($ciphertext); + $mlen -= $blockSize; + $iter += $incr; + } + $res = ParagonIE_Sodium_Core32_Util::verify_16($tag, $state->finish()); + + fseek($ifp, $pos, SEEK_SET); + return $res; + } } diff --git a/libraries/vendor/paragonie/sodium_compat/src/SodiumException.php b/libraries/vendor/paragonie/sodium_compat/src/SodiumException.php new file mode 100644 index 0000000000000..a3176d7dd595d --- /dev/null +++ b/libraries/vendor/paragonie/sodium_compat/src/SodiumException.php @@ -0,0 +1,11 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Polyfill\Ctype; + +/** + * Ctype implementation through regex. + * + * @internal + * + * @author Gert de Pagter + */ +final class Ctype +{ + /** + * Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise. + * + * @see https://php.net/ctype-alnum + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alnum($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is a letter, FALSE otherwise. + * + * @see https://php.net/ctype-alpha + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_alpha($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); + } + + /** + * Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise. + * + * @see https://php.net/ctype-cntrl + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_cntrl($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); + } + + /** + * Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. + * + * @see https://php.net/ctype-digit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_digit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); + } + + /** + * Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise. + * + * @see https://php.net/ctype-graph + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_graph($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); + } + + /** + * Returns TRUE if every character in text is a lowercase letter. + * + * @see https://php.net/ctype-lower + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_lower($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); + } + + /** + * Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all. + * + * @see https://php.net/ctype-print + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_print($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); + } + + /** + * Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise. + * + * @see https://php.net/ctype-punct + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_punct($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); + } + + /** + * Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters. + * + * @see https://php.net/ctype-space + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_space($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); + } + + /** + * Returns TRUE if every character in text is an uppercase letter. + * + * @see https://php.net/ctype-upper + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_upper($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); + } + + /** + * Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise. + * + * @see https://php.net/ctype-xdigit + * + * @param string|int $text + * + * @return bool + */ + public static function ctype_xdigit($text) + { + $text = self::convert_int_to_char_for_ctype($text); + + return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); + } + + /** + * Converts integers to their char versions according to normal ctype behaviour, if needed. + * + * If an integer between -128 and 255 inclusive is provided, + * it is interpreted as the ASCII value of a single character + * (negative values have 256 added in order to allow characters in the Extended ASCII range). + * Any other integer is interpreted as a string containing the decimal digits of the integer. + * + * @param string|int $int + * + * @return mixed + */ + private static function convert_int_to_char_for_ctype($int) + { + if (!\is_int($int)) { + return $int; + } + + if ($int < -128 || $int > 255) { + return (string) $int; + } + + if ($int < 0) { + $int += 256; + } + + return \chr($int); + } +} diff --git a/libraries/vendor/symfony/polyfill-ctype/LICENSE b/libraries/vendor/symfony/polyfill-ctype/LICENSE new file mode 100644 index 0000000000000..ad399a798d6d2 --- /dev/null +++ b/libraries/vendor/symfony/polyfill-ctype/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/libraries/vendor/symfony/polyfill-ctype/bootstrap.php b/libraries/vendor/symfony/polyfill-ctype/bootstrap.php new file mode 100644 index 0000000000000..14d1d0faa3715 --- /dev/null +++ b/libraries/vendor/symfony/polyfill-ctype/bootstrap.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Polyfill\Ctype as p; + +if (!function_exists('ctype_alnum')) { + function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } + function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } + function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } + function ctype_digit($text) { return p\Ctype::ctype_digit($text); } + function ctype_graph($text) { return p\Ctype::ctype_graph($text); } + function ctype_lower($text) { return p\Ctype::ctype_lower($text); } + function ctype_print($text) { return p\Ctype::ctype_print($text); } + function ctype_punct($text) { return p\Ctype::ctype_punct($text); } + function ctype_space($text) { return p\Ctype::ctype_space($text); } + function ctype_upper($text) { return p\Ctype::ctype_upper($text); } + function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } +} diff --git a/libraries/vendor/symfony/polyfill-php55/LICENSE b/libraries/vendor/symfony/polyfill-php55/LICENSE index 39fa189d2b5fc..24fa32c2e9b27 100644 --- a/libraries/vendor/symfony/polyfill-php55/LICENSE +++ b/libraries/vendor/symfony/polyfill-php55/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2016 Fabien Potencier +Copyright (c) 2015-2018 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/vendor/symfony/polyfill-php55/Php55.php b/libraries/vendor/symfony/polyfill-php55/Php55.php index 396baf26de871..bae55e9fb74e4 100644 --- a/libraries/vendor/symfony/polyfill-php55/Php55.php +++ b/libraries/vendor/symfony/polyfill-php55/Php55.php @@ -40,7 +40,7 @@ public static function json_last_error_msg() public static function hash_pbkdf2($algorithm, $password, $salt, $iterations, $length = 0, $rawOutput = false) { // Number of blocks needed to create the derived key - $blocks = ceil($length / strlen(hash($algorithm, null, true))); + $blocks = ceil($length / \strlen(hash($algorithm, null, true))); $digest = ''; for ($i = 1; $i <= $blocks; ++$i) { diff --git a/libraries/vendor/symfony/polyfill-php55/Php55ArrayColumn.php b/libraries/vendor/symfony/polyfill-php55/Php55ArrayColumn.php index a3033d83ed3af..9bdea01bb99c5 100644 --- a/libraries/vendor/symfony/polyfill-php55/Php55ArrayColumn.php +++ b/libraries/vendor/symfony/polyfill-php55/Php55ArrayColumn.php @@ -45,7 +45,7 @@ public static function array_column(array $input, $columnKey, $indexKey = null) if ($columnKey === null) { $valueSet = true; $value = $row; - } elseif (is_array($row) && array_key_exists($columnKey, $row)) { + } elseif (\is_array($row) && \array_key_exists($columnKey, $row)) { $valueSet = true; $value = $row[$columnKey]; } diff --git a/libraries/vendor/symfony/polyfill-php56/LICENSE b/libraries/vendor/symfony/polyfill-php56/LICENSE index 39fa189d2b5fc..24fa32c2e9b27 100644 --- a/libraries/vendor/symfony/polyfill-php56/LICENSE +++ b/libraries/vendor/symfony/polyfill-php56/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2016 Fabien Potencier +Copyright (c) 2015-2018 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/vendor/symfony/polyfill-php56/Php56.php b/libraries/vendor/symfony/polyfill-php56/Php56.php index a7dd9a28ea2b2..6ec354eb28db7 100644 --- a/libraries/vendor/symfony/polyfill-php56/Php56.php +++ b/libraries/vendor/symfony/polyfill-php56/Php56.php @@ -23,13 +23,13 @@ final class Php56 public static function hash_equals($knownString, $userInput) { - if (!is_string($knownString)) { + if (!\is_string($knownString)) { trigger_error('Expected known_string to be a string, '.gettype($knownString).' given', E_USER_WARNING); return false; } - if (!is_string($userInput)) { + if (!\is_string($userInput)) { trigger_error('Expected user_input to be a string, '.gettype($userInput).' given', E_USER_WARNING); return false; @@ -45,7 +45,7 @@ public static function hash_equals($knownString, $userInput) $result = 0; for ($i = 0; $i < $knownLen; ++$i) { - $result |= ord($knownString[$i]) ^ ord($userInput[$i]); + $result |= \ord($knownString[$i]) ^ \ord($userInput[$i]); } return 0 === $result; @@ -80,16 +80,16 @@ public static function ldap_escape($subject, $ignore = '', $flags = 0) $charMaps[0] = array(); for ($i = 0; $i < 256; ++$i) { - $charMaps[0][chr($i)] = sprintf('\\%02x', $i); + $charMaps[0][\chr($i)] = sprintf('\\%02x', $i); } - for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_FILTER]); $i < $l; ++$i) { + for ($i = 0, $l = \count($charMaps[self::LDAP_ESCAPE_FILTER]); $i < $l; ++$i) { $chr = $charMaps[self::LDAP_ESCAPE_FILTER][$i]; unset($charMaps[self::LDAP_ESCAPE_FILTER][$i]); $charMaps[self::LDAP_ESCAPE_FILTER][$chr] = $charMaps[0][$chr]; } - for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_DN]); $i < $l; ++$i) { + for ($i = 0, $l = \count($charMaps[self::LDAP_ESCAPE_DN]); $i < $l; ++$i) { $chr = $charMaps[self::LDAP_ESCAPE_DN][$i]; unset($charMaps[self::LDAP_ESCAPE_DN][$i]); $charMaps[self::LDAP_ESCAPE_DN][$chr] = $charMaps[0][$chr]; @@ -115,7 +115,7 @@ public static function ldap_escape($subject, $ignore = '', $flags = 0) // Remove any chars to ignore from the list $ignore = (string) $ignore; - for ($i = 0, $l = strlen($ignore); $i < $l; ++$i) { + for ($i = 0, $l = \strlen($ignore); $i < $l; ++$i) { unset($charMap[$ignore[$i]]); } @@ -128,7 +128,7 @@ public static function ldap_escape($subject, $ignore = '', $flags = 0) $result = '\\20'.substr($result, 1); } - if ($result[strlen($result) - 1] === ' ') { + if ($result[\strlen($result) - 1] === ' ') { $result = substr($result, 0, -1).'\\20'; } } diff --git a/libraries/vendor/symfony/polyfill-util/BinaryNoFuncOverload.php b/libraries/vendor/symfony/polyfill-util/BinaryNoFuncOverload.php index 5ef3c6c2c22c2..800ad75d05982 100644 --- a/libraries/vendor/symfony/polyfill-util/BinaryNoFuncOverload.php +++ b/libraries/vendor/symfony/polyfill-util/BinaryNoFuncOverload.php @@ -20,7 +20,7 @@ class BinaryNoFuncOverload { public static function strlen($s) { - return strlen($s); + return \strlen($s); } public static function strpos($haystack, $needle, $offset = 0) diff --git a/libraries/vendor/symfony/polyfill-util/LICENSE b/libraries/vendor/symfony/polyfill-util/LICENSE index 39fa189d2b5fc..24fa32c2e9b27 100644 --- a/libraries/vendor/symfony/polyfill-util/LICENSE +++ b/libraries/vendor/symfony/polyfill-util/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2016 Fabien Potencier +Copyright (c) 2015-2018 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/vendor/symfony/yaml/Inline.php b/libraries/vendor/symfony/yaml/Inline.php index a10c0e4194a8a..743be24955a0b 100644 --- a/libraries/vendor/symfony/yaml/Inline.php +++ b/libraries/vendor/symfony/yaml/Inline.php @@ -233,6 +233,9 @@ public static function parseScalar($scalar, $delimiters = null, $stringDelimiter if (null !== $delimiters) { $tmp = ltrim(substr($scalar, $i), ' '); + if ('' === $tmp) { + throw new ParseException(sprintf('Unexpected end of line, expected one of "%s".', implode($delimiters))); + } if (!in_array($tmp[0], $delimiters)) { throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i))); } @@ -375,6 +378,7 @@ private static function parseMapping($mapping, &$i = 0, $references = array()) $output = array(); $len = strlen($mapping); ++$i; + $allowOverwrite = false; // {foo: bar, bar:foo, ...} while ($i < $len) { @@ -394,6 +398,10 @@ private static function parseMapping($mapping, &$i = 0, $references = array()) // key $key = self::parseScalar($mapping, array(':', ' '), array('"', "'"), $i, false); + if ('<<' === $key) { + $allowOverwrite = true; + } + // value $done = false; @@ -405,7 +413,12 @@ private static function parseMapping($mapping, &$i = 0, $references = array()) // Spec: Keys MUST be unique; first one wins. // Parser cannot abort this mapping earlier, since lines // are processed sequentially. - if (!isset($output[$key])) { + // But overwriting is allowed when a merge node is used in current block. + if ('<<' === $key) { + foreach ($value as $parsedValue) { + $output += $parsedValue; + } + } elseif ($allowOverwrite || !isset($output[$key])) { $output[$key] = $value; } $done = true; @@ -416,7 +429,10 @@ private static function parseMapping($mapping, &$i = 0, $references = array()) // Spec: Keys MUST be unique; first one wins. // Parser cannot abort this mapping earlier, since lines // are processed sequentially. - if (!isset($output[$key])) { + // But overwriting is allowed when a merge node is used in current block. + if ('<<' === $key) { + $output += $value; + } elseif ($allowOverwrite || !isset($output[$key])) { $output[$key] = $value; } $done = true; @@ -429,7 +445,10 @@ private static function parseMapping($mapping, &$i = 0, $references = array()) // Spec: Keys MUST be unique; first one wins. // Parser cannot abort this mapping earlier, since lines // are processed sequentially. - if (!isset($output[$key])) { + // But overwriting is allowed when a merge node is used in current block. + if ('<<' === $key) { + $output += $value; + } elseif ($allowOverwrite || !isset($output[$key])) { $output[$key] = $value; } $done = true; diff --git a/libraries/vendor/symfony/yaml/LICENSE b/libraries/vendor/symfony/yaml/LICENSE index 17d16a13367dd..21d7fb9e2f29b 100644 --- a/libraries/vendor/symfony/yaml/LICENSE +++ b/libraries/vendor/symfony/yaml/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2017 Fabien Potencier +Copyright (c) 2004-2018 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/vendor/symfony/yaml/Yaml.php b/libraries/vendor/symfony/yaml/Yaml.php index 7a579432ac09b..595fbef07f889 100644 --- a/libraries/vendor/symfony/yaml/Yaml.php +++ b/libraries/vendor/symfony/yaml/Yaml.php @@ -33,7 +33,7 @@ class Yaml * you must validate the input before calling this method. Passing a file * as an input is a deprecated feature and will be removed in 3.0. * - * Note: the ability to pass file names to the Yaml::parse method is deprecated since version 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead. + * Note: the ability to pass file names to the Yaml::parse method is deprecated since Symfony 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead. * * @param string $input Path to a YAML file or a string containing YAML * @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise @@ -49,7 +49,7 @@ public static function parse($input, $exceptionOnInvalidType = false, $objectSup // if input is a file, process it $file = ''; if (false === strpos($input, "\n") && is_file($input)) { - @trigger_error('The ability to pass file names to the '.__METHOD__.' method is deprecated since version 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead.', E_USER_DEPRECATED); + @trigger_error('The ability to pass file names to the '.__METHOD__.' method is deprecated since Symfony 2.2 and will be removed in 3.0. Pass the YAML contents of the file instead.', E_USER_DEPRECATED); if (false === is_readable($input)) { throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input)); diff --git a/tests/unit/stubs/database/jos_users.csv b/tests/unit/stubs/database/jos_users.csv index 54f4deec035de..331c61840cdd2 100644 --- a/tests/unit/stubs/database/jos_users.csv +++ b/tests/unit/stubs/database/jos_users.csv @@ -1,6 +1,6 @@ 'id','name','username','email','password','block','sendEmail','registerDate','lastvisitDate','activation','params','lastResetTime','resetCount' -'42','Super User','admin','admin@example.com','7017fe127670faddb25f3a893a36229c:eCU2KtKahxQIMH5i3nwc05zVTBtZXbVV','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0',,'0000-00-00 00:00:00','0' -'43','Publisher','publisher','publisher@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0',,'0000-00-00 00:00:00','0' -'44','Manager','manager','manager@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0',,'0000-00-00 00:00:00','0' -'99','Test','test','test@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0',,'0000-00-00 00:00:00','0' -'100','Activate','activate','activate@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','1','1','2010-02-13 00:34:42','0000-00-00 00:00:00','30cc6de70fb18231196a28dd83363d57',,'0000-00-00 00:00:00','0' +'42','Super User','admin','admin@example.com','7017fe127670faddb25f3a893a36229c:eCU2KtKahxQIMH5i3nwc05zVTBtZXbVV','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0','{}','0000-00-00 00:00:00','0' +'43','Publisher','publisher','publisher@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0','{}','0000-00-00 00:00:00','0' +'44','Manager','manager','manager@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0','{}','0000-00-00 00:00:00','0' +'99','Test','test','test@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','0','1','2010-02-13 00:34:42','2010-02-13 00:34:42','0','{}','0000-00-00 00:00:00','0' +'100','Activate','activate','activate@example.com','b69eafa62e549e5fa875e127fadc3c83:VapLaQZx00iYDRwgMjgsfyIHgoe01DK8','1','1','2010-02-13 00:34:42','0000-00-00 00:00:00','30cc6de70fb18231196a28dd83363d57','{}','0000-00-00 00:00:00','0'