Skip to content

Commit ab13da9

Browse files
committed
Merge branch 'PHP-7.2'
* PHP-7.2: ext/sodium: call crypto_pwhash_argon2id() explicitly if required ext/sodium: avoid tautological comparisons
2 parents cb39422 + 33b4405 commit ab13da9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

ext/sodium/libsodium.c

+18-7
Original file line numberDiff line numberDiff line change
@@ -1495,8 +1495,7 @@ PHP_FUNCTION(sodium_crypto_sign)
14951495
zend_throw_exception(sodium_exception_ce, "internal error", 0);
14961496
return;
14971497
}
1498-
if (msg_signed_real_len < 0U || msg_signed_real_len >= SIZE_MAX ||
1499-
msg_signed_real_len > msg_signed_len) {
1498+
if (msg_signed_real_len >= SIZE_MAX || msg_signed_real_len > msg_signed_len) {
15001499
zend_string_free(msg_signed);
15011500
zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
15021501
return;
@@ -1857,6 +1856,7 @@ PHP_FUNCTION(sodium_crypto_pwhash)
18571856
zend_long alg;
18581857
size_t passwd_len;
18591858
size_t salt_len;
1859+
int ret;
18601860

18611861
alg = (zend_long) crypto_pwhash_ALG_DEFAULT;
18621862
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "lssll|l",
@@ -1906,11 +1906,22 @@ PHP_FUNCTION(sodium_crypto_pwhash)
19061906
zend_error(E_WARNING, "maximum memory for the password hashing function is low");
19071907
}
19081908
hash = zend_string_alloc((size_t) hash_len, 0);
1909-
if (crypto_pwhash
1910-
((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
1911-
passwd, (unsigned long long) passwd_len, salt,
1912-
(unsigned long long) opslimit, (size_t) memlimit,
1913-
(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) {
19141925
zend_string_free(hash);
19151926
zend_throw_exception(sodium_exception_ce, "internal error", 0);
19161927
return;

0 commit comments

Comments
 (0)