Rev 1324 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1324 | Rev 1466 | ||
---|---|---|---|
Line 617... | Line 617... | ||
617 | * |
617 | * |
618 | * @return int |
618 | * @return int |
619 | */ |
619 | */ |
620 | public function getLengthInBytes() |
620 | public function getLengthInBytes() |
621 | { |
621 | { |
622 | return strlen($this->toBytes()); |
622 | return (int) ceil($this->getLength() / 8); |
623 | } |
623 | } |
624 | 624 | ||
625 | /** |
625 | /** |
626 | * Performs some pre-processing for powMod |
626 | * Performs some pre-processing for powMod |
627 | * |
627 | * |
Line 784... | Line 784... | ||
784 | $temp = $max; |
784 | $temp = $max; |
785 | $max = $min; |
785 | $max = $min; |
786 | $min = $temp; |
786 | $min = $temp; |
787 | } |
787 | } |
788 | 788 | ||
- | 789 | $length = $max->getLength(); |
|
- | 790 | if ($length > 8196) { |
|
- | 791 | throw new \RuntimeException("Generation of random prime numbers larger than 8196 has been disabled ($length)"); |
|
- | 792 | } |
|
- | 793 | ||
789 | $x = static::randomRange($min, $max); |
794 | $x = static::randomRange($min, $max); |
790 | 795 | ||
791 | return static::randomRangePrimeInner($x, $min, $max); |
796 | return static::randomRangePrimeInner($x, $min, $max); |
792 | } |
797 | } |
793 | 798 | ||
Line 988... | Line 993... | ||
988 | * @param int|bool $t |
993 | * @param int|bool $t |
989 | * @return bool |
994 | * @return bool |
990 | */ |
995 | */ |
991 | public function isPrime($t = false) |
996 | public function isPrime($t = false) |
992 | { |
997 | { |
- | 998 | // OpenSSL limits RSA keys to 16384 bits. The length of an RSA key is equal to the length of the modulo, which is |
|
- | 999 | // produced by multiplying the primes p and q by one another. The largest number two 8196 bit primes can produce is |
|
- | 1000 | // a 16384 bit number so, basically, 8196 bit primes are the largest OpenSSL will generate and if that's the largest |
|
- | 1001 | // that it'll generate it also stands to reason that that's the largest you'll be able to test primality on |
|
- | 1002 | $length = $this->getLength(); |
|
- | 1003 | if ($length > 8196) { |
|
- | 1004 | throw new \RuntimeException("Primality testing is not supported for numbers larger than 8196 bits ($length)"); |
|
- | 1005 | } |
|
- | 1006 | ||
993 | if (!$t) { |
1007 | if (!$t) { |
994 | $t = $this->setupIsPrime(); |
1008 | $t = $this->setupIsPrime(); |
995 | } |
1009 | } |
996 | return $this->testPrimality($t); |
1010 | return $this->testPrimality($t); |
997 | } |
1011 | } |