diff --git a/.gitignore b/.gitignore index 30dd5bab..7b9dbba1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/test/default/Makefile.am b/test/default/Makefile.am index 4343d237..8b9e1130 100644 --- a/test/default/Makefile.am +++ b/test/default/Makefile.am @@ -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) diff --git a/test/default/pwhash.c b/test/default/pwhash.c new file mode 100644 index 00000000..4228c228 --- /dev/null +++ b/test/default/pwhash.c @@ -0,0 +1,39 @@ +#include +#include + +#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; +} diff --git a/test/default/pwhash.exp b/test/default/pwhash.exp new file mode 100644 index 00000000..f0b0d47a --- /dev/null +++ b/test/default/pwhash.exp @@ -0,0 +1,2 @@ +out_hex: [31aaf64490f0afc74344fbfaf0d611642feaa03a96d56154058559359eacc358c111f45a3983a469eccf0b524ac9902ac57d0ac19701a07877523a3d038bfb8207a4695864dc1fbfe5fa1b9e9103472ce89de027fc41cf9a3a5149390c4e4c902c387e59a52f5e6bb5acb9b3e82ab0847d8b0284e3b46e16cf59e69a9e576457] +OK