Switch to custom fork of phpseclib, change namespace

This commit is contained in:
Daniil Gentili 2019-12-18 14:21:27 +01:00
parent 791d6b6b43
commit b8067c7e95
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
19 changed files with 101 additions and 107 deletions

View File

@ -13,7 +13,7 @@
"php": ">=7.4.0",
"danog/primemodule": "^1",
"danog/magicalserializer": "^1.0",
"phpseclib/phpseclib": "dev-master#f715b2928976aaef389839a056c947aa8023277b as 2.0.15",
"danog/tgseclib": "^3",
"erusev/parsedown": "^1.7",
"ext-mbstring": "*",
"ext-json": "*",
@ -62,10 +62,6 @@
]
},
"repositories": [
{
"type": "git",
"url": "https://github.com/danog/phpseclib"
},
{
"type": "git",
"url": "https://github.com/danog/dns"

View File

@ -26,7 +26,7 @@ if (\defined('HHVM_VERSION')) {
$engines = [['PHP64', ['OpenSSL']], ['BCMath', ['OpenSSL']], ['PHP32', ['OpenSSL']]];
foreach ($engines as $engine) {
try {
\phpseclib3\Math\BigInteger::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
\tgseclib\Math\BigInteger::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
break;
} catch (\Exception $e) {
}

View File

@ -115,8 +115,13 @@ class API extends InternalDoc
$changed = true;
}
if (\strpos($tounserialize, 'C:25:"phpseclib\\Math\\BigInteger"') !== false) {
Logger::log("SUBBING PHPSECLIB3!");
$tounserialize = \str_replace('C:25:"phpseclib\\Math\\BigInteger"', 'C:26:"phpseclib3\\Math\\BigInteger"', $tounserialize);
Logger::log("SUBBING TGSECLIB old!");
$tounserialize = \str_replace('C:25:"phpseclib\\Math\\BigInteger"', 'C:24:"tgseclib\\Math\\BigInteger"', $tounserialize);
$changed = true;
}
if (\strpos($tounserialize, 'C:26:"phpseclib3\\Math\\BigInteger"') !== false) {
Logger::log("SUBBING TGSECLIB!");
$tounserialize = \str_replace('C:26:"phpseclib3\\Math\\BigInteger"', 'C:24:"tgseclib\\Math\\BigInteger"', $tounserialize);
$changed = true;
}

View File

@ -4332,7 +4332,7 @@ class InternalDoc extends APIFactory
*
* @return bool
*/
public function checkG(\phpseclib3\Math\BigInteger $g_a, \phpseclib3\Math\BigInteger $p, array $extra = []): bool
public function checkG(\tgseclib\Math\BigInteger $g_a, \tgseclib\Math\BigInteger $p, array $extra = []): bool
{
return $this->__call(__FUNCTION__, [$g_a, $p, $extra]);
}
@ -4344,7 +4344,7 @@ class InternalDoc extends APIFactory
*
* @return boolean
*/
public function checkPG(\phpseclib3\Math\BigInteger $p, \phpseclib3\Math\BigInteger $g, array $extra = []): bool
public function checkPG(\tgseclib\Math\BigInteger $p, \tgseclib\Math\BigInteger $g, array $extra = []): bool
{
return $this->__call(__FUNCTION__, [$p, $g, $extra]);
}

View File

@ -57,7 +57,7 @@ class Lang
'encode_double_error' => 'Non sono riuscito a codificare il numero a virgola mobile fornito',
'file_not_exist' => 'Il file specificato non esiste',
'deserialization_error' => 'C\'è stato un errore durante la deserializzazione',
'rsa_init' => 'Istanziamento di \\phpseclib3\\Crypt\\RSA in corso...',
'rsa_init' => 'Istanziamento di \\tgseclib\\Crypt\\RSA in corso...',
'loading_key' => 'Caricamento della chiave in corso...',
'computing_fingerprint' => 'Calcolo del fingerprint in corso...',
'rsa_encrypting' => 'Criptando con chiave RSA...',
@ -204,7 +204,7 @@ class Lang
'encode_double_error' => 'Could not properly encode double',
'file_not_exist' => 'File does not exist',
'deserialization_error' => 'An error occurred on deserialization',
'rsa_init' => 'Istantiating \\phpseclib3\\Crypt\\RSA...',
'rsa_init' => 'Istantiating \\tgseclib\\Crypt\\RSA...',
'loading_key' => 'Loading key...',
'computing_fingerprint' => 'Computing fingerprint...',
'rsa_encrypting' => 'Encrypting with rsa key...',
@ -5291,7 +5291,7 @@ class Lang
'encode_double_error' => 'Could not properly encode double',
'file_not_exist' => 'File does not exist',
'deserialization_error' => 'An error occurred on deserialization',
'rsa_init' => 'Istantiating \\phpseclib3\\Crypt\\RSA...',
'rsa_init' => 'Istantiating \\tgseclib\\Crypt\\RSA...',
'loading_key' => 'Loading key...',
'computing_fingerprint' => 'Computing fingerprint...',
'rsa_encrypting' => 'Encrypting with rsa key...',

View File

@ -169,7 +169,7 @@ class Lua
public static function convertObjects(&$data)
{
\array_walk_recursive($data, function (&$value, $key) {
if (\is_object($value) && !$value instanceof \phpseclib3\Math\BigInteger) {
if (\is_object($value) && !$value instanceof \tgseclib\Math\BigInteger) {
$newval = [];
foreach (\get_class_methods($value) as $name) {
$newval[$name] = [$value, $name];

View File

@ -30,13 +30,13 @@ trait MsgIdHandler
public function checkMessageId($new_message_id, $aargs)
{
if (!\is_object($new_message_id)) {
$new_message_id = new \phpseclib3\Math\BigInteger(\strrev($new_message_id), 256);
$new_message_id = new \tgseclib\Math\BigInteger(\strrev($new_message_id), 256);
}
$min_message_id = (new \phpseclib3\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32);
$min_message_id = (new \tgseclib\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32);
if ($min_message_id->compare($new_message_id) > 0) {
$this->API->logger->logger('Given message id ('.$new_message_id.') is too old compared to the min value ('.$min_message_id.').', \danog\MadelineProto\Logger::WARNING);
}
$max_message_id = (new \phpseclib3\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32);
$max_message_id = (new \tgseclib\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32);
if ($max_message_id->compare($new_message_id) < 0) {
throw new \danog\MadelineProto\Exception('Given message id ('.$new_message_id.') is too new compared to the max value ('.$max_message_id.'). Consider syncing your date.');
}
@ -84,7 +84,7 @@ trait MsgIdHandler
public function generateMessageId()
{
$message_id = (new \phpseclib3\Math\BigInteger(\time() + $this->time_delta))->bitwise_leftShift(32);
$message_id = (new \tgseclib\Math\BigInteger(\time() + $this->time_delta))->bitwise_leftShift(32);
if ($message_id->compare($key = $this->getMaxId($incoming = false)) <= 0) {
$message_id = $key->add(\danog\MadelineProto\Magic::$four);
}

View File

@ -34,11 +34,11 @@ trait ResponseHandler
foreach ($msg_ids as $msg_id) {
$cur_info = 0;
if (!isset($this->incoming_messages[$msg_id])) {
$msg_id = new \phpseclib3\Math\BigInteger(\strrev($msg_id), 256);
if ((new \phpseclib3\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32)->compare($msg_id) < 0) {
$msg_id = new \tgseclib\Math\BigInteger(\strrev($msg_id), 256);
if ((new \tgseclib\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32)->compare($msg_id) < 0) {
$this->logger->logger("Do not know anything about $msg_id and it is too small");
$cur_info |= 3;
} elseif ((new \phpseclib3\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32)->compare($msg_id) > 0) {
} elseif ((new \tgseclib\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32)->compare($msg_id) > 0) {
$this->logger->logger("Do not know anything about $msg_id and it is too big");
$cur_info |= 1;
} else {
@ -185,7 +185,7 @@ trait ResponseHandler
foreach ($this->incoming_messages[$current_msg_id]['content']['msg_ids'] as $key => $msg_id) {
$info = \ord($this->incoming_messages[$current_msg_id]['content']['info'][$key]);
$msg_id = new \phpseclib3\Math\BigInteger(\strrev($msg_id), 256);
$msg_id = new \tgseclib\Math\BigInteger(\strrev($msg_id), 256);
$status = 'Status for message id '.$msg_id.': ';
/*if ($info & 4) {
*$this->gotResponseForOutgoingMessageId($msg_id);
@ -551,7 +551,7 @@ trait ResponseHandler
return;
case 16:
case 17:
$this->time_delta = (int) (new \phpseclib3\Math\BigInteger(\strrev($response_id), 256))->bitwise_rightShift(32)->subtract(new \phpseclib3\Math\BigInteger(\time()))->toString();
$this->time_delta = (int) (new \tgseclib\Math\BigInteger(\strrev($response_id), 256))->bitwise_rightShift(32)->subtract(new \tgseclib\Math\BigInteger(\time()))->toString();
$this->logger->logger('Set time delta to '.$this->time_delta, \danog\MadelineProto\Logger::WARNING);
$this->API->resetMTProtoSession();
$this->shared->setTempAuthKey(null);

View File

@ -24,7 +24,7 @@ use danog\MadelineProto\DataCenterConnection;
use danog\MadelineProto\MTProto\AuthKey;
use danog\MadelineProto\MTProto\PermAuthKey;
use danog\MadelineProto\MTProto\TempAuthKey;
use phpseclib3\Math\BigInteger;
use tgseclib\Math\BigInteger;
/**
* Manages the creation of the authorization key.
@ -108,9 +108,9 @@ trait AuthKeyHandler
* ***********************************************************************
* Compute p and q
*/
$pq = new \phpseclib3\Math\BigInteger((string) $pq_bytes, 256);
$q = new \phpseclib3\Math\BigInteger(0);
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
$pq = new \tgseclib\Math\BigInteger((string) $pq_bytes, 256);
$q = new \tgseclib\Math\BigInteger(0);
$p = new \tgseclib\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -119,7 +119,7 @@ trait AuthKeyHandler
}
if (!$pq->equals($p->multiply($q))) {
$this->logger->logger('Automatic factorization failed, trying native CPP module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::native_single_cpp($pq->__toString()));
$p = new \tgseclib\Math\BigInteger(\danog\PrimeModule::native_single_cpp($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -129,7 +129,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$this->logger->logger('Automatic factorization failed, trying alt py module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::python_single_alt($pq->__toString()));
$p = new \tgseclib\Math\BigInteger(\danog\PrimeModule::python_single_alt($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -139,7 +139,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$this->logger->logger('Automatic factorization failed, trying py module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::python_single($pq->__toString()));
$p = new \tgseclib\Math\BigInteger(\danog\PrimeModule::python_single($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -149,7 +149,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$this->logger->logger('Automatic factorization failed, trying native module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::native_single($pq->__toString()));
$p = new \tgseclib\Math\BigInteger(\danog\PrimeModule::native_single($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -160,7 +160,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$this->logger->logger('Automatic factorization failed, trying wolfram module', \danog\MadelineProto\Logger::ERROR);
$p = new \phpseclib3\Math\BigInteger(yield $this->wolframSingle($pq->__toString()));
$p = new \tgseclib\Math\BigInteger(yield $this->wolframSingle($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -284,9 +284,9 @@ trait AuthKeyHandler
if ($server_nonce != $server_DH_inner_data['server_nonce']) {
throw new \danog\MadelineProto\SecurityException('wrong server nonce');
}
$g = new \phpseclib3\Math\BigInteger($server_DH_inner_data['g']);
$g_a = new \phpseclib3\Math\BigInteger((string) $server_DH_inner_data['g_a'], 256);
$dh_prime = new \phpseclib3\Math\BigInteger((string) $server_DH_inner_data['dh_prime'], 256);
$g = new \tgseclib\Math\BigInteger($server_DH_inner_data['g']);
$g_a = new \tgseclib\Math\BigInteger((string) $server_DH_inner_data['g_a'], 256);
$dh_prime = new \tgseclib\Math\BigInteger((string) $server_DH_inner_data['dh_prime'], 256);
/*
* ***********************************************************************
* Time delta
@ -298,7 +298,7 @@ trait AuthKeyHandler
$this->checkG($g_a, $dh_prime);
for ($retry_id = 0; $retry_id <= $this->settings['max_tries']['authorization']; $retry_id++) {
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$b = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$this->logger->logger('Generating g_b...', \danog\MadelineProto\Logger::VERBOSE);
$g_b = $g->powMod($b, $dh_prime);
$this->checkG($g_b, $dh_prime);
@ -526,8 +526,8 @@ trait AuthKeyHandler
return $this->dh_config;
}
$dh_config['p'] = new \phpseclib3\Math\BigInteger((string) $dh_config['p'], 256);
$dh_config['g'] = new \phpseclib3\Math\BigInteger($dh_config['g']);
$dh_config['p'] = new \tgseclib\Math\BigInteger((string) $dh_config['p'], 256);
$dh_config['g'] = new \tgseclib\Math\BigInteger($dh_config['g']);
$this->checkPG($dh_config['p'], $dh_config['g']);
return $this->dh_config = $dh_config;

View File

@ -47,7 +47,7 @@ trait Crypt
public static function ctrEncrypt($message, $key, $iv)
{
$cipher = new \phpseclib3\Crypt\AES('ctr');
$cipher = new \tgseclib\Crypt\AES('ctr');
$cipher->setKey($key);
$cipher->setIV($iv);
@ -56,7 +56,7 @@ trait Crypt
public static function igeEncrypt($message, $key, $iv)
{
$cipher = new \phpseclib3\Crypt\AES('ige');
$cipher = new \tgseclib\Crypt\AES('ige');
$cipher->setKey($key);
$cipher->setIV($iv);
@ -64,7 +64,7 @@ trait Crypt
}
public static function igeDecrypt($message, $key, $iv)
{
$cipher = new \phpseclib3\Crypt\AES('ige');
$cipher = new \tgseclib\Crypt\AES('ige');
$cipher->setKey($key);
$cipher->setIV($iv);

View File

@ -217,7 +217,7 @@ trait Files
$iv = \danog\MadelineProto\Tools::random(32);
$digest = \hash('md5', $key.$iv, true);
$fingerprint = \danog\MadelineProto\Tools::unpackSignedInt(\substr($digest, 0, 4) ^ \substr($digest, 4, 4));
$ige = new \phpseclib3\Crypt\AES('ige');
$ige = new \tgseclib\Crypt\AES('ige');
$ige->setIV($iv);
$ige->setKey($key);
$ige->enableContinuousBuffer();
@ -956,7 +956,7 @@ trait Files
if ($fingerprint !== $message_media['key_fingerprint']) {
throw new \danog\MadelineProto\Exception('Fingerprint mismatch!');
}
$ige = new \phpseclib3\Crypt\AES('ige');
$ige = new \tgseclib\Crypt\AES('ige');
$ige->setIV($message_media['iv']);
$ige->setKey($message_media['key']);
$ige->enableContinuousBuffer();

View File

@ -22,7 +22,7 @@ use danog\MadelineProto\Exception;
use danog\MadelineProto\Magic;
use danog\MadelineProto\SecurityException;
use danog\MadelineProto\Tools;
use phpseclib3\Math\BigInteger;
use tgseclib\Math\BigInteger;
/**
* Manages SRP password calculation.

View File

@ -115,69 +115,63 @@ class Magic
/**
* Bigint zero.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $zero;
/**
* Bigint one.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $one;
/**
* Bigint two.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $two;
/**
* Bigint three.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $three;
/**
* Bigint four.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $four;
/**
* Bigint 2^1984.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $twoe1984;
/**
* Bigint 2^2047.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $twoe2047;
/**
* Bigint 2^2048.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $twoe2048;
/**
* Bigint 2^31.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $zeroeight;
/**
* Bigint 20261.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public static $twozerotwosixone;
/**
* Bigint ECDH num.
*
* @var \phpseclib3\Math\BigInteger
*/
public static $ton;
/**
* Decoded UTF8 emojis for call fingerprint.
*
@ -239,7 +233,7 @@ class Magic
\set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
\set_exception_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionHandler']);
if (!self::$inited) {
if (!\defined('\\phpseclib3\\Crypt\\Common\\SymmetricKey::MODE_IGE') || \phpseclib3\Crypt\Common\SymmetricKey::MODE_IGE !== 7) {
if (!\defined('\\tgseclib\\Crypt\\Common\\SymmetricKey::MODE_IGE') || \tgseclib\Crypt\Common\SymmetricKey::MODE_IGE !== 7) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['phpseclib_fork']);
}
foreach (['xml', 'fileinfo', 'json', 'mbstring'] as $extension) {
@ -261,17 +255,16 @@ class Magic
}
}
self::$emojis = \json_decode(self::JSON_EMOJIS);
self::$zero = new \phpseclib3\Math\BigInteger(0);
self::$one = new \phpseclib3\Math\BigInteger(1);
self::$two = new \phpseclib3\Math\BigInteger(2);
self::$three = new \phpseclib3\Math\BigInteger(3);
self::$four = new \phpseclib3\Math\BigInteger(4);
self::$twoe1984 = new \phpseclib3\Math\BigInteger('1751908409537131537220509645351687597690304110853111572994449976845956819751541616602568796259317428464425605223064365804210081422215355425149431390635151955247955156636234741221447435733643262808668929902091770092492911737768377135426590363166295684370498604708288556044687341394398676292971255828404734517580702346564613427770683056761383955397564338690628093211465848244049196353703022640400205739093118270803778352768276670202698397214556629204420309965547056893233608758387329699097930255380715679250799950923553703740673620901978370802540218870279314810722790539899334271514365444369275682816');
self::$twoe2047 = new \phpseclib3\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328');
self::$twoe2048 = new \phpseclib3\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656');
self::$twozerotwosixone = new \phpseclib3\Math\BigInteger(20261);
self::$zeroeight = new \phpseclib3\Math\BigInteger('2147483648');
self::$ton = new \phpseclib3\Math\BigInteger('7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed', 16);
self::$zero = new \tgseclib\Math\BigInteger(0);
self::$one = new \tgseclib\Math\BigInteger(1);
self::$two = new \tgseclib\Math\BigInteger(2);
self::$three = new \tgseclib\Math\BigInteger(3);
self::$four = new \tgseclib\Math\BigInteger(4);
self::$twoe1984 = new \tgseclib\Math\BigInteger('1751908409537131537220509645351687597690304110853111572994449976845956819751541616602568796259317428464425605223064365804210081422215355425149431390635151955247955156636234741221447435733643262808668929902091770092492911737768377135426590363166295684370498604708288556044687341394398676292971255828404734517580702346564613427770683056761383955397564338690628093211465848244049196353703022640400205739093118270803778352768276670202698397214556629204420309965547056893233608758387329699097930255380715679250799950923553703740673620901978370802540218870279314810722790539899334271514365444369275682816');
self::$twoe2047 = new \tgseclib\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328');
self::$twoe2048 = new \tgseclib\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656');
self::$twozerotwosixone = new \tgseclib\Math\BigInteger(20261);
self::$zeroeight = new \tgseclib\Math\BigInteger('2147483648');
try {
self::$isatty = \defined('STDOUT') && \function_exists('posix_isatty') && \posix_isatty(STDOUT);

View File

@ -30,13 +30,13 @@ class RSA
/**
* Exponent.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public $e;
/**
* Modulus.
*
* @var \phpseclib3\Math\BigInteger
* @var \tgseclib\Math\BigInteger
*/
public $n;
/**
@ -58,7 +58,7 @@ class RSA
{
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['rsa_init'], Logger::ULTRA_VERBOSE);
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['loading_key'], Logger::ULTRA_VERBOSE);
$key = \phpseclib3\Crypt\RSA::load($rsa_key);
$key = \tgseclib\Crypt\RSA::load($rsa_key);
$this->n = Tools::getVar($key, 'modulus');
$this->e = Tools::getVar($key, 'exponent');
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['computing_fingerprint'], Logger::ULTRA_VERBOSE);
@ -88,6 +88,6 @@ class RSA
{
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['rsa_encrypting'], Logger::VERBOSE);
return (new \phpseclib3\Math\BigInteger((string) $data, 256))->powMod($this->e, $this->n)->toBytes();
return (new \tgseclib\Math\BigInteger((string) $data, 256))->powMod($this->e, $this->n)->toBytes();
}
}

View File

@ -59,8 +59,8 @@ trait AuthKeyHandler
}
$dh_config = yield $this->getDhConfig();
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \phpseclib3\Math\BigInteger((string) $params['g_a'], 256);
$b = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \tgseclib\Math\BigInteger((string) $params['g_a'], 256);
$this->checkG($params['g_a'], $dh_config['p']);
$key = ['auth_key' => \str_pad($params['g_a']->powMod($b, $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT)];
//$this->logger->logger($key);
@ -92,7 +92,7 @@ trait AuthKeyHandler
$this->logger->logger('Creating secret chat with '.$user['user_id'].'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
$a = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$a = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->checkG($g_a, $dh_config['p']);
@ -120,7 +120,7 @@ trait AuthKeyHandler
return false;
}
$dh_config = yield $this->getDhConfig();
$params['g_a_or_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_a_or_b'], 256);
$params['g_a_or_b'] = new \tgseclib\Math\BigInteger((string) $params['g_a_or_b'], 256);
$this->checkG($params['g_a_or_b'], $dh_config['p']);
$key = ['auth_key' => \str_pad($params['g_a_or_b']->powMod($this->temp_requested_secret_chats[$params['id']], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT)];
unset($this->temp_requested_secret_chats[$params['id']]);
@ -165,7 +165,7 @@ trait AuthKeyHandler
$this->logger->logger('Rekeying secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
$a = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$a = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->checkG($g_a, $dh_config['p']);
@ -189,8 +189,8 @@ trait AuthKeyHandler
private function acceptRekey($chat, array $params): \Generator
{
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
$my_exchange_id = new \phpseclib3\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
$other_exchange_id = new \phpseclib3\Math\BigInteger($params['exchange_id'], -256);
$my_exchange_id = new \tgseclib\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
$other_exchange_id = new \tgseclib\Math\BigInteger($params['exchange_id'], -256);
//$this->logger->logger($my, $params);
if ($my_exchange_id->compare($other_exchange_id) > 0) {
return;
@ -204,8 +204,8 @@ trait AuthKeyHandler
$this->logger->logger('Accepting rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \phpseclib3\Math\BigInteger((string) $params['g_a'], 256);
$b = new \tgseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \tgseclib\Math\BigInteger((string) $params['g_a'], 256);
$this->checkG($params['g_a'], $dh_config['p']);
$key = ['auth_key' => \str_pad($params['g_a']->powMod($b, $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT)];
$key['fingerprint'] = \substr(\sha1($key['auth_key'], true), -8);
@ -236,7 +236,7 @@ trait AuthKeyHandler
}
$this->logger->logger('Committing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$params['g_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_b'], 256);
$params['g_b'] = new \tgseclib\Math\BigInteger((string) $params['g_b'], 256);
$this->checkG($params['g_b'], $dh_config['p']);
$key = ['auth_key' => \str_pad($params['g_b']->powMod($this->temp_rekeyed_secret_chats[$params['exchange_id']], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT)];
$key['fingerprint'] = \substr(\sha1($key['auth_key'], true), -8);

View File

@ -27,7 +27,7 @@ use danog\MadelineProto\Stream\BufferInterface;
use danog\MadelineProto\Stream\ConnectionContext;
use danog\MadelineProto\Stream\RawStreamInterface;
use phpseclib3\Crypt\AES;
use tgseclib\Crypt\AES;
/**
* AES CTR stream wrapper.
@ -58,12 +58,12 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface
*/
public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator
{
$this->encrypt = new \phpseclib3\Crypt\AES('ctr');
$this->encrypt = new \tgseclib\Crypt\AES('ctr');
$this->encrypt->enableContinuousBuffer();
$this->encrypt->setKey($this->extra['encrypt']['key']);
$this->encrypt->setIV($this->extra['encrypt']['iv']);
$this->decrypt = new \phpseclib3\Crypt\AES('ctr');
$this->decrypt = new \tgseclib\Crypt\AES('ctr');
$this->decrypt->enableContinuousBuffer();
$this->decrypt->setKey($this->extra['decrypt']['key']);
$this->decrypt->setIV($this->extra['decrypt']['iv']);

View File

@ -32,12 +32,12 @@ use danog\MadelineProto\Stream\Transport\DefaultStream;
use danog\MadelineProto\TL\TL;
use danog\MadelineProto\Tools;
use Exception;
use phpseclib3\Crypt\DH;
use phpseclib3\Crypt\EC;
use phpseclib3\Crypt\EC\Curves\Curve25519;
use phpseclib3\Crypt\EC\PrivateKey;
use phpseclib3\Crypt\EC\PublicKey;
use phpseclib3\Math\BigInteger;
use tgseclib\Crypt\DH;
use tgseclib\Crypt\EC;
use tgseclib\Crypt\EC\Curves\Curve25519;
use tgseclib\Crypt\EC\PrivateKey;
use tgseclib\Crypt\EC\PublicKey;
use tgseclib\Math\BigInteger;
class ADNLConnection
{

View File

@ -24,7 +24,7 @@ use Amp\File\StatCache;
use Amp\Loop;
use Amp\Promise;
use Amp\Success;
use phpseclib3\Math\BigInteger;
use tgseclib\Math\BigInteger;
use function Amp\ByteStream\getOutputBufferStream;
use function Amp\ByteStream\getStdin;
@ -73,9 +73,9 @@ trait Tools
{
//sort($ints, SORT_NUMERIC);
if (\danog\MadelineProto\Magic::$bigint) {
$hash = new \phpseclib3\Math\BigInteger(0);
$hash = new \tgseclib\Math\BigInteger(0);
foreach ($ints as $int) {
$hash = $hash->multiply(\danog\MadelineProto\Magic::$twozerotwosixone)->add(\danog\MadelineProto\Magic::$zeroeight)->add(new \phpseclib3\Math\BigInteger($int))->divide(\danog\MadelineProto\Magic::$zeroeight)[1];
$hash = $hash->multiply(\danog\MadelineProto\Magic::$twozerotwosixone)->add(\danog\MadelineProto\Magic::$zeroeight)->add(new \tgseclib\Math\BigInteger($int))->divide(\danog\MadelineProto\Magic::$zeroeight)[1];
}
$hash = self::unpackSignedInt(\strrev(\str_pad($hash->toBytes(), 4, "\0", STR_PAD_LEFT)));
} else {
@ -132,7 +132,7 @@ trait Tools
*/
public static function random(int $length): string
{
return $length === 0 ? '' : \phpseclib3\Crypt\Random::string($length);
return $length === 0 ? '' : \tgseclib\Crypt\Random::string($length);
}
/**

View File

@ -57,7 +57,7 @@ trait AuthKeyHandler
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['calling_user'], $user['user_id']), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_a'], \danog\MadelineProto\Logger::VERBOSE);
$a = \phpseclib3\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
$a = \tgseclib\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_g_a'], \danog\MadelineProto\Logger::VERBOSE);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->checkG($g_a, $dh_config['p']);
@ -84,7 +84,7 @@ trait AuthKeyHandler
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['accepting_call'], $this->calls[$call['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_b'], \danog\MadelineProto\Logger::VERBOSE);
$b = \phpseclib3\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
$b = \tgseclib\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
$this->checkG($g_b, $dh_config['p']);
@ -123,7 +123,7 @@ trait AuthKeyHandler
}
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['call_confirming'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$params['g_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_b'], 256);
$params['g_b'] = new \tgseclib\Math\BigInteger((string) $params['g_b'], 256);
$this->checkG($params['g_b'], $dh_config['p']);
$key = \str_pad($params['g_b']->powMod($this->calls[$params['id']]->storage['a'], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT);
try {
@ -145,10 +145,10 @@ trait AuthKeyHandler
}
$visualization = [];
$length = new \phpseclib3\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
$length = new \tgseclib\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
foreach (\str_split(\hash('sha256', $key.\str_pad($this->calls[$params['id']]->storage['g_a'], 256, \chr(0), \STR_PAD_LEFT), true), 8) as $number) {
$number[0] = \chr(\ord($number[0]) & 0x7f);
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \phpseclib3\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \tgseclib\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
}
$this->calls[$params['id']]->setVisualization($visualization);
@ -175,17 +175,17 @@ trait AuthKeyHandler
if (\hash('sha256', $params['g_a_or_b'], true) != $this->calls[$params['id']]->storage['g_a_hash']) {
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['invalid_g_a']);
}
$params['g_a_or_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_a_or_b'], 256);
$params['g_a_or_b'] = new \tgseclib\Math\BigInteger((string) $params['g_a_or_b'], 256);
$this->checkG($params['g_a_or_b'], $dh_config['p']);
$key = \str_pad($params['g_a_or_b']->powMod($this->calls[$params['id']]->storage['b'], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT);
if (\substr(\sha1($key, true), -8) != $params['key_fingerprint']) {
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['fingerprint_invalid']);
}
$visualization = [];
$length = new \phpseclib3\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
$length = new \tgseclib\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
foreach (\str_split(\hash('sha256', $key.\str_pad($params['g_a_or_b']->toBytes(), 256, \chr(0), \STR_PAD_LEFT), true), 8) as $number) {
$number[0] = \chr(\ord($number[0]) & 0x7f);
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \phpseclib3\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \tgseclib\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
}
$this->calls[$params['id']]->setVisualization($visualization);
$this->calls[$params['id']]->configuration['endpoints'] = \array_merge($params['connections'], $this->calls[$params['id']]->configuration['endpoints']);