pwhash_scrypt_ll.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #define TEST_NAME "pwhash_scrypt_ll"
  2. #include "cmptest.h"
  3. static const char * passwd1 = "";
  4. static const char * salt1 = "";
  5. static const uint64_t N1 = 16U;
  6. static const uint32_t r1 = 1U;
  7. static const uint32_t p1 = 1U;
  8. static const char * passwd2 = "password";
  9. static const char * salt2 = "NaCl";
  10. static const uint64_t N2 = 1024U;
  11. static const uint32_t r2 = 8U;
  12. static const uint32_t p2 = 16U;
  13. static const char * passwd3 = "pleaseletmein";
  14. static const char * salt3 = "SodiumChloride";
  15. static const uint64_t N3 = 16384U;
  16. static const uint32_t r3 = 8U;
  17. static const uint32_t p3 = 1U;
  18. static void
  19. tv(const char *passwd, const char *salt, uint64_t N, uint32_t r, uint32_t p)
  20. {
  21. uint8_t data[64];
  22. size_t i;
  23. size_t olen = (sizeof data / sizeof data[0]);
  24. size_t passwd_len = strlen(passwd);
  25. size_t salt_len = strlen(salt);
  26. int line_items = 0;
  27. if (crypto_pwhash_scryptsalsa208sha256_ll(
  28. (const uint8_t *) passwd, passwd_len, (const uint8_t *) salt,
  29. salt_len, N, r, p, data, olen) != 0) {
  30. printf("pwhash_scryptsalsa208sha256_ll([%s],[%s]) failure\n", passwd,
  31. salt);
  32. return;
  33. }
  34. printf("scrypt('%s', '%s', %lu, %lu, %lu, %lu) =\n", passwd, salt,
  35. (unsigned long) N, (unsigned long) r, (unsigned long) p,
  36. (unsigned long) olen);
  37. for (i = 0; i < olen; i++) {
  38. printf("%02x%c", data[i], line_items < 15 ? ' ' : '\n');
  39. line_items = line_items < 15 ? line_items + 1 : 0;
  40. }
  41. }
  42. int
  43. main(void)
  44. {
  45. tv(passwd1, salt1, N1, r1, p1);
  46. tv(passwd2, salt2, N2, r2, p2);
  47. tv(passwd3, salt3, N3, r3, p3);
  48. return 0;
  49. }