Rev 130 Rev 139
Line 1... Line 1...
1 <?php 1 <?php
2 // +----------------------------------------------------------------------+ 2 // +----------------------------------------------------------------------+
3 // | PHP Version 4 | 3 // | PHP Version 4 |
4 // +----------------------------------------------------------------------+ 4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 1997-2004 The PHP Group | 5 // | Copyright (c) 1997-2004 The PHP Group |
6 // +----------------------------------------------------------------------+ 6 // +----------------------------------------------------------------------+
7 // | This source file is subject to version 3.0 of the PHP license, | 7 // | This source file is subject to version 3.0 of the PHP license, |
8 // | that is bundled with this package in the file LICENSE, and is | 8 // | that is bundled with this package in the file LICENSE, and is |
9 // | available at through the world-wide-web at | 9 // | available at through the world-wide-web at |
10 // | http://www.php.net/license/3_0.txt. | 10 // | http://www.php.net/license/3_0.txt. |
11 // | If you did not receive a copy of the PHP license and are unable to | 11 // | If you did not receive a copy of the PHP license and are unable to |
12 // | obtain it through the world-wide-web, please send a note to | 12 // | obtain it through the world-wide-web, please send a note to |
13 // | license@php.net so we can mail you a copy immediately. | 13 // | license@php.net so we can mail you a copy immediately. |
14 // +----------------------------------------------------------------------+ 14 // +----------------------------------------------------------------------+
15 // | Authors: Aidan Lister <aidan@php.net> | 15 // | Authors: Aidan Lister <aidan@php.net> |
16 // +----------------------------------------------------------------------+ 16 // +----------------------------------------------------------------------+
17 // 17 //
18 // $Id: mhash.php,v 1.1 2005/05/10 07:56:44 aidan Exp $ 18 // $Id: mhash.php,v 1.1 2005/05/10 07:56:44 aidan Exp $
19   19  
20   20  
21 if (!defined('MHASH_CRC32')) { 21 if (!defined('MHASH_CRC32')) {
22 define('MHASH_CRC32', 0); 22 define('MHASH_CRC32', 0);
23 } 23 }
24   24  
25 if (!defined('MHASH_MD5')) { 25 if (!defined('MHASH_MD5')) {
26 define('MHASH_MD5', 1); 26 define('MHASH_MD5', 1);
27 } 27 }
28   28  
29 if (!defined('MHASH_SHA1')) { 29 if (!defined('MHASH_SHA1')) {
30 define('MHASH_SHA1', 2); 30 define('MHASH_SHA1', 2);
31 } 31 }
32   32  
33 if (!defined('MHASH_HAVAL256')) { 33 if (!defined('MHASH_HAVAL256')) {
34 define('MHASH_HAVAL256', 3); 34 define('MHASH_HAVAL256', 3);
35 } 35 }
36   36  
37 if (!defined('MHASH_RIPEMD160')) { 37 if (!defined('MHASH_RIPEMD160')) {
38 define('MHASH_RIPEMD160', 5); 38 define('MHASH_RIPEMD160', 5);
39 } 39 }
40   40  
41 if (!defined('MHASH_TIGER')) { 41 if (!defined('MHASH_TIGER')) {
42 define('MHASH_TIGER', 7); 42 define('MHASH_TIGER', 7);
43 } 43 }
44   44  
45 if (!defined('MHASH_GOST')) { 45 if (!defined('MHASH_GOST')) {
46 define('MHASH_GOST', 8); 46 define('MHASH_GOST', 8);
47 } 47 }
48   48  
49 if (!defined('MHASH_CRC32B')) { 49 if (!defined('MHASH_CRC32B')) {
50 define('MHASH_CRC32B', 9); 50 define('MHASH_CRC32B', 9);
51 } 51 }
52   52  
53 if (!defined('MHASH_HAVAL192')) { 53 if (!defined('MHASH_HAVAL192')) {
54 define('MHASH_HAVAL192', 11); 54 define('MHASH_HAVAL192', 11);
55 } 55 }
56   56  
57 if (!defined('MHASH_HAVAL160')) { 57 if (!defined('MHASH_HAVAL160')) {
58 define('MHASH_HAVAL160', 12); 58 define('MHASH_HAVAL160', 12);
59 } 59 }
60   60  
61 if (!defined('MHASH_HAVAL128')) { 61 if (!defined('MHASH_HAVAL128')) {
62 define('MHASH_HAVAL128', 13); 62 define('MHASH_HAVAL128', 13);
63 } 63 }
64   64  
65 if (!defined('MHASH_TIGER128')) { 65 if (!defined('MHASH_TIGER128')) {
66 define('MHASH_TIGER128', 14); 66 define('MHASH_TIGER128', 14);
67 } 67 }
68   68  
69 if (!defined('MHASH_TIGER160')) { 69 if (!defined('MHASH_TIGER160')) {
70 define('MHASH_TIGER160', 15); 70 define('MHASH_TIGER160', 15);
71 } 71 }
72   72  
73 if (!defined('MHASH_MD4')) { 73 if (!defined('MHASH_MD4')) {
74 define('MHASH_MD4', 16); 74 define('MHASH_MD4', 16);
75 } 75 }
76   76  
77 if (!defined('MHASH_SHA256')) { 77 if (!defined('MHASH_SHA256')) {
78 define('MHASH_SHA256', 17); 78 define('MHASH_SHA256', 17);
79 } 79 }
80   80  
81 if (!defined('MHASH_ADLER32')) { 81 if (!defined('MHASH_ADLER32')) {
82 define('MHASH_ADLER32', 18); 82 define('MHASH_ADLER32', 18);
83 } 83 }
84   84  
85   85  
86 /** 86 /**
87 * Replace mhash() 87 * Replace mhash()
88 * 88 *
89 * @category PHP 89 * @category PHP
90 * @package PHP_Compat 90 * @package PHP_Compat
91 * @link http://php.net/function.mhash 91 * @link http://php.net/function.mhash
92 * @author Aidan Lister <aidan@php.net> 92 * @author Aidan Lister <aidan@php.net>
93 * @version $Revision: 1.1 $ 93 * @version $Revision: 1.1 $
94 * @since PHP 4.1.0 94 * @since PHP 4.1.0
95 * @require PHP 4.0.0 (user_error) 95 * @require PHP 4.0.0 (user_error)
96 */ 96 */
97 if (!function_exists('mhash')) { 97 if (!function_exists('mhash')) {
98 function mhash($hashtype, $data, $key = '') 98 function mhash($hashtype, $data, $key = '')
99 { 99 {
100 switch ($hashtype) { 100 switch ($hashtype) {
101 case MHASH_MD5: 101 case MHASH_MD5:
102 $key = str_pad((strlen($key) > 64 ? pack("H*", md5($key)) : $key), 64, chr(0x00)); 102 $key = str_pad((strlen($key) > 64 ? pack("H*", md5($key)) : $key), 64, chr(0x00));
103 $k_opad = $key ^ (str_pad('', 64, chr(0x5c))); 103 $k_opad = $key ^ (str_pad('', 64, chr(0x5c)));
104 $k_ipad = $key ^ (str_pad('', 64, chr(0x36))); 104 $k_ipad = $key ^ (str_pad('', 64, chr(0x36)));
105 return pack("H*", md5($k_opad . pack("H*", md5($k_ipad . $data)))); 105 return pack("H*", md5($k_opad . pack("H*", md5($k_ipad . $data))));
106   106  
107 default: 107 default:
108 return false; 108 return false;
109   109  
110 break; 110 break;
111 } 111 }
112 } 112 }
113 } 113 }
114   114  
115 ?> 115 ?>
116 116