1 /*******************************************************************************
2 
3     D language bindings for libsodium's crypto_pwhash.h
4 
5     License: ISC (see LICENSE.txt)
6 
7 *******************************************************************************/
8 
9 module libsodium.crypto_pwhash;
10 
11 @nogc nothrow:
12 
13 import libsodium.export_;
14 import libsodium.crypto_pwhash_argon2i;
15 import libsodium.crypto_pwhash_argon2id;
16 
17 extern (C):
18 
19 enum crypto_pwhash_ALG_ARGON2I13 = crypto_pwhash_argon2i_ALG_ARGON2I13;
20 int crypto_pwhash_alg_argon2i13 ();
21 
22 enum crypto_pwhash_ALG_ARGON2ID13 = crypto_pwhash_argon2id_ALG_ARGON2ID13;
23 int crypto_pwhash_alg_argon2id13 ();
24 
25 enum crypto_pwhash_ALG_DEFAULT = crypto_pwhash_ALG_ARGON2ID13;
26 int crypto_pwhash_alg_default ();
27 
28 enum crypto_pwhash_BYTES_MIN = crypto_pwhash_argon2id_BYTES_MIN;
29 size_t crypto_pwhash_bytes_min ();
30 
31 enum crypto_pwhash_BYTES_MAX = crypto_pwhash_argon2id_BYTES_MAX;
32 size_t crypto_pwhash_bytes_max ();
33 
34 enum crypto_pwhash_PASSWD_MIN = crypto_pwhash_argon2id_PASSWD_MIN;
35 size_t crypto_pwhash_passwd_min ();
36 
37 enum crypto_pwhash_PASSWD_MAX = crypto_pwhash_argon2id_PASSWD_MAX;
38 size_t crypto_pwhash_passwd_max ();
39 
40 enum crypto_pwhash_SALTBYTES = crypto_pwhash_argon2id_SALTBYTES;
41 size_t crypto_pwhash_saltbytes ();
42 
43 enum crypto_pwhash_STRBYTES = crypto_pwhash_argon2id_STRBYTES;
44 size_t crypto_pwhash_strbytes ();
45 
46 enum crypto_pwhash_STRPREFIX = crypto_pwhash_argon2id_STRPREFIX;
47 const(char)* crypto_pwhash_strprefix ();
48 
49 enum crypto_pwhash_OPSLIMIT_MIN = crypto_pwhash_argon2id_OPSLIMIT_MIN;
50 size_t crypto_pwhash_opslimit_min ();
51 
52 enum crypto_pwhash_OPSLIMIT_MAX = crypto_pwhash_argon2id_OPSLIMIT_MAX;
53 size_t crypto_pwhash_opslimit_max ();
54 
55 enum crypto_pwhash_MEMLIMIT_MIN = crypto_pwhash_argon2id_MEMLIMIT_MIN;
56 size_t crypto_pwhash_memlimit_min ();
57 
58 enum crypto_pwhash_MEMLIMIT_MAX = crypto_pwhash_argon2id_MEMLIMIT_MAX;
59 size_t crypto_pwhash_memlimit_max ();
60 
61 enum crypto_pwhash_OPSLIMIT_INTERACTIVE = crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE;
62 size_t crypto_pwhash_opslimit_interactive ();
63 
64 enum crypto_pwhash_MEMLIMIT_INTERACTIVE = crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE;
65 size_t crypto_pwhash_memlimit_interactive ();
66 
67 enum crypto_pwhash_OPSLIMIT_MODERATE = crypto_pwhash_argon2id_OPSLIMIT_MODERATE;
68 size_t crypto_pwhash_opslimit_moderate ();
69 
70 enum crypto_pwhash_MEMLIMIT_MODERATE = crypto_pwhash_argon2id_MEMLIMIT_MODERATE;
71 size_t crypto_pwhash_memlimit_moderate ();
72 
73 enum crypto_pwhash_OPSLIMIT_SENSITIVE = crypto_pwhash_argon2id_OPSLIMIT_SENSITIVE;
74 size_t crypto_pwhash_opslimit_sensitive ();
75 
76 enum crypto_pwhash_MEMLIMIT_SENSITIVE = crypto_pwhash_argon2id_MEMLIMIT_SENSITIVE;
77 size_t crypto_pwhash_memlimit_sensitive ();
78 
79 /*
80  * With this function, do not forget to store all parameters, including the
81  * algorithm identifier in order to produce deterministic output.
82  * The crypto_pwhash_* definitions, including crypto_pwhash_ALG_DEFAULT,
83  * may change.
84  */
85 int crypto_pwhash (
86     ubyte* out_,
87     ulong outlen,
88     const char* passwd,
89     ulong passwdlen,
90     const ubyte* salt,
91     ulong opslimit,
92     size_t memlimit,
93     int alg);
94 
95 /*
96  * The output string already includes all the required parameters, including
97  * the algorithm identifier. The string is all that has to be stored in
98  * order to verify a password.
99  */
100 int crypto_pwhash_str (
101     ref char[crypto_pwhash_STRBYTES] out_,
102     const char* passwd,
103     ulong passwdlen,
104     ulong opslimit,
105     size_t memlimit);
106 
107 int crypto_pwhash_str_alg (
108     ref char[crypto_pwhash_STRBYTES] out_,
109     const char* passwd,
110     ulong passwdlen,
111     ulong opslimit,
112     size_t memlimit,
113     int alg);
114 
115 int crypto_pwhash_str_verify (
116     ref const(char)[crypto_pwhash_STRBYTES] str,
117     const char* passwd,
118     ulong passwdlen);
119 
120 int crypto_pwhash_str_needs_rehash (
121     ref const(char)[crypto_pwhash_STRBYTES] str,
122     ulong opslimit,
123     size_t memlimit);
124 
125 enum crypto_pwhash_PRIMITIVE = "argon2i";
126 const(char)* crypto_pwhash_primitive ();