ParagonIE_Sodium_Core32_Ed25519::verify_detached( string $sig, string $message, string $pk ): bool
- Source
wp-includes/sodium_compat/src/Core32/Ed25519.php:280
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_Core32_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
- Scaling
- Scales with input
- Instructions
- 12–102
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 129.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost ParagonIE_Sodium_Core32_Ed25519::verify_detached() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12 | ::strlen() |
::small_order() | 23 | ::strlen(), ::chrToInt(), ::small_order() |
::check_S_lt_L() | 28 | ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L() |
!::small_order() | 31–38 | ::strlen(), ::chrToInt(), ::small_order(), ::chrToInt() |
!::check_S_lt_L() && ::small_order() | 32 | ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L(), ::small_order() |
!::check_S_lt_L() && !::small_order() | 40–47 | ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L(), ::small_order(), ::chrToInt() |
!::small_order() && !$i && $d !== 0 | 93 | ::strlen(), ::chrToInt(), ::small_order(), ::chrToInt(), ::ge_frombytes_negate_vartime(), ::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 | 102 | ::strlen(), ::chrToInt(), ::substr(), ::check_S_lt_L(), ::small_order(), ::chrToInt(), ::ge_frombytes_negate_vartime(), ::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: 129 instructions, 12–102 executed per call, 7 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 · 11
- ParagonIE_Sodium_Core32_Ed25519::strlen()
- SodiumException::__construct()
- ParagonIE_Sodium_Core32_Ed25519::chrToInt()
- ParagonIE_Sodium_Core32_Ed25519::check_S_lt_L()
- ParagonIE_Sodium_Core32_Ed25519::substr()
- ParagonIE_Sodium_Core32_Ed25519::small_order()
- ParagonIE_Sodium_Core32_Ed25519::ge_frombytes_negate_vartime()
- ParagonIE_Sodium_Core32_Ed25519::sc_reduce()
- ParagonIE_Sodium_Core32_Ed25519::ge_double_scalarmult_vartime()
- ParagonIE_Sodium_Core32_Ed25519::ge_tobytes()
- ParagonIE_Sodium_Core32_Ed25519::verify_32()
Used by · 2
- ParagonIE_Sodium_Core32_Ed25519::sign_open()
- ParagonIE_Sodium_Crypto32::sign_verify_detached()Verify a detached signature of a given message and public key.
Source code
public static function verify_detached($sig, $message, $pk) { if (self::strlen($sig) < 64) { throw new SodiumException('Signature is too short'); } 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_Core32_Curve25519_Ge_P3 $A */ $A = self::ge_frombytes_negate_vartime($pk); /** @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_Core32_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.
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/Core32/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.