diff --git a/test/default/pwhash.c b/test/default/pwhash.c index 73d0c64f..b90063fa 100644 --- a/test/default/pwhash.c +++ b/test/default/pwhash.c @@ -11,10 +11,12 @@ int main(void) { char str_out[crypto_pwhash_scryptxsalsa208sha256_STRBYTES]; + char str_out2[crypto_pwhash_scryptxsalsa208sha256_STRBYTES]; unsigned char out[OUT_LEN]; char out_hex[OUT_LEN * 2 + 1]; const char *salt = "[<~A 32-bytes salt for scrypt~>]"; const char *passwd = "Correct Horse Battery Staple"; + size_t i; if (crypto_pwhash_scryptxsalsa208sha256(out, sizeof out, passwd, strlen(passwd), @@ -28,10 +30,29 @@ int main(void) MEMLIMIT, OPSLIMIT) != 0) { printf("pwhash_str failure\n"); } + if (crypto_pwhash_scryptxsalsa208sha256_str(str_out2, passwd, strlen(passwd), + MEMLIMIT, OPSLIMIT) != 0) { + 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"); } + if (crypto_pwhash_scryptxsalsa208sha256_str_verify(str_out, passwd, + strlen(passwd)) != 0) { + printf("pwhash_str_verify failure\n"); + } + 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]--; + } printf("OK\n"); return 0;