Add support for optional parameters to future-proof crypto_pwhash()

This commit is contained in:
Frank Denis 2016-03-21 09:38:43 +01:00
parent 33f406892f
commit 359553f07d
3 changed files with 16 additions and 13 deletions

View File

@ -59,8 +59,10 @@ int
crypto_pwhash(unsigned char * const out, unsigned long long outlen,
const char * const passwd, unsigned long long passwdlen,
const unsigned char * const salt,
unsigned long long opslimit, size_t memlimit)
unsigned long long opslimit, size_t memlimit,
const struct crypto_pwhash_options *options)
{
(void) options;
return crypto_pwhash_argon2i(out, outlen, passwd, passwdlen, salt,
opslimit, memlimit);
}

View File

@ -49,11 +49,14 @@ size_t crypto_pwhash_opslimit_sensitive(void);
SODIUM_EXPORT
size_t crypto_pwhash_memlimit_sensitive(void);
typedef struct crypto_pwhash_options crypto_pwhash_options;
SODIUM_EXPORT
int crypto_pwhash(unsigned char * const out, unsigned long long outlen,
const char * const passwd, unsigned long long passwdlen,
const unsigned char * const salt,
unsigned long long opslimit, size_t memlimit)
unsigned long long opslimit, size_t memlimit,
const crypto_pwhash_options *options)
__attribute__ ((warn_unused_result));
SODIUM_EXPORT

View File

@ -89,11 +89,10 @@ static void tv(void)
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash(
out, (unsigned long long) tests[i].outlen,
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen,
passwd, tests[i].passwdlen,
(const unsigned char *) salt, tests[i].opslimit,
tests[i].memlimit) != 0) {
tests[i].memlimit, NULL) != 0) {
printf("[tv] pwhash failure (maybe intentional): [%u]\n", (unsigned int) i);
continue;
}
@ -140,11 +139,10 @@ static void tv2(void)
NULL, NULL);
sodium_hex2bin(salt, sizeof salt, tests[i].salt_hex,
strlen(tests[i].salt_hex), NULL, NULL, NULL);
if (crypto_pwhash(
out, (unsigned long long) tests[i].outlen,
if (crypto_pwhash(out, (unsigned long long) tests[i].outlen,
passwd, tests[i].passwdlen,
(const unsigned char *) salt, tests[i].opslimit,
tests[i].memlimit) != 0) {
tests[i].memlimit, NULL) != 0) {
printf("[tv2] pwhash failure: [%u]\n", (unsigned int) i);
continue;
}
@ -179,7 +177,7 @@ 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_argon2i_str_verify
if (crypto_pwhash_str_verify
(out, passwd, strlen(passwd)) != 0) {
printf("[tv3] pwhash_str failure (maybe intentional): [%u]\n", (unsigned int) i);
continue;