You are here

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

Constant-time conditional move.

@internal You should not use this directly from another application

@psalm-suppress MixedAssignment

Parameters

ParagonIE_Sodium_Core_Curve25519_Fe $f:

ParagonIE_Sodium_Core_Curve25519_Fe $g:

int $b:

Return value

ParagonIE_Sodium_Core_Curve25519_Fe

1 call to ParagonIE_Sodium_Core_Curve25519::fe_cmov()
ParagonIE_Sodium_Core_Curve25519::cmov in vendor/paragonie/sodium_compat/src/Core/Curve25519.php
Conditional move

File

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

Class

ParagonIE_Sodium_Core_Curve25519
Class ParagonIE_Sodium_Core_Curve25519

Code

public static function fe_cmov(ParagonIE_Sodium_Core_Curve25519_Fe $f, ParagonIE_Sodium_Core_Curve25519_Fe $g, $b = 0) {

  /** @var array<int, int> $h */
  $h = array();
  $b *= -1;
  for ($i = 0; $i < 10; ++$i) {

    /** @var int $x */
    $x = ($f[$i] ^ $g[$i]) & $b;
    $h[$i] = (int) ((int) $f[$i] ^ $x);
  }
  return ParagonIE_Sodium_Core_Curve25519_Fe::fromArray($h);
}