You are here

public function ParagonIE_Sodium_Core_Poly1305_State::__construct in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Core/Poly1305/State.php \ParagonIE_Sodium_Core_Poly1305_State::__construct()

ParagonIE_Sodium_Core_Poly1305_State constructor.

@internal You should not use this directly from another application

Parameters

string $key:

Throws

InvalidArgumentException

TypeError

File

vendor/paragonie/sodium_compat/src/Core/Poly1305/State.php, line 51

Class

ParagonIE_Sodium_Core_Poly1305_State
Class ParagonIE_Sodium_Core_Poly1305_State

Code

public function __construct($key = '') {
  if (self::strlen($key) < 32) {
    throw new InvalidArgumentException('Poly1305 requires a 32-byte key');
  }

  /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
  $this->r = array(
    (int) (self::load_4(self::substr($key, 0, 4)) & 0x3ffffff),
    (int) (self::load_4(self::substr($key, 3, 4)) >> 2 & 0x3ffff03),
    (int) (self::load_4(self::substr($key, 6, 4)) >> 4 & 0x3ffc0ff),
    (int) (self::load_4(self::substr($key, 9, 4)) >> 6 & 0x3f03fff),
    (int) (self::load_4(self::substr($key, 12, 4)) >> 8 & 0xfffff),
  );

  /* h = 0 */
  $this->h = array(
    0,
    0,
    0,
    0,
    0,
  );

  /* save pad for later */
  $this->pad = array(
    self::load_4(self::substr($key, 16, 4)),
    self::load_4(self::substr($key, 20, 4)),
    self::load_4(self::substr($key, 24, 4)),
    self::load_4(self::substr($key, 28, 4)),
  );
  $this->leftover = 0;
  $this->final = false;
}