[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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 : Sat Apr 20 08:20:01 2024 Cross-referenced by PHPXref