xref: /freebsd/sys/contrib/libsodium/test/default/pwhash_scrypt.c (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 
2 #define TEST_NAME "pwhash_scrypt"
3 #include "cmptest.h"
4 
5 #define OUT_LEN 128
6 #define OPSLIMIT 1000000
7 #define MEMLIMIT 10000000
8 
9 static void
10 tv(void)
11 {
12     static struct {
13         const char        *passwd_hex;
14         size_t             passwdlen;
15         const char        *salt_hex;
16         size_t             outlen;
17         unsigned long long opslimit;
18         size_t             memlimit;
19     } tests[] = {
20         { "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
21           "65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
22           "a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
23           "8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
24           127,
25           "5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
26           155, 481326, 7256678 },
27         { "e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed"
28           "9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e0"
29           "0cc2890277f0fd3c622115772f7048adaebed86e",
30           86,
31           "f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d",
32           250, 535778, 7849083 },
33         { "92263cbf6ac376499f68a4289d3bb59e5a22335eba63a32e6410249155b956b6a3"
34           "b48d4a44906b18b897127300b375b8f834f1ceffc70880a885f47c33876717e392"
35           "be57f7da3ae58da4fd1f43daa7e44bb82d3717af4319349c24cd31e46d295856b0"
36           "441b6b289992a11ced1cc3bf3011604590244a3eb737ff221129215e4e4347f491"
37           "5d41292b5173d196eb9add693be5319fdadc242906178bb6c0286c9b6ca6012746"
38           "711f58c8c392016b2fdfc09c64f0f6b6ab7b",
39           183,
40           "3b840e20e9555e9fb031c4ba1f1747ce25cc1d0ff664be676b9b4a90641ff194",
41           249, 311757, 7994791 },
42         { "027b6d8e8c8c474e9b69c7d9ed4f9971e8e1ce2f6ba95048414c3970f0f09b70e3"
43           "b6c5ae05872b3d8678705b7d381829c351a5a9c88c233569b35d6b0b809df44b64"
44           "51a9c273f1150e2ef8a0b5437eb701e373474cd44b97ef0248ebce2ca0400e1b53"
45           "f3d86221eca3f18eb45b702b9172440f774a82cbf1f6f525df30a6e293c873cce6"
46           "9bb078ed1f0d31e7f9b8062409f37f19f8550aae",
47           152,
48           "eb2a3056a09ad2d7d7f975bcd707598f24cd32518cde3069f2e403b34bfee8a5", 5,
49           643464, 1397645 },
50         { "4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b82"
51           "ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc097d"
52           "43ced68642bfb8bbbdd0f50b30118f5e",
53           82,
54           "39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258",
55           190, 758010, 5432947 },
56         { "1845e375479537e9dd4f4486d5c91ac72775d66605eeb11a787b78a7745f1fd005"
57           "2d526c67235dbae1b2a4d575a74cb551c8e9096c593a497aee74ba3047d911358e"
58           "de57bc27c9ea1829824348daaab606217cc931dcb6627787bd6e4e5854f0e8",
59           97,
60           "3ee91a805aa62cfbe8dce29a2d9a44373a5006f4a4ce24022aca9cecb29d1473",
61           212, 233177, 13101817 },
62         { "c7b09aec680e7b42fedd7fc792e78b2f6c1bea8f4a884320b648f81e8cf515e8ba"
63           "9dcfb11d43c4aae114c1734aa69ca82d44998365db9c93744fa28b63fd16000e82"
64           "61cbbe083e7e2da1e5f696bde0834fe53146d7e0e35e7de9920d041f5a5621aabe"
65           "02da3e2b09b405b77937efef3197bd5772e41fdb73fb5294478e45208063b5f58e"
66           "089dbeb6d6342a909c1307b3fff5fe2cf4da56bdae50848f",
67           156,
68           "039c056d933b475032777edbaffac50f143f64c123329ed9cf59e3b65d3f43b6",
69           178, 234753, 4886999 },
70         { "8f3a06e2fd8711350a517bb12e31f3d3423e8dc0bb14aac8240fca0995938d59bb"
71           "37bd0a7dfc9c9cc0705684b46612e8c8b1d6655fb0f9887562bb9899791a0250d1"
72           "320f945eda48cdc20c233f40a5bb0a7e3ac5ad7250ce684f68fc0b8c9633bfd75a"
73           "ad116525af7bdcdbbdb4e00ab163fd4df08f243f12557e",
74           122,
75           "90631f686a8c3dbc0703ffa353bc1fdf35774568ac62406f98a13ed8f47595fd",
76           55, 695191, 15738350 },
77         { "b540beb016a5366524d4605156493f9874514a5aa58818cd0c6dfffaa9e90205f1"
78           "7b",
79           34,
80           "44071f6d181561670bda728d43fb79b443bb805afdebaf98622b5165e01b15fb",
81           231, 78652, 6631659 },
82         { "a14975c26c088755a8b715ff2528d647cd343987fcf4aa25e7194a8417fb2b4b3f"
83           "7268da9f3182b4cfb22d138b2749d673a47ecc7525dd15a0a3c66046971784bb63"
84           "d7eae24cc84f2631712075a10e10a96b0e0ee67c43e01c423cb9c44e5371017e9c"
85           "496956b632158da3fe12addecb88912e6759bc37f9af2f45af72c5cae3b179ffb6"
86           "76a697de6ebe45cd4c16d4a9d642d29ddc0186a0a48cb6cd62bfc3dd229d313b30"
87           "1560971e740e2cf1f99a9a090a5b283f35475057e96d7064e2e0fc81984591068d"
88           "55a3b4169f22cccb0745a2689407ea1901a0a766eb99",
89           220,
90           "3d968b2752b8838431165059319f3ff8910b7b8ecb54ea01d3f54769e9d98daf",
91           167, 717248, 10784179 },
92     };
93     char          passwd[256];
94     unsigned char salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES];
95     unsigned char out[256];
96     char          out_hex[256 * 2 + 1];
97     size_t        i = 0U;
98 
99     do {
100         sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
101                        tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
102                        NULL, NULL);
103         sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
104                        strlen(tests[i].salt_hex), NULL, NULL, NULL);
105         if (crypto_pwhash_scryptsalsa208sha256(
106                 out, (unsigned long long) tests[i].outlen, passwd,
107                 tests[i].passwdlen, (const unsigned char *) salt,
108                 tests[i].opslimit, tests[i].memlimit) != 0) {
109             printf("pwhash failure\n");
110         }
111         sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
112         printf("%s\n", out_hex);
113     } while (++i < (sizeof tests) / (sizeof tests[0]));
114 }
115 
116 static void
117 tv2(void)
118 {
119     static struct {
120         const char        *passwd_hex;
121         size_t             passwdlen;
122         const char        *salt_hex;
123         size_t             outlen;
124         unsigned long long opslimit;
125         size_t             memlimit;
126     } tests[] = {
127         { "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
128           "65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
129           "a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
130           "8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
131           127,
132           "5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
133           155, 64, 1397645 },
134         { "a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae0"
135           "65577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08d"
136           "a232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f5"
137           "8d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6",
138           127,
139           "5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2",
140           155, 32768, 1397645 },
141     };
142     char          passwd[256];
143     unsigned char salt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES];
144     unsigned char out[256];
145     char          out_hex[256 * 2 + 1];
146     size_t        i = 0U;
147 
148     do {
149         sodium_hex2bin((unsigned char *) passwd, sizeof passwd,
150                        tests[i].passwd_hex, strlen(tests[i].passwd_hex), NULL,
151                        NULL, NULL);
152         sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
153                        strlen(tests[i].salt_hex), NULL, NULL, NULL);
154         if (crypto_pwhash_scryptsalsa208sha256(
155                 out, (unsigned long long) tests[i].outlen, passwd,
156                 tests[i].passwdlen, (const unsigned char *) salt,
157                 tests[i].opslimit, tests[i].memlimit) != 0) {
158             printf("pwhash failure\n");
159         }
160         sodium_bin2hex(out_hex, sizeof out_hex, out, tests[i].outlen);
161         printf("%s\n", out_hex);
162     } while (++i < (sizeof tests) / (sizeof tests[0]));
163 }
164 
165 static void
166 tv3(void)
167 {
168     static struct {
169         const char *passwd;
170         const char *out;
171     } tests[] = {
172         { "^T5H$JYt39n%K*j:W]!1s?vg!:jGi]Ax?..l7[p0v:1jHTpla9;]bUN;?bWyCbtqg "
173           "nrDFal+Jxl3,2`#^tFSu%v_+7iYse8-cCkNf!tD=KrW)",
174           "$7$B6....1....75gBMAGwfFWZqBdyF3WdTQnWdUsuTiWjG1fF9c1jiSD$tc8RoB3."
175           "Em3/zNgMLWo2u00oGIoTyJv4fl3Fl8Tix72" },
176         { "bl72h6#y<':MFRZ>B IA1=NRkCKS%W8`1I.2uQxJN0g)N N aTt^4K!Iw5r "
177           "H6;crDsv^a55j9tsk'/GqweZn;cdk6+F_St6:#*=?ZCD_lw>.",
178           "$7$A6....3....Iahc6qM0.UQJHVgE4h9oa1/"
179           "4OWlWLm9CCtfguvz6bQD$QnXCo3M7nIqtry2WKsUZ5gQ.mY0wAlJu."
180           "WUhtE8vF66" },
181         { "Py "
182           ">e.5b+tLo@rL`dC2k@eJ&4eVl!W=JJ4+k&mAt@gt',FS1JjqKW3aq21:]^kna`"
183           "mde7kVkN5NrpKUptu)@4*b&?BE_sJMG1=&@`3GBCV]Wg7xwgo7x3El",
184           "$7$96..../....f6bEusKt79kK4wdYN0ki2nw4bJQ7P3rN6k3BSigsK/"
185           "D$Dsvuw7vXj5xijmrb/NOhdgoyK/OiSIYv88cEtl9Cik7" },
186         { "2vj;Um]FKOL27oam(:Uo8+UmSTvb1FD*h?jk_,S=;RDgF-$Fjk?]9yvfxe@fN^!NN("
187           "Cuml?+2Raa",
188           "$7$86....I....7XwIxLtCx4VphmFeUa6OGuGJrFaIaYzDiLNu/"
189           "tyUPhD$U3q5GCEqCWxMwh.YQHDJrlg7FIZgViv9pcXE3h1vg61" },
190         { "CT=[9uUoGav,J`kU+348tA50ue#sL:ABZ3QgF+r[#vh:tTOiL>s8tv%,Jeo]jH/"
191           "_4^i(*jD-_ku[9Ko[=86 06V",
192           "$7$A6....2....R3.bjH6YS9wz9z8Jsj.3weGQ3J80ZZElGw2oVux1TP6$"
193           "i5u6lFzXDHaIgYEICinLD6WNaovbiXP8SnLrDRdKgA9" },
194         { "J#wNn`hDgOpTHNI.w^1a70%f,.9V_m038H_JIJQln`vdWnn/"
195           "rmILR?9H5g(+`;@H(2VosN9Fgk[WEjaBr'yB9Q19-imNa04[Mk5kvGcSn-TV",
196           "$7$B6....1....Dj1y.4mF1J9XmT/6IDskYdCLaPFJTq9xcCwXQ1DpT92$92/"
197           "hYfZLRq1nTLyIz.uc/dC6wLqwnsoqpkadrCXusm6" },
198         { "j4BS38Asa;p)[K+9TY!3YDj<LK-`nLVXQw9%*QfM",
199           "$7$B6....1....5Ods8mojVwXJq4AywF/uI9BdMSiJ/zT8hQP/"
200           "4cB68VC$nk4ExHNXJ802froj51/1wJTrSZvTIyyK7PecOxRRaz0" },
201         { "M.R>Qw+!qJb]>pP :_.9`dxM9k [eR7Y!yL-3)sNs[R,j_/^ "
202           "TH=5ny'15>6UXWcQW^6D%XCsO[vN[%ReA-`tV1vW(Nt*0KVK#]45P_A",
203           "$7$B6....1....D/"
204           "eyk8N5y6Z8YVQEsw521cTx.9zzLuK7YDs1KMMh.o4$alfW8ZbsUWnXc."
205           "vqon2zoljVk24Tt1.IsCuo2KurvS2" },
206         { "K3S=KyH#)36_?]LxeR8QNKw6X=gFb'ai$C%29V* "
207           "tyh^Wo$TN-#Q4qkmtTCf0LLb.^E$0uykkP",
208           "$7$B6....1....CuBuU97xgAage8whp/"
209           "JNKobo0TFbsORGVbfcQIefyP8$aqalP."
210           "XofGViB8EPLONqHma8vs1xc9uTIMYh9CgE.S8" },
211         { "Y0!?iQa9M%5ekffW(`",
212           "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
213           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
214 
215         /* Invalid pwhash strings */
216 
217         { "Y0!?iQa9M%5ekffW(`",
218           "$7$A6....1....$TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4"
219           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
220         { "Y0!?iQa9M%5ekffW(`",
221           "$7$.6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
222           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
223         { "Y0!?iQa9M%5ekffW(`",
224           "$7$A.....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
225           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
226         { "Y0!?iQa9M%5ekffW(`",
227           "$7$A6.........TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
228           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
229         { "Y0!?iQa9M%5ekffW(`",
230           "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i44269$"
231           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AH" },
232         { "Y0!?iQa9M%5ekffW(`",
233           "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
234           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx54269" },
235         { "Y0!?iQa9M%5ekffW(`",
236           "$7^A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
237           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
238         { "Y0!?iQa9M%5ekffW(`",
239           "$7$!6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
240           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
241         { "Y0!?iQa9M%5ekffW(`",
242           "$7$A!....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
243           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
244         { "Y0!?iQa9M%5ekffW(`",
245           "$7$A6....!....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
246           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
247         { "",
248           "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
249           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
250         { "Y0!?iQa9M%5ekffW(`",
251           "$7fA6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4#"
252           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
253         { "Y0!?iQa9M%5ekffW(`",
254           "$7$AX....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
255           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
256         { "Y0!?iQa9M%5ekffW(`",
257           "$7$A6....1!...TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$"
258           "a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5" },
259         { "Y0!?iQa9M%5ekffW(`", "$7$A6....1" },
260         { "Y0!?iQa9M%5ekffW(`", "$7$" },
261         { "Y0!?iQa9M%5ekffW(`", "" },
262         { "Y0!?iQa9M%5ekffW(`",
263           "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$" },
264         { "test",
265           "$7$.6..../.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
266         { "test",
267           "$7$z6..../.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
268         { "test",
269           "$7$8zzzzz/.....lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
270         { "test",
271           "$7$8zzzzzzzzzz.lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
272         { "test",
273           "$7$8.....zzzzz.lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." },
274         { "test",
275           "$7$86..../..../lgPchkGHqbeONR/xtuXyjCrt9kUSg6NlKFQO0OSxo/$.DbajbPYH9T7sg3fOtcgxvJzzfIgJBIxMkeQ8b24YQ." }
276     };
277     char * out;
278     char * passwd;
279     size_t i = 0U;
280 
281     do {
282         out = (char *) sodium_malloc(strlen(tests[i].out) + 1U);
283         assert(out != NULL);
284         memcpy(out, tests[i].out, strlen(tests[i].out) + 1U);
285         passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U);
286         assert(passwd != NULL);
287         memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U);
288         if (crypto_pwhash_scryptsalsa208sha256_str_verify(
289                 out, passwd, strlen(passwd)) != 0) {
290             printf("pwhash_str failure: [%u]\n", (unsigned int) i);
291         }
292         sodium_free(out);
293         sodium_free(passwd);
294     } while (++i < (sizeof tests) / (sizeof tests[0]));
295 }
296 
297 static void
298 str_tests(void)
299 {
300     char       *str_out;
301     char       *str_out2;
302     char       *salt;
303     const char *passwd = "Correct Horse Battery Staple";
304 
305     salt = (char *) sodium_malloc(crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
306     str_out =
307         (char *) sodium_malloc(crypto_pwhash_scryptsalsa208sha256_STRBYTES);
308     str_out2 =
309         (char *) sodium_malloc(crypto_pwhash_scryptsalsa208sha256_STRBYTES);
310     memcpy(salt, "[<~A 32-bytes salt for scrypt~>]",
311            crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
312     if (crypto_pwhash_scryptsalsa208sha256_str(str_out, passwd, strlen(passwd),
313                                                OPSLIMIT, MEMLIMIT) != 0) {
314         printf("pwhash_str failure\n");
315     }
316     if (crypto_pwhash_scryptsalsa208sha256_str(str_out2, passwd, strlen(passwd),
317                                                OPSLIMIT, MEMLIMIT) != 0) {
318         printf("pwhash_str(2) failure\n");
319     }
320     if (strcmp(str_out, str_out2) == 0) {
321         printf("pwhash_str doesn't generate different salts\n");
322     }
323     if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
324         (str_out, OPSLIMIT, MEMLIMIT) != 0) {
325         printf("needs_rehash() false positive\n");
326     }
327     if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
328         (str_out, OPSLIMIT, MEMLIMIT / 2) != 1 ||
329         crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
330         (str_out, OPSLIMIT / 2, MEMLIMIT) != 1 ||
331         crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
332         (str_out, OPSLIMIT, MEMLIMIT * 2) != 1 ||
333         crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
334         (str_out, OPSLIMIT * 2, MEMLIMIT) != 1) {
335         printf("needs_rehash() false negative\n");
336     }
337     if (crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
338         (str_out + 1, OPSLIMIT, MEMLIMIT) != -1) {
339         printf("needs_rehash() didn't fail with an invalid hash string\n");
340     }
341     if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
342                                                       strlen(passwd)) != 0) {
343         printf("pwhash_str_verify failure\n");
344     }
345     if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
346                                                       strlen(passwd)) != 0) {
347         printf("pwhash_str_verify failure\n");
348     }
349     str_out[14]++;
350     if (crypto_pwhash_scryptsalsa208sha256_str_verify(str_out, passwd,
351                                                       strlen(passwd)) == 0) {
352         printf("pwhash_str_verify(2) failure\n");
353     }
354     str_out[14]--;
355 
356     assert(str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U] == 0);
357 
358     assert(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
359            (str_out, 0, 0) == 1);
360     assert(crypto_pwhash_str_needs_rehash(str_out, 0, 0) == -1);
361     assert(crypto_pwhash_str_needs_rehash(str_out, OPSLIMIT, MEMLIMIT) == -1);
362     assert(crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
363            ("", OPSLIMIT, MEMLIMIT) == -1);
364 
365     sodium_free(salt);
366     sodium_free(str_out);
367     sodium_free(str_out2);
368 }
369 
370 int
371 main(void)
372 {
373     tv();
374     tv2();
375     tv3();
376     str_tests();
377 
378     assert(crypto_pwhash_scryptsalsa208sha256_bytes_min() > 0U);
379     assert(crypto_pwhash_scryptsalsa208sha256_bytes_max() >
380            crypto_pwhash_scryptsalsa208sha256_bytes_min());
381     assert(crypto_pwhash_scryptsalsa208sha256_passwd_max() >
382            crypto_pwhash_scryptsalsa208sha256_passwd_min());
383     assert(crypto_pwhash_scryptsalsa208sha256_saltbytes() > 0U);
384     assert(crypto_pwhash_scryptsalsa208sha256_strbytes() > 1U);
385     assert(crypto_pwhash_scryptsalsa208sha256_strbytes() >
386            strlen(crypto_pwhash_scryptsalsa208sha256_strprefix()));
387 
388     assert(crypto_pwhash_scryptsalsa208sha256_opslimit_min() > 0U);
389     assert(crypto_pwhash_scryptsalsa208sha256_opslimit_max() > 0U);
390     assert(crypto_pwhash_scryptsalsa208sha256_memlimit_min() > 0U);
391     assert(crypto_pwhash_scryptsalsa208sha256_memlimit_max() > 0U);
392     assert(crypto_pwhash_scryptsalsa208sha256_opslimit_interactive() > 0U);
393     assert(crypto_pwhash_scryptsalsa208sha256_memlimit_interactive() > 0U);
394     assert(crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() > 0U);
395     assert(crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() > 0U);
396 
397     printf("OK\n");
398 
399     return 0;
400 }
401