1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
<?xml version="1.0" encoding="utf-8"?>
<reference id="ref.mhash">
<title>Mhash Functions</title>
<titleabbrev>mhash</titleabbrev>
<partintro>
<para>
These functions are intended to work with <ulink
url="&url.mhash;">mhash</ulink>.</para>
<para>
This is an interface to the mhash library. mhash supports a wide
variety of hash algorithms such as MD5, SHA1, GOST, and many
others.
</para>
<para>
To use it, download the mhash distribution from <ulink
url="&url.mhash;">its web site</ulink> and follow the included
installation instructions. You need to compile PHP with the
<option role="configure">--with-mhash</option> parameter to enable
this extension.
</para>
<para>
Mhash can be used to create checksums, message digests, message
authentication codes, and more.
</para>
<para>
<example>
<title>Compute the MD5 digest and hmac and print it out as hex</title>
<programlisting role="php">
<?php
$input = "what do ya want for nothing?";
$hash = mhash (MHASH_MD5, $input);
print "The hash is ".bin2hex ($hash)."\n<br>";
$hash = mhash (MHASH_MD5, $input, "Jefe");
print "The hmac is ".bin2hex ($hash)."\n<br>";
?>
</programlisting>
</example>
This will produce:
<programlisting>
The hash is d03cb659cbf9192dcd066272249f8412
The hmac is 750c783e6ab0b503eaa86e310a5db738
</programlisting>
For a complete list of supported hashes, refer to the
documentation of mhash. The general rule is that you can access
the hash algorithm from PHP with MHASH_HASHNAME. For example, to
access TIGER you use the PHP constant MHASH_TIGER.
</para>
<para>
Here is a list of hashes which are currently supported by mhash. If a
hash is not listed here, but is listed by mhash as supported, you can
safely assume that this documentation is outdated.
<itemizedlist>
<listitem>
<simpara>
MHASH_MD5
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_SHA1
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_HAVAL256
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_HAVAL192
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_HAVAL160
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_HAVAL128
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_RIPEMD160
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_GOST
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_TIGER
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_CRC32
</simpara>
</listitem>
<listitem>
<simpara>
MHASH_CRC32B
</simpara>
</listitem>
</itemizedlist>
</para>
</partintro>
<refentry id="function.mhash-get-hash-name">
<refnamediv>
<refname>mhash_get_hash_name</refname>
<refpurpose>Get the name of the specified hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>mhash_get_hash_name</methodname>
<methodparam><type>int</type><parameter>hash</parameter></methodparam>
</methodsynopsis>
<para>
<function>mhash_get_hash_name</function> is used to get the name
of the specified hash.
</para>
<para>
<function>mhash_get_hash_name</function> takes the hash id as an
argument and returns the name of the hash or &false;, if the hash
does not exist.
</para>
<para>
<example>
<title><function>mhash_get_hash_name</function> Example</title>
<programlisting>
<?php
$hash = MHASH_MD5;
print mhash_get_hash_name ($hash);
?>
</programlisting>
</example>
The above example will print out:
<programlisting>
MD5
</programlisting>
</para>
</refsect1>
</refentry>
<refentry id="function.mhash-get-block-size">
<refnamediv>
<refname>mhash_get_block_size</refname>
<refpurpose>Get the block size of the specified hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>mhash_get_block_size</methodname>
<methodparam><type>int</type><parameter>hash</parameter></methodparam>
</methodsynopsis>
<para>
<function>mhash_get_block_size</function> is used to get the size
of a block of the specified <parameter>hash</parameter>.
</para>
<para>
<function>mhash_get_block_size</function> takes one argument, the
<parameter>hash</parameter> and returns the size in bytes or
&false;, if the <parameter>hash</parameter> does not exist.
</para>
</refsect1>
</refentry>
<refentry id="function.mhash-count">
<refnamediv>
<refname>mhash_count</refname>
<refpurpose>Get the highest available hash id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>mhash_count</methodname>
<void/>
</methodsynopsis>
<para>
<function>mhash_count</function> returns the highest available hash
id. Hashes are numbered from 0 to this hash id.
</para>
<para>
<example>
<title>Traversing all hashes</title>
<programlisting role="php">
<?php
$nr = mhash_count();
for ($i = 0; $i <= $nr; $i++) {
echo sprintf ("The blocksize of %s is %d\n",
mhash_get_hash_name ($i),
mhash_get_block_size ($i));
}
?>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.mhash">
<refnamediv>
<refname>mhash</refname>
<refpurpose>Compute hash</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>mhash</methodname>
<methodparam><type>int</type><parameter>hash</parameter></methodparam>
<methodparam><type>string</type><parameter>data</parameter></methodparam>
<methodparam><type>string</type><parameter>[ key ]</parameter></methodparam>
</methodsynopsis>
<para>
<function>mhash</function> applies a hash function specified by
<parameter>hash</parameter> to the <parameter>data</parameter> and
returns the resulting hash (also called digest). If the <parameter> key</parameter>
is specified it will return the resulting HMAC. HMAC is keyed hashing
for message authentication, or simply a message digest that depends on
the specified key. Not all algorithms supported in mhash can be used in
HMAC mode. In case of an error returns &false;.
</para>
</refsect1>
</refentry>
<refentry id="function.mhash-keygen-s2k">
<refnamediv>
<refname>mhash_keygen_s2k</refname>
<refpurpose>Generates a key</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>mhash_keygen_s2k</methodname>
<methodparam><type>int</type><parameter>hash</parameter></methodparam>
<methodparam><type>string</type><parameter>password</parameter></methodparam>
<methodparam><type>string</type><parameter>salt</parameter></methodparam>
<methodparam><type>int</type><parameter>bytes</parameter></methodparam>
</methodsynopsis>
<para>
<function>mhash_keygen_s2k</function> generates a key that is
<parameter>bytes</parameter> long, from a user given password.
This is the Salted S2K algorithm as specified in the OpenPGP
document (RFC 2440). That algorithm will use the specified
<parameter>hash</parameter> algorithm to create the key.
The <parameter>salt</parameter> must be different and random
enough for every key you generate in order to create different keys.
That salt must be known when you check the keys, thus it is
a good idea to append the key to it. Salt has a fixed length
of 8 bytes and will be padded with zeros if you supply less bytes.
Keep in mind that user supplied passwords are not really suitable
to be used as keys in cryptographic algorithms, since users normally
choose keys they can write on keyboard. These passwords use
only 6 to 7 bits per character (or less). It is highly recommended
to use some kind of tranformation (like this function) to the user
supplied key.
</para>
</refsect1>
</refentry>
</reference>
<!-- 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:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
|