tests.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php /* -*- coding: utf-8; indent-tabs-mode: t; tab-width: 4 -*-
  2. vim: ts=4 noet ai */
  3. /**
  4. Tests for the SHA-3 library.
  5. Copyright © 2016 Desktopd Developers
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. @license GPL-3+
  17. @file
  18. */
  19. // The library is under GNU LGPL 3+
  20. require_once dirname (__FILE__) . '/SHA3.php'; // Oops, this is PHP 5.2+...
  21. // SHA3-256("")
  22. $sha3_256 = SHA3::init (SHA3::SHA3_256);
  23. $sha3_256->absorb ('');
  24. var_dump (bin2hex ($sha3_256->squeeze ())
  25. === 'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a');
  26. // SHA3-256("")
  27. $sha3_256 = SHA3::init (SHA3::SHA3_256);
  28. var_dump (bin2hex ($sha3_256->squeeze ())
  29. === 'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a');
  30. // SHA3-512("")
  31. $sha3_512 = SHA3::init (SHA3::SHA3_512);
  32. $sha3_512->absorb ('');
  33. var_dump (bin2hex ($sha3_512->squeeze ())
  34. === 'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a6'
  35. . '15b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
  36. // SHA3-512("")
  37. $sha3_512 = SHA3::init (SHA3::SHA3_512);
  38. var_dump (bin2hex ($sha3_512->squeeze ())
  39. === 'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a6'
  40. . '15b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
  41. // SHAKE128("The quick brown fox jumps over the lazy dog", 256)
  42. $shake128 = SHA3::init (SHA3::SHAKE128);
  43. $shake128->absorb ('The quick brown fox jumps over the lazy dog');
  44. var_dump (bin2hex ($shake128->squeeze (32))
  45. === 'f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
  46. // SHAKE128("The quick brown fox jumps over the lazy dog", 256)
  47. $shake128 = SHA3::init (SHA3::SHAKE128);
  48. $shake128->absorb ('The quick brown fox ');
  49. $shake128->absorb ('jumps over the lazy dog');
  50. var_dump (bin2hex ($shake128->squeeze (32))
  51. === 'f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
  52. // SHAKE256("The quick brown fox jumps over the lazy dog", 512)
  53. $shake256 = SHA3::init (SHA3::SHAKE256);
  54. $shake256->absorb ('The quick brown fox ');
  55. $shake256->absorb ('jumps over the lazy dog');
  56. var_dump (bin2hex ($shake256->squeeze (64))
  57. === '2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca'
  58. . '1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442');