wppaste
WordPress

ParagonIE_Sodium_Core_AEGIS128L

Source
wp-includes/sodium_compat/src/Core/AEGIS128L.php:10

Compatibility

WordPress
core
  • 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).

Methods · 3

Source code

class ParagonIE_Sodium_Core_AEGIS128L extends ParagonIE_Sodium_Core_AES{    /**     * @param string $ct     * @param string $tag     * @param string $ad     * @param string $key     * @param string $nonce     * @return string     * @throws SodiumException     */    public static function decrypt($ct, $tag, $ad, $key, $nonce)    {        $state = self::init($key, $nonce);        $ad_blocks = (self::strlen($ad) + 31) >> 5;        for ($i = 0; $i < $ad_blocks; ++$i) {            $ai = self::substr($ad, $i << 5, 32);            if (self::strlen($ai) < 32) {                $ai = str_pad($ai, 32, "\0", STR_PAD_RIGHT);            }            $state->absorb($ai);        }         $msg = '';        $cn = self::strlen($ct) & 31;        $ct_blocks = self::strlen($ct) >> 5;        for ($i = 0; $i < $ct_blocks; ++$i) {            $msg .= $state->dec(self::substr($ct, $i << 5, 32));        }        if ($cn) {            $start = $ct_blocks << 5;            $msg .= $state->decPartial(self::substr($ct, $start, $cn));        }        $expected_tag = $state->finalize(            self::strlen($ad) << 3,            self::strlen($msg) << 3        );        if (!self::hashEquals($expected_tag, $tag)) {            try {                // The RFC says to erase msg, so we shall try:                ParagonIE_Sodium_Compat::memzero($msg);            } catch (SodiumException $ex) {                // Do nothing if we cannot memzero            }            throw new SodiumException('verification failed');        }        return $msg;    }     /**     * @param string $msg     * @param string $ad     * @param string $key     * @param string $nonce     * @return array     *     * @throws SodiumException     */    public static function encrypt($msg, $ad, $key, $nonce)    {        $state = self::init($key, $nonce);        // ad_blocks = Split(ZeroPad(ad, 256), 256)        // for ai in ad_blocks:        //     Absorb(ai)        $ad_len = self::strlen($ad);        $msg_len = self::strlen($msg);        $ad_blocks = ($ad_len + 31) >> 5;        for ($i = 0; $i < $ad_blocks; ++$i) {            $ai = self::substr($ad, $i << 5, 32);            if (self::strlen($ai) < 32) {                $ai = str_pad($ai, 32, "\0", STR_PAD_RIGHT);            }            $state->absorb($ai);        }         // msg_blocks = Split(ZeroPad(msg, 256), 256)        // for xi in msg_blocks:        //     ct = ct || Enc(xi)        $ct = '';        $msg_blocks = ($msg_len + 31) >> 5;

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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/Core/AEGIS128L.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.