1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SKien\PNServer\Utils; |
5
|
|
|
|
6
|
|
|
/* |
7
|
|
|
* extracted required classes and functions from package |
8
|
|
|
* spomky-labs/jose |
9
|
|
|
* https://github.com/Spomky-Labs/Jose |
10
|
|
|
* |
11
|
|
|
* @package PNServer |
12
|
|
|
* @version 1.0.0 |
13
|
|
|
* @copyright MIT License - see the copyright below and LICENSE file for details |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/* |
17
|
|
|
* ********************************************************************* |
18
|
|
|
* Copyright (C) 2012 Matyas Danter. |
19
|
|
|
* |
20
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining |
21
|
|
|
* a copy of this software and associated documentation files (the "Software"), |
22
|
|
|
* to deal in the Software without restriction, including without limitation |
23
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
24
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the |
25
|
|
|
* Software is furnished to do so, subject to the following conditions: |
26
|
|
|
* |
27
|
|
|
* The above copyright notice and this permission notice shall be included |
28
|
|
|
* in all copies or substantial portions of the Software. |
29
|
|
|
* |
30
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
31
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
32
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
33
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES |
34
|
|
|
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
35
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
36
|
|
|
* OTHER DEALINGS IN THE SOFTWARE. |
37
|
|
|
* *********************************************************************** |
38
|
|
|
*/ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @internal |
42
|
|
|
*/ |
43
|
|
|
class NistCurve |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* Returns an NIST P-256 curve. |
47
|
|
|
*/ |
48
|
|
|
public static function curve256() : Curve |
49
|
|
|
{ |
50
|
|
|
$p = \gmp_init('ffffffff00000001000000000000000000000000ffffffffffffffffffffffff', 16); |
51
|
|
|
$a = \gmp_init('ffffffff00000001000000000000000000000000fffffffffffffffffffffffc', 16); |
52
|
|
|
$b = \gmp_init('5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b', 16); |
53
|
|
|
$x = \gmp_init('6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296', 16); |
54
|
|
|
$y = \gmp_init('4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5', 16); |
55
|
|
|
$n = \gmp_init('ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', 16); |
56
|
|
|
$generator = Point::create($x, $y, $n); |
|
|
|
|
57
|
|
|
|
58
|
|
|
return new Curve(256, $p, $a, $b, $generator); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|