PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/misc/rfc2104_testvectors.php

https://bitbucket.org/jmcastagnetto/pear_message
PHP | 76 lines | 39 code | 11 blank | 26 comment | 1 complexity | 28e26573358053281ea844bcfa27f24c MD5 | raw file
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id$
  20. //
  21. /**
  22. * Test package by using the test vectors from the RFC 2104
  23. * @author Jesus M. Castagnetto
  24. * @version 0.6
  25. * @access public
  26. * @package Message
  27. */
  28. require_once 'Message/Message.php';
  29. echo "Test Vectors from rfc 2104\n\n";
  30. echo "* Using static calls\n\n";
  31. $key1 = str_repeat(chr(0x0b), 16);
  32. $data1 = "Hi There";
  33. echo "rfc 2104 output: 0x9294727a3638bb1c13f48ef8158bfc9d\n";
  34. echo 'key: 0x'.str_repeat('0b', 16)."\n";
  35. echo "data: $data1\n";
  36. echo "md5 HMAC: ".Message::calcHMAC('MD5', $data1, $key1)."\n\n";
  37. $key2 = "Jefe";
  38. $data2 = "what do ya want for nothing?";
  39. echo "rfc 2104 output: 0x750c783e6ab0b503eaa86e310a5db738\n";
  40. echo "key: $key2\n";
  41. echo "data: $data2\n";
  42. echo "md5 HMAC: ".Message::calcHMAC('MD5', $data2, $key2)."\n\n";
  43. $key3 = str_repeat(chr(0xAA), 16);
  44. $data3 = str_repeat(chr(0xDD), 50);
  45. echo "rfc 2104 output: 0x56be34521d144c88dbb8c733f0e8b3f6\n";
  46. echo 'key: 0x'.str_repeat('AA', 16)."\n";
  47. echo 'data: 0x'.wordwrap(str_repeat('DD', 50),30,"\n",1)."\n";
  48. echo "md5 HMAC: ".Message::calcHMAC('MD5', $data3, $key3)."\n\n";
  49. echo "\n* Using a Message_HMAC_MD5 object\n\n";
  50. $md5 =& Message::createHMAC('MD5', $key1);
  51. echo "rfc 2104 output: 0x9294727a3638bb1c13f48ef8158bfc9d\n";
  52. echo 'key: 0x'.str_repeat('0b', 16)."\n";
  53. echo "data: $data1\n";
  54. echo "md5 HMAC: ".$md5->calc($data1)."\n\n";
  55. $md5->setKey($key2);
  56. echo "rfc 2104 output: 0x750c783e6ab0b503eaa86e310a5db738\n";
  57. echo "key: $key2\n";
  58. echo "data: $data2\n";
  59. echo "md5 HMAC: ".$md5->calc($data2)."\n\n";
  60. $md5->setKey($key3);
  61. echo "rfc 2104 output: 0x56be34521d144c88dbb8c733f0e8b3f6\n";
  62. echo 'key: 0x'.str_repeat('AA', 16)."\n";
  63. echo 'data: 0x'.wordwrap(str_repeat('DD', 50),30,"\n",1)."\n";
  64. echo "md5 HMAC: ".$md5->calc($data3)."\n\n";
  65. ?>