ParagonIE_Sodium_Crypto32::aead_chacha20poly1305_decrypt( string $message = '', string $ad = '', string $nonce = '', string $key = '' ): string
- Source
wp-includes/sodium_compat/src/Crypto32.php:71
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
$messagestringoptional- Default:
'' $adstringoptional- Default:
'' $noncestringoptional- Default:
'' $keystringoptional- Default:
''
Return value
string
Performance profile
How much work a call to ParagonIE_Sodium_Crypto32::aead_chacha20poly1305_decrypt() 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
- Constant
- Instructions
- 72–78
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->update().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 84.
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
- sqldatabase query
->update()called directly
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost ParagonIE_Sodium_Crypto32::aead_chacha20poly1305_decrypt() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!::ParagonIE_Sodium_Core32_Util() | 72 | ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ::ParagonIE_Sodium_Compat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ->finish(), ::ParagonIE_Sodium_Core32_Util() |
::ParagonIE_Sodium_Core32_Util() | 78 | ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ::ParagonIE_Sodium_Compat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ->finish(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 84 instructions, 72–78 executed per call, 1 branch. 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 · 9
- ParagonIE_Sodium_Core32_Util::strlen()
- ParagonIE_Sodium_Core32_Util::substr()
- ParagonIE_Sodium_Core32_ChaCha20::stream()
- ParagonIE_Sodium_Core32_Poly1305_State::__construct()ParagonIE_Sodium_Core32_Poly1305_State constructor.
- ParagonIE_Sodium_Compat::memzero()It's actually not possible to zero memory buffers in PHP. You need the native library for that.
- ParagonIE_Sodium_Core32_Util::store64_le()
- ParagonIE_Sodium_Core32_Util::verify_16()
- SodiumException::__construct()
- ParagonIE_Sodium_Core32_ChaCha20::streamXorIc()
Used by · 1
- ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt()Authenticated Encryption with Associated Data: Decryption
Source code
public static function aead_chacha20poly1305_decrypt( $message = '', $ad = '', $nonce = '', $key = '' ) { /** @var int $len - Length of message (ciphertext + MAC) */ $len = ParagonIE_Sodium_Core32_Util::strlen($message); /** @var int $clen - Length of ciphertext */ $clen = $len - self::aead_chacha20poly1305_ABYTES; /** @var int $adlen - Length of associated data */ $adlen = ParagonIE_Sodium_Core32_Util::strlen($ad); /** @var string $mac - Message authentication code */ $mac = ParagonIE_Sodium_Core32_Util::substr( $message, $clen, self::aead_chacha20poly1305_ABYTES ); /** @var string $ciphertext - The encrypted message (sans MAC) */ $ciphertext = ParagonIE_Sodium_Core32_Util::substr($message, 0, $clen); /** @var string The first block of the chacha20 keystream, used as a poly1305 key */ $block0 = ParagonIE_Sodium_Core32_ChaCha20::stream( 32, $nonce, $key ); /* Recalculate the Poly1305 authentication tag (MAC): */ $state = new ParagonIE_Sodium_Core32_Poly1305_State($block0); try { ParagonIE_Sodium_Compat::memzero($block0); } catch (SodiumException $ex) { $block0 = null; } $state->update($ad); $state->update(ParagonIE_Sodium_Core32_Util::store64_le($adlen)); $state->update($ciphertext); $state->update(ParagonIE_Sodium_Core32_Util::store64_le($clen)); $computed_mac = $state->finish(); /* Compare the given MAC with the recalculated MAC: */ if (!ParagonIE_Sodium_Core32_Util::verify_16($computed_mac, $mac)) { throw new SodiumException('Invalid MAC'); } // Here, we know that the MAC is valid, so we decrypt and return the plaintext return ParagonIE_Sodium_Core32_ChaCha20::streamXorIc( $ciphertext, $nonce, $key, ParagonIE_Sodium_Core32_Util::store64_le(1) ); }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/Crypto32.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.