test_scrypt.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "crypto_scrypt.h"
  5. #include "warnp.h"
  6. static struct scrypt_test {
  7. const char * passwd;
  8. const char * salt;
  9. uint64_t N;
  10. uint32_t r;
  11. uint32_t p;
  12. } tests[4] = {
  13. { "", "", 16, 1, 1 },
  14. { "password", "NaCl", 1024, 8, 16 },
  15. { "pleaseletmein", "SodiumChloride", 16384, 8, 1 },
  16. { "pleaseletmein", "SodiumChloride", 1048576, 8, 1 }
  17. };
  18. int
  19. main(int argc, char * argv[])
  20. {
  21. struct scrypt_test * test;
  22. char kbuf[64];
  23. size_t i;
  24. WARNP_INIT;
  25. (void)argc; /* UNUSED */
  26. (void)argv; /* UNUSED */
  27. for (test = tests;
  28. test < tests + sizeof(tests) / sizeof(tests[0]);
  29. test++) {
  30. crypto_scrypt((const uint8_t *)test->passwd,
  31. strlen(test->passwd), (const uint8_t *)test->salt,
  32. strlen(test->salt), test->N, test->r, test->p,
  33. (uint8_t *)kbuf, 64);
  34. printf("scrypt(\"%s\", \"%s\", %u, %u, %u, 64) =\n",
  35. test->passwd, test->salt, (unsigned int)test->N,
  36. (unsigned int)(test->r), (unsigned int)test->p);
  37. for (i = 0; i < 64; i++) {
  38. printf("%02x ", (uint8_t)kbuf[i]);
  39. if ((i % 16) == 15)
  40. printf("\n");
  41. }
  42. }
  43. return (0);
  44. }