@@ -1495,8 +1495,7 @@ PHP_FUNCTION(sodium_crypto_sign)
1495
1495
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
1496
1496
return ;
1497
1497
}
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 ) {
1500
1499
zend_string_free (msg_signed );
1501
1500
zend_throw_exception (sodium_exception_ce , "arithmetic overflow" , 0 );
1502
1501
return ;
@@ -1857,6 +1856,7 @@ PHP_FUNCTION(sodium_crypto_pwhash)
1857
1856
zend_long alg ;
1858
1857
size_t passwd_len ;
1859
1858
size_t salt_len ;
1859
+ int ret ;
1860
1860
1861
1861
alg = (zend_long ) crypto_pwhash_ALG_DEFAULT ;
1862
1862
if (zend_parse_parameters_throw (ZEND_NUM_ARGS (), "lssll|l" ,
@@ -1906,11 +1906,22 @@ PHP_FUNCTION(sodium_crypto_pwhash)
1906
1906
zend_error (E_WARNING , "maximum memory for the password hashing function is low" );
1907
1907
}
1908
1908
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 ) {
1914
1925
zend_string_free (hash );
1915
1926
zend_throw_exception (sodium_exception_ce , "internal error" , 0 );
1916
1927
return ;
0 commit comments