You are here

public static function ParagonIE_Sodium_Core_Curve25519::ge_select in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core/Curve25519.php \ParagonIE_Sodium_Core_Curve25519::ge_select()

@internal You should not use this directly from another application

@psalm-suppress MixedArgument @psalm-suppress MixedArrayAccess @psalm-suppress MixedArrayOffset

Parameters

int $pos:

int $b:

Return value

ParagonIE_Sodium_Core_Curve25519_Ge_Precomp

Throws

SodiumException

TypeError

1 call to ParagonIE_Sodium_Core_Curve25519::ge_select()
ParagonIE_Sodium_Core_Curve25519::ge_scalarmult_base in vendor/paragonie/sodium_compat/src/Core/Curve25519.php
@internal You should not use this directly from another application

File

vendor/paragonie/sodium_compat/src/Core/Curve25519.php, line 1704

Class

ParagonIE_Sodium_Core_Curve25519
Class ParagonIE_Sodium_Core_Curve25519

Code

public static function ge_select($pos = 0, $b = 0) {
  static $base = null;
  if ($base === null) {
    $base = array();

    /** @var int $i */
    foreach (self::$base as $i => $bas) {
      for ($j = 0; $j < 8; ++$j) {
        $base[$i][$j] = new ParagonIE_Sodium_Core_Curve25519_Ge_Precomp(ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($bas[$j][0]), ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($bas[$j][1]), ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($bas[$j][2]));
      }
    }
  }

  /** @var array<int, array<int, ParagonIE_Sodium_Core_Curve25519_Ge_Precomp>> $base */
  if (!is_int($pos)) {
    throw new InvalidArgumentException('Position must be an integer');
  }
  if ($pos < 0 || $pos > 31) {
    throw new RangeException('Position is out of range [0, 31]');
  }

  /** @var int $bnegative */
  $bnegative = self::negative($b);

  /** @var int $babs */
  $babs = $b - ((-$bnegative & $b) << 1);
  $t = self::ge_precomp_0();
  for ($i = 0; $i < 8; ++$i) {
    $t = self::cmov($t, $base[$pos][$i], self::equal($babs, $i + 1));
  }
  $minusT = new ParagonIE_Sodium_Core_Curve25519_Ge_Precomp(self::fe_copy($t->yminusx), self::fe_copy($t->yplusx), self::fe_neg($t->xy2d));
  return self::cmov($t, $minusT, $bnegative);
}