2014-06-01 14:58:20 -04:00
|
|
|
#include <stdio.h>
|
2014-06-04 02:22:38 -04:00
|
|
|
#include <stdint.h>
|
2014-06-01 14:58:20 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define TEST_NAME "pwhash_scrypt_ll"
|
|
|
|
#include "cmptest.h"
|
|
|
|
|
|
|
|
/* Tarsnap test vectors, see: https://www.tarsnap.com/scrypt/scrypt.pdf */
|
|
|
|
|
2014-06-03 06:15:39 -04:00
|
|
|
uint8_t password1[] = "";
|
|
|
|
uint8_t salt1[] = "";
|
2014-06-01 14:58:20 -04:00
|
|
|
uint64_t N1 = 16ul;
|
|
|
|
uint32_t r1 = 1ul;
|
|
|
|
uint32_t p1 = 1ul;
|
|
|
|
|
2014-06-03 06:15:39 -04:00
|
|
|
uint8_t password2[] = "password";
|
|
|
|
uint8_t salt2[] = "NaCl";
|
2014-06-01 14:58:20 -04:00
|
|
|
uint64_t N2 = 1024ul;
|
|
|
|
uint32_t r2 = 8ul;
|
|
|
|
uint32_t p2 = 16ul;
|
|
|
|
|
2014-06-03 06:15:39 -04:00
|
|
|
uint8_t password3[] = "pleaseletmein";
|
|
|
|
uint8_t salt3[] = "SodiumChloride";
|
2014-06-01 14:58:20 -04:00
|
|
|
uint64_t N3 = 16384ul;
|
|
|
|
uint32_t r3 = 8ul;
|
|
|
|
uint32_t p3 = 1ul;
|
|
|
|
|
2014-06-03 06:15:39 -04:00
|
|
|
uint8_t password4[] = "pleaseletmein";
|
|
|
|
uint8_t salt4[] = "SodiumChloride";
|
2014-06-01 14:58:20 -04:00
|
|
|
size_t N4 = 1048576ul;
|
|
|
|
size_t r4 = 8ul;
|
|
|
|
size_t p4 = 1ul;
|
|
|
|
|
2014-06-03 06:15:39 -04:00
|
|
|
void test_vector(uint8_t * password, uint8_t * 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
|
|
|
const size_t olen = 64;
|
|
|
|
uint8_t data[64];
|
|
|
|
size_t passwordLength = strlen((const char*) password);
|
|
|
|
size_t saltLenght = strlen((const char*) salt);
|
|
|
|
int lineitems = 0;
|
|
|
|
const int lineitemsLimit = 15;
|
|
|
|
|
|
|
|
int i = crypto_pwhash_scryptsalsa208sha256_ll(password, passwordLength, salt, saltLenght, N, r, p, data, olen);
|
|
|
|
if(i != 0)
|
2014-06-01 14:58:20 -04:00
|
|
|
{
|
|
|
|
printf("crypto_scrypt_compat failed!");
|
2014-06-03 06:15:39 -04:00
|
|
|
}
|
|
|
|
|
2014-06-01 14:58:20 -04:00
|
|
|
// Print header
|
2014-06-03 06:15:39 -04:00
|
|
|
printf("scrypt('");
|
2014-06-01 15:31:44 -04:00
|
|
|
printf("%s", password);
|
2014-06-03 06:15:39 -04:00
|
|
|
printf("', '");
|
2014-06-01 15:31:44 -04:00
|
|
|
printf("%s", salt);
|
2014-06-04 02:22:38 -04:00
|
|
|
printf("', %llu, %lu, %lu, %lu) =",
|
|
|
|
(unsigned long long) N, (unsigned long) r, (unsigned long) p,
|
|
|
|
(unsigned long) olen);
|
2014-06-03 06:15:39 -04:00
|
|
|
printf("\n");
|
2014-06-01 14:58:20 -04:00
|
|
|
|
|
|
|
// Print test result
|
2014-06-03 06:15:39 -04:00
|
|
|
for(i = 0; i < olen; ++i)
|
2014-06-01 14:58:20 -04:00
|
|
|
{
|
|
|
|
printf("%02x", data[i]);
|
|
|
|
printf((lineitems < lineitemsLimit)? " " : "\n");
|
|
|
|
lineitems = (lineitems < lineitemsLimit)? lineitems+1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2014-06-03 06:15:39 -04:00
|
|
|
test_vector(password1, salt1, N1, r1, p1);
|
|
|
|
test_vector(password2, salt2, N2, r2, p2);
|
|
|
|
test_vector(password3, salt3, N3, r3, p3);
|
|
|
|
test_vector(password4, salt4, N4, r4, p4);
|
2014-06-01 14:58:20 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|