public static function ParagonIE_Sodium_Core32_Curve25519::fe_tobytes in Automatic Updates 7
Same name and namespace in other branches
- 8 vendor/paragonie/sodium_compat/src/Core32/Curve25519.php \ParagonIE_Sodium_Core32_Curve25519::fe_tobytes()
Convert a field element to a byte string.
@internal You should not use this directly from another application
@psalm-suppress MixedAssignment @psalm-suppress MixedMethodCall
Parameters
ParagonIE_Sodium_Core32_Curve25519_Fe $h:
Return value
string
Throws
SodiumException
TypeError
7 calls to ParagonIE_Sodium_Core32_Curve25519::fe_tobytes()
- ParagonIE_Sodium_Core32_Curve25519::fe_isnegative in vendor/
paragonie/ sodium_compat/ src/ Core32/ Curve25519.php - Is a field element negative? (1 = yes, 0 = no. Used in calculations.)
- ParagonIE_Sodium_Core32_Curve25519::fe_isnonzero in vendor/
paragonie/ sodium_compat/ src/ Core32/ Curve25519.php - Returns 0 if this field element results in all NUL bytes.
- ParagonIE_Sodium_Core32_Curve25519::ge_p3_tobytes in vendor/
paragonie/ sodium_compat/ src/ Core32/ Curve25519.php - @internal You should not use this directly from another application
- ParagonIE_Sodium_Core32_Curve25519::ge_tobytes in vendor/
paragonie/ sodium_compat/ src/ Core32/ Curve25519.php - Convert a group element to a byte string.
- ParagonIE_Sodium_Core32_Ed25519::pk_to_curve25519 in vendor/
paragonie/ sodium_compat/ src/ Core32/ Ed25519.php
File
- vendor/
paragonie/ sodium_compat/ src/ Core32/ Curve25519.php, line 263
Class
- ParagonIE_Sodium_Core32_Curve25519
- Class ParagonIE_Sodium_Core32_Curve25519
Code
public static function fe_tobytes(ParagonIE_Sodium_Core32_Curve25519_Fe $h) {
/**
* @var ParagonIE_Sodium_Core32_Int64[] $f
* @var ParagonIE_Sodium_Core32_Int64 $q
*/
$f = array();
for ($i = 0; $i < 10; ++$i) {
$f[$i] = $h[$i]
->toInt64();
}
$q = $f[9]
->mulInt(19, 5)
->addInt(1 << 14)
->shiftRight(25)
->addInt64($f[0])
->shiftRight(26)
->addInt64($f[1])
->shiftRight(25)
->addInt64($f[2])
->shiftRight(26)
->addInt64($f[3])
->shiftRight(25)
->addInt64($f[4])
->shiftRight(26)
->addInt64($f[5])
->shiftRight(25)
->addInt64($f[6])
->shiftRight(26)
->addInt64($f[7])
->shiftRight(25)
->addInt64($f[8])
->shiftRight(26)
->addInt64($f[9])
->shiftRight(25);
$f[0] = $f[0]
->addInt64($q
->mulInt(19, 5));
$carry0 = $f[0]
->shiftRight(26);
$f[1] = $f[1]
->addInt64($carry0);
$f[0] = $f[0]
->subInt64($carry0
->shiftLeft(26));
$carry1 = $f[1]
->shiftRight(25);
$f[2] = $f[2]
->addInt64($carry1);
$f[1] = $f[1]
->subInt64($carry1
->shiftLeft(25));
$carry2 = $f[2]
->shiftRight(26);
$f[3] = $f[3]
->addInt64($carry2);
$f[2] = $f[2]
->subInt64($carry2
->shiftLeft(26));
$carry3 = $f[3]
->shiftRight(25);
$f[4] = $f[4]
->addInt64($carry3);
$f[3] = $f[3]
->subInt64($carry3
->shiftLeft(25));
$carry4 = $f[4]
->shiftRight(26);
$f[5] = $f[5]
->addInt64($carry4);
$f[4] = $f[4]
->subInt64($carry4
->shiftLeft(26));
$carry5 = $f[5]
->shiftRight(25);
$f[6] = $f[6]
->addInt64($carry5);
$f[5] = $f[5]
->subInt64($carry5
->shiftLeft(25));
$carry6 = $f[6]
->shiftRight(26);
$f[7] = $f[7]
->addInt64($carry6);
$f[6] = $f[6]
->subInt64($carry6
->shiftLeft(26));
$carry7 = $f[7]
->shiftRight(25);
$f[8] = $f[8]
->addInt64($carry7);
$f[7] = $f[7]
->subInt64($carry7
->shiftLeft(25));
$carry8 = $f[8]
->shiftRight(26);
$f[9] = $f[9]
->addInt64($carry8);
$f[8] = $f[8]
->subInt64($carry8
->shiftLeft(26));
$carry9 = $f[9]
->shiftRight(25);
$f[9] = $f[9]
->subInt64($carry9
->shiftLeft(25));
/** @var int $h0 */
$h0 = $f[0]
->toInt32()
->toInt();
/** @var int $h1 */
$h1 = $f[1]
->toInt32()
->toInt();
/** @var int $h2 */
$h2 = $f[2]
->toInt32()
->toInt();
/** @var int $h3 */
$h3 = $f[3]
->toInt32()
->toInt();
/** @var int $h4 */
$h4 = $f[4]
->toInt32()
->toInt();
/** @var int $h5 */
$h5 = $f[5]
->toInt32()
->toInt();
/** @var int $h6 */
$h6 = $f[6]
->toInt32()
->toInt();
/** @var int $h7 */
$h7 = $f[7]
->toInt32()
->toInt();
/** @var int $h8 */
$h8 = $f[8]
->toInt32()
->toInt();
/** @var int $h9 */
$h9 = $f[9]
->toInt32()
->toInt();
/**
* @var array<int, int>
*/
$s = array(
(int) ($h0 >> 0 & 0xff),
(int) ($h0 >> 8 & 0xff),
(int) ($h0 >> 16 & 0xff),
(int) (($h0 >> 24 | $h1 << 2) & 0xff),
(int) ($h1 >> 6 & 0xff),
(int) ($h1 >> 14 & 0xff),
(int) (($h1 >> 22 | $h2 << 3) & 0xff),
(int) ($h2 >> 5 & 0xff),
(int) ($h2 >> 13 & 0xff),
(int) (($h2 >> 21 | $h3 << 5) & 0xff),
(int) ($h3 >> 3 & 0xff),
(int) ($h3 >> 11 & 0xff),
(int) (($h3 >> 19 | $h4 << 6) & 0xff),
(int) ($h4 >> 2 & 0xff),
(int) ($h4 >> 10 & 0xff),
(int) ($h4 >> 18 & 0xff),
(int) ($h5 >> 0 & 0xff),
(int) ($h5 >> 8 & 0xff),
(int) ($h5 >> 16 & 0xff),
(int) (($h5 >> 24 | $h6 << 1) & 0xff),
(int) ($h6 >> 7 & 0xff),
(int) ($h6 >> 15 & 0xff),
(int) (($h6 >> 23 | $h7 << 3) & 0xff),
(int) ($h7 >> 5 & 0xff),
(int) ($h7 >> 13 & 0xff),
(int) (($h7 >> 21 | $h8 << 4) & 0xff),
(int) ($h8 >> 4 & 0xff),
(int) ($h8 >> 12 & 0xff),
(int) (($h8 >> 20 | $h9 << 6) & 0xff),
(int) ($h9 >> 2 & 0xff),
(int) ($h9 >> 10 & 0xff),
(int) ($h9 >> 18 & 0xff),
);
return self::intArrayToString($s);
}