You are here

public function ParagonIE_Sodium_Core32_Int64::mulInt64Fast in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core32/Int64.php \ParagonIE_Sodium_Core32_Int64::mulInt64Fast()

Parameters

ParagonIE_Sodium_Core32_Int64 $right:

Return value

ParagonIE_Sodium_Core32_Int64

1 call to ParagonIE_Sodium_Core32_Int64::mulInt64Fast()
ParagonIE_Sodium_Core32_Int64::mulInt64 in vendor/paragonie/sodium_compat/src/Core32/Int64.php
@psalm-suppress MixedAssignment

File

vendor/paragonie/sodium_compat/src/Core32/Int64.php, line 413

Class

ParagonIE_Sodium_Core32_Int64
Class ParagonIE_Sodium_Core32_Int64

Code

public function mulInt64Fast(ParagonIE_Sodium_Core32_Int64 $right) {
  $aNeg = $this->limbs[0] >> 15 & 1;
  $bNeg = $right->limbs[0] >> 15 & 1;
  $a = array_reverse($this->limbs);
  $b = array_reverse($right->limbs);
  if ($aNeg) {
    for ($i = 0; $i < 4; ++$i) {
      $a[$i] = ($a[$i] ^ 0xffff) & 0xffff;
    }
    ++$a[0];
  }
  if ($bNeg) {
    for ($i = 0; $i < 4; ++$i) {
      $b[$i] = ($b[$i] ^ 0xffff) & 0xffff;
    }
    ++$b[0];
  }
  $res = $this
    ->multiplyLong($a, $b);
  if ($aNeg !== $bNeg) {
    if ($aNeg !== $bNeg) {
      for ($i = 0; $i < 4; ++$i) {
        $res[$i] = ($res[$i] ^ 0xffff) & 0xffff;
      }
      $c = 1;
      for ($i = 0; $i < 4; ++$i) {
        $res[$i] += $c;
        $c = $res[$i] >> 16;
        $res[$i] &= 0xffff;
      }
    }
  }
  $return = new ParagonIE_Sodium_Core32_Int64();
  $return->limbs = array(
    $res[3] & 0xffff,
    $res[2] & 0xffff,
    $res[1] & 0xffff,
    $res[0] & 0xffff,
  );
  if (count($res) > 4) {
    $return->overflow = $res[4];
  }
  return $return;
}