sha256c-test.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <crypt.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. static const struct
  5. {
  6. const char *salt;
  7. const char *input;
  8. const char *expected;
  9. } tests[] =
  10. {
  11. { "$5$saltstring", "Hello world!",
  12. "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5" },
  13. { "$5$rounds=10000$saltstringsaltstring", "Hello world!",
  14. "$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2."
  15. "opqey6IcA" },
  16. { "$5$rounds=5000$toolongsaltstring", "This is just a test",
  17. "$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8"
  18. "mGRcvxa5" },
  19. { "$5$rounds=1400$anotherlongsaltstring",
  20. "a very much longer text to encrypt. This one even stretches over more"
  21. "than one line.",
  22. "$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12"
  23. "oP84Bnq1" },
  24. { "$5$rounds=77777$short",
  25. "we have a short salt string but not a short password",
  26. "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/" },
  27. { "$5$rounds=123456$asaltof16chars..", "a short string",
  28. "$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/"
  29. "cZKmF/wJvD" },
  30. { "$5$rounds=10$roundstoolow", "the minimum number is still observed",
  31. "$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97"
  32. "2bIC" },
  33. };
  34. #define ntests (sizeof (tests) / sizeof (tests[0]))
  35. static int
  36. do_test (void)
  37. {
  38. int result = 0;
  39. int i;
  40. for (i = 0; i < ntests; ++i)
  41. {
  42. char *cp = crypt (tests[i].input, tests[i].salt);
  43. if (strcmp (cp, tests[i].expected) != 0)
  44. {
  45. printf ("test %d: expected \"%s\", got \"%s\"\n",
  46. i, tests[i].expected, cp);
  47. result = 1;
  48. }
  49. }
  50. return result;
  51. }
  52. #define TIMEOUT 6
  53. #define TEST_FUNCTION do_test ()
  54. #include "../test-skeleton.c"