wppaste
WordPress

ParagonIE_Sodium_Core_Ed25519::verify_detached( string $sig, string $message, string $pk ): bool

Source
wp-includes/sodium_compat/src/Core/Ed25519.php:296

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$sigstring
$messagestring
$pkstring

Return value

bool

Performance profile

How much work a call to ParagonIE_Sodium_Core_Ed25519::verify_detached() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
12–111

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 146.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 11 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost ParagonIE_Sodium_Core_Ed25519::verify_detached() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always12::strlen()
always17::strlen(), ::strlen()
::small_order()28::strlen(), ::strlen(), ::chrToInt(), ::small_order()
::check_S_lt_L()33::strlen(), ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L()
!::small_order()36–43::strlen(), ::strlen(), ::chrToInt(), ::small_order(), ::chrToInt()
!::check_S_lt_L() && ::small_order()37::strlen(), ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L(), ::small_order()
!::check_S_lt_L() && !::small_order()45–52::strlen(), ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L(), ::small_order(), ::chrToInt()
!::small_order() && !$i && $d !== 0 && !::is_on_main_subgroup()54::strlen(), ::strlen(), ::chrToInt(), ::small_order(), ::chrToInt(), ::ge_frombytes_negate_vartime(), ::is_on_main_subgroup()
!::check_S_lt_L() && !::small_order() && !$i && $d !== 0 && !::is_on_main_subgroup()63::strlen(), ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L(), ::small_order(), ::chrToInt(), ::ge_frombytes_negate_vartime(), ::is_on_main_subgroup()
!::small_order() && !$i && $d !== 0 && ::is_on_main_subgroup()102::strlen(), ::strlen(), ::chrToInt(), ::small_order(), ::chrToInt(), ::ge_frombytes_negate_vartime(), ::is_on_main_subgroup(), ::substr(), ::substr(), hash(), ::sc_reduce(), ::substr(), ::substr(), ::ge_double_scalarmult_vartime(), ::ge_tobytes(), ::substr(), ::verify_32()
!::check_S_lt_L() && !::small_order() && !$i && $d !== 0 && ::is_on_main_subgroup()111::strlen(), ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L(), ::small_order(), ::chrToInt(), ::ge_frombytes_negate_vartime(), ::is_on_main_subgroup(), ::substr(), ::substr(), hash(), ::sc_reduce(), ::substr(), ::substr(), ::ge_double_scalarmult_vartime(), ::ge_tobytes(), ::substr(), ::verify_32()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 146 instructions, 12–111 executed per call, 9 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 12

Used by · 2

Source code

    public static function verify_detached($sig, $message, $pk)    {        if (self::strlen($sig) !== 64) {            throw new SodiumException('Argument 1 must be CRYPTO_SIGN_BYTES long');        }        if (self::strlen($pk) !== 32) {            throw new SodiumException('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES long');        }        if ((self::chrToInt($sig[63]) & 240) && self::check_S_lt_L(self::substr($sig, 32, 32))) {            throw new SodiumException('S >= L - Invalid signature');        }        if (self::small_order($sig)) {            throw new SodiumException('Signature is on too small of an order');        }        if ((self::chrToInt($sig[63]) & 224) !== 0) {            throw new SodiumException('Invalid signature');        }        $d = 0;        for ($i = 0; $i < 32; ++$i) {            $d |= self::chrToInt($pk[$i]);        }        if ($d === 0) {            throw new SodiumException('All zero public key');        }         /** @var bool The original value of ParagonIE_Sodium_Compat::$fastMult */        $orig = ParagonIE_Sodium_Compat::$fastMult;         // Set ParagonIE_Sodium_Compat::$fastMult to true to speed up verification.        ParagonIE_Sodium_Compat::$fastMult = true;         /** @var ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A */        $A = self::ge_frombytes_negate_vartime($pk);        if (!self::is_on_main_subgroup($A)) {            throw new SodiumException('Public key is not on a member of the main subgroup');        }         /** @var string $hDigest */        $hDigest = hash(            'sha512',            self::substr($sig, 0, 32) .                self::substr($pk, 0, 32) .                $message,            true        );         /** @var string $h */        $h = self::sc_reduce($hDigest) . self::substr($hDigest, 32);         /** @var ParagonIE_Sodium_Core_Curve25519_Ge_P2 $R */        $R = self::ge_double_scalarmult_vartime(            $h,            $A,            self::substr($sig, 32)        );         /** @var string $rcheck */        $rcheck = self::ge_tobytes($R);         // Reset ParagonIE_Sodium_Compat::$fastMult to what it was before.        ParagonIE_Sodium_Compat::$fastMult = $orig;         return self::verify_32($rcheck, self::substr($sig, 0, 32));    }

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/sodium_compat/src/Core/Ed25519.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.