libscrypt.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*-
  2. */
  3. #ifndef _CRYPTO_SCRYPT_H_
  4. #define _CRYPTO_SCRYPT_H_
  5. #include <stdint.h>
  6. #ifdef __cplusplus
  7. extern "C"{
  8. #endif
  9. /**
  10. * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
  11. * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
  12. * p, buflen) and write the result into buf. The parameters r, p, and buflen
  13. * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
  14. * must be a power of 2 greater than 1.
  15. *
  16. * libscrypt_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
  17. * password; duh
  18. * N: CPU AND RAM cost (first modifier)
  19. * r: RAM Cost
  20. * p: CPU cost (parallelisation)
  21. * In short, N is your main performance modifier. Values of r = 8, p = 1 are
  22. * standard unless you want to modify the CPU/RAM ratio.
  23. * Return 0 on success; or -1 on error.
  24. */
  25. int libscrypt_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t,
  26. uint32_t, uint32_t, /*@out@*/ uint8_t *, size_t);
  27. /* Converts a series of input parameters to a MCF form for storage */
  28. int libscrypt_mcf(uint32_t N, uint32_t r, uint32_t p, const char *salt,
  29. const char *hash, char *mcf);
  30. /* Checks a given MCF against a password */
  31. int libscrypt_check(char *mcf, const char *password);
  32. #ifdef __cplusplus
  33. }
  34. #endif
  35. /* Sane default values */
  36. #define SCRYPT_HASH_LEN 64 /* This can be user defined -
  37. *but 64 is the reference size
  38. */
  39. #define SCRYPT_SAFE_N 30 /* This is much higher than you want. It's just
  40. * a blocker for insane defines
  41. */
  42. #define SCRYPT_SALT_LEN 16 /* This is just a recommended size */
  43. #define SCRYPT_MCF_LEN 125 /* mcf is 120 byte + nul */
  44. #define SCRYPT_MCF_ID "$s1"
  45. #define SCRYPT_N 16384
  46. #define SCRYPT_r 8
  47. #define SCRYPT_p 16
  48. #endif /* !_CRYPTO_SCRYPT_H_ */