/** * @param string $secretKeyMaterial * @param string $algorithm Name of hashing algorithm * @param BagOStuff $cache * @param string|array $context Context to mix into HKDF context * @param CryptRand $cryptRand * @throws InvalidArgumentException if secret key material is too short */ public function __construct($secretKeyMaterial, $algorithm, BagOStuff $cache, $context, CryptRand $cryptRand) { if (strlen($secretKeyMaterial) < 16) { throw new InvalidArgumentException("secret was too short."); } $this->skm = $secretKeyMaterial; $this->algorithm = $algorithm; $this->cache = $cache; $this->context = is_array($context) ? $context : [$context]; $this->cryptRand = $cryptRand; // To prevent every call from hitting the same memcache server, pick // from a set of keys to use. mt_rand is only use to pick a random // server, and does not affect the security of the process. $this->cacheKey = $cache->makeKey('HKDF', mt_rand(0, 16)); }