You are here

class ParagonIE_Sodium_Core_HChaCha20 in Automatic Updates 7

Same name and namespace in other branches
  1. 8 vendor/paragonie/sodium_compat/src/Core/HChaCha20.php \ParagonIE_Sodium_Core_HChaCha20

Class ParagonIE_Sodium_Core_HChaCha20

Hierarchy

Expanded class hierarchy of ParagonIE_Sodium_Core_HChaCha20

1 string reference to 'ParagonIE_Sodium_Core_HChaCha20'
HChaCha20.php in vendor/paragonie/sodium_compat/src/Core/HChaCha20.php

File

vendor/paragonie/sodium_compat/src/Core/HChaCha20.php, line 10

View source
class ParagonIE_Sodium_Core_HChaCha20 extends ParagonIE_Sodium_Core_ChaCha20 {

  /**
   * @param string $in
   * @param string $key
   * @param string|null $c
   * @return string
   * @throws TypeError
   */
  public static function hChaCha20($in = '', $key = '', $c = null) {
    $ctx = array();
    if ($c === null) {
      $ctx[0] = 0x61707865;
      $ctx[1] = 0x3320646e;
      $ctx[2] = 0x79622d32;
      $ctx[3] = 0x6b206574;
    }
    else {
      $ctx[0] = self::load_4(self::substr($c, 0, 4));
      $ctx[1] = self::load_4(self::substr($c, 4, 4));
      $ctx[2] = self::load_4(self::substr($c, 8, 4));
      $ctx[3] = self::load_4(self::substr($c, 12, 4));
    }
    $ctx[4] = self::load_4(self::substr($key, 0, 4));
    $ctx[5] = self::load_4(self::substr($key, 4, 4));
    $ctx[6] = self::load_4(self::substr($key, 8, 4));
    $ctx[7] = self::load_4(self::substr($key, 12, 4));
    $ctx[8] = self::load_4(self::substr($key, 16, 4));
    $ctx[9] = self::load_4(self::substr($key, 20, 4));
    $ctx[10] = self::load_4(self::substr($key, 24, 4));
    $ctx[11] = self::load_4(self::substr($key, 28, 4));
    $ctx[12] = self::load_4(self::substr($in, 0, 4));
    $ctx[13] = self::load_4(self::substr($in, 4, 4));
    $ctx[14] = self::load_4(self::substr($in, 8, 4));
    $ctx[15] = self::load_4(self::substr($in, 12, 4));
    return self::hChaCha20Bytes($ctx);
  }

  /**
   * @param array $ctx
   * @return string
   * @throws TypeError
   */
  protected static function hChaCha20Bytes(array $ctx) {
    $x0 = (int) $ctx[0];
    $x1 = (int) $ctx[1];
    $x2 = (int) $ctx[2];
    $x3 = (int) $ctx[3];
    $x4 = (int) $ctx[4];
    $x5 = (int) $ctx[5];
    $x6 = (int) $ctx[6];
    $x7 = (int) $ctx[7];
    $x8 = (int) $ctx[8];
    $x9 = (int) $ctx[9];
    $x10 = (int) $ctx[10];
    $x11 = (int) $ctx[11];
    $x12 = (int) $ctx[12];
    $x13 = (int) $ctx[13];
    $x14 = (int) $ctx[14];
    $x15 = (int) $ctx[15];
    for ($i = 0; $i < 10; ++$i) {

      # QUARTERROUND( x0,  x4,  x8,  x12)
      list($x0, $x4, $x8, $x12) = self::quarterRound($x0, $x4, $x8, $x12);

      # QUARTERROUND( x1,  x5,  x9,  x13)
      list($x1, $x5, $x9, $x13) = self::quarterRound($x1, $x5, $x9, $x13);

      # QUARTERROUND( x2,  x6,  x10,  x14)
      list($x2, $x6, $x10, $x14) = self::quarterRound($x2, $x6, $x10, $x14);

      # QUARTERROUND( x3,  x7,  x11,  x15)
      list($x3, $x7, $x11, $x15) = self::quarterRound($x3, $x7, $x11, $x15);

      # QUARTERROUND( x0,  x5,  x10,  x15)
      list($x0, $x5, $x10, $x15) = self::quarterRound($x0, $x5, $x10, $x15);

      # QUARTERROUND( x1,  x6,  x11,  x12)
      list($x1, $x6, $x11, $x12) = self::quarterRound($x1, $x6, $x11, $x12);

      # QUARTERROUND( x2,  x7,  x8,  x13)
      list($x2, $x7, $x8, $x13) = self::quarterRound($x2, $x7, $x8, $x13);

      # QUARTERROUND( x3,  x4,  x9,  x14)
      list($x3, $x4, $x9, $x14) = self::quarterRound($x3, $x4, $x9, $x14);
    }
    return self::store32_le((int) ($x0 & 0xffffffff)) . self::store32_le((int) ($x1 & 0xffffffff)) . self::store32_le((int) ($x2 & 0xffffffff)) . self::store32_le((int) ($x3 & 0xffffffff)) . self::store32_le((int) ($x12 & 0xffffffff)) . self::store32_le((int) ($x13 & 0xffffffff)) . self::store32_le((int) ($x14 & 0xffffffff)) . self::store32_le((int) ($x15 & 0xffffffff));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagonIE_Sodium_Core_ChaCha20::encryptBytes public static function @internal You should not use this directly from another application
ParagonIE_Sodium_Core_ChaCha20::ietfStream public static function @internal You should not use this directly from another application 1
ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc public static function @internal You should not use this directly from another application 1
ParagonIE_Sodium_Core_ChaCha20::quarterRound protected static function The ChaCha20 quarter round function. Works on four 32-bit integers.
ParagonIE_Sodium_Core_ChaCha20::rotate public static function Bitwise left rotation
ParagonIE_Sodium_Core_ChaCha20::stream public static function @internal You should not use this directly from another application 1
ParagonIE_Sodium_Core_ChaCha20::streamXorIc public static function @internal You should not use this directly from another application 1
ParagonIE_Sodium_Core_HChaCha20::hChaCha20 public static function
ParagonIE_Sodium_Core_HChaCha20::hChaCha20Bytes protected static function
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.