You are here

public static function ParagonIE_Sodium_Core_BLAKE2b::contextToString in Automatic Updates 7

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

@internal You should not use this directly from another application

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

Parameters

SplFixedArray $ctx:

Return value

string

Throws

TypeError

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

File

vendor/paragonie/sodium_compat/src/Core/BLAKE2b.php, line 687

Class

ParagonIE_Sodium_Core_BLAKE2b
Class ParagonIE_Sodium_Core_BLAKE2b

Code

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

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

  # uint64_t h[8];
  for ($i = 0; $i < 8; ++$i) {
    $str .= self::store32_le($ctxA[$i][1]);
    $str .= self::store32_le($ctxA[$i][0]);
  }

  # uint64_t t[2];

  # uint64_t f[2];
  for ($i = 1; $i < 3; ++$i) {
    $ctxA = $ctx[$i]
      ->toArray();
    $str .= self::store32_le($ctxA[0][1]);
    $str .= self::store32_le($ctxA[0][0]);
    $str .= self::store32_le($ctxA[1][1]);
    $str .= self::store32_le($ctxA[1][0]);
  }

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

  /** @var int $ctx4 */
  $ctx4 = (int) $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),
    self::intToChr($ctx4 >> 32 & 0xff),
    self::intToChr($ctx4 >> 40 & 0xff),
    self::intToChr($ctx4 >> 48 & 0xff),
    self::intToChr($ctx4 >> 56 & 0xff),
  ));

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