ParagonIE_Sodium_File::verify( string $sig, string $filePath, string $publicKey ): bool
- Source
wp-includes/sodium_compat/src/File.php:715
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() 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
- 12–162
- Plugin surface
- None
- Called by
- 0
Reads or writes the filesystem via file_exists().
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 238.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- filesystemfilesystem access
file_exists()called directly
What one call costs · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost ParagonIE_Sodium_File::verify() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12–16 | none |
is_string($sig) && is_string($filePath) && is_string($publicKey) | 19 | ::strlen() |
is_string($sig) && is_string($filePath) && is_string($publicKey) | 25 | ::strlen(), ::strlen() |
is_string($sig) && is_string($filePath) && is_string($publicKey) | 30 | ::strlen(), ::strlen(), ::strlen() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && ::ParagonIE_Sodium_Core_Ed25519() | 41 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && ::ParagonIE_Sodium_Core_Ed25519() | 46 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() | 49–56 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt() |
is_string($sig) && is_string($filePath) && is_string($publicKey) | 50 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() | 58–65 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && !file_exists() | 60 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && file_exists() && !is_int($size) | 65 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && !file_exists() | 69 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists() |
9 further outcomes, up to 162 instructions
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && file_exists() && is_int($size) && !is_resource($fp) | 72 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && file_exists() && !is_int($size) | 74 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !$i && $d !== 0 && file_exists() && is_int($size) && is_resource($fp) | 79 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen(), ::ParagonIE_Sodium_Core_Ed25519() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && file_exists() && is_int($size) && !is_resource($fp) | 81 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && file_exists() && is_int($size) && is_resource($fp) | 87 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !$i && $d !== 0 && file_exists() && is_int($size) && is_resource($fp) | 88 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen(), ::ParagonIE_Sodium_Core_Ed25519() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !::ParagonIE_Sodium_Core_Ed25519() && !$i && $d !== 0 && file_exists() && is_int($size) && is_resource($fp) | 96 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !$i && $d !== 0 && file_exists() && is_int($size) && is_resource($fp) | 153 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), hash_init(), ::substr(), ::hash_update(), ::substr(), ::hash_update(), ::updateHashWithFile(), hash_final(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), fclose(), ::substr(), ::verify_32() |
is_string($sig) && is_string($filePath) && is_string($publicKey) && !$i && $d !== 0 && file_exists() && is_int($size) && is_resource($fp) | 162 | ::strlen(), ::strlen(), ::strlen(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::chrToInt(), file_exists(), filesize(), fopen(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_Ed25519(), hash_init(), ::substr(), ::hash_update(), ::substr(), ::hash_update(), ::updateHashWithFile(), hash_final(), ::ParagonIE_Sodium_Core_Ed25519(), ::substr(), ::substr(), ::ParagonIE_Sodium_Core_Ed25519(), ::ParagonIE_Sodium_Core_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: 238 instructions, 12–162 executed per call, 17 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 · 17
- TypeError::__construct()
- ParagonIE_Sodium_File::strlen()
- SodiumException::__construct()
- ParagonIE_Sodium_File::verify_core32()Verify a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but produces the same result. (32-bit)
- ParagonIE_Sodium_Core_Ed25519::chrToInt()
- ParagonIE_Sodium_Core_Ed25519::check_S_lt_L()
- ParagonIE_Sodium_File::substr()
- ParagonIE_Sodium_Core_Ed25519::small_order()
- ParagonIE_Sodium_File::chrToInt()
- ParagonIE_Sodium_Core_Ed25519::ge_frombytes_negate_vartime()
- ParagonIE_Sodium_Core_Ed25519::is_on_main_subgroup()Returns TRUE if $A represents a point on the order of the Edwards25519 prime order subgroup.
- ParagonIE_Sodium_File::hash_update()
Show all 17
- ParagonIE_Sodium_File::updateHashWithFile()Update a hash context with the contents of a file, without loading the entire file into memory.
- ParagonIE_Sodium_Core_Ed25519::sc_reduce()
- ParagonIE_Sodium_Core_Ed25519::ge_double_scalarmult_vartime()
- ParagonIE_Sodium_Core_Ed25519::ge_tobytes()
- ParagonIE_Sodium_File::verify_32()
Source code
public static function verify( $sig, $filePath, $publicKey ) { /* Type checks: */ if (!is_string($sig)) { throw new TypeError('Argument 1 must be a string, ' . gettype($sig) . ' given.'); } if (!is_string($filePath)) { throw new TypeError('Argument 2 must be a string, ' . gettype($filePath) . ' given.'); } if (!is_string($publicKey)) { throw new TypeError('Argument 3 must be a string, ' . gettype($publicKey) . ' given.'); } /* Input validation: */ if (self::strlen($sig) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_BYTES) { throw new TypeError('Argument 1 must be CRYPTO_SIGN_BYTES bytes'); } if (self::strlen($publicKey) !== ParagonIE_Sodium_Compat::CRYPTO_SIGN_PUBLICKEYBYTES) { throw new TypeError('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES bytes'); } if (self::strlen($sig) < 64) { throw new SodiumException('Signature is too short'); } if (PHP_INT_SIZE === 4) { return self::verify_core32($sig, $filePath, $publicKey); } /* Security checks */ if ( (ParagonIE_Sodium_Core_Ed25519::chrToInt($sig[63]) & 240) && ParagonIE_Sodium_Core_Ed25519::check_S_lt_L(self::substr($sig, 32, 32)) ) { throw new SodiumException('S < L - Invalid signature'); } if (ParagonIE_Sodium_Core_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'); } if (!file_exists($filePath)) { throw new SodiumException('File does not exist'); } /** @var int $size */ $size = filesize($filePath); if (!is_int($size)) { throw new SodiumException('Could not obtain the file size'); } /** @var resource $fp */ $fp = fopen($filePath, 'rb'); if (!is_resource($fp)) { throw new SodiumException('Could not open input file for reading'); } /** @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; if (ParagonIE_Sodium_Core_Ed25519::small_order($publicKey)) { throw new SodiumException('Public key has small order'); } /** @var ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A */ $A = ParagonIE_Sodium_Core_Ed25519::ge_frombytes_negate_vartime($publicKey); if (!ParagonIE_Sodium_Core_Ed25519::is_on_main_subgroup($A)) {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.