mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-06-29 05:13:31 +00:00
Merge branch '1.0' into 2.0
This commit is contained in:
commit
e46ef4cdf7
|
@ -729,6 +729,33 @@ class BigInteger
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the size of a BigInteger in bits
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
function getLength()
|
||||||
|
{
|
||||||
|
if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
|
||||||
|
return strlen($this->toBits());
|
||||||
|
}
|
||||||
|
|
||||||
|
$max = count($this->value) - 1;
|
||||||
|
return $max != -1 ?
|
||||||
|
$max * MATH_BIGINTEGER_BASE + ceil(log($a->value[$max] + 1, 2)) :
|
||||||
|
0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the size of a BigInteger in bytes
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
function getLengthInBytes()
|
||||||
|
{
|
||||||
|
return ceil($this->getLength() / 8);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy an object
|
* Copy an object
|
||||||
*
|
*
|
||||||
|
@ -3237,6 +3264,11 @@ class BigInteger
|
||||||
$min = $temp;
|
$min = $temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$length = $max->getLength();
|
||||||
|
if ($length > 8196) {
|
||||||
|
user_error('Generation of random prime numbers larger than 8196 has been disabled');
|
||||||
|
}
|
||||||
|
|
||||||
static $one, $two;
|
static $one, $two;
|
||||||
if (!isset($one)) {
|
if (!isset($one)) {
|
||||||
$one = new static(1);
|
$one = new static(1);
|
||||||
|
@ -3344,7 +3376,14 @@ class BigInteger
|
||||||
*/
|
*/
|
||||||
function isPrime($t = false)
|
function isPrime($t = false)
|
||||||
{
|
{
|
||||||
$length = strlen($this->toBytes());
|
$length = $this->getLength();
|
||||||
|
// OpenSSL limits RSA keys to 16384 bits. The length of an RSA key is equal to the length of the modulo, which is
|
||||||
|
// produced by multiplying the primes p and q by one another. The largest number two 8196 bit primes can produce is
|
||||||
|
// a 16384 bit number so, basically, 8196 bit primes are the largest OpenSSL will generate and if that's the largest
|
||||||
|
// that it'll generate it also stands to reason that that's the largest you'll be able to test primality on
|
||||||
|
if ($length > 8196) {
|
||||||
|
user_error('Primality testing is not supported for numbers larger than 8196 bits');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$t) {
|
if (!$t) {
|
||||||
// see HAC 4.49 "Note (controlling the error probability)"
|
// see HAC 4.49 "Note (controlling the error probability)"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user