You are here

public static function ParagonIE_Sodium_Crypto32::secretstream_xchacha20poly1305_init_push in Automatic Updates 7

Same name and namespace in other branches
  1. 8 vendor/paragonie/sodium_compat/src/Crypto32.php \ParagonIE_Sodium_Crypto32::secretstream_xchacha20poly1305_init_push()

Parameters

string $key:

Return value

array<int, string> Returns a state and a header.

Throws

Exception

SodiumException

1 call to ParagonIE_Sodium_Crypto32::secretstream_xchacha20poly1305_init_push()
ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_push in vendor/paragonie/sodium_compat/src/Compat.php

File

vendor/paragonie/sodium_compat/src/Crypto32.php, line 1240

Class

ParagonIE_Sodium_Crypto32
Class ParagonIE_Sodium_Crypto

Code

public static function secretstream_xchacha20poly1305_init_push($key) {

  # randombytes_buf(out, crypto_secretstream_xchacha20poly1305_HEADERBYTES);
  $out = random_bytes(24);

  # crypto_core_hchacha20(state->k, out, k, NULL);
  $subkey = ParagonIE_Sodium_Core32_HChaCha20::hChaCha20($out, $key);
  $state = new ParagonIE_Sodium_Core32_SecretStream_State($subkey, ParagonIE_Sodium_Core32_Util::substr($out, 16, 8) . str_repeat("\0", 4));

  # _crypto_secretstream_xchacha20poly1305_counter_reset(state);
  $state
    ->counterReset();

  # memcpy(STATE_INONCE(state), out + crypto_core_hchacha20_INPUTBYTES,

  #        crypto_secretstream_xchacha20poly1305_INONCEBYTES);

  # memset(state->_pad, 0, sizeof state->_pad);
  return array(
    $state
      ->toString(),
    $out,
  );
}