Skip to content

Commit 33b4405

Browse files
committed
ext/sodium: call crypto_pwhash_argon2id() explicitly if required
1 parent 47d7539 commit 33b4405

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

ext/sodium/libsodium.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,7 @@ PHP_FUNCTION(sodium_crypto_pwhash)
18561856
zend_long alg;
18571857
size_t passwd_len;
18581858
size_t salt_len;
1859+
int ret;
18591860

18601861
alg = (zend_long) crypto_pwhash_ALG_DEFAULT;
18611862
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "lssll|l",
@@ -1905,11 +1906,22 @@ PHP_FUNCTION(sodium_crypto_pwhash)
19051906
zend_error(E_WARNING, "maximum memory for the password hashing function is low");
19061907
}
19071908
hash = zend_string_alloc((size_t) hash_len, 0);
1908-
if (crypto_pwhash
1909-
((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
1910-
passwd, (unsigned long long) passwd_len, salt,
1911-
(unsigned long long) opslimit, (size_t) memlimit,
1912-
(int) alg) != 0) {
1909+
ret = -1;
1910+
# ifdef crypto_pwhash_ALG_ARGON2ID13
1911+
if (alg == crypto_pwhash_ALG_ARGON2ID13) {
1912+
ret = crypto_pwhash_argon2id
1913+
((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
1914+
passwd, (unsigned long long) passwd_len, salt,
1915+
(unsigned long long) opslimit, (size_t) memlimit, (int) alg);
1916+
}
1917+
# endif
1918+
if (ret == -1) {
1919+
ret = crypto_pwhash
1920+
((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
1921+
passwd, (unsigned long long) passwd_len, salt,
1922+
(unsigned long long) opslimit, (size_t) memlimit, (int) alg);
1923+
}
1924+
if (ret != 0) {
19131925
zend_string_free(hash);
19141926
zend_throw_exception(sodium_exception_ce, "internal error", 0);
19151927
return;

0 commit comments

Comments
 (0)