Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-inclu.../sodium_c.../src/Core32
File: X25519.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (class_exists('ParagonIE_Sodium_Core32_X25519', false)) {
[2] Fix | Delete
return;
[3] Fix | Delete
}
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Class ParagonIE_Sodium_Core32_X25519
[7] Fix | Delete
*/
[8] Fix | Delete
abstract class ParagonIE_Sodium_Core32_X25519 extends ParagonIE_Sodium_Core32_Curve25519
[9] Fix | Delete
{
[10] Fix | Delete
/**
[11] Fix | Delete
* Alters the objects passed to this method in place.
[12] Fix | Delete
*
[13] Fix | Delete
* @internal You should not use this directly from another application
[14] Fix | Delete
*
[15] Fix | Delete
* @param ParagonIE_Sodium_Core32_Curve25519_Fe $f
[16] Fix | Delete
* @param ParagonIE_Sodium_Core32_Curve25519_Fe $g
[17] Fix | Delete
* @param int $b
[18] Fix | Delete
* @return void
[19] Fix | Delete
* @throws SodiumException
[20] Fix | Delete
* @throws TypeError
[21] Fix | Delete
* @psalm-suppress MixedMethodCall
[22] Fix | Delete
*/
[23] Fix | Delete
public static function fe_cswap(
[24] Fix | Delete
ParagonIE_Sodium_Core32_Curve25519_Fe $f,
[25] Fix | Delete
ParagonIE_Sodium_Core32_Curve25519_Fe $g,
[26] Fix | Delete
$b = 0
[27] Fix | Delete
) {
[28] Fix | Delete
$f0 = (int) $f[0]->toInt();
[29] Fix | Delete
$f1 = (int) $f[1]->toInt();
[30] Fix | Delete
$f2 = (int) $f[2]->toInt();
[31] Fix | Delete
$f3 = (int) $f[3]->toInt();
[32] Fix | Delete
$f4 = (int) $f[4]->toInt();
[33] Fix | Delete
$f5 = (int) $f[5]->toInt();
[34] Fix | Delete
$f6 = (int) $f[6]->toInt();
[35] Fix | Delete
$f7 = (int) $f[7]->toInt();
[36] Fix | Delete
$f8 = (int) $f[8]->toInt();
[37] Fix | Delete
$f9 = (int) $f[9]->toInt();
[38] Fix | Delete
$g0 = (int) $g[0]->toInt();
[39] Fix | Delete
$g1 = (int) $g[1]->toInt();
[40] Fix | Delete
$g2 = (int) $g[2]->toInt();
[41] Fix | Delete
$g3 = (int) $g[3]->toInt();
[42] Fix | Delete
$g4 = (int) $g[4]->toInt();
[43] Fix | Delete
$g5 = (int) $g[5]->toInt();
[44] Fix | Delete
$g6 = (int) $g[6]->toInt();
[45] Fix | Delete
$g7 = (int) $g[7]->toInt();
[46] Fix | Delete
$g8 = (int) $g[8]->toInt();
[47] Fix | Delete
$g9 = (int) $g[9]->toInt();
[48] Fix | Delete
$b = -$b;
[49] Fix | Delete
/** @var int $x0 */
[50] Fix | Delete
$x0 = ($f0 ^ $g0) & $b;
[51] Fix | Delete
/** @var int $x1 */
[52] Fix | Delete
$x1 = ($f1 ^ $g1) & $b;
[53] Fix | Delete
/** @var int $x2 */
[54] Fix | Delete
$x2 = ($f2 ^ $g2) & $b;
[55] Fix | Delete
/** @var int $x3 */
[56] Fix | Delete
$x3 = ($f3 ^ $g3) & $b;
[57] Fix | Delete
/** @var int $x4 */
[58] Fix | Delete
$x4 = ($f4 ^ $g4) & $b;
[59] Fix | Delete
/** @var int $x5 */
[60] Fix | Delete
$x5 = ($f5 ^ $g5) & $b;
[61] Fix | Delete
/** @var int $x6 */
[62] Fix | Delete
$x6 = ($f6 ^ $g6) & $b;
[63] Fix | Delete
/** @var int $x7 */
[64] Fix | Delete
$x7 = ($f7 ^ $g7) & $b;
[65] Fix | Delete
/** @var int $x8 */
[66] Fix | Delete
$x8 = ($f8 ^ $g8) & $b;
[67] Fix | Delete
/** @var int $x9 */
[68] Fix | Delete
$x9 = ($f9 ^ $g9) & $b;
[69] Fix | Delete
$f[0] = ParagonIE_Sodium_Core32_Int32::fromInt($f0 ^ $x0);
[70] Fix | Delete
$f[1] = ParagonIE_Sodium_Core32_Int32::fromInt($f1 ^ $x1);
[71] Fix | Delete
$f[2] = ParagonIE_Sodium_Core32_Int32::fromInt($f2 ^ $x2);
[72] Fix | Delete
$f[3] = ParagonIE_Sodium_Core32_Int32::fromInt($f3 ^ $x3);
[73] Fix | Delete
$f[4] = ParagonIE_Sodium_Core32_Int32::fromInt($f4 ^ $x4);
[74] Fix | Delete
$f[5] = ParagonIE_Sodium_Core32_Int32::fromInt($f5 ^ $x5);
[75] Fix | Delete
$f[6] = ParagonIE_Sodium_Core32_Int32::fromInt($f6 ^ $x6);
[76] Fix | Delete
$f[7] = ParagonIE_Sodium_Core32_Int32::fromInt($f7 ^ $x7);
[77] Fix | Delete
$f[8] = ParagonIE_Sodium_Core32_Int32::fromInt($f8 ^ $x8);
[78] Fix | Delete
$f[9] = ParagonIE_Sodium_Core32_Int32::fromInt($f9 ^ $x9);
[79] Fix | Delete
$g[0] = ParagonIE_Sodium_Core32_Int32::fromInt($g0 ^ $x0);
[80] Fix | Delete
$g[1] = ParagonIE_Sodium_Core32_Int32::fromInt($g1 ^ $x1);
[81] Fix | Delete
$g[2] = ParagonIE_Sodium_Core32_Int32::fromInt($g2 ^ $x2);
[82] Fix | Delete
$g[3] = ParagonIE_Sodium_Core32_Int32::fromInt($g3 ^ $x3);
[83] Fix | Delete
$g[4] = ParagonIE_Sodium_Core32_Int32::fromInt($g4 ^ $x4);
[84] Fix | Delete
$g[5] = ParagonIE_Sodium_Core32_Int32::fromInt($g5 ^ $x5);
[85] Fix | Delete
$g[6] = ParagonIE_Sodium_Core32_Int32::fromInt($g6 ^ $x6);
[86] Fix | Delete
$g[7] = ParagonIE_Sodium_Core32_Int32::fromInt($g7 ^ $x7);
[87] Fix | Delete
$g[8] = ParagonIE_Sodium_Core32_Int32::fromInt($g8 ^ $x8);
[88] Fix | Delete
$g[9] = ParagonIE_Sodium_Core32_Int32::fromInt($g9 ^ $x9);
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* @internal You should not use this directly from another application
[93] Fix | Delete
*
[94] Fix | Delete
* @param ParagonIE_Sodium_Core32_Curve25519_Fe $f
[95] Fix | Delete
* @return ParagonIE_Sodium_Core32_Curve25519_Fe
[96] Fix | Delete
* @throws SodiumException
[97] Fix | Delete
* @throws TypeError
[98] Fix | Delete
* @psalm-suppress MixedAssignment
[99] Fix | Delete
* @psalm-suppress MixedMethodCall
[100] Fix | Delete
*/
[101] Fix | Delete
public static function fe_mul121666(ParagonIE_Sodium_Core32_Curve25519_Fe $f)
[102] Fix | Delete
{
[103] Fix | Delete
/** @var array<int, ParagonIE_Sodium_Core32_Int64> $h */
[104] Fix | Delete
$h = array();
[105] Fix | Delete
for ($i = 0; $i < 10; ++$i) {
[106] Fix | Delete
$h[$i] = $f[$i]->toInt64()->mulInt(121666, 17);
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
$carry9 = $h[9]->addInt(1 << 24)->shiftRight(25);
[110] Fix | Delete
$h[0] = $h[0]->addInt64($carry9->mulInt(19, 5));
[111] Fix | Delete
$h[9] = $h[9]->subInt64($carry9->shiftLeft(25));
[112] Fix | Delete
[113] Fix | Delete
$carry1 = $h[1]->addInt(1 << 24)->shiftRight(25);
[114] Fix | Delete
$h[2] = $h[2]->addInt64($carry1);
[115] Fix | Delete
$h[1] = $h[1]->subInt64($carry1->shiftLeft(25));
[116] Fix | Delete
[117] Fix | Delete
$carry3 = $h[3]->addInt(1 << 24)->shiftRight(25);
[118] Fix | Delete
$h[4] = $h[4]->addInt64($carry3);
[119] Fix | Delete
$h[3] = $h[3]->subInt64($carry3->shiftLeft(25));
[120] Fix | Delete
[121] Fix | Delete
$carry5 = $h[5]->addInt(1 << 24)->shiftRight(25);
[122] Fix | Delete
$h[6] = $h[6]->addInt64($carry5);
[123] Fix | Delete
$h[5] = $h[5]->subInt64($carry5->shiftLeft(25));
[124] Fix | Delete
[125] Fix | Delete
$carry7 = $h[7]->addInt(1 << 24)->shiftRight(25);
[126] Fix | Delete
$h[8] = $h[8]->addInt64($carry7);
[127] Fix | Delete
$h[7] = $h[7]->subInt64($carry7->shiftLeft(25));
[128] Fix | Delete
[129] Fix | Delete
$carry0 = $h[0]->addInt(1 << 25)->shiftRight(26);
[130] Fix | Delete
$h[1] = $h[1]->addInt64($carry0);
[131] Fix | Delete
$h[0] = $h[0]->subInt64($carry0->shiftLeft(26));
[132] Fix | Delete
[133] Fix | Delete
$carry2 = $h[2]->addInt(1 << 25)->shiftRight(26);
[134] Fix | Delete
$h[3] = $h[3]->addInt64($carry2);
[135] Fix | Delete
$h[2] = $h[2]->subInt64($carry2->shiftLeft(26));
[136] Fix | Delete
[137] Fix | Delete
$carry4 = $h[4]->addInt(1 << 25)->shiftRight(26);
[138] Fix | Delete
$h[5] = $h[5]->addInt64($carry4);
[139] Fix | Delete
$h[4] = $h[4]->subInt64($carry4->shiftLeft(26));
[140] Fix | Delete
[141] Fix | Delete
$carry6 = $h[6]->addInt(1 << 25)->shiftRight(26);
[142] Fix | Delete
$h[7] = $h[7]->addInt64($carry6);
[143] Fix | Delete
$h[6] = $h[6]->subInt64($carry6->shiftLeft(26));
[144] Fix | Delete
[145] Fix | Delete
$carry8 = $h[8]->addInt(1 << 25)->shiftRight(26);
[146] Fix | Delete
$h[9] = $h[9]->addInt64($carry8);
[147] Fix | Delete
$h[8] = $h[8]->subInt64($carry8->shiftLeft(26));
[148] Fix | Delete
[149] Fix | Delete
for ($i = 0; $i < 10; ++$i) {
[150] Fix | Delete
$h[$i] = $h[$i]->toInt32();
[151] Fix | Delete
}
[152] Fix | Delete
/** @var array<int, ParagonIE_Sodium_Core32_Int32> $h2 */
[153] Fix | Delete
$h2 = $h;
[154] Fix | Delete
return ParagonIE_Sodium_Core32_Curve25519_Fe::fromArray($h2);
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* @internal You should not use this directly from another application
[159] Fix | Delete
*
[160] Fix | Delete
* Inline comments preceded by # are from libsodium's ref10 code.
[161] Fix | Delete
*
[162] Fix | Delete
* @param string $n
[163] Fix | Delete
* @param string $p
[164] Fix | Delete
* @return string
[165] Fix | Delete
* @throws SodiumException
[166] Fix | Delete
* @throws TypeError
[167] Fix | Delete
*/
[168] Fix | Delete
public static function crypto_scalarmult_curve25519_ref10($n, $p)
[169] Fix | Delete
{
[170] Fix | Delete
# for (i = 0;i < 32;++i) e[i] = n[i];
[171] Fix | Delete
$e = '' . $n;
[172] Fix | Delete
# e[0] &= 248;
[173] Fix | Delete
$e[0] = self::intToChr(
[174] Fix | Delete
self::chrToInt($e[0]) & 248
[175] Fix | Delete
);
[176] Fix | Delete
# e[31] &= 127;
[177] Fix | Delete
# e[31] |= 64;
[178] Fix | Delete
$e[31] = self::intToChr(
[179] Fix | Delete
(self::chrToInt($e[31]) & 127) | 64
[180] Fix | Delete
);
[181] Fix | Delete
# fe_frombytes(x1,p);
[182] Fix | Delete
$x1 = self::fe_frombytes($p);
[183] Fix | Delete
# fe_1(x2);
[184] Fix | Delete
$x2 = self::fe_1();
[185] Fix | Delete
# fe_0(z2);
[186] Fix | Delete
$z2 = self::fe_0();
[187] Fix | Delete
# fe_copy(x3,x1);
[188] Fix | Delete
$x3 = self::fe_copy($x1);
[189] Fix | Delete
# fe_1(z3);
[190] Fix | Delete
$z3 = self::fe_1();
[191] Fix | Delete
[192] Fix | Delete
# swap = 0;
[193] Fix | Delete
/** @var int $swap */
[194] Fix | Delete
$swap = 0;
[195] Fix | Delete
[196] Fix | Delete
# for (pos = 254;pos >= 0;--pos) {
[197] Fix | Delete
for ($pos = 254; $pos >= 0; --$pos) {
[198] Fix | Delete
# b = e[pos / 8] >> (pos & 7);
[199] Fix | Delete
/** @var int $b */
[200] Fix | Delete
$b = self::chrToInt(
[201] Fix | Delete
$e[(int) floor($pos / 8)]
[202] Fix | Delete
) >> ($pos & 7);
[203] Fix | Delete
# b &= 1;
[204] Fix | Delete
$b &= 1;
[205] Fix | Delete
[206] Fix | Delete
# swap ^= b;
[207] Fix | Delete
$swap ^= $b;
[208] Fix | Delete
[209] Fix | Delete
# fe_cswap(x2,x3,swap);
[210] Fix | Delete
self::fe_cswap($x2, $x3, $swap);
[211] Fix | Delete
[212] Fix | Delete
# fe_cswap(z2,z3,swap);
[213] Fix | Delete
self::fe_cswap($z2, $z3, $swap);
[214] Fix | Delete
[215] Fix | Delete
# swap = b;
[216] Fix | Delete
/** @var int $swap */
[217] Fix | Delete
$swap = $b;
[218] Fix | Delete
[219] Fix | Delete
# fe_sub(tmp0,x3,z3);
[220] Fix | Delete
$tmp0 = self::fe_sub($x3, $z3);
[221] Fix | Delete
[222] Fix | Delete
# fe_sub(tmp1,x2,z2);
[223] Fix | Delete
$tmp1 = self::fe_sub($x2, $z2);
[224] Fix | Delete
[225] Fix | Delete
# fe_add(x2,x2,z2);
[226] Fix | Delete
$x2 = self::fe_add($x2, $z2);
[227] Fix | Delete
[228] Fix | Delete
# fe_add(z2,x3,z3);
[229] Fix | Delete
$z2 = self::fe_add($x3, $z3);
[230] Fix | Delete
[231] Fix | Delete
# fe_mul(z3,tmp0,x2);
[232] Fix | Delete
$z3 = self::fe_mul($tmp0, $x2);
[233] Fix | Delete
[234] Fix | Delete
# fe_mul(z2,z2,tmp1);
[235] Fix | Delete
$z2 = self::fe_mul($z2, $tmp1);
[236] Fix | Delete
[237] Fix | Delete
# fe_sq(tmp0,tmp1);
[238] Fix | Delete
$tmp0 = self::fe_sq($tmp1);
[239] Fix | Delete
[240] Fix | Delete
# fe_sq(tmp1,x2);
[241] Fix | Delete
$tmp1 = self::fe_sq($x2);
[242] Fix | Delete
[243] Fix | Delete
# fe_add(x3,z3,z2);
[244] Fix | Delete
$x3 = self::fe_add($z3, $z2);
[245] Fix | Delete
[246] Fix | Delete
# fe_sub(z2,z3,z2);
[247] Fix | Delete
$z2 = self::fe_sub($z3, $z2);
[248] Fix | Delete
[249] Fix | Delete
# fe_mul(x2,tmp1,tmp0);
[250] Fix | Delete
$x2 = self::fe_mul($tmp1, $tmp0);
[251] Fix | Delete
[252] Fix | Delete
# fe_sub(tmp1,tmp1,tmp0);
[253] Fix | Delete
$tmp1 = self::fe_sub($tmp1, $tmp0);
[254] Fix | Delete
[255] Fix | Delete
# fe_sq(z2,z2);
[256] Fix | Delete
$z2 = self::fe_sq($z2);
[257] Fix | Delete
[258] Fix | Delete
# fe_mul121666(z3,tmp1);
[259] Fix | Delete
$z3 = self::fe_mul121666($tmp1);
[260] Fix | Delete
[261] Fix | Delete
# fe_sq(x3,x3);
[262] Fix | Delete
$x3 = self::fe_sq($x3);
[263] Fix | Delete
[264] Fix | Delete
# fe_add(tmp0,tmp0,z3);
[265] Fix | Delete
$tmp0 = self::fe_add($tmp0, $z3);
[266] Fix | Delete
[267] Fix | Delete
# fe_mul(z3,x1,z2);
[268] Fix | Delete
$z3 = self::fe_mul($x1, $z2);
[269] Fix | Delete
[270] Fix | Delete
# fe_mul(z2,tmp1,tmp0);
[271] Fix | Delete
$z2 = self::fe_mul($tmp1, $tmp0);
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
# fe_cswap(x2,x3,swap);
[275] Fix | Delete
self::fe_cswap($x2, $x3, $swap);
[276] Fix | Delete
[277] Fix | Delete
# fe_cswap(z2,z3,swap);
[278] Fix | Delete
self::fe_cswap($z2, $z3, $swap);
[279] Fix | Delete
[280] Fix | Delete
# fe_invert(z2,z2);
[281] Fix | Delete
$z2 = self::fe_invert($z2);
[282] Fix | Delete
[283] Fix | Delete
# fe_mul(x2,x2,z2);
[284] Fix | Delete
$x2 = self::fe_mul($x2, $z2);
[285] Fix | Delete
# fe_tobytes(q,x2);
[286] Fix | Delete
return (string) self::fe_tobytes($x2);
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* @internal You should not use this directly from another application
[291] Fix | Delete
*
[292] Fix | Delete
* @param ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsY
[293] Fix | Delete
* @param ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsZ
[294] Fix | Delete
* @return ParagonIE_Sodium_Core32_Curve25519_Fe
[295] Fix | Delete
* @throws SodiumException
[296] Fix | Delete
* @throws TypeError
[297] Fix | Delete
*/
[298] Fix | Delete
public static function edwards_to_montgomery(
[299] Fix | Delete
ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsY,
[300] Fix | Delete
ParagonIE_Sodium_Core32_Curve25519_Fe $edwardsZ
[301] Fix | Delete
) {
[302] Fix | Delete
$tempX = self::fe_add($edwardsZ, $edwardsY);
[303] Fix | Delete
$tempZ = self::fe_sub($edwardsZ, $edwardsY);
[304] Fix | Delete
$tempZ = self::fe_invert($tempZ);
[305] Fix | Delete
return self::fe_mul($tempX, $tempZ);
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
/**
[309] Fix | Delete
* @internal You should not use this directly from another application
[310] Fix | Delete
*
[311] Fix | Delete
* @param string $n
[312] Fix | Delete
* @return string
[313] Fix | Delete
* @throws SodiumException
[314] Fix | Delete
* @throws TypeError
[315] Fix | Delete
*/
[316] Fix | Delete
public static function crypto_scalarmult_curve25519_ref10_base($n)
[317] Fix | Delete
{
[318] Fix | Delete
# for (i = 0;i < 32;++i) e[i] = n[i];
[319] Fix | Delete
$e = '' . $n;
[320] Fix | Delete
[321] Fix | Delete
# e[0] &= 248;
[322] Fix | Delete
$e[0] = self::intToChr(
[323] Fix | Delete
self::chrToInt($e[0]) & 248
[324] Fix | Delete
);
[325] Fix | Delete
[326] Fix | Delete
# e[31] &= 127;
[327] Fix | Delete
# e[31] |= 64;
[328] Fix | Delete
$e[31] = self::intToChr(
[329] Fix | Delete
(self::chrToInt($e[31]) & 127) | 64
[330] Fix | Delete
);
[331] Fix | Delete
[332] Fix | Delete
$A = self::ge_scalarmult_base($e);
[333] Fix | Delete
if (
[334] Fix | Delete
!($A->Y instanceof ParagonIE_Sodium_Core32_Curve25519_Fe)
[335] Fix | Delete
||
[336] Fix | Delete
!($A->Z instanceof ParagonIE_Sodium_Core32_Curve25519_Fe)
[337] Fix | Delete
) {
[338] Fix | Delete
throw new TypeError('Null points encountered');
[339] Fix | Delete
}
[340] Fix | Delete
$pk = self::edwards_to_montgomery($A->Y, $A->Z);
[341] Fix | Delete
return self::fe_tobytes($pk);
[342] Fix | Delete
}
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function