You are here

public static function ParagonIE_Sodium_Core_Curve25519::slide 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::slide()

@internal You should not use this directly from another application

@ref https://github.com/jedisct1/libsodium/blob/157c4a80c13b117608aeae12178b2...

Parameters

string $a:

Return value

array<int, mixed>

Throws

SodiumException

TypeError

1 call to ParagonIE_Sodium_Core_Curve25519::slide()
ParagonIE_Sodium_Core_Curve25519::ge_double_scalarmult_vartime 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 1282

Class

ParagonIE_Sodium_Core_Curve25519
Class ParagonIE_Sodium_Core_Curve25519

Code

public static function slide($a) {
  if (self::strlen($a) < 256) {
    if (self::strlen($a) < 16) {
      $a = str_pad($a, 256, '0', STR_PAD_RIGHT);
    }
  }

  /** @var array<int, int> $r */
  $r = array();

  /** @var int $i */
  for ($i = 0; $i < 256; ++$i) {
    $r[$i] = (int) (1 & self::chrToInt($a[(int) ($i >> 3)]) >> ($i & 7));
  }
  for ($i = 0; $i < 256; ++$i) {
    if ($r[$i]) {
      for ($b = 1; $b <= 6 && $i + $b < 256; ++$b) {
        if ($r[$i + $b]) {
          if ($r[$i] + ($r[$i + $b] << $b) <= 15) {
            $r[$i] += $r[$i + $b] << $b;
            $r[$i + $b] = 0;
          }
          elseif ($r[$i] - ($r[$i + $b] << $b) >= -15) {
            $r[$i] -= $r[$i + $b] << $b;
            for ($k = $i + $b; $k < 256; ++$k) {
              if (!$r[$k]) {
                $r[$k] = 1;
                break;
              }
              $r[$k] = 0;
            }
          }
          else {
            break;
          }
        }
      }
    }
  }
  return $r;
}