Lines Matching refs:hash

4  * Wrapper around hash() and hash_hmac() functions supporting truncated hashes
5 * such as sha256-96. Any hash algorithm returned by hash_algos() (and
8 * If {@link self::setKey() setKey()} is called, {@link self::hash() hash()} will
9 * return the HMAC as opposed to the hash.
16 * $hash = new \phpseclib3\Crypt\Hash('sha512');
18 * $hash->setKey('abcdefg');
20 * echo base64_encode($hash->hash('abcdefg'));
82 * Byte-length of hash output (Internal HMAC)
133 * @see self::hash()
143 * @see self::hash()
153 * @see self::hash()
161 * @see self::hash()
169 * @see self::hash()
200 * @param string $hash
202 public function __construct($hash = 'sha256')
204 $this->setHash($hash);
245 * will first hash the key using H and then use the resultant L byte string as the actual key to HMAC."
248 * when doing an HMAC multiple times it's faster to compute the hash once instead of computing it during
266 hash($this->algo, $this->key, true);
270 * Gets the hash function.
282 * Sets the hash function.
284 * @param string $hash
286 public function setHash($hash)
288 $this->hashParam = $hash = strtolower($hash);
289 switch ($hash) {
295 $this->length = abs(substr($hash, -3)) >> 3;
307 $hash = substr($hash, 0, -3);
339 if (preg_match('#^(shake(?:128|256))-(\d+)$#', $hash, $matches)) {
341 $hash = $matches[1];
345 "$hash is not a supported algorithm"
350 switch ($hash) {
386 if (in_array(substr($hash, 0, 5), ['sha3-', 'shake', 'kecca'])) {
389 if (version_compare(PHP_VERSION, '7.1.0') < 0 || substr($hash, 0, 5) != 'sha3-') {
390 //preg_match('#(\d+)$#', $hash, $matches);
402 $hash = ['phpseclib3\Crypt\Hash', PHP_INT_SIZE == 8 ? 'sha3_64' : 'sha3_32'];
406 if ($hash == 'sha512/224' || $hash == 'sha512/256') {
411 $initial = $hash == 'sha512/256' ?
427 $hash = ['phpseclib3\Crypt\Hash', 'sha512'];
431 if (is_array($hash)) {
437 $this->algo = $hash;
445 * The key-derivation function generates pseudorandom bits used to key the hash functions.
526 // For each iteration, extract key and do three-layer hash.
548 * The first-layer hash breaks the message into 1024-byte chunks and
564 // For each chunk, except the last: endian-adjust, NH hash
576 // NH hash and add bit-length. Concatenate the result to Y.
617 // Perform NH hash on the chunks, pairing words for multiplication
653 * The second-layer rehashes the L1-HASH output using a polynomial hash
676 // If M is no more than 2^17 bytes, hash under 64-bit prime,
677 // otherwise, hash first 2^17 bytes under 64-bit prime and
750 * The output from L2-HASH is 16 bytes long. This final hash function
780 public function hash($text)
855 hash($algo, $text, true);
863 * Returns the hash length (in bits)
873 * Returns the hash length (in bytes)
1294 * @param array $hash
1297 private static function sha512($m, $hash)
1372 // Initialize hash value for this chunk
1373 $a = clone $hash[0];
1374 $b = clone $hash[1];
1375 $c = clone $hash[2];
1376 $d = clone $hash[3];
1377 $e = clone $hash[4];
1378 $f = clone $hash[5];
1379 $g = clone $hash[6];
1380 $h = clone $hash[7];
1427 // Add this chunk's hash to result so far
1428 $hash = [
1429 $hash[0]->add($a),
1430 $hash[1]->add($b),
1431 $hash[2]->add($c),
1432 $hash[3]->add($d),
1433 $hash[4]->add($e),
1434 $hash[5]->add($f),
1435 $hash[6]->add($g),
1436 $hash[7]->add($h)
1440 // Produce the final hash value (big-endian)
1441 // (\phpseclib3\Crypt\Hash::hash() trims the output for hashes but not for HMACs. as such, we trim the output here)
1442 $temp = $hash[0]->toBytes() . $hash[1]->toBytes() . $hash[2]->toBytes() . $hash[3]->toBytes() .
1443 $hash[4]->toBytes() . $hash[5]->toBytes() . $hash[6]->toBytes() . $hash[7]->toBytes();