<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/refs.crypto.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'book.hash.php',
    1 => 'Hash',
    2 => 'HASH Message Digest Framework',
  ),
  'up' => 
  array (
    0 => 'refs.crypto.php',
    1 => 'Cryptography Extensions',
  ),
  'prev' => 
  array (
    0 => 'refs.crypto.php',
    1 => 'Cryptography Extensions',
  ),
  'next' => 
  array (
    0 => 'hash.setup.php',
    1 => 'Installing/Configuring',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/hash/book.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/book.hash.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="book.hash" class="book">
 
 <h1 class="title">HASH Message Digest Framework</h1>
 
 
 
 <div id="intro.hash" class="preface">
  <h1 class="title">Introduction</h1>
  <p class="para">
   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 <abbr title="Hash-based Message Authentication Code">HMAC</abbr>
   values and key derivations including <abbr title="HMAC Key Definition Function">HKDF</abbr> and
   <abbr title="Password-Based Key Derivation Function 2">PBKDF2</abbr>.
  </p>
  <p class="para">
   There are roughly three categories of hashing algorithms, and a complete list of
   algorithms can be found in the documentation for <span class="function"><a href="function.hash-algos.php" class="function">hash_algos()</a></span>.

   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      Checksum algorithms (such as <code class="literal">&quot;crc32b&quot;</code> or <code class="literal">&quot;adler32&quot;</code>):
      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 &quot;guessable&quot; or can be manipulated
      to create collisions, so they are entirely unsuitable for cryptographic use.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      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.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      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.
     </span>
     <span class="simpara">
      The Computer Security Resource Center of the <abbr>NIST</abbr> has
      <a href="https://csrc.nist.gov/projects/hash-functions" class="link external">&raquo;&nbsp;explanation of the algorithms
      currently approved by United States Federal Information Processing
      Standards</a>.
     </span>
     <div class="caution"><strong class="caution">Caution</strong>
      <p class="para">
       Some of the early cryptographic algorithms, such as <code class="literal">&quot;md4&quot;</code>,
       <code class="literal">&quot;md5&quot;</code>, and <code class="literal">&quot;sha1&quot;</code>, have been proven
       to be prone to collision attacks and it is generally recommended to no
       longer use these for cryptographic applications.
      </p>
     </div>
    </li>
   </ul>
  </p>

  <p class="para">
   See also the <a href="faq.passwords.php" class="link">FAQ on Safe Password Hashing</a>
   for information on best practices for using hash functions in handling
   passwords.
  </p>
 </div>
 
 
 







 




 




 







<ul class="chunklist chunklist_book"><li><a href="hash.setup.php">Installing/Configuring</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="hash.installation.php">Installation</a></li><li><a href="hash.resources.php">Resource Types</a></li></ul></li><li><a href="hash.constants.php">Predefined Constants</a></li><li><a href="class.hashcontext.php">HashContext</a> — The HashContext class<ul class="chunklist chunklist_book chunklist_children"><li><a href="hashcontext.construct.php">HashContext::__construct</a> — Private constructor to disallow direct instantiation</li><li><a href="hashcontext.serialize.php">HashContext::__serialize</a> — Serializes the HashContext object</li><li><a href="hashcontext.unserialize.php">HashContext::__unserialize</a> — Deserializes the data parameter into a HashContext object</li></ul></li><li><a href="ref.hash.php">Hash Functions</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="function.hash.php">hash</a> — Generate a hash value (message digest)</li><li><a href="function.hash-algos.php">hash_algos</a> — Return a list of registered hashing algorithms</li><li><a href="function.hash-copy.php">hash_copy</a> — Copy hashing context</li><li><a href="function.hash-equals.php">hash_equals</a> — Timing attack safe string comparison</li><li><a href="function.hash-file.php">hash_file</a> — Generate a hash value using the contents of a given file</li><li><a href="function.hash-final.php">hash_final</a> — Finalize an incremental hash and return resulting digest</li><li><a href="function.hash-hkdf.php">hash_hkdf</a> — Generate a HKDF key derivation of a supplied key input</li><li><a href="function.hash-hmac.php">hash_hmac</a> — Generate a keyed hash value using the HMAC method</li><li><a href="function.hash-hmac-algos.php">hash_hmac_algos</a> — Return a list of registered hashing algorithms suitable for hash_hmac</li><li><a href="function.hash-hmac-file.php">hash_hmac_file</a> — Generate a keyed hash value using the HMAC method and the contents of a given file</li><li><a href="function.hash-init.php">hash_init</a> — Initialize an incremental hashing context</li><li><a href="function.hash-pbkdf2.php">hash_pbkdf2</a> — Generate a PBKDF2 key derivation of a supplied password</li><li><a href="function.hash-update.php">hash_update</a> — Pump data into an active hashing context</li><li><a href="function.hash-update-file.php">hash_update_file</a> — Pump data into an active hashing context from a file</li><li><a href="function.hash-update-stream.php">hash_update_stream</a> — Pump data into an active hashing context from an open stream</li></ul></li></ul></div><?php manual_footer($setup); ?>