test_scrypt.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. int largemem;
  13. } tests[4] = {
  14. { "", "", 16, 1, 1, 0 },
  15. { "password", "NaCl", 1024, 8, 16, 0 },
  16. { "pleaseletmein", "SodiumChloride", 16384, 8, 1, 0 },
  17. { "pleaseletmein", "SodiumChloride", 1048576, 8, 1, 1 }
  18. };
  19. int
  20. main(int argc, char * argv[])
  21. {
  22. struct scrypt_test * test;
  23. char kbuf[64];
  24. size_t i;
  25. int failures = 0;
  26. int skip_largemem = 0;
  27. WARNP_INIT;
  28. /* Do we want to skip the large-memory test? */
  29. if ((argc == 2) && (strcmp(argv[1], "1") == 0))
  30. skip_largemem = 1;
  31. for (test = tests;
  32. test < tests + sizeof(tests) / sizeof(tests[0]);
  33. test++) {
  34. /* Skip large memory tests (if desired). */
  35. if (skip_largemem && test->largemem)
  36. continue;
  37. if (crypto_scrypt((const uint8_t *)test->passwd,
  38. strlen(test->passwd), (const uint8_t *)test->salt,
  39. strlen(test->salt), test->N, test->r, test->p,
  40. (uint8_t *)kbuf, 64)) {
  41. warnp("crypto_scrypt(%u, %u, %u) failed",
  42. (unsigned int)test->N, (unsigned int)test->r,
  43. (unsigned int)test->p);
  44. failures++;
  45. break;
  46. }
  47. printf("scrypt(\"%s\", \"%s\", %u, %u, %u, 64) =\n",
  48. test->passwd, test->salt, (unsigned int)test->N,
  49. (unsigned int)(test->r), (unsigned int)test->p);
  50. for (i = 0; i < 64; i++) {
  51. printf("%02x", (uint8_t)kbuf[i]);
  52. if ((i % 16) == 15)
  53. printf("\n");
  54. else
  55. printf(" ");
  56. }
  57. }
  58. return (failures ? 1 : 0);
  59. }