summaryrefslogtreecommitdiff
path: root/ext/sodium
diff options
context:
space:
mode:
authorFrank Denis <github@pureftpd.org>2017-09-26 18:09:00 +0200
committerFrank Denis <github@pureftpd.org>2017-09-26 18:09:00 +0200
commit33b4405d84539b507b2786a85560fde638d4f643 (patch)
treece47ce2678a297ca527b0c13751bf09b5c3f6fdc /ext/sodium
parent47d75394c9c1baedfffb79201ee7750e74171a31 (diff)
downloadphp-git-33b4405d84539b507b2786a85560fde638d4f643.tar.gz
ext/sodium: call crypto_pwhash_argon2id() explicitly if required
Diffstat (limited to 'ext/sodium')
-rw-r--r--ext/sodium/libsodium.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c
index 6f8b6e80f3..102714ab1a 100644
--- a/ext/sodium/libsodium.c
+++ b/ext/sodium/libsodium.c
@@ -1856,6 +1856,7 @@ PHP_FUNCTION(sodium_crypto_pwhash)
zend_long alg;
size_t passwd_len;
size_t salt_len;
+ int ret;
alg = (zend_long) crypto_pwhash_ALG_DEFAULT;
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "lssll|l",
@@ -1905,11 +1906,22 @@ PHP_FUNCTION(sodium_crypto_pwhash)
zend_error(E_WARNING, "maximum memory for the password hashing function is low");
}
hash = zend_string_alloc((size_t) hash_len, 0);
- if (crypto_pwhash
- ((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
- passwd, (unsigned long long) passwd_len, salt,
- (unsigned long long) opslimit, (size_t) memlimit,
- (int) alg) != 0) {
+ ret = -1;
+# ifdef crypto_pwhash_ALG_ARGON2ID13
+ if (alg == crypto_pwhash_ALG_ARGON2ID13) {
+ ret = crypto_pwhash_argon2id
+ ((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
+ passwd, (unsigned long long) passwd_len, salt,
+ (unsigned long long) opslimit, (size_t) memlimit, (int) alg);
+ }
+# endif
+ if (ret == -1) {
+ ret = crypto_pwhash
+ ((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
+ passwd, (unsigned long long) passwd_len, salt,
+ (unsigned long long) opslimit, (size_t) memlimit, (int) alg);
+ }
+ if (ret != 0) {
zend_string_free(hash);
zend_throw_exception(sodium_exception_ce, "internal error", 0);
return;