PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/PHP/Compat/Function/mhash.php

https://github.com/poppen/p2
PHP | 115 lines | 65 code | 22 blank | 28 comment | 18 complexity | f4ab2eb6f81b6e131efbb998974def46 MD5 | raw file
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group |
  6. // +----------------------------------------------------------------------+
  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 |
  9. // | available at through the world-wide-web at |
  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 |
  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. |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Aidan Lister <aidan@php.net> |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: mhash.php,v 1.3 2008/09/28 16:11:31 akid Exp $
  19. if (!defined('MHASH_CRC32')) {
  20. define('MHASH_CRC32', 0);
  21. }
  22. if (!defined('MHASH_MD5')) {
  23. define('MHASH_MD5', 1);
  24. }
  25. if (!defined('MHASH_SHA1')) {
  26. define('MHASH_SHA1', 2);
  27. }
  28. if (!defined('MHASH_HAVAL256')) {
  29. define('MHASH_HAVAL256', 3);
  30. }
  31. if (!defined('MHASH_RIPEMD160')) {
  32. define('MHASH_RIPEMD160', 5);
  33. }
  34. if (!defined('MHASH_TIGER')) {
  35. define('MHASH_TIGER', 7);
  36. }
  37. if (!defined('MHASH_GOST')) {
  38. define('MHASH_GOST', 8);
  39. }
  40. if (!defined('MHASH_CRC32B')) {
  41. define('MHASH_CRC32B', 9);
  42. }
  43. if (!defined('MHASH_HAVAL192')) {
  44. define('MHASH_HAVAL192', 11);
  45. }
  46. if (!defined('MHASH_HAVAL160')) {
  47. define('MHASH_HAVAL160', 12);
  48. }
  49. if (!defined('MHASH_HAVAL128')) {
  50. define('MHASH_HAVAL128', 13);
  51. }
  52. if (!defined('MHASH_TIGER128')) {
  53. define('MHASH_TIGER128', 14);
  54. }
  55. if (!defined('MHASH_TIGER160')) {
  56. define('MHASH_TIGER160', 15);
  57. }
  58. if (!defined('MHASH_MD4')) {
  59. define('MHASH_MD4', 16);
  60. }
  61. if (!defined('MHASH_SHA256')) {
  62. define('MHASH_SHA256', 17);
  63. }
  64. if (!defined('MHASH_ADLER32')) {
  65. define('MHASH_ADLER32', 18);
  66. }
  67. /**
  68. * Replace mhash()
  69. *
  70. * @category PHP
  71. * @package PHP_Compat
  72. * @link http://php.net/function.mhash
  73. * @author Aidan Lister <aidan@php.net>
  74. * @version $Revision: 1.3 $
  75. * @since PHP 4.1.0
  76. * @require PHP 4.0.0 (user_error)
  77. */
  78. if (!function_exists('mhash')) {
  79. function mhash($hashtype, $data, $key = '')
  80. {
  81. switch ($hashtype) {
  82. case MHASH_MD5:
  83. $key = str_pad((strlen($key) > 64 ? pack("H*", md5($key)) : $key), 64, chr(0x00));
  84. $k_opad = $key ^ (str_pad('', 64, chr(0x5c)));
  85. $k_ipad = $key ^ (str_pad('', 64, chr(0x36)));
  86. return pack("H*", md5($k_opad . pack("H*", md5($k_ipad . $data))));
  87. default:
  88. return false;
  89. break;
  90. }
  91. }
  92. }
  93. ?>