You are here

protected static function ParagonIE_Sodium_Crypto::scalarmult_throw_if_zero in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Crypto.php \ParagonIE_Sodium_Crypto::scalarmult_throw_if_zero()

This throws an Error if a zero public key was passed to the function.

Parameters

string $q:

Return value

void

Throws

SodiumException

TypeError

2 calls to ParagonIE_Sodium_Crypto::scalarmult_throw_if_zero()
ParagonIE_Sodium_Crypto::scalarmult in vendor/paragonie/sodium_compat/src/Crypto.php
ECDH over Curve25519
ParagonIE_Sodium_Crypto::scalarmult_base in vendor/paragonie/sodium_compat/src/Crypto.php
ECDH over Curve25519, using the basepoint. Used to get a secret key from a public key.

File

vendor/paragonie/sodium_compat/src/Crypto.php, line 920

Class

ParagonIE_Sodium_Crypto
Class ParagonIE_Sodium_Crypto

Code

protected static function scalarmult_throw_if_zero($q) {
  $d = 0;
  for ($i = 0; $i < self::box_curve25519xsalsa20poly1305_SECRETKEYBYTES; ++$i) {
    $d |= ParagonIE_Sodium_Core_Util::chrToInt($q[$i]);
  }

  /* branch-free variant of === 0 */
  if (-(1 & $d - 1 >> 8)) {
    throw new SodiumException('Zero public key is not allowed');
  }
}