Add a minimal test for crypto_pwhash

This commit is contained in:
Frank Denis 2014-05-07 23:54:55 -07:00
parent ee20da2cd7
commit 299ff0ceb3
4 changed files with 48 additions and 0 deletions

1
.gitignore vendored
View File

@ -79,6 +79,7 @@ test/default/hash3
test/default/onetimeauth
test/default/onetimeauth2
test/default/onetimeauth7
test/default/pwhash
test/default/randombytes
test/default/scalarmult
test/default/scalarmult2

View File

@ -29,6 +29,7 @@ EXTRA_DIST = \
onetimeauth.exp \
onetimeauth2.exp \
onetimeauth7.exp \
pwhash.exp \
scalarmult.exp \
scalarmult2.exp \
scalarmult5.exp \
@ -82,6 +83,7 @@ DISTCLEANFILES = \
onetimeauth.res \
onetimeauth2.res \
onetimeauth7.res \
pwhash.res \
scalarmult.res \
scalarmult2.res \
scalarmult5.res \
@ -142,6 +144,7 @@ TESTS_TARGETS = \
onetimeauth \
onetimeauth2 \
onetimeauth7 \
pwhash \
randombytes \
scalarmult \
scalarmult2 \
@ -253,6 +256,9 @@ onetimeauth2_LDADD = $(TESTS_LDADD)
onetimeauth7_SOURCE = cmptest.h onetimeauth7.c
onetimeauth7_LDADD = $(TESTS_LDADD)
pwhash_SOURCE = cmptest.h pwhash.c
pwhash_LDADD = $(TESTS_LDADD)
randombytes_SOURCE = randombytes.c
randombytes_LDADD = $(TESTS_LDADD)

39
test/default/pwhash.c Normal file
View File

@ -0,0 +1,39 @@
#include <stdio.h>
#include <string.h>
#define TEST_NAME "pwhash"
#include "cmptest.h"
#define OUT_LEN 128
#define MEMLIMIT 10000000
#define OPSLIMIT 1000000
int main(void)
{
char str_out[crypto_pwhash_scryptxsalsa208sha256_STRBYTES];
unsigned char out[OUT_LEN];
char out_hex[OUT_LEN * 2 + 1];
const char *salt = "0a2c4e63%2AxC+E7";
const char *passwd = "Correct Horse Battery Staple";
if (crypto_pwhash_scryptxsalsa208sha256(out, sizeof out,
passwd, strlen(passwd),
(const unsigned char *) salt,
MEMLIMIT, OPSLIMIT) != 0) {
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),
MEMLIMIT, OPSLIMIT) != 0) {
printf("pwhash_str failure\n");
}
puts(str_out);
if (crypto_pwhash_scryptxsalsa208sha256_str_verify(str_out, passwd,
strlen(passwd)) != 0) {
printf("pwhash_str_verify failure\n");
}
printf("OK\n");
return 0;
}

2
test/default/pwhash.exp Normal file
View File

@ -0,0 +1,2 @@
out_hex: [31aaf64490f0afc74344fbfaf0d611642feaa03a96d56154058559359eacc358c111f45a3983a469eccf0b524ac9902ac57d0ac19701a07877523a3d038bfb8207a4695864dc1fbfe5fa1b9e9103472ce89de027fc41cf9a3a5149390c4e4c902c387e59a52f5e6bb5acb9b3e82ab0847d8b0284e3b46e16cf59e69a9e576457]
OK