com php-src: ext/sodium: call crypto_pwhash_argon2id( ) explicitly if required: ext/sodium/libsodium.c
| From: | Frank Denis | Date: | Tue, 26 Sep 2017 16:09:00 +0000 |
| Subject: | com php-src: ext/sodium: call crypto_pwhash_argon2id( ) explicitly if required: ext/sodium/libsodium.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99549@lists.php.net to get a copy of this message | ||
Commit: 33b4405d84539b507b2786a85560fde638d4f643
Author: Frank Denis <github@pureftpd.org> Tue, 26 Sep 2017 18:09:00 +0200
Parents: 47d75394c9c1baedfffb79201ee7750e74171a31
Branches: PHP-7.2
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=33b4405d84539b507b2786a85560fde638d4f643
Log:
ext/sodium: call crypto_pwhash_argon2id() explicitly if required
Changed paths:
M ext/sodium/libsodium.c
Diff:
diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c
index 6f8b6e8..102714a 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;