[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/sodium_compat/src/Core32/ChaCha20/ -> IetfCtx.php (source)

   1  <?php
   2  
   3  if (class_exists('ParagonIE_Sodium_Core_ChaCha20_IetfCtx', false)) {
   4      return;
   5  }
   6  
   7  /**
   8   * Class ParagonIE_Sodium_Core32_ChaCha20_IetfCtx
   9   */
  10  class ParagonIE_Sodium_Core32_ChaCha20_IetfCtx extends ParagonIE_Sodium_Core32_ChaCha20_Ctx
  11  {
  12      /**
  13       * ParagonIE_Sodium_Core_ChaCha20_IetfCtx constructor.
  14       *
  15       * @internal You should not use this directly from another application
  16       *
  17       * @param string $key     ChaCha20 key.
  18       * @param string $iv      Initialization Vector (a.k.a. nonce).
  19       * @param string $counter The initial counter value.
  20       *                        Defaults to 4 0x00 bytes.
  21       * @throws InvalidArgumentException
  22       * @throws SodiumException
  23       * @throws TypeError
  24       */
  25      public function __construct($key = '', $iv = '', $counter = '')
  26      {
  27          if (self::strlen($iv) !== 12) {
  28              throw new InvalidArgumentException('ChaCha20 expects a 96-bit nonce in IETF mode.');
  29          }
  30          parent::__construct($key, self::substr($iv, 0, 8), $counter);
  31  
  32          if (!empty($counter)) {
  33              $this->container[12] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($counter, 0, 4));
  34          }
  35          $this->container[13] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($iv, 0, 4));
  36          $this->container[14] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($iv, 4, 4));
  37          $this->container[15] = ParagonIE_Sodium_Core32_Int32::fromReverseString(self::substr($iv, 8, 4));
  38      }
  39  }


Generated: Wed Oct 27 01:00:04 2021 Cross-referenced by PHPXref 0.7.1