You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

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