diff --git a/securemail/composer.json b/securemail/composer.json
new file mode 100644
index 00000000..14a2ca9a
--- /dev/null
+++ b/securemail/composer.json
@@ -0,0 +1,21 @@
+{
+ "name": "friendica-addons/securemail",
+ "description": "Send notification mail encrypted with user-defined public GPG key.",
+ "type": "friendica-addon",
+ "authors": [
+ {
+ "name": "Fabio Comuni",
+ "homepage": "https://kirgroup.com/profile/fabrixxm",
+ "role": "Developer"
+ }
+ ],
+ "require": {
+ "phpseclib/phpseclib": "^2.0",
+ "singpolyma/openpgp-php": "^0.3.0"
+ },
+ "license": "AGPL-3.0+",
+ "minimum-stability": "stable",
+ "config": {
+ "autoloader-suffix": "SecuremailAddon"
+ }
+}
diff --git a/securemail/composer.lock b/securemail/composer.lock
new file mode 100644
index 00000000..08de3972
--- /dev/null
+++ b/securemail/composer.lock
@@ -0,0 +1,153 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "b3a33a493eae34d9245ca7cc1b4572ea",
+ "packages": [
+ {
+ "name": "phpseclib/phpseclib",
+ "version": "2.0.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpseclib/phpseclib.git",
+ "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/ab8028c93c03cc8d9c824efa75dc94f1db2369bf",
+ "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phing/phing": "~2.7",
+ "phpunit/phpunit": "~4.0",
+ "sami/sami": "~2.0",
+ "squizlabs/php_codesniffer": "~2.0"
+ },
+ "suggest": {
+ "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
+ "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
+ "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
+ "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
+ },
+ "type": "library",
+ "autoload": {
+ "files": [
+ "phpseclib/bootstrap.php"
+ ],
+ "psr-4": {
+ "phpseclib\\": "phpseclib/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jim Wigginton",
+ "email": "terrafrost@php.net",
+ "role": "Lead Developer"
+ },
+ {
+ "name": "Patrick Monnerat",
+ "email": "pm@datasphere.ch",
+ "role": "Developer"
+ },
+ {
+ "name": "Andreas Fischer",
+ "email": "bantu@phpbb.com",
+ "role": "Developer"
+ },
+ {
+ "name": "Hans-Jürgen Petrich",
+ "email": "petrich@tronic-media.com",
+ "role": "Developer"
+ },
+ {
+ "name": "Graham Campbell",
+ "email": "graham@alt-three.com",
+ "role": "Developer"
+ }
+ ],
+ "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
+ "homepage": "http://phpseclib.sourceforge.net",
+ "keywords": [
+ "BigInteger",
+ "aes",
+ "asn.1",
+ "asn1",
+ "blowfish",
+ "crypto",
+ "cryptography",
+ "encryption",
+ "rsa",
+ "security",
+ "sftp",
+ "signature",
+ "signing",
+ "ssh",
+ "twofish",
+ "x.509",
+ "x509"
+ ],
+ "time": "2016-10-04T00:57:04+00:00"
+ },
+ {
+ "name": "singpolyma/openpgp-php",
+ "version": "0.3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/singpolyma/openpgp-php.git",
+ "reference": "6006111bbc4c3b6cb8f0acb7d6c4a7047df366e8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/singpolyma/openpgp-php/zipball/6006111bbc4c3b6cb8f0acb7d6c4a7047df366e8",
+ "reference": "6006111bbc4c3b6cb8f0acb7d6c4a7047df366e8",
+ "shasum": ""
+ },
+ "require": {
+ "phpseclib/phpseclib": ">=2.0.0 <=2.0.4"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "lib/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "Unlicense"
+ ],
+ "authors": [
+ {
+ "name": "Arto Bendiken",
+ "email": "arto.bendiken@gmail.com"
+ },
+ {
+ "name": "Stephen Paul Weber",
+ "email": "singpolyma@singpolyma.net"
+ }
+ ],
+ "description": "Pure-PHP implementation of the OpenPGP Message Format (RFC 4880)",
+ "time": "2017-04-12T21:23:15+00:00"
+ }
+ ],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": []
+}
diff --git a/securemail/securemail.php b/securemail/securemail.php
index a0ec211a..5662714b 100644
--- a/securemail/securemail.php
+++ b/securemail/securemail.php
@@ -15,199 +15,166 @@ use Friendica\Core\PConfig;
use Friendica\Core\Renderer;
use Friendica\Util\Emailer;
-/* because the fraking openpgp-php is in composer, require libs in composer
- * and then don't use autoloader to load classes... */
-$path = __DIR__ . '/vendor/phpseclib/phpseclib/phpseclib/';
-set_include_path(get_include_path() . PATH_SEPARATOR . $path);
-/* so, we don't use the autoloader and include what we need */
-$path = __DIR__ . '/vendor/singpolyma/openpgp-php/lib';
-set_include_path(get_include_path() . PATH_SEPARATOR . $path);
+require_once __DIR__ . '/vendor/autoload.php';
-require_once 'openpgp.php';
-require_once 'openpgp_crypt_symmetric.php';
+function securemail_install()
+{
+ Hook::register('addon_settings', 'addon/securemail/securemail.php', 'securemail_settings');
+ Hook::register('addon_settings_post', 'addon/securemail/securemail.php', 'securemail_settings_post');
+ Hook::register('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare');
-function securemail_install() {
- Hook::register('addon_settings', 'addon/securemail/securemail.php', 'securemail_settings');
- Hook::register('addon_settings_post', 'addon/securemail/securemail.php', 'securemail_settings_post');
-
- Hook::register('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare');
-
- Logger::log('installed securemail');
+ Logger::log('installed securemail');
}
-function securemail_uninstall() {
- Hook::unregister('addon_settings', 'addon/securemail/securemail.php', 'securemail_settings');
- Hook::unregister('addon_settings_post', 'addon/securemail/securemail.php', 'securemail_settings_post');
+function securemail_uninstall()
+{
+ Hook::unregister('addon_settings', 'addon/securemail/securemail.php', 'securemail_settings');
+ Hook::unregister('addon_settings_post', 'addon/securemail/securemail.php', 'securemail_settings_post');
- Hook::unregister('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare');
+ Hook::unregister('emailer_send_prepare', 'addon/securemail/securemail.php', 'securemail_emailer_send_prepare');
- Logger::log('removed securemail');
+ Logger::log('removed securemail');
}
/**
* @brief Build user settings form
*
- * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#addon_settings 'addon_settings' hook
+ * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#addon_settings 'addon_settings' hook
*
- * @param App $a App instance
+ * @param App $a App instance
* @param string $s output html
*
- * @see App
+ * @see App
*/
-function securemail_settings(App &$a, &$s){
- if (!local_user()) {
- return;
- }
+function securemail_settings(App &$a, &$s)
+{
+ if (!local_user()) {
+ return;
+ }
- $enable = intval(PConfig::get(local_user(), 'securemail', 'enable'));
- $publickey = PConfig::get(local_user(), 'securemail', 'pkey');
+ $enable = intval(PConfig::get(local_user(), 'securemail', 'enable'));
+ $publickey = PConfig::get(local_user(), 'securemail', 'pkey');
- $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/securemail/');
+ $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/securemail/');
- $s .= Renderer::replaceMacros($t, [
- '$title' => L10n::t('"Secure Mail" Settings'),
- '$submit' => L10n::t('Save Settings'),
- '$test' => L10n::t('Save and send test'), //NOTE: update also in 'post'
- '$enable' => ['securemail-enable', L10n::t('Enable Secure Mail'), $enable, ''],
- '$publickey' => ['securemail-pkey', L10n::t('Public key'), $publickey, L10n::t('Your public PGP key, ascii armored format'), 'rows="10"']
- ]);
+ $s .= Renderer::replaceMacros($t, [
+ '$title' => L10n::t('"Secure Mail" Settings'),
+ '$submit' => L10n::t('Save Settings'),
+ '$test' => L10n::t('Save and send test'), //NOTE: update also in 'post'
+ '$enable' => ['securemail-enable', L10n::t('Enable Secure Mail'), $enable, ''],
+ '$publickey' => ['securemail-pkey', L10n::t('Public key'), $publickey, L10n::t('Your public PGP key, ascii armored format'), 'rows="10"']
+ ]);
}
/**
* @brief Handle data from user settings form
*
- * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#addon_settings_post 'addon_settings_post' hook
+ * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#addon_settings_post 'addon_settings_post' hook
*
- * @param App $a App instance
+ * @param App $a App instance
* @param array $b hook data
*
- * @see App
+ * @see App
*/
-function securemail_settings_post(App &$a, array &$b){
+function securemail_settings_post(App &$a, array &$b)
+{
+ if (!local_user()) {
+ return;
+ }
- if (!local_user()) {
- return;
- }
+ if ($_POST['securemail-submit']) {
+ PConfig::set(local_user(), 'securemail', 'pkey', trim($_POST['securemail-pkey']));
+ $enable = (!empty($_POST['securemail-enable']) ? 1 : 0);
+ PConfig::set(local_user(), 'securemail', 'enable', $enable);
+ info(L10n::t('Secure Mail Settings saved.') . EOL);
- if ($_POST['securemail-submit']) {
- PConfig::set(local_user(), 'securemail', 'pkey', trim($_POST['securemail-pkey']));
- $enable = (!empty($_POST['securemail-enable']) ? 1 : 0);
- PConfig::set(local_user(), 'securemail', 'enable', $enable);
- info(L10n::t('Secure Mail Settings saved.') . EOL);
+ if ($_POST['securemail-submit'] == L10n::t('Save and send test')) {
+ $sitename = Config::get('config', 'sitename');
- if ($_POST['securemail-submit'] == L10n::t('Save and send test')) {
- $sitename = Config::get('config', 'sitename');
+ $hostname = $a->getHostName();
+ if (strpos($hostname, ':')) {
+ $hostname = substr($hostname, 0, strpos($hostname, ':'));
+ }
- $hostname = $a->getHostName();
- if (strpos($hostname, ':')) {
- $hostname = substr($hostname, 0, strpos($hostname, ':'));
- }
+ $sender_email = Config::get('config', 'sender_email');
+ if (empty($sender_email)) {
+ $sender_email = 'noreply@' . $hostname;
+ }
- $sender_email = Config::get('config', 'sender_email');
- if (empty($sender_email)) {
- $sender_email = 'noreply@' . $hostname;
- }
+ $subject = 'Friendica - Secure Mail - Test';
+ $message = 'This is a test message from your Friendica Secure Mail addon.';
- $subject = 'Friendica - Secure Mail - Test';
- $message = 'This is a test message from your Friendica Secure Mail addon.';
+ $params = [
+ 'uid' => local_user(),
+ 'fromName' => $sitename,
+ 'fromEmail' => $sender_email,
+ 'toEmail' => $a->user['email'],
+ 'messageSubject' => $subject,
+ 'htmlVersion' => "
{$message}
",
+ 'textVersion' => $message,
+ ];
- $params = [
- 'uid' => local_user(),
- 'fromName' => $sitename,
- 'fromEmail' => $sender_email,
- 'toEmail' => $a->user['email'],
- 'messageSubject' => $subject,
- 'htmlVersion' => "{$message}
",
- 'textVersion' => $message,
- ];
+ // enable addon for test
+ PConfig::set(local_user(), 'securemail', 'enable', 1);
- // enable addon for test
- PConfig::set(local_user(), 'securemail', 'enable', 1);
+ $res = Emailer::send($params);
- $res = Emailer::send($params);
+ // revert to saved value
+ PConfig::set(local_user(), 'securemail', 'enable', $enable);
- // revert to saved value
- PConfig::set(local_user(), 'securemail', 'enable', $enable);
-
- if ($res) {
- info(L10n::t('Test email sent') . EOL);
- } else {
- notice(L10n::t('There was an error sending the test email') . EOL);
- }
- }
- }
+ if ($res) {
+ info(L10n::t('Test email sent') . EOL);
+ } else {
+ notice(L10n::t('There was an error sending the test email') . EOL);
+ }
+ }
+ }
}
/**
* @brief Encrypt notification emails text
*
- * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#emailer_send_prepare 'emailer_send_prepare' hook
+ * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#emailer_send_prepare 'emailer_send_prepare' hook
*
- * @param App $a App instance
+ * @param App $a App instance
* @param array $b hook data
*
- * @see App
+ * @see App
*/
-function securemail_emailer_send_prepare(App &$a, array &$b) {
- if (empty($b['uid'])) {
- return;
- }
+function securemail_emailer_send_prepare(App &$a, array &$b)
+{
+ if (empty($b['uid'])) {
+ return;
+ }
- $uid = $b['uid'];
+ $uid = $b['uid'];
- $enable_checked = PConfig::get($uid, 'securemail', 'enable');
- if (!$enable_checked) {
- return;
- }
+ $enable_checked = PConfig::get($uid, 'securemail', 'enable');
+ if (!$enable_checked) {
+ return;
+ }
- $public_key_ascii = PConfig::get($uid, 'securemail', 'pkey');
+ $public_key_ascii = PConfig::get($uid, 'securemail', 'pkey');
- preg_match('/-----BEGIN ([A-Za-z ]+)-----/', $public_key_ascii, $matches);
- $marker = empty($matches[1]) ? 'MESSAGE' : $matches[1];
- $public_key = OpenPGP::unarmor($public_key_ascii, $marker);
+ preg_match('/-----BEGIN ([A-Za-z ]+)-----/', $public_key_ascii, $matches);
+ $marker = empty($matches[1]) ? 'MESSAGE' : $matches[1];
+ $public_key = OpenPGP::unarmor($public_key_ascii, $marker);
- $key = OpenPGP_Message::parse($public_key);
+ $key = OpenPGP_Message::parse($public_key);
- $data = new OpenPGP_LiteralDataPacket($b['textVersion'], [
- 'format' => 'u',
- 'filename' => 'encrypted.gpg'
- ]);
- $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data]));
- $armored_encrypted = wordwrap(
- OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'),
- 64,
- "\n",
- true
- );
+ $data = new OpenPGP_LiteralDataPacket($b['textVersion'], [
+ 'format' => 'u',
+ 'filename' => 'encrypted.gpg'
+ ]);
+ $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data]));
+ $armored_encrypted = wordwrap(
+ OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'),
+ 64,
+ "\n",
+ true
+ );
- $b['textVersion'] = $armored_encrypted;
- $b['htmlVersion'] = null;
+ $b['textVersion'] = $armored_encrypted;
+ $b['htmlVersion'] = null;
}
-
-
-/**
- * add addon composer autoloader maps to system autoloader
-
-function securemail_autoloader() {
-
- $loader = require dirname(dirname(__DIR__)) . '/vendor/autoload.php';
-
- $map = require __DIR__ . '/vendor/composer/autoload_namespaces.php';
- foreach ($map as $namespace => $path) {
- $loader->set($namespace, $path);
- }
-
- $map = require __DIR__ . '/vendor/composer/autoload_psr4.php';
- foreach ($map as $namespace => $path) {
- $loader->setPsr4($namespace, $path);
- }
-
- $classMap = require __DIR__ . '/vendor/composer/autoload_classmap.php';
- if ($classMap) {
- $loader->addClassMap($classMap);
- }
-}
-securemail_autoloader();
-
-*/
diff --git a/securemail/vendor/autoload.php b/securemail/vendor/autoload.php
new file mode 100644
index 00000000..eebfd6c5
--- /dev/null
+++ b/securemail/vendor/autoload.php
@@ -0,0 +1,7 @@
+
+ * Jordi Boggiano
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Autoload;
+
+/**
+ * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
+ *
+ * $loader = new \Composer\Autoload\ClassLoader();
+ *
+ * // register classes with namespaces
+ * $loader->add('Symfony\Component', __DIR__.'/component');
+ * $loader->add('Symfony', __DIR__.'/framework');
+ *
+ * // activate the autoloader
+ * $loader->register();
+ *
+ * // to enable searching the include path (eg. for PEAR packages)
+ * $loader->setUseIncludePath(true);
+ *
+ * In this example, if you try to use a class in the Symfony\Component
+ * namespace or one of its children (Symfony\Component\Console for instance),
+ * the autoloader will first look for the class under the component/
+ * directory, and it will then fallback to the framework/ directory if not
+ * found before giving up.
+ *
+ * This class is loosely based on the Symfony UniversalClassLoader.
+ *
+ * @author Fabien Potencier
+ * @author Jordi Boggiano
+ * @see http://www.php-fig.org/psr/psr-0/
+ * @see http://www.php-fig.org/psr/psr-4/
+ */
+class ClassLoader
+{
+ // PSR-4
+ private $prefixLengthsPsr4 = array();
+ private $prefixDirsPsr4 = array();
+ private $fallbackDirsPsr4 = array();
+
+ // PSR-0
+ private $prefixesPsr0 = array();
+ private $fallbackDirsPsr0 = array();
+
+ private $useIncludePath = false;
+ private $classMap = array();
+ private $classMapAuthoritative = false;
+ private $missingClasses = array();
+ private $apcuPrefix;
+
+ public function getPrefixes()
+ {
+ if (!empty($this->prefixesPsr0)) {
+ return call_user_func_array('array_merge', $this->prefixesPsr0);
+ }
+
+ return array();
+ }
+
+ public function getPrefixesPsr4()
+ {
+ return $this->prefixDirsPsr4;
+ }
+
+ public function getFallbackDirs()
+ {
+ return $this->fallbackDirsPsr0;
+ }
+
+ public function getFallbackDirsPsr4()
+ {
+ return $this->fallbackDirsPsr4;
+ }
+
+ public function getClassMap()
+ {
+ return $this->classMap;
+ }
+
+ /**
+ * @param array $classMap Class to filename map
+ */
+ public function addClassMap(array $classMap)
+ {
+ if ($this->classMap) {
+ $this->classMap = array_merge($this->classMap, $classMap);
+ } else {
+ $this->classMap = $classMap;
+ }
+ }
+
+ /**
+ * Registers a set of PSR-0 directories for a given prefix, either
+ * appending or prepending to the ones previously set for this prefix.
+ *
+ * @param string $prefix The prefix
+ * @param array|string $paths The PSR-0 root directories
+ * @param bool $prepend Whether to prepend the directories
+ */
+ public function add($prefix, $paths, $prepend = false)
+ {
+ if (!$prefix) {
+ if ($prepend) {
+ $this->fallbackDirsPsr0 = array_merge(
+ (array) $paths,
+ $this->fallbackDirsPsr0
+ );
+ } else {
+ $this->fallbackDirsPsr0 = array_merge(
+ $this->fallbackDirsPsr0,
+ (array) $paths
+ );
+ }
+
+ return;
+ }
+
+ $first = $prefix[0];
+ if (!isset($this->prefixesPsr0[$first][$prefix])) {
+ $this->prefixesPsr0[$first][$prefix] = (array) $paths;
+
+ return;
+ }
+ if ($prepend) {
+ $this->prefixesPsr0[$first][$prefix] = array_merge(
+ (array) $paths,
+ $this->prefixesPsr0[$first][$prefix]
+ );
+ } else {
+ $this->prefixesPsr0[$first][$prefix] = array_merge(
+ $this->prefixesPsr0[$first][$prefix],
+ (array) $paths
+ );
+ }
+ }
+
+ /**
+ * Registers a set of PSR-4 directories for a given namespace, either
+ * appending or prepending to the ones previously set for this namespace.
+ *
+ * @param string $prefix The prefix/namespace, with trailing '\\'
+ * @param array|string $paths The PSR-4 base directories
+ * @param bool $prepend Whether to prepend the directories
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function addPsr4($prefix, $paths, $prepend = false)
+ {
+ if (!$prefix) {
+ // Register directories for the root namespace.
+ if ($prepend) {
+ $this->fallbackDirsPsr4 = array_merge(
+ (array) $paths,
+ $this->fallbackDirsPsr4
+ );
+ } else {
+ $this->fallbackDirsPsr4 = array_merge(
+ $this->fallbackDirsPsr4,
+ (array) $paths
+ );
+ }
+ } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
+ // Register directories for a new namespace.
+ $length = strlen($prefix);
+ if ('\\' !== $prefix[$length - 1]) {
+ throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
+ }
+ $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
+ $this->prefixDirsPsr4[$prefix] = (array) $paths;
+ } elseif ($prepend) {
+ // Prepend directories for an already registered namespace.
+ $this->prefixDirsPsr4[$prefix] = array_merge(
+ (array) $paths,
+ $this->prefixDirsPsr4[$prefix]
+ );
+ } else {
+ // Append directories for an already registered namespace.
+ $this->prefixDirsPsr4[$prefix] = array_merge(
+ $this->prefixDirsPsr4[$prefix],
+ (array) $paths
+ );
+ }
+ }
+
+ /**
+ * Registers a set of PSR-0 directories for a given prefix,
+ * replacing any others previously set for this prefix.
+ *
+ * @param string $prefix The prefix
+ * @param array|string $paths The PSR-0 base directories
+ */
+ public function set($prefix, $paths)
+ {
+ if (!$prefix) {
+ $this->fallbackDirsPsr0 = (array) $paths;
+ } else {
+ $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
+ }
+ }
+
+ /**
+ * Registers a set of PSR-4 directories for a given namespace,
+ * replacing any others previously set for this namespace.
+ *
+ * @param string $prefix The prefix/namespace, with trailing '\\'
+ * @param array|string $paths The PSR-4 base directories
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function setPsr4($prefix, $paths)
+ {
+ if (!$prefix) {
+ $this->fallbackDirsPsr4 = (array) $paths;
+ } else {
+ $length = strlen($prefix);
+ if ('\\' !== $prefix[$length - 1]) {
+ throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
+ }
+ $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
+ $this->prefixDirsPsr4[$prefix] = (array) $paths;
+ }
+ }
+
+ /**
+ * Turns on searching the include path for class files.
+ *
+ * @param bool $useIncludePath
+ */
+ public function setUseIncludePath($useIncludePath)
+ {
+ $this->useIncludePath = $useIncludePath;
+ }
+
+ /**
+ * Can be used to check if the autoloader uses the include path to check
+ * for classes.
+ *
+ * @return bool
+ */
+ public function getUseIncludePath()
+ {
+ return $this->useIncludePath;
+ }
+
+ /**
+ * Turns off searching the prefix and fallback directories for classes
+ * that have not been registered with the class map.
+ *
+ * @param bool $classMapAuthoritative
+ */
+ public function setClassMapAuthoritative($classMapAuthoritative)
+ {
+ $this->classMapAuthoritative = $classMapAuthoritative;
+ }
+
+ /**
+ * Should class lookup fail if not found in the current class map?
+ *
+ * @return bool
+ */
+ public function isClassMapAuthoritative()
+ {
+ return $this->classMapAuthoritative;
+ }
+
+ /**
+ * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
+ *
+ * @param string|null $apcuPrefix
+ */
+ public function setApcuPrefix($apcuPrefix)
+ {
+ $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
+ }
+
+ /**
+ * The APCu prefix in use, or null if APCu caching is not enabled.
+ *
+ * @return string|null
+ */
+ public function getApcuPrefix()
+ {
+ return $this->apcuPrefix;
+ }
+
+ /**
+ * Registers this instance as an autoloader.
+ *
+ * @param bool $prepend Whether to prepend the autoloader or not
+ */
+ public function register($prepend = false)
+ {
+ spl_autoload_register(array($this, 'loadClass'), true, $prepend);
+ }
+
+ /**
+ * Unregisters this instance as an autoloader.
+ */
+ public function unregister()
+ {
+ spl_autoload_unregister(array($this, 'loadClass'));
+ }
+
+ /**
+ * Loads the given class or interface.
+ *
+ * @param string $class The name of the class
+ * @return bool|null True if loaded, null otherwise
+ */
+ public function loadClass($class)
+ {
+ if ($file = $this->findFile($class)) {
+ includeFile($file);
+
+ return true;
+ }
+ }
+
+ /**
+ * Finds the path to the file where the class is defined.
+ *
+ * @param string $class The name of the class
+ *
+ * @return string|false The path if found, false otherwise
+ */
+ public function findFile($class)
+ {
+ // class map lookup
+ if (isset($this->classMap[$class])) {
+ return $this->classMap[$class];
+ }
+ if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
+ return false;
+ }
+ if (null !== $this->apcuPrefix) {
+ $file = apcu_fetch($this->apcuPrefix.$class, $hit);
+ if ($hit) {
+ return $file;
+ }
+ }
+
+ $file = $this->findFileWithExtension($class, '.php');
+
+ // Search for Hack files if we are running on HHVM
+ if (false === $file && defined('HHVM_VERSION')) {
+ $file = $this->findFileWithExtension($class, '.hh');
+ }
+
+ if (null !== $this->apcuPrefix) {
+ apcu_add($this->apcuPrefix.$class, $file);
+ }
+
+ if (false === $file) {
+ // Remember that this class does not exist.
+ $this->missingClasses[$class] = true;
+ }
+
+ return $file;
+ }
+
+ private function findFileWithExtension($class, $ext)
+ {
+ // PSR-4 lookup
+ $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
+
+ $first = $class[0];
+ if (isset($this->prefixLengthsPsr4[$first])) {
+ $subPath = $class;
+ while (false !== $lastPos = strrpos($subPath, '\\')) {
+ $subPath = substr($subPath, 0, $lastPos);
+ $search = $subPath . '\\';
+ if (isset($this->prefixDirsPsr4[$search])) {
+ $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
+ foreach ($this->prefixDirsPsr4[$search] as $dir) {
+ if (file_exists($file = $dir . $pathEnd)) {
+ return $file;
+ }
+ }
+ }
+ }
+ }
+
+ // PSR-4 fallback dirs
+ foreach ($this->fallbackDirsPsr4 as $dir) {
+ if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
+ return $file;
+ }
+ }
+
+ // PSR-0 lookup
+ if (false !== $pos = strrpos($class, '\\')) {
+ // namespaced class name
+ $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
+ . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
+ } else {
+ // PEAR-like class name
+ $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
+ }
+
+ if (isset($this->prefixesPsr0[$first])) {
+ foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
+ if (0 === strpos($class, $prefix)) {
+ foreach ($dirs as $dir) {
+ if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
+ return $file;
+ }
+ }
+ }
+ }
+ }
+
+ // PSR-0 fallback dirs
+ foreach ($this->fallbackDirsPsr0 as $dir) {
+ if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
+ return $file;
+ }
+ }
+
+ // PSR-0 include paths.
+ if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
+ return $file;
+ }
+
+ return false;
+ }
+}
+
+/**
+ * Scope isolated include.
+ *
+ * Prevents access to $this/self from included files.
+ */
+function includeFile($file)
+{
+ include $file;
+}
diff --git a/securemail/vendor/composer/LICENSE b/securemail/vendor/composer/LICENSE
new file mode 100644
index 00000000..f27399a0
--- /dev/null
+++ b/securemail/vendor/composer/LICENSE
@@ -0,0 +1,21 @@
+
+Copyright (c) Nils Adermann, Jordi Boggiano
+
+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/securemail/vendor/composer/autoload_classmap.php b/securemail/vendor/composer/autoload_classmap.php
new file mode 100644
index 00000000..65b2f24d
--- /dev/null
+++ b/securemail/vendor/composer/autoload_classmap.php
@@ -0,0 +1,58 @@
+ $vendorDir . '/singpolyma/openpgp-php/lib/openpgp_mcrypt_wrapper.php',
+ 'OpenPGP' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_AsymmetricSessionKeyPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_CompressedDataPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_Crypt_RSA' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp_crypt_rsa.php',
+ 'OpenPGP_Crypt_Symmetric' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp_crypt_symmetric.php',
+ 'OpenPGP_EncryptedDataPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_ExperimentalPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_IntegrityProtectedDataPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_LiteralDataPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_MarkerPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_Message' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_ModificationDetectionCodePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_OnePassSignaturePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_Packet' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_PublicKeyPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_PublicSubkeyPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_S2K' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SecretKeyPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SecretSubkeyPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_EmbeddedSignaturePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_ExportableCertificationPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_FeaturesPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_IssuerPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_KeyExpirationTimePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_KeyFlagsPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_KeyServerPreferencesPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_NotationDataPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PolicyURIPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredCompressionAlgorithmsPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredHashAlgorithmsPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredKeyServerPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredSymmetricAlgorithmsPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PrimaryUserIDPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_ReasonforRevocationPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_RegularExpressionPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_RevocablePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_RevocationKeyPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignatureCreationTimePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignatureExpirationTimePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignatureTargetPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignersUserIDPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_Subpacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_TrustSignaturePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SymmetricSessionKeyPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_TrustPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_UserAttributePacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_UserIDPacket' => $vendorDir . '/singpolyma/openpgp-php/lib/openpgp.php',
+);
diff --git a/securemail/vendor/composer/autoload_files.php b/securemail/vendor/composer/autoload_files.php
new file mode 100644
index 00000000..9a9a17de
--- /dev/null
+++ b/securemail/vendor/composer/autoload_files.php
@@ -0,0 +1,10 @@
+ $vendorDir . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
+);
diff --git a/securemail/vendor/composer/autoload_namespaces.php b/securemail/vendor/composer/autoload_namespaces.php
new file mode 100644
index 00000000..b7fc0125
--- /dev/null
+++ b/securemail/vendor/composer/autoload_namespaces.php
@@ -0,0 +1,9 @@
+ array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
+);
diff --git a/securemail/vendor/composer/autoload_real.php b/securemail/vendor/composer/autoload_real.php
new file mode 100644
index 00000000..5b57bd5a
--- /dev/null
+++ b/securemail/vendor/composer/autoload_real.php
@@ -0,0 +1,70 @@
+= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
+ if ($useStaticLoader) {
+ require_once __DIR__ . '/autoload_static.php';
+
+ call_user_func(\Composer\Autoload\ComposerStaticInitSecuremailAddon::getInitializer($loader));
+ } else {
+ $map = require __DIR__ . '/autoload_namespaces.php';
+ foreach ($map as $namespace => $path) {
+ $loader->set($namespace, $path);
+ }
+
+ $map = require __DIR__ . '/autoload_psr4.php';
+ foreach ($map as $namespace => $path) {
+ $loader->setPsr4($namespace, $path);
+ }
+
+ $classMap = require __DIR__ . '/autoload_classmap.php';
+ if ($classMap) {
+ $loader->addClassMap($classMap);
+ }
+ }
+
+ $loader->register(true);
+
+ if ($useStaticLoader) {
+ $includeFiles = Composer\Autoload\ComposerStaticInitSecuremailAddon::$files;
+ } else {
+ $includeFiles = require __DIR__ . '/autoload_files.php';
+ }
+ foreach ($includeFiles as $fileIdentifier => $file) {
+ composerRequireSecuremailAddon($fileIdentifier, $file);
+ }
+
+ return $loader;
+ }
+}
+
+function composerRequireSecuremailAddon($fileIdentifier, $file)
+{
+ if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
+ require $file;
+
+ $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
+ }
+}
diff --git a/securemail/vendor/composer/autoload_static.php b/securemail/vendor/composer/autoload_static.php
new file mode 100644
index 00000000..fa77ac92
--- /dev/null
+++ b/securemail/vendor/composer/autoload_static.php
@@ -0,0 +1,88 @@
+ __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
+ );
+
+ public static $prefixLengthsPsr4 = array (
+ 'p' =>
+ array (
+ 'phpseclib\\' => 10,
+ ),
+ );
+
+ public static $prefixDirsPsr4 = array (
+ 'phpseclib\\' =>
+ array (
+ 0 => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib',
+ ),
+ );
+
+ public static $classMap = array (
+ 'MCryptWrapper' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp_mcrypt_wrapper.php',
+ 'OpenPGP' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_AsymmetricSessionKeyPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_CompressedDataPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_Crypt_RSA' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp_crypt_rsa.php',
+ 'OpenPGP_Crypt_Symmetric' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp_crypt_symmetric.php',
+ 'OpenPGP_EncryptedDataPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_ExperimentalPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_IntegrityProtectedDataPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_LiteralDataPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_MarkerPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_Message' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_ModificationDetectionCodePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_OnePassSignaturePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_Packet' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_PublicKeyPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_PublicSubkeyPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_S2K' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SecretKeyPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SecretSubkeyPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_EmbeddedSignaturePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_ExportableCertificationPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_FeaturesPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_IssuerPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_KeyExpirationTimePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_KeyFlagsPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_KeyServerPreferencesPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_NotationDataPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PolicyURIPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredCompressionAlgorithmsPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredHashAlgorithmsPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredKeyServerPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PreferredSymmetricAlgorithmsPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_PrimaryUserIDPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_ReasonforRevocationPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_RegularExpressionPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_RevocablePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_RevocationKeyPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignatureCreationTimePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignatureExpirationTimePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignatureTargetPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_SignersUserIDPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_Subpacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SignaturePacket_TrustSignaturePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_SymmetricSessionKeyPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_TrustPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_UserAttributePacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ 'OpenPGP_UserIDPacket' => __DIR__ . '/..' . '/singpolyma/openpgp-php/lib/openpgp.php',
+ );
+
+ public static function getInitializer(ClassLoader $loader)
+ {
+ return \Closure::bind(function () use ($loader) {
+ $loader->prefixLengthsPsr4 = ComposerStaticInitSecuremailAddon::$prefixLengthsPsr4;
+ $loader->prefixDirsPsr4 = ComposerStaticInitSecuremailAddon::$prefixDirsPsr4;
+ $loader->classMap = ComposerStaticInitSecuremailAddon::$classMap;
+
+ }, null, ClassLoader::class);
+ }
+}
diff --git a/securemail/vendor/composer/installed.json b/securemail/vendor/composer/installed.json
new file mode 100644
index 00000000..8181f155
--- /dev/null
+++ b/securemail/vendor/composer/installed.json
@@ -0,0 +1,141 @@
+[
+ {
+ "name": "phpseclib/phpseclib",
+ "version": "2.0.4",
+ "version_normalized": "2.0.4.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpseclib/phpseclib.git",
+ "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/ab8028c93c03cc8d9c824efa75dc94f1db2369bf",
+ "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phing/phing": "~2.7",
+ "phpunit/phpunit": "~4.0",
+ "sami/sami": "~2.0",
+ "squizlabs/php_codesniffer": "~2.0"
+ },
+ "suggest": {
+ "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
+ "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
+ "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
+ "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
+ },
+ "time": "2016-10-04T00:57:04+00:00",
+ "type": "library",
+ "installation-source": "dist",
+ "autoload": {
+ "files": [
+ "phpseclib/bootstrap.php"
+ ],
+ "psr-4": {
+ "phpseclib\\": "phpseclib/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jim Wigginton",
+ "email": "terrafrost@php.net",
+ "role": "Lead Developer"
+ },
+ {
+ "name": "Patrick Monnerat",
+ "email": "pm@datasphere.ch",
+ "role": "Developer"
+ },
+ {
+ "name": "Andreas Fischer",
+ "email": "bantu@phpbb.com",
+ "role": "Developer"
+ },
+ {
+ "name": "Hans-Jürgen Petrich",
+ "email": "petrich@tronic-media.com",
+ "role": "Developer"
+ },
+ {
+ "name": "Graham Campbell",
+ "email": "graham@alt-three.com",
+ "role": "Developer"
+ }
+ ],
+ "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
+ "homepage": "http://phpseclib.sourceforge.net",
+ "keywords": [
+ "BigInteger",
+ "aes",
+ "asn.1",
+ "asn1",
+ "blowfish",
+ "crypto",
+ "cryptography",
+ "encryption",
+ "rsa",
+ "security",
+ "sftp",
+ "signature",
+ "signing",
+ "ssh",
+ "twofish",
+ "x.509",
+ "x509"
+ ]
+ },
+ {
+ "name": "singpolyma/openpgp-php",
+ "version": "0.3.0",
+ "version_normalized": "0.3.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/singpolyma/openpgp-php.git",
+ "reference": "6006111bbc4c3b6cb8f0acb7d6c4a7047df366e8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/singpolyma/openpgp-php/zipball/6006111bbc4c3b6cb8f0acb7d6c4a7047df366e8",
+ "reference": "6006111bbc4c3b6cb8f0acb7d6c4a7047df366e8",
+ "shasum": ""
+ },
+ "require": {
+ "phpseclib/phpseclib": ">=2.0.0 <=2.0.4"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "time": "2017-04-12T21:23:15+00:00",
+ "type": "library",
+ "installation-source": "dist",
+ "autoload": {
+ "classmap": [
+ "lib/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "Unlicense"
+ ],
+ "authors": [
+ {
+ "name": "Arto Bendiken",
+ "email": "arto.bendiken@gmail.com"
+ },
+ {
+ "name": "Stephen Paul Weber",
+ "email": "singpolyma@singpolyma.net"
+ }
+ ],
+ "description": "Pure-PHP implementation of the OpenPGP Message Format (RFC 4880)"
+ }
+]
diff --git a/securemail/vendor/phpseclib/phpseclib/AUTHORS b/securemail/vendor/phpseclib/phpseclib/AUTHORS
index e175f9f2..a08b3099 100644
--- a/securemail/vendor/phpseclib/phpseclib/AUTHORS
+++ b/securemail/vendor/phpseclib/phpseclib/AUTHORS
@@ -3,3 +3,4 @@ phpseclib Lead Developer: TerraFrost (Jim Wigginton)
phpseclib Developers: monnerat (Patrick Monnerat)
bantu (Andreas Fischer)
petrich (Hans-Jürgen Petrich)
+ GrahamCampbell (Graham Campbell)
diff --git a/securemail/vendor/phpseclib/phpseclib/CHANGELOG.md b/securemail/vendor/phpseclib/phpseclib/CHANGELOG.md
deleted file mode 100644
index 0fd3ca09..00000000
--- a/securemail/vendor/phpseclib/phpseclib/CHANGELOG.md
+++ /dev/null
@@ -1,83 +0,0 @@
-# Changelog
-
-## 0.3.9 - 2014-11-09
-
-- PHP 5.6 improvements ([#482](https://github.com/phpseclib/phpseclib/pull/482), [#491](https://github.com/phpseclib/phpseclib/issues/491))
-
-## 0.3.8 - 2014-09-12
-
-- improve support for indef lengths in File_ASN1
-- add hmac-sha2-256 support to Net_SSH2
-- make it so negotiated algorithms can be seen before Net_SSH2 login
-- add sha256-96 and sha512-96 to Crypt_Hash
-- window size handling adjustments in Net_SSH2
-
-## 0.3.7 - 2014-07-05
-
-- auto-detect public vs private keys
-- add file_exists, is_dir, is_file, readlink and symlink to Net_SFTP
-- add support for recursive nlist and rawlist
-- make it so nlist and rawlist can return pre-sorted output
-- make it so callback functions can make exec() return early
-- add signSPKAC and saveSPKAC methods to File_X509
-- add support for PKCS8 keys in Crypt_RSA
-- add pbkdf1 support to setPassword() in Crypt_Base
-- add getWindowColumns, getWindowRows, setWindowColumns, setWindowRows to Net_SSH2
-- add support for filenames with spaces in them to Net_SCP
-
-## 0.3.6 - 2014-02-23
-
-- add preliminary support for custom SSH subsystems
-- add ssh-agent support
-
-## 0.3.5 - 2013-07-11
-
-- numerous SFTP changes:
- - chown
- - chgrp
- - truncate
- - improved file type detection
- - put() can write to te middle of a file
- - mkdir accepts the same paramters that PHP's mkdir does
- - the ability to upload/download 2GB files
-- across-the-board speedups for the various encryption algorithms
-- multi-factor authentication support for Net_SSH2
-- a $callback parameter for Net_SSH2::exec
-- new classes:
- - Net_SFTP_StreamWrapper
- - Net_SCP
- - Crypt_Twofish
- - Crypt_Blowfish
-
-## 0.3.1 - 2012-11-20
-
-- add Net_SSH2::enableQuietMode() for suppressing stderr
-- add Crypt_RSA::__toString() and Crypt_RSA::getSize()
-- fix problems with File_X509::validateDate(), File_X509::sign() and Crypt_RSA::verify()
-- use OpenSSL to speed up modular exponention in Math_BigInteger
-- improved timeout functionality in Net_SSH2
-- add support for SFTPv2
-- add support for CRLs in File_X509
-- SSH-2.0-SSH doesn't implement hmac-*-96 correctly
-
-## 0.3.0 - 2012-07-08
-
-- add support for reuming Net_SFTP::put()
-- add support for recursive deletes and recursive chmods to Net_SFTP
-- add setTimeout() to Net_SSH2
-- add support for PBKDF2 to the various Crypt_* classes via setPassword()
-- add File_X509 and File_ASN1
-- add the ability to decode various formats in Crypt_RSA
-- make Net_SSH2::getServerPublicHostKey() return a printer-friendly version of the public key
-
-## 0.2.2 - 2011-05-09
-
-- CFB and OFB modes were added to all block ciphers
-- support for interactive mode was added to Net_SSH2
-- Net_SSH2 now has limited keyboard_interactive authentication support
-- support was added for PuTTY formatted RSA private keys and XML formatted RSA private keys
-- Crypt_RSA::loadKey() will now try all key types automatically
-= add support for AES-128-CBC and DES-EDE3-CFB encrypted RSA private keys
-- add Net_SFTP::stat(), Net_SFTP::lstat() and Net_SFTP::rawlist()
-- logging was added to Net_SSH1
-- the license was changed to the less restrictive MIT license
\ No newline at end of file
diff --git a/securemail/vendor/phpseclib/phpseclib/LICENSE b/securemail/vendor/phpseclib/phpseclib/LICENSE
index 75f6b204..a8ec8ebd 100644
--- a/securemail/vendor/phpseclib/phpseclib/LICENSE
+++ b/securemail/vendor/phpseclib/phpseclib/LICENSE
@@ -1,4 +1,4 @@
-Copyright 2007-2013 TerraFrost and other contributors
+Copyright 2007-2016 TerraFrost and other contributors
http://phpseclib.sourceforge.net/
Permission is hereby granted, free of charge, to any person obtaining
diff --git a/securemail/vendor/phpseclib/phpseclib/README.md b/securemail/vendor/phpseclib/phpseclib/README.md
index cad56570..a6bde111 100644
--- a/securemail/vendor/phpseclib/phpseclib/README.md
+++ b/securemail/vendor/phpseclib/phpseclib/README.md
@@ -1,14 +1,14 @@
# phpseclib - PHP Secure Communications Library
-[![Build Status](https://secure.travis-ci.org/phpseclib/phpseclib.png?branch=master)](http://travis-ci.org/phpseclib/phpseclib)
+[![Build Status](https://travis-ci.org/phpseclib/phpseclib.svg?branch=2.0)](https://travis-ci.org/phpseclib/phpseclib)
MIT-licensed pure-PHP implementations of an arbitrary-precision integer
arithmetic library, fully PKCS#1 (v2.1) compliant RSA, DES, 3DES, RC4, Rijndael,
AES, Blowfish, Twofish, SSH-1, SSH-2, SFTP, and X.509
-* [Download (0.3.9)](http://sourceforge.net/projects/phpseclib/files/phpseclib0.3.9.zip/download)
+* [Download (1.0.4)](http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.4.zip/download)
* [Browse Git](https://github.com/phpseclib/phpseclib)
-* [Code Coverage Report](http://phpseclib.bantux.org/code_coverage/master/latest/)
+* [Code Coverage Report](http://phpseclib.bantux.org/code_coverage/2.0/latest/)
PEAR Channel: [phpseclib.sourceforge.net](http://phpseclib.sourceforge.net/pear.htm)
@@ -16,7 +16,7 @@ PEAR Channel: [phpseclib.sourceforge.net](http://phpseclib.sourceforge.net/pear.
## Documentation
* [Documentation / Manual](http://phpseclib.sourceforge.net/)
-* [API Documentation](http://phpseclib.bantux.org/api/master/) (generated by Sami)
+* [API Documentation](http://phpseclib.bantux.org/api/2.0/) (generated by Sami)
## Support
@@ -40,7 +40,7 @@ Dependencies are managed via Composer.
2. Install Dependencies
``` sh
- php composer.phar install --dev
+ php composer.phar install
```
## Contributing
diff --git a/securemail/vendor/phpseclib/phpseclib/composer.json b/securemail/vendor/phpseclib/phpseclib/composer.json
new file mode 100644
index 00000000..4b84b110
--- /dev/null
+++ b/securemail/vendor/phpseclib/phpseclib/composer.json
@@ -0,0 +1,76 @@
+{
+ "name": "phpseclib/phpseclib",
+ "type": "library",
+ "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
+ "keywords": [
+ "security",
+ "crypto",
+ "cryptography",
+ "encryption",
+ "signature",
+ "signing",
+ "rsa",
+ "aes",
+ "blowfish",
+ "twofish",
+ "ssh",
+ "sftp",
+ "x509",
+ "x.509",
+ "asn1",
+ "asn.1",
+ "BigInteger"
+ ],
+ "homepage": "http://phpseclib.sourceforge.net",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Jim Wigginton",
+ "email": "terrafrost@php.net",
+ "role": "Lead Developer"
+ },
+ {
+ "name": "Patrick Monnerat",
+ "email": "pm@datasphere.ch",
+ "role": "Developer"
+ },
+ {
+ "name": "Andreas Fischer",
+ "email": "bantu@phpbb.com",
+ "role": "Developer"
+ },
+ {
+ "name": "Hans-Jürgen Petrich",
+ "email": "petrich@tronic-media.com",
+ "role": "Developer"
+ },
+ {
+ "name": "Graham Campbell",
+ "email": "graham@alt-three.com",
+ "role": "Developer"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phing/phing": "~2.7",
+ "phpunit/phpunit": "~4.0",
+ "sami/sami": "~2.0",
+ "squizlabs/php_codesniffer": "~2.0"
+ },
+ "suggest": {
+ "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
+ "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations.",
+ "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
+ "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations."
+ },
+ "autoload": {
+ "files": [
+ "phpseclib/bootstrap.php"
+ ],
+ "psr-4": {
+ "phpseclib\\": "phpseclib/"
+ }
+ }
+}
diff --git a/securemail/vendor/phpseclib/phpseclib/composer.lock b/securemail/vendor/phpseclib/phpseclib/composer.lock
new file mode 100644
index 00000000..beda2d64
--- /dev/null
+++ b/securemail/vendor/phpseclib/phpseclib/composer.lock
@@ -0,0 +1,1819 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
+ ],
+ "hash": "8599992bf6058a9da82372eb8bcae2c2",
+ "content-hash": "fde47c84178c55c06de858a2128e3d07",
+ "packages": [],
+ "packages-dev": [
+ {
+ "name": "doctrine/instantiator",
+ "version": "1.0.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/instantiator.git",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3,<8.0-DEV"
+ },
+ "require-dev": {
+ "athletic/athletic": "~0.1.8",
+ "ext-pdo": "*",
+ "ext-phar": "*",
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "~2.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Marco Pivetta",
+ "email": "ocramius@gmail.com",
+ "homepage": "http://ocramius.github.com/"
+ }
+ ],
+ "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
+ "homepage": "https://github.com/doctrine/instantiator",
+ "keywords": [
+ "constructor",
+ "instantiate"
+ ],
+ "time": "2015-06-14 21:17:01"
+ },
+ {
+ "name": "michelf/php-markdown",
+ "version": "1.6.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/michelf/php-markdown.git",
+ "reference": "156e56ee036505ec637d761ee62dc425d807183c"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/michelf/php-markdown/zipball/156e56ee036505ec637d761ee62dc425d807183c",
+ "reference": "156e56ee036505ec637d761ee62dc425d807183c",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-lib": "1.4.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Michelf": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Michel Fortin",
+ "email": "michel.fortin@michelf.ca",
+ "homepage": "https://michelf.ca/",
+ "role": "Developer"
+ },
+ {
+ "name": "John Gruber",
+ "homepage": "https://daringfireball.net/"
+ }
+ ],
+ "description": "PHP Markdown",
+ "homepage": "https://michelf.ca/projects/php-markdown/",
+ "keywords": [
+ "markdown"
+ ],
+ "time": "2015-12-24 01:37:31"
+ },
+ {
+ "name": "nikic/php-parser",
+ "version": "v0.9.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/nikic/PHP-Parser.git",
+ "reference": "ef70767475434bdb3615b43c327e2cae17ef12eb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/ef70767475434bdb3615b43c327e2cae17ef12eb",
+ "reference": "ef70767475434bdb3615b43c327e2cae17ef12eb",
+ "shasum": ""
+ },
+ "require": {
+ "ext-tokenizer": "*",
+ "php": ">=5.2"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "0.9-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "PHPParser": "lib/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Nikita Popov"
+ }
+ ],
+ "description": "A PHP parser written in PHP",
+ "keywords": [
+ "parser",
+ "php"
+ ],
+ "time": "2014-07-23 18:24:17"
+ },
+ {
+ "name": "phing/phing",
+ "version": "2.14.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phingofficial/phing.git",
+ "reference": "7dd73c83c377623def54b58121f46b4dcb35dd61"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phingofficial/phing/zipball/7dd73c83c377623def54b58121f46b4dcb35dd61",
+ "reference": "7dd73c83c377623def54b58121f46b4dcb35dd61",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.2.0"
+ },
+ "require-dev": {
+ "ext-pdo_sqlite": "*",
+ "lastcraft/simpletest": "@dev",
+ "mikey179/vfsstream": "^1.6",
+ "pdepend/pdepend": "2.x",
+ "pear/archive_tar": "1.4.x",
+ "pear/http_request2": "dev-trunk",
+ "pear/net_growl": "dev-trunk",
+ "pear/pear-core-minimal": "1.10.1",
+ "pear/versioncontrol_git": "@dev",
+ "pear/versioncontrol_svn": "~0.5",
+ "phpdocumentor/phpdocumentor": "2.x",
+ "phploc/phploc": "~2.0.6",
+ "phpmd/phpmd": "~2.2",
+ "phpunit/phpunit": ">=3.7",
+ "sebastian/git": "~1.0",
+ "sebastian/phpcpd": "2.x",
+ "squizlabs/php_codesniffer": "~2.2",
+ "symfony/yaml": "~2.7"
+ },
+ "suggest": {
+ "pdepend/pdepend": "PHP version of JDepend",
+ "pear/archive_tar": "Tar file management class",
+ "pear/versioncontrol_git": "A library that provides OO interface to handle Git repository",
+ "pear/versioncontrol_svn": "A simple OO-style interface for Subversion, the free/open-source version control system",
+ "phpdocumentor/phpdocumentor": "Documentation Generator for PHP",
+ "phploc/phploc": "A tool for quickly measuring the size of a PHP project",
+ "phpmd/phpmd": "PHP version of PMD tool",
+ "phpunit/php-code-coverage": "Library that provides collection, processing, and rendering functionality for PHP code coverage information",
+ "phpunit/phpunit": "The PHP Unit Testing Framework",
+ "sebastian/phpcpd": "Copy/Paste Detector (CPD) for PHP code",
+ "tedivm/jshrink": "Javascript Minifier built in PHP"
+ },
+ "bin": [
+ "bin/phing"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.14.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "classes/phing/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ "classes"
+ ],
+ "license": [
+ "LGPL-3.0"
+ ],
+ "authors": [
+ {
+ "name": "Michiel Rook",
+ "email": "mrook@php.net"
+ },
+ {
+ "name": "Phing Community",
+ "homepage": "https://www.phing.info/trac/wiki/Development/Contributors"
+ }
+ ],
+ "description": "PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.",
+ "homepage": "https://www.phing.info/",
+ "keywords": [
+ "build",
+ "phing",
+ "task",
+ "tool"
+ ],
+ "time": "2016-03-10 21:39:23"
+ },
+ {
+ "name": "phpdocumentor/reflection-common",
+ "version": "1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpDocumentor/ReflectionCommon.git",
+ "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c",
+ "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.6"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "phpDocumentor\\Reflection\\": [
+ "src"
+ ]
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jaap van Otterdijk",
+ "email": "opensource@ijaap.nl"
+ }
+ ],
+ "description": "Common reflection classes used by phpdocumentor to reflect the code structure",
+ "homepage": "http://www.phpdoc.org",
+ "keywords": [
+ "FQSEN",
+ "phpDocumentor",
+ "phpdoc",
+ "reflection",
+ "static analysis"
+ ],
+ "time": "2015-12-27 11:43:31"
+ },
+ {
+ "name": "phpdocumentor/reflection-docblock",
+ "version": "3.1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
+ "reference": "9270140b940ff02e58ec577c237274e92cd40cdd"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd",
+ "reference": "9270140b940ff02e58ec577c237274e92cd40cdd",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5",
+ "phpdocumentor/reflection-common": "^1.0@dev",
+ "phpdocumentor/type-resolver": "^0.2.0",
+ "webmozart/assert": "^1.0"
+ },
+ "require-dev": {
+ "mockery/mockery": "^0.9.4",
+ "phpunit/phpunit": "^4.4"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "phpDocumentor\\Reflection\\": [
+ "src/"
+ ]
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Mike van Riel",
+ "email": "me@mikevanriel.com"
+ }
+ ],
+ "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
+ "time": "2016-06-10 09:48:41"
+ },
+ {
+ "name": "phpdocumentor/type-resolver",
+ "version": "0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpDocumentor/TypeResolver.git",
+ "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443",
+ "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5",
+ "phpdocumentor/reflection-common": "^1.0"
+ },
+ "require-dev": {
+ "mockery/mockery": "^0.9.4",
+ "phpunit/phpunit": "^5.2||^4.8.24"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "phpDocumentor\\Reflection\\": [
+ "src/"
+ ]
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Mike van Riel",
+ "email": "me@mikevanriel.com"
+ }
+ ],
+ "time": "2016-06-10 07:14:17"
+ },
+ {
+ "name": "phpspec/prophecy",
+ "version": "v1.6.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpspec/prophecy.git",
+ "reference": "58a8137754bc24b25740d4281399a4a3596058e0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0",
+ "reference": "58a8137754bc24b25740d4281399a4a3596058e0",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/instantiator": "^1.0.2",
+ "php": "^5.3|^7.0",
+ "phpdocumentor/reflection-docblock": "^2.0|^3.0.2",
+ "sebastian/comparator": "^1.1",
+ "sebastian/recursion-context": "^1.0"
+ },
+ "require-dev": {
+ "phpspec/phpspec": "^2.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.6.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Prophecy\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Konstantin Kudryashov",
+ "email": "ever.zet@gmail.com",
+ "homepage": "http://everzet.com"
+ },
+ {
+ "name": "Marcello Duarte",
+ "email": "marcello.duarte@gmail.com"
+ }
+ ],
+ "description": "Highly opinionated mocking framework for PHP 5.3+",
+ "homepage": "https://github.com/phpspec/prophecy",
+ "keywords": [
+ "Double",
+ "Dummy",
+ "fake",
+ "mock",
+ "spy",
+ "stub"
+ ],
+ "time": "2016-06-07 08:13:47"
+ },
+ {
+ "name": "phpunit/php-code-coverage",
+ "version": "2.2.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
+ "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979",
+ "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "phpunit/php-file-iterator": "~1.3",
+ "phpunit/php-text-template": "~1.2",
+ "phpunit/php-token-stream": "~1.3",
+ "sebastian/environment": "^1.3.2",
+ "sebastian/version": "~1.0"
+ },
+ "require-dev": {
+ "ext-xdebug": ">=2.1.4",
+ "phpunit/phpunit": "~4"
+ },
+ "suggest": {
+ "ext-dom": "*",
+ "ext-xdebug": ">=2.2.1",
+ "ext-xmlwriter": "*"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.2.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
+ "homepage": "https://github.com/sebastianbergmann/php-code-coverage",
+ "keywords": [
+ "coverage",
+ "testing",
+ "xunit"
+ ],
+ "time": "2015-10-06 15:47:00"
+ },
+ {
+ "name": "phpunit/php-file-iterator",
+ "version": "1.4.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
+ "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
+ "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.4.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "FilterIterator implementation that filters files based on a list of suffixes.",
+ "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
+ "keywords": [
+ "filesystem",
+ "iterator"
+ ],
+ "time": "2015-06-21 13:08:43"
+ },
+ {
+ "name": "phpunit/php-text-template",
+ "version": "1.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-text-template.git",
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Simple template engine.",
+ "homepage": "https://github.com/sebastianbergmann/php-text-template/",
+ "keywords": [
+ "template"
+ ],
+ "time": "2015-06-21 13:50:34"
+ },
+ {
+ "name": "phpunit/php-timer",
+ "version": "1.0.8",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-timer.git",
+ "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260",
+ "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4|~5"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Utility class for timing",
+ "homepage": "https://github.com/sebastianbergmann/php-timer/",
+ "keywords": [
+ "timer"
+ ],
+ "time": "2016-05-12 18:03:57"
+ },
+ {
+ "name": "phpunit/php-token-stream",
+ "version": "1.4.8",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-token-stream.git",
+ "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
+ "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
+ "shasum": ""
+ },
+ "require": {
+ "ext-tokenizer": "*",
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.2"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.4-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Wrapper around PHP's tokenizer extension.",
+ "homepage": "https://github.com/sebastianbergmann/php-token-stream/",
+ "keywords": [
+ "tokenizer"
+ ],
+ "time": "2015-09-15 10:49:45"
+ },
+ {
+ "name": "phpunit/phpunit",
+ "version": "4.8.26",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/phpunit.git",
+ "reference": "fc1d8cd5b5de11625979125c5639347896ac2c74"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc1d8cd5b5de11625979125c5639347896ac2c74",
+ "reference": "fc1d8cd5b5de11625979125c5639347896ac2c74",
+ "shasum": ""
+ },
+ "require": {
+ "ext-dom": "*",
+ "ext-json": "*",
+ "ext-pcre": "*",
+ "ext-reflection": "*",
+ "ext-spl": "*",
+ "php": ">=5.3.3",
+ "phpspec/prophecy": "^1.3.1",
+ "phpunit/php-code-coverage": "~2.1",
+ "phpunit/php-file-iterator": "~1.4",
+ "phpunit/php-text-template": "~1.2",
+ "phpunit/php-timer": "^1.0.6",
+ "phpunit/phpunit-mock-objects": "~2.3",
+ "sebastian/comparator": "~1.1",
+ "sebastian/diff": "~1.2",
+ "sebastian/environment": "~1.3",
+ "sebastian/exporter": "~1.2",
+ "sebastian/global-state": "~1.0",
+ "sebastian/version": "~1.0",
+ "symfony/yaml": "~2.1|~3.0"
+ },
+ "suggest": {
+ "phpunit/php-invoker": "~1.1"
+ },
+ "bin": [
+ "phpunit"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "4.8.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "The PHP Unit Testing framework.",
+ "homepage": "https://phpunit.de/",
+ "keywords": [
+ "phpunit",
+ "testing",
+ "xunit"
+ ],
+ "time": "2016-05-17 03:09:28"
+ },
+ {
+ "name": "phpunit/phpunit-mock-objects",
+ "version": "2.3.8",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
+ "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983",
+ "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/instantiator": "^1.0.2",
+ "php": ">=5.3.3",
+ "phpunit/php-text-template": "~1.2",
+ "sebastian/exporter": "~1.2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "suggest": {
+ "ext-soap": "*"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.3.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Mock Object library for PHPUnit",
+ "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
+ "keywords": [
+ "mock",
+ "xunit"
+ ],
+ "time": "2015-10-02 06:51:40"
+ },
+ {
+ "name": "pimple/pimple",
+ "version": "v2.1.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/silexphp/Pimple.git",
+ "reference": "ea22fb2880faf7b7b0e17c9809c6fe25b071fd76"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/silexphp/Pimple/zipball/ea22fb2880faf7b7b0e17c9809c6fe25b071fd76",
+ "reference": "ea22fb2880faf7b7b0e17c9809c6fe25b071fd76",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.1.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Pimple": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ }
+ ],
+ "description": "Pimple is a simple Dependency Injection Container for PHP 5.3",
+ "homepage": "http://pimple.sensiolabs.org",
+ "keywords": [
+ "container",
+ "dependency injection"
+ ],
+ "time": "2014-07-24 07:10:08"
+ },
+ {
+ "name": "sami/sami",
+ "version": "v2.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/FriendsOfPHP/Sami.git",
+ "reference": "fa58b324f41aa2aefe21dac4f22d8c98965fc012"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/FriendsOfPHP/Sami/zipball/fa58b324f41aa2aefe21dac4f22d8c98965fc012",
+ "reference": "fa58b324f41aa2aefe21dac4f22d8c98965fc012",
+ "shasum": ""
+ },
+ "require": {
+ "michelf/php-markdown": "~1.3",
+ "nikic/php-parser": "0.9.*",
+ "php": ">=5.3.0",
+ "pimple/pimple": "2.*",
+ "symfony/console": "~2.1",
+ "symfony/filesystem": "~2.1",
+ "symfony/finder": "~2.1",
+ "symfony/process": "~2.1",
+ "symfony/yaml": "~2.1",
+ "twig/twig": "1.*"
+ },
+ "bin": [
+ "sami.php"
+ ],
+ "type": "application",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Sami": "."
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ }
+ ],
+ "description": "Sami, an API documentation generator",
+ "homepage": "http://sami.sensiolabs.org",
+ "keywords": [
+ "phpdoc"
+ ],
+ "time": "2014-06-25 12:05:18"
+ },
+ {
+ "name": "sebastian/comparator",
+ "version": "1.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/comparator.git",
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "sebastian/diff": "~1.2",
+ "sebastian/exporter": "~1.2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.2.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
+ "name": "Volker Dusch",
+ "email": "github@wallbash.com"
+ },
+ {
+ "name": "Bernhard Schussek",
+ "email": "bschussek@2bepublished.at"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Provides the functionality to compare PHP values for equality",
+ "homepage": "http://www.github.com/sebastianbergmann/comparator",
+ "keywords": [
+ "comparator",
+ "compare",
+ "equality"
+ ],
+ "time": "2015-07-26 15:48:44"
+ },
+ {
+ "name": "sebastian/diff",
+ "version": "1.4.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/diff.git",
+ "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e",
+ "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.8"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.4-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Kore Nordmann",
+ "email": "mail@kore-nordmann.de"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Diff implementation",
+ "homepage": "https://github.com/sebastianbergmann/diff",
+ "keywords": [
+ "diff"
+ ],
+ "time": "2015-12-08 07:14:41"
+ },
+ {
+ "name": "sebastian/environment",
+ "version": "1.3.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/environment.git",
+ "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716",
+ "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Provides functionality to handle HHVM/PHP environments",
+ "homepage": "http://www.github.com/sebastianbergmann/environment",
+ "keywords": [
+ "Xdebug",
+ "environment",
+ "hhvm"
+ ],
+ "time": "2016-05-17 03:18:57"
+ },
+ {
+ "name": "sebastian/exporter",
+ "version": "1.2.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/exporter.git",
+ "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4",
+ "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "sebastian/recursion-context": "~1.0"
+ },
+ "require-dev": {
+ "ext-mbstring": "*",
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
+ "name": "Volker Dusch",
+ "email": "github@wallbash.com"
+ },
+ {
+ "name": "Bernhard Schussek",
+ "email": "bschussek@2bepublished.at"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ },
+ {
+ "name": "Adam Harvey",
+ "email": "aharvey@php.net"
+ }
+ ],
+ "description": "Provides the functionality to export PHP variables for visualization",
+ "homepage": "http://www.github.com/sebastianbergmann/exporter",
+ "keywords": [
+ "export",
+ "exporter"
+ ],
+ "time": "2016-06-17 09:04:28"
+ },
+ {
+ "name": "sebastian/global-state",
+ "version": "1.1.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/global-state.git",
+ "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4",
+ "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.2"
+ },
+ "suggest": {
+ "ext-uopz": "*"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ }
+ ],
+ "description": "Snapshotting of global state",
+ "homepage": "http://www.github.com/sebastianbergmann/global-state",
+ "keywords": [
+ "global state"
+ ],
+ "time": "2015-10-12 03:26:01"
+ },
+ {
+ "name": "sebastian/recursion-context",
+ "version": "1.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/recursion-context.git",
+ "reference": "913401df809e99e4f47b27cdd781f4a258d58791"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791",
+ "reference": "913401df809e99e4f47b27cdd781f4a258d58791",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.4"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de"
+ },
+ {
+ "name": "Adam Harvey",
+ "email": "aharvey@php.net"
+ }
+ ],
+ "description": "Provides functionality to recursively process PHP variables",
+ "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+ "time": "2015-11-11 19:50:13"
+ },
+ {
+ "name": "sebastian/version",
+ "version": "1.0.6",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/version.git",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
+ "shasum": ""
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Library that helps with managing the version number of Git-hosted PHP projects",
+ "homepage": "https://github.com/sebastianbergmann/version",
+ "time": "2015-06-21 13:59:46"
+ },
+ {
+ "name": "squizlabs/php_codesniffer",
+ "version": "2.6.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
+ "reference": "fb72ed32f8418db5e7770be1653e62e0d6f5dd3d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/fb72ed32f8418db5e7770be1653e62e0d6f5dd3d",
+ "reference": "fb72ed32f8418db5e7770be1653e62e0d6f5dd3d",
+ "shasum": ""
+ },
+ "require": {
+ "ext-simplexml": "*",
+ "ext-tokenizer": "*",
+ "ext-xmlwriter": "*",
+ "php": ">=5.1.2"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "bin": [
+ "scripts/phpcs",
+ "scripts/phpcbf"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "CodeSniffer.php",
+ "CodeSniffer/CLI.php",
+ "CodeSniffer/Exception.php",
+ "CodeSniffer/File.php",
+ "CodeSniffer/Fixer.php",
+ "CodeSniffer/Report.php",
+ "CodeSniffer/Reporting.php",
+ "CodeSniffer/Sniff.php",
+ "CodeSniffer/Tokens.php",
+ "CodeSniffer/Reports/",
+ "CodeSniffer/Tokenizers/",
+ "CodeSniffer/DocGenerators/",
+ "CodeSniffer/Standards/AbstractPatternSniff.php",
+ "CodeSniffer/Standards/AbstractScopeSniff.php",
+ "CodeSniffer/Standards/AbstractVariableSniff.php",
+ "CodeSniffer/Standards/IncorrectPatternException.php",
+ "CodeSniffer/Standards/Generic/Sniffs/",
+ "CodeSniffer/Standards/MySource/Sniffs/",
+ "CodeSniffer/Standards/PEAR/Sniffs/",
+ "CodeSniffer/Standards/PSR1/Sniffs/",
+ "CodeSniffer/Standards/PSR2/Sniffs/",
+ "CodeSniffer/Standards/Squiz/Sniffs/",
+ "CodeSniffer/Standards/Zend/Sniffs/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Greg Sherwood",
+ "role": "lead"
+ }
+ ],
+ "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
+ "homepage": "http://www.squizlabs.com/php-codesniffer",
+ "keywords": [
+ "phpcs",
+ "standards"
+ ],
+ "time": "2016-05-30 22:24:32"
+ },
+ {
+ "name": "symfony/console",
+ "version": "v2.8.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/console.git",
+ "reference": "5ac8bc9aa77bb2edf06af3a1bb6bc1020d23acd3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/console/zipball/5ac8bc9aa77bb2edf06af3a1bb6bc1020d23acd3",
+ "reference": "5ac8bc9aa77bb2edf06af3a1bb6bc1020d23acd3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.9",
+ "symfony/polyfill-mbstring": "~1.0"
+ },
+ "require-dev": {
+ "psr/log": "~1.0",
+ "symfony/event-dispatcher": "~2.1|~3.0.0",
+ "symfony/process": "~2.1|~3.0.0"
+ },
+ "suggest": {
+ "psr/log": "For using the console logger",
+ "symfony/event-dispatcher": "",
+ "symfony/process": ""
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.8-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Console\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Console Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-06-06 15:06:25"
+ },
+ {
+ "name": "symfony/filesystem",
+ "version": "v2.8.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/filesystem.git",
+ "reference": "dee379131dceed90a429e951546b33edfe7dccbb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/filesystem/zipball/dee379131dceed90a429e951546b33edfe7dccbb",
+ "reference": "dee379131dceed90a429e951546b33edfe7dccbb",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.9"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.8-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Filesystem\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Filesystem Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-04-12 18:01:21"
+ },
+ {
+ "name": "symfony/finder",
+ "version": "v2.8.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/finder.git",
+ "reference": "3ec095fab1800222732ca522a95dce8fa124007b"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/finder/zipball/3ec095fab1800222732ca522a95dce8fa124007b",
+ "reference": "3ec095fab1800222732ca522a95dce8fa124007b",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.9"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.8-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Finder\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Finder Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-06-06 11:11:27"
+ },
+ {
+ "name": "symfony/polyfill-mbstring",
+ "version": "v1.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/polyfill-mbstring.git",
+ "reference": "dff51f72b0706335131b00a7f49606168c582594"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594",
+ "reference": "dff51f72b0706335131b00a7f49606168c582594",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "suggest": {
+ "ext-mbstring": "For best performance"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.2-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Polyfill\\Mbstring\\": ""
+ },
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill for the Mbstring extension",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "mbstring",
+ "polyfill",
+ "portable",
+ "shim"
+ ],
+ "time": "2016-05-18 14:26:46"
+ },
+ {
+ "name": "symfony/process",
+ "version": "v2.8.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/process.git",
+ "reference": "115347d00c342198cdc52a7bd8bc15b5ab43500c"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/process/zipball/115347d00c342198cdc52a7bd8bc15b5ab43500c",
+ "reference": "115347d00c342198cdc52a7bd8bc15b5ab43500c",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.9"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.8-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Process\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Process Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-06-06 11:11:27"
+ },
+ {
+ "name": "symfony/yaml",
+ "version": "v2.8.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/yaml.git",
+ "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/815fabf3f48c7d1df345a69d1ad1a88f59757b34",
+ "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.9"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.8-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Yaml\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Yaml Component",
+ "homepage": "https://symfony.com",
+ "time": "2016-06-06 11:11:27"
+ },
+ {
+ "name": "twig/twig",
+ "version": "v1.24.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/twigphp/Twig.git",
+ "reference": "3566d311a92aae4deec6e48682dc5a4528c4a512"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/twigphp/Twig/zipball/3566d311a92aae4deec6e48682dc5a4528c4a512",
+ "reference": "3566d311a92aae4deec6e48682dc5a4528c4a512",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.2.7"
+ },
+ "require-dev": {
+ "symfony/debug": "~2.7",
+ "symfony/phpunit-bridge": "~2.7"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.24-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Twig_": "lib/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com",
+ "homepage": "http://fabien.potencier.org",
+ "role": "Lead Developer"
+ },
+ {
+ "name": "Armin Ronacher",
+ "email": "armin.ronacher@active-4.com",
+ "role": "Project Founder"
+ },
+ {
+ "name": "Twig Team",
+ "homepage": "http://twig.sensiolabs.org/contributors",
+ "role": "Contributors"
+ }
+ ],
+ "description": "Twig, the flexible, fast, and secure template language for PHP",
+ "homepage": "http://twig.sensiolabs.org",
+ "keywords": [
+ "templating"
+ ],
+ "time": "2016-05-30 09:11:59"
+ },
+ {
+ "name": "webmozart/assert",
+ "version": "1.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/webmozart/assert.git",
+ "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde",
+ "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.6"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Webmozart\\Assert\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Bernhard Schussek",
+ "email": "bschussek@gmail.com"
+ }
+ ],
+ "description": "Assertions to validate method input/output with nice error messages.",
+ "keywords": [
+ "assert",
+ "check",
+ "validate"
+ ],
+ "time": "2015-08-24 13:29:44"
+ }
+ ],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": {
+ "php": ">=5.3.3"
+ },
+ "platform-dev": []
+}
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/AES.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/AES.php
index 6b1f9daa..7d8cb8b0 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/AES.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/AES.php
@@ -5,23 +5,27 @@
*
* Uses mcrypt, if available/possible, and an internal implementation, otherwise.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
- * If {@link Crypt_AES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
- * {@link Crypt_AES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
- * it'll be null-padded to 192-bits and 192 bits will be the key length until {@link Crypt_AES::setKey() setKey()}
+ * NOTE: Since AES.php is (for compatibility and phpseclib-historical reasons) virtually
+ * just a wrapper to Rijndael.php you may consider using Rijndael.php instead of
+ * to save one include_once().
+ *
+ * If {@link self::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
+ * {@link self::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
+ * it'll be null-padded to 192-bits and 192 bits will be the key length until {@link self::setKey() setKey()}
* is called, again, at which point, it'll be recalculated.
*
- * Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't
- * make a whole lot of sense. {@link Crypt_AES::setBlockLength() setBlockLength()}, for instance. Calling that function,
+ * Since \phpseclib\Crypt\AES extends \phpseclib\Crypt\Rijndael, some functions are available to be called that, in the context of AES, don't
+ * make a whole lot of sense. {@link self::setBlockLength() setBlockLength()}, for instance. Calling that function,
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
*
* Here's a short example of how to use this library:
*
* setKey('abcdefghijklmnop');
*
@@ -35,118 +39,33 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_AES
+ * @package AES
* @author Jim Wigginton
* @copyright 2008 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Rijndael
- */
-if (!class_exists('Crypt_Rijndael')) {
- include_once 'Rijndael.php';
-}
-
-/**#@+
- * @access public
- * @see Crypt_AES::encrypt()
- * @see Crypt_AES::decrypt()
- */
-/**
- * Encrypt / decrypt using the Counter mode.
- *
- * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
- */
-define('CRYPT_AES_MODE_CTR', CRYPT_MODE_CTR);
-/**
- * Encrypt / decrypt using the Electronic Code Book mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
- */
-define('CRYPT_AES_MODE_ECB', CRYPT_MODE_ECB);
-/**
- * Encrypt / decrypt using the Code Book Chaining mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
- */
-define('CRYPT_AES_MODE_CBC', CRYPT_MODE_CBC);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
- */
-define('CRYPT_AES_MODE_CFB', CRYPT_MODE_CFB);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
- */
-define('CRYPT_AES_MODE_OFB', CRYPT_MODE_OFB);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_Base::Crypt_Base()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_AES_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
-/**
- * Toggles the mcrypt implementation
- */
-define('CRYPT_AES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of AES.
*
- * @package Crypt_AES
+ * @package AES
* @author Jim Wigginton
* @access public
*/
-class Crypt_AES extends Crypt_Rijndael
+class AES extends Rijndael
{
- /**
- * The namespace used by the cipher for its constants.
- *
- * @see Crypt_Base::const_namespace
- * @var String
- * @access private
- */
- var $const_namespace = 'AES';
-
/**
* Dummy function
*
- * Since Crypt_AES extends Crypt_Rijndael, this function is, technically, available, but it doesn't do anything.
+ * Since \phpseclib\Crypt\AES extends \phpseclib\Crypt\Rijndael, this function is, technically, available, but it doesn't do anything.
*
- * @see Crypt_Rijndael::setBlockLength()
+ * @see \phpseclib\Crypt\Rijndael::setBlockLength()
* @access public
- * @param Integer $length
+ * @param int $length
*/
function setBlockLength($length)
{
@@ -159,9 +78,9 @@ class Crypt_AES extends Crypt_Rijndael
* Valid key lengths are 128, 192, and 256. If the length is less than 128, it will be rounded up to
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
*
- * @see Crypt_Rijndael:setKeyLength()
+ * @see \phpseclib\Crypt\Rijndael:setKeyLength()
* @access public
- * @param Integer $length
+ * @param int $length
*/
function setKeyLength($length)
{
@@ -180,10 +99,10 @@ class Crypt_AES extends Crypt_Rijndael
*
* Rijndael supports five different key lengths, AES only supports three.
*
- * @see Crypt_Rijndael:setKey()
+ * @see \phpseclib\Crypt\Rijndael:setKey()
* @see setKeyLength()
* @access public
- * @param String $key
+ * @param string $key
*/
function setKey($key)
{
@@ -193,15 +112,15 @@ class Crypt_AES extends Crypt_Rijndael
$length = strlen($key);
switch (true) {
case $length <= 16:
- $this->key_size = 16;
+ $this->key_length = 16;
break;
case $length <= 24:
- $this->key_size = 24;
+ $this->key_length = 24;
break;
default:
- $this->key_size = 32;
+ $this->key_length = 32;
}
- $this->_setupEngine();
+ $this->_setEngine();
}
}
}
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Base.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Base.php
index 4df2a2db..fd99c44f 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Base.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Base.php
@@ -1,14 +1,14 @@
* @author Hans-Juergen Petrich
* @copyright 2007 Jim Wigginton
@@ -52,79 +34,92 @@
* @link http://phpseclib.sourceforge.net
*/
-/**#@+
- * @access public
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::decrypt()
- */
-/**
- * Encrypt / decrypt using the Counter mode.
- *
- * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
- */
-define('CRYPT_MODE_CTR', -1);
-/**
- * Encrypt / decrypt using the Electronic Code Book mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
- */
-define('CRYPT_MODE_ECB', 1);
-/**
- * Encrypt / decrypt using the Code Book Chaining mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
- */
-define('CRYPT_MODE_CBC', 2);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
- */
-define('CRYPT_MODE_CFB', 3);
-/**
- * Encrypt / decrypt using the Output Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
- */
-define('CRYPT_MODE_OFB', 4);
-/**
- * Encrypt / decrypt using streaming mode.
- *
- */
-define('CRYPT_MODE_STREAM', 5);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_Base::Crypt_Base()
- */
-/**
- * Base value for the internal implementation $engine switch
- */
-define('CRYPT_MODE_INTERNAL', 1);
-/**
- * Base value for the mcrypt implementation $engine switch
- */
-define('CRYPT_MODE_MCRYPT', 2);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
- * Base Class for all Crypt_* cipher classes
+ * Base Class for all \phpseclib\Crypt\* cipher classes
*
- * @package Crypt_Base
+ * @package Base
* @author Jim Wigginton
* @author Hans-Juergen Petrich
- * @access public
*/
-class Crypt_Base
+abstract class Base
{
+ /**#@+
+ * @access public
+ * @see \phpseclib\Crypt\Base::encrypt()
+ * @see \phpseclib\Crypt\Base::decrypt()
+ */
+ /**
+ * Encrypt / decrypt using the Counter mode.
+ *
+ * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
+ *
+ * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
+ */
+ const MODE_CTR = -1;
+ /**
+ * Encrypt / decrypt using the Electronic Code Book mode.
+ *
+ * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
+ */
+ const MODE_ECB = 1;
+ /**
+ * Encrypt / decrypt using the Code Book Chaining mode.
+ *
+ * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
+ */
+ const MODE_CBC = 2;
+ /**
+ * Encrypt / decrypt using the Cipher Feedback mode.
+ *
+ * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
+ */
+ const MODE_CFB = 3;
+ /**
+ * Encrypt / decrypt using the Output Feedback mode.
+ *
+ * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
+ */
+ const MODE_OFB = 4;
+ /**
+ * Encrypt / decrypt using streaming mode.
+ */
+ const MODE_STREAM = 5;
+ /**#@-*/
+
+ /**
+ * Whirlpool available flag
+ *
+ * @see \phpseclib\Crypt\Base::_hashInlineCryptFunction()
+ * @var bool
+ * @access private
+ */
+ static $WHIRLPOOL_AVAILABLE;
+
+ /**#@+
+ * @access private
+ * @see \phpseclib\Crypt\Base::__construct()
+ */
+ /**
+ * Base value for the internal implementation $engine switch
+ */
+ const ENGINE_INTERNAL = 1;
+ /**
+ * Base value for the mcrypt implementation $engine switch
+ */
+ const ENGINE_MCRYPT = 2;
+ /**
+ * Base value for the mcrypt implementation $engine switch
+ */
+ const ENGINE_OPENSSL = 3;
+ /**#@-*/
+
/**
* The Encryption Mode
*
- * @see Crypt_Base::Crypt_Base()
- * @var Integer
+ * @see self::__construct()
+ * @var int
* @access private
*/
var $mode;
@@ -132,7 +127,7 @@ class Crypt_Base
/**
* The Block Length of the block cipher
*
- * @var Integer
+ * @var int
* @access private
*/
var $block_size = 16;
@@ -140,8 +135,8 @@ class Crypt_Base
/**
* The Key
*
- * @see Crypt_Base::setKey()
- * @var String
+ * @see self::setKey()
+ * @var string
* @access private
*/
var $key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
@@ -149,8 +144,8 @@ class Crypt_Base
/**
* The Initialization Vector
*
- * @see Crypt_Base::setIV()
- * @var String
+ * @see self::setIV()
+ * @var string
* @access private
*/
var $iv;
@@ -158,9 +153,9 @@ class Crypt_Base
/**
* A "sliding" Initialization Vector
*
- * @see Crypt_Base::enableContinuousBuffer()
- * @see Crypt_Base::_clearBuffers()
- * @var String
+ * @see self::enableContinuousBuffer()
+ * @see self::_clearBuffers()
+ * @var string
* @access private
*/
var $encryptIV;
@@ -168,9 +163,9 @@ class Crypt_Base
/**
* A "sliding" Initialization Vector
*
- * @see Crypt_Base::enableContinuousBuffer()
- * @see Crypt_Base::_clearBuffers()
- * @var String
+ * @see self::enableContinuousBuffer()
+ * @see self::_clearBuffers()
+ * @var string
* @access private
*/
var $decryptIV;
@@ -178,8 +173,8 @@ class Crypt_Base
/**
* Continuous Buffer status
*
- * @see Crypt_Base::enableContinuousBuffer()
- * @var Boolean
+ * @see self::enableContinuousBuffer()
+ * @var bool
* @access private
*/
var $continuousBuffer = false;
@@ -187,9 +182,9 @@ class Crypt_Base
/**
* Encryption buffer for CTR, OFB and CFB modes
*
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::_clearBuffers()
- * @var Array
+ * @see self::encrypt()
+ * @see self::_clearBuffers()
+ * @var array
* @access private
*/
var $enbuffer;
@@ -197,9 +192,9 @@ class Crypt_Base
/**
* Decryption buffer for CTR, OFB and CFB modes
*
- * @see Crypt_Base::decrypt()
- * @see Crypt_Base::_clearBuffers()
- * @var Array
+ * @see self::decrypt()
+ * @see self::_clearBuffers()
+ * @var array
* @access private
*/
var $debuffer;
@@ -210,8 +205,8 @@ class Crypt_Base
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
*
- * @see Crypt_Base::encrypt()
- * @var Resource
+ * @see self::encrypt()
+ * @var resource
* @access private
*/
var $enmcrypt;
@@ -222,8 +217,8 @@ class Crypt_Base
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
*
- * @see Crypt_Base::decrypt()
- * @var Resource
+ * @see self::decrypt()
+ * @var resource
* @access private
*/
var $demcrypt;
@@ -231,9 +226,9 @@ class Crypt_Base
/**
* Does the enmcrypt resource need to be (re)initialized?
*
- * @see Crypt_Twofish::setKey()
- * @see Crypt_Twofish::setIV()
- * @var Boolean
+ * @see \phpseclib\Crypt\Twofish::setKey()
+ * @see \phpseclib\Crypt\Twofish::setIV()
+ * @var bool
* @access private
*/
var $enchanged = true;
@@ -241,9 +236,9 @@ class Crypt_Base
/**
* Does the demcrypt resource need to be (re)initialized?
*
- * @see Crypt_Twofish::setKey()
- * @see Crypt_Twofish::setIV()
- * @var Boolean
+ * @see \phpseclib\Crypt\Twofish::setKey()
+ * @see \phpseclib\Crypt\Twofish::setIV()
+ * @var bool
* @access private
*/
var $dechanged = true;
@@ -259,10 +254,10 @@ class Crypt_Base
* use a separate ECB-mode mcrypt resource.
*
* @link http://phpseclib.sourceforge.net/cfb-demo.phps
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::decrypt()
- * @see Crypt_Base::_setupMcrypt()
- * @var Resource
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @see self::_setupMcrypt()
+ * @var resource
* @access private
*/
var $ecb;
@@ -271,7 +266,7 @@ class Crypt_Base
* Optimizing value while CFB-encrypting
*
* Only relevant if $continuousBuffer enabled
- * and $engine == CRYPT_MODE_MCRYPT
+ * and $engine == self::ENGINE_MCRYPT
*
* It's faster to re-init $enmcrypt if
* $buffer bytes > $cfb_init_len than
@@ -283,8 +278,8 @@ class Crypt_Base
* which, typically, depends on the complexity
* on its internaly Key-expanding algorithm.
*
- * @see Crypt_Base::encrypt()
- * @var Integer
+ * @see self::encrypt()
+ * @var int
* @access private
*/
var $cfb_init_len = 600;
@@ -292,10 +287,10 @@ class Crypt_Base
/**
* Does internal cipher state need to be (re)initialized?
*
- * @see setKey()
- * @see setIV()
- * @see disableContinuousBuffer()
- * @var Boolean
+ * @see self::setKey()
+ * @see self::setIV()
+ * @see self::disableContinuousBuffer()
+ * @var bool
* @access private
*/
var $changed = true;
@@ -303,8 +298,8 @@ class Crypt_Base
/**
* Padding status
*
- * @see Crypt_Base::enablePadding()
- * @var Boolean
+ * @see self::enablePadding()
+ * @var bool
* @access private
*/
var $padding = true;
@@ -312,8 +307,8 @@ class Crypt_Base
/**
* Is the mode one that is paddable?
*
- * @see Crypt_Base::Crypt_Base()
- * @var Boolean
+ * @see self::__construct()
+ * @var bool
* @access private
*/
var $paddable = false;
@@ -323,86 +318,83 @@ class Crypt_Base
* which will be determined automatically on __construct()
*
* Currently available $engines are:
- * - CRYPT_MODE_MCRYPT (fast, php-extension: mcrypt, extension_loaded('mcrypt') required)
- * - CRYPT_MODE_INTERNAL (slower, pure php-engine, no php-extension required)
+ * - self::ENGINE_OPENSSL (very fast, php-extension: openssl, extension_loaded('openssl') required)
+ * - self::ENGINE_MCRYPT (fast, php-extension: mcrypt, extension_loaded('mcrypt') required)
+ * - self::ENGINE_INTERNAL (slower, pure php-engine, no php-extension required)
*
- * In the pipeline... maybe. But currently not available:
- * - CRYPT_MODE_OPENSSL (very fast, php-extension: openssl, extension_loaded('openssl') required)
- *
- * If possible, CRYPT_MODE_MCRYPT will be used for each cipher.
- * Otherwise CRYPT_MODE_INTERNAL
- *
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::decrypt()
- * @var Integer
+ * @see self::_setEngine()
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @var int
* @access private
*/
var $engine;
+ /**
+ * Holds the preferred crypt engine
+ *
+ * @see self::_setEngine()
+ * @see self::setPreferredEngine()
+ * @var int
+ * @access private
+ */
+ var $preferredEngine;
+
/**
* The mcrypt specific name of the cipher
*
- * Only used if $engine == CRYPT_MODE_MCRYPT
+ * Only used if $engine == self::ENGINE_MCRYPT
*
* @link http://www.php.net/mcrypt_module_open
* @link http://www.php.net/mcrypt_list_algorithms
- * @see Crypt_Base::_setupMcrypt()
- * @var String
+ * @see self::_setupMcrypt()
+ * @var string
* @access private
*/
var $cipher_name_mcrypt;
/**
- * The default password key_size used by setPassword()
+ * The openssl specific name of the cipher
*
- * @see Crypt_Base::setPassword()
- * @var Integer
+ * Only used if $engine == self::ENGINE_OPENSSL
+ *
+ * @link http://www.php.net/openssl-get-cipher-methods
+ * @var string
* @access private
*/
- var $password_key_size = 32;
+ var $cipher_name_openssl;
+
+ /**
+ * The openssl specific name of the cipher in ECB mode
+ *
+ * If OpenSSL does not support the mode we're trying to use (CTR)
+ * it can still be emulated with ECB mode.
+ *
+ * @link http://www.php.net/openssl-get-cipher-methods
+ * @var string
+ * @access private
+ */
+ var $cipher_name_openssl_ecb;
/**
* The default salt used by setPassword()
*
- * @see Crypt_Base::setPassword()
- * @var String
+ * @see self::setPassword()
+ * @var string
* @access private
*/
var $password_default_salt = 'phpseclib/salt';
- /**
- * The namespace used by the cipher for its constants.
- *
- * ie: AES.php is using CRYPT_AES_MODE_* for its constants
- * so $const_namespace is AES
- *
- * DES.php is using CRYPT_DES_MODE_* for its constants
- * so $const_namespace is DES... and so on
- *
- * All CRYPT_<$const_namespace>_MODE_* are aliases of
- * the generic CRYPT_MODE_* constants, so both could be used
- * for each cipher.
- *
- * Example:
- * $aes = new Crypt_AES(CRYPT_AES_MODE_CFB); // $aes will operate in cfb mode
- * $aes = new Crypt_AES(CRYPT_MODE_CFB); // identical
- *
- * @see Crypt_Base::Crypt_Base()
- * @var String
- * @access private
- */
- var $const_namespace;
-
/**
* The name of the performance-optimized callback function
*
* Used by encrypt() / decrypt()
- * only if $engine == CRYPT_MODE_INTERNAL
+ * only if $engine == self::ENGINE_INTERNAL
*
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::decrypt()
- * @see Crypt_Base::_setupInlineCrypt()
- * @see Crypt_Base::$use_inline_crypt
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @see self::_setupInlineCrypt()
+ * @see self::$use_inline_crypt
* @var Callback
* @access private
*/
@@ -411,14 +403,50 @@ class Crypt_Base
/**
* Holds whether performance-optimized $inline_crypt() can/should be used.
*
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::decrypt()
- * @see Crypt_Base::inline_crypt
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @see self::inline_crypt
* @var mixed
* @access private
*/
var $use_inline_crypt;
+ /**
+ * If OpenSSL can be used in ECB but not in CTR we can emulate CTR
+ *
+ * @see self::_openssl_ctr_process()
+ * @var bool
+ * @access private
+ */
+ var $openssl_emulate_ctr = false;
+
+ /**
+ * Determines what options are passed to openssl_encrypt/decrypt
+ *
+ * @see self::isValidEngine()
+ * @var mixed
+ * @access private
+ */
+ var $openssl_options;
+
+ /**
+ * Has the key length explicitly been set or should it be derived from the key, itself?
+ *
+ * @see self::setKeyLength()
+ * @var bool
+ * @access private
+ */
+ var $explicit_key_length = false;
+
+ /**
+ * Don't truncate / null pad key
+ *
+ * @see self::_clearBuffers()
+ * @var bool
+ * @access private
+ */
+ var $skip_key_adjustment = false;
+
/**
* Default Constructor.
*
@@ -426,69 +454,43 @@ class Crypt_Base
*
* $mode could be:
*
- * - CRYPT_MODE_ECB
+ * - self::MODE_ECB
*
- * - CRYPT_MODE_CBC
+ * - self::MODE_CBC
*
- * - CRYPT_MODE_CTR
+ * - self::MODE_CTR
*
- * - CRYPT_MODE_CFB
+ * - self::MODE_CFB
*
- * - CRYPT_MODE_OFB
+ * - self::MODE_OFB
*
- * (or the alias constants of the chosen cipher, for example for AES: CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC ...)
+ * If not explicitly set, self::MODE_CBC will be used.
*
- * If not explicitly set, CRYPT_MODE_CBC will be used.
- *
- * @param optional Integer $mode
+ * @param int $mode
* @access public
*/
- function Crypt_Base($mode = CRYPT_MODE_CBC)
+ function __construct($mode = self::MODE_CBC)
{
- $const_crypt_mode = 'CRYPT_' . $this->const_namespace . '_MODE';
-
- // Determining the availibility of mcrypt support for the cipher
- if (!defined($const_crypt_mode)) {
- switch (true) {
- case extension_loaded('mcrypt') && in_array($this->cipher_name_mcrypt, mcrypt_list_algorithms()):
- define($const_crypt_mode, CRYPT_MODE_MCRYPT);
- break;
- default:
- define($const_crypt_mode, CRYPT_MODE_INTERNAL);
- }
- }
-
- // Determining which internal $engine should be used.
- // The fastes possible first.
- switch (true) {
- case empty($this->cipher_name_mcrypt): // The cipher module has no mcrypt-engine support at all so we force CRYPT_MODE_INTERNAL
- $this->engine = CRYPT_MODE_INTERNAL;
- break;
- case constant($const_crypt_mode) == CRYPT_MODE_MCRYPT:
- $this->engine = CRYPT_MODE_MCRYPT;
- break;
- default:
- $this->engine = CRYPT_MODE_INTERNAL;
- }
-
// $mode dependent settings
switch ($mode) {
- case CRYPT_MODE_ECB:
+ case self::MODE_ECB:
$this->paddable = true;
+ $this->mode = self::MODE_ECB;
+ break;
+ case self::MODE_CTR:
+ case self::MODE_CFB:
+ case self::MODE_OFB:
+ case self::MODE_STREAM:
$this->mode = $mode;
break;
- case CRYPT_MODE_CTR:
- case CRYPT_MODE_CFB:
- case CRYPT_MODE_OFB:
- case CRYPT_MODE_STREAM:
- $this->mode = $mode;
- break;
- case CRYPT_MODE_CBC:
+ case self::MODE_CBC:
default:
$this->paddable = true;
- $this->mode = CRYPT_MODE_CBC;
+ $this->mode = self::MODE_CBC;
}
+ $this->_setEngine();
+
// Determining whether inline crypting can be used by the cipher
if ($this->use_inline_crypt !== false && function_exists('create_function')) {
$this->use_inline_crypt = true;
@@ -498,17 +500,16 @@ class Crypt_Base
/**
* Sets the initialization vector. (optional)
*
- * SetIV is not required when CRYPT_MODE_ECB (or ie for AES: CRYPT_AES_MODE_ECB) is being used. If not explicitly set, it'll be assumed
+ * SetIV is not required when self::MODE_ECB (or ie for AES: \phpseclib\Crypt\AES::MODE_ECB) is being used. If not explicitly set, it'll be assumed
* to be all zero's.
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
* @access public
- * @param String $iv
+ * @param string $iv
+ * @internal Can be overwritten by a sub class, but does not have to be
*/
function setIV($iv)
{
- if ($this->mode == CRYPT_MODE_ECB) {
+ if ($this->mode == self::MODE_ECB) {
return;
}
@@ -516,6 +517,43 @@ class Crypt_Base
$this->changed = true;
}
+ /**
+ * Sets the key length.
+ *
+ * Keys with explicitly set lengths need to be treated accordingly
+ *
+ * @access public
+ * @param int $length
+ */
+ function setKeyLength($length)
+ {
+ $this->explicit_key_length = true;
+ $this->changed = true;
+ $this->_setEngine();
+ }
+
+ /**
+ * Returns the current key length in bits
+ *
+ * @access public
+ * @return int
+ */
+ function getKeyLength()
+ {
+ return $this->key_length << 3;
+ }
+
+ /**
+ * Returns the current block length in bits
+ *
+ * @access public
+ * @return int
+ */
+ function getBlockLength()
+ {
+ return $this->block_size << 3;
+ }
+
/**
* Sets the key.
*
@@ -526,15 +564,20 @@ class Crypt_Base
*
* If the key is not explicitly set, it'll be assumed to be all null bytes.
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
* @access public
- * @param String $key
+ * @param string $key
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function setKey($key)
{
+ if (!$this->explicit_key_length) {
+ $this->setKeyLength(strlen($key) << 3);
+ $this->explicit_key_length = false;
+ }
+
$this->key = $key;
$this->changed = true;
+ $this->_setEngine();
}
/**
@@ -546,13 +589,12 @@ class Crypt_Base
*
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
* @see Crypt/Hash.php
- * @param String $password
- * @param optional String $method
- * @return Boolean
+ * @param string $password
+ * @param string $method
+ * @return bool
* @access public
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function setPassword($password, $method = 'pbkdf2')
{
@@ -576,15 +618,12 @@ class Crypt_Base
if (isset($func_args[5])) {
$dkLen = $func_args[5];
} else {
- $dkLen = $method == 'pbkdf1' ? 2 * $this->password_key_size : $this->password_key_size;
+ $dkLen = $method == 'pbkdf1' ? 2 * $this->key_length : $this->key_length;
}
switch (true) {
case $method == 'pbkdf1':
- if (!class_exists('Crypt_Hash')) {
- include_once 'Crypt/Hash.php';
- }
- $hashObj = new Crypt_Hash();
+ $hashObj = new Hash();
$hashObj->setHash($hash);
if ($dkLen > $hashObj->getLength()) {
user_error('Derived key too long');
@@ -604,12 +643,9 @@ class Crypt_Base
case !function_exists('hash_pbkdf2'):
case !function_exists('hash_algos'):
case !in_array($hash, hash_algos()):
- if (!class_exists('Crypt_Hash')) {
- include_once 'Crypt/Hash.php';
- }
$i = 1;
while (strlen($key) < $dkLen) {
- $hmac = new Crypt_Hash();
+ $hmac = new Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
@@ -645,29 +681,107 @@ class Crypt_Base
* strlen($plaintext) will still need to be a multiple of the block size, however, arbitrary values can be added to make it that
* length.
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
- * @see Crypt_Base::decrypt()
+ * @see self::decrypt()
* @access public
- * @param String $plaintext
- * @return String $cipertext
+ * @param string $plaintext
+ * @return string $ciphertext
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function encrypt($plaintext)
{
- if ($this->engine == CRYPT_MODE_MCRYPT) {
+ if ($this->paddable) {
+ $plaintext = $this->_pad($plaintext);
+ }
+
+ if ($this->engine === self::ENGINE_OPENSSL) {
+ if ($this->changed) {
+ $this->_clearBuffers();
+ $this->changed = false;
+ }
+ switch ($this->mode) {
+ case self::MODE_STREAM:
+ return openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options);
+ case self::MODE_ECB:
+ $result = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options);
+ return !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result;
+ case self::MODE_CBC:
+ $result = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->encryptIV);
+ if (!defined('OPENSSL_RAW_DATA')) {
+ $result = substr($result, 0, -$this->block_size);
+ }
+ if ($this->continuousBuffer) {
+ $this->encryptIV = substr($result, -$this->block_size);
+ }
+ return $result;
+ case self::MODE_CTR:
+ return $this->_openssl_ctr_process($plaintext, $this->encryptIV, $this->enbuffer);
+ case self::MODE_CFB:
+ // cfb loosely routines inspired by openssl's:
+ // {@link http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1}
+ $ciphertext = '';
+ if ($this->continuousBuffer) {
+ $iv = &$this->encryptIV;
+ $pos = &$this->enbuffer['pos'];
+ } else {
+ $iv = $this->encryptIV;
+ $pos = 0;
+ }
+ $len = strlen($plaintext);
+ $i = 0;
+ if ($pos) {
+ $orig_pos = $pos;
+ $max = $this->block_size - $pos;
+ if ($len >= $max) {
+ $i = $max;
+ $len-= $max;
+ $pos = 0;
+ } else {
+ $i = $len;
+ $pos+= $len;
+ $len = 0;
+ }
+ // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
+ $ciphertext = substr($iv, $orig_pos) ^ $plaintext;
+ $iv = substr_replace($iv, $ciphertext, $orig_pos, $i);
+ $plaintext = substr($plaintext, $i);
+ }
+
+ $overflow = $len % $this->block_size;
+
+ if ($overflow) {
+ $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
+ $iv = $this->_string_pop($ciphertext, $this->block_size);
+
+ $size = $len - $overflow;
+ $block = $iv ^ substr($plaintext, -$overflow);
+ $iv = substr_replace($iv, $block, 0, $overflow);
+ $ciphertext.= $block;
+ $pos = $overflow;
+ } elseif ($len) {
+ $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
+ $iv = substr($ciphertext, -$this->block_size);
+ }
+
+ return $ciphertext;
+ case self::MODE_OFB:
+ return $this->_openssl_ofb_process($plaintext, $this->encryptIV, $this->enbuffer);
+ }
+ }
+
+ if ($this->engine === self::ENGINE_MCRYPT) {
if ($this->changed) {
$this->_setupMcrypt();
$this->changed = false;
}
if ($this->enchanged) {
- mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
+ @mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
$this->enchanged = false;
}
// re: {@link http://phpseclib.sourceforge.net/cfb-demo.phps}
// using mcrypt's default handing of CFB the above would output two different things. using phpseclib's
// rewritten CFB implementation the above outputs the same thing twice.
- if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) {
+ if ($this->mode == self::MODE_CFB && $this->continuousBuffer) {
$block_size = $this->block_size;
$iv = &$this->encryptIV;
$pos = &$this->enbuffer['pos'];
@@ -693,15 +807,15 @@ class Crypt_Base
if ($len >= $block_size) {
if ($this->enbuffer['enmcrypt_init'] === false || $len > $this->cfb_init_len) {
if ($this->enbuffer['enmcrypt_init'] === true) {
- mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
+ @mcrypt_generic_init($this->enmcrypt, $this->key, $iv);
$this->enbuffer['enmcrypt_init'] = false;
}
- $ciphertext.= mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % $block_size));
+ $ciphertext.= @mcrypt_generic($this->enmcrypt, substr($plaintext, $i, $len - $len % $block_size));
$iv = substr($ciphertext, -$block_size);
$len%= $block_size;
} else {
while ($len >= $block_size) {
- $iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, $block_size);
+ $iv = @mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, $block_size);
$ciphertext.= $iv;
$len-= $block_size;
$i+= $block_size;
@@ -710,7 +824,7 @@ class Crypt_Base
}
if ($len) {
- $iv = mcrypt_generic($this->ecb, $iv);
+ $iv = @mcrypt_generic($this->ecb, $iv);
$block = $iv ^ substr($plaintext, -$len);
$iv = substr_replace($iv, $block, 0, $len);
$ciphertext.= $block;
@@ -720,14 +834,10 @@ class Crypt_Base
return $ciphertext;
}
- if ($this->paddable) {
- $plaintext = $this->_pad($plaintext);
- }
-
- $ciphertext = mcrypt_generic($this->enmcrypt, $plaintext);
+ $ciphertext = @mcrypt_generic($this->enmcrypt, $plaintext);
if (!$this->continuousBuffer) {
- mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
+ @mcrypt_generic_init($this->enmcrypt, $this->key, $this->encryptIV);
}
return $ciphertext;
@@ -741,20 +851,17 @@ class Crypt_Base
$inline = $this->inline_crypt;
return $inline('encrypt', $this, $plaintext);
}
- if ($this->paddable) {
- $plaintext = $this->_pad($plaintext);
- }
$buffer = &$this->enbuffer;
$block_size = $this->block_size;
$ciphertext = '';
switch ($this->mode) {
- case CRYPT_MODE_ECB:
+ case self::MODE_ECB:
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
$ciphertext.= $this->_encryptBlock(substr($plaintext, $i, $block_size));
}
break;
- case CRYPT_MODE_CBC:
+ case self::MODE_CBC:
$xor = $this->encryptIV;
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
$block = substr($plaintext, $i, $block_size);
@@ -766,32 +873,34 @@ class Crypt_Base
$this->encryptIV = $xor;
}
break;
- case CRYPT_MODE_CTR:
+ case self::MODE_CTR:
$xor = $this->encryptIV;
- if (strlen($buffer['encrypted'])) {
+ if (strlen($buffer['ciphertext'])) {
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
$block = substr($plaintext, $i, $block_size);
- if (strlen($block) > strlen($buffer['encrypted'])) {
- $buffer['encrypted'].= $this->_encryptBlock($this->_generateXor($xor, $block_size));
+ if (strlen($block) > strlen($buffer['ciphertext'])) {
+ $buffer['ciphertext'].= $this->_encryptBlock($xor);
}
- $key = $this->_stringShift($buffer['encrypted'], $block_size);
+ $this->_increment_str($xor);
+ $key = $this->_string_shift($buffer['ciphertext'], $block_size);
$ciphertext.= $block ^ $key;
}
} else {
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
$block = substr($plaintext, $i, $block_size);
- $key = $this->_encryptBlock($this->_generateXor($xor, $block_size));
+ $key = $this->_encryptBlock($xor);
+ $this->_increment_str($xor);
$ciphertext.= $block ^ $key;
}
}
if ($this->continuousBuffer) {
$this->encryptIV = $xor;
if ($start = strlen($plaintext) % $block_size) {
- $buffer['encrypted'] = substr($key, $start) . $buffer['encrypted'];
+ $buffer['ciphertext'] = substr($key, $start) . $buffer['ciphertext'];
}
}
break;
- case CRYPT_MODE_CFB:
+ case self::MODE_CFB:
// cfb loosely routines inspired by openssl's:
// {@link http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1}
if ($this->continuousBuffer) {
@@ -833,7 +942,7 @@ class Crypt_Base
$pos = $len;
}
break;
- case CRYPT_MODE_OFB:
+ case self::MODE_OFB:
$xor = $this->encryptIV;
if (strlen($buffer['xor'])) {
for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
@@ -842,7 +951,7 @@ class Crypt_Base
$xor = $this->_encryptBlock($xor);
$buffer['xor'].= $xor;
}
- $key = $this->_stringShift($buffer['xor'], $block_size);
+ $key = $this->_string_shift($buffer['xor'], $block_size);
$ciphertext.= $block ^ $key;
}
} else {
@@ -855,11 +964,11 @@ class Crypt_Base
if ($this->continuousBuffer) {
$this->encryptIV = $xor;
if ($start = strlen($plaintext) % $block_size) {
- $buffer['xor'] = substr($key, $start) . $buffer['xor'];
+ $buffer['xor'] = substr($key, $start) . $buffer['xor'];
}
}
break;
- case CRYPT_MODE_STREAM:
+ case self::MODE_STREAM:
$ciphertext = $this->_encryptBlock($plaintext);
break;
}
@@ -873,27 +982,115 @@ class Crypt_Base
* If strlen($ciphertext) is not a multiple of the block size, null bytes will be added to the end of the string until
* it is.
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
- * @see Crypt_Base::encrypt()
+ * @see self::encrypt()
* @access public
- * @param String $ciphertext
- * @return String $plaintext
+ * @param string $ciphertext
+ * @return string $plaintext
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function decrypt($ciphertext)
{
- if ($this->engine == CRYPT_MODE_MCRYPT) {
+ if ($this->paddable) {
+ // we pad with chr(0) since that's what mcrypt_generic does. to quote from {@link http://www.php.net/function.mcrypt-generic}:
+ // "The data is padded with "\0" to make sure the length of the data is n * blocksize."
+ $ciphertext = str_pad($ciphertext, strlen($ciphertext) + ($this->block_size - strlen($ciphertext) % $this->block_size) % $this->block_size, chr(0));
+ }
+
+ if ($this->engine === self::ENGINE_OPENSSL) {
+ if ($this->changed) {
+ $this->_clearBuffers();
+ $this->changed = false;
+ }
+ switch ($this->mode) {
+ case self::MODE_STREAM:
+ $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options);
+ break;
+ case self::MODE_ECB:
+ if (!defined('OPENSSL_RAW_DATA')) {
+ $ciphertext.= openssl_encrypt('', $this->cipher_name_openssl_ecb, $this->key, true);
+ }
+ $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options);
+ break;
+ case self::MODE_CBC:
+ if (!defined('OPENSSL_RAW_DATA')) {
+ $padding = str_repeat(chr($this->block_size), $this->block_size) ^ substr($ciphertext, -$this->block_size);
+ $ciphertext.= substr(openssl_encrypt($padding, $this->cipher_name_openssl_ecb, $this->key, true), 0, $this->block_size);
+ $offset = 2 * $this->block_size;
+ } else {
+ $offset = $this->block_size;
+ }
+ $plaintext = openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $this->decryptIV);
+ if ($this->continuousBuffer) {
+ $this->decryptIV = substr($ciphertext, -$offset, $this->block_size);
+ }
+ break;
+ case self::MODE_CTR:
+ $plaintext = $this->_openssl_ctr_process($ciphertext, $this->decryptIV, $this->debuffer);
+ break;
+ case self::MODE_CFB:
+ // cfb loosely routines inspired by openssl's:
+ // {@link http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1}
+ $plaintext = '';
+ if ($this->continuousBuffer) {
+ $iv = &$this->decryptIV;
+ $pos = &$this->buffer['pos'];
+ } else {
+ $iv = $this->decryptIV;
+ $pos = 0;
+ }
+ $len = strlen($ciphertext);
+ $i = 0;
+ if ($pos) {
+ $orig_pos = $pos;
+ $max = $this->block_size - $pos;
+ if ($len >= $max) {
+ $i = $max;
+ $len-= $max;
+ $pos = 0;
+ } else {
+ $i = $len;
+ $pos+= $len;
+ $len = 0;
+ }
+ // ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $this->blocksize
+ $plaintext = substr($iv, $orig_pos) ^ $ciphertext;
+ $iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
+ $ciphertext = substr($ciphertext, $i);
+ }
+ $overflow = $len % $this->block_size;
+ if ($overflow) {
+ $plaintext.= openssl_decrypt(substr($ciphertext, 0, -$overflow), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
+ if ($len - $overflow) {
+ $iv = substr($ciphertext, -$overflow - $this->block_size, -$overflow);
+ }
+ $iv = openssl_encrypt(str_repeat("\0", $this->block_size), $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
+ $plaintext.= $iv ^ substr($ciphertext, -$overflow);
+ $iv = substr_replace($iv, substr($ciphertext, -$overflow), 0, $overflow);
+ $pos = $overflow;
+ } elseif ($len) {
+ $plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
+ $iv = substr($ciphertext, -$this->block_size);
+ }
+ break;
+ case self::MODE_OFB:
+ $plaintext = $this->_openssl_ofb_process($ciphertext, $this->decryptIV, $this->debuffer);
+ }
+
+ return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
+ }
+
+ if ($this->engine === self::ENGINE_MCRYPT) {
$block_size = $this->block_size;
if ($this->changed) {
$this->_setupMcrypt();
$this->changed = false;
}
if ($this->dechanged) {
- mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
+ @mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
$this->dechanged = false;
}
- if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) {
+ if ($this->mode == self::MODE_CFB && $this->continuousBuffer) {
$iv = &$this->decryptIV;
$pos = &$this->debuffer['pos'];
$len = strlen($ciphertext);
@@ -917,12 +1114,12 @@ class Crypt_Base
}
if ($len >= $block_size) {
$cb = substr($ciphertext, $i, $len - $len % $block_size);
- $plaintext.= mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
+ $plaintext.= @mcrypt_generic($this->ecb, $iv . $cb) ^ $cb;
$iv = substr($cb, -$block_size);
$len%= $block_size;
}
if ($len) {
- $iv = mcrypt_generic($this->ecb, $iv);
+ $iv = @mcrypt_generic($this->ecb, $iv);
$plaintext.= $iv ^ substr($ciphertext, -$len);
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
$pos = $len;
@@ -931,16 +1128,10 @@ class Crypt_Base
return $plaintext;
}
- if ($this->paddable) {
- // we pad with chr(0) since that's what mcrypt_generic does. to quote from {@link http://www.php.net/function.mcrypt-generic}:
- // "The data is padded with "\0" to make sure the length of the data is n * blocksize."
- $ciphertext = str_pad($ciphertext, strlen($ciphertext) + ($block_size - strlen($ciphertext) % $block_size) % $block_size, chr(0));
- }
-
- $plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);
+ $plaintext = @mdecrypt_generic($this->demcrypt, $ciphertext);
if (!$this->continuousBuffer) {
- mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
+ @mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
}
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
@@ -956,20 +1147,16 @@ class Crypt_Base
}
$block_size = $this->block_size;
- if ($this->paddable) {
- // we pad with chr(0) since that's what mcrypt_generic does [...]
- $ciphertext = str_pad($ciphertext, strlen($ciphertext) + ($block_size - strlen($ciphertext) % $block_size) % $block_size, chr(0));
- }
$buffer = &$this->debuffer;
$plaintext = '';
switch ($this->mode) {
- case CRYPT_MODE_ECB:
+ case self::MODE_ECB:
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
$plaintext.= $this->_decryptBlock(substr($ciphertext, $i, $block_size));
}
break;
- case CRYPT_MODE_CBC:
+ case self::MODE_CBC:
$xor = $this->decryptIV;
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
$block = substr($ciphertext, $i, $block_size);
@@ -980,21 +1167,23 @@ class Crypt_Base
$this->decryptIV = $xor;
}
break;
- case CRYPT_MODE_CTR:
+ case self::MODE_CTR:
$xor = $this->decryptIV;
if (strlen($buffer['ciphertext'])) {
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
$block = substr($ciphertext, $i, $block_size);
if (strlen($block) > strlen($buffer['ciphertext'])) {
- $buffer['ciphertext'].= $this->_encryptBlock($this->_generateXor($xor, $block_size));
+ $buffer['ciphertext'].= $this->_encryptBlock($xor);
+ $this->_increment_str($xor);
}
- $key = $this->_stringShift($buffer['ciphertext'], $block_size);
+ $key = $this->_string_shift($buffer['ciphertext'], $block_size);
$plaintext.= $block ^ $key;
}
} else {
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
$block = substr($ciphertext, $i, $block_size);
- $key = $this->_encryptBlock($this->_generateXor($xor, $block_size));
+ $key = $this->_encryptBlock($xor);
+ $this->_increment_str($xor);
$plaintext.= $block ^ $key;
}
}
@@ -1005,7 +1194,7 @@ class Crypt_Base
}
}
break;
- case CRYPT_MODE_CFB:
+ case self::MODE_CFB:
if ($this->continuousBuffer) {
$iv = &$this->decryptIV;
$pos = &$buffer['pos'];
@@ -1046,7 +1235,7 @@ class Crypt_Base
$pos = $len;
}
break;
- case CRYPT_MODE_OFB:
+ case self::MODE_OFB:
$xor = $this->decryptIV;
if (strlen($buffer['xor'])) {
for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
@@ -1055,7 +1244,7 @@ class Crypt_Base
$xor = $this->_encryptBlock($xor);
$buffer['xor'].= $xor;
}
- $key = $this->_stringShift($buffer['xor'], $block_size);
+ $key = $this->_string_shift($buffer['xor'], $block_size);
$plaintext.= $block ^ $key;
}
} else {
@@ -1068,17 +1257,189 @@ class Crypt_Base
if ($this->continuousBuffer) {
$this->decryptIV = $xor;
if ($start = strlen($ciphertext) % $block_size) {
- $buffer['xor'] = substr($key, $start) . $buffer['xor'];
+ $buffer['xor'] = substr($key, $start) . $buffer['xor'];
}
}
break;
- case CRYPT_MODE_STREAM:
+ case self::MODE_STREAM:
$plaintext = $this->_decryptBlock($ciphertext);
break;
}
return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
}
+ /**
+ * OpenSSL CTR Processor
+ *
+ * PHP's OpenSSL bindings do not operate in continuous mode so we'll wrap around it. Since the keystream
+ * for CTR is the same for both encrypting and decrypting this function is re-used by both Base::encrypt()
+ * and Base::decrypt(). Also, OpenSSL doesn't implement CTR for all of it's symmetric ciphers so this
+ * function will emulate CTR with ECB when necessary.
+ *
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @param string $plaintext
+ * @param string $encryptIV
+ * @param array $buffer
+ * @return string
+ * @access private
+ */
+ function _openssl_ctr_process($plaintext, &$encryptIV, &$buffer)
+ {
+ $ciphertext = '';
+
+ $block_size = $this->block_size;
+ $key = $this->key;
+
+ if ($this->openssl_emulate_ctr) {
+ $xor = $encryptIV;
+ if (strlen($buffer['ciphertext'])) {
+ for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
+ $block = substr($plaintext, $i, $block_size);
+ if (strlen($block) > strlen($buffer['ciphertext'])) {
+ $result = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, $this->openssl_options);
+ $result = !defined('OPENSSL_RAW_DATA') ? substr($result, 0, -$this->block_size) : $result;
+ $buffer['ciphertext'].= $result;
+ }
+ $this->_increment_str($xor);
+ $otp = $this->_string_shift($buffer['ciphertext'], $block_size);
+ $ciphertext.= $block ^ $otp;
+ }
+ } else {
+ for ($i = 0; $i < strlen($plaintext); $i+=$block_size) {
+ $block = substr($plaintext, $i, $block_size);
+ $otp = openssl_encrypt($xor, $this->cipher_name_openssl_ecb, $key, $this->openssl_options);
+ $otp = !defined('OPENSSL_RAW_DATA') ? substr($otp, 0, -$this->block_size) : $otp;
+ $this->_increment_str($xor);
+ $ciphertext.= $block ^ $otp;
+ }
+ }
+ if ($this->continuousBuffer) {
+ $encryptIV = $xor;
+ if ($start = strlen($plaintext) % $block_size) {
+ $buffer['ciphertext'] = substr($key, $start) . $buffer['ciphertext'];
+ }
+ }
+
+ return $ciphertext;
+ }
+
+ if (strlen($buffer['ciphertext'])) {
+ $ciphertext = $plaintext ^ $this->_string_shift($buffer['ciphertext'], strlen($plaintext));
+ $plaintext = substr($plaintext, strlen($ciphertext));
+
+ if (!strlen($plaintext)) {
+ return $ciphertext;
+ }
+ }
+
+ $overflow = strlen($plaintext) % $block_size;
+ if ($overflow) {
+ $plaintext2 = $this->_string_pop($plaintext, $overflow); // ie. trim $plaintext to a multiple of $block_size and put rest of $plaintext in $plaintext2
+ $encrypted = openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
+ $temp = $this->_string_pop($encrypted, $block_size);
+ $ciphertext.= $encrypted . ($plaintext2 ^ $temp);
+ if ($this->continuousBuffer) {
+ $buffer['ciphertext'] = substr($temp, $overflow);
+ $encryptIV = $temp;
+ }
+ } elseif (!strlen($buffer['ciphertext'])) {
+ $ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
+ $temp = $this->_string_pop($ciphertext, $block_size);
+ if ($this->continuousBuffer) {
+ $encryptIV = $temp;
+ }
+ }
+ if ($this->continuousBuffer) {
+ if (!defined('OPENSSL_RAW_DATA')) {
+ $encryptIV.= openssl_encrypt('', $this->cipher_name_openssl_ecb, $key, $this->openssl_options);
+ }
+ $encryptIV = openssl_decrypt($encryptIV, $this->cipher_name_openssl_ecb, $key, $this->openssl_options);
+ if ($overflow) {
+ $this->_increment_str($encryptIV);
+ }
+ }
+
+ return $ciphertext;
+ }
+
+ /**
+ * OpenSSL OFB Processor
+ *
+ * PHP's OpenSSL bindings do not operate in continuous mode so we'll wrap around it. Since the keystream
+ * for OFB is the same for both encrypting and decrypting this function is re-used by both Base::encrypt()
+ * and Base::decrypt().
+ *
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @param string $plaintext
+ * @param string $encryptIV
+ * @param array $buffer
+ * @return string
+ * @access private
+ */
+ function _openssl_ofb_process($plaintext, &$encryptIV, &$buffer)
+ {
+ if (strlen($buffer['xor'])) {
+ $ciphertext = $plaintext ^ $buffer['xor'];
+ $buffer['xor'] = substr($buffer['xor'], strlen($ciphertext));
+ $plaintext = substr($plaintext, strlen($ciphertext));
+ } else {
+ $ciphertext = '';
+ }
+
+ $block_size = $this->block_size;
+
+ $len = strlen($plaintext);
+ $key = $this->key;
+ $overflow = $len % $block_size;
+
+ if (strlen($plaintext)) {
+ if ($overflow) {
+ $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
+ $xor = $this->_string_pop($ciphertext, $block_size);
+ if ($this->continuousBuffer) {
+ $encryptIV = $xor;
+ }
+ $ciphertext.= $this->_string_shift($xor, $overflow) ^ substr($plaintext, -$overflow);
+ if ($this->continuousBuffer) {
+ $buffer['xor'] = $xor;
+ }
+ } else {
+ $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
+ if ($this->continuousBuffer) {
+ $encryptIV = substr($ciphertext, -$block_size) ^ substr($plaintext, -$block_size);
+ }
+ }
+ }
+
+ return $ciphertext;
+ }
+
+ /**
+ * phpseclib <-> OpenSSL Mode Mapper
+ *
+ * May need to be overwritten by classes extending this one in some cases
+ *
+ * @return int
+ * @access private
+ */
+ function _openssl_translate_mode()
+ {
+ switch ($this->mode) {
+ case self::MODE_ECB:
+ return 'ecb';
+ case self::MODE_CBC:
+ return 'cbc';
+ case self::MODE_CTR:
+ return 'ctr';
+ case self::MODE_CFB:
+ return 'cfb';
+ case self::MODE_OFB:
+ return 'ofb';
+ }
+ }
+
/**
* Pad "packets".
*
@@ -1091,7 +1452,7 @@ class Crypt_Base
* away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is
* transmitted separately)
*
- * @see Crypt_Base::disablePadding()
+ * @see self::disablePadding()
* @access public
*/
function enablePadding()
@@ -1102,7 +1463,7 @@ class Crypt_Base
/**
* Do not pad packets.
*
- * @see Crypt_Base::enablePadding()
+ * @see self::enablePadding()
* @access public
*/
function disablePadding()
@@ -1139,23 +1500,24 @@ class Crypt_Base
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
*
- * Put another way, when the continuous buffer is enabled, the state of the Crypt_*() object changes after each
+ * Put another way, when the continuous buffer is enabled, the state of the \phpseclib\Crypt\*() object changes after each
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
* however, they are also less intuitive and more likely to cause you problems.
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
- * @see Crypt_Base::disableContinuousBuffer()
+ * @see self::disableContinuousBuffer()
* @access public
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function enableContinuousBuffer()
{
- if ($this->mode == CRYPT_MODE_ECB) {
+ if ($this->mode == self::MODE_ECB) {
return;
}
$this->continuousBuffer = true;
+
+ $this->_setEngine();
}
/**
@@ -1163,14 +1525,13 @@ class Crypt_Base
*
* The default behavior.
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
- * @see Crypt_Base::enableContinuousBuffer()
+ * @see self::enableContinuousBuffer()
* @access public
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function disableContinuousBuffer()
{
- if ($this->mode == CRYPT_MODE_ECB) {
+ if ($this->mode == self::MODE_ECB) {
return;
}
if (!$this->continuousBuffer) {
@@ -1179,56 +1540,191 @@ class Crypt_Base
$this->continuousBuffer = false;
$this->changed = true;
+
+ $this->_setEngine();
+ }
+
+ /**
+ * Test for engine validity
+ *
+ * @see self::__construct()
+ * @param int $engine
+ * @access public
+ * @return bool
+ */
+ function isValidEngine($engine)
+ {
+ switch ($engine) {
+ case self::ENGINE_OPENSSL:
+ if ($this->mode == self::MODE_STREAM && $this->continuousBuffer) {
+ return false;
+ }
+ $this->openssl_emulate_ctr = false;
+ $result = $this->cipher_name_openssl &&
+ extension_loaded('openssl') &&
+ // PHP 5.3.0 - 5.3.2 did not let you set IV's
+ version_compare(PHP_VERSION, '5.3.3', '>=');
+ if (!$result) {
+ return false;
+ }
+
+ // prior to PHP 5.4.0 OPENSSL_RAW_DATA and OPENSSL_ZERO_PADDING were not defined. instead of expecting an integer
+ // $options openssl_encrypt expected a boolean $raw_data.
+ if (!defined('OPENSSL_RAW_DATA')) {
+ $this->openssl_options = true;
+ } else {
+ $this->openssl_options = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING;
+ }
+
+ $methods = openssl_get_cipher_methods();
+ if (in_array($this->cipher_name_openssl, $methods)) {
+ return true;
+ }
+ // not all of openssl's symmetric cipher's support ctr. for those
+ // that don't we'll emulate it
+ switch ($this->mode) {
+ case self::MODE_CTR:
+ if (in_array($this->cipher_name_openssl_ecb, $methods)) {
+ $this->openssl_emulate_ctr = true;
+ return true;
+ }
+ }
+ return false;
+ case self::ENGINE_MCRYPT:
+ return $this->cipher_name_mcrypt &&
+ extension_loaded('mcrypt') &&
+ in_array($this->cipher_name_mcrypt, @mcrypt_list_algorithms());
+ case self::ENGINE_INTERNAL:
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Sets the preferred crypt engine
+ *
+ * Currently, $engine could be:
+ *
+ * - \phpseclib\Crypt\Base::ENGINE_OPENSSL [very fast]
+ *
+ * - \phpseclib\Crypt\Base::ENGINE_MCRYPT [fast]
+ *
+ * - \phpseclib\Crypt\Base::ENGINE_INTERNAL [slow]
+ *
+ * If the preferred crypt engine is not available the fastest available one will be used
+ *
+ * @see self::__construct()
+ * @param int $engine
+ * @access public
+ */
+ function setPreferredEngine($engine)
+ {
+ switch ($engine) {
+ //case self::ENGINE_OPENSSL;
+ case self::ENGINE_MCRYPT:
+ case self::ENGINE_INTERNAL:
+ $this->preferredEngine = $engine;
+ break;
+ default:
+ $this->preferredEngine = self::ENGINE_OPENSSL;
+ }
+
+ $this->_setEngine();
+ }
+
+ /**
+ * Returns the engine currently being utilized
+ *
+ * @see self::_setEngine()
+ * @access public
+ */
+ function getEngine()
+ {
+ return $this->engine;
+ }
+
+ /**
+ * Sets the engine as appropriate
+ *
+ * @see self::__construct()
+ * @access private
+ */
+ function _setEngine()
+ {
+ $this->engine = null;
+
+ $candidateEngines = array(
+ $this->preferredEngine,
+ self::ENGINE_OPENSSL,
+ self::ENGINE_MCRYPT
+ );
+ foreach ($candidateEngines as $engine) {
+ if ($this->isValidEngine($engine)) {
+ $this->engine = $engine;
+ break;
+ }
+ }
+ if (!$this->engine) {
+ $this->engine = self::ENGINE_INTERNAL;
+ }
+
+ if ($this->engine != self::ENGINE_MCRYPT && $this->enmcrypt) {
+ // Closing the current mcrypt resource(s). _mcryptSetup() will, if needed,
+ // (re)open them with the module named in $this->cipher_name_mcrypt
+ @mcrypt_module_close($this->enmcrypt);
+ @mcrypt_module_close($this->demcrypt);
+ $this->enmcrypt = null;
+ $this->demcrypt = null;
+
+ if ($this->ecb) {
+ @mcrypt_module_close($this->ecb);
+ $this->ecb = null;
+ }
+ }
+
+ $this->changed = true;
}
/**
* Encrypts a block
*
- * Note: Must extend by the child Crypt_* class
+ * Note: Must be extended by the child \phpseclib\Crypt\* class
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
- function _encryptBlock($in)
- {
- user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
- }
+ abstract function _encryptBlock($in);
/**
* Decrypts a block
*
- * Note: Must extend by the child Crypt_* class
+ * Note: Must be extended by the child \phpseclib\Crypt\* class
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
- function _decryptBlock($in)
- {
- user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
- }
+ abstract function _decryptBlock($in);
/**
* Setup the key (expansion)
*
- * Only used if $engine == CRYPT_MODE_INTERNAL
+ * Only used if $engine == self::ENGINE_INTERNAL
*
- * Note: Must extend by the child Crypt_* class
+ * Note: Must extend by the child \phpseclib\Crypt\* class
*
- * @see Crypt_Base::_setup()
+ * @see self::_setup()
* @access private
*/
- function _setupKey()
- {
- user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
- }
+ abstract function _setupKey();
/**
- * Setup the CRYPT_MODE_INTERNAL $engine
+ * Setup the self::ENGINE_INTERNAL $engine
*
* (re)init, if necessary, the internal cipher $engine and flush all $buffers
- * Used (only) if $engine == CRYPT_MODE_INTERNAL
+ * Used (only) if $engine == self::ENGINE_INTERNAL
*
* _setup() will be called each time if $changed === true
* typically this happens when using one or more of following public methods:
@@ -1241,14 +1737,12 @@ class Crypt_Base
*
* - First run of encrypt() / decrypt() with no init-settings
*
- * Internally: _setup() is called always before(!) en/decryption.
- *
- * Note: Could, but not must, extend by the child Crypt_* class
- *
- * @see setKey()
- * @see setIV()
- * @see disableContinuousBuffer()
+ * @see self::setKey()
+ * @see self::setIV()
+ * @see self::disableContinuousBuffer()
* @access private
+ * @internal _setup() is always called before en/decryption.
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function _setup()
{
@@ -1261,10 +1755,10 @@ class Crypt_Base
}
/**
- * Setup the CRYPT_MODE_MCRYPT $engine
+ * Setup the self::ENGINE_MCRYPT $engine
*
* (re)init, if necessary, the (ext)mcrypt resources and flush all $buffers
- * Used (only) if $engine = CRYPT_MODE_MCRYPT
+ * Used (only) if $engine = self::ENGINE_MCRYPT
*
* _setupMcrypt() will be called each time if $changed === true
* typically this happens when using one or more of following public methods:
@@ -1277,13 +1771,11 @@ class Crypt_Base
*
* - First run of encrypt() / decrypt()
*
- *
- * Note: Could, but not must, extend by the child Crypt_* class
- *
- * @see setKey()
- * @see setIV()
- * @see disableContinuousBuffer()
+ * @see self::setKey()
+ * @see self::setIV()
+ * @see self::disableContinuousBuffer()
* @access private
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function _setupMcrypt()
{
@@ -1292,28 +1784,27 @@ class Crypt_Base
if (!isset($this->enmcrypt)) {
static $mcrypt_modes = array(
- CRYPT_MODE_CTR => 'ctr',
- CRYPT_MODE_ECB => MCRYPT_MODE_ECB,
- CRYPT_MODE_CBC => MCRYPT_MODE_CBC,
- CRYPT_MODE_CFB => 'ncfb',
- CRYPT_MODE_OFB => MCRYPT_MODE_NOFB,
- CRYPT_MODE_STREAM => MCRYPT_MODE_STREAM,
+ self::MODE_CTR => 'ctr',
+ self::MODE_ECB => MCRYPT_MODE_ECB,
+ self::MODE_CBC => MCRYPT_MODE_CBC,
+ self::MODE_CFB => 'ncfb',
+ self::MODE_OFB => MCRYPT_MODE_NOFB,
+ self::MODE_STREAM => MCRYPT_MODE_STREAM,
);
- $this->demcrypt = mcrypt_module_open($this->cipher_name_mcrypt, '', $mcrypt_modes[$this->mode], '');
- $this->enmcrypt = mcrypt_module_open($this->cipher_name_mcrypt, '', $mcrypt_modes[$this->mode], '');
+ $this->demcrypt = @mcrypt_module_open($this->cipher_name_mcrypt, '', $mcrypt_modes[$this->mode], '');
+ $this->enmcrypt = @mcrypt_module_open($this->cipher_name_mcrypt, '', $mcrypt_modes[$this->mode], '');
// we need the $ecb mcrypt resource (only) in MODE_CFB with enableContinuousBuffer()
// to workaround mcrypt's broken ncfb implementation in buffered mode
// see: {@link http://phpseclib.sourceforge.net/cfb-demo.phps}
- if ($this->mode == CRYPT_MODE_CFB) {
- $this->ecb = mcrypt_module_open($this->cipher_name_mcrypt, '', MCRYPT_MODE_ECB, '');
+ if ($this->mode == self::MODE_CFB) {
+ $this->ecb = @mcrypt_module_open($this->cipher_name_mcrypt, '', MCRYPT_MODE_ECB, '');
}
-
} // else should mcrypt_generic_deinit be called?
- if ($this->mode == CRYPT_MODE_CFB) {
- mcrypt_generic_init($this->ecb, $this->key, str_repeat("\0", $this->block_size));
+ if ($this->mode == self::MODE_CFB) {
+ @mcrypt_generic_init($this->ecb, $this->key, str_repeat("\0", $this->block_size));
}
}
@@ -1327,10 +1818,10 @@ class Crypt_Base
* If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless
* and padding will, hence forth, be enabled.
*
- * @see Crypt_Base::_unpad()
- * @param String $text
+ * @see self::_unpad()
+ * @param string $text
* @access private
- * @return String
+ * @return string
*/
function _pad($text)
{
@@ -1356,10 +1847,10 @@ class Crypt_Base
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong
* and false will be returned.
*
- * @see Crypt_Base::_pad()
- * @param String $text
+ * @see self::_pad()
+ * @param string $text
* @access private
- * @return String
+ * @return string
*/
function _unpad($text)
{
@@ -1383,18 +1874,20 @@ class Crypt_Base
* after disableContinuousBuffer() or on cipher $engine (re)init
* ie after setKey() or setIV()
*
- * Note: Could, but not must, extend by the child Crypt_* class
- *
* @access public
+ * @internal Could, but not must, extend by the child Crypt_* class
*/
function _clearBuffers()
{
- $this->enbuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
- $this->debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
+ $this->enbuffer = $this->debuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
// mcrypt's handling of invalid's $iv:
// $this->encryptIV = $this->decryptIV = strlen($this->iv) == $this->block_size ? $this->iv : str_repeat("\0", $this->block_size);
$this->encryptIV = $this->decryptIV = str_pad(substr($this->iv, 0, $this->block_size), $this->block_size, "\0");
+
+ if (!$this->skip_key_adjustment) {
+ $this->key = str_pad(substr($this->key, 0, $this->key_length), $this->key_length, "\0");
+ }
}
/**
@@ -1402,12 +1895,12 @@ class Crypt_Base
*
* Inspired by array_shift
*
- * @param String $string
- * @param optional Integer $index
+ * @param string $string
+ * @param int $index
* @access private
- * @return String
+ * @return string
*/
- function _stringShift(&$string, $index = 1)
+ function _string_shift(&$string, $index = 1)
{
$substr = substr($string, 0, $index);
$string = substr($string, $index);
@@ -1415,43 +1908,57 @@ class Crypt_Base
}
/**
- * Generate CTR XOR encryption key
+ * String Pop
*
- * Encrypt the output of this and XOR it against the ciphertext / plaintext to get the
- * plaintext / ciphertext in CTR mode.
+ * Inspired by array_pop
*
- * @see Crypt_Base::decrypt()
- * @see Crypt_Base::encrypt()
- * @param String $iv
- * @param Integer $length
+ * @param string $string
+ * @param int $index
* @access private
- * @return String $xor
+ * @return string
*/
- function _generateXor(&$iv, $length)
+ function _string_pop(&$string, $index = 1)
{
- $xor = '';
- $block_size = $this->block_size;
- $num_blocks = floor(($length + ($block_size - 1)) / $block_size);
- for ($i = 0; $i < $num_blocks; $i++) {
- $xor.= $iv;
- for ($j = 4; $j <= $block_size; $j+= 4) {
- $temp = substr($iv, -$j, 4);
- switch ($temp) {
- case "\xFF\xFF\xFF\xFF":
- $iv = substr_replace($iv, "\x00\x00\x00\x00", -$j, 4);
- break;
- case "\x7F\xFF\xFF\xFF":
- $iv = substr_replace($iv, "\x80\x00\x00\x00", -$j, 4);
- break 2;
- default:
- extract(unpack('Ncount', $temp));
- $iv = substr_replace($iv, pack('N', $count + 1), -$j, 4);
- break 2;
- }
+ $substr = substr($string, -$index);
+ $string = substr($string, 0, -$index);
+ return $substr;
+ }
+
+ /**
+ * Increment the current string
+ *
+ * @see self::decrypt()
+ * @see self::encrypt()
+ * @param string $var
+ * @access private
+ */
+ function _increment_str(&$var)
+ {
+ for ($i = 4; $i <= strlen($var); $i+= 4) {
+ $temp = substr($var, -$i, 4);
+ switch ($temp) {
+ case "\xFF\xFF\xFF\xFF":
+ $var = substr_replace($var, "\x00\x00\x00\x00", -$i, 4);
+ break;
+ case "\x7F\xFF\xFF\xFF":
+ $var = substr_replace($var, "\x80\x00\x00\x00", -$i, 4);
+ return;
+ default:
+ $temp = unpack('Nnum', $temp);
+ $var = substr_replace($var, pack('N', $temp['num'] + 1), -$i, 4);
+ return;
}
}
- return $xor;
+ $remainder = strlen($var) % 4;
+
+ if ($remainder == 0) {
+ return;
+ }
+
+ $temp = unpack('Nnum', str_pad(substr($var, 0, $remainder), 4, "\0", STR_PAD_LEFT));
+ $temp = substr(pack('N', $temp['num'] + 1), -$remainder);
+ $var = substr_replace($var, $temp, 0, $remainder);
}
/**
@@ -1464,7 +1971,7 @@ class Crypt_Base
*
* _setupInlineCrypt() would be called only if:
*
- * - $engine == CRYPT_MODE_INTERNAL and
+ * - $engine == self::ENGINE_INTERNAL and
*
* - $use_inline_crypt === true
*
@@ -1499,7 +2006,7 @@ class Crypt_Base
* - short (as good as possible)
*
* Note: - _setupInlineCrypt() is using _createInlineCryptFunction() to create the full callback function code.
- * - In case of using inline crypting, _setupInlineCrypt() must extend by the child Crypt_* class.
+ * - In case of using inline crypting, _setupInlineCrypt() must extend by the child \phpseclib\Crypt\* class.
* - The following variable names are reserved:
* - $_* (all variable names prefixed with an underscore)
* - $self (object reference to it self. Do not use $this, but $self instead)
@@ -1507,19 +2014,18 @@ class Crypt_Base
* - The callback function should not use the 'return' statement, but en/decrypt'ing the content of $in only
*
*
- * @see Crypt_Base::_setup()
- * @see Crypt_Base::_createInlineCryptFunction()
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::decrypt()
+ * @see self::_setup()
+ * @see self::_createInlineCryptFunction()
+ * @see self::encrypt()
+ * @see self::decrypt()
* @access private
+ * @internal If a Crypt_* class providing inline crypting it must extend _setupInlineCrypt()
*/
function _setupInlineCrypt()
{
- // If a Crypt_* class providing inline crypting it must extend _setupInlineCrypt()
-
- // If, for any reason, an extending Crypt_Base() Crypt_* class
+ // If, for any reason, an extending \phpseclib\Crypt\Base() \phpseclib\Crypt\* class
// not using inline crypting then it must be ensured that: $this->use_inline_crypt = false
- // ie in the class var declaration of $use_inline_crypt in general for the Crypt_* class,
+ // ie in the class var declaration of $use_inline_crypt in general for the \phpseclib\Crypt\* class,
// in the constructor at object instance-time
// or, if it's runtime-specific, at runtime
@@ -1616,7 +2122,7 @@ class Crypt_Base
* +----------------------------------------------------------------------------------------------+
*
*
- * See also the Crypt_*::_setupInlineCrypt()'s for
+ * See also the \phpseclib\Crypt\*::_setupInlineCrypt()'s for
* productive inline $cipher_code's how they works.
*
* Structure of:
@@ -1630,12 +2136,12 @@ class Crypt_Base
* );
*
*
- * @see Crypt_Base::_setupInlineCrypt()
- * @see Crypt_Base::encrypt()
- * @see Crypt_Base::decrypt()
- * @param Array $cipher_code
+ * @see self::_setupInlineCrypt()
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @param array $cipher_code
* @access private
- * @return String (the name of the created callback function)
+ * @return string (the name of the created callback function)
*/
function _createInlineCryptFunction($cipher_code)
{
@@ -1653,10 +2159,9 @@ class Crypt_Base
// merged with the $cipher_code algorithm
// for encrypt- and decryption.
switch ($this->mode) {
- case CRYPT_MODE_ECB:
+ case self::MODE_ECB:
$encrypt = $init_encrypt . '
$_ciphertext = "";
- $_text = $self->_pad($_text);
$_plaintext_len = strlen($_text);
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
@@ -1682,29 +2187,30 @@ class Crypt_Base
return $self->_unpad($_plaintext);
';
break;
- case CRYPT_MODE_CTR:
+ case self::MODE_CTR:
$encrypt = $init_encrypt . '
$_ciphertext = "";
$_plaintext_len = strlen($_text);
$_xor = $self->encryptIV;
$_buffer = &$self->enbuffer;
-
- if (strlen($_buffer["encrypted"])) {
+ if (strlen($_buffer["ciphertext"])) {
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
$_block = substr($_text, $_i, '.$block_size.');
- if (strlen($_block) > strlen($_buffer["encrypted"])) {
- $in = $self->_generateXor($_xor, '.$block_size.');
+ if (strlen($_block) > strlen($_buffer["ciphertext"])) {
+ $in = $_xor;
'.$encrypt_block.'
- $_buffer["encrypted"].= $in;
+ $self->_increment_str($_xor);
+ $_buffer["ciphertext"].= $in;
}
- $_key = $self->_stringShift($_buffer["encrypted"], '.$block_size.');
+ $_key = $self->_string_shift($_buffer["ciphertext"], '.$block_size.');
$_ciphertext.= $_block ^ $_key;
}
} else {
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
$_block = substr($_text, $_i, '.$block_size.');
- $in = $self->_generateXor($_xor, '.$block_size.');
+ $in = $_xor;
'.$encrypt_block.'
+ $self->_increment_str($_xor);
$_key = $in;
$_ciphertext.= $_block ^ $_key;
}
@@ -1712,7 +2218,7 @@ class Crypt_Base
if ($self->continuousBuffer) {
$self->encryptIV = $_xor;
if ($_start = $_plaintext_len % '.$block_size.') {
- $_buffer["encrypted"] = substr($_key, $_start) . $_buffer["encrypted"];
+ $_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"];
}
}
@@ -1729,18 +2235,20 @@ class Crypt_Base
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
$_block = substr($_text, $_i, '.$block_size.');
if (strlen($_block) > strlen($_buffer["ciphertext"])) {
- $in = $self->_generateXor($_xor, '.$block_size.');
+ $in = $_xor;
'.$encrypt_block.'
+ $self->_increment_str($_xor);
$_buffer["ciphertext"].= $in;
}
- $_key = $self->_stringShift($_buffer["ciphertext"], '.$block_size.');
+ $_key = $self->_string_shift($_buffer["ciphertext"], '.$block_size.');
$_plaintext.= $_block ^ $_key;
}
} else {
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
$_block = substr($_text, $_i, '.$block_size.');
- $in = $self->_generateXor($_xor, '.$block_size.');
+ $in = $_xor;
'.$encrypt_block.'
+ $self->_increment_str($_xor);
$_key = $in;
$_plaintext.= $_block ^ $_key;
}
@@ -1755,7 +2263,7 @@ class Crypt_Base
return $_plaintext;
';
break;
- case CRYPT_MODE_CFB:
+ case self::MODE_CFB:
$encrypt = $init_encrypt . '
$_ciphertext = "";
$_buffer = &$self->enbuffer;
@@ -1854,7 +2362,7 @@ class Crypt_Base
return $_plaintext;
';
break;
- case CRYPT_MODE_OFB:
+ case self::MODE_OFB:
$encrypt = $init_encrypt . '
$_ciphertext = "";
$_plaintext_len = strlen($_text);
@@ -1870,7 +2378,7 @@ class Crypt_Base
$_xor = $in;
$_buffer["xor"].= $_xor;
}
- $_key = $self->_stringShift($_buffer["xor"], '.$block_size.');
+ $_key = $self->_string_shift($_buffer["xor"], '.$block_size.');
$_ciphertext.= $_block ^ $_key;
}
} else {
@@ -1906,7 +2414,7 @@ class Crypt_Base
$_xor = $in;
$_buffer["xor"].= $_xor;
}
- $_key = $self->_stringShift($_buffer["xor"], '.$block_size.');
+ $_key = $self->_string_shift($_buffer["xor"], '.$block_size.');
$_plaintext.= $_block ^ $_key;
}
} else {
@@ -1927,7 +2435,7 @@ class Crypt_Base
return $_plaintext;
';
break;
- case CRYPT_MODE_STREAM:
+ case self::MODE_STREAM:
$encrypt = $init_encrypt . '
$_ciphertext = "";
'.$encrypt_block.'
@@ -1939,11 +2447,10 @@ class Crypt_Base
return $_plaintext;
';
break;
- // case CRYPT_MODE_CBC:
+ // case self::MODE_CBC:
default:
$encrypt = $init_encrypt . '
$_ciphertext = "";
- $_text = $self->_pad($_text);
$_plaintext_len = strlen($_text);
$in = $self->encryptIV;
@@ -1996,16 +2503,51 @@ class Crypt_Base
* is stored, classwide (!), here for reusing.
*
* The string-based index of $function is a classwide
- * uniqe value representing, at least, the $mode of
+ * unique value representing, at least, the $mode of
* operation (or more... depends of the optimizing level)
* for which $mode the lambda function was created.
*
* @access private
- * @return &Array
+ * @return array &$functions
*/
function &_getLambdaFunctions()
{
static $functions = array();
return $functions;
}
+
+ /**
+ * Generates a digest from $bytes
+ *
+ * @see self::_setupInlineCrypt()
+ * @access private
+ * @param $bytes
+ * @return string
+ */
+ function _hashInlineCryptFunction($bytes)
+ {
+ if (!isset(self::$WHIRLPOOL_AVAILABLE)) {
+ self::$WHIRLPOOL_AVAILABLE = extension_loaded('hash') && in_array('whirlpool', hash_algos());
+ }
+
+ $result = '';
+ $hash = $bytes;
+
+ switch (true) {
+ case self::$WHIRLPOOL_AVAILABLE:
+ foreach (str_split($bytes, 64) as $t) {
+ $hash = hash('whirlpool', $hash, true);
+ $result .= $t ^ $hash;
+ }
+ return $result . hash('whirlpool', $hash, true);
+ default:
+ $len = strlen($bytes);
+ for ($i = 0; $i < $len; $i+=20) {
+ $t = substr($bytes, $i, 20);
+ $hash = pack('H*', sha1($hash));
+ $result .= $t ^ $hash;
+ }
+ return $result . pack('H*', sha1($hash));
+ }
+ }
}
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Blowfish.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Blowfish.php
index f39f17d7..3949e812 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Blowfish.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Blowfish.php
@@ -5,7 +5,7 @@
*
* Uses mcrypt, if available, and an internal implementation, otherwise.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* Useful resources are as follows:
*
@@ -14,9 +14,9 @@
* Here's a short example of how to use this library:
*
* setKey('12345678901234567890123456789012');
*
@@ -26,26 +26,8 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_Blowfish
+ * @package Blowfish
* @author Jim Wigginton
* @author Hans-Juergen Petrich
* @copyright 2007 Jim Wigginton
@@ -53,111 +35,32 @@
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Base
- *
- * Base cipher class
- */
-if (!class_exists('Crypt_Base')) {
- include_once 'Base.php';
-}
-
-/**#@+
- * @access public
- * @see Crypt_Blowfish::encrypt()
- * @see Crypt_Blowfish::decrypt()
- */
-/**
- * Encrypt / decrypt using the Counter mode.
- *
- * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
- */
-define('CRYPT_BLOWFISH_MODE_CTR', CRYPT_MODE_CTR);
-/**
- * Encrypt / decrypt using the Electronic Code Book mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
- */
-define('CRYPT_BLOWFISH_MODE_ECB', CRYPT_MODE_ECB);
-/**
- * Encrypt / decrypt using the Code Book Chaining mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
- */
-define('CRYPT_BLOWFISH_MODE_CBC', CRYPT_MODE_CBC);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
- */
-define('CRYPT_BLOWFISH_MODE_CFB', CRYPT_MODE_CFB);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
- */
-define('CRYPT_BLOWFISH_MODE_OFB', CRYPT_MODE_OFB);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_Base::Crypt_Base()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_BLOWFISH_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
-/**
- * Toggles the mcrypt implementation
- */
-define('CRYPT_BLOWFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of Blowfish.
*
- * @package Crypt_Blowfish
+ * @package Blowfish
* @author Jim Wigginton
* @author Hans-Juergen Petrich
* @access public
*/
-class Crypt_Blowfish extends Crypt_Base
+class Blowfish extends Base
{
/**
* Block Length of the cipher
*
- * @see Crypt_Base::block_size
- * @var Integer
+ * @see \phpseclib\Crypt\Base::block_size
+ * @var int
* @access private
*/
var $block_size = 8;
- /**
- * The default password key_size used by setPassword()
- *
- * @see Crypt_Base::password_key_size
- * @see Crypt_Base::setPassword()
- * @var Integer
- * @access private
- */
- var $password_key_size = 56;
-
- /**
- * The namespace used by the cipher for its constants.
- *
- * @see Crypt_Base::const_namespace
- * @var String
- * @access private
- */
- var $const_namespace = 'BLOWFISH';
-
/**
* The mcrypt specific name of the cipher
*
- * @see Crypt_Base::cipher_name_mcrypt
- * @var String
+ * @see \phpseclib\Crypt\Base::cipher_name_mcrypt
+ * @var string
* @access private
*/
var $cipher_name_mcrypt = 'blowfish';
@@ -165,8 +68,8 @@ class Crypt_Blowfish extends Crypt_Base
/**
* Optimizing value while CFB-encrypting
*
- * @see Crypt_Base::cfb_init_len
- * @var Integer
+ * @see \phpseclib\Crypt\Base::cfb_init_len
+ * @var int
* @access private
*/
var $cfb_init_len = 500;
@@ -174,12 +77,12 @@ class Crypt_Blowfish extends Crypt_Base
/**
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
*
- * S-Box 1
+ * S-Box 0
*
* @access private
* @var array
*/
- var $sbox0 = array (
+ var $sbox0 = array(
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
@@ -340,7 +243,7 @@ class Crypt_Blowfish extends Crypt_Base
/**
* P-Array consists of 18 32-bit subkeys
*
- * @var array $parray
+ * @var array
* @access private
*/
var $parray = array(
@@ -354,7 +257,7 @@ class Crypt_Blowfish extends Crypt_Base
*
* Holds the expanded key [p] and the key-depended s-boxes [sb]
*
- * @var array $bctx
+ * @var array
* @access private
*/
var $bctx;
@@ -362,43 +265,72 @@ class Crypt_Blowfish extends Crypt_Base
/**
* Holds the last used key
*
- * @var Array
+ * @var array
* @access private
*/
var $kl;
/**
- * Sets the key.
+ * The Key Length (in bytes)
*
- * Keys can be of any length. Blowfish, itself, requires the use of a key between 32 and max. 448-bits long.
- * If the key is less than 32-bits we NOT fill the key to 32bit but let the key as it is to be compatible
- * with mcrypt because mcrypt act this way with blowfish key's < 32 bits.
+ * @see \phpseclib\Crypt\Base::setKeyLength()
+ * @var int
+ * @access private
+ * @internal The max value is 256 / 8 = 32, the min value is 128 / 8 = 16. Exists in conjunction with $Nk
+ * because the encryption / decryption / key schedule creation requires this number and not $key_length. We could
+ * derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
+ * of that, we'll just precompute it once.
+ */
+ var $key_length = 16;
+
+ /**
+ * Sets the key length.
*
- * If the key is more than 448-bits, we trim the excess bits.
- *
- * If the key is not explicitly set, or empty, it'll be assumed a 128 bits key to be all null bytes.
+ * Key lengths can be between 32 and 448 bits.
*
* @access public
- * @see Crypt_Base::setKey()
- * @param String $key
+ * @param int $length
*/
- function setKey($key)
+ function setKeyLength($length)
{
- $keylength = strlen($key);
-
- if (!$keylength) {
- $key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
- } elseif ($keylength > 56) {
- $key = substr($key, 0, 56);
+ if ($length < 32) {
+ $this->key_length = 7;
+ } elseif ($length > 448) {
+ $this->key_length = 56;
+ } else {
+ $this->key_length = $length >> 3;
}
- parent::setKey($key);
+ parent::setKeyLength($length);
+ }
+
+ /**
+ * Test for engine validity
+ *
+ * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Base::isValidEngine()
+ *
+ * @see \phpseclib\Crypt\Base::isValidEngine()
+ * @param int $engine
+ * @access public
+ * @return bool
+ */
+ function isValidEngine($engine)
+ {
+ if ($engine == self::ENGINE_OPENSSL) {
+ if ($this->key_length != 16) {
+ return false;
+ }
+ $this->cipher_name_openssl_ecb = 'bf-ecb';
+ $this->cipher_name_openssl = 'bf-' . $this->_openssl_translate_mode();
+ }
+
+ return parent::isValidEngine($engine);
}
/**
* Setup the key (expansion)
*
- * @see Crypt_Base::_setupKey()
+ * @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@@ -455,8 +387,8 @@ class Crypt_Blowfish extends Crypt_Base
* Encrypts a block
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _encryptBlock($in)
{
@@ -472,17 +404,17 @@ class Crypt_Blowfish extends Crypt_Base
$r = $in[2];
for ($i = 0; $i < 16; $i+= 2) {
- $l^= $p[$i];
- $r^= ($sb_0[$l >> 24 & 0xff] +
- $sb_1[$l >> 16 & 0xff] ^
- $sb_2[$l >> 8 & 0xff]) +
- $sb_3[$l & 0xff];
+ $l^= $p[$i];
+ $r^= ($sb_0[$l >> 24 & 0xff] +
+ $sb_1[$l >> 16 & 0xff] ^
+ $sb_2[$l >> 8 & 0xff]) +
+ $sb_3[$l & 0xff];
- $r^= $p[$i + 1];
- $l^= ($sb_0[$r >> 24 & 0xff] +
- $sb_1[$r >> 16 & 0xff] ^
- $sb_2[$r >> 8 & 0xff]) +
- $sb_3[$r & 0xff];
+ $r^= $p[$i + 1];
+ $l^= ($sb_0[$r >> 24 & 0xff] +
+ $sb_1[$r >> 16 & 0xff] ^
+ $sb_2[$r >> 8 & 0xff]) +
+ $sb_3[$r & 0xff];
}
return pack("N*", $r ^ $p[17], $l ^ $p[16]);
}
@@ -491,8 +423,8 @@ class Crypt_Blowfish extends Crypt_Base
* Decrypts a block
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _decryptBlock($in)
{
@@ -519,30 +451,28 @@ class Crypt_Blowfish extends Crypt_Base
$sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff];
}
-
return pack("N*", $r ^ $p[0], $l ^ $p[1]);
}
/**
* Setup the performance-optimized function for de/encrypt()
*
- * @see Crypt_Base::_setupInlineCrypt()
+ * @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
- $lambda_functions =& Crypt_Blowfish::_getLambdaFunctions();
+ $lambda_functions =& self::_getLambdaFunctions();
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
+ // (Currently, for Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit)
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
- $gen_hi_opt_code = (bool)( count($lambda_functions) < 10);
+ $gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
- switch (true) {
- case $gen_hi_opt_code:
- $code_hash = md5(str_pad("Crypt_Blowfish, {$this->mode}, ", 32, "\0") . $this->key);
- break;
- default:
- $code_hash = "Crypt_Blowfish, {$this->mode}";
+ // Generation of a unique hash for our generated code
+ $code_hash = "Crypt_Blowfish, {$this->mode}";
+ if ($gen_hi_opt_code) {
+ $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
}
if (!isset($lambda_functions[$code_hash])) {
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/DES.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/DES.php
index f92f30b2..51220469 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/DES.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/DES.php
@@ -5,7 +5,7 @@
*
* Uses mcrypt, if available, and an internal implementation, otherwise.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* Useful resources are as follows:
*
@@ -16,9 +16,9 @@
* Here's a short example of how to use this library:
*
* setKey('abcdefgh');
*
@@ -32,170 +32,87 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_DES
+ * @package DES
* @author Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Base
- *
- * Base cipher class
- */
-if (!class_exists('Crypt_Base')) {
- include_once 'Base.php';
-}
-
-/**#@+
- * @access private
- * @see Crypt_DES::_setupKey()
- * @see Crypt_DES::_processBlock()
- */
-/**
- * Contains $keys[CRYPT_DES_ENCRYPT]
- */
-define('CRYPT_DES_ENCRYPT', 0);
-/**
- * Contains $keys[CRYPT_DES_DECRYPT]
- */
-define('CRYPT_DES_DECRYPT', 1);
-/**#@-*/
-
-/**#@+
- * @access public
- * @see Crypt_DES::encrypt()
- * @see Crypt_DES::decrypt()
- */
-/**
- * Encrypt / decrypt using the Counter mode.
- *
- * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
- */
-define('CRYPT_DES_MODE_CTR', CRYPT_MODE_CTR);
-/**
- * Encrypt / decrypt using the Electronic Code Book mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
- */
-define('CRYPT_DES_MODE_ECB', CRYPT_MODE_ECB);
-/**
- * Encrypt / decrypt using the Code Book Chaining mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
- */
-define('CRYPT_DES_MODE_CBC', CRYPT_MODE_CBC);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
- */
-define('CRYPT_DES_MODE_CFB', CRYPT_MODE_CFB);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
- */
-define('CRYPT_DES_MODE_OFB', CRYPT_MODE_OFB);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_Base::Crypt_Base()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_DES_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
-/**
- * Toggles the mcrypt implementation
- */
-define('CRYPT_DES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of DES.
*
- * @package Crypt_DES
+ * @package DES
* @author Jim Wigginton
* @access public
*/
-class Crypt_DES extends Crypt_Base
+class DES extends Base
{
+ /**#@+
+ * @access private
+ * @see \phpseclib\Crypt\DES::_setupKey()
+ * @see \phpseclib\Crypt\DES::_processBlock()
+ */
+ /**
+ * Contains $keys[self::ENCRYPT]
+ */
+ const ENCRYPT = 0;
+ /**
+ * Contains $keys[self::DECRYPT]
+ */
+ const DECRYPT = 1;
+ /**#@-*/
+
/**
* Block Length of the cipher
*
- * @see Crypt_Base::block_size
- * @var Integer
+ * @see \phpseclib\Crypt\Base::block_size
+ * @var int
* @access private
*/
var $block_size = 8;
/**
- * The Key
+ * Key Length (in bytes)
*
- * @see Crypt_Base::key
- * @see setKey()
- * @var String
+ * @see \phpseclib\Crypt\Base::setKeyLength()
+ * @var int
* @access private
*/
- var $key = "\0\0\0\0\0\0\0\0";
-
- /**
- * The default password key_size used by setPassword()
- *
- * @see Crypt_Base::password_key_size
- * @see Crypt_Base::setPassword()
- * @var Integer
- * @access private
- */
- var $password_key_size = 8;
-
- /**
- * The namespace used by the cipher for its constants.
- *
- * @see Crypt_Base::const_namespace
- * @var String
- * @access private
- */
- var $const_namespace = 'DES';
+ var $key_length = 8;
/**
* The mcrypt specific name of the cipher
*
- * @see Crypt_Base::cipher_name_mcrypt
- * @var String
+ * @see \phpseclib\Crypt\Base::cipher_name_mcrypt
+ * @var string
* @access private
*/
var $cipher_name_mcrypt = 'des';
+ /**
+ * The OpenSSL names of the cipher / modes
+ *
+ * @see \phpseclib\Crypt\Base::openssl_mode_names
+ * @var array
+ * @access private
+ */
+ var $openssl_mode_names = array(
+ self::MODE_ECB => 'des-ecb',
+ self::MODE_CBC => 'des-cbc',
+ self::MODE_CFB => 'des-cfb',
+ self::MODE_OFB => 'des-ofb'
+ // self::MODE_CTR is undefined for DES
+ );
+
/**
* Optimizing value while CFB-encrypting
*
- * @see Crypt_Base::cfb_init_len
- * @var Integer
+ * @see \phpseclib\Crypt\Base::cfb_init_len
+ * @var int
* @access private
*/
var $cfb_init_len = 500;
@@ -203,11 +120,11 @@ class Crypt_DES extends Crypt_Base
/**
* Switch for DES/3DES encryption
*
- * Used only if $engine == CRYPT_DES_MODE_INTERNAL
+ * Used only if $engine == self::ENGINE_INTERNAL
*
- * @see Crypt_DES::_setupKey()
- * @see Crypt_DES::_processBlock()
- * @var Integer
+ * @see self::_setupKey()
+ * @see self::_processBlock()
+ * @var int
* @access private
*/
var $des_rounds = 1;
@@ -215,17 +132,17 @@ class Crypt_DES extends Crypt_Base
/**
* max possible size of $key
*
- * @see Crypt_DES::setKey()
- * @var String
+ * @see self::setKey()
+ * @var string
* @access private
*/
- var $key_size_max = 8;
+ var $key_length_max = 8;
/**
* The Key Schedule
*
- * @see Crypt_DES::_setupKey()
- * @var Array
+ * @see self::_setupKey()
+ * @var array
* @access private
*/
var $keys;
@@ -237,9 +154,9 @@ class Crypt_DES extends Crypt_Base
* with each byte containing all bits in the same state as the
* corresponding bit in the index value.
*
- * @see Crypt_DES::_processBlock()
- * @see Crypt_DES::_setupKey()
- * @var Array
+ * @see self::_processBlock()
+ * @see self::_setupKey()
+ * @var array
* @access private
*/
var $shuffle = array(
@@ -378,7 +295,7 @@ class Crypt_DES extends Crypt_Base
*
* Indexing this table with each source byte performs the initial bit permutation.
*
- * @var Array
+ * @var array
* @access private
*/
var $ipmap = array(
@@ -420,7 +337,7 @@ class Crypt_DES extends Crypt_Base
* Inverse IP mapping helper table.
* Indexing this table with a byte value reverses the bit order.
*
- * @var Array
+ * @var array
* @access private
*/
var $invipmap = array(
@@ -464,7 +381,7 @@ class Crypt_DES extends Crypt_Base
* Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the
* P table: concatenation can then be replaced by exclusive ORs.
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox1 = array(
@@ -489,7 +406,7 @@ class Crypt_DES extends Crypt_Base
/**
* Pre-permuted S-box2
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox2 = array(
@@ -514,7 +431,7 @@ class Crypt_DES extends Crypt_Base
/**
* Pre-permuted S-box3
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox3 = array(
@@ -539,7 +456,7 @@ class Crypt_DES extends Crypt_Base
/**
* Pre-permuted S-box4
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox4 = array(
@@ -564,7 +481,7 @@ class Crypt_DES extends Crypt_Base
/**
* Pre-permuted S-box5
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox5 = array(
@@ -589,7 +506,7 @@ class Crypt_DES extends Crypt_Base
/**
* Pre-permuted S-box6
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox6 = array(
@@ -614,7 +531,7 @@ class Crypt_DES extends Crypt_Base
/**
* Pre-permuted S-box7
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox7 = array(
@@ -639,7 +556,7 @@ class Crypt_DES extends Crypt_Base
/**
* Pre-permuted S-box8
*
- * @var Array
+ * @var array
* @access private
*/
var $sbox8 = array(
@@ -661,6 +578,28 @@ class Crypt_DES extends Crypt_Base
0x00000820, 0x00020020, 0x08000000, 0x08020800
);
+ /**
+ * Test for engine validity
+ *
+ * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Base::isValidEngine()
+ *
+ * @see \phpseclib\Crypt\Base::isValidEngine()
+ * @param int $engine
+ * @access public
+ * @return bool
+ */
+ function isValidEngine($engine)
+ {
+ if ($this->key_length_max == 8) {
+ if ($engine == self::ENGINE_OPENSSL) {
+ $this->cipher_name_openssl_ecb = 'des-ecb';
+ $this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode();
+ }
+ }
+
+ return parent::isValidEngine($engine);
+ }
+
/**
* Sets the key.
*
@@ -672,16 +611,16 @@ class Crypt_DES extends Crypt_Base
*
* If the key is not explicitly set, it'll be assumed to be all zero's.
*
- * @see Crypt_Base::setKey()
+ * @see \phpseclib\Crypt\Base::setKey()
* @access public
- * @param String $key
+ * @param string $key
*/
function setKey($key)
{
// We check/cut here only up to max length of the key.
// Key padding to the proper length will be done in _setupKey()
- if (strlen($key) > $this->key_size_max) {
- $key = substr($key, 0, $this->key_size_max);
+ if (strlen($key) > $this->key_length_max) {
+ $key = substr($key, 0, $this->key_length_max);
}
// Sets the key
@@ -691,46 +630,46 @@ class Crypt_DES extends Crypt_Base
/**
* Encrypts a block
*
- * @see Crypt_Base::_encryptBlock()
- * @see Crypt_Base::encrypt()
- * @see Crypt_DES::encrypt()
+ * @see \phpseclib\Crypt\Base::_encryptBlock()
+ * @see \phpseclib\Crypt\Base::encrypt()
+ * @see self::encrypt()
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _encryptBlock($in)
{
- return $this->_processBlock($in, CRYPT_DES_ENCRYPT);
+ return $this->_processBlock($in, self::ENCRYPT);
}
/**
* Decrypts a block
*
- * @see Crypt_Base::_decryptBlock()
- * @see Crypt_Base::decrypt()
- * @see Crypt_DES::decrypt()
+ * @see \phpseclib\Crypt\Base::_decryptBlock()
+ * @see \phpseclib\Crypt\Base::decrypt()
+ * @see self::decrypt()
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _decryptBlock($in)
{
- return $this->_processBlock($in, CRYPT_DES_DECRYPT);
+ return $this->_processBlock($in, self::DECRYPT);
}
/**
* Encrypts or decrypts a 64-bit block
*
- * $mode should be either CRYPT_DES_ENCRYPT or CRYPT_DES_DECRYPT. See
+ * $mode should be either self::ENCRYPT or self::DECRYPT. See
* {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
* idea of what this function does.
*
- * @see Crypt_DES::_encryptBlock()
- * @see Crypt_DES::_decryptBlock()
+ * @see self::_encryptBlock()
+ * @see self::_decryptBlock()
* @access private
- * @param String $block
- * @param Integer $mode
- * @return String
+ * @param string $block
+ * @param int $mode
+ * @return string
*/
function _processBlock($block, $mode)
{
@@ -810,7 +749,7 @@ class Crypt_DES extends Crypt_Base
/**
* Creates the key schedule
*
- * @see Crypt_Base::_setupKey()
+ * @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@@ -1291,8 +1230,8 @@ class Crypt_DES extends Crypt_Base
$d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F);
$keys[$des_round] = array(
- CRYPT_DES_ENCRYPT => array(),
- CRYPT_DES_DECRYPT => array_fill(0, 32, 0)
+ self::ENCRYPT => array(),
+ self::DECRYPT => array_fill(0, 32, 0)
);
for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) {
$c <<= $shifts[$i];
@@ -1311,33 +1250,33 @@ class Crypt_DES extends Crypt_Base
(($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF);
$val2 = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
(($dp >> 8) & 0x0000FF00) | ( $dp & 0x000000FF);
- $keys[$des_round][CRYPT_DES_ENCRYPT][ ] = $val1;
- $keys[$des_round][CRYPT_DES_DECRYPT][$ki - 1] = $val1;
- $keys[$des_round][CRYPT_DES_ENCRYPT][ ] = $val2;
- $keys[$des_round][CRYPT_DES_DECRYPT][$ki ] = $val2;
+ $keys[$des_round][self::ENCRYPT][ ] = $val1;
+ $keys[$des_round][self::DECRYPT][$ki - 1] = $val1;
+ $keys[$des_round][self::ENCRYPT][ ] = $val2;
+ $keys[$des_round][self::DECRYPT][$ki ] = $val2;
}
}
switch ($this->des_rounds) {
case 3: // 3DES keys
$this->keys = array(
- CRYPT_DES_ENCRYPT => array_merge(
- $keys[0][CRYPT_DES_ENCRYPT],
- $keys[1][CRYPT_DES_DECRYPT],
- $keys[2][CRYPT_DES_ENCRYPT]
+ self::ENCRYPT => array_merge(
+ $keys[0][self::ENCRYPT],
+ $keys[1][self::DECRYPT],
+ $keys[2][self::ENCRYPT]
),
- CRYPT_DES_DECRYPT => array_merge(
- $keys[2][CRYPT_DES_DECRYPT],
- $keys[1][CRYPT_DES_ENCRYPT],
- $keys[0][CRYPT_DES_DECRYPT]
+ self::DECRYPT => array_merge(
+ $keys[2][self::DECRYPT],
+ $keys[1][self::ENCRYPT],
+ $keys[0][self::DECRYPT]
)
);
break;
// case 1: // DES keys
default:
$this->keys = array(
- CRYPT_DES_ENCRYPT => $keys[0][CRYPT_DES_ENCRYPT],
- CRYPT_DES_DECRYPT => $keys[0][CRYPT_DES_DECRYPT]
+ self::ENCRYPT => $keys[0][self::ENCRYPT],
+ self::DECRYPT => $keys[0][self::DECRYPT]
);
}
}
@@ -1345,12 +1284,12 @@ class Crypt_DES extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
- * @see Crypt_Base::_setupInlineCrypt()
+ * @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
- $lambda_functions =& Crypt_DES::_getLambdaFunctions();
+ $lambda_functions =& self::_getLambdaFunctions();
// Engine configuration for:
// - DES ($des_rounds == 1) or
@@ -1358,21 +1297,20 @@ class Crypt_DES extends Crypt_Base
$des_rounds = $this->des_rounds;
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
+ // (Currently, for DES, one generated $lambda_function cost on php5.5@32bit ~135kb unfreeable mem and ~230kb on php5.5@64bit)
+ // (Currently, for TripleDES, one generated $lambda_function cost on php5.5@32bit ~240kb unfreeable mem and ~340kb on php5.5@64bit)
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
- // Generation of a uniqe hash for our generated code
- switch (true) {
- case $gen_hi_opt_code:
- // For hi-optimized code, we create for each combination of
- // $mode, $des_rounds and $this->key its own encrypt/decrypt function.
- $code_hash = md5(str_pad("Crypt_DES, $des_rounds, {$this->mode}, ", 32, "\0") . $this->key);
- break;
- default:
- // After max 10 hi-optimized functions, we create generic
- // (still very fast.. but not ultra) functions for each $mode/$des_rounds
- // Currently 2 * 5 generic functions will be then max. possible.
- $code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
+ // Generation of a unique hash for our generated code
+ $code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
+ if ($gen_hi_opt_code) {
+ // For hi-optimized code, we create for each combination of
+ // $mode, $des_rounds and $this->key its own encrypt/decrypt function.
+ // After max 10 hi-optimized functions, we create generic
+ // (still very fast.. but not ultra) functions for each $mode/$des_rounds
+ // Currently 2 * 5 generic functions will be then max. possible.
+ $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
}
// Is there a re-usable $lambda_functions in there? If not, we have to create it.
@@ -1402,8 +1340,8 @@ class Crypt_DES extends Crypt_Base
// No futher initialisation of the $keys schedule is necessary.
// That is the extra performance boost.
$k = array(
- CRYPT_DES_ENCRYPT => $this->keys[CRYPT_DES_ENCRYPT],
- CRYPT_DES_DECRYPT => $this->keys[CRYPT_DES_DECRYPT]
+ self::ENCRYPT => $this->keys[self::ENCRYPT],
+ self::DECRYPT => $this->keys[self::DECRYPT]
);
$init_encrypt = '';
$init_decrypt = '';
@@ -1412,22 +1350,21 @@ class Crypt_DES extends Crypt_Base
// In generic optimized code mode, we have to use, as the best compromise [currently],
// our key schedule as $ke/$kd arrays. (with hardcoded indexes...)
$k = array(
- CRYPT_DES_ENCRYPT => array(),
- CRYPT_DES_DECRYPT => array()
+ self::ENCRYPT => array(),
+ self::DECRYPT => array()
);
- for ($i = 0, $c = count($this->keys[CRYPT_DES_ENCRYPT]); $i < $c; ++$i) {
- $k[CRYPT_DES_ENCRYPT][$i] = '$ke[' . $i . ']';
- $k[CRYPT_DES_DECRYPT][$i] = '$kd[' . $i . ']';
+ for ($i = 0, $c = count($this->keys[self::ENCRYPT]); $i < $c; ++$i) {
+ $k[self::ENCRYPT][$i] = '$ke[' . $i . ']';
+ $k[self::DECRYPT][$i] = '$kd[' . $i . ']';
}
- $init_encrypt = '$ke = $self->keys[CRYPT_DES_ENCRYPT];';
- $init_decrypt = '$kd = $self->keys[CRYPT_DES_DECRYPT];';
+ $init_encrypt = '$ke = $self->keys[self::ENCRYPT];';
+ $init_decrypt = '$kd = $self->keys[self::DECRYPT];';
break;
}
// Creating code for en- and decryption.
$crypt_block = array();
- foreach (array(CRYPT_DES_ENCRYPT, CRYPT_DES_DECRYPT) as $c) {
-
+ foreach (array(self::ENCRYPT, self::DECRYPT) as $c) {
/* Do the initial IP permutation. */
$crypt_block[$c] = '
$in = unpack("N*", $in);
@@ -1494,8 +1431,8 @@ class Crypt_DES extends Crypt_Base
'init_crypt' => $init_crypt,
'init_encrypt' => $init_encrypt,
'init_decrypt' => $init_decrypt,
- 'encrypt_block' => $crypt_block[CRYPT_DES_ENCRYPT],
- 'decrypt_block' => $crypt_block[CRYPT_DES_DECRYPT]
+ 'encrypt_block' => $crypt_block[self::ENCRYPT],
+ 'decrypt_block' => $crypt_block[self::DECRYPT]
)
);
}
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Hash.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Hash.php
index 4ab75b2d..07665a16 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Hash.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Hash.php
@@ -7,10 +7,10 @@
*
* md2, md5, md5-96, sha1, sha1-96, sha256, sha256-96, sha384, and sha512, sha512-96
*
- * If {@link Crypt_Hash::setKey() setKey()} is called, {@link Crypt_Hash::hash() hash()} will return the HMAC as opposed to
+ * If {@link self::setKey() setKey()} is called, {@link self::hash() hash()} will return the HMAC as opposed to
* the hash. If no valid algorithm is provided, sha1 will be used.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* {@internal The variable names are the same as those in
* {@link http://tools.ietf.org/html/rfc2104#section-2 RFC2104}.}}
@@ -18,9 +18,9 @@
* Here's a short example of how to use this library:
*
* setKey('abcdefg');
*
@@ -28,64 +28,50 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_Hash
+ * @package Hash
* @author Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**#@+
- * @access private
- * @see Crypt_Hash::Crypt_Hash()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_HASH_MODE_INTERNAL', 1);
-/**
- * Toggles the mhash() implementation, which has been deprecated on PHP 5.3.0+.
- */
-define('CRYPT_HASH_MODE_MHASH', 2);
-/**
- * Toggles the hash() implementation, which works on PHP 5.1.2+.
- */
-define('CRYPT_HASH_MODE_HASH', 3);
-/**#@-*/
+namespace phpseclib\Crypt;
+
+use phpseclib\Math\BigInteger;
/**
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
*
- * @package Crypt_Hash
+ * @package Hash
* @author Jim Wigginton
* @access public
*/
-class Crypt_Hash
+class Hash
{
+ /**#@+
+ * @access private
+ * @see \phpseclib\Crypt\Hash::__construct()
+ */
+ /**
+ * Toggles the internal implementation
+ */
+ const MODE_INTERNAL = 1;
+ /**
+ * Toggles the mhash() implementation, which has been deprecated on PHP 5.3.0+.
+ */
+ const MODE_MHASH = 2;
+ /**
+ * Toggles the hash() implementation, which works on PHP 5.1.2+.
+ */
+ const MODE_HASH = 3;
+ /**#@-*/
+
/**
* Hash Parameter
*
- * @see Crypt_Hash::setHash()
- * @var Integer
+ * @see self::setHash()
+ * @var int
* @access private
*/
var $hashParam;
@@ -93,8 +79,8 @@ class Crypt_Hash
/**
* Byte-length of compression blocks / key (Internal HMAC)
*
- * @see Crypt_Hash::setAlgorithm()
- * @var Integer
+ * @see self::setAlgorithm()
+ * @var int
* @access private
*/
var $b;
@@ -102,8 +88,8 @@ class Crypt_Hash
/**
* Byte-length of hash output (Internal HMAC)
*
- * @see Crypt_Hash::setHash()
- * @var Integer
+ * @see self::setHash()
+ * @var int
* @access private
*/
var $l = false;
@@ -111,8 +97,8 @@ class Crypt_Hash
/**
* Hash Algorithm
*
- * @see Crypt_Hash::setHash()
- * @var String
+ * @see self::setHash()
+ * @var string
* @access private
*/
var $hash;
@@ -120,8 +106,8 @@ class Crypt_Hash
/**
* Key
*
- * @see Crypt_Hash::setKey()
- * @var String
+ * @see self::setKey()
+ * @var string
* @access private
*/
var $key = false;
@@ -129,8 +115,8 @@ class Crypt_Hash
/**
* Outer XOR (Internal HMAC)
*
- * @see Crypt_Hash::setKey()
- * @var String
+ * @see self::setKey()
+ * @var string
* @access private
*/
var $opad;
@@ -138,8 +124,8 @@ class Crypt_Hash
/**
* Inner XOR (Internal HMAC)
*
- * @see Crypt_Hash::setKey()
- * @var String
+ * @see self::setKey()
+ * @var string
* @access private
*/
var $ipad;
@@ -147,22 +133,22 @@ class Crypt_Hash
/**
* Default Constructor.
*
- * @param optional String $hash
- * @return Crypt_Hash
+ * @param string $hash
+ * @return \phpseclib\Crypt\Hash
* @access public
*/
- function Crypt_Hash($hash = 'sha1')
+ function __construct($hash = 'sha1')
{
- if ( !defined('CRYPT_HASH_MODE') ) {
+ if (!defined('CRYPT_HASH_MODE')) {
switch (true) {
case extension_loaded('hash'):
- define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH);
+ define('CRYPT_HASH_MODE', self::MODE_HASH);
break;
case extension_loaded('mhash'):
- define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_MHASH);
+ define('CRYPT_HASH_MODE', self::MODE_MHASH);
break;
default:
- define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL);
+ define('CRYPT_HASH_MODE', self::MODE_INTERNAL);
}
}
@@ -175,7 +161,7 @@ class Crypt_Hash
* Keys can be of any length.
*
* @access public
- * @param optional String $key
+ * @param string $key
*/
function setKey($key = false)
{
@@ -188,7 +174,7 @@ class Crypt_Hash
* As set by the constructor or by the setHash() method.
*
* @access public
- * @return String
+ * @return string
*/
function getHash()
{
@@ -199,7 +185,7 @@ class Crypt_Hash
* Sets the hash function.
*
* @access public
- * @param String $hash
+ * @param string $hash
*/
function setHash($hash)
{
@@ -231,19 +217,19 @@ class Crypt_Hash
switch ($hash) {
case 'md2':
- $mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ?
- CRYPT_HASH_MODE_HASH : CRYPT_HASH_MODE_INTERNAL;
+ $mode = CRYPT_HASH_MODE == self::MODE_HASH && in_array('md2', hash_algos()) ?
+ self::MODE_HASH : self::MODE_INTERNAL;
break;
case 'sha384':
case 'sha512':
- $mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
+ $mode = CRYPT_HASH_MODE == self::MODE_MHASH ? self::MODE_INTERNAL : CRYPT_HASH_MODE;
break;
default:
$mode = CRYPT_HASH_MODE;
}
- switch ( $mode ) {
- case CRYPT_HASH_MODE_MHASH:
+ switch ($mode) {
+ case self::MODE_MHASH:
switch ($hash) {
case 'md5':
$this->hash = MHASH_MD5;
@@ -256,7 +242,7 @@ class Crypt_Hash
$this->hash = MHASH_SHA1;
}
return;
- case CRYPT_HASH_MODE_HASH:
+ case self::MODE_HASH:
switch ($hash) {
case 'md5':
$this->hash = 'md5';
@@ -276,26 +262,26 @@ class Crypt_Hash
switch ($hash) {
case 'md2':
- $this->b = 16;
- $this->hash = array($this, '_md2');
- break;
+ $this->b = 16;
+ $this->hash = array($this, '_md2');
+ break;
case 'md5':
- $this->b = 64;
- $this->hash = array($this, '_md5');
- break;
+ $this->b = 64;
+ $this->hash = array($this, '_md5');
+ break;
case 'sha256':
- $this->b = 64;
- $this->hash = array($this, '_sha256');
- break;
+ $this->b = 64;
+ $this->hash = array($this, '_sha256');
+ break;
case 'sha384':
case 'sha512':
- $this->b = 128;
- $this->hash = array($this, '_sha512');
- break;
+ $this->b = 128;
+ $this->hash = array($this, '_sha512');
+ break;
case 'sha1':
default:
- $this->b = 64;
- $this->hash = array($this, '_sha1');
+ $this->b = 64;
+ $this->hash = array($this, '_sha1');
}
$this->ipad = str_repeat(chr(0x36), $this->b);
@@ -306,22 +292,22 @@ class Crypt_Hash
* Compute the HMAC.
*
* @access public
- * @param String $text
- * @return String
+ * @param string $text
+ * @return string
*/
function hash($text)
{
- $mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
+ $mode = is_array($this->hash) ? self::MODE_INTERNAL : CRYPT_HASH_MODE;
if (!empty($this->key) || is_string($this->key)) {
- switch ( $mode ) {
- case CRYPT_HASH_MODE_MHASH:
+ switch ($mode) {
+ case self::MODE_MHASH:
$output = mhash($this->hash, $text, $this->key);
break;
- case CRYPT_HASH_MODE_HASH:
+ case self::MODE_HASH:
$output = hash_hmac($this->hash, $text, $this->key, true);
break;
- case CRYPT_HASH_MODE_INTERNAL:
+ case self::MODE_INTERNAL:
/* "Applications that use keys longer than B bytes will first hash the key using H and then use the
resultant L byte string as the actual key to HMAC."
@@ -337,14 +323,14 @@ class Crypt_Hash
$output = call_user_func($this->hash, $output); // step 7
}
} else {
- switch ( $mode ) {
- case CRYPT_HASH_MODE_MHASH:
+ switch ($mode) {
+ case self::MODE_MHASH:
$output = mhash($this->hash, $text);
break;
- case CRYPT_HASH_MODE_HASH:
+ case self::MODE_HASH:
$output = hash($this->hash, $text, true);
break;
- case CRYPT_HASH_MODE_INTERNAL:
+ case self::MODE_INTERNAL:
$output = call_user_func($this->hash, $text);
}
}
@@ -356,7 +342,7 @@ class Crypt_Hash
* Returns the hash length (in bytes)
*
* @access public
- * @return Integer
+ * @return int
*/
function getLength()
{
@@ -367,7 +353,7 @@ class Crypt_Hash
* Wrapper for MD5
*
* @access private
- * @param String $m
+ * @param string $m
*/
function _md5($m)
{
@@ -378,7 +364,7 @@ class Crypt_Hash
* Wrapper for SHA1
*
* @access private
- * @param String $m
+ * @param string $m
*/
function _sha1($m)
{
@@ -391,7 +377,7 @@ class Crypt_Hash
* See {@link http://tools.ietf.org/html/rfc1319 RFC1319}.
*
* @access private
- * @param String $m
+ * @param string $m
*/
function _md2($m)
{
@@ -467,7 +453,7 @@ class Crypt_Hash
* See {@link http://en.wikipedia.org/wiki/SHA_hash_functions#SHA-256_.28a_SHA-2_variant.29_pseudocode SHA-256 (a SHA-2 variant) pseudocode - Wikipedia}.
*
* @access private
- * @param String $m
+ * @param string $m
*/
function _sha256($m)
{
@@ -511,14 +497,15 @@ class Crypt_Hash
// Extend the sixteen 32-bit words into sixty-four 32-bit words
for ($i = 16; $i < 64; $i++) {
+ // @codingStandardsIgnoreStart
$s0 = $this->_rightRotate($w[$i - 15], 7) ^
$this->_rightRotate($w[$i - 15], 18) ^
$this->_rightShift( $w[$i - 15], 3);
$s1 = $this->_rightRotate($w[$i - 2], 17) ^
$this->_rightRotate($w[$i - 2], 19) ^
$this->_rightShift( $w[$i - 2], 10);
+ // @codingStandardsIgnoreEnd
$w[$i] = $this->_add($w[$i - 16], $s0, $w[$i - 7], $s1);
-
}
// Initialize hash value for this chunk
@@ -572,14 +559,10 @@ class Crypt_Hash
* Pure-PHP implementation of SHA384 and SHA512
*
* @access private
- * @param String $m
+ * @param string $m
*/
function _sha512($m)
{
- if (!class_exists('Math_BigInteger')) {
- include_once 'Math/BigInteger.php';
- }
-
static $init384, $init512, $k;
if (!isset($k)) {
@@ -594,9 +577,9 @@ class Crypt_Hash
);
for ($i = 0; $i < 8; $i++) {
- $init384[$i] = new Math_BigInteger($init384[$i], 16);
+ $init384[$i] = new BigInteger($init384[$i], 16);
$init384[$i]->setPrecision(64);
- $init512[$i] = new Math_BigInteger($init512[$i], 16);
+ $init512[$i] = new BigInteger($init512[$i], 16);
$init512[$i]->setPrecision(64);
}
@@ -626,7 +609,7 @@ class Crypt_Hash
);
for ($i = 0; $i < 80; $i++) {
- $k[$i] = new Math_BigInteger($k[$i], 16);
+ $k[$i] = new BigInteger($k[$i], 16);
}
}
@@ -645,7 +628,7 @@ class Crypt_Hash
foreach ($chunks as $chunk) {
$w = array();
for ($i = 0; $i < 16; $i++) {
- $temp = new Math_BigInteger($this->_string_shift($chunk, 8), 256);
+ $temp = new BigInteger($this->_string_shift($chunk, 8), 256);
$temp->setPrecision(64);
$w[] = $temp;
}
@@ -741,7 +724,7 @@ class Crypt_Hash
}
// Produce the final hash value (big-endian)
- // (Crypt_Hash::hash() trims the output for hashes but not for HMACs. as such, we trim the output here)
+ // (\phpseclib\Crypt\Hash::hash() trims the output for hashes but not for HMACs. as such, we trim the output here)
$temp = $hash[0]->toBytes() . $hash[1]->toBytes() . $hash[2]->toBytes() . $hash[3]->toBytes() .
$hash[4]->toBytes() . $hash[5]->toBytes();
if ($this->l != 48) {
@@ -755,10 +738,10 @@ class Crypt_Hash
* Right Rotate
*
* @access private
- * @param Integer $int
- * @param Integer $amt
- * @see _sha256()
- * @return Integer
+ * @param int $int
+ * @param int $amt
+ * @see self::_sha256()
+ * @return int
*/
function _rightRotate($int, $amt)
{
@@ -771,10 +754,10 @@ class Crypt_Hash
* Right Shift
*
* @access private
- * @param Integer $int
- * @param Integer $amt
- * @see _sha256()
- * @return Integer
+ * @param int $int
+ * @param int $amt
+ * @see self::_sha256()
+ * @return int
*/
function _rightShift($int, $amt)
{
@@ -786,9 +769,9 @@ class Crypt_Hash
* Not
*
* @access private
- * @param Integer $int
- * @see _sha256()
- * @return Integer
+ * @param int $int
+ * @see self::_sha256()
+ * @return int
*/
function _not($int)
{
@@ -799,11 +782,11 @@ class Crypt_Hash
* Add
*
* _sha256() adds multiple unsigned 32-bit integers. Since PHP doesn't support unsigned integers and since the
- * possibility of overflow exists, care has to be taken. Math_BigInteger() could be used but this should be faster.
+ * possibility of overflow exists, care has to be taken. BigInteger could be used but this should be faster.
*
- * @param Integer $...
- * @return Integer
- * @see _sha256()
+ * @param int $...
+ * @return int
+ * @see self::_sha256()
* @access private
*/
function _add()
@@ -827,9 +810,9 @@ class Crypt_Hash
*
* Inspired by array_shift
*
- * @param String $string
- * @param optional Integer $index
- * @return String
+ * @param string $string
+ * @param int $index
+ * @return string
* @access private
*/
function _string_shift(&$string, $index = 1)
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC2.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC2.php
index 96c9f18c..e9cfa3f8 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC2.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC2.php
@@ -5,7 +5,7 @@
*
* Uses mcrypt, if available, and an internal implementation, otherwise.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* Useful resources are as follows:
*
@@ -14,9 +14,9 @@
* Here's a short example of how to use this library:
*
* setKey('abcdefgh');
*
@@ -26,106 +26,28 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_RC2
+ * @package RC2
* @author Patrick Monnerat
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Base
- *
- * Base cipher class
- */
-if (!class_exists('Crypt_Base')) {
- include_once 'Base.php';
-}
-
-/**#@+
- * @access public
- * @see Crypt_RC2::encrypt()
- * @see Crypt_RC2::decrypt()
- */
-/**
- * Encrypt / decrypt using the Counter mode.
- *
- * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
- */
-define('CRYPT_RC2_MODE_CTR', CRYPT_MODE_CTR);
-/**
- * Encrypt / decrypt using the Electronic Code Book mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
- */
-define('CRYPT_RC2_MODE_ECB', CRYPT_MODE_ECB);
-/**
- * Encrypt / decrypt using the Code Book Chaining mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
- */
-define('CRYPT_RC2_MODE_CBC', CRYPT_MODE_CBC);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
- */
-define('CRYPT_RC2_MODE_CFB', CRYPT_MODE_CFB);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
- */
-define('CRYPT_RC2_MODE_OFB', CRYPT_MODE_OFB);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_RC2::Crypt_RC2()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_RC2_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
-/**
- * Toggles the mcrypt implementation
- */
-define('CRYPT_RC2_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of RC2.
*
- * @package Crypt_RC2
+ * @package RC2
* @access public
*/
-class Crypt_RC2 extends Crypt_Base
+class RC2 extends Base
{
/**
* Block Length of the cipher
*
- * @see Crypt_Base::block_size
- * @var Integer
+ * @see \phpseclib\Crypt\Base::block_size
+ * @var int
* @access private
*/
var $block_size = 8;
@@ -133,37 +55,48 @@ class Crypt_RC2 extends Crypt_Base
/**
* The Key
*
- * @see Crypt_Base::key
- * @see setKey()
- * @var String
+ * @see \phpseclib\Crypt\Base::key
+ * @see self::setKey()
+ * @var string
* @access private
*/
- var $key = "\0";
+ var $key;
/**
- * The default password key_size used by setPassword()
+ * The Original (unpadded) Key
*
- * @see Crypt_Base::password_key_size
- * @see Crypt_Base::setPassword()
- * @var Integer
+ * @see \phpseclib\Crypt\Base::key
+ * @see self::setKey()
+ * @see self::encrypt()
+ * @see self::decrypt()
+ * @var string
* @access private
*/
- var $password_key_size = 16; // = 128 bits
+ var $orig_key;
/**
- * The namespace used by the cipher for its constants.
+ * Don't truncate / null pad key
*
- * @see Crypt_Base::const_namespace
- * @var String
+ * @see \phpseclib\Crypt\Base::_clearBuffers()
+ * @var bool
* @access private
*/
- var $const_namespace = 'RC2';
+ var $skip_key_adjustment = true;
+
+ /**
+ * Key Length (in bytes)
+ *
+ * @see \phpseclib\Crypt\RC2::setKeyLength()
+ * @var int
+ * @access private
+ */
+ var $key_length = 16; // = 128 bits
/**
* The mcrypt specific name of the cipher
*
- * @see Crypt_Base::cipher_name_mcrypt
- * @var String
+ * @see \phpseclib\Crypt\Base::cipher_name_mcrypt
+ * @var string
* @access private
*/
var $cipher_name_mcrypt = 'rc2';
@@ -171,8 +104,8 @@ class Crypt_RC2 extends Crypt_Base
/**
* Optimizing value while CFB-encrypting
*
- * @see Crypt_Base::cfb_init_len
- * @var Integer
+ * @see \phpseclib\Crypt\Base::cfb_init_len
+ * @var int
* @access private
*/
var $cfb_init_len = 500;
@@ -180,20 +113,31 @@ class Crypt_RC2 extends Crypt_Base
/**
* The key length in bits.
*
- * @see Crypt_RC2::setKeyLength()
- * @see Crypt_RC2::setKey()
- * @var Integer
+ * @see self::setKeyLength()
+ * @see self::setKey()
+ * @var int
* @access private
* @internal Should be in range [1..1024].
* @internal Changing this value after setting the key has no effect.
*/
var $default_key_length = 1024;
+ /**
+ * The key length in bits.
+ *
+ * @see self::isValidEnine()
+ * @see self::setKey()
+ * @var int
+ * @access private
+ * @internal Should be in range [1..1024].
+ */
+ var $current_key_length;
+
/**
* The Key Schedule
*
- * @see Crypt_RC2::_setupKey()
- * @var Array
+ * @see self::_setupKey()
+ * @var array
* @access private
*/
var $keys;
@@ -202,8 +146,8 @@ class Crypt_RC2 extends Crypt_Base
* Key expansion randomization table.
* Twice the same 256-value sequence to save a modulus in key expansion.
*
- * @see Crypt_RC2::setKey()
- * @var Array
+ * @see self::setKey()
+ * @var array
* @access private
*/
var $pitable = array(
@@ -276,8 +220,8 @@ class Crypt_RC2 extends Crypt_Base
/**
* Inverse key expansion randomization table.
*
- * @see Crypt_RC2::setKey()
- * @var Array
+ * @see self::setKey()
+ * @var array
* @access private
*/
var $invpitable = array(
@@ -316,55 +260,68 @@ class Crypt_RC2 extends Crypt_Base
);
/**
- * Default Constructor.
+ * Test for engine validity
*
- * Determines whether or not the mcrypt extension should be used.
+ * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Base::isValidEngine()
*
- * $mode could be:
- *
- * - CRYPT_RC2_MODE_ECB
- *
- * - CRYPT_RC2_MODE_CBC
- *
- * - CRYPT_RC2_MODE_CTR
- *
- * - CRYPT_RC2_MODE_CFB
- *
- * - CRYPT_RC2_MODE_OFB
- *
- * If not explicitly set, CRYPT_RC2_MODE_CBC will be used.
- *
- * @see Crypt_Base::Crypt_Base()
- * @param optional Integer $mode
+ * @see \phpseclib\Crypt\Base::__construct()
+ * @param int $engine
* @access public
+ * @return bool
*/
- function Crypt_RC2($mode = CRYPT_RC2_MODE_CBC)
+ function isValidEngine($engine)
{
- parent::Crypt_Base($mode);
- $this->setKey('');
+ switch ($engine) {
+ case self::ENGINE_OPENSSL:
+ if ($this->current_key_length != 128 || strlen($this->orig_key) < 16) {
+ return false;
+ }
+ $this->cipher_name_openssl_ecb = 'rc2-ecb';
+ $this->cipher_name_openssl = 'rc2-' . $this->_openssl_translate_mode();
+ }
+
+ return parent::isValidEngine($engine);
}
/**
- * Sets the key length
+ * Sets the key length.
*
- * Valid key lengths are 1 to 1024.
+ * Valid key lengths are 8 to 1024.
* Calling this function after setting the key has no effect until the next
- * Crypt_RC2::setKey() call.
+ * \phpseclib\Crypt\RC2::setKey() call.
*
* @access public
- * @param Integer $length in bits
+ * @param int $length in bits
*/
function setKeyLength($length)
{
- if ($length >= 1 && $length <= 1024) {
+ if ($length < 8) {
+ $this->default_key_length = 8;
+ } elseif ($length > 1024) {
+ $this->default_key_length = 128;
+ } else {
$this->default_key_length = $length;
}
+ $this->current_key_length = $this->default_key_length;
+
+ parent::setKeyLength($length);
+ }
+
+ /**
+ * Returns the current key length
+ *
+ * @access public
+ * @return int
+ */
+ function getKeyLength()
+ {
+ return $this->current_key_length;
}
/**
* Sets the key.
*
- * Keys can be of any length. RC2, itself, uses 1 to 1024 bit keys (eg.
+ * Keys can be of any length. RC2, itself, uses 8 to 1024 bit keys (eg.
* strlen($key) <= 128), however, we only use the first 128 bytes if $key
* has more then 128 bytes in it, and set $key to a single null byte if
* it is empty.
@@ -372,18 +329,21 @@ class Crypt_RC2 extends Crypt_Base
* If the key is not explicitly set, it'll be assumed to be a single
* null byte.
*
- * @see Crypt_Base::setKey()
+ * @see \phpseclib\Crypt\Base::setKey()
* @access public
- * @param String $key
- * @param Integer $t1 optional Effective key length in bits.
+ * @param string $key
+ * @param int $t1 optional Effective key length in bits.
*/
function setKey($key, $t1 = 0)
{
+ $this->orig_key = $key;
+
if ($t1 <= 0) {
$t1 = $this->default_key_length;
- } else if ($t1 > 1024) {
+ } elseif ($t1 > 1024) {
$t1 = 1024;
}
+ $this->current_key_length = $t1;
// Key byte count should be 1..128.
$key = strlen($key) ? substr($key, 0, 128) : "\x00";
$t = strlen($key);
@@ -413,17 +373,64 @@ class Crypt_RC2 extends Crypt_Base
// Prepare the key for mcrypt.
$l[0] = $this->invpitable[$l[0]];
array_unshift($l, 'C*');
+
parent::setKey(call_user_func_array('pack', $l));
}
+ /**
+ * Encrypts a message.
+ *
+ * Mostly a wrapper for \phpseclib\Crypt\Base::encrypt, with some additional OpenSSL handling code
+ *
+ * @see self::decrypt()
+ * @access public
+ * @param string $plaintext
+ * @return string $ciphertext
+ */
+ function encrypt($plaintext)
+ {
+ if ($this->engine == self::ENGINE_OPENSSL) {
+ $temp = $this->key;
+ $this->key = $this->orig_key;
+ $result = parent::encrypt($plaintext);
+ $this->key = $temp;
+ return $result;
+ }
+
+ return parent::encrypt($plaintext);
+ }
+
+ /**
+ * Decrypts a message.
+ *
+ * Mostly a wrapper for \phpseclib\Crypt\Base::decrypt, with some additional OpenSSL handling code
+ *
+ * @see self::encrypt()
+ * @access public
+ * @param string $ciphertext
+ * @return string $plaintext
+ */
+ function decrypt($ciphertext)
+ {
+ if ($this->engine == self::ENGINE_OPENSSL) {
+ $temp = $this->key;
+ $this->key = $this->orig_key;
+ $result = parent::decrypt($ciphertext);
+ $this->key = $temp;
+ return $result;
+ }
+
+ return parent::decrypt($ciphertext);
+ }
+
/**
* Encrypts a block
*
- * @see Crypt_Base::_encryptBlock()
- * @see Crypt_Base::encrypt()
+ * @see \phpseclib\Crypt\Base::_encryptBlock()
+ * @see \phpseclib\Crypt\Base::encrypt()
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _encryptBlock($in)
{
@@ -464,11 +471,11 @@ class Crypt_RC2 extends Crypt_Base
/**
* Decrypts a block
*
- * @see Crypt_Base::_decryptBlock()
- * @see Crypt_Base::decrypt()
+ * @see \phpseclib\Crypt\Base::_decryptBlock()
+ * @see \phpseclib\Crypt\Base::decrypt()
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _decryptBlock($in)
{
@@ -506,15 +513,34 @@ class Crypt_RC2 extends Crypt_Base
return pack('vvvv', $r0, $r1, $r2, $r3);
}
+ /**
+ * Setup the \phpseclib\Crypt\Base::ENGINE_MCRYPT $engine
+ *
+ * @see \phpseclib\Crypt\Base::_setupMcrypt()
+ * @access private
+ */
+ function _setupMcrypt()
+ {
+ if (!isset($this->key)) {
+ $this->setKey('');
+ }
+
+ parent::_setupMcrypt();
+ }
+
/**
* Creates the key schedule
*
- * @see Crypt_Base::_setupKey()
+ * @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
{
- // Key has already been expanded in Crypt_RC2::setKey():
+ if (!isset($this->key)) {
+ $this->setKey('');
+ }
+
+ // Key has already been expanded in \phpseclib\Crypt\RC2::setKey():
// Only the first value must be altered.
$l = unpack('Ca/Cb/v*', $this->key);
array_unshift($l, $this->pitable[$l['a']] | ($l['b'] << 8));
@@ -526,24 +552,24 @@ class Crypt_RC2 extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
- * @see Crypt_Base::_setupInlineCrypt()
+ * @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
- $lambda_functions = &Crypt_RC2::_getLambdaFunctions();
+ $lambda_functions =& self::_getLambdaFunctions();
// The first 10 generated $lambda_functions will use the $keys hardcoded as integers
// for the mixing rounds, for better inline crypt performance [~20% faster].
// But for memory reason we have to limit those ultra-optimized $lambda_functions to an amount of 10.
- $keys = $this->keys;
- if (count($lambda_functions) >= 10) {
- foreach ($this->keys as $k => $v) {
- $keys[$k] = '$keys[' . $k . ']';
- }
- }
+ // (Currently, for Crypt_RC2, one generated $lambda_function cost on php5.5@32bit ~60kb unfreeable mem and ~100kb on php5.5@64bit)
+ $gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
- $code_hash = md5(str_pad("Crypt_RC2, {$this->mode}, ", 32, "\0") . implode(',', $keys));
+ // Generation of a unique hash for our generated code
+ $code_hash = "Crypt_RC2, {$this->mode}";
+ if ($gen_hi_opt_code) {
+ $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
+ }
// Is there a re-usable $lambda_functions in there?
// If not, we have to create it.
@@ -551,6 +577,16 @@ class Crypt_RC2 extends Crypt_Base
// Init code for both, encrypt and decrypt.
$init_crypt = '$keys = $self->keys;';
+ switch (true) {
+ case $gen_hi_opt_code:
+ $keys = $this->keys;
+ default:
+ $keys = array();
+ foreach ($this->keys as $k => $v) {
+ $keys[$k] = '$keys[' . $k . ']';
+ }
+ }
+
// $in is the current 8 bytes block which has to be en/decrypt
$encrypt_block = $decrypt_block = '
$in = unpack("v4", $in);
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC4.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC4.php
index d5eda8c3..1e768d7d 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC4.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RC4.php
@@ -5,7 +5,7 @@
*
* Uses mcrypt, if available, and an internal implementation, otherwise.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* Useful resources are as follows:
*
@@ -18,9 +18,9 @@
* Here's a short example of how to use this library:
*
* setKey('abcdefgh');
*
@@ -34,108 +34,59 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_RC4
+ * @package RC4
* @author Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Base
- *
- * Base cipher class
- */
-if (!class_exists('Crypt_Base')) {
- include_once 'Base.php';
-}
-
-/**#@+
- * @access private
- * @see Crypt_RC4::Crypt_RC4()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_RC4_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
-/**
- * Toggles the mcrypt implementation
- */
-define('CRYPT_RC4_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_RC4::_crypt()
- */
-define('CRYPT_RC4_ENCRYPT', 0);
-define('CRYPT_RC4_DECRYPT', 1);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of RC4.
*
- * @package Crypt_RC4
+ * @package RC4
* @author Jim Wigginton
* @access public
*/
-class Crypt_RC4 extends Crypt_Base
+class RC4 extends Base
{
+ /**#@+
+ * @access private
+ * @see \phpseclib\Crypt\RC4::_crypt()
+ */
+ const ENCRYPT = 0;
+ const DECRYPT = 1;
+ /**#@-*/
+
/**
* Block Length of the cipher
*
* RC4 is a stream cipher
* so we the block_size to 0
*
- * @see Crypt_Base::block_size
- * @var Integer
+ * @see \phpseclib\Crypt\Base::block_size
+ * @var int
* @access private
*/
var $block_size = 0;
/**
- * The default password key_size used by setPassword()
+ * Key Length (in bytes)
*
- * @see Crypt_Base::password_key_size
- * @see Crypt_Base::setPassword()
- * @var Integer
+ * @see \phpseclib\Crypt\RC4::setKeyLength()
+ * @var int
* @access private
*/
- var $password_key_size = 128; // = 1024 bits
-
- /**
- * The namespace used by the cipher for its constants.
- *
- * @see Crypt_Base::const_namespace
- * @var String
- * @access private
- */
- var $const_namespace = 'RC4';
+ var $key_length = 128; // = 1024 bits
/**
* The mcrypt specific name of the cipher
*
- * @see Crypt_Base::cipher_name_mcrypt
- * @var String
+ * @see \phpseclib\Crypt\Base::cipher_name_mcrypt
+ * @var string
* @access private
*/
var $cipher_name_mcrypt = 'arcfour';
@@ -143,7 +94,7 @@ class Crypt_RC4 extends Crypt_Base
/**
* Holds whether performance-optimized $inline_crypt() can/should be used.
*
- * @see Crypt_Base::inline_crypt
+ * @see \phpseclib\Crypt\Base::inline_crypt
* @var mixed
* @access private
*/
@@ -152,8 +103,8 @@ class Crypt_RC4 extends Crypt_Base
/**
* The Key
*
- * @see Crypt_RC4::setKey()
- * @var String
+ * @see self::setKey()
+ * @var string
* @access private
*/
var $key = "\0";
@@ -161,8 +112,8 @@ class Crypt_RC4 extends Crypt_Base
/**
* The Key Stream for decryption and encryption
*
- * @see Crypt_RC4::setKey()
- * @var Array
+ * @see self::setKey()
+ * @var array
* @access private
*/
var $stream;
@@ -172,13 +123,45 @@ class Crypt_RC4 extends Crypt_Base
*
* Determines whether or not the mcrypt extension should be used.
*
- * @see Crypt_Base::Crypt_Base()
- * @return Crypt_RC4
+ * @see \phpseclib\Crypt\Base::__construct()
+ * @return \phpseclib\Crypt\RC4
* @access public
*/
- function Crypt_RC4()
+ function __construct()
{
- parent::Crypt_Base(CRYPT_MODE_STREAM);
+ parent::__construct(Base::MODE_STREAM);
+ }
+
+ /**
+ * Test for engine validity
+ *
+ * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Base::isValidEngine()
+ *
+ * @see \phpseclib\Crypt\Base::__construct()
+ * @param int $engine
+ * @access public
+ * @return bool
+ */
+ function isValidEngine($engine)
+ {
+ switch ($engine) {
+ case Base::ENGINE_OPENSSL:
+ switch (strlen($this->key)) {
+ case 5:
+ $this->cipher_name_openssl = 'rc4-40';
+ break;
+ case 8:
+ $this->cipher_name_openssl = 'rc4-64';
+ break;
+ case 16:
+ $this->cipher_name_openssl = 'rc4';
+ break;
+ default:
+ return false;
+ }
+ }
+
+ return parent::isValidEngine($engine);
}
/**
@@ -196,8 +179,8 @@ class Crypt_RC4 extends Crypt_Base
* {@link http://www.rsa.com/rsalabs/node.asp?id=2009 http://www.rsa.com/rsalabs/node.asp?id=2009}
* {@link http://en.wikipedia.org/wiki/Related_key_attack http://en.wikipedia.org/wiki/Related_key_attack}
*
- * @param String $iv
- * @see Crypt_RC4::setKey()
+ * @param string $iv
+ * @see self::setKey()
* @access public
*/
function setIV($iv)
@@ -205,35 +188,41 @@ class Crypt_RC4 extends Crypt_Base
}
/**
- * Sets the key.
+ * Sets the key length
*
- * Keys can be between 1 and 256 bytes long. If they are longer then 256 bytes, the first 256 bytes will
- * be used. If no key is explicitly set, it'll be assumed to be a single null byte.
+ * Keys can be between 1 and 256 bytes long.
*
* @access public
- * @see Crypt_Base::setKey()
- * @param String $key
+ * @param int $length
*/
- function setKey($key)
+ function setKeyLength($length)
{
- parent::setKey(substr($key, 0, 256));
+ if ($length < 8) {
+ $this->key_length = 1;
+ } elseif ($length > 2048) {
+ $this->key_length = 256;
+ } else {
+ $this->key_length = $length >> 3;
+ }
+
+ parent::setKeyLength($length);
}
/**
* Encrypts a message.
*
- * @see Crypt_Base::decrypt()
- * @see Crypt_RC4::_crypt()
+ * @see \phpseclib\Crypt\Base::decrypt()
+ * @see self::_crypt()
* @access public
- * @param String $plaintext
- * @return String $ciphertext
+ * @param string $plaintext
+ * @return string $ciphertext
*/
function encrypt($plaintext)
{
- if ($this->engine == CRYPT_MODE_MCRYPT) {
+ if ($this->engine != Base::ENGINE_INTERNAL) {
return parent::encrypt($plaintext);
}
- return $this->_crypt($plaintext, CRYPT_RC4_ENCRYPT);
+ return $this->_crypt($plaintext, self::ENCRYPT);
}
/**
@@ -242,25 +231,46 @@ class Crypt_RC4 extends Crypt_Base
* $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)).
* At least if the continuous buffer is disabled.
*
- * @see Crypt_Base::encrypt()
- * @see Crypt_RC4::_crypt()
+ * @see \phpseclib\Crypt\Base::encrypt()
+ * @see self::_crypt()
* @access public
- * @param String $ciphertext
- * @return String $plaintext
+ * @param string $ciphertext
+ * @return string $plaintext
*/
function decrypt($ciphertext)
{
- if ($this->engine == CRYPT_MODE_MCRYPT) {
+ if ($this->engine != Base::ENGINE_INTERNAL) {
return parent::decrypt($ciphertext);
}
- return $this->_crypt($ciphertext, CRYPT_RC4_DECRYPT);
+ return $this->_crypt($ciphertext, self::DECRYPT);
}
+ /**
+ * Encrypts a block
+ *
+ * @access private
+ * @param string $in
+ */
+ function _encryptBlock($in)
+ {
+ // RC4 does not utilize this method
+ }
+
+ /**
+ * Decrypts a block
+ *
+ * @access private
+ * @param string $in
+ */
+ function _decryptBlock($in)
+ {
+ // RC4 does not utilize this method
+ }
/**
* Setup the key (expansion)
*
- * @see Crypt_Base::_setupKey()
+ * @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@@ -277,7 +287,7 @@ class Crypt_RC4 extends Crypt_Base
}
$this->stream = array();
- $this->stream[CRYPT_RC4_DECRYPT] = $this->stream[CRYPT_RC4_ENCRYPT] = array(
+ $this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = array(
0, // index $i
0, // index $j
$keyStream
@@ -287,12 +297,12 @@ class Crypt_RC4 extends Crypt_Base
/**
* Encrypts or decrypts a message.
*
- * @see Crypt_RC4::encrypt()
- * @see Crypt_RC4::decrypt()
+ * @see self::encrypt()
+ * @see self::decrypt()
* @access private
- * @param String $text
- * @param Integer $mode
- * @return String $text
+ * @param string $text
+ * @param int $mode
+ * @return string $text
*/
function _crypt($text, $mode)
{
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php
index 53f94354..ef508a43 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php
@@ -3,14 +3,14 @@
/**
* Pure-PHP PKCS#1 (v2.1) compliant implementation of RSA.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* Here's an example of how to encrypt and decrypt text with this library:
*
* createKey());
*
* $plaintext = 'terrafrost';
@@ -26,9 +26,9 @@
* Here's an example of how to create signatures and verify signatures with this library:
*
* createKey());
*
* $plaintext = 'terrafrost';
@@ -41,241 +41,211 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_RSA
+ * @package RSA
* @author Jim Wigginton
* @copyright 2009 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Random
- */
-// the class_exists() will only be called if the crypt_random_string function hasn't been defined and
-// will trigger a call to __autoload() if you're wanting to auto-load classes
-// call function_exists() a second time to stop the include_once from being called outside
-// of the auto loader
-if (!function_exists('crypt_random_string')) {
- include_once 'Random.php';
-}
+namespace phpseclib\Crypt;
-/**
- * Include Crypt_Hash
- */
-if (!class_exists('Crypt_Hash')) {
- include_once 'Hash.php';
-}
-
-/**#@+
- * @access public
- * @see Crypt_RSA::encrypt()
- * @see Crypt_RSA::decrypt()
- */
-/**
- * Use {@link http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding Optimal Asymmetric Encryption Padding}
- * (OAEP) for encryption / decryption.
- *
- * Uses sha1 by default.
- *
- * @see Crypt_RSA::setHash()
- * @see Crypt_RSA::setMGFHash()
- */
-define('CRYPT_RSA_ENCRYPTION_OAEP', 1);
-/**
- * Use PKCS#1 padding.
- *
- * Although CRYPT_RSA_ENCRYPTION_OAEP offers more security, including PKCS#1 padding is necessary for purposes of backwards
- * compatibility with protocols (like SSH-1) written before OAEP's introduction.
- */
-define('CRYPT_RSA_ENCRYPTION_PKCS1', 2);
-/**#@-*/
-
-/**#@+
- * @access public
- * @see Crypt_RSA::sign()
- * @see Crypt_RSA::verify()
- * @see Crypt_RSA::setHash()
- */
-/**
- * Use the Probabilistic Signature Scheme for signing
- *
- * Uses sha1 by default.
- *
- * @see Crypt_RSA::setSaltLength()
- * @see Crypt_RSA::setMGFHash()
- */
-define('CRYPT_RSA_SIGNATURE_PSS', 1);
-/**
- * Use the PKCS#1 scheme by default.
- *
- * Although CRYPT_RSA_SIGNATURE_PSS offers more security, including PKCS#1 signing is necessary for purposes of backwards
- * compatibility with protocols (like SSH-2) written before PSS's introduction.
- */
-define('CRYPT_RSA_SIGNATURE_PKCS1', 2);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_RSA::createKey()
- */
-/**
- * ASN1 Integer
- */
-define('CRYPT_RSA_ASN1_INTEGER', 2);
-/**
- * ASN1 Bit String
- */
-define('CRYPT_RSA_ASN1_BITSTRING', 3);
-/**
- * ASN1 Octet String
- */
-define('CRYPT_RSA_ASN1_OCTETSTRING', 4);
-/**
- * ASN1 Object Identifier
- */
-define('CRYPT_RSA_ASN1_OBJECT', 6);
-/**
- * ASN1 Sequence (with the constucted bit set)
- */
-define('CRYPT_RSA_ASN1_SEQUENCE', 48);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_RSA::Crypt_RSA()
- */
-/**
- * To use the pure-PHP implementation
- */
-define('CRYPT_RSA_MODE_INTERNAL', 1);
-/**
- * To use the OpenSSL library
- *
- * (if enabled; otherwise, the internal implementation will be used)
- */
-define('CRYPT_RSA_MODE_OPENSSL', 2);
-/**#@-*/
-
-/**
- * Default openSSL configuration file.
- */
-define('CRYPT_RSA_OPENSSL_CONFIG', dirname(__FILE__) . '/../openssl.cnf');
-
-/**#@+
- * @access public
- * @see Crypt_RSA::createKey()
- * @see Crypt_RSA::setPrivateKeyFormat()
- */
-/**
- * PKCS#1 formatted private key
- *
- * Used by OpenSSH
- */
-define('CRYPT_RSA_PRIVATE_FORMAT_PKCS1', 0);
-/**
- * PuTTY formatted private key
- */
-define('CRYPT_RSA_PRIVATE_FORMAT_PUTTY', 1);
-/**
- * XML formatted private key
- */
-define('CRYPT_RSA_PRIVATE_FORMAT_XML', 2);
-/**
- * PKCS#8 formatted private key
- */
-define('CRYPT_RSA_PRIVATE_FORMAT_PKCS8', 3);
-/**#@-*/
-
-/**#@+
- * @access public
- * @see Crypt_RSA::createKey()
- * @see Crypt_RSA::setPublicKeyFormat()
- */
-/**
- * Raw public key
- *
- * An array containing two Math_BigInteger objects.
- *
- * The exponent can be indexed with any of the following:
- *
- * 0, e, exponent, publicExponent
- *
- * The modulus can be indexed with any of the following:
- *
- * 1, n, modulo, modulus
- */
-define('CRYPT_RSA_PUBLIC_FORMAT_RAW', 3);
-/**
- * PKCS#1 formatted public key (raw)
- *
- * Used by File/X509.php
- *
- * Has the following header:
- *
- * -----BEGIN RSA PUBLIC KEY-----
- *
- * Analogous to ssh-keygen's pem format (as specified by -m)
- */
-define('CRYPT_RSA_PUBLIC_FORMAT_PKCS1', 4);
-define('CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW', 4);
-/**
- * XML formatted public key
- */
-define('CRYPT_RSA_PUBLIC_FORMAT_XML', 5);
-/**
- * OpenSSH formatted public key
- *
- * Place in $HOME/.ssh/authorized_keys
- */
-define('CRYPT_RSA_PUBLIC_FORMAT_OPENSSH', 6);
-/**
- * PKCS#1 formatted public key (encapsulated)
- *
- * Used by PHP's openssl_public_encrypt() and openssl's rsautl (when -pubin is set)
- *
- * Has the following header:
- *
- * -----BEGIN PUBLIC KEY-----
- *
- * Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
- * is specific to private keys it's basically creating a DER-encoded wrapper
- * for keys. This just extends that same concept to public keys (much like ssh-keygen)
- */
-define('CRYPT_RSA_PUBLIC_FORMAT_PKCS8', 7);
-/**#@-*/
+use phpseclib\Math\BigInteger;
/**
* Pure-PHP PKCS#1 compliant implementation of RSA.
*
- * @package Crypt_RSA
+ * @package RSA
* @author Jim Wigginton
* @access public
*/
-class Crypt_RSA
+class RSA
{
+ /**#@+
+ * @access public
+ * @see self::encrypt()
+ * @see self::decrypt()
+ */
+ /**
+ * Use {@link http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding Optimal Asymmetric Encryption Padding}
+ * (OAEP) for encryption / decryption.
+ *
+ * Uses sha1 by default.
+ *
+ * @see self::setHash()
+ * @see self::setMGFHash()
+ */
+ const ENCRYPTION_OAEP = 1;
+ /**
+ * Use PKCS#1 padding.
+ *
+ * Although self::ENCRYPTION_OAEP offers more security, including PKCS#1 padding is necessary for purposes of backwards
+ * compatibility with protocols (like SSH-1) written before OAEP's introduction.
+ */
+ const ENCRYPTION_PKCS1 = 2;
+ /**
+ * Do not use any padding
+ *
+ * Although this method is not recommended it can none-the-less sometimes be useful if you're trying to decrypt some legacy
+ * stuff, if you're trying to diagnose why an encrypted message isn't decrypting, etc.
+ */
+ const ENCRYPTION_NONE = 3;
+ /**#@-*/
+
+ /**#@+
+ * @access public
+ * @see self::sign()
+ * @see self::verify()
+ * @see self::setHash()
+ */
+ /**
+ * Use the Probabilistic Signature Scheme for signing
+ *
+ * Uses sha1 by default.
+ *
+ * @see self::setSaltLength()
+ * @see self::setMGFHash()
+ */
+ const SIGNATURE_PSS = 1;
+ /**
+ * Use the PKCS#1 scheme by default.
+ *
+ * Although self::SIGNATURE_PSS offers more security, including PKCS#1 signing is necessary for purposes of backwards
+ * compatibility with protocols (like SSH-2) written before PSS's introduction.
+ */
+ const SIGNATURE_PKCS1 = 2;
+ /**#@-*/
+
+ /**#@+
+ * @access private
+ * @see \phpseclib\Crypt\RSA::createKey()
+ */
+ /**
+ * ASN1 Integer
+ */
+ const ASN1_INTEGER = 2;
+ /**
+ * ASN1 Bit String
+ */
+ const ASN1_BITSTRING = 3;
+ /**
+ * ASN1 Octet String
+ */
+ const ASN1_OCTETSTRING = 4;
+ /**
+ * ASN1 Object Identifier
+ */
+ const ASN1_OBJECT = 6;
+ /**
+ * ASN1 Sequence (with the constucted bit set)
+ */
+ const ASN1_SEQUENCE = 48;
+ /**#@-*/
+
+ /**#@+
+ * @access private
+ * @see \phpseclib\Crypt\RSA::__construct()
+ */
+ /**
+ * To use the pure-PHP implementation
+ */
+ const MODE_INTERNAL = 1;
+ /**
+ * To use the OpenSSL library
+ *
+ * (if enabled; otherwise, the internal implementation will be used)
+ */
+ const MODE_OPENSSL = 2;
+ /**#@-*/
+
+ /**#@+
+ * @access public
+ * @see \phpseclib\Crypt\RSA::createKey()
+ * @see \phpseclib\Crypt\RSA::setPrivateKeyFormat()
+ */
+ /**
+ * PKCS#1 formatted private key
+ *
+ * Used by OpenSSH
+ */
+ const PRIVATE_FORMAT_PKCS1 = 0;
+ /**
+ * PuTTY formatted private key
+ */
+ const PRIVATE_FORMAT_PUTTY = 1;
+ /**
+ * XML formatted private key
+ */
+ const PRIVATE_FORMAT_XML = 2;
+ /**
+ * PKCS#8 formatted private key
+ */
+ const PRIVATE_FORMAT_PKCS8 = 8;
+ /**#@-*/
+
+ /**#@+
+ * @access public
+ * @see \phpseclib\Crypt\RSA::createKey()
+ * @see \phpseclib\Crypt\RSA::setPublicKeyFormat()
+ */
+ /**
+ * Raw public key
+ *
+ * An array containing two \phpseclib\Math\BigInteger objects.
+ *
+ * The exponent can be indexed with any of the following:
+ *
+ * 0, e, exponent, publicExponent
+ *
+ * The modulus can be indexed with any of the following:
+ *
+ * 1, n, modulo, modulus
+ */
+ const PUBLIC_FORMAT_RAW = 3;
+ /**
+ * PKCS#1 formatted public key (raw)
+ *
+ * Used by File/X509.php
+ *
+ * Has the following header:
+ *
+ * -----BEGIN RSA PUBLIC KEY-----
+ *
+ * Analogous to ssh-keygen's pem format (as specified by -m)
+ */
+ const PUBLIC_FORMAT_PKCS1 = 4;
+ const PUBLIC_FORMAT_PKCS1_RAW = 4;
+ /**
+ * XML formatted public key
+ */
+ const PUBLIC_FORMAT_XML = 5;
+ /**
+ * OpenSSH formatted public key
+ *
+ * Place in $HOME/.ssh/authorized_keys
+ */
+ const PUBLIC_FORMAT_OPENSSH = 6;
+ /**
+ * PKCS#1 formatted public key (encapsulated)
+ *
+ * Used by PHP's openssl_public_encrypt() and openssl's rsautl (when -pubin is set)
+ *
+ * Has the following header:
+ *
+ * -----BEGIN PUBLIC KEY-----
+ *
+ * Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
+ * is specific to private keys it's basically creating a DER-encoded wrapper
+ * for keys. This just extends that same concept to public keys (much like ssh-keygen)
+ */
+ const PUBLIC_FORMAT_PKCS8 = 7;
+ /**#@-*/
+
/**
* Precomputed Zero
*
- * @var Array
+ * @var \phpseclib\Math\BigInteger
* @access private
*/
var $zero;
@@ -283,7 +253,7 @@ class Crypt_RSA
/**
* Precomputed One
*
- * @var Array
+ * @var \phpseclib\Math\BigInteger
* @access private
*/
var $one;
@@ -291,23 +261,23 @@ class Crypt_RSA
/**
* Private Key Format
*
- * @var Integer
+ * @var int
* @access private
*/
- var $privateKeyFormat = CRYPT_RSA_PRIVATE_FORMAT_PKCS1;
+ var $privateKeyFormat = self::PRIVATE_FORMAT_PKCS1;
/**
* Public Key Format
*
- * @var Integer
+ * @var int
* @access public
*/
- var $publicKeyFormat = CRYPT_RSA_PUBLIC_FORMAT_PKCS8;
+ var $publicKeyFormat = self::PUBLIC_FORMAT_PKCS8;
/**
* Modulus (ie. n)
*
- * @var Math_BigInteger
+ * @var \phpseclib\Math\BigInteger
* @access private
*/
var $modulus;
@@ -315,7 +285,7 @@ class Crypt_RSA
/**
* Modulus length
*
- * @var Math_BigInteger
+ * @var \phpseclib\Math\BigInteger
* @access private
*/
var $k;
@@ -323,7 +293,7 @@ class Crypt_RSA
/**
* Exponent (ie. e or d)
*
- * @var Math_BigInteger
+ * @var \phpseclib\Math\BigInteger
* @access private
*/
var $exponent;
@@ -331,7 +301,7 @@ class Crypt_RSA
/**
* Primes for Chinese Remainder Theorem (ie. p and q)
*
- * @var Array
+ * @var array
* @access private
*/
var $primes;
@@ -339,7 +309,7 @@ class Crypt_RSA
/**
* Exponents for Chinese Remainder Theorem (ie. dP and dQ)
*
- * @var Array
+ * @var array
* @access private
*/
var $exponents;
@@ -347,7 +317,7 @@ class Crypt_RSA
/**
* Coefficients for Chinese Remainder Theorem (ie. qInv)
*
- * @var Array
+ * @var array
* @access private
*/
var $coefficients;
@@ -355,7 +325,7 @@ class Crypt_RSA
/**
* Hash name
*
- * @var String
+ * @var string
* @access private
*/
var $hashName;
@@ -363,7 +333,7 @@ class Crypt_RSA
/**
* Hash function
*
- * @var Crypt_Hash
+ * @var \phpseclib\Crypt\Hash
* @access private
*/
var $hash;
@@ -371,7 +341,7 @@ class Crypt_RSA
/**
* Length of hash function output
*
- * @var Integer
+ * @var int
* @access private
*/
var $hLen;
@@ -379,7 +349,7 @@ class Crypt_RSA
/**
* Length of salt
*
- * @var Integer
+ * @var int
* @access private
*/
var $sLen;
@@ -387,7 +357,7 @@ class Crypt_RSA
/**
* Hash function for the Mask Generation Function
*
- * @var Crypt_Hash
+ * @var \phpseclib\Crypt\Hash
* @access private
*/
var $mgfHash;
@@ -395,7 +365,7 @@ class Crypt_RSA
/**
* Length of MGF hash function output
*
- * @var Integer
+ * @var int
* @access private
*/
var $mgfHLen;
@@ -403,23 +373,23 @@ class Crypt_RSA
/**
* Encryption mode
*
- * @var Integer
+ * @var int
* @access private
*/
- var $encryptionMode = CRYPT_RSA_ENCRYPTION_OAEP;
+ var $encryptionMode = self::ENCRYPTION_OAEP;
/**
* Signature mode
*
- * @var Integer
+ * @var int
* @access private
*/
- var $signatureMode = CRYPT_RSA_SIGNATURE_PSS;
+ var $signatureMode = self::SIGNATURE_PSS;
/**
* Public Exponent
*
- * @var Mixed
+ * @var mixed
* @access private
*/
var $publicExponent = false;
@@ -427,7 +397,7 @@ class Crypt_RSA
/**
* Password
*
- * @var String
+ * @var string
* @access private
*/
var $password = false;
@@ -438,8 +408,8 @@ class Crypt_RSA
* For use with parsing XML formatted keys. PHP's XML Parser functions use utilized - instead of PHP's DOM functions -
* because PHP's XML Parser functions work on PHP4 whereas PHP's DOM functions - although surperior - don't.
*
- * @see Crypt_RSA::_start_element_handler()
- * @var Array
+ * @see self::_start_element_handler()
+ * @var array
* @access private
*/
var $components = array();
@@ -449,9 +419,9 @@ class Crypt_RSA
*
* For use with parsing XML formatted keys.
*
- * @see Crypt_RSA::_character_handler()
- * @see Crypt_RSA::_stop_element_handler()
- * @var Mixed
+ * @see self::_character_handler()
+ * @see self::_stop_element_handler()
+ * @var mixed
* @access private
*/
var $current;
@@ -460,8 +430,8 @@ class Crypt_RSA
* OpenSSL configuration file name.
*
* Set to null to use system configuration file.
- * @see Crypt_RSA::createKey()
- * @var Mixed
+ * @see self::createKey()
+ * @var mixed
* @Access public
*/
var $configFile;
@@ -469,7 +439,7 @@ class Crypt_RSA
/**
* Public key comment field.
*
- * @var String
+ * @var string
* @access private
*/
var $comment = 'phpseclib-generated-key';
@@ -478,33 +448,25 @@ class Crypt_RSA
* The constructor
*
* If you want to make use of the openssl extension, you'll need to set the mode manually, yourself. The reason
- * Crypt_RSA doesn't do it is because OpenSSL doesn't fail gracefully. openssl_pkey_new(), in particular, requires
+ * \phpseclib\Crypt\RSA doesn't do it is because OpenSSL doesn't fail gracefully. openssl_pkey_new(), in particular, requires
* openssl.cnf be present somewhere and, unfortunately, the only real way to find out is too late.
*
- * @return Crypt_RSA
+ * @return \phpseclib\Crypt\RSA
* @access public
*/
- function Crypt_RSA()
+ function __construct()
{
- if (!class_exists('Math_BigInteger')) {
- include_once 'Math/BigInteger.php';
- }
+ $this->configFile = dirname(__FILE__) . '/../openssl.cnf';
- $this->configFile = CRYPT_RSA_OPENSSL_CONFIG;
-
- if ( !defined('CRYPT_RSA_MODE') ) {
+ if (!defined('CRYPT_RSA_MODE')) {
switch (true) {
// Math/BigInteger's openssl requirements are a little less stringent than Crypt/RSA's. in particular,
// Math/BigInteger doesn't require an openssl.cfg file whereas Crypt/RSA does. so if Math/BigInteger
// can't use OpenSSL it can be pretty trivially assumed, then, that Crypt/RSA can't either.
case defined('MATH_BIGINTEGER_OPENSSL_DISABLE'):
- define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
+ define('CRYPT_RSA_MODE', self::MODE_INTERNAL);
break;
- // openssl_pkey_get_details - which is used in the only place Crypt/RSA.php uses OpenSSL - was introduced in PHP 5.2.0
- case !function_exists('openssl_pkey_get_details'):
- define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
- break;
- case extension_loaded('openssl') && version_compare(PHP_VERSION, '4.2.0', '>=') && file_exists($this->configFile):
+ case extension_loaded('openssl') && file_exists($this->configFile):
// some versions of XAMPP have mismatched versions of OpenSSL which causes it not to work
ob_start();
@phpinfo();
@@ -532,25 +494,26 @@ class Crypt_RSA
case !isset($versions['Header']):
case !isset($versions['Library']):
case $versions['Header'] == $versions['Library']:
- define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_OPENSSL);
+ case version_compare($versions['Header'], '1.0.0') >= 0 && version_compare($versions['Library'], '1.0.0') >= 0:
+ define('CRYPT_RSA_MODE', self::MODE_OPENSSL);
break;
default:
- define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
+ define('CRYPT_RSA_MODE', self::MODE_INTERNAL);
define('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
}
break;
default:
- define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
+ define('CRYPT_RSA_MODE', self::MODE_INTERNAL);
}
}
- $this->zero = new Math_BigInteger();
- $this->one = new Math_BigInteger(1);
+ $this->zero = new BigInteger();
+ $this->one = new BigInteger(1);
- $this->hash = new Crypt_Hash('sha1');
+ $this->hash = new Hash('sha1');
$this->hLen = $this->hash->getLength();
$this->hashName = 'sha1';
- $this->mgfHash = new Crypt_Hash('sha1');
+ $this->mgfHash = new Hash('sha1');
$this->mgfHLen = $this->mgfHash->getLength();
}
@@ -561,12 +524,12 @@ class Crypt_RSA
* - 'privatekey': The private key.
* - 'publickey': The public key.
* - 'partialkey': A partially computed key (if the execution time exceeded $timeout).
- * Will need to be passed back to Crypt_RSA::createKey() as the third parameter for further processing.
+ * Will need to be passed back to \phpseclib\Crypt\RSA::createKey() as the third parameter for further processing.
*
* @access public
- * @param optional Integer $bits
- * @param optional Integer $timeout
- * @param optional Math_BigInteger $p
+ * @param int $bits
+ * @param int $timeout
+ * @param array $p
*/
function createKey($bits = 1024, $timeout = false, $partial = array())
{
@@ -577,7 +540,7 @@ class Crypt_RSA
// per , this number ought not result in primes smaller
// than 256 bits. as a consequence if the key you're trying to create is 1024 bits and you've set CRYPT_RSA_SMALLEST_PRIME
// to 384 bits then you're going to get a 384 bit prime and a 640 bit prime (384 + 1024 % 384). at least if
- // CRYPT_RSA_MODE is set to CRYPT_RSA_MODE_INTERNAL. if CRYPT_RSA_MODE is set to CRYPT_RSA_MODE_OPENSSL then
+ // CRYPT_RSA_MODE is set to self::MODE_INTERNAL. if CRYPT_RSA_MODE is set to self::MODE_OPENSSL then
// CRYPT_RSA_SMALLEST_PRIME is ignored (ie. multi-prime RSA support is more intended as a way to speed up RSA key
// generation when there's a chance neither gmp nor OpenSSL are installed)
if (!defined('CRYPT_RSA_SMALLEST_PRIME')) {
@@ -585,7 +548,7 @@ class Crypt_RSA
}
// OpenSSL uses 65537 as the exponent and requires RSA keys be 384 bits minimum
- if ( CRYPT_RSA_MODE == CRYPT_RSA_MODE_OPENSSL && $bits >= 384 && CRYPT_RSA_EXPONENT == 65537) {
+ if (CRYPT_RSA_MODE == self::MODE_OPENSSL && $bits >= 384 && CRYPT_RSA_EXPONENT == 65537) {
$config = array();
if (isset($this->configFile)) {
$config['config'] = $this->configFile;
@@ -595,11 +558,12 @@ class Crypt_RSA
$publickey = openssl_pkey_get_details($rsa);
$publickey = $publickey['key'];
- $privatekey = call_user_func_array(array($this, '_convertPrivateKey'), array_values($this->_parseKey($privatekey, CRYPT_RSA_PRIVATE_FORMAT_PKCS1)));
- $publickey = call_user_func_array(array($this, '_convertPublicKey'), array_values($this->_parseKey($publickey, CRYPT_RSA_PUBLIC_FORMAT_PKCS1)));
+ $privatekey = call_user_func_array(array($this, '_convertPrivateKey'), array_values($this->_parseKey($privatekey, self::PRIVATE_FORMAT_PKCS1)));
+ $publickey = call_user_func_array(array($this, '_convertPublicKey'), array_values($this->_parseKey($publickey, self::PUBLIC_FORMAT_PKCS1)));
// clear the buffer of error strings stemming from a minimalistic openssl.cnf
- while (openssl_error_string() !== false);
+ while (openssl_error_string() !== false) {
+ }
return array(
'privatekey' => $privatekey,
@@ -610,7 +574,7 @@ class Crypt_RSA
static $e;
if (!isset($e)) {
- $e = new Math_BigInteger(CRYPT_RSA_EXPONENT);
+ $e = new BigInteger(CRYPT_RSA_EXPONENT);
}
extract($this->_generateMinMax($bits));
@@ -626,7 +590,7 @@ class Crypt_RSA
$finalMax = $max;
extract($this->_generateMinMax($temp));
- $generator = new Math_BigInteger();
+ $generator = new BigInteger();
$n = $this->one->copy();
if (!empty($partial)) {
@@ -743,13 +707,13 @@ class Crypt_RSA
* Convert a private key to the appropriate format.
*
* @access private
- * @see setPrivateKeyFormat()
- * @param String $RSAPrivateKey
- * @return String
+ * @see self::setPrivateKeyFormat()
+ * @param string $RSAPrivateKey
+ * @return string
*/
function _convertPrivateKey($n, $e, $d, $primes, $exponents, $coefficients)
{
- $signed = $this->privateKeyFormat != CRYPT_RSA_PRIVATE_FORMAT_XML;
+ $signed = $this->privateKeyFormat != self::PRIVATE_FORMAT_XML;
$num_primes = count($primes);
$raw = array(
'version' => $num_primes == 2 ? chr(0) : chr(1), // two-prime vs. multi
@@ -766,7 +730,7 @@ class Crypt_RSA
// if the format in question does not support multi-prime rsa and multi-prime rsa was used,
// call _convertPublicKey() instead.
switch ($this->privateKeyFormat) {
- case CRYPT_RSA_PRIVATE_FORMAT_XML:
+ case self::PRIVATE_FORMAT_XML:
if ($num_primes != 2) {
return false;
}
@@ -781,7 +745,7 @@ class Crypt_RSA
' ' . base64_encode($raw['privateExponent']) . "\r\n" .
'';
break;
- case CRYPT_RSA_PRIVATE_FORMAT_PUTTY:
+ case self::PRIVATE_FORMAT_PUTTY:
if ($num_primes != 2) {
return false;
}
@@ -789,29 +753,46 @@ class Crypt_RSA
$encryption = (!empty($this->password) || is_string($this->password)) ? 'aes256-cbc' : 'none';
$key.= $encryption;
$key.= "\r\nComment: " . $this->comment . "\r\n";
- $public = pack('Na*Na*Na*',
- strlen('ssh-rsa'), 'ssh-rsa', strlen($raw['publicExponent']), $raw['publicExponent'], strlen($raw['modulus']), $raw['modulus']
+ $public = pack(
+ 'Na*Na*Na*',
+ strlen('ssh-rsa'),
+ 'ssh-rsa',
+ strlen($raw['publicExponent']),
+ $raw['publicExponent'],
+ strlen($raw['modulus']),
+ $raw['modulus']
);
- $source = pack('Na*Na*Na*Na*',
- strlen('ssh-rsa'), 'ssh-rsa', strlen($encryption), $encryption,
- strlen($this->comment), $this->comment, strlen($public), $public
+ $source = pack(
+ 'Na*Na*Na*Na*',
+ strlen('ssh-rsa'),
+ 'ssh-rsa',
+ strlen($encryption),
+ $encryption,
+ strlen($this->comment),
+ $this->comment,
+ strlen($public),
+ $public
);
$public = base64_encode($public);
$key.= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n";
$key.= chunk_split($public, 64);
- $private = pack('Na*Na*Na*Na*',
- strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'],
- strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient']
+ $private = pack(
+ 'Na*Na*Na*Na*',
+ strlen($raw['privateExponent']),
+ $raw['privateExponent'],
+ strlen($raw['prime1']),
+ $raw['prime1'],
+ strlen($raw['prime2']),
+ $raw['prime2'],
+ strlen($raw['coefficient']),
+ $raw['coefficient']
);
if (empty($this->password) && !is_string($this->password)) {
$source.= pack('Na*', strlen($private), $private);
$hashkey = 'putty-private-key-file-mac-key';
} else {
- $private.= crypt_random_string(16 - (strlen($private) & 15));
+ $private.= Random::string(16 - (strlen($private) & 15));
$source.= pack('Na*', strlen($private), $private);
- if (!class_exists('Crypt_AES')) {
- include_once 'Crypt/AES.php';
- }
$sequence = 0;
$symkey = '';
while (strlen($symkey) < 32) {
@@ -819,7 +800,7 @@ class Crypt_RSA
$symkey.= pack('H*', sha1($temp));
}
$symkey = substr($symkey, 0, 32);
- $crypto = new Crypt_AES();
+ $crypto = new AES();
$crypto->setKey($symkey);
$crypto->disablePadding();
@@ -830,18 +811,15 @@ class Crypt_RSA
$private = base64_encode($private);
$key.= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
$key.= chunk_split($private, 64);
- if (!class_exists('Crypt_Hash')) {
- include_once 'Crypt/Hash.php';
- }
- $hash = new Crypt_Hash('sha1');
+ $hash = new Hash('sha1');
$hash->setKey(pack('H*', sha1($hashkey)));
$key.= 'Private-MAC: ' . bin2hex($hash->hash($source)) . "\r\n";
return $key;
- default: // eg. CRYPT_RSA_PRIVATE_FORMAT_PKCS1
+ default: // eg. self::PRIVATE_FORMAT_PKCS1
$components = array();
foreach ($raw as $name => $value) {
- $components[$name] = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($value)), $value);
+ $components[$name] = pack('Ca*a*', self::ASN1_INTEGER, $this->_encodeLength(strlen($value)), $value);
}
$RSAPrivateKey = implode('', $components);
@@ -856,50 +834,68 @@ class Crypt_RSA
// exponent INTEGER, -- di
// coefficient INTEGER -- ti
// }
- $OtherPrimeInfo = pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($primes[$i]->toBytes(true))), $primes[$i]->toBytes(true));
- $OtherPrimeInfo.= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true));
- $OtherPrimeInfo.= pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true));
- $OtherPrimeInfos.= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo);
+ $OtherPrimeInfo = pack('Ca*a*', self::ASN1_INTEGER, $this->_encodeLength(strlen($primes[$i]->toBytes(true))), $primes[$i]->toBytes(true));
+ $OtherPrimeInfo.= pack('Ca*a*', self::ASN1_INTEGER, $this->_encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true));
+ $OtherPrimeInfo.= pack('Ca*a*', self::ASN1_INTEGER, $this->_encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true));
+ $OtherPrimeInfos.= pack('Ca*a*', self::ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo);
}
- $RSAPrivateKey.= pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos);
+ $RSAPrivateKey.= pack('Ca*a*', self::ASN1_SEQUENCE, $this->_encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos);
}
- $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
+ $RSAPrivateKey = pack('Ca*a*', self::ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
- if ($this->privateKeyFormat == CRYPT_RSA_PRIVATE_FORMAT_PKCS8) {
+ if ($this->privateKeyFormat == self::PRIVATE_FORMAT_PKCS8) {
$rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
- $RSAPrivateKey = pack('Ca*a*Ca*a*',
- CRYPT_RSA_ASN1_INTEGER, "\01\00", $rsaOID, 4, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey
+ $RSAPrivateKey = pack(
+ 'Ca*a*Ca*a*',
+ self::ASN1_INTEGER,
+ "\01\00",
+ $rsaOID,
+ 4,
+ $this->_encodeLength(strlen($RSAPrivateKey)),
+ $RSAPrivateKey
);
- $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
+ $RSAPrivateKey = pack('Ca*a*', self::ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
if (!empty($this->password) || is_string($this->password)) {
- $salt = crypt_random_string(8);
+ $salt = Random::string(8);
$iterationCount = 2048;
- if (!class_exists('Crypt_DES')) {
- include_once 'Crypt/DES.php';
- }
- $crypto = new Crypt_DES();
+ $crypto = new DES();
$crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount);
$RSAPrivateKey = $crypto->encrypt($RSAPrivateKey);
- $parameters = pack('Ca*a*Ca*N',
- CRYPT_RSA_ASN1_OCTETSTRING, $this->_encodeLength(strlen($salt)), $salt,
- CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(4), $iterationCount
+ $parameters = pack(
+ 'Ca*a*Ca*N',
+ self::ASN1_OCTETSTRING,
+ $this->_encodeLength(strlen($salt)),
+ $salt,
+ self::ASN1_INTEGER,
+ $this->_encodeLength(4),
+ $iterationCount
);
$pbeWithMD5AndDES_CBC = "\x2a\x86\x48\x86\xf7\x0d\x01\x05\x03";
- $encryptionAlgorithm = pack('Ca*a*Ca*a*',
- CRYPT_RSA_ASN1_OBJECT, $this->_encodeLength(strlen($pbeWithMD5AndDES_CBC)), $pbeWithMD5AndDES_CBC,
- CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($parameters)), $parameters
+ $encryptionAlgorithm = pack(
+ 'Ca*a*Ca*a*',
+ self::ASN1_OBJECT,
+ $this->_encodeLength(strlen($pbeWithMD5AndDES_CBC)),
+ $pbeWithMD5AndDES_CBC,
+ self::ASN1_SEQUENCE,
+ $this->_encodeLength(strlen($parameters)),
+ $parameters
);
- $RSAPrivateKey = pack('Ca*a*Ca*a*',
- CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($encryptionAlgorithm)), $encryptionAlgorithm,
- CRYPT_RSA_ASN1_OCTETSTRING, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey
+ $RSAPrivateKey = pack(
+ 'Ca*a*Ca*a*',
+ self::ASN1_SEQUENCE,
+ $this->_encodeLength(strlen($encryptionAlgorithm)),
+ $encryptionAlgorithm,
+ self::ASN1_OCTETSTRING,
+ $this->_encodeLength(strlen($RSAPrivateKey)),
+ $RSAPrivateKey
);
- $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
+ $RSAPrivateKey = pack('Ca*a*', self::ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
$RSAPrivateKey = "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" .
chunk_split(base64_encode($RSAPrivateKey), 64) .
@@ -913,13 +909,10 @@ class Crypt_RSA
}
if (!empty($this->password) || is_string($this->password)) {
- $iv = crypt_random_string(8);
+ $iv = Random::string(8);
$symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key
$symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
- if (!class_exists('Crypt_TripleDES')) {
- include_once 'Crypt/TripleDES.php';
- }
- $des = new Crypt_TripleDES();
+ $des = new TripleDES();
$des->setKey($symkey);
$des->setIV($iv);
$iv = strtoupper(bin2hex($iv));
@@ -943,27 +936,27 @@ class Crypt_RSA
* Convert a public key to the appropriate format
*
* @access private
- * @see setPublicKeyFormat()
- * @param String $RSAPrivateKey
- * @return String
+ * @see self::setPublicKeyFormat()
+ * @param string $RSAPrivateKey
+ * @return string
*/
function _convertPublicKey($n, $e)
{
- $signed = $this->publicKeyFormat != CRYPT_RSA_PUBLIC_FORMAT_XML;
+ $signed = $this->publicKeyFormat != self::PUBLIC_FORMAT_XML;
$modulus = $n->toBytes($signed);
$publicExponent = $e->toBytes($signed);
switch ($this->publicKeyFormat) {
- case CRYPT_RSA_PUBLIC_FORMAT_RAW:
+ case self::PUBLIC_FORMAT_RAW:
return array('e' => $e->copy(), 'n' => $n->copy());
- case CRYPT_RSA_PUBLIC_FORMAT_XML:
+ case self::PUBLIC_FORMAT_XML:
return "\r\n" .
' ' . base64_encode($modulus) . "\r\n" .
' ' . base64_encode($publicExponent) . "\r\n" .
'';
break;
- case CRYPT_RSA_PUBLIC_FORMAT_OPENSSH:
+ case self::PUBLIC_FORMAT_OPENSSH:
// from :
// string "ssh-rsa"
// mpint e
@@ -972,23 +965,26 @@ class Crypt_RSA
$RSAPublicKey = 'ssh-rsa ' . base64_encode($RSAPublicKey) . ' ' . $this->comment;
return $RSAPublicKey;
- default: // eg. CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW or CRYPT_RSA_PUBLIC_FORMAT_PKCS1
+ default: // eg. self::PUBLIC_FORMAT_PKCS1_RAW or self::PUBLIC_FORMAT_PKCS1
// from :
// RSAPublicKey ::= SEQUENCE {
// modulus INTEGER, -- n
// publicExponent INTEGER -- e
// }
$components = array(
- 'modulus' => pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($modulus)), $modulus),
- 'publicExponent' => pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($publicExponent)), $publicExponent)
+ 'modulus' => pack('Ca*a*', self::ASN1_INTEGER, $this->_encodeLength(strlen($modulus)), $modulus),
+ 'publicExponent' => pack('Ca*a*', self::ASN1_INTEGER, $this->_encodeLength(strlen($publicExponent)), $publicExponent)
);
- $RSAPublicKey = pack('Ca*a*a*',
- CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])),
- $components['modulus'], $components['publicExponent']
+ $RSAPublicKey = pack(
+ 'Ca*a*a*',
+ self::ASN1_SEQUENCE,
+ $this->_encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])),
+ $components['modulus'],
+ $components['publicExponent']
);
- if ($this->publicKeyFormat == CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW) {
+ if ($this->publicKeyFormat == self::PUBLIC_FORMAT_PKCS1_RAW) {
$RSAPublicKey = "-----BEGIN RSA PUBLIC KEY-----\r\n" .
chunk_split(base64_encode($RSAPublicKey), 64) .
'-----END RSA PUBLIC KEY-----';
@@ -998,8 +994,11 @@ class Crypt_RSA
$RSAPublicKey = chr(0) . $RSAPublicKey;
$RSAPublicKey = chr(3) . $this->_encodeLength(strlen($RSAPublicKey)) . $RSAPublicKey;
- $RSAPublicKey = pack('Ca*a*',
- CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($rsaOID . $RSAPublicKey)), $rsaOID . $RSAPublicKey
+ $RSAPublicKey = pack(
+ 'Ca*a*',
+ self::ASN1_SEQUENCE,
+ $this->_encodeLength(strlen($rsaOID . $RSAPublicKey)),
+ $rsaOID . $RSAPublicKey
);
$RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
@@ -1015,20 +1014,20 @@ class Crypt_RSA
* Break a public or private key down into its constituant components
*
* @access private
- * @see _convertPublicKey()
- * @see _convertPrivateKey()
- * @param String $key
- * @param Integer $type
- * @return Array
+ * @see self::_convertPublicKey()
+ * @see self::_convertPrivateKey()
+ * @param string $key
+ * @param int $type
+ * @return array
*/
function _parseKey($key, $type)
{
- if ($type != CRYPT_RSA_PUBLIC_FORMAT_RAW && !is_string($key)) {
+ if ($type != self::PUBLIC_FORMAT_RAW && !is_string($key)) {
return false;
}
switch ($type) {
- case CRYPT_RSA_PUBLIC_FORMAT_RAW:
+ case self::PUBLIC_FORMAT_RAW:
if (!is_array($key)) {
return false;
}
@@ -1060,9 +1059,9 @@ class Crypt_RSA
$components['modulus'] = $key[1]->copy();
}
return isset($components['modulus']) && isset($components['publicExponent']) ? $components : false;
- case CRYPT_RSA_PRIVATE_FORMAT_PKCS1:
- case CRYPT_RSA_PRIVATE_FORMAT_PKCS8:
- case CRYPT_RSA_PUBLIC_FORMAT_PKCS1:
+ case self::PRIVATE_FORMAT_PKCS1:
+ case self::PRIVATE_FORMAT_PKCS8:
+ case self::PUBLIC_FORMAT_PKCS1:
/* Although PKCS#1 proposes a format that public and private keys can use, encrypting them is
"outside the scope" of PKCS#1. PKCS#1 then refers you to PKCS#12 and PKCS#15 if you're wanting to
protect private keys, however, that's not what OpenSSL* does. OpenSSL protects private keys by adding
@@ -1090,36 +1089,21 @@ class Crypt_RSA
}
switch ($matches[1]) {
case 'AES-256-CBC':
- if (!class_exists('Crypt_AES')) {
- include_once 'Crypt/AES.php';
- }
- $crypto = new Crypt_AES();
+ $crypto = new AES();
break;
case 'AES-128-CBC':
- if (!class_exists('Crypt_AES')) {
- include_once 'Crypt/AES.php';
- }
$symkey = substr($symkey, 0, 16);
- $crypto = new Crypt_AES();
+ $crypto = new AES();
break;
case 'DES-EDE3-CFB':
- if (!class_exists('Crypt_TripleDES')) {
- include_once 'Crypt/TripleDES.php';
- }
- $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
+ $crypto = new TripleDES(Base::MODE_CFB);
break;
case 'DES-EDE3-CBC':
- if (!class_exists('Crypt_TripleDES')) {
- include_once 'Crypt/TripleDES.php';
- }
$symkey = substr($symkey, 0, 24);
- $crypto = new Crypt_TripleDES();
+ $crypto = new TripleDES();
break;
case 'DES-CBC':
- if (!class_exists('Crypt_DES')) {
- include_once 'Crypt/DES.php';
- }
- $crypto = new Crypt_DES();
+ $crypto = new DES();
break;
default:
return false;
@@ -1137,7 +1121,7 @@ class Crypt_RSA
$components = array();
- if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
+ if (ord($this->_string_shift($key)) != self::ASN1_SEQUENCE) {
return false;
}
if ($this->_decodeLength($key) != strlen($key)) {
@@ -1156,14 +1140,14 @@ class Crypt_RSA
ie. PKCS8 keys*/
- if ($tag == CRYPT_RSA_ASN1_INTEGER && substr($key, 0, 3) == "\x01\x00\x30") {
+ if ($tag == self::ASN1_INTEGER && substr($key, 0, 3) == "\x01\x00\x30") {
$this->_string_shift($key, 3);
- $tag = CRYPT_RSA_ASN1_SEQUENCE;
+ $tag = self::ASN1_SEQUENCE;
}
- if ($tag == CRYPT_RSA_ASN1_SEQUENCE) {
+ if ($tag == self::ASN1_SEQUENCE) {
$temp = $this->_string_shift($key, $this->_decodeLength($key));
- if (ord($this->_string_shift($temp)) != CRYPT_RSA_ASN1_OBJECT) {
+ if (ord($this->_string_shift($temp)) != self::ASN1_OBJECT) {
return false;
}
$length = $this->_decodeLength($temp);
@@ -1176,7 +1160,7 @@ class Crypt_RSA
salt OCTET STRING (SIZE(8)),
iterationCount INTEGER }
*/
- if (ord($this->_string_shift($temp)) != CRYPT_RSA_ASN1_SEQUENCE) {
+ if (ord($this->_string_shift($temp)) != self::ASN1_SEQUENCE) {
return false;
}
if ($this->_decodeLength($temp) != strlen($temp)) {
@@ -1184,7 +1168,7 @@ class Crypt_RSA
}
$this->_string_shift($temp); // assume it's an octet string
$salt = $this->_string_shift($temp, $this->_decodeLength($temp));
- if (ord($this->_string_shift($temp)) != CRYPT_RSA_ASN1_INTEGER) {
+ if (ord($this->_string_shift($temp)) != self::ASN1_INTEGER) {
return false;
}
$this->_decodeLength($temp);
@@ -1195,16 +1179,13 @@ class Crypt_RSA
return false;
}
- if (!class_exists('Crypt_DES')) {
- include_once 'Crypt/DES.php';
- }
- $crypto = new Crypt_DES();
+ $crypto = new DES();
$crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount);
$key = $crypto->decrypt($key);
if ($key === false) {
return false;
}
- return $this->_parseKey($key, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
+ return $this->_parseKey($key, self::PRIVATE_FORMAT_PKCS1);
default:
return false;
}
@@ -1220,10 +1201,10 @@ class Crypt_RSA
// "The initial octet shall encode, as an unsigned binary integer wtih bit 1 as the least significant bit, the number of
// unused bits in the final subsequent octet. The number shall be in the range zero to seven."
// -- http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf (section 8.6.2.2)
- if ($tag == CRYPT_RSA_ASN1_BITSTRING) {
+ if ($tag == self::ASN1_BITSTRING) {
$this->_string_shift($key);
}
- if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
+ if (ord($this->_string_shift($key)) != self::ASN1_SEQUENCE) {
return false;
}
if ($this->_decodeLength($key) != strlen($key)) {
@@ -1231,71 +1212,71 @@ class Crypt_RSA
}
$tag = ord($this->_string_shift($key));
}
- if ($tag != CRYPT_RSA_ASN1_INTEGER) {
+ if ($tag != self::ASN1_INTEGER) {
return false;
}
$length = $this->_decodeLength($key);
$temp = $this->_string_shift($key, $length);
if (strlen($temp) != 1 || ord($temp) > 2) {
- $components['modulus'] = new Math_BigInteger($temp, 256);
- $this->_string_shift($key); // skip over CRYPT_RSA_ASN1_INTEGER
+ $components['modulus'] = new BigInteger($temp, 256);
+ $this->_string_shift($key); // skip over self::ASN1_INTEGER
$length = $this->_decodeLength($key);
- $components[$type == CRYPT_RSA_PUBLIC_FORMAT_PKCS1 ? 'publicExponent' : 'privateExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components[$type == self::PUBLIC_FORMAT_PKCS1 ? 'publicExponent' : 'privateExponent'] = new BigInteger($this->_string_shift($key, $length), 256);
return $components;
}
- if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_INTEGER) {
+ if (ord($this->_string_shift($key)) != self::ASN1_INTEGER) {
return false;
}
$length = $this->_decodeLength($key);
- $components['modulus'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['modulus'] = new BigInteger($this->_string_shift($key, $length), 256);
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['publicExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['publicExponent'] = new BigInteger($this->_string_shift($key, $length), 256);
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['privateExponent'] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['privateExponent'] = new BigInteger($this->_string_shift($key, $length), 256);
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['primes'] = array(1 => new Math_BigInteger($this->_string_shift($key, $length), 256));
+ $components['primes'] = array(1 => new BigInteger($this->_string_shift($key, $length), 256));
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['primes'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['primes'][] = new BigInteger($this->_string_shift($key, $length), 256);
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['exponents'] = array(1 => new Math_BigInteger($this->_string_shift($key, $length), 256));
+ $components['exponents'] = array(1 => new BigInteger($this->_string_shift($key, $length), 256));
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['exponents'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['exponents'][] = new BigInteger($this->_string_shift($key, $length), 256);
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['coefficients'] = array(2 => new Math_BigInteger($this->_string_shift($key, $length), 256));
+ $components['coefficients'] = array(2 => new BigInteger($this->_string_shift($key, $length), 256));
if (!empty($key)) {
- if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
+ if (ord($this->_string_shift($key)) != self::ASN1_SEQUENCE) {
return false;
}
$this->_decodeLength($key);
while (!empty($key)) {
- if (ord($this->_string_shift($key)) != CRYPT_RSA_ASN1_SEQUENCE) {
+ if (ord($this->_string_shift($key)) != self::ASN1_SEQUENCE) {
return false;
}
$this->_decodeLength($key);
$key = substr($key, 1);
$length = $this->_decodeLength($key);
- $components['primes'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['primes'][] = new BigInteger($this->_string_shift($key, $length), 256);
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['exponents'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['exponents'][] = new BigInteger($this->_string_shift($key, $length), 256);
$this->_string_shift($key);
$length = $this->_decodeLength($key);
- $components['coefficients'][] = new Math_BigInteger($this->_string_shift($key, $length), 256);
+ $components['coefficients'][] = new BigInteger($this->_string_shift($key, $length), 256);
}
}
return $components;
- case CRYPT_RSA_PUBLIC_FORMAT_OPENSSH:
+ case self::PUBLIC_FORMAT_OPENSSH:
$parts = explode(' ', $key, 3);
$key = isset($parts[1]) ? base64_decode($parts[1]) : false;
@@ -1311,19 +1292,19 @@ class Crypt_RSA
return false;
}
extract(unpack('Nlength', $this->_string_shift($key, 4)));
- $publicExponent = new Math_BigInteger($this->_string_shift($key, $length), -256);
+ $publicExponent = new BigInteger($this->_string_shift($key, $length), -256);
if (strlen($key) <= 4) {
return false;
}
extract(unpack('Nlength', $this->_string_shift($key, 4)));
- $modulus = new Math_BigInteger($this->_string_shift($key, $length), -256);
+ $modulus = new BigInteger($this->_string_shift($key, $length), -256);
if ($cleanup && strlen($key)) {
if (strlen($key) <= 4) {
return false;
}
extract(unpack('Nlength', $this->_string_shift($key, 4)));
- $realModulus = new Math_BigInteger($this->_string_shift($key, $length), -256);
+ $realModulus = new BigInteger($this->_string_shift($key, $length), -256);
return strlen($key) ? false : array(
'modulus' => $realModulus,
'publicExponent' => $modulus,
@@ -1338,8 +1319,8 @@ class Crypt_RSA
}
// http://www.w3.org/TR/xmldsig-core/#sec-RSAKeyValue
// http://en.wikipedia.org/wiki/XML_Signature
- case CRYPT_RSA_PRIVATE_FORMAT_XML:
- case CRYPT_RSA_PUBLIC_FORMAT_XML:
+ case self::PRIVATE_FORMAT_XML:
+ case self::PUBLIC_FORMAT_XML:
$this->components = array();
$xml = xml_parser_create('UTF-8');
@@ -1353,7 +1334,7 @@ class Crypt_RSA
return isset($this->components['modulus']) && isset($this->components['publicExponent']) ? $this->components : false;
// from PuTTY's SSHPUBK.C
- case CRYPT_RSA_PRIVATE_FORMAT_PUTTY:
+ case self::PRIVATE_FORMAT_PUTTY:
$components = array();
$key = preg_split('#\r\n|\r|\n#', $key);
$type = trim(preg_replace('#PuTTY-User-Key-File-2: (.+)#', '$1', $key[0]));
@@ -1367,18 +1348,15 @@ class Crypt_RSA
$public = base64_decode(implode('', array_map('trim', array_slice($key, 4, $publicLength))));
$public = substr($public, 11);
extract(unpack('Nlength', $this->_string_shift($public, 4)));
- $components['publicExponent'] = new Math_BigInteger($this->_string_shift($public, $length), -256);
+ $components['publicExponent'] = new BigInteger($this->_string_shift($public, $length), -256);
extract(unpack('Nlength', $this->_string_shift($public, 4)));
- $components['modulus'] = new Math_BigInteger($this->_string_shift($public, $length), -256);
+ $components['modulus'] = new BigInteger($this->_string_shift($public, $length), -256);
$privateLength = trim(preg_replace('#Private-Lines: (\d+)#', '$1', $key[$publicLength + 4]));
$private = base64_decode(implode('', array_map('trim', array_slice($key, $publicLength + 5, $privateLength))));
switch ($encryption) {
case 'aes256-cbc':
- if (!class_exists('Crypt_AES')) {
- include_once 'Crypt/AES.php';
- }
$symkey = '';
$sequence = 0;
while (strlen($symkey) < 32) {
@@ -1386,7 +1364,7 @@ class Crypt_RSA
$symkey.= pack('H*', sha1($temp));
}
$symkey = substr($symkey, 0, 32);
- $crypto = new Crypt_AES();
+ $crypto = new AES();
}
if ($encryption != 'none') {
@@ -1402,17 +1380,17 @@ class Crypt_RSA
if (strlen($private) < $length) {
return false;
}
- $components['privateExponent'] = new Math_BigInteger($this->_string_shift($private, $length), -256);
+ $components['privateExponent'] = new BigInteger($this->_string_shift($private, $length), -256);
extract(unpack('Nlength', $this->_string_shift($private, 4)));
if (strlen($private) < $length) {
return false;
}
- $components['primes'] = array(1 => new Math_BigInteger($this->_string_shift($private, $length), -256));
+ $components['primes'] = array(1 => new BigInteger($this->_string_shift($private, $length), -256));
extract(unpack('Nlength', $this->_string_shift($private, 4)));
if (strlen($private) < $length) {
return false;
}
- $components['primes'][] = new Math_BigInteger($this->_string_shift($private, $length), -256);
+ $components['primes'][] = new BigInteger($this->_string_shift($private, $length), -256);
$temp = $components['primes'][1]->subtract($this->one);
$components['exponents'] = array(1 => $components['publicExponent']->modInverse($temp));
@@ -1423,7 +1401,7 @@ class Crypt_RSA
if (strlen($private) < $length) {
return false;
}
- $components['coefficients'] = array(2 => new Math_BigInteger($this->_string_shift($private, $length), -256));
+ $components['coefficients'] = array(2 => new BigInteger($this->_string_shift($private, $length), -256));
return $components;
}
@@ -1435,7 +1413,7 @@ class Crypt_RSA
* More specifically, this returns the size of the modulo in bits.
*
* @access public
- * @return Integer
+ * @return int
*/
function getSize()
{
@@ -1448,9 +1426,9 @@ class Crypt_RSA
* Called by xml_set_element_handler()
*
* @access private
- * @param Resource $parser
- * @param String $name
- * @param Array $attribs
+ * @param resource $parser
+ * @param string $name
+ * @param array $attribs
*/
function _start_element_handler($parser, $name, $attribs)
{
@@ -1489,13 +1467,13 @@ class Crypt_RSA
* Called by xml_set_element_handler()
*
* @access private
- * @param Resource $parser
- * @param String $name
+ * @param resource $parser
+ * @param string $name
*/
function _stop_element_handler($parser, $name)
{
if (isset($this->current)) {
- $this->current = new Math_BigInteger(base64_decode($this->current), 256);
+ $this->current = new BigInteger(base64_decode($this->current), 256);
unset($this->current);
}
}
@@ -1506,8 +1484,8 @@ class Crypt_RSA
* Called by xml_set_character_data_handler()
*
* @access private
- * @param Resource $parser
- * @param String $data
+ * @param resource $parser
+ * @param string $data
*/
function _data_handler($parser, $data)
{
@@ -1523,12 +1501,12 @@ class Crypt_RSA
* Returns true on success and false on failure (ie. an incorrect password was provided or the key was malformed)
*
* @access public
- * @param String $key
- * @param Integer $type optional
+ * @param string $key
+ * @param int $type optional
*/
function loadKey($key, $type = false)
{
- if (is_object($key) && strtolower(get_class($key)) == 'crypt_rsa') {
+ if ($key instanceof RSA) {
$this->privateKeyFormat = $key->privateKeyFormat;
$this->publicKeyFormat = $key->publicKeyFormat;
$this->k = $key->k;
@@ -1542,10 +1520,10 @@ class Crypt_RSA
$this->comment = $key->comment;
if (is_object($key->hash)) {
- $this->hash = new Crypt_Hash($key->hash->getHash());
+ $this->hash = new Hash($key->hash->getHash());
}
if (is_object($key->mgfHash)) {
- $this->mgfHash = new Crypt_Hash($key->mgfHash->getHash());
+ $this->mgfHash = new Hash($key->mgfHash->getHash());
}
if (is_object($key->modulus)) {
@@ -1577,11 +1555,11 @@ class Crypt_RSA
if ($type === false) {
$types = array(
- CRYPT_RSA_PUBLIC_FORMAT_RAW,
- CRYPT_RSA_PRIVATE_FORMAT_PKCS1,
- CRYPT_RSA_PRIVATE_FORMAT_XML,
- CRYPT_RSA_PRIVATE_FORMAT_PUTTY,
- CRYPT_RSA_PUBLIC_FORMAT_OPENSSH
+ self::PUBLIC_FORMAT_RAW,
+ self::PRIVATE_FORMAT_PKCS1,
+ self::PRIVATE_FORMAT_XML,
+ self::PRIVATE_FORMAT_PUTTY,
+ self::PUBLIC_FORMAT_OPENSSH
);
foreach ($types as $type) {
$components = $this->_parseKey($key, $type);
@@ -1589,7 +1567,6 @@ class Crypt_RSA
break;
}
}
-
} else {
$components = $this->_parseKey($key, $type);
}
@@ -1617,11 +1594,11 @@ class Crypt_RSA
}
switch ($type) {
- case CRYPT_RSA_PUBLIC_FORMAT_OPENSSH:
- case CRYPT_RSA_PUBLIC_FORMAT_RAW:
+ case self::PUBLIC_FORMAT_OPENSSH:
+ case self::PUBLIC_FORMAT_RAW:
$this->setPublicKey();
break;
- case CRYPT_RSA_PRIVATE_FORMAT_PKCS1:
+ case self::PRIVATE_FORMAT_PKCS1:
switch (true) {
case strpos($key, '-BEGIN PUBLIC KEY-') !== false:
case strpos($key, '-BEGIN RSA PUBLIC KEY-') !== false:
@@ -1638,10 +1615,10 @@ class Crypt_RSA
* Private keys can be encrypted with a password. To unset the password, pass in the empty string or false.
* Or rather, pass in $password such that empty($password) && !is_string($password) is true.
*
- * @see createKey()
- * @see loadKey()
+ * @see self::createKey()
+ * @see self::loadKey()
* @access public
- * @param String $password
+ * @param string $password
*/
function setPassword($password = false)
{
@@ -1663,11 +1640,11 @@ class Crypt_RSA
*
* Returns true on success, false on failure
*
- * @see getPublicKey()
+ * @see self::getPublicKey()
* @access public
- * @param String $key optional
- * @param Integer $type optional
- * @return Boolean
+ * @param string $key optional
+ * @param int $type optional
+ * @return bool
*/
function setPublicKey($key = false, $type = false)
{
@@ -1683,10 +1660,10 @@ class Crypt_RSA
if ($type === false) {
$types = array(
- CRYPT_RSA_PUBLIC_FORMAT_RAW,
- CRYPT_RSA_PUBLIC_FORMAT_PKCS1,
- CRYPT_RSA_PUBLIC_FORMAT_XML,
- CRYPT_RSA_PUBLIC_FORMAT_OPENSSH
+ self::PUBLIC_FORMAT_RAW,
+ self::PUBLIC_FORMAT_PKCS1,
+ self::PUBLIC_FORMAT_XML,
+ self::PUBLIC_FORMAT_OPENSSH
);
foreach ($types as $type) {
$components = $this->_parseKey($key, $type);
@@ -1723,24 +1700,24 @@ class Crypt_RSA
*
* Returns true on success, false on failure
*
- * @see getPublicKey()
+ * @see self::getPublicKey()
* @access public
- * @param String $key optional
- * @param Integer $type optional
- * @return Boolean
+ * @param string $key optional
+ * @param int $type optional
+ * @return bool
*/
function setPrivateKey($key = false, $type = false)
{
if ($key === false && !empty($this->publicExponent)) {
- unset($this->publicExponent);
+ $this->publicExponent = false;
return true;
}
- $rsa = new Crypt_RSA();
+ $rsa = new RSA();
if (!$rsa->loadKey($key, $type)) {
return false;
}
- unset($rsa->publicExponent);
+ $rsa->publicExponent = false;
// don't overwrite the old key if the new key is invalid
$this->loadKey($rsa);
@@ -1754,12 +1731,12 @@ class Crypt_RSA
* or if the public key was set via setPublicKey(). If the currently loaded key is supposed to be the public key this
* function won't return it since this library, for the most part, doesn't distinguish between public and private keys.
*
- * @see getPublicKey()
+ * @see self::getPublicKey()
* @access public
- * @param String $key
- * @param Integer $type optional
+ * @param string $key
+ * @param int $type optional
*/
- function getPublicKey($type = CRYPT_RSA_PUBLIC_FORMAT_PKCS8)
+ function getPublicKey($type = self::PUBLIC_FORMAT_PKCS8)
{
if (empty($this->modulus) || empty($this->publicExponent)) {
return false;
@@ -1772,17 +1749,53 @@ class Crypt_RSA
return $temp;
}
+ /**
+ * Returns the public key's fingerprint
+ *
+ * The public key's fingerprint is returned, which is equivalent to running `ssh-keygen -lf rsa.pub`. If there is
+ * no public key currently loaded, false is returned.
+ * Example output (md5): "c1:b1:30:29:d7:b8:de:6c:97:77:10:d7:46:41:63:87" (as specified by RFC 4716)
+ *
+ * @access public
+ * @param string $algorithm The hashing algorithm to be used. Valid options are 'md5' and 'sha256'. False is returned
+ * for invalid values.
+ * @return mixed
+ */
+ function getPublicKeyFingerprint($algorithm = 'md5')
+ {
+ if (empty($this->modulus) || empty($this->publicExponent)) {
+ return false;
+ }
+
+ $modulus = $this->modulus->toBytes(true);
+ $publicExponent = $this->publicExponent->toBytes(true);
+
+ $RSAPublicKey = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($publicExponent), $publicExponent, strlen($modulus), $modulus);
+
+ switch ($algorithm) {
+ case 'sha256':
+ $hash = new Hash('sha256');
+ $base = base64_encode($hash->hash($RSAPublicKey));
+ return substr($base, 0, strlen($base) - 1);
+ case 'md5':
+ return substr(chunk_split(md5($RSAPublicKey), 2, ':'), 0, -1);
+ default:
+ return false;
+ }
+ }
+
/**
* Returns the private key
*
* The private key is only returned if the currently loaded key contains the constituent prime numbers.
*
- * @see getPublicKey()
+ * @see self::getPublicKey()
* @access public
- * @param String $key
- * @param Integer $type optional
+ * @param string $key
+ * @param int $type optional
+ * @return mixed
*/
- function getPrivateKey($type = CRYPT_RSA_PUBLIC_FORMAT_PKCS1)
+ function getPrivateKey($type = self::PUBLIC_FORMAT_PKCS1)
{
if (empty($this->primes)) {
return false;
@@ -1801,12 +1814,12 @@ class Crypt_RSA
* Returns the private key without the prime number constituants. Structurally identical to a public key that
* hasn't been set as the public key
*
- * @see getPrivateKey()
+ * @see self::getPrivateKey()
* @access private
- * @param String $key
- * @param Integer $type optional
+ * @param string $key
+ * @param int $type optional
*/
- function _getPrivatePublicKey($mode = CRYPT_RSA_PUBLIC_FORMAT_PKCS8)
+ function _getPrivatePublicKey($mode = self::PUBLIC_FORMAT_PKCS8)
{
if (empty($this->modulus) || empty($this->exponent)) {
return false;
@@ -1823,6 +1836,7 @@ class Crypt_RSA
* __toString() magic method
*
* @access public
+ * @return string
*/
function __toString()
{
@@ -1838,10 +1852,11 @@ class Crypt_RSA
* __clone() magic method
*
* @access public
+ * @return Crypt_RSA
*/
function __clone()
{
- $key = new Crypt_RSA();
+ $key = new RSA();
$key->loadKey($this);
return $key;
}
@@ -1850,8 +1865,8 @@ class Crypt_RSA
* Generates the smallest and largest numbers requiring $bits bits
*
* @access private
- * @param Integer $bits
- * @return Array
+ * @param int $bits
+ * @return array
*/
function _generateMinMax($bits)
{
@@ -1867,8 +1882,8 @@ class Crypt_RSA
}
return array(
- 'min' => new Math_BigInteger($min, 256),
- 'max' => new Math_BigInteger($max, 256)
+ 'min' => new BigInteger($min, 256),
+ 'max' => new BigInteger($max, 256)
);
}
@@ -1879,13 +1894,13 @@ class Crypt_RSA
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
*
* @access private
- * @param String $string
- * @return Integer
+ * @param string $string
+ * @return int
*/
function _decodeLength(&$string)
{
$length = ord($this->_string_shift($string));
- if ( $length & 0x80 ) { // definite length, long form
+ if ($length & 0x80) { // definite length, long form
$length&= 0x7F;
$temp = $this->_string_shift($string, $length);
list(, $length) = unpack('N', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4));
@@ -1900,8 +1915,8 @@ class Crypt_RSA
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
*
* @access private
- * @param Integer $length
- * @return String
+ * @param int $length
+ * @return string
*/
function _encodeLength($length)
{
@@ -1918,9 +1933,9 @@ class Crypt_RSA
*
* Inspired by array_shift
*
- * @param String $string
- * @param optional Integer $index
- * @return String
+ * @param string $string
+ * @param int $index
+ * @return string
* @access private
*/
function _string_shift(&$string, $index = 1)
@@ -1933,9 +1948,9 @@ class Crypt_RSA
/**
* Determines the private key format
*
- * @see createKey()
+ * @see self::createKey()
* @access public
- * @param Integer $format
+ * @param int $format
*/
function setPrivateKeyFormat($format)
{
@@ -1945,9 +1960,9 @@ class Crypt_RSA
/**
* Determines the public key format
*
- * @see createKey()
+ * @see self::createKey()
* @access public
- * @param Integer $format
+ * @param int $format
*/
function setPublicKeyFormat($format)
{
@@ -1957,15 +1972,15 @@ class Crypt_RSA
/**
* Determines which hashing function should be used
*
- * Used with signature production / verification and (if the encryption mode is CRYPT_RSA_ENCRYPTION_OAEP) encryption and
+ * Used with signature production / verification and (if the encryption mode is self::ENCRYPTION_OAEP) encryption and
* decryption. If $hash isn't supported, sha1 is used.
*
* @access public
- * @param String $hash
+ * @param string $hash
*/
function setHash($hash)
{
- // Crypt_Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
+ // \phpseclib\Crypt\Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
switch ($hash) {
case 'md2':
case 'md5':
@@ -1973,11 +1988,11 @@ class Crypt_RSA
case 'sha256':
case 'sha384':
case 'sha512':
- $this->hash = new Crypt_Hash($hash);
+ $this->hash = new Hash($hash);
$this->hashName = $hash;
break;
default:
- $this->hash = new Crypt_Hash('sha1');
+ $this->hash = new Hash('sha1');
$this->hashName = 'sha1';
}
$this->hLen = $this->hash->getLength();
@@ -1986,15 +2001,15 @@ class Crypt_RSA
/**
* Determines which hashing function should be used for the mask generation function
*
- * The mask generation function is used by CRYPT_RSA_ENCRYPTION_OAEP and CRYPT_RSA_SIGNATURE_PSS and although it's
+ * The mask generation function is used by self::ENCRYPTION_OAEP and self::SIGNATURE_PSS and although it's
* best if Hash and MGFHash are set to the same thing this is not a requirement.
*
* @access public
- * @param String $hash
+ * @param string $hash
*/
function setMGFHash($hash)
{
- // Crypt_Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
+ // \phpseclib\Crypt\Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
switch ($hash) {
case 'md2':
case 'md5':
@@ -2002,10 +2017,10 @@ class Crypt_RSA
case 'sha256':
case 'sha384':
case 'sha512':
- $this->mgfHash = new Crypt_Hash($hash);
+ $this->mgfHash = new Hash($hash);
break;
default:
- $this->mgfHash = new Crypt_Hash('sha1');
+ $this->mgfHash = new Hash('sha1');
}
$this->mgfHLen = $this->mgfHash->getLength();
}
@@ -2019,7 +2034,7 @@ class Crypt_RSA
* of the hash function Hash) and 0.
*
* @access public
- * @param Integer $format
+ * @param int $format
*/
function setSaltLength($sLen)
{
@@ -2032,9 +2047,9 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-4.1 RFC3447#section-4.1}.
*
* @access private
- * @param Math_BigInteger $x
- * @param Integer $xLen
- * @return String
+ * @param \phpseclib\Math\BigInteger $x
+ * @param int $xLen
+ * @return string
*/
function _i2osp($x, $xLen)
{
@@ -2052,12 +2067,12 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-4.2 RFC3447#section-4.2}.
*
* @access private
- * @param String $x
- * @return Math_BigInteger
+ * @param string $x
+ * @return \phpseclib\Math\BigInteger
*/
function _os2ip($x)
{
- return new Math_BigInteger($x, 256);
+ return new BigInteger($x, 256);
}
/**
@@ -2066,13 +2081,19 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.2}.
*
* @access private
- * @param Math_BigInteger $x
- * @return Math_BigInteger
+ * @param \phpseclib\Math\BigInteger $x
+ * @return \phpseclib\Math\BigInteger
*/
function _exponentiate($x)
{
- if (empty($this->primes) || empty($this->coefficients) || empty($this->exponents)) {
- return $x->modPow($this->exponent, $this->modulus);
+ switch (true) {
+ case empty($this->primes):
+ case $this->primes[1]->equals($this->zero):
+ case empty($this->coefficients):
+ case $this->coefficients[2]->equals($this->zero):
+ case empty($this->exponents):
+ case $this->exponents[1]->equals($this->zero):
+ return $x->modPow($this->exponent, $this->modulus);
}
$num_primes = count($this->primes);
@@ -2107,7 +2128,7 @@ class Crypt_RSA
}
}
- $one = new Math_BigInteger(1);
+ $one = new BigInteger(1);
$r = $one->random($one, $smallest->subtract($one));
@@ -2144,10 +2165,10 @@ class Crypt_RSA
* Returns $x->modPow($this->exponents[$i], $this->primes[$i])
*
* @access private
- * @param Math_BigInteger $x
- * @param Math_BigInteger $r
- * @param Integer $i
- * @return Math_BigInteger
+ * @param \phpseclib\Math\BigInteger $x
+ * @param \phpseclib\Math\BigInteger $r
+ * @param int $i
+ * @return \phpseclib\Math\BigInteger
*/
function _blind($x, $r, $i)
{
@@ -2171,9 +2192,9 @@ class Crypt_RSA
* Thanks for the heads up singpolyma!
*
* @access private
- * @param String $x
- * @param String $y
- * @return Boolean
+ * @param string $x
+ * @param string $y
+ * @return bool
*/
function _equals($x, $y)
{
@@ -2195,8 +2216,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-5.1.1 RFC3447#section-5.1.1}.
*
* @access private
- * @param Math_BigInteger $m
- * @return Math_BigInteger
+ * @param \phpseclib\Math\BigInteger $m
+ * @return \phpseclib\Math\BigInteger
*/
function _rsaep($m)
{
@@ -2213,8 +2234,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-5.1.2 RFC3447#section-5.1.2}.
*
* @access private
- * @param Math_BigInteger $c
- * @return Math_BigInteger
+ * @param \phpseclib\Math\BigInteger $c
+ * @return \phpseclib\Math\BigInteger
*/
function _rsadp($c)
{
@@ -2231,8 +2252,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-5.2.1 RFC3447#section-5.2.1}.
*
* @access private
- * @param Math_BigInteger $m
- * @return Math_BigInteger
+ * @param \phpseclib\Math\BigInteger $m
+ * @return \phpseclib\Math\BigInteger
*/
function _rsasp1($m)
{
@@ -2249,8 +2270,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-5.2.2 RFC3447#section-5.2.2}.
*
* @access private
- * @param Math_BigInteger $s
- * @return Math_BigInteger
+ * @param \phpseclib\Math\BigInteger $s
+ * @return \phpseclib\Math\BigInteger
*/
function _rsavp1($s)
{
@@ -2267,9 +2288,9 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#appendix-B.2.1 RFC3447#appendix-B.2.1}.
*
* @access private
- * @param String $mgfSeed
- * @param Integer $mgfLen
- * @return String
+ * @param string $mgfSeed
+ * @param int $mgfLen
+ * @return string
*/
function _mgf1($mgfSeed, $maskLen)
{
@@ -2292,9 +2313,9 @@ class Crypt_RSA
* {http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding OAES}.
*
* @access private
- * @param String $m
- * @param String $l
- * @return String
+ * @param string $m
+ * @param string $l
+ * @return string
*/
function _rsaes_oaep_encrypt($m, $l = '')
{
@@ -2315,7 +2336,7 @@ class Crypt_RSA
$lHash = $this->hash->hash($l);
$ps = str_repeat(chr(0), $this->k - $mLen - 2 * $this->hLen - 2);
$db = $lHash . $ps . chr(1) . $m;
- $seed = crypt_random_string($this->hLen);
+ $seed = Random::string($this->hLen);
$dbMask = $this->_mgf1($seed, $this->k - $this->hLen - 1);
$maskedDB = $db ^ $dbMask;
$seedMask = $this->_mgf1($maskedDB, $this->hLen);
@@ -2355,9 +2376,9 @@ class Crypt_RSA
* this document.
*
* @access private
- * @param String $c
- * @param String $l
- * @return String
+ * @param string $c
+ * @param string $l
+ * @return string
*/
function _rsaes_oaep_decrypt($c, $l = '')
{
@@ -2408,14 +2429,30 @@ class Crypt_RSA
return substr($m, 1);
}
+ /**
+ * Raw Encryption / Decryption
+ *
+ * Doesn't use padding and is not recommended.
+ *
+ * @access private
+ * @param string $m
+ * @return string
+ */
+ function _raw_encrypt($m)
+ {
+ $temp = $this->_os2ip($m);
+ $temp = $this->_rsaep($temp);
+ return $this->_i2osp($temp, $this->k);
+ }
+
/**
* RSAES-PKCS1-V1_5-ENCRYPT
*
* See {@link http://tools.ietf.org/html/rfc3447#section-7.2.1 RFC3447#section-7.2.1}.
*
* @access private
- * @param String $m
- * @return String
+ * @param string $m
+ * @return string
*/
function _rsaes_pkcs1_v1_5_encrypt($m)
{
@@ -2433,7 +2470,7 @@ class Crypt_RSA
$psLen = $this->k - $mLen - 3;
$ps = '';
while (strlen($ps) != $psLen) {
- $temp = crypt_random_string($psLen - strlen($ps));
+ $temp = Random::string($psLen - strlen($ps));
$temp = str_replace("\x00", '', $temp);
$ps.= $temp;
}
@@ -2468,13 +2505,13 @@ class Crypt_RSA
* to be 2 regardless of which key is used. For compatibility purposes, we'll just check to make sure the
* second byte is 2 or less. If it is, we'll accept the decrypted string as valid.
*
- * As a consequence of this, a private key encrypted ciphertext produced with Crypt_RSA may not decrypt
+ * As a consequence of this, a private key encrypted ciphertext produced with \phpseclib\Crypt\RSA may not decrypt
* with a strictly PKCS#1 v1.5 compliant RSA implementation. Public key encrypted ciphertext's should but
* not private key encrypted ciphertext's.
*
* @access private
- * @param String $c
- * @return String
+ * @param string $c
+ * @return string
*/
function _rsaes_pkcs1_v1_5_decrypt($c)
{
@@ -2522,8 +2559,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-9.1.1 RFC3447#section-9.1.1}.
*
* @access private
- * @param String $m
- * @param Integer $emBits
+ * @param string $m
+ * @param int $emBits
*/
function _emsa_pss_encode($m, $emBits)
{
@@ -2531,7 +2568,7 @@ class Crypt_RSA
// be output.
$emLen = ($emBits + 1) >> 3; // ie. ceil($emBits / 8)
- $sLen = $this->sLen == false ? $this->hLen : $this->sLen;
+ $sLen = $this->sLen !== null ? $this->sLen : $this->hLen;
$mHash = $this->hash->hash($m);
if ($emLen < $this->hLen + $sLen + 2) {
@@ -2539,7 +2576,7 @@ class Crypt_RSA
return false;
}
- $salt = crypt_random_string($sLen);
+ $salt = Random::string($sLen);
$m2 = "\0\0\0\0\0\0\0\0" . $mHash . $salt;
$h = $this->hash->hash($m2);
$ps = str_repeat(chr(0), $emLen - $sLen - $this->hLen - 2);
@@ -2558,10 +2595,10 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-9.1.2 RFC3447#section-9.1.2}.
*
* @access private
- * @param String $m
- * @param String $em
- * @param Integer $emBits
- * @return String
+ * @param string $m
+ * @param string $em
+ * @param int $emBits
+ * @return string
*/
function _emsa_pss_verify($m, $em, $emBits)
{
@@ -2569,7 +2606,7 @@ class Crypt_RSA
// be output.
$emLen = ($emBits + 1) >> 3; // ie. ceil($emBits / 8);
- $sLen = $this->sLen == false ? $this->hLen : $this->sLen;
+ $sLen = $this->sLen !== null ? $this->sLen : $this->hLen;
$mHash = $this->hash->hash($m);
if ($emLen < $this->hLen + $sLen + 2) {
@@ -2605,8 +2642,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-8.1.1 RFC3447#section-8.1.1}.
*
* @access private
- * @param String $m
- * @return String
+ * @param string $m
+ * @return string
*/
function _rsassa_pss_sign($m)
{
@@ -2631,9 +2668,9 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-8.1.2 RFC3447#section-8.1.2}.
*
* @access private
- * @param String $m
- * @param String $s
- * @return String
+ * @param string $m
+ * @param string $s
+ * @return string
*/
function _rsassa_pss_verify($m, $s)
{
@@ -2671,9 +2708,9 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-9.2 RFC3447#section-9.2}.
*
* @access private
- * @param String $m
- * @param Integer $emLen
- * @return String
+ * @param string $m
+ * @param int $emLen
+ * @return string
*/
function _emsa_pkcs1_v1_5_encode($m, $emLen)
{
@@ -2723,8 +2760,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-8.2.1 RFC3447#section-8.2.1}.
*
* @access private
- * @param String $m
- * @return String
+ * @param string $m
+ * @return string
*/
function _rsassa_pkcs1_v1_5_sign($m)
{
@@ -2753,8 +2790,8 @@ class Crypt_RSA
* See {@link http://tools.ietf.org/html/rfc3447#section-8.2.2 RFC3447#section-8.2.2}.
*
* @access private
- * @param String $m
- * @return String
+ * @param string $m
+ * @return string
*/
function _rsassa_pkcs1_v1_5_verify($m, $s)
{
@@ -2794,10 +2831,10 @@ class Crypt_RSA
/**
* Set Encryption Mode
*
- * Valid values include CRYPT_RSA_ENCRYPTION_OAEP and CRYPT_RSA_ENCRYPTION_PKCS1.
+ * Valid values include self::ENCRYPTION_OAEP and self::ENCRYPTION_PKCS1.
*
* @access public
- * @param Integer $mode
+ * @param int $mode
*/
function setEncryptionMode($mode)
{
@@ -2807,10 +2844,10 @@ class Crypt_RSA
/**
* Set Signature Mode
*
- * Valid values include CRYPT_RSA_SIGNATURE_PSS and CRYPT_RSA_SIGNATURE_PKCS1
+ * Valid values include self::SIGNATURE_PSS and self::SIGNATURE_PKCS1
*
* @access public
- * @param Integer $mode
+ * @param int $mode
*/
function setSignatureMode($mode)
{
@@ -2821,7 +2858,7 @@ class Crypt_RSA
* Set public key comment.
*
* @access public
- * @param String $comment
+ * @param string $comment
*/
function setComment($comment)
{
@@ -2832,7 +2869,7 @@ class Crypt_RSA
* Get public key comment.
*
* @access public
- * @return String
+ * @return string
*/
function getComment()
{
@@ -2842,19 +2879,26 @@ class Crypt_RSA
/**
* Encryption
*
- * Both CRYPT_RSA_ENCRYPTION_OAEP and CRYPT_RSA_ENCRYPTION_PKCS1 both place limits on how long $plaintext can be.
+ * Both self::ENCRYPTION_OAEP and self::ENCRYPTION_PKCS1 both place limits on how long $plaintext can be.
* If $plaintext exceeds those limits it will be broken up so that it does and the resultant ciphertext's will
* be concatenated together.
*
- * @see decrypt()
+ * @see self::decrypt()
* @access public
- * @param String $plaintext
- * @return String
+ * @param string $plaintext
+ * @return string
*/
function encrypt($plaintext)
{
switch ($this->encryptionMode) {
- case CRYPT_RSA_ENCRYPTION_PKCS1:
+ case self::ENCRYPTION_NONE:
+ $plaintext = str_split($plaintext, $this->k);
+ $ciphertext = '';
+ foreach ($plaintext as $m) {
+ $ciphertext.= $this->_raw_encrypt($m);
+ }
+ return $ciphertext;
+ case self::ENCRYPTION_PKCS1:
$length = $this->k - 11;
if ($length <= 0) {
return false;
@@ -2866,7 +2910,7 @@ class Crypt_RSA
$ciphertext.= $this->_rsaes_pkcs1_v1_5_encrypt($m);
}
return $ciphertext;
- //case CRYPT_RSA_ENCRYPTION_OAEP:
+ //case self::ENCRYPTION_OAEP:
default:
$length = $this->k - 2 * $this->hLen - 2;
if ($length <= 0) {
@@ -2885,10 +2929,10 @@ class Crypt_RSA
/**
* Decryption
*
- * @see encrypt()
+ * @see self::encrypt()
* @access public
- * @param String $plaintext
- * @return String
+ * @param string $plaintext
+ * @return string
*/
function decrypt($ciphertext)
{
@@ -2902,10 +2946,13 @@ class Crypt_RSA
$plaintext = '';
switch ($this->encryptionMode) {
- case CRYPT_RSA_ENCRYPTION_PKCS1:
+ case self::ENCRYPTION_NONE:
+ $decrypt = '_raw_encrypt';
+ break;
+ case self::ENCRYPTION_PKCS1:
$decrypt = '_rsaes_pkcs1_v1_5_decrypt';
break;
- //case CRYPT_RSA_ENCRYPTION_OAEP:
+ //case self::ENCRYPTION_OAEP:
default:
$decrypt = '_rsaes_oaep_decrypt';
}
@@ -2924,10 +2971,10 @@ class Crypt_RSA
/**
* Create a signature
*
- * @see verify()
+ * @see self::verify()
* @access public
- * @param String $message
- * @return String
+ * @param string $message
+ * @return string
*/
function sign($message)
{
@@ -2936,9 +2983,9 @@ class Crypt_RSA
}
switch ($this->signatureMode) {
- case CRYPT_RSA_SIGNATURE_PKCS1:
+ case self::SIGNATURE_PKCS1:
return $this->_rsassa_pkcs1_v1_5_sign($message);
- //case CRYPT_RSA_SIGNATURE_PSS:
+ //case self::SIGNATURE_PSS:
default:
return $this->_rsassa_pss_sign($message);
}
@@ -2947,11 +2994,11 @@ class Crypt_RSA
/**
* Verifies a signature
*
- * @see sign()
+ * @see self::sign()
* @access public
- * @param String $message
- * @param String $signature
- * @return Boolean
+ * @param string $message
+ * @param string $signature
+ * @return bool
*/
function verify($message, $signature)
{
@@ -2960,9 +3007,9 @@ class Crypt_RSA
}
switch ($this->signatureMode) {
- case CRYPT_RSA_SIGNATURE_PKCS1:
+ case self::SIGNATURE_PKCS1:
return $this->_rsassa_pkcs1_v1_5_verify($message, $signature);
- //case CRYPT_RSA_SIGNATURE_PSS:
+ //case self::SIGNATURE_PSS:
default:
return $this->_rsassa_pss_verify($message, $signature);
}
@@ -2972,8 +3019,8 @@ class Crypt_RSA
* Extract raw BER from Base64 encoding
*
* @access private
- * @param String $str
- * @return String
+ * @param string $str
+ * @return string
*/
function _extractBER($str)
{
@@ -2986,7 +3033,7 @@ class Crypt_RSA
* subject=/O=organization/OU=org unit/CN=common name
* issuer=/O=organization/CN=common name
*/
- $temp = preg_replace('#.*?^-+[^-]+-+#ms', '', $str, 1);
+ $temp = preg_replace('#.*?^-+[^-]+-+[\r\n ]*$#ms', '', $str, 1);
// remove the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- stuff
$temp = preg_replace('#-+[^-]+-+#', '', $temp);
// remove new lines
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php
index 918b97bf..170d1c37 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php
@@ -3,57 +3,36 @@
/**
* Random Number Generator
*
- * The idea behind this function is that it can be easily replaced with your own crypt_random_string()
- * function. eg. maybe you have a better source of entropy for creating the initial states or whatever.
- *
- * PHP versions 4 and 5
+ * PHP version 5
*
* Here's a short example of how to use this library:
*
*
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_Random
+ * @package Random
* @author Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-// laravel is a PHP framework that utilizes phpseclib. laravel workbenches may, independently,
-// have phpseclib as a requirement as well. if you're developing such a program you may encounter
-// a "Cannot redeclare crypt_random_string()" error.
-if (!function_exists('crypt_random_string')) {
- /**
- * "Is Windows" test
- *
- * @access private
- */
- define('CRYPT_RANDOM_IS_WINDOWS', strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
+namespace phpseclib\Crypt;
+/**
+ * Pure-PHP Random Number Generator
+ *
+ * @package Random
+ * @author Jim Wigginton
+ * @access public
+ */
+class Random
+{
/**
* Generate a random string.
*
@@ -61,16 +40,28 @@ if (!function_exists('crypt_random_string')) {
* microoptimizations because this function has the potential of being called a huge number of times.
* eg. for RSA key generation.
*
- * @param Integer $length
- * @return String
- * @access public
+ * @param int $length
+ * @return string
*/
- function crypt_random_string($length)
+ static function string($length)
{
- if (CRYPT_RANDOM_IS_WINDOWS) {
+ if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
+ try {
+ return \random_bytes($length);
+ } catch (\Throwable $e) {
+ // If a sufficient source of randomness is unavailable, random_bytes() will throw an
+ // object that implements the Throwable interface (Exception, TypeError, Error).
+ // We don't actually need to do anything here. The string() method should just continue
+ // as normal. Note, however, that if we don't have a sufficient source of randomness for
+ // random_bytes(), most of the other calls here will fail too, so we'll end up using
+ // the PHP implementation.
+ }
+ }
+
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call.
// ie. class_alias is a function that was introduced in PHP 5.3
- if (function_exists('mcrypt_create_iv') && function_exists('class_alias')) {
+ if (extension_loaded('mcrypt') && function_exists('class_alias')) {
return mcrypt_create_iv($length);
}
// method 2. openssl_random_pseudo_bytes was introduced in PHP 5.3.0 but prior to PHP 5.3.4 there was,
@@ -86,12 +77,12 @@ if (!function_exists('crypt_random_string')) {
// https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/win32/winutil.c#L80
//
// we're calling it, all the same, in the off chance that the mcrypt extension is not available
- if (function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>=')) {
+ if (extension_loaded('openssl') && version_compare(PHP_VERSION, '5.3.4', '>=')) {
return openssl_random_pseudo_bytes($length);
}
} else {
// method 1. the fastest
- if (function_exists('openssl_random_pseudo_bytes')) {
+ if (extension_loaded('openssl')) {
return openssl_random_pseudo_bytes($length);
}
// method 2
@@ -109,7 +100,7 @@ if (!function_exists('crypt_random_string')) {
// surprisingly slower than method 2. maybe that's because mcrypt_create_iv does a bunch of error checking that we're
// not doing. regardless, this'll only be called if this PHP script couldn't open /dev/urandom due to open_basedir
// restrictions or some such
- if (function_exists('mcrypt_create_iv')) {
+ if (extension_loaded('mcrypt')) {
return mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
}
}
@@ -149,13 +140,13 @@ if (!function_exists('crypt_random_string')) {
session_start();
$v = $seed = $_SESSION['seed'] = pack('H*', sha1(
- serialize($_SERVER) .
- serialize($_POST) .
- serialize($_GET) .
- serialize($_COOKIE) .
- serialize($GLOBALS) .
- serialize($_SESSION) .
- serialize($_OLD_SESSION)
+ (isset($_SERVER) ? phpseclib_safe_serialize($_SERVER) : '') .
+ (isset($_POST) ? phpseclib_safe_serialize($_POST) : '') .
+ (isset($_GET) ? phpseclib_safe_serialize($_GET) : '') .
+ (isset($_COOKIE) ? phpseclib_safe_serialize($_COOKIE) : '') .
+ phpseclib_safe_serialize($GLOBALS) .
+ phpseclib_safe_serialize($_SESSION) .
+ phpseclib_safe_serialize($_OLD_SESSION)
));
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
@@ -171,9 +162,9 @@ if (!function_exists('crypt_random_string')) {
ini_set('session.use_cookies', $old_use_cookies);
session_cache_limiter($old_session_cache_limiter);
} else {
- if ($_OLD_SESSION !== false) {
- $_SESSION = $_OLD_SESSION;
- unset($_OLD_SESSION);
+ if ($_OLD_SESSION !== false) {
+ $_SESSION = $_OLD_SESSION;
+ unset($_OLD_SESSION);
} else {
unset($_SESSION);
}
@@ -194,44 +185,26 @@ if (!function_exists('crypt_random_string')) {
//
// http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Designs_based_on_cryptographic_primitives
switch (true) {
- case phpseclib_resolve_include_path('Crypt/AES.php'):
- if (!class_exists('Crypt_AES')) {
- include_once 'AES.php';
- }
- $crypto = new Crypt_AES(CRYPT_AES_MODE_CTR);
+ case class_exists('\phpseclib\Crypt\AES'):
+ $crypto = new AES(Base::MODE_CTR);
break;
- case phpseclib_resolve_include_path('Crypt/Twofish.php'):
- if (!class_exists('Crypt_Twofish')) {
- include_once 'Twofish.php';
- }
- $crypto = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
+ case class_exists('\phpseclib\Crypt\Twofish'):
+ $crypto = new Twofish(Base::MODE_CTR);
break;
- case phpseclib_resolve_include_path('Crypt/Blowfish.php'):
- if (!class_exists('Crypt_Blowfish')) {
- include_once 'Blowfish.php';
- }
- $crypto = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
+ case class_exists('\phpseclib\Crypt\Blowfish'):
+ $crypto = new Blowfish(Base::MODE_CTR);
break;
- case phpseclib_resolve_include_path('Crypt/TripleDES.php'):
- if (!class_exists('Crypt_TripleDES')) {
- include_once 'TripleDES.php';
- }
- $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
+ case class_exists('\phpseclib\Crypt\TripleDES'):
+ $crypto = new TripleDES(Base::MODE_CTR);
break;
- case phpseclib_resolve_include_path('Crypt/DES.php'):
- if (!class_exists('Crypt_DES')) {
- include_once 'DES.php';
- }
- $crypto = new Crypt_DES(CRYPT_DES_MODE_CTR);
+ case class_exists('\phpseclib\Crypt\DES'):
+ $crypto = new DES(Base::MODE_CTR);
break;
- case phpseclib_resolve_include_path('Crypt/RC4.php'):
- if (!class_exists('Crypt_RC4')) {
- include_once 'RC4.php';
- }
- $crypto = new Crypt_RC4();
+ case class_exists('\phpseclib\Crypt\RC4'):
+ $crypto = new RC4();
break;
default:
- user_error('crypt_random_string requires at least one symmetric cipher be loaded');
+ user_error(__CLASS__ . ' requires at least one symmetric cipher be loaded');
return false;
}
@@ -261,40 +234,37 @@ if (!function_exists('crypt_random_string')) {
}
}
-if (!function_exists('phpseclib_resolve_include_path')) {
+if (!function_exists('phpseclib_safe_serialize')) {
/**
- * Resolve filename against the include path.
+ * Safely serialize variables
*
- * Wrapper around stream_resolve_include_path() (which was introduced in
- * PHP 5.3.2) with fallback implementation for earlier PHP versions.
+ * If a class has a private __sleep() method it'll give a fatal error on PHP 5.2 and earlier.
+ * PHP 5.3 will emit a warning.
*
- * @param string $filename
- * @return mixed Filename (string) on success, false otherwise.
+ * @param mixed $arr
* @access public
*/
- function phpseclib_resolve_include_path($filename)
+ function phpseclib_safe_serialize(&$arr)
{
- if (function_exists('stream_resolve_include_path')) {
- return stream_resolve_include_path($filename);
+ if (is_object($arr)) {
+ return '';
}
-
- // handle non-relative paths
- if (file_exists($filename)) {
- return realpath($filename);
+ if (!is_array($arr)) {
+ return serialize($arr);
}
-
- $paths = PATH_SEPARATOR == ':' ?
- preg_split('#(?
* setKey('abcdefghijklmnop');
*
@@ -44,134 +44,37 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_Rijndael
+ * @package Rijndael
* @author Jim Wigginton
* @copyright 2008 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Base
- *
- * Base cipher class
- */
-if (!class_exists('Crypt_Base')) {
- include_once 'Base.php';
-}
-
-/**#@+
- * @access public
- * @see Crypt_Rijndael::encrypt()
- * @see Crypt_Rijndael::decrypt()
- */
-/**
- * Encrypt / decrypt using the Counter mode.
- *
- * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
- */
-define('CRYPT_RIJNDAEL_MODE_CTR', CRYPT_MODE_CTR);
-/**
- * Encrypt / decrypt using the Electronic Code Book mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
- */
-define('CRYPT_RIJNDAEL_MODE_ECB', CRYPT_MODE_ECB);
-/**
- * Encrypt / decrypt using the Code Book Chaining mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
- */
-define('CRYPT_RIJNDAEL_MODE_CBC', CRYPT_MODE_CBC);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
- */
-define('CRYPT_RIJNDAEL_MODE_CFB', CRYPT_MODE_CFB);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
- */
-define('CRYPT_RIJNDAEL_MODE_OFB', CRYPT_MODE_OFB);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_Base::Crypt_Base()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_RIJNDAEL_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
-/**
- * Toggles the mcrypt implementation
- */
-define('CRYPT_RIJNDAEL_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of Rijndael.
*
- * @package Crypt_Rijndael
+ * @package Rijndael
* @author Jim Wigginton
* @access public
*/
-class Crypt_Rijndael extends Crypt_Base
+class Rijndael extends Base
{
- /**
- * The default password key_size used by setPassword()
- *
- * @see Crypt_Base::password_key_size
- * @see Crypt_Base::setPassword()
- * @var Integer
- * @access private
- */
- var $password_key_size = 16;
-
- /**
- * The namespace used by the cipher for its constants.
- *
- * @see Crypt_Base::const_namespace
- * @var String
- * @access private
- */
- var $const_namespace = 'RIJNDAEL';
-
/**
* The mcrypt specific name of the cipher
*
- * Mcrypt is useable for 128/192/256-bit $block_size/$key_size. For 160/224 not.
- * Crypt_Rijndael determines automatically whether mcrypt is useable
- * or not for the current $block_size/$key_size.
+ * Mcrypt is useable for 128/192/256-bit $block_size/$key_length. For 160/224 not.
+ * \phpseclib\Crypt\Rijndael determines automatically whether mcrypt is useable
+ * or not for the current $block_size/$key_length.
* In case of, $cipher_name_mcrypt will be set dynamically at run time accordingly.
*
- * @see Crypt_Base::cipher_name_mcrypt
- * @see Crypt_Base::engine
- * @see _setupEngine()
- * @var String
+ * @see \phpseclib\Crypt\Base::cipher_name_mcrypt
+ * @see \phpseclib\Crypt\Base::engine
+ * @see self::isValidEngine()
+ * @var string
* @access private
*/
var $cipher_name_mcrypt = 'rijndael-128';
@@ -179,27 +82,18 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The default salt used by setPassword()
*
- * @see Crypt_Base::password_default_salt
- * @see Crypt_Base::setPassword()
- * @var String
+ * @see \phpseclib\Crypt\Base::password_default_salt
+ * @see \phpseclib\Crypt\Base::setPassword()
+ * @var string
* @access private
*/
var $password_default_salt = 'phpseclib';
- /**
- * Has the key length explicitly been set or should it be derived from the key, itself?
- *
- * @see setKeyLength()
- * @var Boolean
- * @access private
- */
- var $explicit_key_length = false;
-
/**
* The Key Schedule
*
- * @see _setup()
- * @var Array
+ * @see self::_setup()
+ * @var array
* @access private
*/
var $w;
@@ -207,8 +101,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The Inverse Key Schedule
*
- * @see _setup()
- * @var Array
+ * @see self::_setup()
+ * @var array
* @access private
*/
var $dw;
@@ -216,35 +110,34 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The Block Length divided by 32
*
- * @see setBlockLength()
- * @var Integer
+ * @see self::setBlockLength()
+ * @var int
* @access private
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4. Exists in conjunction with $block_size
* because the encryption / decryption / key schedule creation requires this number and not $block_size. We could
* derive this from $block_size or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
* of that, we'll just precompute it once.
- *
*/
var $Nb = 4;
/**
- * The Key Length
+ * The Key Length (in bytes)
*
- * @see setKeyLength()
- * @var Integer
+ * @see self::setKeyLength()
+ * @var int
* @access private
* @internal The max value is 256 / 8 = 32, the min value is 128 / 8 = 16. Exists in conjunction with $Nk
- * because the encryption / decryption / key schedule creation requires this number and not $key_size. We could
- * derive this from $key_size or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
+ * because the encryption / decryption / key schedule creation requires this number and not $key_length. We could
+ * derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
* of that, we'll just precompute it once.
*/
- var $key_size = 16;
+ var $key_length = 16;
/**
* The Key Length divided by 32
*
- * @see setKeyLength()
- * @var Integer
+ * @see self::setKeyLength()
+ * @var int
* @access private
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4
*/
@@ -253,7 +146,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The Number of Rounds
*
- * @var Integer
+ * @var int
* @access private
* @internal The max value is 14, the min value is 10.
*/
@@ -262,7 +155,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Shift offsets
*
- * @var Array
+ * @var array
* @access private
*/
var $c;
@@ -270,456 +163,13 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Holds the last used key- and block_size information
*
- * @var Array
+ * @var array
* @access private
*/
var $kl;
/**
- * Precomputed mixColumns table
- *
- * According to (section 5.2.1),
- * precomputed tables can be used in the mixColumns phase. in that example, they're assigned t0...t3, so
- * those are the names we'll use.
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $t0 = array(
- 0xC66363A5, 0xF87C7C84, 0xEE777799, 0xF67B7B8D, 0xFFF2F20D, 0xD66B6BBD, 0xDE6F6FB1, 0x91C5C554,
- 0x60303050, 0x02010103, 0xCE6767A9, 0x562B2B7D, 0xE7FEFE19, 0xB5D7D762, 0x4DABABE6, 0xEC76769A,
- 0x8FCACA45, 0x1F82829D, 0x89C9C940, 0xFA7D7D87, 0xEFFAFA15, 0xB25959EB, 0x8E4747C9, 0xFBF0F00B,
- 0x41ADADEC, 0xB3D4D467, 0x5FA2A2FD, 0x45AFAFEA, 0x239C9CBF, 0x53A4A4F7, 0xE4727296, 0x9BC0C05B,
- 0x75B7B7C2, 0xE1FDFD1C, 0x3D9393AE, 0x4C26266A, 0x6C36365A, 0x7E3F3F41, 0xF5F7F702, 0x83CCCC4F,
- 0x6834345C, 0x51A5A5F4, 0xD1E5E534, 0xF9F1F108, 0xE2717193, 0xABD8D873, 0x62313153, 0x2A15153F,
- 0x0804040C, 0x95C7C752, 0x46232365, 0x9DC3C35E, 0x30181828, 0x379696A1, 0x0A05050F, 0x2F9A9AB5,
- 0x0E070709, 0x24121236, 0x1B80809B, 0xDFE2E23D, 0xCDEBEB26, 0x4E272769, 0x7FB2B2CD, 0xEA75759F,
- 0x1209091B, 0x1D83839E, 0x582C2C74, 0x341A1A2E, 0x361B1B2D, 0xDC6E6EB2, 0xB45A5AEE, 0x5BA0A0FB,
- 0xA45252F6, 0x763B3B4D, 0xB7D6D661, 0x7DB3B3CE, 0x5229297B, 0xDDE3E33E, 0x5E2F2F71, 0x13848497,
- 0xA65353F5, 0xB9D1D168, 0x00000000, 0xC1EDED2C, 0x40202060, 0xE3FCFC1F, 0x79B1B1C8, 0xB65B5BED,
- 0xD46A6ABE, 0x8DCBCB46, 0x67BEBED9, 0x7239394B, 0x944A4ADE, 0x984C4CD4, 0xB05858E8, 0x85CFCF4A,
- 0xBBD0D06B, 0xC5EFEF2A, 0x4FAAAAE5, 0xEDFBFB16, 0x864343C5, 0x9A4D4DD7, 0x66333355, 0x11858594,
- 0x8A4545CF, 0xE9F9F910, 0x04020206, 0xFE7F7F81, 0xA05050F0, 0x783C3C44, 0x259F9FBA, 0x4BA8A8E3,
- 0xA25151F3, 0x5DA3A3FE, 0x804040C0, 0x058F8F8A, 0x3F9292AD, 0x219D9DBC, 0x70383848, 0xF1F5F504,
- 0x63BCBCDF, 0x77B6B6C1, 0xAFDADA75, 0x42212163, 0x20101030, 0xE5FFFF1A, 0xFDF3F30E, 0xBFD2D26D,
- 0x81CDCD4C, 0x180C0C14, 0x26131335, 0xC3ECEC2F, 0xBE5F5FE1, 0x359797A2, 0x884444CC, 0x2E171739,
- 0x93C4C457, 0x55A7A7F2, 0xFC7E7E82, 0x7A3D3D47, 0xC86464AC, 0xBA5D5DE7, 0x3219192B, 0xE6737395,
- 0xC06060A0, 0x19818198, 0x9E4F4FD1, 0xA3DCDC7F, 0x44222266, 0x542A2A7E, 0x3B9090AB, 0x0B888883,
- 0x8C4646CA, 0xC7EEEE29, 0x6BB8B8D3, 0x2814143C, 0xA7DEDE79, 0xBC5E5EE2, 0x160B0B1D, 0xADDBDB76,
- 0xDBE0E03B, 0x64323256, 0x743A3A4E, 0x140A0A1E, 0x924949DB, 0x0C06060A, 0x4824246C, 0xB85C5CE4,
- 0x9FC2C25D, 0xBDD3D36E, 0x43ACACEF, 0xC46262A6, 0x399191A8, 0x319595A4, 0xD3E4E437, 0xF279798B,
- 0xD5E7E732, 0x8BC8C843, 0x6E373759, 0xDA6D6DB7, 0x018D8D8C, 0xB1D5D564, 0x9C4E4ED2, 0x49A9A9E0,
- 0xD86C6CB4, 0xAC5656FA, 0xF3F4F407, 0xCFEAEA25, 0xCA6565AF, 0xF47A7A8E, 0x47AEAEE9, 0x10080818,
- 0x6FBABAD5, 0xF0787888, 0x4A25256F, 0x5C2E2E72, 0x381C1C24, 0x57A6A6F1, 0x73B4B4C7, 0x97C6C651,
- 0xCBE8E823, 0xA1DDDD7C, 0xE874749C, 0x3E1F1F21, 0x964B4BDD, 0x61BDBDDC, 0x0D8B8B86, 0x0F8A8A85,
- 0xE0707090, 0x7C3E3E42, 0x71B5B5C4, 0xCC6666AA, 0x904848D8, 0x06030305, 0xF7F6F601, 0x1C0E0E12,
- 0xC26161A3, 0x6A35355F, 0xAE5757F9, 0x69B9B9D0, 0x17868691, 0x99C1C158, 0x3A1D1D27, 0x279E9EB9,
- 0xD9E1E138, 0xEBF8F813, 0x2B9898B3, 0x22111133, 0xD26969BB, 0xA9D9D970, 0x078E8E89, 0x339494A7,
- 0x2D9B9BB6, 0x3C1E1E22, 0x15878792, 0xC9E9E920, 0x87CECE49, 0xAA5555FF, 0x50282878, 0xA5DFDF7A,
- 0x038C8C8F, 0x59A1A1F8, 0x09898980, 0x1A0D0D17, 0x65BFBFDA, 0xD7E6E631, 0x844242C6, 0xD06868B8,
- 0x824141C3, 0x299999B0, 0x5A2D2D77, 0x1E0F0F11, 0x7BB0B0CB, 0xA85454FC, 0x6DBBBBD6, 0x2C16163A
- );
-
- /**
- * Precomputed mixColumns table
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $t1 = array(
- 0xA5C66363, 0x84F87C7C, 0x99EE7777, 0x8DF67B7B, 0x0DFFF2F2, 0xBDD66B6B, 0xB1DE6F6F, 0x5491C5C5,
- 0x50603030, 0x03020101, 0xA9CE6767, 0x7D562B2B, 0x19E7FEFE, 0x62B5D7D7, 0xE64DABAB, 0x9AEC7676,
- 0x458FCACA, 0x9D1F8282, 0x4089C9C9, 0x87FA7D7D, 0x15EFFAFA, 0xEBB25959, 0xC98E4747, 0x0BFBF0F0,
- 0xEC41ADAD, 0x67B3D4D4, 0xFD5FA2A2, 0xEA45AFAF, 0xBF239C9C, 0xF753A4A4, 0x96E47272, 0x5B9BC0C0,
- 0xC275B7B7, 0x1CE1FDFD, 0xAE3D9393, 0x6A4C2626, 0x5A6C3636, 0x417E3F3F, 0x02F5F7F7, 0x4F83CCCC,
- 0x5C683434, 0xF451A5A5, 0x34D1E5E5, 0x08F9F1F1, 0x93E27171, 0x73ABD8D8, 0x53623131, 0x3F2A1515,
- 0x0C080404, 0x5295C7C7, 0x65462323, 0x5E9DC3C3, 0x28301818, 0xA1379696, 0x0F0A0505, 0xB52F9A9A,
- 0x090E0707, 0x36241212, 0x9B1B8080, 0x3DDFE2E2, 0x26CDEBEB, 0x694E2727, 0xCD7FB2B2, 0x9FEA7575,
- 0x1B120909, 0x9E1D8383, 0x74582C2C, 0x2E341A1A, 0x2D361B1B, 0xB2DC6E6E, 0xEEB45A5A, 0xFB5BA0A0,
- 0xF6A45252, 0x4D763B3B, 0x61B7D6D6, 0xCE7DB3B3, 0x7B522929, 0x3EDDE3E3, 0x715E2F2F, 0x97138484,
- 0xF5A65353, 0x68B9D1D1, 0x00000000, 0x2CC1EDED, 0x60402020, 0x1FE3FCFC, 0xC879B1B1, 0xEDB65B5B,
- 0xBED46A6A, 0x468DCBCB, 0xD967BEBE, 0x4B723939, 0xDE944A4A, 0xD4984C4C, 0xE8B05858, 0x4A85CFCF,
- 0x6BBBD0D0, 0x2AC5EFEF, 0xE54FAAAA, 0x16EDFBFB, 0xC5864343, 0xD79A4D4D, 0x55663333, 0x94118585,
- 0xCF8A4545, 0x10E9F9F9, 0x06040202, 0x81FE7F7F, 0xF0A05050, 0x44783C3C, 0xBA259F9F, 0xE34BA8A8,
- 0xF3A25151, 0xFE5DA3A3, 0xC0804040, 0x8A058F8F, 0xAD3F9292, 0xBC219D9D, 0x48703838, 0x04F1F5F5,
- 0xDF63BCBC, 0xC177B6B6, 0x75AFDADA, 0x63422121, 0x30201010, 0x1AE5FFFF, 0x0EFDF3F3, 0x6DBFD2D2,
- 0x4C81CDCD, 0x14180C0C, 0x35261313, 0x2FC3ECEC, 0xE1BE5F5F, 0xA2359797, 0xCC884444, 0x392E1717,
- 0x5793C4C4, 0xF255A7A7, 0x82FC7E7E, 0x477A3D3D, 0xACC86464, 0xE7BA5D5D, 0x2B321919, 0x95E67373,
- 0xA0C06060, 0x98198181, 0xD19E4F4F, 0x7FA3DCDC, 0x66442222, 0x7E542A2A, 0xAB3B9090, 0x830B8888,
- 0xCA8C4646, 0x29C7EEEE, 0xD36BB8B8, 0x3C281414, 0x79A7DEDE, 0xE2BC5E5E, 0x1D160B0B, 0x76ADDBDB,
- 0x3BDBE0E0, 0x56643232, 0x4E743A3A, 0x1E140A0A, 0xDB924949, 0x0A0C0606, 0x6C482424, 0xE4B85C5C,
- 0x5D9FC2C2, 0x6EBDD3D3, 0xEF43ACAC, 0xA6C46262, 0xA8399191, 0xA4319595, 0x37D3E4E4, 0x8BF27979,
- 0x32D5E7E7, 0x438BC8C8, 0x596E3737, 0xB7DA6D6D, 0x8C018D8D, 0x64B1D5D5, 0xD29C4E4E, 0xE049A9A9,
- 0xB4D86C6C, 0xFAAC5656, 0x07F3F4F4, 0x25CFEAEA, 0xAFCA6565, 0x8EF47A7A, 0xE947AEAE, 0x18100808,
- 0xD56FBABA, 0x88F07878, 0x6F4A2525, 0x725C2E2E, 0x24381C1C, 0xF157A6A6, 0xC773B4B4, 0x5197C6C6,
- 0x23CBE8E8, 0x7CA1DDDD, 0x9CE87474, 0x213E1F1F, 0xDD964B4B, 0xDC61BDBD, 0x860D8B8B, 0x850F8A8A,
- 0x90E07070, 0x427C3E3E, 0xC471B5B5, 0xAACC6666, 0xD8904848, 0x05060303, 0x01F7F6F6, 0x121C0E0E,
- 0xA3C26161, 0x5F6A3535, 0xF9AE5757, 0xD069B9B9, 0x91178686, 0x5899C1C1, 0x273A1D1D, 0xB9279E9E,
- 0x38D9E1E1, 0x13EBF8F8, 0xB32B9898, 0x33221111, 0xBBD26969, 0x70A9D9D9, 0x89078E8E, 0xA7339494,
- 0xB62D9B9B, 0x223C1E1E, 0x92158787, 0x20C9E9E9, 0x4987CECE, 0xFFAA5555, 0x78502828, 0x7AA5DFDF,
- 0x8F038C8C, 0xF859A1A1, 0x80098989, 0x171A0D0D, 0xDA65BFBF, 0x31D7E6E6, 0xC6844242, 0xB8D06868,
- 0xC3824141, 0xB0299999, 0x775A2D2D, 0x111E0F0F, 0xCB7BB0B0, 0xFCA85454, 0xD66DBBBB, 0x3A2C1616
- );
-
- /**
- * Precomputed mixColumns table
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $t2 = array(
- 0x63A5C663, 0x7C84F87C, 0x7799EE77, 0x7B8DF67B, 0xF20DFFF2, 0x6BBDD66B, 0x6FB1DE6F, 0xC55491C5,
- 0x30506030, 0x01030201, 0x67A9CE67, 0x2B7D562B, 0xFE19E7FE, 0xD762B5D7, 0xABE64DAB, 0x769AEC76,
- 0xCA458FCA, 0x829D1F82, 0xC94089C9, 0x7D87FA7D, 0xFA15EFFA, 0x59EBB259, 0x47C98E47, 0xF00BFBF0,
- 0xADEC41AD, 0xD467B3D4, 0xA2FD5FA2, 0xAFEA45AF, 0x9CBF239C, 0xA4F753A4, 0x7296E472, 0xC05B9BC0,
- 0xB7C275B7, 0xFD1CE1FD, 0x93AE3D93, 0x266A4C26, 0x365A6C36, 0x3F417E3F, 0xF702F5F7, 0xCC4F83CC,
- 0x345C6834, 0xA5F451A5, 0xE534D1E5, 0xF108F9F1, 0x7193E271, 0xD873ABD8, 0x31536231, 0x153F2A15,
- 0x040C0804, 0xC75295C7, 0x23654623, 0xC35E9DC3, 0x18283018, 0x96A13796, 0x050F0A05, 0x9AB52F9A,
- 0x07090E07, 0x12362412, 0x809B1B80, 0xE23DDFE2, 0xEB26CDEB, 0x27694E27, 0xB2CD7FB2, 0x759FEA75,
- 0x091B1209, 0x839E1D83, 0x2C74582C, 0x1A2E341A, 0x1B2D361B, 0x6EB2DC6E, 0x5AEEB45A, 0xA0FB5BA0,
- 0x52F6A452, 0x3B4D763B, 0xD661B7D6, 0xB3CE7DB3, 0x297B5229, 0xE33EDDE3, 0x2F715E2F, 0x84971384,
- 0x53F5A653, 0xD168B9D1, 0x00000000, 0xED2CC1ED, 0x20604020, 0xFC1FE3FC, 0xB1C879B1, 0x5BEDB65B,
- 0x6ABED46A, 0xCB468DCB, 0xBED967BE, 0x394B7239, 0x4ADE944A, 0x4CD4984C, 0x58E8B058, 0xCF4A85CF,
- 0xD06BBBD0, 0xEF2AC5EF, 0xAAE54FAA, 0xFB16EDFB, 0x43C58643, 0x4DD79A4D, 0x33556633, 0x85941185,
- 0x45CF8A45, 0xF910E9F9, 0x02060402, 0x7F81FE7F, 0x50F0A050, 0x3C44783C, 0x9FBA259F, 0xA8E34BA8,
- 0x51F3A251, 0xA3FE5DA3, 0x40C08040, 0x8F8A058F, 0x92AD3F92, 0x9DBC219D, 0x38487038, 0xF504F1F5,
- 0xBCDF63BC, 0xB6C177B6, 0xDA75AFDA, 0x21634221, 0x10302010, 0xFF1AE5FF, 0xF30EFDF3, 0xD26DBFD2,
- 0xCD4C81CD, 0x0C14180C, 0x13352613, 0xEC2FC3EC, 0x5FE1BE5F, 0x97A23597, 0x44CC8844, 0x17392E17,
- 0xC45793C4, 0xA7F255A7, 0x7E82FC7E, 0x3D477A3D, 0x64ACC864, 0x5DE7BA5D, 0x192B3219, 0x7395E673,
- 0x60A0C060, 0x81981981, 0x4FD19E4F, 0xDC7FA3DC, 0x22664422, 0x2A7E542A, 0x90AB3B90, 0x88830B88,
- 0x46CA8C46, 0xEE29C7EE, 0xB8D36BB8, 0x143C2814, 0xDE79A7DE, 0x5EE2BC5E, 0x0B1D160B, 0xDB76ADDB,
- 0xE03BDBE0, 0x32566432, 0x3A4E743A, 0x0A1E140A, 0x49DB9249, 0x060A0C06, 0x246C4824, 0x5CE4B85C,
- 0xC25D9FC2, 0xD36EBDD3, 0xACEF43AC, 0x62A6C462, 0x91A83991, 0x95A43195, 0xE437D3E4, 0x798BF279,
- 0xE732D5E7, 0xC8438BC8, 0x37596E37, 0x6DB7DA6D, 0x8D8C018D, 0xD564B1D5, 0x4ED29C4E, 0xA9E049A9,
- 0x6CB4D86C, 0x56FAAC56, 0xF407F3F4, 0xEA25CFEA, 0x65AFCA65, 0x7A8EF47A, 0xAEE947AE, 0x08181008,
- 0xBAD56FBA, 0x7888F078, 0x256F4A25, 0x2E725C2E, 0x1C24381C, 0xA6F157A6, 0xB4C773B4, 0xC65197C6,
- 0xE823CBE8, 0xDD7CA1DD, 0x749CE874, 0x1F213E1F, 0x4BDD964B, 0xBDDC61BD, 0x8B860D8B, 0x8A850F8A,
- 0x7090E070, 0x3E427C3E, 0xB5C471B5, 0x66AACC66, 0x48D89048, 0x03050603, 0xF601F7F6, 0x0E121C0E,
- 0x61A3C261, 0x355F6A35, 0x57F9AE57, 0xB9D069B9, 0x86911786, 0xC15899C1, 0x1D273A1D, 0x9EB9279E,
- 0xE138D9E1, 0xF813EBF8, 0x98B32B98, 0x11332211, 0x69BBD269, 0xD970A9D9, 0x8E89078E, 0x94A73394,
- 0x9BB62D9B, 0x1E223C1E, 0x87921587, 0xE920C9E9, 0xCE4987CE, 0x55FFAA55, 0x28785028, 0xDF7AA5DF,
- 0x8C8F038C, 0xA1F859A1, 0x89800989, 0x0D171A0D, 0xBFDA65BF, 0xE631D7E6, 0x42C68442, 0x68B8D068,
- 0x41C38241, 0x99B02999, 0x2D775A2D, 0x0F111E0F, 0xB0CB7BB0, 0x54FCA854, 0xBBD66DBB, 0x163A2C16
- );
-
- /**
- * Precomputed mixColumns table
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $t3 = array(
- 0x6363A5C6, 0x7C7C84F8, 0x777799EE, 0x7B7B8DF6, 0xF2F20DFF, 0x6B6BBDD6, 0x6F6FB1DE, 0xC5C55491,
- 0x30305060, 0x01010302, 0x6767A9CE, 0x2B2B7D56, 0xFEFE19E7, 0xD7D762B5, 0xABABE64D, 0x76769AEC,
- 0xCACA458F, 0x82829D1F, 0xC9C94089, 0x7D7D87FA, 0xFAFA15EF, 0x5959EBB2, 0x4747C98E, 0xF0F00BFB,
- 0xADADEC41, 0xD4D467B3, 0xA2A2FD5F, 0xAFAFEA45, 0x9C9CBF23, 0xA4A4F753, 0x727296E4, 0xC0C05B9B,
- 0xB7B7C275, 0xFDFD1CE1, 0x9393AE3D, 0x26266A4C, 0x36365A6C, 0x3F3F417E, 0xF7F702F5, 0xCCCC4F83,
- 0x34345C68, 0xA5A5F451, 0xE5E534D1, 0xF1F108F9, 0x717193E2, 0xD8D873AB, 0x31315362, 0x15153F2A,
- 0x04040C08, 0xC7C75295, 0x23236546, 0xC3C35E9D, 0x18182830, 0x9696A137, 0x05050F0A, 0x9A9AB52F,
- 0x0707090E, 0x12123624, 0x80809B1B, 0xE2E23DDF, 0xEBEB26CD, 0x2727694E, 0xB2B2CD7F, 0x75759FEA,
- 0x09091B12, 0x83839E1D, 0x2C2C7458, 0x1A1A2E34, 0x1B1B2D36, 0x6E6EB2DC, 0x5A5AEEB4, 0xA0A0FB5B,
- 0x5252F6A4, 0x3B3B4D76, 0xD6D661B7, 0xB3B3CE7D, 0x29297B52, 0xE3E33EDD, 0x2F2F715E, 0x84849713,
- 0x5353F5A6, 0xD1D168B9, 0x00000000, 0xEDED2CC1, 0x20206040, 0xFCFC1FE3, 0xB1B1C879, 0x5B5BEDB6,
- 0x6A6ABED4, 0xCBCB468D, 0xBEBED967, 0x39394B72, 0x4A4ADE94, 0x4C4CD498, 0x5858E8B0, 0xCFCF4A85,
- 0xD0D06BBB, 0xEFEF2AC5, 0xAAAAE54F, 0xFBFB16ED, 0x4343C586, 0x4D4DD79A, 0x33335566, 0x85859411,
- 0x4545CF8A, 0xF9F910E9, 0x02020604, 0x7F7F81FE, 0x5050F0A0, 0x3C3C4478, 0x9F9FBA25, 0xA8A8E34B,
- 0x5151F3A2, 0xA3A3FE5D, 0x4040C080, 0x8F8F8A05, 0x9292AD3F, 0x9D9DBC21, 0x38384870, 0xF5F504F1,
- 0xBCBCDF63, 0xB6B6C177, 0xDADA75AF, 0x21216342, 0x10103020, 0xFFFF1AE5, 0xF3F30EFD, 0xD2D26DBF,
- 0xCDCD4C81, 0x0C0C1418, 0x13133526, 0xECEC2FC3, 0x5F5FE1BE, 0x9797A235, 0x4444CC88, 0x1717392E,
- 0xC4C45793, 0xA7A7F255, 0x7E7E82FC, 0x3D3D477A, 0x6464ACC8, 0x5D5DE7BA, 0x19192B32, 0x737395E6,
- 0x6060A0C0, 0x81819819, 0x4F4FD19E, 0xDCDC7FA3, 0x22226644, 0x2A2A7E54, 0x9090AB3B, 0x8888830B,
- 0x4646CA8C, 0xEEEE29C7, 0xB8B8D36B, 0x14143C28, 0xDEDE79A7, 0x5E5EE2BC, 0x0B0B1D16, 0xDBDB76AD,
- 0xE0E03BDB, 0x32325664, 0x3A3A4E74, 0x0A0A1E14, 0x4949DB92, 0x06060A0C, 0x24246C48, 0x5C5CE4B8,
- 0xC2C25D9F, 0xD3D36EBD, 0xACACEF43, 0x6262A6C4, 0x9191A839, 0x9595A431, 0xE4E437D3, 0x79798BF2,
- 0xE7E732D5, 0xC8C8438B, 0x3737596E, 0x6D6DB7DA, 0x8D8D8C01, 0xD5D564B1, 0x4E4ED29C, 0xA9A9E049,
- 0x6C6CB4D8, 0x5656FAAC, 0xF4F407F3, 0xEAEA25CF, 0x6565AFCA, 0x7A7A8EF4, 0xAEAEE947, 0x08081810,
- 0xBABAD56F, 0x787888F0, 0x25256F4A, 0x2E2E725C, 0x1C1C2438, 0xA6A6F157, 0xB4B4C773, 0xC6C65197,
- 0xE8E823CB, 0xDDDD7CA1, 0x74749CE8, 0x1F1F213E, 0x4B4BDD96, 0xBDBDDC61, 0x8B8B860D, 0x8A8A850F,
- 0x707090E0, 0x3E3E427C, 0xB5B5C471, 0x6666AACC, 0x4848D890, 0x03030506, 0xF6F601F7, 0x0E0E121C,
- 0x6161A3C2, 0x35355F6A, 0x5757F9AE, 0xB9B9D069, 0x86869117, 0xC1C15899, 0x1D1D273A, 0x9E9EB927,
- 0xE1E138D9, 0xF8F813EB, 0x9898B32B, 0x11113322, 0x6969BBD2, 0xD9D970A9, 0x8E8E8907, 0x9494A733,
- 0x9B9BB62D, 0x1E1E223C, 0x87879215, 0xE9E920C9, 0xCECE4987, 0x5555FFAA, 0x28287850, 0xDFDF7AA5,
- 0x8C8C8F03, 0xA1A1F859, 0x89898009, 0x0D0D171A, 0xBFBFDA65, 0xE6E631D7, 0x4242C684, 0x6868B8D0,
- 0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C
- );
-
- /**
- * Precomputed invMixColumns table
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $dt0 = array(
- 0x51F4A750, 0x7E416553, 0x1A17A4C3, 0x3A275E96, 0x3BAB6BCB, 0x1F9D45F1, 0xACFA58AB, 0x4BE30393,
- 0x2030FA55, 0xAD766DF6, 0x88CC7691, 0xF5024C25, 0x4FE5D7FC, 0xC52ACBD7, 0x26354480, 0xB562A38F,
- 0xDEB15A49, 0x25BA1B67, 0x45EA0E98, 0x5DFEC0E1, 0xC32F7502, 0x814CF012, 0x8D4697A3, 0x6BD3F9C6,
- 0x038F5FE7, 0x15929C95, 0xBF6D7AEB, 0x955259DA, 0xD4BE832D, 0x587421D3, 0x49E06929, 0x8EC9C844,
- 0x75C2896A, 0xF48E7978, 0x99583E6B, 0x27B971DD, 0xBEE14FB6, 0xF088AD17, 0xC920AC66, 0x7DCE3AB4,
- 0x63DF4A18, 0xE51A3182, 0x97513360, 0x62537F45, 0xB16477E0, 0xBB6BAE84, 0xFE81A01C, 0xF9082B94,
- 0x70486858, 0x8F45FD19, 0x94DE6C87, 0x527BF8B7, 0xAB73D323, 0x724B02E2, 0xE31F8F57, 0x6655AB2A,
- 0xB2EB2807, 0x2FB5C203, 0x86C57B9A, 0xD33708A5, 0x302887F2, 0x23BFA5B2, 0x02036ABA, 0xED16825C,
- 0x8ACF1C2B, 0xA779B492, 0xF307F2F0, 0x4E69E2A1, 0x65DAF4CD, 0x0605BED5, 0xD134621F, 0xC4A6FE8A,
- 0x342E539D, 0xA2F355A0, 0x058AE132, 0xA4F6EB75, 0x0B83EC39, 0x4060EFAA, 0x5E719F06, 0xBD6E1051,
- 0x3E218AF9, 0x96DD063D, 0xDD3E05AE, 0x4DE6BD46, 0x91548DB5, 0x71C45D05, 0x0406D46F, 0x605015FF,
- 0x1998FB24, 0xD6BDE997, 0x894043CC, 0x67D99E77, 0xB0E842BD, 0x07898B88, 0xE7195B38, 0x79C8EEDB,
- 0xA17C0A47, 0x7C420FE9, 0xF8841EC9, 0x00000000, 0x09808683, 0x322BED48, 0x1E1170AC, 0x6C5A724E,
- 0xFD0EFFFB, 0x0F853856, 0x3DAED51E, 0x362D3927, 0x0A0FD964, 0x685CA621, 0x9B5B54D1, 0x24362E3A,
- 0x0C0A67B1, 0x9357E70F, 0xB4EE96D2, 0x1B9B919E, 0x80C0C54F, 0x61DC20A2, 0x5A774B69, 0x1C121A16,
- 0xE293BA0A, 0xC0A02AE5, 0x3C22E043, 0x121B171D, 0x0E090D0B, 0xF28BC7AD, 0x2DB6A8B9, 0x141EA9C8,
- 0x57F11985, 0xAF75074C, 0xEE99DDBB, 0xA37F60FD, 0xF701269F, 0x5C72F5BC, 0x44663BC5, 0x5BFB7E34,
- 0x8B432976, 0xCB23C6DC, 0xB6EDFC68, 0xB8E4F163, 0xD731DCCA, 0x42638510, 0x13972240, 0x84C61120,
- 0x854A247D, 0xD2BB3DF8, 0xAEF93211, 0xC729A16D, 0x1D9E2F4B, 0xDCB230F3, 0x0D8652EC, 0x77C1E3D0,
- 0x2BB3166C, 0xA970B999, 0x119448FA, 0x47E96422, 0xA8FC8CC4, 0xA0F03F1A, 0x567D2CD8, 0x223390EF,
- 0x87494EC7, 0xD938D1C1, 0x8CCAA2FE, 0x98D40B36, 0xA6F581CF, 0xA57ADE28, 0xDAB78E26, 0x3FADBFA4,
- 0x2C3A9DE4, 0x5078920D, 0x6A5FCC9B, 0x547E4662, 0xF68D13C2, 0x90D8B8E8, 0x2E39F75E, 0x82C3AFF5,
- 0x9F5D80BE, 0x69D0937C, 0x6FD52DA9, 0xCF2512B3, 0xC8AC993B, 0x10187DA7, 0xE89C636E, 0xDB3BBB7B,
- 0xCD267809, 0x6E5918F4, 0xEC9AB701, 0x834F9AA8, 0xE6956E65, 0xAAFFE67E, 0x21BCCF08, 0xEF15E8E6,
- 0xBAE79BD9, 0x4A6F36CE, 0xEA9F09D4, 0x29B07CD6, 0x31A4B2AF, 0x2A3F2331, 0xC6A59430, 0x35A266C0,
- 0x744EBC37, 0xFC82CAA6, 0xE090D0B0, 0x33A7D815, 0xF104984A, 0x41ECDAF7, 0x7FCD500E, 0x1791F62F,
- 0x764DD68D, 0x43EFB04D, 0xCCAA4D54, 0xE49604DF, 0x9ED1B5E3, 0x4C6A881B, 0xC12C1FB8, 0x4665517F,
- 0x9D5EEA04, 0x018C355D, 0xFA877473, 0xFB0B412E, 0xB3671D5A, 0x92DBD252, 0xE9105633, 0x6DD64713,
- 0x9AD7618C, 0x37A10C7A, 0x59F8148E, 0xEB133C89, 0xCEA927EE, 0xB761C935, 0xE11CE5ED, 0x7A47B13C,
- 0x9CD2DF59, 0x55F2733F, 0x1814CE79, 0x73C737BF, 0x53F7CDEA, 0x5FFDAA5B, 0xDF3D6F14, 0x7844DB86,
- 0xCAAFF381, 0xB968C43E, 0x3824342C, 0xC2A3405F, 0x161DC372, 0xBCE2250C, 0x283C498B, 0xFF0D9541,
- 0x39A80171, 0x080CB3DE, 0xD8B4E49C, 0x6456C190, 0x7BCB8461, 0xD532B670, 0x486C5C74, 0xD0B85742
- );
-
- /**
- * Precomputed invMixColumns table
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $dt1 = array(
- 0x5051F4A7, 0x537E4165, 0xC31A17A4, 0x963A275E, 0xCB3BAB6B, 0xF11F9D45, 0xABACFA58, 0x934BE303,
- 0x552030FA, 0xF6AD766D, 0x9188CC76, 0x25F5024C, 0xFC4FE5D7, 0xD7C52ACB, 0x80263544, 0x8FB562A3,
- 0x49DEB15A, 0x6725BA1B, 0x9845EA0E, 0xE15DFEC0, 0x02C32F75, 0x12814CF0, 0xA38D4697, 0xC66BD3F9,
- 0xE7038F5F, 0x9515929C, 0xEBBF6D7A, 0xDA955259, 0x2DD4BE83, 0xD3587421, 0x2949E069, 0x448EC9C8,
- 0x6A75C289, 0x78F48E79, 0x6B99583E, 0xDD27B971, 0xB6BEE14F, 0x17F088AD, 0x66C920AC, 0xB47DCE3A,
- 0x1863DF4A, 0x82E51A31, 0x60975133, 0x4562537F, 0xE0B16477, 0x84BB6BAE, 0x1CFE81A0, 0x94F9082B,
- 0x58704868, 0x198F45FD, 0x8794DE6C, 0xB7527BF8, 0x23AB73D3, 0xE2724B02, 0x57E31F8F, 0x2A6655AB,
- 0x07B2EB28, 0x032FB5C2, 0x9A86C57B, 0xA5D33708, 0xF2302887, 0xB223BFA5, 0xBA02036A, 0x5CED1682,
- 0x2B8ACF1C, 0x92A779B4, 0xF0F307F2, 0xA14E69E2, 0xCD65DAF4, 0xD50605BE, 0x1FD13462, 0x8AC4A6FE,
- 0x9D342E53, 0xA0A2F355, 0x32058AE1, 0x75A4F6EB, 0x390B83EC, 0xAA4060EF, 0x065E719F, 0x51BD6E10,
- 0xF93E218A, 0x3D96DD06, 0xAEDD3E05, 0x464DE6BD, 0xB591548D, 0x0571C45D, 0x6F0406D4, 0xFF605015,
- 0x241998FB, 0x97D6BDE9, 0xCC894043, 0x7767D99E, 0xBDB0E842, 0x8807898B, 0x38E7195B, 0xDB79C8EE,
- 0x47A17C0A, 0xE97C420F, 0xC9F8841E, 0x00000000, 0x83098086, 0x48322BED, 0xAC1E1170, 0x4E6C5A72,
- 0xFBFD0EFF, 0x560F8538, 0x1E3DAED5, 0x27362D39, 0x640A0FD9, 0x21685CA6, 0xD19B5B54, 0x3A24362E,
- 0xB10C0A67, 0x0F9357E7, 0xD2B4EE96, 0x9E1B9B91, 0x4F80C0C5, 0xA261DC20, 0x695A774B, 0x161C121A,
- 0x0AE293BA, 0xE5C0A02A, 0x433C22E0, 0x1D121B17, 0x0B0E090D, 0xADF28BC7, 0xB92DB6A8, 0xC8141EA9,
- 0x8557F119, 0x4CAF7507, 0xBBEE99DD, 0xFDA37F60, 0x9FF70126, 0xBC5C72F5, 0xC544663B, 0x345BFB7E,
- 0x768B4329, 0xDCCB23C6, 0x68B6EDFC, 0x63B8E4F1, 0xCAD731DC, 0x10426385, 0x40139722, 0x2084C611,
- 0x7D854A24, 0xF8D2BB3D, 0x11AEF932, 0x6DC729A1, 0x4B1D9E2F, 0xF3DCB230, 0xEC0D8652, 0xD077C1E3,
- 0x6C2BB316, 0x99A970B9, 0xFA119448, 0x2247E964, 0xC4A8FC8C, 0x1AA0F03F, 0xD8567D2C, 0xEF223390,
- 0xC787494E, 0xC1D938D1, 0xFE8CCAA2, 0x3698D40B, 0xCFA6F581, 0x28A57ADE, 0x26DAB78E, 0xA43FADBF,
- 0xE42C3A9D, 0x0D507892, 0x9B6A5FCC, 0x62547E46, 0xC2F68D13, 0xE890D8B8, 0x5E2E39F7, 0xF582C3AF,
- 0xBE9F5D80, 0x7C69D093, 0xA96FD52D, 0xB3CF2512, 0x3BC8AC99, 0xA710187D, 0x6EE89C63, 0x7BDB3BBB,
- 0x09CD2678, 0xF46E5918, 0x01EC9AB7, 0xA8834F9A, 0x65E6956E, 0x7EAAFFE6, 0x0821BCCF, 0xE6EF15E8,
- 0xD9BAE79B, 0xCE4A6F36, 0xD4EA9F09, 0xD629B07C, 0xAF31A4B2, 0x312A3F23, 0x30C6A594, 0xC035A266,
- 0x37744EBC, 0xA6FC82CA, 0xB0E090D0, 0x1533A7D8, 0x4AF10498, 0xF741ECDA, 0x0E7FCD50, 0x2F1791F6,
- 0x8D764DD6, 0x4D43EFB0, 0x54CCAA4D, 0xDFE49604, 0xE39ED1B5, 0x1B4C6A88, 0xB8C12C1F, 0x7F466551,
- 0x049D5EEA, 0x5D018C35, 0x73FA8774, 0x2EFB0B41, 0x5AB3671D, 0x5292DBD2, 0x33E91056, 0x136DD647,
- 0x8C9AD761, 0x7A37A10C, 0x8E59F814, 0x89EB133C, 0xEECEA927, 0x35B761C9, 0xEDE11CE5, 0x3C7A47B1,
- 0x599CD2DF, 0x3F55F273, 0x791814CE, 0xBF73C737, 0xEA53F7CD, 0x5B5FFDAA, 0x14DF3D6F, 0x867844DB,
- 0x81CAAFF3, 0x3EB968C4, 0x2C382434, 0x5FC2A340, 0x72161DC3, 0x0CBCE225, 0x8B283C49, 0x41FF0D95,
- 0x7139A801, 0xDE080CB3, 0x9CD8B4E4, 0x906456C1, 0x617BCB84, 0x70D532B6, 0x74486C5C, 0x42D0B857
- );
-
- /**
- * Precomputed invMixColumns table
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $dt2 = array(
- 0xA75051F4, 0x65537E41, 0xA4C31A17, 0x5E963A27, 0x6BCB3BAB, 0x45F11F9D, 0x58ABACFA, 0x03934BE3,
- 0xFA552030, 0x6DF6AD76, 0x769188CC, 0x4C25F502, 0xD7FC4FE5, 0xCBD7C52A, 0x44802635, 0xA38FB562,
- 0x5A49DEB1, 0x1B6725BA, 0x0E9845EA, 0xC0E15DFE, 0x7502C32F, 0xF012814C, 0x97A38D46, 0xF9C66BD3,
- 0x5FE7038F, 0x9C951592, 0x7AEBBF6D, 0x59DA9552, 0x832DD4BE, 0x21D35874, 0x692949E0, 0xC8448EC9,
- 0x896A75C2, 0x7978F48E, 0x3E6B9958, 0x71DD27B9, 0x4FB6BEE1, 0xAD17F088, 0xAC66C920, 0x3AB47DCE,
- 0x4A1863DF, 0x3182E51A, 0x33609751, 0x7F456253, 0x77E0B164, 0xAE84BB6B, 0xA01CFE81, 0x2B94F908,
- 0x68587048, 0xFD198F45, 0x6C8794DE, 0xF8B7527B, 0xD323AB73, 0x02E2724B, 0x8F57E31F, 0xAB2A6655,
- 0x2807B2EB, 0xC2032FB5, 0x7B9A86C5, 0x08A5D337, 0x87F23028, 0xA5B223BF, 0x6ABA0203, 0x825CED16,
- 0x1C2B8ACF, 0xB492A779, 0xF2F0F307, 0xE2A14E69, 0xF4CD65DA, 0xBED50605, 0x621FD134, 0xFE8AC4A6,
- 0x539D342E, 0x55A0A2F3, 0xE132058A, 0xEB75A4F6, 0xEC390B83, 0xEFAA4060, 0x9F065E71, 0x1051BD6E,
- 0x8AF93E21, 0x063D96DD, 0x05AEDD3E, 0xBD464DE6, 0x8DB59154, 0x5D0571C4, 0xD46F0406, 0x15FF6050,
- 0xFB241998, 0xE997D6BD, 0x43CC8940, 0x9E7767D9, 0x42BDB0E8, 0x8B880789, 0x5B38E719, 0xEEDB79C8,
- 0x0A47A17C, 0x0FE97C42, 0x1EC9F884, 0x00000000, 0x86830980, 0xED48322B, 0x70AC1E11, 0x724E6C5A,
- 0xFFFBFD0E, 0x38560F85, 0xD51E3DAE, 0x3927362D, 0xD9640A0F, 0xA621685C, 0x54D19B5B, 0x2E3A2436,
- 0x67B10C0A, 0xE70F9357, 0x96D2B4EE, 0x919E1B9B, 0xC54F80C0, 0x20A261DC, 0x4B695A77, 0x1A161C12,
- 0xBA0AE293, 0x2AE5C0A0, 0xE0433C22, 0x171D121B, 0x0D0B0E09, 0xC7ADF28B, 0xA8B92DB6, 0xA9C8141E,
- 0x198557F1, 0x074CAF75, 0xDDBBEE99, 0x60FDA37F, 0x269FF701, 0xF5BC5C72, 0x3BC54466, 0x7E345BFB,
- 0x29768B43, 0xC6DCCB23, 0xFC68B6ED, 0xF163B8E4, 0xDCCAD731, 0x85104263, 0x22401397, 0x112084C6,
- 0x247D854A, 0x3DF8D2BB, 0x3211AEF9, 0xA16DC729, 0x2F4B1D9E, 0x30F3DCB2, 0x52EC0D86, 0xE3D077C1,
- 0x166C2BB3, 0xB999A970, 0x48FA1194, 0x642247E9, 0x8CC4A8FC, 0x3F1AA0F0, 0x2CD8567D, 0x90EF2233,
- 0x4EC78749, 0xD1C1D938, 0xA2FE8CCA, 0x0B3698D4, 0x81CFA6F5, 0xDE28A57A, 0x8E26DAB7, 0xBFA43FAD,
- 0x9DE42C3A, 0x920D5078, 0xCC9B6A5F, 0x4662547E, 0x13C2F68D, 0xB8E890D8, 0xF75E2E39, 0xAFF582C3,
- 0x80BE9F5D, 0x937C69D0, 0x2DA96FD5, 0x12B3CF25, 0x993BC8AC, 0x7DA71018, 0x636EE89C, 0xBB7BDB3B,
- 0x7809CD26, 0x18F46E59, 0xB701EC9A, 0x9AA8834F, 0x6E65E695, 0xE67EAAFF, 0xCF0821BC, 0xE8E6EF15,
- 0x9BD9BAE7, 0x36CE4A6F, 0x09D4EA9F, 0x7CD629B0, 0xB2AF31A4, 0x23312A3F, 0x9430C6A5, 0x66C035A2,
- 0xBC37744E, 0xCAA6FC82, 0xD0B0E090, 0xD81533A7, 0x984AF104, 0xDAF741EC, 0x500E7FCD, 0xF62F1791,
- 0xD68D764D, 0xB04D43EF, 0x4D54CCAA, 0x04DFE496, 0xB5E39ED1, 0x881B4C6A, 0x1FB8C12C, 0x517F4665,
- 0xEA049D5E, 0x355D018C, 0x7473FA87, 0x412EFB0B, 0x1D5AB367, 0xD25292DB, 0x5633E910, 0x47136DD6,
- 0x618C9AD7, 0x0C7A37A1, 0x148E59F8, 0x3C89EB13, 0x27EECEA9, 0xC935B761, 0xE5EDE11C, 0xB13C7A47,
- 0xDF599CD2, 0x733F55F2, 0xCE791814, 0x37BF73C7, 0xCDEA53F7, 0xAA5B5FFD, 0x6F14DF3D, 0xDB867844,
- 0xF381CAAF, 0xC43EB968, 0x342C3824, 0x405FC2A3, 0xC372161D, 0x250CBCE2, 0x498B283C, 0x9541FF0D,
- 0x017139A8, 0xB3DE080C, 0xE49CD8B4, 0xC1906456, 0x84617BCB, 0xB670D532, 0x5C74486C, 0x5742D0B8
- );
-
- /**
- * Precomputed invMixColumns table
- *
- * @see Crypt_Rijndael:_encryptBlock()
- * @see Crypt_Rijndael:_decryptBlock()
- * @var Array
- * @access private
- */
- var $dt3 = array(
- 0xF4A75051, 0x4165537E, 0x17A4C31A, 0x275E963A, 0xAB6BCB3B, 0x9D45F11F, 0xFA58ABAC, 0xE303934B,
- 0x30FA5520, 0x766DF6AD, 0xCC769188, 0x024C25F5, 0xE5D7FC4F, 0x2ACBD7C5, 0x35448026, 0x62A38FB5,
- 0xB15A49DE, 0xBA1B6725, 0xEA0E9845, 0xFEC0E15D, 0x2F7502C3, 0x4CF01281, 0x4697A38D, 0xD3F9C66B,
- 0x8F5FE703, 0x929C9515, 0x6D7AEBBF, 0x5259DA95, 0xBE832DD4, 0x7421D358, 0xE0692949, 0xC9C8448E,
- 0xC2896A75, 0x8E7978F4, 0x583E6B99, 0xB971DD27, 0xE14FB6BE, 0x88AD17F0, 0x20AC66C9, 0xCE3AB47D,
- 0xDF4A1863, 0x1A3182E5, 0x51336097, 0x537F4562, 0x6477E0B1, 0x6BAE84BB, 0x81A01CFE, 0x082B94F9,
- 0x48685870, 0x45FD198F, 0xDE6C8794, 0x7BF8B752, 0x73D323AB, 0x4B02E272, 0x1F8F57E3, 0x55AB2A66,
- 0xEB2807B2, 0xB5C2032F, 0xC57B9A86, 0x3708A5D3, 0x2887F230, 0xBFA5B223, 0x036ABA02, 0x16825CED,
- 0xCF1C2B8A, 0x79B492A7, 0x07F2F0F3, 0x69E2A14E, 0xDAF4CD65, 0x05BED506, 0x34621FD1, 0xA6FE8AC4,
- 0x2E539D34, 0xF355A0A2, 0x8AE13205, 0xF6EB75A4, 0x83EC390B, 0x60EFAA40, 0x719F065E, 0x6E1051BD,
- 0x218AF93E, 0xDD063D96, 0x3E05AEDD, 0xE6BD464D, 0x548DB591, 0xC45D0571, 0x06D46F04, 0x5015FF60,
- 0x98FB2419, 0xBDE997D6, 0x4043CC89, 0xD99E7767, 0xE842BDB0, 0x898B8807, 0x195B38E7, 0xC8EEDB79,
- 0x7C0A47A1, 0x420FE97C, 0x841EC9F8, 0x00000000, 0x80868309, 0x2BED4832, 0x1170AC1E, 0x5A724E6C,
- 0x0EFFFBFD, 0x8538560F, 0xAED51E3D, 0x2D392736, 0x0FD9640A, 0x5CA62168, 0x5B54D19B, 0x362E3A24,
- 0x0A67B10C, 0x57E70F93, 0xEE96D2B4, 0x9B919E1B, 0xC0C54F80, 0xDC20A261, 0x774B695A, 0x121A161C,
- 0x93BA0AE2, 0xA02AE5C0, 0x22E0433C, 0x1B171D12, 0x090D0B0E, 0x8BC7ADF2, 0xB6A8B92D, 0x1EA9C814,
- 0xF1198557, 0x75074CAF, 0x99DDBBEE, 0x7F60FDA3, 0x01269FF7, 0x72F5BC5C, 0x663BC544, 0xFB7E345B,
- 0x4329768B, 0x23C6DCCB, 0xEDFC68B6, 0xE4F163B8, 0x31DCCAD7, 0x63851042, 0x97224013, 0xC6112084,
- 0x4A247D85, 0xBB3DF8D2, 0xF93211AE, 0x29A16DC7, 0x9E2F4B1D, 0xB230F3DC, 0x8652EC0D, 0xC1E3D077,
- 0xB3166C2B, 0x70B999A9, 0x9448FA11, 0xE9642247, 0xFC8CC4A8, 0xF03F1AA0, 0x7D2CD856, 0x3390EF22,
- 0x494EC787, 0x38D1C1D9, 0xCAA2FE8C, 0xD40B3698, 0xF581CFA6, 0x7ADE28A5, 0xB78E26DA, 0xADBFA43F,
- 0x3A9DE42C, 0x78920D50, 0x5FCC9B6A, 0x7E466254, 0x8D13C2F6, 0xD8B8E890, 0x39F75E2E, 0xC3AFF582,
- 0x5D80BE9F, 0xD0937C69, 0xD52DA96F, 0x2512B3CF, 0xAC993BC8, 0x187DA710, 0x9C636EE8, 0x3BBB7BDB,
- 0x267809CD, 0x5918F46E, 0x9AB701EC, 0x4F9AA883, 0x956E65E6, 0xFFE67EAA, 0xBCCF0821, 0x15E8E6EF,
- 0xE79BD9BA, 0x6F36CE4A, 0x9F09D4EA, 0xB07CD629, 0xA4B2AF31, 0x3F23312A, 0xA59430C6, 0xA266C035,
- 0x4EBC3774, 0x82CAA6FC, 0x90D0B0E0, 0xA7D81533, 0x04984AF1, 0xECDAF741, 0xCD500E7F, 0x91F62F17,
- 0x4DD68D76, 0xEFB04D43, 0xAA4D54CC, 0x9604DFE4, 0xD1B5E39E, 0x6A881B4C, 0x2C1FB8C1, 0x65517F46,
- 0x5EEA049D, 0x8C355D01, 0x877473FA, 0x0B412EFB, 0x671D5AB3, 0xDBD25292, 0x105633E9, 0xD647136D,
- 0xD7618C9A, 0xA10C7A37, 0xF8148E59, 0x133C89EB, 0xA927EECE, 0x61C935B7, 0x1CE5EDE1, 0x47B13C7A,
- 0xD2DF599C, 0xF2733F55, 0x14CE7918, 0xC737BF73, 0xF7CDEA53, 0xFDAA5B5F, 0x3D6F14DF, 0x44DB8678,
- 0xAFF381CA, 0x68C43EB9, 0x24342C38, 0xA3405FC2, 0x1DC37216, 0xE2250CBC, 0x3C498B28, 0x0D9541FF,
- 0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0
- );
-
- /**
- * The SubByte S-Box
- *
- * @see Crypt_Rijndael::_encryptBlock()
- * @var Array
- * @access private
- */
- var $sbox = array(
- 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
- 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
- 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
- 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
- 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
- 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
- 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
- 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
- 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
- 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
- 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
- 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
- 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
- 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
- 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
- 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
- );
-
- /**
- * The inverse SubByte S-Box
- *
- * @see Crypt_Rijndael::_decryptBlock()
- * @var Array
- * @access private
- */
- var $isbox = array(
- 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
- 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
- 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
- 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
- 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
- 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
- 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
- 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
- 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
- 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
- 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
- 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
- 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
- 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
- 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
- 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
- );
-
- /**
- * Sets the key.
- *
- * Keys can be of any length. Rijndael, itself, requires the use of a key that's between 128-bits and 256-bits long and
- * whose length is a multiple of 32. If the key is less than 256-bits and the key length isn't set, we round the length
- * up to the closest valid key length, padding $key with null bytes. If the key is more than 256-bits, we trim the
- * excess bits.
- *
- * If the key is not explicitly set, it'll be assumed to be all null bytes.
- *
- * Note: 160/224-bit keys must explicitly set by setKeyLength(), otherwise they will be round/pad up to 192/256 bits.
- *
- * @see Crypt_Base:setKey()
- * @see setKeyLength()
- * @access public
- * @param String $key
- */
- function setKey($key)
- {
- parent::setKey($key);
-
- if (!$this->explicit_key_length) {
- $length = strlen($key);
- switch (true) {
- case $length <= 16:
- $this->key_size = 16;
- break;
- case $length <= 20:
- $this->key_size = 20;
- break;
- case $length <= 24:
- $this->key_size = 24;
- break;
- case $length <= 28:
- $this->key_size = 28;
- break;
- default:
- $this->key_size = 32;
- }
- $this->_setupEngine();
- }
- }
-
- /**
- * Sets the key length
+ * Sets the key length.
*
* Valid key lengths are 128, 160, 192, 224, and 256. If the length is less than 128, it will be rounded up to
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
@@ -736,30 +186,28 @@ class Crypt_Rijndael extends Crypt_Base
* This results then in slower encryption.
*
* @access public
- * @param Integer $length
+ * @param int $length
*/
function setKeyLength($length)
{
switch (true) {
- case $length == 160:
- $this->key_size = 20;
- break;
- case $length == 224:
- $this->key_size = 28;
- break;
case $length <= 128:
- $this->key_size = 16;
+ $this->key_length = 16;
+ break;
+ case $length <= 160:
+ $this->key_length = 20;
break;
case $length <= 192:
- $this->key_size = 24;
+ $this->key_length = 24;
+ break;
+ case $length <= 224:
+ $this->key_length = 28;
break;
default:
- $this->key_size = 32;
+ $this->key_length = 32;
}
- $this->explicit_key_length = true;
- $this->changed = true;
- $this->_setupEngine();
+ parent::setKeyLength($length);
}
/**
@@ -769,110 +217,71 @@ class Crypt_Rijndael extends Crypt_Base
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
*
* @access public
- * @param Integer $length
+ * @param int $length
*/
function setBlockLength($length)
{
$length >>= 5;
if ($length > 8) {
$length = 8;
- } else if ($length < 4) {
+ } elseif ($length < 4) {
$length = 4;
}
$this->Nb = $length;
$this->block_size = $length << 2;
$this->changed = true;
- $this->_setupEngine();
+ $this->_setEngine();
}
/**
- * Setup the fastest possible $engine
+ * Test for engine validity
*
- * Determines if the mcrypt (MODE_MCRYPT) $engine available
- * and usable for the current $block_size and $key_size.
+ * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Base::isValidEngine()
*
- * If not, the slower MODE_INTERNAL $engine will be set.
- *
- * @see setKey()
- * @see setKeyLength()
- * @see setBlockLength()
- * @access private
+ * @see \phpseclib\Crypt\Base::__construct()
+ * @param int $engine
+ * @access public
+ * @return bool
*/
- function _setupEngine()
+ function isValidEngine($engine)
{
- if (constant('CRYPT_' . $this->const_namespace . '_MODE') == CRYPT_MODE_INTERNAL) {
- // No mcrypt support at all for rijndael
- return;
- }
-
- // The required mcrypt module name for the current $block_size of rijndael
- $cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3);
-
- // Determining the availibility/usability of $cipher_name_mcrypt
- switch (true) {
- case $this->key_size % 8: // mcrypt is not usable for 160/224-bit keys, only for 128/192/256-bit keys
- case !in_array($cipher_name_mcrypt, mcrypt_list_algorithms()): // $cipher_name_mcrypt is not available for the current $block_size
- $engine = CRYPT_MODE_INTERNAL;
+ switch ($engine) {
+ case self::ENGINE_OPENSSL:
+ if ($this->block_size != 16) {
+ return false;
+ }
+ $this->cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb';
+ $this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->_openssl_translate_mode();
break;
- default:
- $engine = CRYPT_MODE_MCRYPT;
+ case self::ENGINE_MCRYPT:
+ $this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3);
+ if ($this->key_length % 8) { // is it a 160/224-bit key?
+ // mcrypt is not usable for them, only for 128/192/256-bit keys
+ return false;
+ }
}
- if ($this->engine == $engine && $this->cipher_name_mcrypt == $cipher_name_mcrypt) {
- // allready set, so we not unnecessary close $this->enmcrypt/demcrypt/ecb
- return;
- }
-
- // Set the $engine
- $this->engine = $engine;
- $this->cipher_name_mcrypt = $cipher_name_mcrypt;
-
- if ($this->enmcrypt) {
- // Closing the current mcrypt resource(s). _mcryptSetup() will, if needed,
- // (re)open them with the module named in $this->cipher_name_mcrypt
- mcrypt_module_close($this->enmcrypt);
- mcrypt_module_close($this->demcrypt);
- $this->enmcrypt = null;
- $this->demcrypt = null;
-
- if ($this->ecb) {
- mcrypt_module_close($this->ecb);
- $this->ecb = null;
- }
- }
- }
-
- /**
- * Setup the CRYPT_MODE_MCRYPT $engine
- *
- * @see Crypt_Base::_setupMcrypt()
- * @access private
- */
- function _setupMcrypt()
- {
- $this->key = str_pad(substr($this->key, 0, $this->key_size), $this->key_size, "\0");
- parent::_setupMcrypt();
+ return parent::isValidEngine($engine);
}
/**
* Encrypts a block
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _encryptBlock($in)
{
- static $t0, $t1, $t2, $t3, $sbox;
- if (!$t0) {
- for ($i = 0; $i < 256; ++$i) {
- $t0[] = (int)$this->t0[$i];
- $t1[] = (int)$this->t1[$i];
- $t2[] = (int)$this->t2[$i];
- $t3[] = (int)$this->t3[$i];
- $sbox[] = (int)$this->sbox[$i];
- }
+ static $tables;
+ if (empty($tables)) {
+ $tables = &$this->_getTables();
}
+ $t0 = $tables[0];
+ $t1 = $tables[1];
+ $t2 = $tables[2];
+ $t3 = $tables[3];
+ $sbox = $tables[4];
$state = array();
$words = unpack('N*', $in);
@@ -883,9 +292,9 @@ class Crypt_Rijndael extends Crypt_Base
$Nr = $this->Nr;
// addRoundKey
- $i = -1;
+ $wc = $Nb - 1;
foreach ($words as $word) {
- $state[] = $word ^ $w[0][++$i];
+ $state[] = $word ^ $w[++$wc];
}
// fips-197.pdf#page=19, "Figure 5. Pseudo Code for the Cipher", states that this loop has four components -
@@ -908,7 +317,7 @@ class Crypt_Rijndael extends Crypt_Base
$t1[$state[$j] >> 16 & 0x000000FF] ^
$t2[$state[$k] >> 8 & 0x000000FF] ^
$t3[$state[$l] & 0x000000FF] ^
- $w[$round][$i];
+ $w[++$wc];
++$i;
$j = ($j + 1) % $Nb;
$k = ($k + 1) % $Nb;
@@ -935,7 +344,7 @@ class Crypt_Rijndael extends Crypt_Base
($state[$j] & 0x00FF0000) ^
($state[$k] & 0x0000FF00) ^
($state[$l] & 0x000000FF) ^
- $w[$Nr][$i];
+ $w[$i];
++$i;
$j = ($j + 1) % $Nb;
$k = ($k + 1) % $Nb;
@@ -960,21 +369,20 @@ class Crypt_Rijndael extends Crypt_Base
* Decrypts a block
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _decryptBlock($in)
{
- static $dt0, $dt1, $dt2, $dt3, $isbox;
- if (!$dt0) {
- for ($i = 0; $i < 256; ++$i) {
- $dt0[] = (int)$this->dt0[$i];
- $dt1[] = (int)$this->dt1[$i];
- $dt2[] = (int)$this->dt2[$i];
- $dt3[] = (int)$this->dt3[$i];
- $isbox[] = (int)$this->isbox[$i];
- }
+ static $invtables;
+ if (empty($invtables)) {
+ $invtables = &$this->_getInvTables();
}
+ $dt0 = $invtables[0];
+ $dt1 = $invtables[1];
+ $dt2 = $invtables[2];
+ $dt3 = $invtables[3];
+ $isbox = $invtables[4];
$state = array();
$words = unpack('N*', $in);
@@ -985,9 +393,9 @@ class Crypt_Rijndael extends Crypt_Base
$Nr = $this->Nr;
// addRoundKey
- $i = -1;
+ $wc = $Nb - 1;
foreach ($words as $word) {
- $state[] = $word ^ $dw[$Nr][++$i];
+ $state[] = $word ^ $dw[++$wc];
}
$temp = array();
@@ -1002,7 +410,7 @@ class Crypt_Rijndael extends Crypt_Base
$dt1[$state[$j] >> 16 & 0x000000FF] ^
$dt2[$state[$k] >> 8 & 0x000000FF] ^
$dt3[$state[$l] & 0x000000FF] ^
- $dw[$round][$i];
+ $dw[++$wc];
++$i;
$j = ($j + 1) % $Nb;
$k = ($k + 1) % $Nb;
@@ -1023,10 +431,10 @@ class Crypt_Rijndael extends Crypt_Base
($state[$k] & 0x0000FF00) |
($state[$l] & 0x000000FF);
- $temp[$i] = $dw[0][$i] ^ ($isbox[$word & 0x000000FF] |
- ($isbox[$word >> 8 & 0x000000FF] << 8) |
- ($isbox[$word >> 16 & 0x000000FF] << 16) |
- ($isbox[$word >> 24 & 0x000000FF] << 24));
+ $temp[$i] = $dw[$i] ^ ($isbox[$word & 0x000000FF] |
+ ($isbox[$word >> 8 & 0x000000FF] << 8) |
+ ($isbox[$word >> 16 & 0x000000FF] << 16) |
+ ($isbox[$word >> 24 & 0x000000FF] << 24));
++$i;
$j = ($j + 1) % $Nb;
$k = ($k + 1) % $Nb;
@@ -1050,7 +458,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Setup the key (expansion)
*
- * @see Crypt_Base::_setupKey()
+ * @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@@ -1066,15 +474,13 @@ class Crypt_Rijndael extends Crypt_Base
0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000
);
- $this->key = str_pad(substr($this->key, 0, $this->key_size), $this->key_size, "\0");
-
- if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_size === $this->kl['key_size'] && $this->block_size === $this->kl['block_size']) {
+ if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_length === $this->kl['key_length'] && $this->block_size === $this->kl['block_size']) {
// already expanded
return;
}
- $this->kl = array('key' => $this->key, 'key_size' => $this->key_size, 'block_size' => $this->block_size);
+ $this->kl = array('key' => $this->key, 'key_length' => $this->key_length, 'block_size' => $this->block_size);
- $this->Nk = $this->key_size >> 2;
+ $this->Nk = $this->key_length >> 2;
// see Rijndael-ammended.pdf#page=44
$this->Nr = max($this->Nk, $this->Nb) + 6;
@@ -1107,7 +513,7 @@ class Crypt_Rijndael extends Crypt_Base
// with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is.
$temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord
$temp = $this->_subWord($temp) ^ $rcon[$i / $this->Nk];
- } else if ($this->Nk > 6 && $i % $this->Nk == 4) {
+ } elseif ($this->Nk > 6 && $i % $this->Nk == 4) {
$temp = $this->_subWord($temp);
}
$w[$i] = $w[$i - $this->Nk] ^ $temp;
@@ -1120,6 +526,7 @@ class Crypt_Rijndael extends Crypt_Base
// 1. Apply the Key Expansion.
// 2. Apply InvMixColumn to all Round Keys except the first and the last one."
// also, see fips-197.pdf#page=27, "5.3.5 Equivalent Inverse Cipher"
+ list($dt0, $dt1, $dt2, $dt3) = $this->_getInvTables();
$temp = $this->w = $this->dw = array();
for ($i = $row = $col = 0; $i < $length; $i++, $col++) {
if ($col == $this->Nb) {
@@ -1130,10 +537,10 @@ class Crypt_Rijndael extends Crypt_Base
$j = 0;
while ($j < $this->Nb) {
$dw = $this->_subWord($this->w[$row][$j]);
- $temp[$j] = $this->dt0[$dw >> 24 & 0x000000FF] ^
- $this->dt1[$dw >> 16 & 0x000000FF] ^
- $this->dt2[$dw >> 8 & 0x000000FF] ^
- $this->dt3[$dw & 0x000000FF];
+ $temp[$j] = $dt0[$dw >> 24 & 0x000000FF] ^
+ $dt1[$dw >> 16 & 0x000000FF] ^
+ $dt2[$dw >> 8 & 0x000000FF] ^
+ $dt3[$dw & 0x000000FF];
$j++;
}
$this->dw[$row] = $temp;
@@ -1147,31 +554,32 @@ class Crypt_Rijndael extends Crypt_Base
$this->dw[$row] = $this->w[$row];
- // In case of $this->use_inline_crypt === true we have to use 1-dim key arrays (both ascending)
- if ($this->use_inline_crypt) {
- $this->dw = array_reverse($this->dw);
- $w = array_pop($this->w);
- $dw = array_pop($this->dw);
- foreach ($this->w as $r => $wr) {
- foreach ($wr as $c => $wc) {
- $w[] = $wc;
- $dw[] = $this->dw[$r][$c];
- }
+ // Converting to 1-dim key arrays (both ascending)
+ $this->dw = array_reverse($this->dw);
+ $w = array_pop($this->w);
+ $dw = array_pop($this->dw);
+ foreach ($this->w as $r => $wr) {
+ foreach ($wr as $c => $wc) {
+ $w[] = $wc;
+ $dw[] = $this->dw[$r][$c];
}
- $this->w = $w;
- $this->dw = $dw;
}
+ $this->w = $w;
+ $this->dw = $dw;
}
/**
* Performs S-Box substitutions
*
* @access private
- * @param Integer $word
+ * @param int $word
*/
function _subWord($word)
{
- $sbox = $this->sbox;
+ static $sbox;
+ if (empty($sbox)) {
+ list(, , , , $sbox) = $this->_getTables();
+ }
return $sbox[$word & 0x000000FF] |
($sbox[$word >> 8 & 0x000000FF] << 8) |
@@ -1179,10 +587,183 @@ class Crypt_Rijndael extends Crypt_Base
($sbox[$word >> 24 & 0x000000FF] << 24);
}
+ /**
+ * Provides the mixColumns and sboxes tables
+ *
+ * @see self::_encryptBlock()
+ * @see self::_setupInlineCrypt()
+ * @see self::_subWord()
+ * @access private
+ * @return array &$tables
+ */
+ function &_getTables()
+ {
+ static $tables;
+ if (empty($tables)) {
+ // according to (section 5.2.1),
+ // precomputed tables can be used in the mixColumns phase. in that example, they're assigned t0...t3, so
+ // those are the names we'll use.
+ $t3 = array_map('intval', array(
+ // with array_map('intval', ...) we ensure we have only int's and not
+ // some slower floats converted by php automatically on high values
+ 0x6363A5C6, 0x7C7C84F8, 0x777799EE, 0x7B7B8DF6, 0xF2F20DFF, 0x6B6BBDD6, 0x6F6FB1DE, 0xC5C55491,
+ 0x30305060, 0x01010302, 0x6767A9CE, 0x2B2B7D56, 0xFEFE19E7, 0xD7D762B5, 0xABABE64D, 0x76769AEC,
+ 0xCACA458F, 0x82829D1F, 0xC9C94089, 0x7D7D87FA, 0xFAFA15EF, 0x5959EBB2, 0x4747C98E, 0xF0F00BFB,
+ 0xADADEC41, 0xD4D467B3, 0xA2A2FD5F, 0xAFAFEA45, 0x9C9CBF23, 0xA4A4F753, 0x727296E4, 0xC0C05B9B,
+ 0xB7B7C275, 0xFDFD1CE1, 0x9393AE3D, 0x26266A4C, 0x36365A6C, 0x3F3F417E, 0xF7F702F5, 0xCCCC4F83,
+ 0x34345C68, 0xA5A5F451, 0xE5E534D1, 0xF1F108F9, 0x717193E2, 0xD8D873AB, 0x31315362, 0x15153F2A,
+ 0x04040C08, 0xC7C75295, 0x23236546, 0xC3C35E9D, 0x18182830, 0x9696A137, 0x05050F0A, 0x9A9AB52F,
+ 0x0707090E, 0x12123624, 0x80809B1B, 0xE2E23DDF, 0xEBEB26CD, 0x2727694E, 0xB2B2CD7F, 0x75759FEA,
+ 0x09091B12, 0x83839E1D, 0x2C2C7458, 0x1A1A2E34, 0x1B1B2D36, 0x6E6EB2DC, 0x5A5AEEB4, 0xA0A0FB5B,
+ 0x5252F6A4, 0x3B3B4D76, 0xD6D661B7, 0xB3B3CE7D, 0x29297B52, 0xE3E33EDD, 0x2F2F715E, 0x84849713,
+ 0x5353F5A6, 0xD1D168B9, 0x00000000, 0xEDED2CC1, 0x20206040, 0xFCFC1FE3, 0xB1B1C879, 0x5B5BEDB6,
+ 0x6A6ABED4, 0xCBCB468D, 0xBEBED967, 0x39394B72, 0x4A4ADE94, 0x4C4CD498, 0x5858E8B0, 0xCFCF4A85,
+ 0xD0D06BBB, 0xEFEF2AC5, 0xAAAAE54F, 0xFBFB16ED, 0x4343C586, 0x4D4DD79A, 0x33335566, 0x85859411,
+ 0x4545CF8A, 0xF9F910E9, 0x02020604, 0x7F7F81FE, 0x5050F0A0, 0x3C3C4478, 0x9F9FBA25, 0xA8A8E34B,
+ 0x5151F3A2, 0xA3A3FE5D, 0x4040C080, 0x8F8F8A05, 0x9292AD3F, 0x9D9DBC21, 0x38384870, 0xF5F504F1,
+ 0xBCBCDF63, 0xB6B6C177, 0xDADA75AF, 0x21216342, 0x10103020, 0xFFFF1AE5, 0xF3F30EFD, 0xD2D26DBF,
+ 0xCDCD4C81, 0x0C0C1418, 0x13133526, 0xECEC2FC3, 0x5F5FE1BE, 0x9797A235, 0x4444CC88, 0x1717392E,
+ 0xC4C45793, 0xA7A7F255, 0x7E7E82FC, 0x3D3D477A, 0x6464ACC8, 0x5D5DE7BA, 0x19192B32, 0x737395E6,
+ 0x6060A0C0, 0x81819819, 0x4F4FD19E, 0xDCDC7FA3, 0x22226644, 0x2A2A7E54, 0x9090AB3B, 0x8888830B,
+ 0x4646CA8C, 0xEEEE29C7, 0xB8B8D36B, 0x14143C28, 0xDEDE79A7, 0x5E5EE2BC, 0x0B0B1D16, 0xDBDB76AD,
+ 0xE0E03BDB, 0x32325664, 0x3A3A4E74, 0x0A0A1E14, 0x4949DB92, 0x06060A0C, 0x24246C48, 0x5C5CE4B8,
+ 0xC2C25D9F, 0xD3D36EBD, 0xACACEF43, 0x6262A6C4, 0x9191A839, 0x9595A431, 0xE4E437D3, 0x79798BF2,
+ 0xE7E732D5, 0xC8C8438B, 0x3737596E, 0x6D6DB7DA, 0x8D8D8C01, 0xD5D564B1, 0x4E4ED29C, 0xA9A9E049,
+ 0x6C6CB4D8, 0x5656FAAC, 0xF4F407F3, 0xEAEA25CF, 0x6565AFCA, 0x7A7A8EF4, 0xAEAEE947, 0x08081810,
+ 0xBABAD56F, 0x787888F0, 0x25256F4A, 0x2E2E725C, 0x1C1C2438, 0xA6A6F157, 0xB4B4C773, 0xC6C65197,
+ 0xE8E823CB, 0xDDDD7CA1, 0x74749CE8, 0x1F1F213E, 0x4B4BDD96, 0xBDBDDC61, 0x8B8B860D, 0x8A8A850F,
+ 0x707090E0, 0x3E3E427C, 0xB5B5C471, 0x6666AACC, 0x4848D890, 0x03030506, 0xF6F601F7, 0x0E0E121C,
+ 0x6161A3C2, 0x35355F6A, 0x5757F9AE, 0xB9B9D069, 0x86869117, 0xC1C15899, 0x1D1D273A, 0x9E9EB927,
+ 0xE1E138D9, 0xF8F813EB, 0x9898B32B, 0x11113322, 0x6969BBD2, 0xD9D970A9, 0x8E8E8907, 0x9494A733,
+ 0x9B9BB62D, 0x1E1E223C, 0x87879215, 0xE9E920C9, 0xCECE4987, 0x5555FFAA, 0x28287850, 0xDFDF7AA5,
+ 0x8C8C8F03, 0xA1A1F859, 0x89898009, 0x0D0D171A, 0xBFBFDA65, 0xE6E631D7, 0x4242C684, 0x6868B8D0,
+ 0x4141C382, 0x9999B029, 0x2D2D775A, 0x0F0F111E, 0xB0B0CB7B, 0x5454FCA8, 0xBBBBD66D, 0x16163A2C
+ ));
+
+ foreach ($t3 as $t3i) {
+ $t0[] = (($t3i << 24) & 0xFF000000) | (($t3i >> 8) & 0x00FFFFFF);
+ $t1[] = (($t3i << 16) & 0xFFFF0000) | (($t3i >> 16) & 0x0000FFFF);
+ $t2[] = (($t3i << 8) & 0xFFFFFF00) | (($t3i >> 24) & 0x000000FF);
+ }
+
+ $tables = array(
+ // The Precomputed mixColumns tables t0 - t3
+ $t0,
+ $t1,
+ $t2,
+ $t3,
+ // The SubByte S-Box
+ array(
+ 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
+ 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
+ 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
+ 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
+ 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
+ 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
+ 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
+ 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
+ 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
+ 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
+ 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
+ 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
+ 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
+ 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
+ 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
+ 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
+ )
+ );
+ }
+ return $tables;
+ }
+
+ /**
+ * Provides the inverse mixColumns and inverse sboxes tables
+ *
+ * @see self::_decryptBlock()
+ * @see self::_setupInlineCrypt()
+ * @see self::_setupKey()
+ * @access private
+ * @return array &$tables
+ */
+ function &_getInvTables()
+ {
+ static $tables;
+ if (empty($tables)) {
+ $dt3 = array_map('intval', array(
+ 0xF4A75051, 0x4165537E, 0x17A4C31A, 0x275E963A, 0xAB6BCB3B, 0x9D45F11F, 0xFA58ABAC, 0xE303934B,
+ 0x30FA5520, 0x766DF6AD, 0xCC769188, 0x024C25F5, 0xE5D7FC4F, 0x2ACBD7C5, 0x35448026, 0x62A38FB5,
+ 0xB15A49DE, 0xBA1B6725, 0xEA0E9845, 0xFEC0E15D, 0x2F7502C3, 0x4CF01281, 0x4697A38D, 0xD3F9C66B,
+ 0x8F5FE703, 0x929C9515, 0x6D7AEBBF, 0x5259DA95, 0xBE832DD4, 0x7421D358, 0xE0692949, 0xC9C8448E,
+ 0xC2896A75, 0x8E7978F4, 0x583E6B99, 0xB971DD27, 0xE14FB6BE, 0x88AD17F0, 0x20AC66C9, 0xCE3AB47D,
+ 0xDF4A1863, 0x1A3182E5, 0x51336097, 0x537F4562, 0x6477E0B1, 0x6BAE84BB, 0x81A01CFE, 0x082B94F9,
+ 0x48685870, 0x45FD198F, 0xDE6C8794, 0x7BF8B752, 0x73D323AB, 0x4B02E272, 0x1F8F57E3, 0x55AB2A66,
+ 0xEB2807B2, 0xB5C2032F, 0xC57B9A86, 0x3708A5D3, 0x2887F230, 0xBFA5B223, 0x036ABA02, 0x16825CED,
+ 0xCF1C2B8A, 0x79B492A7, 0x07F2F0F3, 0x69E2A14E, 0xDAF4CD65, 0x05BED506, 0x34621FD1, 0xA6FE8AC4,
+ 0x2E539D34, 0xF355A0A2, 0x8AE13205, 0xF6EB75A4, 0x83EC390B, 0x60EFAA40, 0x719F065E, 0x6E1051BD,
+ 0x218AF93E, 0xDD063D96, 0x3E05AEDD, 0xE6BD464D, 0x548DB591, 0xC45D0571, 0x06D46F04, 0x5015FF60,
+ 0x98FB2419, 0xBDE997D6, 0x4043CC89, 0xD99E7767, 0xE842BDB0, 0x898B8807, 0x195B38E7, 0xC8EEDB79,
+ 0x7C0A47A1, 0x420FE97C, 0x841EC9F8, 0x00000000, 0x80868309, 0x2BED4832, 0x1170AC1E, 0x5A724E6C,
+ 0x0EFFFBFD, 0x8538560F, 0xAED51E3D, 0x2D392736, 0x0FD9640A, 0x5CA62168, 0x5B54D19B, 0x362E3A24,
+ 0x0A67B10C, 0x57E70F93, 0xEE96D2B4, 0x9B919E1B, 0xC0C54F80, 0xDC20A261, 0x774B695A, 0x121A161C,
+ 0x93BA0AE2, 0xA02AE5C0, 0x22E0433C, 0x1B171D12, 0x090D0B0E, 0x8BC7ADF2, 0xB6A8B92D, 0x1EA9C814,
+ 0xF1198557, 0x75074CAF, 0x99DDBBEE, 0x7F60FDA3, 0x01269FF7, 0x72F5BC5C, 0x663BC544, 0xFB7E345B,
+ 0x4329768B, 0x23C6DCCB, 0xEDFC68B6, 0xE4F163B8, 0x31DCCAD7, 0x63851042, 0x97224013, 0xC6112084,
+ 0x4A247D85, 0xBB3DF8D2, 0xF93211AE, 0x29A16DC7, 0x9E2F4B1D, 0xB230F3DC, 0x8652EC0D, 0xC1E3D077,
+ 0xB3166C2B, 0x70B999A9, 0x9448FA11, 0xE9642247, 0xFC8CC4A8, 0xF03F1AA0, 0x7D2CD856, 0x3390EF22,
+ 0x494EC787, 0x38D1C1D9, 0xCAA2FE8C, 0xD40B3698, 0xF581CFA6, 0x7ADE28A5, 0xB78E26DA, 0xADBFA43F,
+ 0x3A9DE42C, 0x78920D50, 0x5FCC9B6A, 0x7E466254, 0x8D13C2F6, 0xD8B8E890, 0x39F75E2E, 0xC3AFF582,
+ 0x5D80BE9F, 0xD0937C69, 0xD52DA96F, 0x2512B3CF, 0xAC993BC8, 0x187DA710, 0x9C636EE8, 0x3BBB7BDB,
+ 0x267809CD, 0x5918F46E, 0x9AB701EC, 0x4F9AA883, 0x956E65E6, 0xFFE67EAA, 0xBCCF0821, 0x15E8E6EF,
+ 0xE79BD9BA, 0x6F36CE4A, 0x9F09D4EA, 0xB07CD629, 0xA4B2AF31, 0x3F23312A, 0xA59430C6, 0xA266C035,
+ 0x4EBC3774, 0x82CAA6FC, 0x90D0B0E0, 0xA7D81533, 0x04984AF1, 0xECDAF741, 0xCD500E7F, 0x91F62F17,
+ 0x4DD68D76, 0xEFB04D43, 0xAA4D54CC, 0x9604DFE4, 0xD1B5E39E, 0x6A881B4C, 0x2C1FB8C1, 0x65517F46,
+ 0x5EEA049D, 0x8C355D01, 0x877473FA, 0x0B412EFB, 0x671D5AB3, 0xDBD25292, 0x105633E9, 0xD647136D,
+ 0xD7618C9A, 0xA10C7A37, 0xF8148E59, 0x133C89EB, 0xA927EECE, 0x61C935B7, 0x1CE5EDE1, 0x47B13C7A,
+ 0xD2DF599C, 0xF2733F55, 0x14CE7918, 0xC737BF73, 0xF7CDEA53, 0xFDAA5B5F, 0x3D6F14DF, 0x44DB8678,
+ 0xAFF381CA, 0x68C43EB9, 0x24342C38, 0xA3405FC2, 0x1DC37216, 0xE2250CBC, 0x3C498B28, 0x0D9541FF,
+ 0xA8017139, 0x0CB3DE08, 0xB4E49CD8, 0x56C19064, 0xCB84617B, 0x32B670D5, 0x6C5C7448, 0xB85742D0
+ ));
+
+ foreach ($dt3 as $dt3i) {
+ $dt0[] = (($dt3i << 24) & 0xFF000000) | (($dt3i >> 8) & 0x00FFFFFF);
+ $dt1[] = (($dt3i << 16) & 0xFFFF0000) | (($dt3i >> 16) & 0x0000FFFF);
+ $dt2[] = (($dt3i << 8) & 0xFFFFFF00) | (($dt3i >> 24) & 0x000000FF);
+ };
+
+ $tables = array(
+ // The Precomputed inverse mixColumns tables dt0 - dt3
+ $dt0,
+ $dt1,
+ $dt2,
+ $dt3,
+ // The inverse SubByte S-Box
+ array(
+ 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
+ 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
+ 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
+ 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
+ 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
+ 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
+ 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
+ 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
+ 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
+ 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
+ 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
+ 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
+ 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
+ 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
+ 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
+ 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
+ )
+ );
+ }
+ return $tables;
+ }
+
/**
* Setup the performance-optimized function for de/encrypt()
*
- * @see Crypt_Base::_setupInlineCrypt()
+ * @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
@@ -1191,44 +772,52 @@ class Crypt_Rijndael extends Crypt_Base
// So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt().
// However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible.
- $lambda_functions =& Crypt_Rijndael::_getLambdaFunctions();
+ $lambda_functions =& self::_getLambdaFunctions();
- // The first 10 generated $lambda_functions will use the key-words hardcoded for better performance.
- // For memory reason we limit those ultra-optimized functions.
- // After that, we use pure (extracted) integer vars for the key-words which is faster than accessing them via array.
- if (count($lambda_functions) < 10) {
- $w = $this->w;
- $dw = $this->dw;
- $init_encrypt = '';
- $init_decrypt = '';
- } else {
- for ($i = 0, $cw = count($this->w); $i < $cw; ++$i) {
- $w[] = '$w[' . $i . ']';
- $dw[] = '$dw[' . $i . ']';
- }
- $init_encrypt = '$w = $self->w;';
- $init_decrypt = '$dw = $self->dw;';
+ // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
+ // (Currently, for Crypt_Rijndael/AES, one generated $lambda_function cost on php5.5@32bit ~80kb unfreeable mem and ~130kb on php5.5@64bit)
+ // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
+ $gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
+
+ // Generation of a uniqe hash for our generated code
+ $code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}";
+ if ($gen_hi_opt_code) {
+ $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
}
- $code_hash = md5(str_pad("Crypt_Rijndael, {$this->mode}, {$this->block_size}, ", 32, "\0") . implode(',', $w));
-
if (!isset($lambda_functions[$code_hash])) {
+ switch (true) {
+ case $gen_hi_opt_code:
+ // The hi-optimized $lambda_functions will use the key-words hardcoded for better performance.
+ $w = $this->w;
+ $dw = $this->dw;
+ $init_encrypt = '';
+ $init_decrypt = '';
+ break;
+ default:
+ for ($i = 0, $cw = count($this->w); $i < $cw; ++$i) {
+ $w[] = '$w[' . $i . ']';
+ $dw[] = '$dw[' . $i . ']';
+ }
+ $init_encrypt = '$w = $self->w;';
+ $init_decrypt = '$dw = $self->dw;';
+ }
+
$Nr = $this->Nr;
$Nb = $this->Nb;
$c = $this->c;
// Generating encrypt code:
$init_encrypt.= '
- static $t0, $t1, $t2, $t3, $sbox;
- if (!$t0) {
- for ($i = 0; $i < 256; ++$i) {
- $t0[$i] = (int)$self->t0[$i];
- $t1[$i] = (int)$self->t1[$i];
- $t2[$i] = (int)$self->t2[$i];
- $t3[$i] = (int)$self->t3[$i];
- $sbox[$i] = (int)$self->sbox[$i];
- }
+ static $tables;
+ if (empty($tables)) {
+ $tables = &$self->_getTables();
}
+ $t0 = $tables[0];
+ $t1 = $tables[1];
+ $t2 = $tables[2];
+ $t3 = $tables[3];
+ $sbox = $tables[4];
';
$s = 'e';
@@ -1267,26 +856,25 @@ class Crypt_Rijndael extends Crypt_Base
$encrypt_block .= '$in = pack("N*"'."\n";
for ($i = 0; $i < $Nb; ++$i) {
$encrypt_block.= ',
- ($'.$e.$i .' & 0xFF000000) ^
- ($'.$e.(($i + $c[1]) % $Nb).' & 0x00FF0000) ^
- ($'.$e.(($i + $c[2]) % $Nb).' & 0x0000FF00) ^
- ($'.$e.(($i + $c[3]) % $Nb).' & 0x000000FF) ^
+ ($'.$e.$i .' & '.((int)0xFF000000).') ^
+ ($'.$e.(($i + $c[1]) % $Nb).' & 0x00FF0000 ) ^
+ ($'.$e.(($i + $c[2]) % $Nb).' & 0x0000FF00 ) ^
+ ($'.$e.(($i + $c[3]) % $Nb).' & 0x000000FF ) ^
'.$w[$i]."\n";
}
$encrypt_block .= ');';
// Generating decrypt code:
$init_decrypt.= '
- static $dt0, $dt1, $dt2, $dt3, $isbox;
- if (!$dt0) {
- for ($i = 0; $i < 256; ++$i) {
- $dt0[$i] = (int)$self->dt0[$i];
- $dt1[$i] = (int)$self->dt1[$i];
- $dt2[$i] = (int)$self->dt2[$i];
- $dt3[$i] = (int)$self->dt3[$i];
- $isbox[$i] = (int)$self->isbox[$i];
- }
+ static $invtables;
+ if (empty($invtables)) {
+ $invtables = &$self->_getInvTables();
}
+ $dt0 = $invtables[0];
+ $dt1 = $invtables[1];
+ $dt2 = $invtables[2];
+ $dt3 = $invtables[3];
+ $isbox = $invtables[4];
';
$s = 'e';
@@ -1325,10 +913,10 @@ class Crypt_Rijndael extends Crypt_Base
$decrypt_block .= '$in = pack("N*"'."\n";
for ($i = 0; $i < $Nb; ++$i) {
$decrypt_block.= ',
- ($'.$e.$i. ' & 0xFF000000) ^
- ($'.$e.(($Nb + $i - $c[1]) % $Nb).' & 0x00FF0000) ^
- ($'.$e.(($Nb + $i - $c[2]) % $Nb).' & 0x0000FF00) ^
- ($'.$e.(($Nb + $i - $c[3]) % $Nb).' & 0x000000FF) ^
+ ($'.$e.$i. ' & '.((int)0xFF000000).') ^
+ ($'.$e.(($Nb + $i - $c[1]) % $Nb).' & 0x00FF0000 ) ^
+ ($'.$e.(($Nb + $i - $c[2]) % $Nb).' & 0x0000FF00 ) ^
+ ($'.$e.(($Nb + $i - $c[3]) % $Nb).' & 0x000000FF ) ^
'.$dw[$i]."\n";
}
$decrypt_block .= ');';
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/TripleDES.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/TripleDES.php
index 06ea09b1..a2c41668 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/TripleDES.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/TripleDES.php
@@ -5,14 +5,14 @@
*
* Uses mcrypt, if available, and an internal implementation, otherwise. Operates in the EDE3 mode (encrypt-decrypt-encrypt).
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* Here's a short example of how to use this library:
*
* setKey('abcdefghijklmnopqrstuvwx');
*
@@ -26,99 +26,64 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_TripleDES
+ * @package TripleDES
* @author Jim Wigginton
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_DES
- */
-if (!class_exists('Crypt_DES')) {
- include_once 'DES.php';
-}
-
-/**
- * Encrypt / decrypt using inner chaining
- *
- * Inner chaining is used by SSH-1 and is generally considered to be less secure then outer chaining (CRYPT_DES_MODE_CBC3).
- */
-define('CRYPT_DES_MODE_3CBC', -2);
-
-/**
- * Encrypt / decrypt using outer chaining
- *
- * Outer chaining is used by SSH-2 and when the mode is set to CRYPT_DES_MODE_CBC.
- */
-define('CRYPT_DES_MODE_CBC3', CRYPT_DES_MODE_CBC);
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of Triple DES.
*
- * @package Crypt_TripleDES
+ * @package TripleDES
* @author Jim Wigginton
* @access public
*/
-class Crypt_TripleDES extends Crypt_DES
+class TripleDES extends DES
{
/**
- * The default password key_size used by setPassword()
+ * Encrypt / decrypt using inner chaining
*
- * @see Crypt_DES::password_key_size
- * @see Crypt_Base::password_key_size
- * @see Crypt_Base::setPassword()
- * @var Integer
+ * Inner chaining is used by SSH-1 and is generally considered to be less secure then outer chaining (self::MODE_CBC3).
+ */
+ const MODE_3CBC = -2;
+
+ /**
+ * Encrypt / decrypt using outer chaining
+ *
+ * Outer chaining is used by SSH-2 and when the mode is set to \phpseclib\Crypt\Base::MODE_CBC.
+ */
+ const MODE_CBC3 = Base::MODE_CBC;
+
+ /**
+ * Key Length (in bytes)
+ *
+ * @see \phpseclib\Crypt\TripleDES::setKeyLength()
+ * @var int
* @access private
*/
- var $password_key_size = 24;
+ var $key_length = 24;
/**
* The default salt used by setPassword()
*
- * @see Crypt_Base::password_default_salt
- * @see Crypt_Base::setPassword()
- * @var String
+ * @see \phpseclib\Crypt\Base::password_default_salt
+ * @see \phpseclib\Crypt\Base::setPassword()
+ * @var string
* @access private
*/
var $password_default_salt = 'phpseclib';
- /**
- * The namespace used by the cipher for its constants.
- *
- * @see Crypt_DES::const_namespace
- * @see Crypt_Base::const_namespace
- * @var String
- * @access private
- */
- var $const_namespace = 'DES';
-
/**
* The mcrypt specific name of the cipher
*
- * @see Crypt_DES::cipher_name_mcrypt
- * @see Crypt_Base::cipher_name_mcrypt
- * @var String
+ * @see \phpseclib\Crypt\DES::cipher_name_mcrypt
+ * @see \phpseclib\Crypt\Base::cipher_name_mcrypt
+ * @var string
* @access private
*/
var $cipher_name_mcrypt = 'tripledes';
@@ -126,8 +91,8 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Optimizing value while CFB-encrypting
*
- * @see Crypt_Base::cfb_init_len
- * @var Integer
+ * @see \phpseclib\Crypt\Base::cfb_init_len
+ * @var int
* @access private
*/
var $cfb_init_len = 750;
@@ -135,27 +100,27 @@ class Crypt_TripleDES extends Crypt_DES
/**
* max possible size of $key
*
- * @see Crypt_TripleDES::setKey()
- * @see Crypt_DES::setKey()
- * @var String
+ * @see self::setKey()
+ * @see \phpseclib\Crypt\DES::setKey()
+ * @var string
* @access private
*/
- var $key_size_max = 24;
+ var $key_length_max = 24;
/**
- * Internal flag whether using CRYPT_DES_MODE_3CBC or not
+ * Internal flag whether using self::MODE_3CBC or not
*
- * @var Boolean
+ * @var bool
* @access private
*/
var $mode_3cbc;
/**
- * The Crypt_DES objects
+ * The \phpseclib\Crypt\DES objects
*
* Used only if $mode_3cbc === true
*
- * @var Array
+ * @var array
* @access private
*/
var $des;
@@ -167,61 +132,82 @@ class Crypt_TripleDES extends Crypt_DES
*
* $mode could be:
*
- * - CRYPT_DES_MODE_ECB
+ * - \phpseclib\Crypt\Base::MODE_ECB
*
- * - CRYPT_DES_MODE_CBC
+ * - \phpseclib\Crypt\Base::MODE_CBC
*
- * - CRYPT_DES_MODE_CTR
+ * - \phpseclib\Crypt\Base::MODE_CTR
*
- * - CRYPT_DES_MODE_CFB
+ * - \phpseclib\Crypt\Base::MODE_CFB
*
- * - CRYPT_DES_MODE_OFB
+ * - \phpseclib\Crypt\Base::MODE_OFB
*
- * - CRYPT_DES_MODE_3CBC
+ * - \phpseclib\Crypt\TripleDES::MODE_3CBC
*
- * If not explicitly set, CRYPT_DES_MODE_CBC will be used.
+ * If not explicitly set, \phpseclib\Crypt\Base::MODE_CBC will be used.
*
- * @see Crypt_DES::Crypt_DES()
- * @see Crypt_Base::Crypt_Base()
- * @param optional Integer $mode
+ * @see \phpseclib\Crypt\DES::__construct()
+ * @see \phpseclib\Crypt\Base::__construct()
+ * @param int $mode
* @access public
*/
- function Crypt_TripleDES($mode = CRYPT_DES_MODE_CBC)
+ function __construct($mode = Base::MODE_CBC)
{
switch ($mode) {
- // In case of CRYPT_DES_MODE_3CBC, we init as CRYPT_DES_MODE_CBC
+ // In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC
// and additional flag us internally as 3CBC
- case CRYPT_DES_MODE_3CBC:
- parent::Crypt_Base(CRYPT_DES_MODE_CBC);
+ case self::MODE_3CBC:
+ parent::__construct(Base::MODE_CBC);
$this->mode_3cbc = true;
// This three $des'es will do the 3CBC work (if $key > 64bits)
$this->des = array(
- new Crypt_DES(CRYPT_DES_MODE_CBC),
- new Crypt_DES(CRYPT_DES_MODE_CBC),
- new Crypt_DES(CRYPT_DES_MODE_CBC),
+ new DES(Base::MODE_CBC),
+ new DES(Base::MODE_CBC),
+ new DES(Base::MODE_CBC),
);
- // we're going to be doing the padding, ourselves, so disable it in the Crypt_DES objects
+ // we're going to be doing the padding, ourselves, so disable it in the \phpseclib\Crypt\DES objects
$this->des[0]->disablePadding();
$this->des[1]->disablePadding();
$this->des[2]->disablePadding();
break;
// If not 3CBC, we init as usual
default:
- parent::Crypt_Base($mode);
+ parent::__construct($mode);
}
}
+ /**
+ * Test for engine validity
+ *
+ * This is mainly just a wrapper to set things up for \phpseclib\Crypt\Base::isValidEngine()
+ *
+ * @see \phpseclib\Crypt\Base::__construct()
+ * @param int $engine
+ * @access public
+ * @return bool
+ */
+ function isValidEngine($engine)
+ {
+ if ($engine == self::ENGINE_OPENSSL) {
+ $this->cipher_name_openssl_ecb = 'des-ede3';
+ $mode = $this->_openssl_translate_mode();
+ $this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-' . $mode;
+ }
+
+ return parent::isValidEngine($engine);
+ }
+
/**
* Sets the initialization vector. (optional)
*
- * SetIV is not required when CRYPT_DES_MODE_ECB is being used. If not explicitly set, it'll be assumed
+ * SetIV is not required when \phpseclib\Crypt\Base::MODE_ECB is being used. If not explicitly set, it'll be assumed
* to be all zero's.
*
- * @see Crypt_Base::setIV()
+ * @see \phpseclib\Crypt\Base::setIV()
* @access public
- * @param String $iv
+ * @param string $iv
*/
function setIV($iv)
{
@@ -233,6 +219,32 @@ class Crypt_TripleDES extends Crypt_DES
}
}
+ /**
+ * Sets the key length.
+ *
+ * Valid key lengths are 64, 128 and 192
+ *
+ * @see \phpseclib\Crypt\Base:setKeyLength()
+ * @access public
+ * @param int $length
+ */
+ function setKeyLength($length)
+ {
+ $length >>= 3;
+ switch (true) {
+ case $length <= 8:
+ $this->key_length = 8;
+ break;
+ case $length <= 16:
+ $this->key_length = 16;
+ break;
+ default:
+ $this->key_length = 24;
+ }
+
+ parent::setKeyLength($length);
+ }
+
/**
* Sets the key.
*
@@ -244,24 +256,24 @@ class Crypt_TripleDES extends Crypt_DES
* If the key is not explicitly set, it'll be assumed to be all null bytes.
*
* @access public
- * @see Crypt_DES::setKey()
- * @see Crypt_Base::setKey()
- * @param String $key
+ * @see \phpseclib\Crypt\DES::setKey()
+ * @see \phpseclib\Crypt\Base::setKey()
+ * @param string $key
*/
function setKey($key)
{
- $length = strlen($key);
+ $length = $this->explicit_key_length ? $this->key_length : strlen($key);
if ($length > 8) {
$key = str_pad(substr($key, 0, 24), 24, chr(0));
// if $key is between 64 and 128-bits, use the first 64-bits as the last, per this:
// http://php.net/function.mcrypt-encrypt#47973
- //$key = $length <= 16 ? substr_replace($key, substr($key, 0, 8), 16) : substr($key, 0, 24);
+ $key = $length <= 16 ? substr_replace($key, substr($key, 0, 8), 16) : substr($key, 0, 24);
} else {
$key = str_pad($key, 8, chr(0));
}
parent::setKey($key);
- // And in case of CRYPT_DES_MODE_3CBC:
+ // And in case of self::MODE_3CBC:
// if key <= 64bits we not need the 3 $des to work,
// because we will then act as regular DES-CBC with just a <= 64bit key.
// So only if the key > 64bits (> 8 bytes) we will call setKey() for the 3 $des.
@@ -275,15 +287,15 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Encrypts a message.
*
- * @see Crypt_Base::encrypt()
+ * @see \phpseclib\Crypt\Base::encrypt()
* @access public
- * @param String $plaintext
- * @return String $cipertext
+ * @param string $plaintext
+ * @return string $cipertext
*/
function encrypt($plaintext)
{
// parent::en/decrypt() is able to do all the work for all modes and keylengths,
- // except for: CRYPT_DES_MODE_3CBC (inner chaining CBC) with a key > 64bits
+ // except for: self::MODE_3CBC (inner chaining CBC) with a key > 64bits
// if the key is smaller then 8, do what we'd normally do
if ($this->mode_3cbc && strlen($this->key) > 8) {
@@ -302,10 +314,10 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Decrypts a message.
*
- * @see Crypt_Base::decrypt()
+ * @see \phpseclib\Crypt\Base::decrypt()
* @access public
- * @param String $ciphertext
- * @return String $plaintext
+ * @param string $ciphertext
+ * @return string $plaintext
*/
function decrypt($ciphertext)
{
@@ -353,13 +365,13 @@ class Crypt_TripleDES extends Crypt_DES
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
*
- * Put another way, when the continuous buffer is enabled, the state of the Crypt_DES() object changes after each
+ * Put another way, when the continuous buffer is enabled, the state of the \phpseclib\Crypt\DES() object changes after each
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
* however, they are also less intuitive and more likely to cause you problems.
*
- * @see Crypt_Base::enableContinuousBuffer()
- * @see Crypt_TripleDES::disableContinuousBuffer()
+ * @see \phpseclib\Crypt\Base::enableContinuousBuffer()
+ * @see self::disableContinuousBuffer()
* @access public
*/
function enableContinuousBuffer()
@@ -377,8 +389,8 @@ class Crypt_TripleDES extends Crypt_DES
*
* The default behavior.
*
- * @see Crypt_Base::disableContinuousBuffer()
- * @see Crypt_TripleDES::enableContinuousBuffer()
+ * @see \phpseclib\Crypt\Base::disableContinuousBuffer()
+ * @see self::enableContinuousBuffer()
* @access public
*/
function disableContinuousBuffer()
@@ -394,8 +406,8 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Creates the key schedule
*
- * @see Crypt_DES::_setupKey()
- * @see Crypt_Base::_setupKey()
+ * @see \phpseclib\Crypt\DES::_setupKey()
+ * @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@@ -425,4 +437,24 @@ class Crypt_TripleDES extends Crypt_DES
// setup our key
parent::_setupKey();
}
+
+ /**
+ * Sets the internal crypt engine
+ *
+ * @see \phpseclib\Crypt\Base::__construct()
+ * @see \phpseclib\Crypt\Base::setPreferredEngine()
+ * @param int $engine
+ * @access public
+ * @return int
+ */
+ function setPreferredEngine($engine)
+ {
+ if ($this->mode_3cbc) {
+ $this->des[0]->setPreferredEngine($engine);
+ $this->des[1]->setPreferredEngine($engine);
+ $this->des[2]->setPreferredEngine($engine);
+ }
+
+ return parent::setPreferredEngine($engine);
+ }
}
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Twofish.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Twofish.php
index 8dd7933a..3dd4ea1d 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Twofish.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/Crypt/Twofish.php
@@ -5,7 +5,7 @@
*
* Uses mcrypt, if available, and an internal implementation, otherwise.
*
- * PHP versions 4 and 5
+ * PHP version 5
*
* Useful resources are as follows:
*
@@ -14,9 +14,9 @@
* Here's a short example of how to use this library:
*
* setKey('12345678901234567890123456789012');
*
@@ -26,26 +26,8 @@
* ?>
*
*
- * LICENSE: 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.
- *
* @category Crypt
- * @package Crypt_Twofish
+ * @package Twofish
* @author Jim Wigginton
* @author Hans-Juergen Petrich
* @copyright 2007 Jim Wigginton
@@ -53,92 +35,23 @@
* @link http://phpseclib.sourceforge.net
*/
-/**
- * Include Crypt_Base
- *
- * Base cipher class
- */
-if (!class_exists('Crypt_Base')) {
- include_once 'Base.php';
-}
-
-/**#@+
- * @access public
- * @see Crypt_Twofish::encrypt()
- * @see Crypt_Twofish::decrypt()
- */
-/**
- * Encrypt / decrypt using the Counter mode.
- *
- * Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
- */
-define('CRYPT_TWOFISH_MODE_CTR', CRYPT_MODE_CTR);
-/**
- * Encrypt / decrypt using the Electronic Code Book mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
- */
-define('CRYPT_TWOFISH_MODE_ECB', CRYPT_MODE_ECB);
-/**
- * Encrypt / decrypt using the Code Book Chaining mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
- */
-define('CRYPT_TWOFISH_MODE_CBC', CRYPT_MODE_CBC);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
- */
-define('CRYPT_TWOFISH_MODE_CFB', CRYPT_MODE_CFB);
-/**
- * Encrypt / decrypt using the Cipher Feedback mode.
- *
- * @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
- */
-define('CRYPT_TWOFISH_MODE_OFB', CRYPT_MODE_OFB);
-/**#@-*/
-
-/**#@+
- * @access private
- * @see Crypt_Base::Crypt_Base()
- */
-/**
- * Toggles the internal implementation
- */
-define('CRYPT_TWOFISH_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
-/**
- * Toggles the mcrypt implementation
- */
-define('CRYPT_TWOFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
-/**#@-*/
+namespace phpseclib\Crypt;
/**
* Pure-PHP implementation of Twofish.
*
- * @package Crypt_Twofish
+ * @package Twofish
* @author Jim Wigginton
* @author Hans-Juergen Petrich
* @access public
*/
-class Crypt_Twofish extends Crypt_Base
+class Twofish extends Base
{
- /**
- * The namespace used by the cipher for its constants.
- *
- * @see Crypt_Base::const_namespace
- * @var String
- * @access private
- */
- var $const_namespace = 'TWOFISH';
-
/**
* The mcrypt specific name of the cipher
*
- * @see Crypt_Base::cipher_name_mcrypt
- * @var String
+ * @see \phpseclib\Crypt\Base::cipher_name_mcrypt
+ * @var string
* @access private
*/
var $cipher_name_mcrypt = 'twofish';
@@ -146,8 +59,8 @@ class Crypt_Twofish extends Crypt_Base
/**
* Optimizing value while CFB-encrypting
*
- * @see Crypt_Base::cfb_init_len
- * @var Integer
+ * @see \phpseclib\Crypt\Base::cfb_init_len
+ * @var int
* @access private
*/
var $cfb_init_len = 800;
@@ -155,10 +68,10 @@ class Crypt_Twofish extends Crypt_Base
/**
* Q-Table
*
- * @var Array
+ * @var array
* @access private
*/
- var $q0 = array (
+ var $q0 = array(
0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76,
0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38,
0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
@@ -196,10 +109,10 @@ class Crypt_Twofish extends Crypt_Base
/**
* Q-Table
*
- * @var Array
+ * @var array
* @access private
*/
- var $q1 = array (
+ var $q1 = array(
0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8,
0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B,
0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
@@ -237,10 +150,10 @@ class Crypt_Twofish extends Crypt_Base
/**
* M-Table
*
- * @var Array
+ * @var array
* @access private
*/
- var $m0 = array (
+ var $m0 = array(
0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8,
0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B,
0x3C3C57D6, 0x93938A32, 0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1,
@@ -278,10 +191,10 @@ class Crypt_Twofish extends Crypt_Base
/**
* M-Table
*
- * @var Array
+ * @var array
* @access private
*/
- var $m1 = array (
+ var $m1 = array(
0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4,
0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A,
0x0D54E6E6, 0xC6432020, 0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141,
@@ -319,10 +232,10 @@ class Crypt_Twofish extends Crypt_Base
/**
* M-Table
*
- * @var Array
+ * @var array
* @access private
*/
- var $m2 = array (
+ var $m2 = array(
0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA,
0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7,
0x3CD63C57, 0x9332938A, 0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783,
@@ -360,10 +273,10 @@ class Crypt_Twofish extends Crypt_Base
/**
* M-Table
*
- * @var Array
+ * @var array
* @access private
*/
- var $m3 = array (
+ var $m3 = array(
0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF,
0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836,
0x54E60D54, 0x4320C643, 0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77,
@@ -401,7 +314,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* The Key Schedule Array
*
- * @var Array
+ * @var array
* @access private
*/
var $K = array();
@@ -409,7 +322,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* The Key depended S-Table 0
*
- * @var Array
+ * @var array
* @access private
*/
var $S0 = array();
@@ -417,7 +330,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* The Key depended S-Table 1
*
- * @var Array
+ * @var array
* @access private
*/
var $S1 = array();
@@ -425,7 +338,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* The Key depended S-Table 2
*
- * @var Array
+ * @var array
* @access private
*/
var $S2 = array();
@@ -433,7 +346,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* The Key depended S-Table 3
*
- * @var Array
+ * @var array
* @access private
*/
var $S3 = array();
@@ -441,47 +354,48 @@ class Crypt_Twofish extends Crypt_Base
/**
* Holds the last used key
*
- * @var Array
+ * @var array
* @access private
*/
var $kl;
/**
- * Sets the key.
+ * The Key Length (in bytes)
*
- * Keys can be of any length. Twofish, itself, requires the use of a key that's 128, 192 or 256-bits long.
- * If the key is less than 256-bits we round the length up to the closest valid key length,
- * padding $key with null bytes. If the key is more than 256-bits, we trim the excess bits.
+ * @see Crypt_Twofish::setKeyLength()
+ * @var int
+ * @access private
+ */
+ var $key_length = 16;
+
+ /**
+ * Sets the key length.
*
- * If the key is not explicitly set, it'll be assumed a 128 bits key to be all null bytes.
+ * Valid key lengths are 128, 192 or 256 bits
*
* @access public
- * @see Crypt_Base::setKey()
- * @param String $key
+ * @param int $length
*/
- function setKey($key)
+ function setKeyLength($length)
{
- $keylength = strlen($key);
switch (true) {
- case $keylength <= 16:
- $key = str_pad($key, 16, "\0");
+ case $length <= 128:
+ $this->key_length = 16;
break;
- case $keylength <= 24:
- $key = str_pad($key, 24, "\0");
+ case $length <= 192:
+ $this->key_length = 24;
break;
- case $keylength < 32:
- $key = str_pad($key, 32, "\0");
- break;
- case $keylength > 32:
- $key = substr($key, 0, 32);
+ default:
+ $this->key_length = 32;
}
- parent::setKey($key);
+
+ parent::setKeyLength($length);
}
/**
* Setup the key (expansion)
*
- * @see Crypt_Base::_setupKey()
+ * @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@@ -506,9 +420,9 @@ class Crypt_Twofish extends Crypt_Base
switch (strlen($this->key)) {
case 16:
- list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]);
- list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]);
- for ($i = 0, $j = 1; $i < 40; $i+= 2,$j+= 2) {
+ list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]);
+ list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]);
+ for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
$A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^
$m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^
$m2[$q1[$q0[$i] ^ $key[11]] ^ $key[3]] ^
@@ -529,9 +443,9 @@ class Crypt_Twofish extends Crypt_Base
}
break;
case 24:
- list ($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]);
- list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]);
- list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]);
+ list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]);
+ list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]);
+ list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]);
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
$A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^
$m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^
@@ -553,10 +467,10 @@ class Crypt_Twofish extends Crypt_Base
}
break;
default: // 32
- list ($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]);
- list ($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]);
- list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]);
- list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]);
+ list($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]);
+ list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]);
+ list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]);
+ list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]);
for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) {
$A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^
$m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^
@@ -589,9 +503,9 @@ class Crypt_Twofish extends Crypt_Base
* _mdsrem function using by the twofish cipher algorithm
*
* @access private
- * @param String $A
- * @param String $B
- * @return Array
+ * @param string $A
+ * @param string $B
+ * @return array
*/
function _mdsrem($A, $B)
{
@@ -618,7 +532,9 @@ class Crypt_Twofish extends Crypt_Base
$u^= 0x7fffffff & ($t >> 1);
// Add the modular polynomial on underflow.
- if ($t & 0x01) $u^= 0xa6 ;
+ if ($t & 0x01) {
+ $u^= 0xa6 ;
+ }
// Remove t * (a + 1/a) * (x^3 + x).
$B^= ($u << 24) | ($u << 8);
@@ -635,8 +551,8 @@ class Crypt_Twofish extends Crypt_Base
* Encrypts a block
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _encryptBlock($in)
{
@@ -691,8 +607,8 @@ class Crypt_Twofish extends Crypt_Base
* Decrypts a block
*
* @access private
- * @param String $in
- * @return String
+ * @param string $in
+ * @return string
*/
function _decryptBlock($in)
{
@@ -746,29 +662,27 @@ class Crypt_Twofish extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
- * @see Crypt_Base::_setupInlineCrypt()
+ * @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
- $lambda_functions =& Crypt_Twofish::_getLambdaFunctions();
+ $lambda_functions =& self::_getLambdaFunctions();
// Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one.
- $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
+ // (Currently, for Crypt_Twofish, one generated $lambda_function cost on php5.5@32bit ~140kb unfreeable mem and ~240kb on php5.5@64bit)
+ $gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
- switch (true) {
- case $gen_hi_opt_code:
- $code_hash = md5(str_pad("Crypt_Twofish, {$this->mode}, ", 32, "\0") . $this->key);
- break;
- default:
- $code_hash = "Crypt_Twofish, {$this->mode}";
+ // Generation of a unique hash for our generated code
+ $code_hash = "Crypt_Twofish, {$this->mode}";
+ if ($gen_hi_opt_code) {
+ $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
}
if (!isset($lambda_functions[$code_hash])) {
switch (true) {
case $gen_hi_opt_code:
$K = $this->K;
-
$init_crypt = '
static $S0, $S1, $S2, $S3;
if (!$S0) {
@@ -786,7 +700,6 @@ class Crypt_Twofish extends Crypt_Base
for ($i = 0; $i < 40; ++$i) {
$K[] = '$K_' . $i;
}
-
$init_crypt = '
$S0 = $self->S0;
$S1 = $self->S1;
diff --git a/securemail/vendor/phpseclib/phpseclib/phpseclib/File/ANSI.php b/securemail/vendor/phpseclib/phpseclib/phpseclib/File/ANSI.php
index 3ff1b7d4..1f3eecb3 100644
--- a/securemail/vendor/phpseclib/phpseclib/phpseclib/File/ANSI.php
+++ b/securemail/vendor/phpseclib/phpseclib/phpseclib/File/ANSI.php
@@ -3,52 +3,36 @@
/**
* Pure-PHP ANSI Decoder
*
- * PHP versions 4 and 5
+ * PHP version 5
*
- * If you call read() in Net_SSH2 you may get {@link http://en.wikipedia.org/wiki/ANSI_escape_code ANSI escape codes} back.
+ * If you call read() in \phpseclib\Net\SSH2 you may get {@link http://en.wikipedia.org/wiki/ANSI_escape_code ANSI escape codes} back.
* They'd look like chr(0x1B) . '[00m' or whatever (0x1B = ESC). They tell a
* {@link http://en.wikipedia.org/wiki/Terminal_emulator terminal emulator} how to format the characters, what
- * color to display them in, etc. File_ANSI is a {@link http://en.wikipedia.org/wiki/VT100 VT100} terminal emulator.
- *
- * LICENSE: 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.
+ * color to display them in, etc. \phpseclib\File\ANSI is a {@link http://en.wikipedia.org/wiki/VT100 VT100} terminal emulator.
*
* @category File
- * @package File_ANSI
+ * @package ANSI
* @author Jim Wigginton
* @copyright 2012 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
+namespace phpseclib\File;
+
/**
* Pure-PHP ANSI Decoder
*
- * @package File_ANSI
+ * @package ANSI
* @author Jim Wigginton
* @access public
*/
-class File_ANSI
+class ANSI
{
/**
* Max Width
*
- * @var Integer
+ * @var int
* @access private
*/
var $max_x;
@@ -56,7 +40,7 @@ class File_ANSI
/**
* Max Height
*
- * @var Integer
+ * @var int
* @access private
*/
var $max_y;
@@ -64,7 +48,7 @@ class File_ANSI
/**
* Max History
*
- * @var Integer
+ * @var int
* @access private
*/
var $max_history;
@@ -72,7 +56,7 @@ class File_ANSI
/**
* History
*
- * @var Array
+ * @var array
* @access private
*/
var $history;
@@ -80,7 +64,7 @@ class File_ANSI
/**
* History Attributes
*
- * @var Array
+ * @var array
* @access private
*/
var $history_attrs;
@@ -88,7 +72,7 @@ class File_ANSI
/**
* Current Column
*
- * @var Integer
+ * @var int
* @access private
*/
var $x;
@@ -96,7 +80,7 @@ class File_ANSI
/**
* Current Row
*
- * @var Integer
+ * @var int
* @access private
*/
var $y;
@@ -104,7 +88,7 @@ class File_ANSI
/**
* Old Column
*
- * @var Integer
+ * @var int
* @access private
*/
var $old_x;
@@ -112,15 +96,31 @@ class File_ANSI
/**
* Old Row
*
- * @var Integer
+ * @var int
* @access private
*/
var $old_y;
+ /**
+ * An empty attribute cell
+ *
+ * @var object
+ * @access private
+ */
+ var $base_attr_cell;
+
+ /**
+ * The current attribute cell
+ *
+ * @var object
+ * @access private
+ */
+ var $attr_cell;
+
/**
* An empty attribute row
*
- * @var Array
+ * @var array
* @access private
*/
var $attr_row;
@@ -128,7 +128,7 @@ class File_ANSI
/**
* The current screen text
*
- * @var Array
+ * @var array
* @access private
*/
var $screen;
@@ -136,83 +136,45 @@ class File_ANSI
/**
* The current screen attributes
*
- * @var Array
+ * @var array
* @access private
*/
var $attrs;
- /**
- * The current foreground color
- *
- * @var String
- * @access private
- */
- var $foreground;
-
- /**
- * The current background color
- *
- * @var String
- * @access private
- */
- var $background;
-
- /**
- * Bold flag
- *
- * @var Boolean
- * @access private
- */
- var $bold;
-
- /**
- * Underline flag
- *
- * @var Boolean
- * @access private
- */
- var $underline;
-
- /**
- * Blink flag
- *
- * @var Boolean
- * @access private
- */
- var $blink;
-
- /**
- * Reverse flag
- *
- * @var Boolean
- * @access private
- */
- var $reverse;
-
- /**
- * Color flag
- *
- * @var Boolean
- * @access private
- */
- var $color;
-
/**
* Current ANSI code
*
- * @var String
+ * @var string
* @access private
*/
var $ansi;
+ /**
+ * Tokenization
+ *
+ * @var array
+ * @access private
+ */
+ var $tokenization;
+
/**
* Default Constructor.
*
- * @return File_ANSI
+ * @return \phpseclib\File\ANSI
* @access public
*/
- function File_ANSI()
+ function __construct()
{
+ $attr_cell = new \stdClass();
+ $attr_cell->bold = false;
+ $attr_cell->underline = false;
+ $attr_cell->blink = false;
+ $attr_cell->background = 'black';
+ $attr_cell->foreground = 'white';
+ $attr_cell->reverse = false;
+ $this->base_attr_cell = clone $attr_cell;
+ $this->attr_cell = clone $attr_cell;
+
$this->setHistory(200);
$this->setDimensions(80, 24);
}
@@ -222,8 +184,8 @@ class File_ANSI
*
* Resets the screen as well
*
- * @param Integer $x
- * @param Integer $y
+ * @param int $x
+ * @param int $y
* @access public
*/
function setDimensions($x, $y)
@@ -232,25 +194,17 @@ class File_ANSI
$this->max_y = $y - 1;
$this->x = $this->y = 0;
$this->history = $this->history_attrs = array();
- $this->attr_row = array_fill(0, $this->max_x + 1, '');
+ $this->attr_row = array_fill(0, $this->max_x + 2, $this->base_attr_cell);
$this->screen = array_fill(0, $this->max_y + 1, '');
$this->attrs = array_fill(0, $this->max_y + 1, $this->attr_row);
- $this->foreground = 'white';
- $this->background = 'black';
- $this->bold = false;
- $this->underline = false;
- $this->blink = false;
- $this->reverse = false;
- $this->color = false;
-
$this->ansi = '';
}
/**
* Set the number of lines that should be logged past the terminal height
*
- * @param Integer $x
- * @param Integer $y
+ * @param int $x
+ * @param int $y
* @access public
*/
function setHistory($history)
@@ -261,7 +215,7 @@ class File_ANSI
/**
* Load a string
*
- * @param String $source
+ * @param string $source
* @access public
*/
function loadString($source)
@@ -273,11 +227,12 @@ class File_ANSI
/**
* Appdend a string
*
- * @param String $source
+ * @param string $source
* @access public
*/
function appendString($source)
{
+ $this->tokenization = array('');
for ($i = 0; $i < strlen($source); $i++) {
if (strlen($this->ansi)) {
$this->ansi.= $source[$i];
@@ -294,6 +249,8 @@ class File_ANSI
default:
continue 2;
}
+ $this->tokenization[] = $this->ansi;
+ $this->tokenization[] = '';
// http://ascii-table.com/ansi-escape-sequences-vt-100.php
switch ($this->ansi) {
case "\x1B[H": // Move cursor to upper left corner
@@ -315,7 +272,7 @@ class File_ANSI
case "\x1B[K": // Clear screen from cursor right
$this->screen[$this->y] = substr($this->screen[$this->y], 0, $this->x);
- array_splice($this->attrs[$this->y], $this->x + 1);
+ array_splice($this->attrs[$this->y], $this->x + 1, $this->max_x - $this->x, array_fill($this->x, $this->max_x - $this->x - 1, $this->base_attr_cell));
break;
case "\x1B[2K": // Clear entire line
$this->screen[$this->y] = str_repeat(' ', $this->x);
@@ -323,6 +280,7 @@ class File_ANSI
break;
case "\x1B[?1h": // set cursor key to application
case "\x1B[?25h": // show the cursor
+ case "\x1B(B": // set united states g0 character set
break;
case "\x1BE": // Move to next line
$this->_newLine();
@@ -330,6 +288,10 @@ class File_ANSI
break;
default:
switch (true) {
+ case preg_match('#\x1B\[(\d+)B#', $this->ansi, $match): // Move cursor down n lines
+ $this->old_y = $this->y;
+ $this->y+= $match[1];
+ break;
case preg_match('#\x1B\[(\d+);(\d+)H#', $this->ansi, $match): // Move cursor to screen location v,h
$this->old_x = $this->x;
$this->old_y = $this->y;
@@ -338,65 +300,44 @@ class File_ANSI
break;
case preg_match('#\x1B\[(\d+)C#', $this->ansi, $match): // Move cursor right n lines
$this->old_x = $this->x;
- $x = $match[1] - 1;
+ $this->x+= $match[1];
+ break;
+ case preg_match('#\x1B\[(\d+)D#', $this->ansi, $match): // Move cursor left n lines
+ $this->old_x = $this->x;
+ $this->x-= $match[1];
break;
case preg_match('#\x1B\[(\d+);(\d+)r#', $this->ansi, $match): // Set top and bottom lines of a window
break;
case preg_match('#\x1B\[(\d*(?:;\d*)*)m#', $this->ansi, $match): // character attributes
+ $attr_cell = &$this->attr_cell;
$mods = explode(';', $match[1]);
foreach ($mods as $mod) {
switch ($mod) {
case 0: // Turn off character attributes
- $this->attrs[$this->y][$this->x] = '';
-
- if ($this->bold) $this->attrs[$this->y][$this->x].= '';
- if ($this->underline) $this->attrs[$this->y][$this->x].= '';
- if ($this->blink) $this->attrs[$this->y][$this->x].= '';
- if ($this->color) $this->attrs[$this->y][$this->x].= '';
-
- if ($this->reverse) {
- $temp = $this->background;
- $this->background = $this->foreground;
- $this->foreground = $temp;
- }
-
- $this->bold = $this->underline = $this->blink = $this->color = $this->reverse = false;
+ $attr_cell = clone $this->base_attr_cell;
break;
case 1: // Turn bold mode on
- if (!$this->bold) {
- $this->attrs[$this->y][$this->x] = '';
- $this->bold = true;
- }
+ $attr_cell->bold = true;
break;
case 4: // Turn underline mode on
- if (!$this->underline) {
- $this->attrs[$this->y][$this->x] = '';
- $this->underline = true;
- }
+ $attr_cell->underline = true;
break;
case 5: // Turn blinking mode on
- if (!$this->blink) {
- $this->attrs[$this->y][$this->x] = '