From: Frank Denis Date: Mon, 2 Oct 2017 19:54:50 +0000 (+0200) Subject: ext/sodium: add crypto_pwhash_str_needs_rehash() X-Git-Tag: php-7.2.0RC4~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d53e65125e63f522a5ad6dbbabeb7d5fc243dea;p=php ext/sodium: add crypto_pwhash_str_needs_rehash() Also properly define xchacha20poly1305_ietf_keygen() --- diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 07d2c5e038..6b192bc69d 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -240,9 +240,10 @@ const zend_function_entry sodium_functions[] = { PHP_FE(sodium_crypto_aead_chacha20poly1305_keygen, AI_None) PHP_FE(sodium_crypto_aead_chacha20poly1305_ietf_decrypt, AI_StringAndADAndNonceAndKey) PHP_FE(sodium_crypto_aead_chacha20poly1305_ietf_encrypt, AI_StringAndADAndNonceAndKey) + PHP_FE(sodium_crypto_aead_chacha20poly1305_ietf_keygen, AI_None) #ifdef crypto_aead_xchacha20poly1305_IETF_NPUBBYTES PHP_FE(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt, AI_StringAndADAndNonceAndKey) - PHP_FE(sodium_crypto_aead_chacha20poly1305_ietf_keygen, AI_None) + PHP_FE(sodium_crypto_aead_xchacha20poly1305_ietf_keygen, AI_None) PHP_FE(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt, AI_StringAndADAndNonceAndKey) #endif PHP_FE(sodium_crypto_auth, AI_StringAndKey) @@ -276,6 +277,9 @@ const zend_function_entry sodium_functions[] = { PHP_FE(sodium_crypto_pwhash_str, AI_PasswordAndOpsLimitAndMemLimit) PHP_FE(sodium_crypto_pwhash_str_verify, AI_HashAndPassword) #endif +#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) + PHP_FE(sodium_crypto_pwhash_str_needs_rehash, AI_PasswordAndOpsLimitAndMemLimit) +#endif #ifdef crypto_pwhash_scryptsalsa208sha256_SALTBYTES PHP_FE(sodium_crypto_pwhash_scryptsalsa208sha256, AI_LengthAndPasswordAndSaltAndOpsLimitAndMemLimit) PHP_FE(sodium_crypto_pwhash_scryptsalsa208sha256_str, AI_PasswordAndOpsLimitAndMemLimit) @@ -2025,6 +2029,25 @@ PHP_FUNCTION(sodium_crypto_pwhash_str) RETURN_STR(hash_str); } +#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) +PHP_FUNCTION(sodium_crypto_pwhash_str_needs_rehash) +{ + char *hash_str; + zend_long memlimit; + zend_long opslimit; + size_t hash_str_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll", + &hash_str, &hash_str_len) == FAILURE) { + return; + } + if (crypto_pwhash_str_needs_rehash(hash_str, opslimit, memlimit) == 0) { + RETURN_FALSE; + } + RETURN_TRUE; +} +#endif + PHP_FUNCTION(sodium_crypto_pwhash_str_verify) { char *hash_str; diff --git a/ext/sodium/php_libsodium.h b/ext/sodium/php_libsodium.h index d586a2b7dc..adfe40e8ae 100644 --- a/ext/sodium/php_libsodium.h +++ b/ext/sodium/php_libsodium.h @@ -83,6 +83,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256); PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str); PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify); PHP_FUNCTION(sodium_crypto_pwhash_str); +PHP_FUNCTION(sodium_crypto_pwhash_str_needs_rehash); PHP_FUNCTION(sodium_crypto_pwhash_str_verify); PHP_FUNCTION(sodium_crypto_scalarmult); PHP_FUNCTION(sodium_crypto_scalarmult_base);