ParagonIE_Sodium_Crypto32::secretstream_xchacha20poly1305_push( string $state, string $msg, string $aad = '', int $tag = 0 ): string
- Source
wp-includes/sodium_compat/src/Crypto32.php:1297
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
$statestring$msgstring$aadstringoptional- Default:
'' $tagintoptional- Default:
0
Return value
string
Performance profile
How much work a call to ParagonIE_Sodium_Crypto32::secretstream_xchacha20poly1305_push() 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
- 24–134
- 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 138.
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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost ParagonIE_Sodium_Crypto32::secretstream_xchacha20poly1305_push() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 24 | ::ParagonIE_Sodium_Core32_SecretStream_State(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util() |
| always | 131 | ::ParagonIE_Sodium_Core32_SecretStream_State(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), str_repeat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), str_repeat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ->finish(), ->xorNonce(), ->incrementCounter(), ->toString(), ::secretstream_xchacha20poly1305_rekey() |
!->needsRekey() | 131 | ::ParagonIE_Sodium_Core32_SecretStream_State(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), str_repeat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), str_repeat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ->finish(), ->xorNonce(), ->incrementCounter(), ->toString(), ->needsRekey() |
->needsRekey() | 134 | ::ParagonIE_Sodium_Core32_SecretStream_State(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_Util(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), str_repeat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), ->getCombinedNonce(), ->getKey(), ::ParagonIE_Sodium_Core32_Util(), ::ParagonIE_Sodium_Core32_ChaCha20(), ->update(), str_repeat(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ::ParagonIE_Sodium_Core32_Util(), ->update(), ->finish(), ->xorNonce(), ->incrementCounter(), ->toString(), ->needsRekey(), ::secretstream_xchacha20poly1305_rekey() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 138 instructions, 24–134 executed per call, 3 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 · 9
- ParagonIE_Sodium_Core32_SecretStream_State::fromString()
- ParagonIE_Sodium_Core32_Util::strlen()
- SodiumException::__construct()
- ParagonIE_Sodium_Core32_Poly1305_State::__construct()ParagonIE_Sodium_Core32_Poly1305_State constructor.
- ParagonIE_Sodium_Core32_ChaCha20::ietfStream()
- ParagonIE_Sodium_Core32_ChaCha20::ietfStreamXorIc()
- ParagonIE_Sodium_Core32_Util::intToChr()
- ParagonIE_Sodium_Core32_Util::store64_le()
- ParagonIE_Sodium_Crypto32::secretstream_xchacha20poly1305_rekey()
Used by · 1
Source code
public static function secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) { $st = ParagonIE_Sodium_Core32_SecretStream_State::fromString($state); # crypto_onetimeauth_poly1305_state poly1305_state; # unsigned char block[64U]; # unsigned char slen[8U]; # unsigned char *c; # unsigned char *mac; $msglen = ParagonIE_Sodium_Core32_Util::strlen($msg); $aadlen = ParagonIE_Sodium_Core32_Util::strlen($aad); if ((($msglen + 63) >> 6) > 0xfffffffe) { throw new SodiumException( 'message cannot be larger than SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX bytes' ); } # if (outlen_p != NULL) { # *outlen_p = 0U; # } # if (mlen > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX) { # sodium_misuse(); # } # crypto_stream_chacha20_ietf(block, sizeof block, state->nonce, state->k); # crypto_onetimeauth_poly1305_init(&poly1305_state, block); # sodium_memzero(block, sizeof block); $auth = new ParagonIE_Sodium_Core32_Poly1305_State( ParagonIE_Sodium_Core32_ChaCha20::ietfStream(32, $st->getCombinedNonce(), $st->getKey()) ); # crypto_onetimeauth_poly1305_update(&poly1305_state, ad, adlen); $auth->update($aad); # crypto_onetimeauth_poly1305_update(&poly1305_state, _pad0, # (0x10 - adlen) & 0xf); $auth->update(str_repeat("\0", ((0x10 - $aadlen) & 0xf))); # memset(block, 0, sizeof block); # block[0] = tag; # crypto_stream_chacha20_ietf_xor_ic(block, block, sizeof block, # state->nonce, 1U, state->k); $block = ParagonIE_Sodium_Core32_ChaCha20::ietfStreamXorIc( ParagonIE_Sodium_Core32_Util::intToChr($tag) . str_repeat("\0", 63), $st->getCombinedNonce(), $st->getKey(), ParagonIE_Sodium_Core32_Util::store64_le(1) ); # crypto_onetimeauth_poly1305_update(&poly1305_state, block, sizeof block); $auth->update($block); # out[0] = block[0]; $out = $block[0]; # c = out + (sizeof tag); # crypto_stream_chacha20_ietf_xor_ic(c, m, mlen, state->nonce, 2U, state->k); $cipher = ParagonIE_Sodium_Core32_ChaCha20::ietfStreamXorIc( $msg, $st->getCombinedNonce(), $st->getKey(), ParagonIE_Sodium_Core32_Util::store64_le(2) ); # crypto_onetimeauth_poly1305_update(&poly1305_state, c, mlen); $auth->update($cipher); $out .= $cipher; unset($cipher); # crypto_onetimeauth_poly1305_update # (&poly1305_state, _pad0, (0x10 - (sizeof block) + mlen) & 0xf); $auth->update(str_repeat("\0", ((0x10 - 64 + $msglen) & 0xf))); # STORE64_LE(slen, (uint64_t) adlen); $slen = ParagonIE_Sodium_Core32_Util::store64_le($aadlen); # crypto_onetimeauth_poly1305_update(&poly1305_state, slen, sizeof slen); $auth->update($slen);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.