2014-05-07 23:54:55 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define TEST_NAME "pwhash"
|
|
|
|
#include "cmptest.h"
|
|
|
|
|
|
|
|
#define OUT_LEN 128
|
|
|
|
#define OPSLIMIT 1000000
|
2014-05-12 12:34:41 -07:00
|
|
|
#define MEMLIMIT 10000000
|
2014-05-07 23:54:55 -07:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
char str_out[crypto_pwhash_scryptxsalsa208sha256_STRBYTES];
|
2014-05-12 11:26:39 -07:00
|
|
|
char str_out2[crypto_pwhash_scryptxsalsa208sha256_STRBYTES];
|
2014-05-07 23:54:55 -07:00
|
|
|
unsigned char out[OUT_LEN];
|
|
|
|
char out_hex[OUT_LEN * 2 + 1];
|
2014-05-08 20:39:14 -07:00
|
|
|
const char *salt = "[<~A 32-bytes salt for scrypt~>]";
|
2014-05-07 23:54:55 -07:00
|
|
|
const char *passwd = "Correct Horse Battery Staple";
|
2014-05-12 11:26:39 -07:00
|
|
|
size_t i;
|
2014-05-07 23:54:55 -07:00
|
|
|
|
|
|
|
if (crypto_pwhash_scryptxsalsa208sha256(out, sizeof out,
|
|
|
|
passwd, strlen(passwd),
|
|
|
|
(const unsigned char *) salt,
|
2014-05-12 12:34:41 -07:00
|
|
|
OPSLIMIT, MEMLIMIT) != 0) {
|
2014-05-07 23:54:55 -07:00
|
|
|
printf("pwhash failure\n");
|
|
|
|
}
|
|
|
|
sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
|
|
|
|
printf("out_hex: [%s]\n", out_hex);
|
|
|
|
if (crypto_pwhash_scryptxsalsa208sha256_str(str_out, passwd, strlen(passwd),
|
2014-05-12 12:34:41 -07:00
|
|
|
OPSLIMIT, MEMLIMIT) != 0) {
|
2014-05-07 23:54:55 -07:00
|
|
|
printf("pwhash_str failure\n");
|
|
|
|
}
|
2014-05-12 11:26:39 -07:00
|
|
|
if (crypto_pwhash_scryptxsalsa208sha256_str(str_out2, passwd, strlen(passwd),
|
2014-05-12 12:34:41 -07:00
|
|
|
OPSLIMIT, MEMLIMIT) != 0) {
|
2014-05-12 11:26:39 -07:00
|
|
|
printf("pwhash_str(2) failure\n");
|
|
|
|
}
|
|
|
|
if (strcmp(str_out, str_out2) == 0) {
|
|
|
|
printf("pwhash_str doesn't generate different salts\n");
|
|
|
|
}
|
|
|
|
if (crypto_pwhash_scryptxsalsa208sha256_str_verify(str_out, passwd,
|
|
|
|
strlen(passwd)) != 0) {
|
|
|
|
printf("pwhash_str_verify failure\n");
|
|
|
|
}
|
2014-05-07 23:54:55 -07:00
|
|
|
if (crypto_pwhash_scryptxsalsa208sha256_str_verify(str_out, passwd,
|
|
|
|
strlen(passwd)) != 0) {
|
|
|
|
printf("pwhash_str_verify failure\n");
|
|
|
|
}
|
2014-05-12 11:26:39 -07:00
|
|
|
for (i = 14U; i < sizeof str_out; i++) {
|
|
|
|
str_out[i]++;
|
|
|
|
if (crypto_pwhash_scryptxsalsa208sha256_str_verify(str_out, passwd,
|
|
|
|
strlen(passwd)) == 0) {
|
|
|
|
printf("pwhash_str_verify(2) failure\n");
|
|
|
|
}
|
|
|
|
str_out[i]--;
|
|
|
|
}
|
2014-05-07 23:54:55 -07:00
|
|
|
printf("OK\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|