You are here

public static function ParagonIE_Sodium_Core32_BLAKE2b::contextToString in Automatic Updates 7

Same name and namespace in other branches
  1. 8 vendor/paragonie/sodium_compat/src/Core32/BLAKE2b.php \ParagonIE_Sodium_Core32_BLAKE2b::contextToString()

@internal You should not use this directly from another application

@psalm-suppress MixedArgument @psalm-suppress MixedArrayAccess @psalm-suppress MixedArrayAssignment @psalm-suppress MixedMethodCall

Parameters

SplFixedArray $ctx:

Return value

string

Throws

TypeError

3 calls to ParagonIE_Sodium_Core32_BLAKE2b::contextToString()
ParagonIE_Sodium_Crypto32::generichash_init in vendor/paragonie/sodium_compat/src/Crypto32.php
Initialize a hashing context for BLAKE2b.
ParagonIE_Sodium_Crypto32::generichash_init_salt_personal in vendor/paragonie/sodium_compat/src/Crypto32.php
Initialize a hashing context for BLAKE2b.
ParagonIE_Sodium_Crypto32::generichash_update in vendor/paragonie/sodium_compat/src/Crypto32.php
Update a hashing context for BLAKE2b with $message

File

vendor/paragonie/sodium_compat/src/Core32/BLAKE2b.php, line 617

Class

ParagonIE_Sodium_Core32_BLAKE2b
Class ParagonIE_Sodium_Core_BLAKE2b

Code

public static function contextToString(SplFixedArray $ctx) {
  $str = '';

  /** @var array<int, ParagonIE_Sodium_Core32_Int64> $ctxA */
  $ctxA = $ctx[0]
    ->toArray();

  # uint64_t h[8];
  for ($i = 0; $i < 8; ++$i) {
    if (!$ctxA[$i] instanceof ParagonIE_Sodium_Core32_Int64) {
      throw new TypeError('Not an instance of Int64');
    }

    /** @var ParagonIE_Sodium_Core32_Int64 $ctxAi */
    $ctxAi = $ctxA[$i];
    $str .= $ctxAi
      ->toReverseString();
  }

  # uint64_t t[2];

  # uint64_t f[2];
  for ($i = 1; $i < 3; ++$i) {

    /** @var array<int, ParagonIE_Sodium_Core32_Int64> $ctxA */
    $ctxA = $ctx[$i]
      ->toArray();

    /** @var ParagonIE_Sodium_Core32_Int64 $ctxA1 */
    $ctxA1 = $ctxA[0];

    /** @var ParagonIE_Sodium_Core32_Int64 $ctxA2 */
    $ctxA2 = $ctxA[1];
    $str .= $ctxA1
      ->toReverseString();
    $str .= $ctxA2
      ->toReverseString();
  }

  # uint8_t buf[2 * 128];
  $str .= self::SplFixedArrayToString($ctx[3]);

  /** @var int $ctx4 */
  $ctx4 = $ctx[4];

  # size_t buflen;
  $str .= implode('', array(
    self::intToChr($ctx4 & 0xff),
    self::intToChr($ctx4 >> 8 & 0xff),
    self::intToChr($ctx4 >> 16 & 0xff),
    self::intToChr($ctx4 >> 24 & 0xff),
    "\0\0\0\0",
  ));

  # uint8_t last_node;
  return $str . self::intToChr($ctx[5]) . str_repeat("\0", 23);
}