1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jose\Component\Core\Util\Ecc\Curves; |
4
|
|
|
|
5
|
|
|
use Jose\Component\Core\Util\Ecc\Math\GmpMath; |
6
|
|
|
use Jose\Component\Core\Util\Ecc\Math\MathAdapterFactory; |
7
|
|
|
use Jose\Component\Core\Util\Ecc\Primitives\CurveFp; |
8
|
|
|
|
9
|
|
|
final class CurveFactory |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param $name |
13
|
|
|
* @return NamedCurveFp|CurveFp |
14
|
|
|
*/ |
15
|
|
|
public static function getCurveByName($name) |
16
|
|
|
{ |
17
|
|
|
$adapter = MathAdapterFactory::getAdapter(); |
18
|
|
|
$nistFactory = self::getNistFactory($adapter); |
19
|
|
|
|
20
|
|
|
switch ($name) { |
21
|
|
|
case NistCurve::NAME_P192: |
22
|
|
|
return $nistFactory->curve192(); |
|
|
|
|
23
|
|
|
case NistCurve::NAME_P224: |
24
|
|
|
return $nistFactory->curve224(); |
|
|
|
|
25
|
|
|
case NistCurve::NAME_P256: |
26
|
|
|
return $nistFactory->curve256(); |
27
|
|
|
case NistCurve::NAME_P384: |
28
|
|
|
return $nistFactory->curve384(); |
29
|
|
|
case NistCurve::NAME_P521: |
30
|
|
|
return $nistFactory->curve521(); |
31
|
|
|
default: |
32
|
|
|
throw new \RuntimeException('Unknown curve.'); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param $name |
38
|
|
|
* @return \Jose\Component\Core\Util\Ecc\Primitives\GeneratorPoint |
39
|
|
|
*/ |
40
|
|
|
public static function getGeneratorByName($name) |
41
|
|
|
{ |
42
|
|
|
$adapter = MathAdapterFactory::getAdapter(); |
43
|
|
|
$nistFactory = self::getNistFactory($adapter); |
44
|
|
|
|
45
|
|
|
switch ($name) { |
46
|
|
|
case NistCurve::NAME_P192: |
47
|
|
|
return $nistFactory->generator192(); |
|
|
|
|
48
|
|
|
case NistCurve::NAME_P224: |
49
|
|
|
return $nistFactory->generator224(); |
|
|
|
|
50
|
|
|
case NistCurve::NAME_P256: |
51
|
|
|
return $nistFactory->generator256(); |
52
|
|
|
case NistCurve::NAME_P384: |
53
|
|
|
return $nistFactory->generator384(); |
54
|
|
|
case NistCurve::NAME_P521: |
55
|
|
|
return $nistFactory->generator521(); |
56
|
|
|
default: |
57
|
|
|
throw new \RuntimeException('Unknown generator.'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param GmpMath $math |
63
|
|
|
* |
64
|
|
|
* @return NistCurve |
65
|
|
|
*/ |
66
|
|
|
private static function getNistFactory(GmpMath $math): NistCurve |
67
|
|
|
{ |
68
|
|
|
return new NistCurve($math); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.