From a894ec93f26db8f06a9414cd82d1070c5844a9ca Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 5 Aug 2017 20:56:59 +0200 Subject: [PATCH 1/2] Add crypto_pwhash_str_alg() --- src/libsodium/crypto_pwhash/crypto_pwhash.c | 18 ++++++++++++++++++ src/libsodium/include/sodium/crypto_pwhash.h | 6 ++++++ test/default/pwhash.c | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/src/libsodium/crypto_pwhash/crypto_pwhash.c b/src/libsodium/crypto_pwhash/crypto_pwhash.c index 3bccfe2b..bd4b14bf 100644 --- a/src/libsodium/crypto_pwhash/crypto_pwhash.c +++ b/src/libsodium/crypto_pwhash/crypto_pwhash.c @@ -2,6 +2,7 @@ #include #include +#include "core.h" #include "crypto_pwhash.h" int @@ -150,6 +151,23 @@ crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], opslimit, memlimit); } +int +crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES], + const char * const passwd, unsigned long long passwdlen, + unsigned long long opslimit, size_t memlimit, int alg) +{ + switch (alg) { + case crypto_pwhash_ALG_ARGON2I13: + return crypto_pwhash_argon2i_str(out, passwd, passwdlen, + opslimit, memlimit); + case crypto_pwhash_ALG_ARGON2ID13: + return crypto_pwhash_argon2id_str(out, passwd, passwdlen, + opslimit, memlimit); + default: + sodium_misuse(); + } +} + int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES], const char * const passwd, diff --git a/src/libsodium/include/sodium/crypto_pwhash.h b/src/libsodium/include/sodium/crypto_pwhash.h index 4a5309c4..da5f5461 100644 --- a/src/libsodium/include/sodium/crypto_pwhash.h +++ b/src/libsodium/include/sodium/crypto_pwhash.h @@ -107,6 +107,12 @@ int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], unsigned long long opslimit, size_t memlimit) __attribute__ ((warn_unused_result)); +SODIUM_EXPORT +int crypto_pwhash_str_alg(char out[crypto_pwhash_STRBYTES], + const char * const passwd, unsigned long long passwdlen, + unsigned long long opslimit, size_t memlimit, int alg) + __attribute__ ((warn_unused_result)); + SODIUM_EXPORT int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES], const char * const passwd, diff --git a/test/default/pwhash.c b/test/default/pwhash.c index 2a6fef79..dd4de052 100644 --- a/test/default/pwhash.c +++ b/test/default/pwhash.c @@ -349,6 +349,14 @@ main(void) "password", strlen("password")) != -1 || errno != EINVAL) { printf("pwhash_str_verify(invalid(11)) failure\n"); } + + assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT, + crypto_pwhash_ALG_ARGON2I13) == 0); + assert(crypto_pwhash_argon2i_str_verify(str_out, "test", 4) == 0); + assert(crypto_pwhash_str_alg(str_out, "test", 4, OPSLIMIT, MEMLIMIT, + crypto_pwhash_ALG_ARGON2ID13) == 0); + assert(crypto_pwhash_argon2id_str_verify(str_out, "test", 4) == 0); + assert(crypto_pwhash_bytes_min() > 0U); assert(crypto_pwhash_bytes_max() > crypto_pwhash_bytes_min()); assert(crypto_pwhash_passwd_max() > crypto_pwhash_passwd_min()); From 9e0e77a3fd2f5b7cd99bf7989c462ab01670a9fb Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 5 Aug 2017 20:58:11 +0200 Subject: [PATCH 2/2] Update ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2ccfc117..ce502497 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,8 @@ AVX* when temperature/power consumption is a concern. - `crypto_kx_*()` now aborts if called with no non-NULL pointers to store keys to. - SSE2 implementations of `crypto_verify_*()` have been added. + - Passwords can be hashed using a specific algorithm with the new +`crypto_pwhash_str_alg()` function. * Version 1.0.13 - Javascript: the sumo builds now include all symbols. They were