* Class ParagonIE_Sodium_Core_SecretStream_State
class ParagonIE_Sodium_Core_SecretStream_State
/** @var string $nonce */
* ParagonIE_Sodium_Core_SecretStream_State constructor.
* @param string|null $nonce
public function __construct($key, $nonce = null)
$nonce = str_repeat("\0", 12);
$this->nonce = str_pad($nonce, 12, "\0", STR_PAD_RIGHT);;
$this->_pad = str_repeat("\0", 4);
public function counterReset()
$this->_pad = str_repeat("\0", 4);
public function getCounter()
return ParagonIE_Sodium_Core_Util::store32_le($this->counter);
public function getNonce()
if (!is_string($this->nonce)) {
$this->nonce = str_repeat("\0", 12);
if (ParagonIE_Sodium_Core_Util::strlen($this->nonce) !== 12) {
$this->nonce = str_pad($this->nonce, 12, "\0", STR_PAD_RIGHT);
public function getCombinedNonce()
return $this->getCounter() .
ParagonIE_Sodium_Core_Util::substr($this->getNonce(), 0, 8);
public function incrementCounter()
public function needsRekey()
return ($this->counter & 0xffff) === 0;
* @param string $newKeyAndNonce
public function rekey($newKeyAndNonce)
$this->key = ParagonIE_Sodium_Core_Util::substr($newKeyAndNonce, 0, 32);
ParagonIE_Sodium_Core_Util::substr($newKeyAndNonce, 32),
public function xorNonce($str)
$this->nonce = ParagonIE_Sodium_Core_Util::xorStrings(
ParagonIE_Sodium_Core_Util::substr($str, 0, 8),
public static function fromString($string)
$state = new ParagonIE_Sodium_Core_SecretStream_State(
ParagonIE_Sodium_Core_Util::substr($string, 0, 32)
$state->counter = ParagonIE_Sodium_Core_Util::load_4(
ParagonIE_Sodium_Core_Util::substr($string, 32, 4)
$state->nonce = ParagonIE_Sodium_Core_Util::substr($string, 36, 12);
$state->_pad = ParagonIE_Sodium_Core_Util::substr($string, 48, 8);
public function toString()