ParagonIE_Sodium_Core_Salsa20::salsa20

Advertisement

Syntax Syntax

ParagonIE_Sodium_Core_Salsa20::salsa20( int $len, string $nonce, string $key )

Parameters Parameters

$len

(Required)

$nonce

(Required)

$key

(Required)

Return Return

(string)

Source Source

File: wp-includes/sodium_compat/src/Core/Salsa20.php

    public static function salsa20($len, $nonce, $key)
    {
        if (self::strlen($key) !== 32) {
            throw new RangeException('Key must be 32 bytes long');
        }
        $kcopy = '' . $key;
        $in = self::substr($nonce, 0, 8) . str_repeat("\0", 8);
        $c = '';
        while ($len >= 64) {
            $c .= self::core_salsa20($in, $kcopy, null);
            $u = 1;
            // Internal counter.
            for ($i = 8; $i < 16; ++$i) {
                $u += self::chrToInt($in[$i]);
                $in[$i] = self::intToChr($u & 0xff);
                $u >>= 8;
            }
            $len -= 64;
        }
        if ($len > 0) {
            $c .= self::substr(
                self::core_salsa20($in, $kcopy, null),
                0,
                $len
            );
        }
        try {
            ParagonIE_Sodium_Compat::memzero($kcopy);
        } catch (SodiumException $ex) {
            $kcopy = null;
        }
        return $c;
    }

Advertisement

Advertisement

Leave a Reply