vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c in rbnacl-libsodium-1.0.13 vs vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c in rbnacl-libsodium-1.0.15

- old
+ new

@@ -1,9 +1,10 @@ #include <errno.h> #include <string.h> +#include "core.h" #include "crypto_pwhash.h" int crypto_pwhash_alg_argon2i13(void) { @@ -17,11 +18,11 @@ } int crypto_pwhash_alg_default(void) { - return crypto_pwhash_ALG_ARGON2I13; + return crypto_pwhash_ALG_DEFAULT; } size_t crypto_pwhash_bytes_min(void) { @@ -129,14 +130,16 @@ const char * const passwd, unsigned long long passwdlen, const unsigned char * const salt, unsigned long long opslimit, size_t memlimit, int alg) { switch (alg) { - case crypto_pwhash_ALG_ARGON2ID13: case crypto_pwhash_ALG_ARGON2I13: return crypto_pwhash_argon2i(out, outlen, passwd, passwdlen, salt, opslimit, memlimit, alg); + case crypto_pwhash_ALG_ARGON2ID13: + return crypto_pwhash_argon2id(out, outlen, passwd, passwdlen, salt, + opslimit, memlimit, alg); default: errno = EINVAL; return -1; } } @@ -144,15 +147,32 @@ int crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], const char * const passwd, unsigned long long passwdlen, unsigned long long opslimit, size_t memlimit) { - return crypto_pwhash_argon2i_str(out, passwd, passwdlen, - opslimit, memlimit); + return crypto_pwhash_argon2id_str(out, passwd, passwdlen, + 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); + } + sodium_misuse(); + /* NOTREACHED */ +} + +int crypto_pwhash_str_verify(const char str[crypto_pwhash_STRBYTES], const char * const passwd, unsigned long long passwdlen) { if (strncmp(str, crypto_pwhash_argon2id_STRPREFIX, @@ -160,9 +180,26 @@ return crypto_pwhash_argon2id_str_verify(str, passwd, passwdlen); } if (strncmp(str, crypto_pwhash_argon2i_STRPREFIX, sizeof crypto_pwhash_argon2i_STRPREFIX - 1) == 0) { return crypto_pwhash_argon2i_str_verify(str, passwd, passwdlen); + } + errno = EINVAL; + + return -1; +} + +int +crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES], + unsigned long long opslimit, size_t memlimit) +{ + if (strncmp(str, crypto_pwhash_argon2id_STRPREFIX, + sizeof crypto_pwhash_argon2id_STRPREFIX - 1) == 0) { + return crypto_pwhash_argon2id_str_needs_rehash(str, opslimit, memlimit); + } + if (strncmp(str, crypto_pwhash_argon2i_STRPREFIX, + sizeof crypto_pwhash_argon2i_STRPREFIX - 1) == 0) { + return crypto_pwhash_argon2i_str_needs_rehash(str, opslimit, memlimit); } errno = EINVAL; return -1; }