ParagonIE_Sodium_Core32_ChaCha20::quarterRound

Advertisement

Summery Summery

The ChaCha20 quarter round function. Works on four 32-bit integers.

Syntax Syntax

ParagonIE_Sodium_Core32_ChaCha20::quarterRound( ParagonIE_Sodium_Core32_Int32 $a, ParagonIE_Sodium_Core32_Int32 $b, ParagonIE_Sodium_Core32_Int32 $c, ParagonIE_Sodium_Core32_Int32 $d )

Parameters Parameters

$a

(ParagonIE_Sodium_Core32_Int32) (Required)

$b

(ParagonIE_Sodium_Core32_Int32) (Required)

$c

(ParagonIE_Sodium_Core32_Int32) (Required)

$d

(ParagonIE_Sodium_Core32_Int32) (Required)

Return Return

(array<int,) ParagonIE_Sodium_Core32_Int32>

Source Source

File: wp-includes/sodium_compat/src/Core32/ChaCha20.php

    protected static function quarterRound(
        ParagonIE_Sodium_Core32_Int32 $a,
        ParagonIE_Sodium_Core32_Int32 $b,
        ParagonIE_Sodium_Core32_Int32 $c,
        ParagonIE_Sodium_Core32_Int32 $d
    ) {
        /** @var ParagonIE_Sodium_Core32_Int32 $a */
        /** @var ParagonIE_Sodium_Core32_Int32 $b */
        /** @var ParagonIE_Sodium_Core32_Int32 $c */
        /** @var ParagonIE_Sodium_Core32_Int32 $d */

        # a = PLUS(a,b); d = ROTATE(XOR(d,a),16);
        $a = $a->addInt32($b);
        $d = $d->xorInt32($a)->rotateLeft(16);

        # c = PLUS(c,d); b = ROTATE(XOR(b,c),12);
        $c = $c->addInt32($d);
        $b = $b->xorInt32($c)->rotateLeft(12);

        # a = PLUS(a,b); d = ROTATE(XOR(d,a), 8);
        $a = $a->addInt32($b);
        $d = $d->xorInt32($a)->rotateLeft(8);

        # c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
        $c = $c->addInt32($d);
        $b = $b->xorInt32($c)->rotateLeft(7);

        return array($a, $b, $c, $d);
    }

Advertisement

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.