ParagonIE_Sodium_File::verify_core32( string $sig, string $filePath, string $publicKey ): bool
- Source
wp-includes/sodium_compat/src/File.php:1291
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- Ed25519 signature
$filePathstring- Absolute path to a file on the filesystem
$publicKeystring- Signing public key
Return value
bool
Performance profile
How much work a call to ParagonIE_Sodium_File::verify_core32() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 16–120
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via filesize().
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 151.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- filesystemfilesystem access
filesize()called directly
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost ParagonIE_Sodium_File::verify_core32() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
::ParagonIE_Sodium_Core32_Ed25519() | 16 | ::substr(), ::ParagonIE_Sodium_Core32_Ed25519() |
| always | 20 | ::substr(), ::ParagonIE_Sodium_Core32_Ed25519(), ::ParagonIE_Sodium_Core32_Ed25519() |
!::ParagonIE_Sodium_Core32_Ed25519() | 28–35 | ::substr(), ::ParagonIE_Sodium_Core32_Ed25519(), ::ParagonIE_Sodium_Core32_Ed25519(), ::chrToInt() |
!::ParagonIE_Sodium_Core32_Ed25519() && !$i && $d !== 0 && !is_int($size) | 40 | ::substr(), ::ParagonIE_Sodium_Core32_Ed25519(), ::ParagonIE_Sodium_Core32_Ed25519(), ::chrToInt(), filesize() |
!::ParagonIE_Sodium_Core32_Ed25519() && !$i && $d !== 0 && is_int($size) && !is_resource($fp) | 47 | ::substr(), ::ParagonIE_Sodium_Core32_Ed25519(), ::ParagonIE_Sodium_Core32_Ed25519(), ::chrToInt(), filesize(), fopen() |
!::ParagonIE_Sodium_Core32_Ed25519() && !$i && $d !== 0 && is_int($size) && is_resource($fp) | 120 | ::substr(), ::ParagonIE_Sodium_Core32_Ed25519(), ::ParagonIE_Sodium_Core32_Ed25519(), ::chrToInt(), filesize(), fopen(), ::ParagonIE_Sodium_Core32_Ed25519(), hash_init(), ::substr(), ::hash_update(), ::substr(), ::hash_update(), ::updateHashWithFile(), hash_final(), ::ParagonIE_Sodium_Core32_Ed25519(), ::substr(), ::substr(), ::ParagonIE_Sodium_Core32_Ed25519(), ::ParagonIE_Sodium_Core32_Ed25519(), fclose(), ::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: 151 instructions, 16–120 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 · 12
- ParagonIE_Sodium_Core32_Ed25519::check_S_lt_L()
- ParagonIE_Sodium_File::substr()
- SodiumException::__construct()
- ParagonIE_Sodium_Core32_Ed25519::small_order()
- ParagonIE_Sodium_File::chrToInt()
- ParagonIE_Sodium_Core32_Ed25519::ge_frombytes_negate_vartime()
- ParagonIE_Sodium_File::hash_update()
- ParagonIE_Sodium_File::updateHashWithFile()Update a hash context with the contents of a file, without loading the entire file into memory.
- ParagonIE_Sodium_Core32_Ed25519::sc_reduce()
- ParagonIE_Sodium_Core32_Ed25519::ge_double_scalarmult_vartime()
- ParagonIE_Sodium_Core32_Ed25519::ge_tobytes()
- ParagonIE_Sodium_File::verify_32()
Used by · 1
- ParagonIE_Sodium_File::verify()Verify a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but produces the same result.
Source code
public static function verify_core32($sig, $filePath, $publicKey) { /* Security checks */ if (ParagonIE_Sodium_Core32_Ed25519::check_S_lt_L(self::substr($sig, 32, 32))) { throw new SodiumException('S < L - Invalid signature'); } if (ParagonIE_Sodium_Core32_Ed25519::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($publicKey[$i]); } if ($d === 0) { throw new SodiumException('All zero public key'); } /** @var int|bool $size */ $size = filesize($filePath); if (!is_int($size)) { throw new SodiumException('Could not obtain the file size'); } /** @var int $size */ /** @var resource|bool $fp */ $fp = fopen($filePath, 'rb'); if (!is_resource($fp)) { throw new SodiumException('Could not open input file for reading'); } /** @var resource $fp */ /** @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 = ParagonIE_Sodium_Core32_Ed25519::ge_frombytes_negate_vartime($publicKey); $hs = hash_init('sha512'); self::hash_update($hs, self::substr($sig, 0, 32)); self::hash_update($hs, self::substr($publicKey, 0, 32)); /** @var resource $hs */ $hs = self::updateHashWithFile($hs, $fp, $size); /** @var string $hDigest */ $hDigest = hash_final($hs, true); /** @var string $h */ $h = ParagonIE_Sodium_Core32_Ed25519::sc_reduce($hDigest) . self::substr($hDigest, 32); /** @var ParagonIE_Sodium_Core32_Curve25519_Ge_P2 $R */ $R = ParagonIE_Sodium_Core32_Ed25519::ge_double_scalarmult_vartime( $h, $A, self::substr($sig, 32) ); /** @var string $rcheck */ $rcheck = ParagonIE_Sodium_Core32_Ed25519::ge_tobytes($R); // Close the file handle fclose($fp); // 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/File.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.