WordPress at Your Fingertips
function is not described

ParagonIE_Sodium_Core_ChaCha20_Ctx::__construct() public WP 1.0

ParagonIE_Sodium_Core_ChaCha20_Ctx constructor.

{} It's a method of the class: ParagonIE_Sodium_Core_ChaCha20_Ctx{}

No Hooks.

Return

null. Nothing.

Usage

$ParagonIE_Sodium_Core_ChaCha20_Ctx = new ParagonIE_Sodium_Core_ChaCha20_Ctx();
$ParagonIE_Sodium_Core_ChaCha20_Ctx->__construct( $key, $iv, $counter );
$key(string)
ChaCha20 key.
Default: ''
$iv(string)
Initialization Vector (a.k.a. nonce).
Default: ''
$counter(string)
The initial counter value.
Default: 8 0x00 bytes

Code of ParagonIE_Sodium_Core_ChaCha20_Ctx::__construct() WP 5.8.2

public function __construct($key = '', $iv = '', $counter = '')
{
    if (self::strlen($key) !== 32) {
        throw new InvalidArgumentException('ChaCha20 expects a 256-bit key.');
    }
    if (self::strlen($iv) !== 8) {
        throw new InvalidArgumentException('ChaCha20 expects a 64-bit nonce.');
    }
    $this->container = new SplFixedArray(16);

    /* "expand 32-byte k" as per ChaCha20 spec */
    $this->container[0]  = 0x61707865;
    $this->container[1]  = 0x3320646e;
    $this->container[2]  = 0x79622d32;
    $this->container[3]  = 0x6b206574;
    $this->container[4]  = self::load_4(self::substr($key, 0, 4));
    $this->container[5]  = self::load_4(self::substr($key, 4, 4));
    $this->container[6]  = self::load_4(self::substr($key, 8, 4));
    $this->container[7]  = self::load_4(self::substr($key, 12, 4));
    $this->container[8]  = self::load_4(self::substr($key, 16, 4));
    $this->container[9]  = self::load_4(self::substr($key, 20, 4));
    $this->container[10] = self::load_4(self::substr($key, 24, 4));
    $this->container[11] = self::load_4(self::substr($key, 28, 4));

    if (empty($counter)) {
        $this->container[12] = 0;
        $this->container[13] = 0;
    } else {
        $this->container[12] = self::load_4(self::substr($counter, 0, 4));
        $this->container[13] = self::load_4(self::substr($counter, 4, 4));
    }
    $this->container[14] = self::load_4(self::substr($iv, 0, 4));
    $this->container[15] = self::load_4(self::substr($iv, 4, 4));
}