diff --git a/src/libsodium/crypto_pwhash/crypto_pwhash.c b/src/libsodium/crypto_pwhash/crypto_pwhash.c index b65b7209..c2e7b22c 100644 --- a/src/libsodium/crypto_pwhash/crypto_pwhash.c +++ b/src/libsodium/crypto_pwhash/crypto_pwhash.c @@ -1,6 +1,20 @@ +#include + #include "crypto_pwhash.h" +int +crypto_pwhash_alg_argon2i13(void) +{ + return crypto_pwhash_ALG_ARGON2I13; +} + +int +crypto_pwhash_alg_default(void) +{ + return crypto_pwhash_ALG_ARGON2I13; +} + size_t crypto_pwhash_saltbytes(void) { @@ -59,10 +73,12 @@ 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, - const struct crypto_pwhash_options *options) + unsigned long long opslimit, size_t memlimit, int alg) { - (void) options; + if (alg != crypto_pwhash_ALG_ARGON2I13) { + errno = EINVAL; + return -1; + } return crypto_pwhash_argon2i(out, outlen, passwd, passwdlen, salt, opslimit, memlimit); } diff --git a/src/libsodium/include/sodium/crypto_pwhash.h b/src/libsodium/include/sodium/crypto_pwhash.h index 78d01928..a5048d8c 100644 --- a/src/libsodium/include/sodium/crypto_pwhash.h +++ b/src/libsodium/include/sodium/crypto_pwhash.h @@ -13,6 +13,14 @@ extern "C" { #endif +#define crypto_pwhash_ALG_ARGON2I13 1 +SODIUM_EXPORT +int crypto_pwhash_alg_argon2i13(void); + +#define crypto_pwhash_ALG_DEFAULT crypto_pwhash_ALG_ARGON2I13 +SODIUM_EXPORT +int crypto_pwhash_alg_default(void); + #define crypto_pwhash_SALTBYTES crypto_pwhash_argon2i_SALTBYTES SODIUM_EXPORT size_t crypto_pwhash_saltbytes(void); @@ -49,14 +57,11 @@ 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, - const crypto_pwhash_options *options) + unsigned long long opslimit, size_t memlimit, int alg) __attribute__ ((warn_unused_result)); SODIUM_EXPORT diff --git a/test/default/pwhash.c b/test/default/pwhash.c index 2e04f8df..708c09db 100644 --- a/test/default/pwhash.c +++ b/test/default/pwhash.c @@ -92,7 +92,7 @@ static void tv(void) if (crypto_pwhash(out, (unsigned long long) tests[i].outlen, passwd, tests[i].passwdlen, (const unsigned char *) salt, tests[i].opslimit, - tests[i].memlimit, NULL) != 0) { + tests[i].memlimit, crypto_pwhash_alg_default()) != 0) { printf("[tv] pwhash failure (maybe intentional): [%u]\n", (unsigned int) i); continue; } @@ -142,7 +142,7 @@ static void tv2(void) if (crypto_pwhash(out, (unsigned long long) tests[i].outlen, passwd, tests[i].passwdlen, (const unsigned char *) salt, tests[i].opslimit, - tests[i].memlimit, NULL) != 0) { + tests[i].memlimit, crypto_pwhash_alg_default()) != 0) { printf("[tv2] pwhash failure: [%u]\n", (unsigned int) i); continue; } @@ -151,23 +151,27 @@ static void tv2(void) } while (++i < (sizeof tests) / (sizeof tests[0])); if (crypto_pwhash(out, sizeof out, "password", strlen("password"), - salt, 3, 1, NULL) != -1) { + salt, 3, 1ULL << 12, 0) != -1) { + printf("[tv2] pwhash should have failed (0)\n"); + } + if (crypto_pwhash(out, sizeof out, "password", strlen("password"), + salt, 3, 1, crypto_pwhash_alg_default()) != -1) { printf("[tv2] pwhash should have failed (1)\n"); } if (crypto_pwhash(out, sizeof out, "password", strlen("password"), - salt, 3, 1ULL << 12, NULL) != -1) { + salt, 3, 1ULL << 12, crypto_pwhash_alg_default()) != -1) { printf("[tv2] pwhash should have failed (2)\n"); } if (crypto_pwhash(out, sizeof out, "password", strlen("password"), - salt, 2, 1ULL << 12, NULL) != -1) { + salt, 2, 1ULL << 12, crypto_pwhash_alg_default()) != -1) { printf("[tv2] pwhash should have failed (3)\n"); } if (crypto_pwhash(out, 0x100000000ULL, "password", strlen("password"), - salt, 3, 1ULL << 12, NULL) != -1) { + salt, 3, 1ULL << 12, crypto_pwhash_alg_default()) != -1) { printf("[tv2] pwhash with a long output length should have failed\n"); } if (crypto_pwhash(out, sizeof out, "password", 0x100000000ULL, - salt, 3, 1ULL << 12, NULL) != -1) { + salt, 3, 1ULL << 12, crypto_pwhash_alg_default()) != -1) { printf("[tv2] pwhash with a long password length should have failed\n"); } } @@ -349,6 +353,8 @@ int main(void) crypto_pwhash_memlimit_moderate()); assert(crypto_pwhash_argon2i_memlimit_sensitive() == crypto_pwhash_memlimit_sensitive()); + assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_ALG_ARGON2I13); + assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_alg_default()); sodium_free(salt); sodium_free(str_out);