crypto_pwhash.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef crypto_pwhash_H
  2. #define crypto_pwhash_H
  3. #include <stddef.h>
  4. #include "crypto_pwhash_argon2i.h"
  5. #include "crypto_pwhash_argon2id.h"
  6. #include "export.h"
  7. #ifdef __cplusplus
  8. # ifdef __GNUC__
  9. # pragma GCC diagnostic ignored "-Wlong-long"
  10. # endif
  11. extern "C" {
  12. #endif
  13. #define crypto_pwhash_ALG_ARGON2I13 crypto_pwhash_argon2i_ALG_ARGON2I13
  14. SODIUM_EXPORT
  15. int crypto_pwhash_alg_argon2i13(void);
  16. #define crypto_pwhash_ALG_ARGON2ID13 crypto_pwhash_argon2id_ALG_ARGON2ID13
  17. SODIUM_EXPORT
  18. int crypto_pwhash_alg_argon2id13(void);
  19. #define crypto_pwhash_ALG_DEFAULT crypto_pwhash_ALG_ARGON2ID13
  20. SODIUM_EXPORT
  21. int crypto_pwhash_alg_default(void);
  22. #define crypto_pwhash_BYTES_MIN crypto_pwhash_argon2id_BYTES_MIN
  23. SODIUM_EXPORT
  24. size_t crypto_pwhash_bytes_min(void);
  25. #define crypto_pwhash_BYTES_MAX crypto_pwhash_argon2id_BYTES_MAX
  26. SODIUM_EXPORT
  27. size_t crypto_pwhash_bytes_max(void);
  28. #define crypto_pwhash_PASSWD_MIN crypto_pwhash_argon2id_PASSWD_MIN
  29. SODIUM_EXPORT
  30. size_t crypto_pwhash_passwd_min(void);
  31. #define crypto_pwhash_PASSWD_MAX crypto_pwhash_argon2id_PASSWD_MAX
  32. SODIUM_EXPORT
  33. size_t crypto_pwhash_passwd_max(void);
  34. #define crypto_pwhash_SALTBYTES crypto_pwhash_argon2id_SALTBYTES
  35. SODIUM_EXPORT
  36. size_t crypto_pwhash_saltbytes(void);
  37. #define crypto_pwhash_STRBYTES crypto_pwhash_argon2id_STRBYTES
  38. SODIUM_EXPORT
  39. size_t crypto_pwhash_strbytes(void);
  40. #define crypto_pwhash_STRPREFIX crypto_pwhash_argon2id_STRPREFIX
  41. SODIUM_EXPORT
  42. const char *crypto_pwhash_strprefix(void);
  43. #define crypto_pwhash_OPSLIMIT_MIN crypto_pwhash_argon2id_OPSLIMIT_MIN
  44. SODIUM_EXPORT
  45. size_t crypto_pwhash_opslimit_min(void);
  46. #define crypto_pwhash_OPSLIMIT_MAX crypto_pwhash_argon2id_OPSLIMIT_MAX
  47. SODIUM_EXPORT
  48. size_t crypto_pwhash_opslimit_max(void);
  49. #define crypto_pwhash_MEMLIMIT_MIN crypto_pwhash_argon2id_MEMLIMIT_MIN
  50. SODIUM_EXPORT
  51. size_t crypto_pwhash_memlimit_min(void);
  52. #define crypto_pwhash_MEMLIMIT_MAX crypto_pwhash_argon2id_MEMLIMIT_MAX
  53. SODIUM_EXPORT
  54. size_t crypto_pwhash_memlimit_max(void);
  55. #define crypto_pwhash_OPSLIMIT_INTERACTIVE crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE
  56. SODIUM_EXPORT
  57. size_t crypto_pwhash_opslimit_interactive(void);
  58. #define crypto_pwhash_MEMLIMIT_INTERACTIVE crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE
  59. SODIUM_EXPORT
  60. size_t crypto_pwhash_memlimit_interactive(void);
  61. #define crypto_pwhash_OPSLIMIT_MODERATE crypto_pwhash_argon2id_OPSLIMIT_MODERATE
  62. SODIUM_EXPORT
  63. size_t crypto_pwhash_opslimit_moderate(void);
  64. #define crypto_pwhash_MEMLIMIT_MODERATE crypto_pwhash_argon2id_MEMLIMIT_MODERATE
  65. SODIUM_EXPORT
  66. size_t crypto_pwhash_memlimit_moderate(void);
  67. #define crypto_pwhash_OPSLIMIT_SENSITIVE crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE
  68. SODIUM_EXPORT
  69. size_t crypto_pwhash_opslimit_sensitive(void);
  70. #define crypto_pwhash_MEMLIMIT_SENSITIVE crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE
  71. SODIUM_EXPORT
  72. size_t crypto_pwhash_memlimit_sensitive(void);
  73. /*
  74. * With this function, do not forget to store all parameters, including the
  75. * algorithm identifier in order to produce deterministic output.
  76. * The crypto_pwhash_* definitions, including crypto_pwhash_ALG_DEFAULT,
  77. * may change.
  78. */
  79. SODIUM_EXPORT
  80. int crypto_pwhash(unsigned char * const out, unsigned long long outlen,
  81. const char * const passwd, unsigned long long passwdlen,
  82. const unsigned char * const salt,
  83. unsigned long long opslimit, size_t memlimit, int alg)
  84. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
  85. /*
  86. * The output string already includes all the required parameters, including
  87. * the algorithm identifier. The string is all that has to be stored in
  88. * order to verify a password.
  89. */
  90. SODIUM_EXPORT
  91. int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES],
  92. const char * const passwd, unsigned long long passwdlen,
  93. unsigned long long opslimit, size_t memlimit)
  94. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
  95. SODIUM_EXPORT
  96. int crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES],
  97. const char * const passwd, unsigned long long passwdlen,
  98. unsigned long long opslimit, size_t memlimit, int alg)
  99. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
  100. SODIUM_EXPORT
  101. int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES],
  102. const char * const passwd,
  103. unsigned long long passwdlen)
  104. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
  105. SODIUM_EXPORT
  106. int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES],
  107. unsigned long long opslimit, size_t memlimit)
  108. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
  109. #define crypto_pwhash_PRIMITIVE "argon2i"
  110. SODIUM_EXPORT
  111. const char *crypto_pwhash_primitive(void)
  112. __attribute__ ((warn_unused_result));
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif