You are here

protected static function ParagonIE_Sodium_Crypto32::scalarmult_throw_if_zero in Automatic Updates 7

Same name and namespace in other branches
  1. 8 vendor/paragonie/sodium_compat/src/Crypto32.php \ParagonIE_Sodium_Crypto32::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_Crypto32::scalarmult_throw_if_zero()
ParagonIE_Sodium_Crypto32::scalarmult in vendor/paragonie/sodium_compat/src/Crypto32.php
ECDH over Curve25519
ParagonIE_Sodium_Crypto32::scalarmult_base in vendor/paragonie/sodium_compat/src/Crypto32.php
ECDH over Curve25519, using the basepoint. Used to get a secret key from a public key.

File

vendor/paragonie/sodium_compat/src/Crypto32.php, line 919

Class

ParagonIE_Sodium_Crypto32
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_Core32_Util::chrToInt($q[$i]);
  }

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