crypt_sha256.phpt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. crypt() SHA-256
  3. --SKIPIF--
  4. <?php
  5. if (!function_exists('crypt') || !defined("CRYPT_SHA256")) {
  6. die("SKIP crypt()-sha256 is not available");
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. $tests = array(
  12. 1 => array(
  13. b'$5$saltstring',
  14. b'Hello world!',
  15. b'$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5'
  16. ),
  17. 2 => array(
  18. b'$5$rounds=10000$saltstringsaltstring',
  19. b'Hello world!',
  20. b'$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA'
  21. ),
  22. 3 => array(
  23. b'$5$rounds=10000$saltstringsaltstring',
  24. b'Hello world!',
  25. b'$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA'
  26. ),
  27. 4 => array(
  28. b'$5$rounds=5000$toolongsaltstring',
  29. b'This is just a test',
  30. b'$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8mGRcvxa5'
  31. ),
  32. 5 => array(
  33. b'$5$rounds=1400$anotherlongsaltstring',
  34. b'a very much longer text to encrypt. This one even stretches over morethan one line.',
  35. b'$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12oP84Bnq1'
  36. ),
  37. 6 => array(
  38. b'$5$rounds=77777$short',
  39. b'we have a short salt string but not a short password',
  40. b'$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/'
  41. ),
  42. 7 => array(
  43. b'$5$rounds=123456$asaltof16chars..',
  44. b'a short string',
  45. b'$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/cZKmF/wJvD'
  46. ),
  47. 8 => array(
  48. b'$5$rounds=10$roundstoolow',
  49. b'the minimum number is still observed',
  50. b'$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL972bIC'
  51. )
  52. );
  53. foreach ($tests as $iter => $t) {
  54. $res = crypt($t[1], $t[0]);
  55. if ($res != $t[2]) echo "Iteration $iter failed.
  56. Expected: <$t[2]>
  57. Got <$res>\n";
  58. }
  59. echo "Passes.";?>
  60. --EXPECTF--
  61. Passes.