tests-namespaced.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. use desktopd\SHA3\Sponge as SHA3;
  20. // The library is under GNU LGPL 3+
  21. require_once __DIR__ . '/namespaced/desktopd/SHA3/Sponge.php';
  22. // SHA3-256("")
  23. $sha3_256 = SHA3::init (SHA3::SHA3_256);
  24. $sha3_256->absorb ('');
  25. var_dump (bin2hex ($sha3_256->squeeze ())
  26. === 'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a');
  27. // SHA3-256("")
  28. $sha3_256 = SHA3::init (SHA3::SHA3_256);
  29. var_dump (bin2hex ($sha3_256->squeeze ())
  30. === 'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a');
  31. // SHA3-512("")
  32. $sha3_512 = SHA3::init (SHA3::SHA3_512);
  33. $sha3_512->absorb ('');
  34. var_dump (bin2hex ($sha3_512->squeeze ())
  35. === 'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a6'
  36. . '15b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
  37. // SHA3-512("")
  38. $sha3_512 = SHA3::init (SHA3::SHA3_512);
  39. var_dump (bin2hex ($sha3_512->squeeze ())
  40. === 'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a6'
  41. . '15b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26');
  42. // SHAKE128("The quick brown fox jumps over the lazy dog", 256)
  43. $shake128 = SHA3::init (SHA3::SHAKE128);
  44. $shake128->absorb ('The quick brown fox jumps over the lazy dog');
  45. var_dump (bin2hex ($shake128->squeeze (32))
  46. === 'f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
  47. // SHAKE128("The quick brown fox jumps over the lazy dog", 256)
  48. $shake128 = SHA3::init (SHA3::SHAKE128);
  49. $shake128->absorb ('The quick brown fox ');
  50. $shake128->absorb ('jumps over the lazy dog');
  51. var_dump (bin2hex ($shake128->squeeze (32))
  52. === 'f4202e3c5852f9182a0430fd8144f0a74b95e7417ecae17db0f8cfeed0e3e66e');
  53. // SHAKE256("The quick brown fox jumps over the lazy dog", 512)
  54. $shake256 = SHA3::init (SHA3::SHAKE256);
  55. $shake256->absorb ('The quick brown fox ');
  56. $shake256->absorb ('jumps over the lazy dog');
  57. var_dump (bin2hex ($shake256->squeeze (64))
  58. === '2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca'
  59. . '1d01d1369a23539cd80f7c054b6e5daf9c962cad5b8ed5bd11998b40d5734442');