1 | <?php |
||
37 | final class CurveFp |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * @var CurveParameters |
||
42 | */ |
||
43 | private $parameters; |
||
44 | |||
45 | /** |
||
46 | * |
||
47 | * @var GmpMath |
||
48 | */ |
||
49 | private $adapter; |
||
50 | |||
51 | /** |
||
52 | * |
||
53 | * @var ModularArithmetic |
||
54 | */ |
||
55 | private $modAdapter; |
||
56 | |||
57 | /** |
||
58 | * Constructor that sets up the instance variables. |
||
59 | * |
||
60 | * @param CurveParameters $parameters |
||
61 | */ |
||
62 | public function __construct(CurveParameters $parameters) |
||
63 | { |
||
64 | $this->parameters = $parameters; |
||
65 | $this->adapter = new GmpMath(); |
||
66 | $this->modAdapter = new ModularArithmetic($this->parameters->getPrime()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return ModularArithmetic |
||
71 | */ |
||
72 | public function getModAdapter(): ModularArithmetic |
||
73 | { |
||
74 | return $this->modAdapter; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param \GMP $x |
||
79 | * @param \GMP $y |
||
80 | * @param \GMP|null $order |
||
81 | * |
||
82 | * @return Point |
||
83 | */ |
||
84 | public function getPoint(\GMP $x, \GMP $y, ?\GMP $order = null): Point |
||
85 | { |
||
86 | return new Point($this, $x, $y, $order); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return Point |
||
91 | */ |
||
92 | public function getInfinity(): Point |
||
96 | |||
97 | /** |
||
98 | * @param \GMP $x |
||
99 | * @param \GMP $y |
||
100 | * @param \GMP $order |
||
101 | * |
||
102 | * @return GeneratorPoint |
||
103 | */ |
||
104 | public function getGenerator(\GMP $x, \GMP $y, \GMP $order): GeneratorPoint |
||
108 | |||
109 | /** |
||
110 | * @param \GMP $x |
||
111 | * @param \GMP $y |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function contains(\GMP $x, \GMP $y): bool |
||
134 | |||
135 | /** |
||
136 | * @return \GMP |
||
137 | */ |
||
138 | public function getA(): \GMP |
||
142 | |||
143 | /** |
||
144 | * @return \GMP |
||
145 | */ |
||
146 | public function getB(): \GMP |
||
150 | |||
151 | /** |
||
152 | * @return \GMP |
||
153 | */ |
||
154 | public function getPrime(): \GMP |
||
158 | |||
159 | /** |
||
160 | * @return int |
||
161 | */ |
||
162 | public function getSize(): int |
||
166 | |||
167 | /** |
||
168 | * @param CurveFp $other |
||
169 | * |
||
170 | * @return int |
||
171 | */ |
||
172 | public function cmp(CurveFp $other): int |
||
182 | |||
183 | /** |
||
184 | * @param CurveFp $other |
||
185 | * |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function equals(CurveFp $other): bool |
||
192 | } |
||
193 |