2014-06-01 14:58:20 -04:00
|
|
|
|
|
|
|
#define TEST_NAME "pwhash_scrypt_ll"
|
|
|
|
#include "cmptest.h"
|
|
|
|
|
|
|
|
/* Tarsnap test vectors, see: https://www.tarsnap.com/scrypt/scrypt.pdf */
|
|
|
|
|
2014-06-04 02:48:25 -04:00
|
|
|
static const char *password1 = "";
|
2017-02-23 05:30:21 -05:00
|
|
|
static const char *salt1 = "";
|
|
|
|
static uint64_t N1 = 16U;
|
|
|
|
static uint32_t r1 = 1U;
|
|
|
|
static uint32_t p1 = 1U;
|
2014-06-01 14:58:20 -04:00
|
|
|
|
2014-06-04 02:48:25 -04:00
|
|
|
static const char *password2 = "password";
|
2017-02-23 05:30:21 -05:00
|
|
|
static const char *salt2 = "NaCl";
|
|
|
|
static uint64_t N2 = 1024U;
|
|
|
|
static uint32_t r2 = 8U;
|
|
|
|
static uint32_t p2 = 16U;
|
2014-06-01 14:58:20 -04:00
|
|
|
|
2014-06-04 02:48:25 -04:00
|
|
|
static const char *password3 = "pleaseletmein";
|
2017-02-23 05:30:21 -05:00
|
|
|
static const char *salt3 = "SodiumChloride";
|
|
|
|
static uint64_t N3 = 16384U;
|
|
|
|
static uint32_t r3 = 8U;
|
|
|
|
static uint32_t p3 = 1U;
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_vector(const char *password, const char *salt, uint64_t N, uint32_t r,
|
|
|
|
uint32_t p)
|
2014-06-01 14:58:20 -04:00
|
|
|
{
|
2014-06-03 06:15:39 -04:00
|
|
|
uint8_t data[64];
|
2017-02-23 05:30:21 -05:00
|
|
|
size_t i;
|
|
|
|
size_t olen = (sizeof data / sizeof data[0]);
|
|
|
|
size_t passwordLength = strlen(password);
|
|
|
|
size_t saltLenght = strlen(salt);
|
|
|
|
int lineitems = 0;
|
|
|
|
int lineitemsLimit = 15;
|
2014-09-14 14:32:55 -04:00
|
|
|
|
|
|
|
if (crypto_pwhash_scryptsalsa208sha256_ll(
|
2017-02-23 05:30:21 -05:00
|
|
|
(const uint8_t *) password, passwordLength, (const uint8_t *) salt,
|
2014-09-14 14:32:55 -04:00
|
|
|
saltLenght, N, r, p, data, olen) != 0) {
|
|
|
|
printf("pwhash_scryptsalsa208sha256_ll([%s],[%s]) failure\n", password,
|
|
|
|
salt);
|
2014-06-04 02:48:25 -04:00
|
|
|
return;
|
2014-06-03 06:15:39 -04:00
|
|
|
}
|
2014-06-04 02:48:25 -04:00
|
|
|
|
2015-12-10 10:38:26 -05:00
|
|
|
printf("scrypt('%s', '%s', %lu, %lu, %lu, %lu) =\n", password, salt,
|
2017-02-23 05:30:21 -05:00
|
|
|
(unsigned long) N, (unsigned long) r, (unsigned long) p,
|
|
|
|
(unsigned long) olen);
|
2014-06-01 14:58:20 -04:00
|
|
|
|
2014-06-04 02:48:25 -04:00
|
|
|
for (i = 0; i < olen; ++i) {
|
|
|
|
printf("%02x%c", data[i], lineitems < lineitemsLimit ? ' ' : '\n');
|
|
|
|
lineitems = lineitems < lineitemsLimit ? lineitems + 1 : 0;
|
2014-06-01 14:58:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-23 05:30:21 -05:00
|
|
|
int
|
|
|
|
main(void)
|
2014-06-01 14:58:20 -04:00
|
|
|
{
|
2014-09-14 14:32:55 -04:00
|
|
|
test_vector(password1, salt1, N1, r1, p1);
|
|
|
|
test_vector(password2, salt2, N2, r2, p2);
|
|
|
|
test_vector(password3, salt3, N3, r3, p3);
|
2014-06-01 14:58:20 -04:00
|
|
|
|
2014-09-14 14:32:55 -04:00
|
|
|
return 0;
|
2014-06-01 14:58:20 -04:00
|
|
|
}
|