# HASH Message Digest Framework

# Introduction

This extension provides functions that can be used for direct or incremental processing of arbitrary length messages using a variety of hashing algorithms, including the generation of HMAC values and key derivations including HKDF and PBKDF2.

There are roughly three categories of hashing algorithms, and a complete list of algorithms can be found in the documentation for hash_algos().

- Checksum algorithms (such as `"crc32b"` or `"adler32"`): These are used to calculate checksums, useful in situations such as when transmission errors are to be detected. They are often very fast. These algorithms often generate values that are easily "guessable" or can be manipulated to create collisions, so they are entirely unsuitable for cryptographic use.
- Non-cryptographic algorithms (such as the xxHash family): These are often used to calculate hash values for hash tables, as they are designed to yield a good distribution over arbitrary string inputs. They are also generally fast, but also not suitable for cryptographic use.
- Cryptographic algorithms (such as the SHA-2 family): These are designed to yield hash values that are representative of their inputs but are not guessable nor prone to collisions. Performance is often a secondary concern, but modern hardware often supports special handling for these algorithms that PHP tries to use when available. The Computer Security Resource Center of the NIST has » explanation of the algorithms currently approved by United States Federal Information Processing Standards.
  Caution

  Some of the early cryptographic algorithms, such as `"md4"`, `"md5"`, and `"sha1"`, have been proven to be prone to collision attacks and it is generally recommended to no longer use these for cryptographic applications.

See also the FAQ on Safe Password Hashing for information on best practices for using hash functions in handling passwords.

- Installing/Configuring
  - Installation
  - Resource Types
- Predefined Constants
- HashContext — The HashContext class
  - HashContext::__construct — Private constructor to disallow direct instantiation
  - HashContext::__serialize — Serializes the HashContext object
  - HashContext::__unserialize — Deserializes the data parameter into a HashContext object
- Hash Functions
  - hash — Generate a hash value (message digest)
  - hash_algos — Return a list of registered hashing algorithms
  - hash_copy — Copy hashing context
  - hash_equals — Timing attack safe string comparison
  - hash_file — Generate a hash value using the contents of a given file
  - hash_final — Finalize an incremental hash and return resulting digest
  - hash_hkdf — Generate a HKDF key derivation of a supplied key input
  - hash_hmac — Generate a keyed hash value using the HMAC method
  - hash_hmac_algos — Return a list of registered hashing algorithms suitable for hash_hmac
  - hash_hmac_file — Generate a keyed hash value using the HMAC method and the contents of a given file
  - hash_init — Initialize an incremental hashing context
  - hash_pbkdf2 — Generate a PBKDF2 key derivation of a supplied password
  - hash_update — Pump data into an active hashing context
  - hash_update_file — Pump data into an active hashing context from a file
  - hash_update_stream — Pump data into an active hashing context from an open stream

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open