Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/vendor/web-token/jwt-util-ecc/Point.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
declare(strict_types=1);
4
+
5
+
/*
6
+
* The MIT License (MIT)
7
+
*
8
+
* Copyright (c) 2014-2020 Spomky-Labs
9
+
*
10
+
* This software may be modified and distributed under the terms
11
+
* of the MIT license. See the LICENSE file for details.
12
+
*/
13
+
14
+
namespace Jose\Component\Core\Util\Ecc;
15
+
16
+
use Brick\Math\BigInteger;
17
+
18
+
/**
19
+
* *********************************************************************
20
+
* Copyright (C) 2012 Matyas Danter.
21
+
*
22
+
* Permission is hereby granted, free of charge, to any person obtaining
23
+
* a copy of this software and associated documentation files (the "Software"),
24
+
* to deal in the Software without restriction, including without limitation
25
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
26
+
* and/or sell copies of the Software, and to permit persons to whom the
27
+
* Software is furnished to do so, subject to the following conditions:
28
+
*
29
+
* The above copyright notice and this permission notice shall be included
30
+
* in all copies or substantial portions of the Software.
31
+
*
32
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
33
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
35
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
36
+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
37
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
38
+
* OTHER DEALINGS IN THE SOFTWARE.
39
+
* ***********************************************************************
40
+
*/
41
+
42
+
/**
43
+
* @internal
44
+
*/
45
+
class Point
46
+
{
47
+
/**
48
+
* @var BigInteger
49
+
*/
50
+
private $x;
51
+
52
+
/**
53
+
* @var BigInteger
54
+
*/
55
+
private $y;
56
+
57
+
/**
58
+
* @var BigInteger
59
+
*/
60
+
private $order;
61
+
62
+
/**
63
+
* @var bool
64
+
*/
65
+
private $infinity = false;
66
+
67
+
private function __construct(BigInteger $x, BigInteger $y, BigInteger $order, bool $infinity = false)
68
+
{
69
+
$this->x = $x;
70
+
$this->y = $y;
71
+
$this->order = $order;
72
+
$this->infinity = $infinity;
73
+
}
74
+
75
+
public static function create(BigInteger $x, BigInteger $y, ?BigInteger $order = null): self
76
+
{
77
+
return new self($x, $y, $order ?? BigInteger::zero());
78
+
}
79
+
80
+
public static function infinity(): self
81
+
{
82
+
$zero = BigInteger::zero();
83
+
84
+
return new self($zero, $zero, $zero, true);
85
+
}
86
+
87
+
public function isInfinity(): bool
88
+
{
89
+
return $this->infinity;
90
+
}
91
+
92
+
public function getOrder(): BigInteger
93
+
{
94
+
return $this->order;
95
+
}
96
+
97
+
public function getX(): BigInteger
98
+
{
99
+
return $this->x;
100
+
}
101
+
102
+
public function getY(): BigInteger
103
+
{
104
+
return $this->y;
105
+
}
106
+
107
+
public static function cswap(self $a, self $b, int $cond): void
108
+
{
109
+
self::cswapBigInteger($a->x, $b->x, $cond);
110
+
self::cswapBigInteger($a->y, $b->y, $cond);
111
+
self::cswapBigInteger($a->order, $b->order, $cond);
112
+
self::cswapBoolean($a->infinity, $b->infinity, $cond);
113
+
}
114
+
115
+
private static function cswapBoolean(bool &$a, bool &$b, int $cond): void
116
+
{
117
+
$sa = BigInteger::of((int) $a);
118
+
$sb = BigInteger::of((int) $b);
119
+
120
+
self::cswapBigInteger($sa, $sb, $cond);
121
+
122
+
$a = (bool) $sa->toBase(10);
123
+
$b = (bool) $sb->toBase(10);
124
+
}
125
+
126
+
private static function cswapBigInteger(BigInteger &$sa, BigInteger &$sb, int $cond): void
127
+
{
128
+
$size = max(mb_strlen($sa->toBase(2), '8bit'), mb_strlen($sb->toBase(2), '8bit'));
129
+
$mask = (string) (1 - $cond);
130
+
$mask = str_pad('', $size, $mask, STR_PAD_LEFT);
131
+
$mask = BigInteger::fromBase($mask, 2);
132
+
$taA = $sa->and($mask);
133
+
$taB = $sb->and($mask);
134
+
$sa = $sa->xor($sb)->xor($taB);
135
+
$sb = $sa->xor($sb)->xor($taA);
136
+
$sa = $sa->xor($sb)->xor($taB);
137
+
}
138
+
}
139
+