1
2#define TEST_NAME "pwhash_scrypt_ll"
3#include "cmptest.h"
4
5static const char *   passwd1 = "";
6static const char *   salt1   = "";
7static const uint64_t N1      = 16U;
8static const uint32_t r1      = 1U;
9static const uint32_t p1      = 1U;
10
11static const char *   passwd2 = "password";
12static const char *   salt2   = "NaCl";
13static const uint64_t N2      = 1024U;
14static const uint32_t r2      = 8U;
15static const uint32_t p2      = 16U;
16
17static const char *   passwd3 = "pleaseletmein";
18static const char *   salt3   = "SodiumChloride";
19static const uint64_t N3      = 16384U;
20static const uint32_t r3      = 8U;
21static const uint32_t p3      = 1U;
22
23static void
24tv(const char *passwd, const char *salt, uint64_t N, uint32_t r, uint32_t p)
25{
26    uint8_t data[64];
27    size_t  i;
28    size_t  olen       = (sizeof data / sizeof data[0]);
29    size_t  passwd_len = strlen(passwd);
30    size_t  salt_len   = strlen(salt);
31    int     line_items  = 0;
32
33    if (crypto_pwhash_scryptsalsa208sha256_ll(
34            (const uint8_t *) passwd, passwd_len, (const uint8_t *) salt,
35            salt_len, N, r, p, data, olen) != 0) {
36        printf("pwhash_scryptsalsa208sha256_ll([%s],[%s]) failure\n", passwd,
37               salt);
38        return;
39    }
40
41    printf("scrypt('%s', '%s', %lu, %lu, %lu, %lu) =\n", passwd, salt,
42           (unsigned long) N, (unsigned long) r, (unsigned long) p,
43           (unsigned long) olen);
44
45    for (i = 0; i < olen; i++) {
46        printf("%02x%c", data[i], line_items < 15 ? ' ' : '\n');
47        line_items = line_items < 15 ? line_items + 1 : 0;
48    }
49}
50
51int
52main(void)
53{
54    tv(passwd1, salt1, N1, r1, p1);
55    tv(passwd2, salt2, N2, r2, p2);
56    tv(passwd3, salt3, N3, r3, p3);
57
58    return 0;
59}
60