Bugfixes to prime factorization
This commit is contained in:
parent
f73b4645af
commit
f94d4804dd
@ -72,14 +72,75 @@ trait AuthKeyHandler
|
|||||||
* Compute p and q
|
* Compute p and q
|
||||||
*/
|
*/
|
||||||
$pq = new \phpseclib\Math\BigInteger($pq_bytes, 256);
|
$pq = new \phpseclib\Math\BigInteger($pq_bytes, 256);
|
||||||
|
$q = new \phpseclib\Math\BigInteger(0);
|
||||||
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
|
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
|
||||||
$q = $pq->divide($p)[0];
|
if (!$p->equals($this->zero)) {
|
||||||
if ($p->compare($q) > 0) {
|
$q = $pq->divide($p)[0];
|
||||||
list($p, $q) = [$q, $p];
|
if ($p->compare($q) > 0) {
|
||||||
|
list($p, $q) = [$q, $p];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!$pq->equals($p->multiply($q))) {
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
throw new \danog\MadelineProto\SecurityException("couldn't compute p and q. Original pq: {$pq}, computed p: {$p}, computed q: {$q}, computed pq: ".$p->multiply($q));
|
\danog\MadelineProto\Logger::log("Automatic factorization failed, trying native CPP module", \danog\MadelineProto\Logger::ERROR);
|
||||||
|
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::native_single_cpp($pq->__toString()));
|
||||||
|
if (!$p->equals($this->zero)) {
|
||||||
|
$q = $pq->divide($p) [0];
|
||||||
|
if ($p->compare($q) > 0) {
|
||||||
|
list($p, $q) = [$q, $p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
|
\danog\MadelineProto\Logger::log("Automatic factorization failed, trying alt py module", \danog\MadelineProto\Logger::ERROR);
|
||||||
|
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::python_single_alt($pq->__toString()));
|
||||||
|
if (!$p->equals($this->zero)) {
|
||||||
|
$q = $pq->divide($p) [0];
|
||||||
|
if ($p->compare($q) > 0) {
|
||||||
|
list($p, $q) = [$q, $p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
|
\danog\MadelineProto\Logger::log("Automatic factorization failed, trying py module", \danog\MadelineProto\Logger::ERROR);
|
||||||
|
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::python_single($pq->__toString()));
|
||||||
|
if (!$p->equals($this->zero)) {
|
||||||
|
$q = $pq->divide($p) [0];
|
||||||
|
if ($p->compare($q) > 0) {
|
||||||
|
list($p, $q) = [$q, $p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
|
\danog\MadelineProto\Logger::log("Automatic factorization failed, trying native module", \danog\MadelineProto\Logger::ERROR);
|
||||||
|
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::native_single($pq->__toString()));
|
||||||
|
if (!$p->equals($this->zero)) {
|
||||||
|
$q = $pq->divide($p) [0];
|
||||||
|
if ($p->compare($q) > 0) {
|
||||||
|
list($p, $q) = [$q, $p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
|
\danog\MadelineProto\Logger::log("Automatic factorization failed, trying wolfram module", \danog\MadelineProto\Logger::ERROR);
|
||||||
|
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::wolfram_single($pq->__toString()));
|
||||||
|
if (!$p->equals($this->zero)) {
|
||||||
|
$q = $pq->divide($p) [0];
|
||||||
|
if ($p->compare($q) > 0) {
|
||||||
|
list($p, $q) = [$q, $p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
|
throw new \danog\MadelineProto\SecurityException("couldn't compute p and q. Original pq: {$pq}, computed p: {$p}, computed q: {$q}, computed pq: ".$p->multiply($q));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
\danog\MadelineProto\Logger::log('Factorization '.$pq.' = '.$p.' * '.$q, \danog\MadelineProto\Logger::VERBOSE);
|
\danog\MadelineProto\Logger::log('Factorization '.$pq.' = '.$p.' * '.$q, \danog\MadelineProto\Logger::VERBOSE);
|
||||||
/*
|
/*
|
||||||
* ***********************************************************************
|
* ***********************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user