ParagonIE_Sodium_Core32_Poly1305_State::blocks() –

You appear to be a bot. Output may be restricted

Description

Usage

$self = ParagonIE_Sodium_Core32_Poly1305_State::blocks( $message, $bytes );

Parameters

$message
( string ) required
$bytes
( int ) required

Returns

self

Source

File name: wordpress/wp-includes/sodium_compat/src/Core32/Poly1305/State.php
Lines:

1 to 100 of 143
    public function blocks($message, $bytes)
    {
        if (self::strlen($message) < 16) {
            $message = str_pad($message, 16, "\x00", STR_PAD_RIGHT);
        }
        $hibit = ParagonIE_Sodium_Core32_Int32::ParagonIE_Sodium_Core32_Int32::fromInt((int) ($this->final ? 0 : 1 << 24)); /* 1 << 128 */
        $hibit->setUnsignedInt(true);
        $zero = new ParagonIE_Sodium_Core32_Int64(array(0, 0, 0, 0), true);
        
/**
         * @var ParagonIE_Sodium_Core32_Int64 $d0
         * @var ParagonIE_Sodium_Core32_Int64 $d1
         * @var ParagonIE_Sodium_Core32_Int64 $d2
         * @var ParagonIE_Sodium_Core32_Int64 $d3
         * @var ParagonIE_Sodium_Core32_Int64 $d4
         * @var ParagonIE_Sodium_Core32_Int64 $r0
         * @var ParagonIE_Sodium_Core32_Int64 $r1
         * @var ParagonIE_Sodium_Core32_Int64 $r2
         * @var ParagonIE_Sodium_Core32_Int64 $r3
         * @var ParagonIE_Sodium_Core32_Int64 $r4
         *
         * @var ParagonIE_Sodium_Core32_Int32 $h0
         * @var ParagonIE_Sodium_Core32_Int32 $h1
         * @var ParagonIE_Sodium_Core32_Int32 $h2
         * @var ParagonIE_Sodium_Core32_Int32 $h3
         * @var ParagonIE_Sodium_Core32_Int32 $h4
         */
        $r0 = $this->r[0]->toInt64();
        $r1 = $this->r[1]->toInt64();
        $r2 = $this->r[2]->toInt64();
        $r3 = $this->r[3]->toInt64();
        $r4 = $this->r[4]->toInt64();

        $s1 = $r1->toInt64()->mulInt(5, 3);
        $s2 = $r2->toInt64()->mulInt(5, 3);
        $s3 = $r3->toInt64()->mulInt(5, 3);
        $s4 = $r4->toInt64()->mulInt(5, 3);

        $h0 = $this->h[0];
        $h1 = $this->h[1];
        $h2 = $this->h[2];
        $h3 = $this->h[3];
        $h4 = $this->h[4];

        while ($bytes >= ParagonIE_Sodium_Core32_Poly1305::BLOCK_SIZE) {
            /* h += m[i] */
            $h0 = $h0->addInt32(
                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 0, 4))
                    ->mask(0x3ffffff)
            )->toInt64();
            $h1 = $h1->addInt32(
                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 3, 4))
                    ->shiftRight(2)
                    ->mask(0x3ffffff)
            )->toInt64();
            $h2 = $h2->addInt32(
                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 6, 4))
                    ->shiftRight(4)
                    ->mask(0x3ffffff)
            )->toInt64();
            $h3 = $h3->addInt32(
                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 9, 4))
                    ->shiftRight(6)
                    ->mask(0x3ffffff)
            )->toInt64();
            $h4 = $h4->addInt32(
                ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($message, 12, 4))
                    ->shiftRight(8)
                    ->orInt32($hibit)
            )->toInt64();

            /* h *= r */
            $d0 = $zero
                ->addInt64($h0->mulInt64($r0, 25))
                ->addInt64($s4->mulInt64($h1, 26))
                ->addInt64($s3->mulInt64($h2, 26))
                ->addInt64($s2->mulInt64($h3, 26))
                ->addInt64($s1->mulInt64($h4, 26));

            $d1 = $zero
                ->addInt64($h0->mulInt64($r1, 25))
                ->addInt64($h1->mulInt64($r0, 25))
                ->addInt64($s4->mulInt64($h2, 26))
                ->addInt64($s3->mulInt64($h3, 26))
                ->addInt64($s2->mulInt64($h4, 26));

            $d2 = $zero
                ->addInt64($h0->mulInt64($r2, 25))
                ->addInt64($h1->mulInt64($r1, 25))
                ->addInt64($h2->mulInt64($r0, 25))
                ->addInt64($s4->mulInt64($h3, 26))
                ->addInt64($s3->mulInt64($h4, 26));

            $d3 = $zero
                ->addInt64($h0->mulInt64($r3, 25))
                ->addInt64($h1->mulInt64($r2, 25))
                ->addInt64($h2->mulInt64($r1, 25))
                ->addInt64($h3->mulInt64($r0, 25))
                ->addInt64($s4->mulInt64($h4, 26));

            $d4 = $zero
 

 View on GitHub View on Trac