1
0
mirror of https://github.com/php/doc-en.git synced 2026-04-23 15:28:17 +02:00
Files
archived-doc-en/reference/hash/functions/hash-init.xml
T
Tim Starling 91e303f2d2 Updates for hash functions that now throw errors
Update the manual for the changes to the hash functions by Mark Randall
in August 2019 and subsequent tweaks by Máté Kocsis in March 2020.

Closes GH-1932.
2022-11-03 11:34:34 +01:00

184 lines
5.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- Generated by xml_proto.php v2.3. Found in /scripts directory of phpdoc. -->
<refentry xml:id="function.hash-init" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>hash_init</refname>
<refpurpose>Initialize an incremental hashing context</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>HashContext</type><methodname>hash_init</methodname>
<methodparam><type>string</type><parameter>algo</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
<methodparam choice="opt"><type>string</type><parameter>key</parameter><initializer>""</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>[]</initializer></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>algo</parameter></term>
<listitem>
<para>
Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..). For a list of supported algorithms see <function>hash_algos</function>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Optional settings for hash generation, currently supports only one option:
<constant>HASH_HMAC</constant>. When specified, the <parameter>key</parameter>
<emphasis>must</emphasis> be specified.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>key</parameter></term>
<listitem>
<para>
When <constant>HASH_HMAC</constant> is specified for <parameter>flags</parameter>,
a shared secret key to be used with the HMAC hashing method must be supplied in this
parameter.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
An array of options for the various hashing algorithms. Currently, only the "seed" parameter is
supported by the MurmurHash variants.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a Hashing Context for use with <function>hash_update</function>,
<function>hash_update_stream</function>, <function>hash_update_file</function>,
and <function>hash_final</function>.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws a <classname>ValueError</classname> exception if
<parameter>algo</parameter> is unknown or is a non-cryptographic hash
function, or if <parameter>key</parameter> is empty.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.1.0</entry>
<entry>The <parameter>options</parameter> parameter has been added.</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
Now throws an <classname>ValueError</classname> exception if the
<parameter>algo</parameter> is unknown or is a non-cryptographic hash
function, or if <parameter>key</parameter> is empty. Previously,
&false; was returned and an <constant>E_WARNING</constant> message was
emitted.
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>Usage of non-cryptographic hash functions (adler32, crc32, crc32b, fnv132, fnv1a32, fnv164, fnv1a64, joaat) with <constant>HASH_HMAC</constant> was disabled.</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
Return <classname>HashContext</classname> instead of resource.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Incremental hashing example</title>
<programlisting role="php">
<![CDATA[
<?php
$ctx = hash_init('md5');
hash_update($ctx, 'The quick brown fox ');
hash_update($ctx, 'jumped over the lazy dog.');
echo hash_final($ctx);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
5c6ffbdd40d9556b73a21e63c3e0e904
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>hash</function></member>
<member><function>hash_algos</function></member>
<member><function>hash_file</function></member>
<member><function>hash_hmac</function></member>
<member><function>hash_hmac_file</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->