Use sodium_malloc() in the pwhash test.

This commit is contained in:
Frank Denis 2015-05-01 17:35:45 +02:00
parent e0d1d042b7
commit 1b0e51da5e

View File

@ -276,8 +276,8 @@ static void tv3(void)
passwd = (char *) sodium_malloc(strlen(tests[i].passwd) + 1U);
assert(passwd != NULL);
memcpy(passwd, tests[i].passwd, strlen(tests[i].passwd) + 1U);
if (crypto_pwhash_scryptsalsa208sha256_str_verify(
out, passwd, strlen(passwd)) != 0) {
if (crypto_pwhash_scryptsalsa208sha256_str_verify
(out, passwd, strlen(passwd)) != 0) {
printf("pwhash_str failure: [%u]\n", (unsigned int)i);
}
sodium_free(out);
@ -287,14 +287,22 @@ static void tv3(void)
int main(void)
{
char str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES];
char str_out2[crypto_pwhash_scryptsalsa208sha256_STRBYTES];
const char *salt = "[<~A 32-bytes salt for scrypt~>]";
char *str_out;
char *str_out2;
char *salt;
const char *passwd = "Correct Horse Battery Staple";
tv();
tv2();
tv3();
salt = (char *)
sodium_malloc(crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
str_out = (char *)
sodium_malloc(crypto_pwhash_scryptsalsa208sha256_STRBYTES);
str_out2 = (char *)
sodium_malloc(crypto_pwhash_scryptsalsa208sha256_STRBYTES);
memcpy(salt, "[<~A 32-bytes salt for scrypt~>]",
crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
if (crypto_pwhash_scryptsalsa208sha256_str(str_out, passwd, strlen(passwd),
OPSLIMIT, MEMLIMIT) != 0) {
printf("pwhash_str failure\n");
@ -321,6 +329,7 @@ int main(void)
}
str_out[14]--;
assert(str_out[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1U] == 0);
assert(crypto_pwhash_scryptsalsa208sha256_saltbytes() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_strbytes() > 1U);
assert(crypto_pwhash_scryptsalsa208sha256_strbytes() >
@ -330,6 +339,10 @@ int main(void)
assert(crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive() > 0U);
assert(crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive() > 0U);
sodium_free(salt);
sodium_free(str_out);
sodium_free(str_out2);
printf("OK\n");
return 0;