PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / 3rdparty / phpseclib3 / Math / PrimeField.php
backup / src / JetBackup / 3rdparty / phpseclib3 / Math Last commit date
BigInteger 1 year ago BinaryField 1 year ago Common 1 year ago PrimeField 1 year ago .htaccess 1 year ago BigInteger.php 1 year ago BinaryField.php 1 year ago PrimeField.php 1 year ago index.html 1 year ago web.config 1 year ago
PrimeField.php
111 lines
1 <?php
2
3 /**
4 * Prime Finite Fields
5 *
6 * Utilizes the factory design pattern
7 *
8 * PHP version 5 and 7
9 *
10 * @author Jim Wigginton <terrafrost@php.net>
11 * @copyright 2017 Jim Wigginton
12 * @license http://www.opensource.org/licenses/mit-license.html MIT License
13 * @link http://pear.php.net/package/Math_BigInteger
14 */
15
16 declare(strict_types=1);
17
18 namespace phpseclib3\Math;
19
20 use phpseclib3\Math\Common\FiniteField;
21 use phpseclib3\Math\PrimeField\Integer;
22
23 /**
24 * Prime Finite Fields
25 *
26 * @author Jim Wigginton <terrafrost@php.net>
27 */
28 class PrimeField extends FiniteField
29 {
30 /**
31 * Instance Counter
32 *
33 * @var int
34 */
35 private static $instanceCounter = 0;
36
37 /**
38 * Keeps track of current instance
39 *
40 * @var int
41 */
42 protected $instanceID;
43
44 /**
45 * Default constructor
46 */
47 public function __construct(BigInteger $modulo)
48 {
49 if (!$modulo->isPrime()) {
50 throw new \phpseclib3\Exception\UnexpectedValueException('PrimeField requires a prime number be passed to the constructor');
51 }
52
53 $this->instanceID = self::$instanceCounter++;
54 Integer::setModulo($this->instanceID, $modulo);
55 Integer::setRecurringModuloFunction($this->instanceID, $modulo->createRecurringModuloFunction());
56 }
57
58 /**
59 * Use a custom defined modular reduction function
60 */
61 public function setReduction(\Closure $func): void
62 {
63 $this->reduce = $func->bindTo($this, $this);
64 }
65
66 /**
67 * Returns an instance of a dynamically generated PrimeFieldInteger class
68 */
69 public function newInteger(BigInteger $num): Integer
70 {
71 return new Integer($this->instanceID, $num);
72 }
73
74 /**
75 * Returns an integer on the finite field between one and the prime modulo
76 */
77 public function randomInteger(): Integer
78 {
79 static $one;
80 if (!isset($one)) {
81 $one = new BigInteger(1);
82 }
83
84 return new Integer($this->instanceID, BigInteger::randomRange($one, Integer::getModulo($this->instanceID)));
85 }
86
87 /**
88 * Returns the length of the modulo in bytes
89 */
90 public function getLengthInBytes(): int
91 {
92 return Integer::getModulo($this->instanceID)->getLengthInBytes();
93 }
94
95 /**
96 * Returns the length of the modulo in bits
97 */
98 public function getLength(): int
99 {
100 return Integer::getModulo($this->instanceID)->getLength();
101 }
102
103 /**
104 * Destructor
105 */
106 public function __destruct()
107 {
108 Integer::cleanupCache($this->instanceID);
109 }
110 }
111