You are here

public static function ParagonIE_Sodium_Core32_BLAKE2b::stringToContext 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::stringToContext()

Creates an SplFixedArray containing other SplFixedArray elements, from a string (compatible with \Sodium\crypto_generichash_{init, update, final})

@internal You should not use this directly from another application

@psalm-suppress MixedArrayAccess @psalm-suppress MixedArrayAssignment

Parameters

string $string:

Return value

SplFixedArray

Throws

SodiumException

TypeError

2 calls to ParagonIE_Sodium_Core32_BLAKE2b::stringToContext()
ParagonIE_Sodium_Crypto32::generichash_final in vendor/paragonie/sodium_compat/src/Crypto32.php
Finalize a BLAKE2b hashing context, returning the hash.
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 684

Class

ParagonIE_Sodium_Core32_BLAKE2b
Class ParagonIE_Sodium_Core_BLAKE2b

Code

public static function stringToContext($string) {
  $ctx = self::context();

  # uint64_t h[8];
  for ($i = 0; $i < 8; ++$i) {
    $ctx[0][$i] = ParagonIE_Sodium_Core32_Int64::fromReverseString(self::substr($string, ($i << 3) + 0, 8));
  }

  # uint64_t t[2];

  # uint64_t f[2];
  for ($i = 1; $i < 3; ++$i) {
    $ctx[$i][1] = ParagonIE_Sodium_Core32_Int64::fromReverseString(self::substr($string, 72 + ($i - 1 << 4), 8));
    $ctx[$i][0] = ParagonIE_Sodium_Core32_Int64::fromReverseString(self::substr($string, 64 + ($i - 1 << 4), 8));
  }

  # uint8_t buf[2 * 128];
  $ctx[3] = self::stringToSplFixedArray(self::substr($string, 96, 256));

  # uint8_t buf[2 * 128];
  $int = 0;
  for ($i = 0; $i < 8; ++$i) {
    $int |= self::chrToInt($string[352 + $i]) << ($i << 3);
  }
  $ctx[4] = $int;
  return $ctx;
}