You are here

class ParagonIE_Sodium_Core_ChaCha20_Ctx in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core/ChaCha20/Ctx.php \ParagonIE_Sodium_Core_ChaCha20_Ctx

Class ParagonIE_Sodium_Core_ChaCha20_Ctx

Hierarchy

Expanded class hierarchy of ParagonIE_Sodium_Core_ChaCha20_Ctx

2 string references to 'ParagonIE_Sodium_Core_ChaCha20_Ctx'
Ctx.php in vendor/paragonie/sodium_compat/src/Core/ChaCha20/Ctx.php
Ctx.php in vendor/paragonie/sodium_compat/src/Core32/ChaCha20/Ctx.php

File

vendor/paragonie/sodium_compat/src/Core/ChaCha20/Ctx.php, line 10

View source
class ParagonIE_Sodium_Core_ChaCha20_Ctx extends ParagonIE_Sodium_Core_Util implements ArrayAccess {

  /**
   * @var SplFixedArray internally, <int, int>
   */
  protected $container;

  /**
   * ParagonIE_Sodium_Core_ChaCha20_Ctx constructor.
   *
   * @internal You should not use this directly from another application
   *
   * @param string $key     ChaCha20 key.
   * @param string $iv      Initialization Vector (a.k.a. nonce).
   * @param string $counter The initial counter value.
   *                        Defaults to 8 0x00 bytes.
   * @throws InvalidArgumentException
   * @throws TypeError
   */
  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));
  }

  /**
   * @internal You should not use this directly from another application
   *
   * @param int $offset
   * @param int $value
   * @return void
   * @psalm-suppress MixedArrayOffset
   */
  public function offsetSet($offset, $value) {
    if (!is_int($offset)) {
      throw new InvalidArgumentException('Expected an integer');
    }
    if (!is_int($value)) {
      throw new InvalidArgumentException('Expected an integer');
    }
    $this->container[$offset] = $value;
  }

  /**
   * @internal You should not use this directly from another application
   *
   * @param int $offset
   * @return bool
   */
  public function offsetExists($offset) {
    return isset($this->container[$offset]);
  }

  /**
   * @internal You should not use this directly from another application
   *
   * @param int $offset
   * @return void
   * @psalm-suppress MixedArrayOffset
   */
  public function offsetUnset($offset) {
    unset($this->container[$offset]);
  }

  /**
   * @internal You should not use this directly from another application
   *
   * @param int $offset
   * @return mixed|null
   * @psalm-suppress MixedArrayOffset
   */
  public function offsetGet($offset) {
    return isset($this->container[$offset]) ? $this->container[$offset] : null;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagonIE_Sodium_Core_ChaCha20_Ctx::$container protected property
ParagonIE_Sodium_Core_ChaCha20_Ctx::offsetExists public function @internal You should not use this directly from another application
ParagonIE_Sodium_Core_ChaCha20_Ctx::offsetGet public function @internal You should not use this directly from another application
ParagonIE_Sodium_Core_ChaCha20_Ctx::offsetSet public function @internal You should not use this directly from another application
ParagonIE_Sodium_Core_ChaCha20_Ctx::offsetUnset public function @internal You should not use this directly from another application
ParagonIE_Sodium_Core_ChaCha20_Ctx::__construct public function ParagonIE_Sodium_Core_ChaCha20_Ctx constructor. 1
ParagonIE_Sodium_Core_Util::abs public static function
ParagonIE_Sodium_Core_Util::bin2hex public static function Convert a binary string into a hexadecimal string without cache-timing leaks
ParagonIE_Sodium_Core_Util::bin2hexUpper public static function Convert a binary string into a hexadecimal string without cache-timing leaks, returning uppercase letters (as per RFC 4648)
ParagonIE_Sodium_Core_Util::chrToInt public static function Cache-timing-safe variant of ord()
ParagonIE_Sodium_Core_Util::compare public static function Compares two strings.
ParagonIE_Sodium_Core_Util::declareScalarType public static function If a variable does not match a given type, throw a TypeError.
ParagonIE_Sodium_Core_Util::hashEquals public static function Evaluate whether or not two strings are equal (in constant-time)
ParagonIE_Sodium_Core_Util::hex2bin public static function Convert a hexadecimal string into a binary string without cache-timing leaks
ParagonIE_Sodium_Core_Util::intArrayToString public static function Turn an array of integers into a string
ParagonIE_Sodium_Core_Util::intToChr public static function Cache-timing-safe variant of ord()
ParagonIE_Sodium_Core_Util::isMbStringOverride protected static function Returns whether or not mbstring.func_overload is in effect.
ParagonIE_Sodium_Core_Util::load64_le public static function Load a 8 character substring into an integer
ParagonIE_Sodium_Core_Util::load_3 public static function Load a 3 character substring into an integer
ParagonIE_Sodium_Core_Util::load_4 public static function Load a 4 character substring into an integer
ParagonIE_Sodium_Core_Util::memcmp public static function @internal You should not use this directly from another application
ParagonIE_Sodium_Core_Util::mul public static function Multiply two integers in constant-time
ParagonIE_Sodium_Core_Util::numericTo64BitInteger public static function Convert any arbitrary numbers into two 32-bit integers that represent a 64-bit integer.
ParagonIE_Sodium_Core_Util::store32_le public static function Store a 32-bit integer into a string, treating it as little-endian.
ParagonIE_Sodium_Core_Util::store64_le public static function Stores a 64-bit integer as an string, treating it as little-endian.
ParagonIE_Sodium_Core_Util::store_3 public static function Store a 24-bit integer into a string, treating it as big-endian.
ParagonIE_Sodium_Core_Util::store_4 public static function Store a 32-bit integer into a string, treating it as big-endian.
ParagonIE_Sodium_Core_Util::stringToIntArray public static function Turn a string into an array of integers
ParagonIE_Sodium_Core_Util::strlen public static function Safe string length
ParagonIE_Sodium_Core_Util::substr public static function Safe substring
ParagonIE_Sodium_Core_Util::verify_16 public static function Compare a 16-character byte string in constant time.
ParagonIE_Sodium_Core_Util::verify_32 public static function Compare a 32-character byte string in constant time.
ParagonIE_Sodium_Core_Util::xorStrings public static function Calculate $a ^ $b for two strings.