PageRenderTime 4587ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/html/data/module/Compat/Compat/Function/hash_hmac.php

http://eccubeonazure.codeplex.com
PHP | 44 lines | 22 code | 8 blank | 14 comment | 3 complexity | c9624d62651a5f1223915bc961a32144 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. require_once dirname(__FILE__) . '/hash.php';
  3. /**
  4. * Replace hash_hmac()
  5. *
  6. * @category PHP
  7. * @package PHP_Compat
  8. * @license LGPL - http://www.gnu.org/licenses/lgpl.html
  9. * @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
  10. * @link http://php.net/function.hash_hmac
  11. * @author revulo <revulon@gmail.com>
  12. * @since PHP 5.1.2
  13. * @require PHP 4.0.1 (str_pad)
  14. */
  15. function php_compat_hash_hmac($algo, $data, $key, $raw_output = false)
  16. {
  17. // Block size (byte) for MD5, SHA-1 and SHA-256.
  18. $blocksize = 64;
  19. $ipad = str_repeat("\x36", $blocksize);
  20. $opad = str_repeat("\x5c", $blocksize);
  21. if (strlen($key) > $blocksize) {
  22. $key = hash($algo, $key, true);
  23. } else {
  24. $key = str_pad($key, $blocksize, "\x00");
  25. }
  26. $ipad ^= $key;
  27. $opad ^= $key;
  28. return hash($algo, $opad . hash($algo, $ipad . $data, true), $raw_output);
  29. }
  30. // Define
  31. if (!function_exists('hash_hmac')) {
  32. function hash_hmac($algo, $data, $key, $raw_output = false)
  33. {
  34. return php_compat_hash_hmac($algo, $data, $key, $raw_output);
  35. }
  36. }