You are here

public static function ParagonIE_Sodium_Crypto::secretstream_xchacha20poly1305_rekey in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Crypto.php \ParagonIE_Sodium_Crypto::secretstream_xchacha20poly1305_rekey()

Parameters

string $state:

Return value

void

Throws

SodiumException

3 calls to ParagonIE_Sodium_Crypto::secretstream_xchacha20poly1305_rekey()
ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_rekey in vendor/paragonie/sodium_compat/src/Compat.php
ParagonIE_Sodium_Crypto::secretstream_xchacha20poly1305_pull in vendor/paragonie/sodium_compat/src/Crypto.php
ParagonIE_Sodium_Crypto::secretstream_xchacha20poly1305_push in vendor/paragonie/sodium_compat/src/Crypto.php

File

vendor/paragonie/sodium_compat/src/Crypto.php, line 1550

Class

ParagonIE_Sodium_Crypto
Class ParagonIE_Sodium_Crypto

Code

public static function secretstream_xchacha20poly1305_rekey(&$state) {
  $st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state);

  # unsigned char new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES +

  # crypto_secretstream_xchacha20poly1305_INONCEBYTES];

  # size_t        i;

  # for (i = 0U; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) {

  #     new_key_and_inonce[i] = state->k[i];

  # }
  $new_key_and_inonce = $st
    ->getKey();

  # for (i = 0U; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) {

  #     new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] =

  #         STATE_INONCE(state)[i];

  # }
  $new_key_and_inonce .= ParagonIE_Sodium_Core_Util::substR($st
    ->getNonce(), 0, 8);

  # crypto_stream_chacha20_ietf_xor(new_key_and_inonce, new_key_and_inonce,

  #                                 sizeof new_key_and_inonce,

  #                                 state->nonce, state->k);
  $st
    ->rekey(ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc($new_key_and_inonce, $st
    ->getCombinedNonce(), $st
    ->getKey(), ParagonIE_Sodium_Core_Util::store64_le(0)));

  # for (i = 0U; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) {

  #     state->k[i] = new_key_and_inonce[i];

  # }

  # for (i = 0U; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) {

  #     STATE_INONCE(state)[i] =

  #          new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i];

  # }

  # _crypto_secretstream_xchacha20poly1305_counter_reset(state);
  $st
    ->counterReset();
  $state = $st
    ->toString();
}