@@ -83,11 +83,11 @@ static struct mhash_bc_entry mhash_to_hash[MHASH_NUM_ALGOS] = {
83
83
84
84
/* Hash Registry Access */
85
85
86
- PHP_HASH_API const php_hash_ops * php_hash_fetch_ops (const char * algo , size_t algo_len ) /* {{{ */
86
+ PHP_HASH_API const php_hash_ops * php_hash_fetch_ops (zend_string * algo ) /* {{{ */
87
87
{
88
- char * lower = zend_str_tolower_dup (algo , algo_len );
89
- php_hash_ops * ops = zend_hash_str_find_ptr (& php_hash_hashtable , lower , algo_len );
90
- efree (lower );
88
+ zend_string * lower = zend_string_tolower (algo );
89
+ php_hash_ops * ops = zend_hash_find_ptr (& php_hash_hashtable , lower );
90
+ zend_string_release (lower );
91
91
92
92
return ops ;
93
93
}
@@ -115,21 +115,21 @@ PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_c
115
115
116
116
static void php_hash_do_hash (INTERNAL_FUNCTION_PARAMETERS , int isfilename , zend_bool raw_output_default ) /* {{{ */
117
117
{
118
- zend_string * digest ;
119
- char * algo , * data ;
120
- size_t algo_len , data_len ;
118
+ zend_string * digest , * algo ;
119
+ char * data ;
120
+ size_t data_len ;
121
121
zend_bool raw_output = raw_output_default ;
122
122
const php_hash_ops * ops ;
123
123
void * context ;
124
124
php_stream * stream = NULL ;
125
125
126
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "ss |b" , & algo , & algo_len , & data , & data_len , & raw_output ) == FAILURE ) {
126
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Ss |b" , & algo , & data , & data_len , & raw_output ) == FAILURE ) {
127
127
RETURN_THROWS ();
128
128
}
129
129
130
- ops = php_hash_fetch_ops (algo , algo_len );
130
+ ops = php_hash_fetch_ops (algo );
131
131
if (!ops ) {
132
- php_error_docref (NULL , E_WARNING , "Unknown hashing algorithm: %s" , algo );
132
+ php_error_docref (NULL , E_WARNING , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
133
133
RETURN_FALSE ;
134
134
}
135
135
if (isfilename ) {
@@ -236,27 +236,27 @@ static inline void php_hash_hmac_round(unsigned char *final, const php_hash_ops
236
236
237
237
static void php_hash_do_hash_hmac (INTERNAL_FUNCTION_PARAMETERS , int isfilename , zend_bool raw_output_default ) /* {{{ */
238
238
{
239
- zend_string * digest ;
240
- char * algo , * data , * key ;
239
+ zend_string * digest , * algo ;
240
+ char * data , * key ;
241
241
unsigned char * K ;
242
- size_t algo_len , data_len , key_len ;
242
+ size_t data_len , key_len ;
243
243
zend_bool raw_output = raw_output_default ;
244
244
const php_hash_ops * ops ;
245
245
void * context ;
246
246
php_stream * stream = NULL ;
247
247
248
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sss |b" , & algo , & algo_len , & data , & data_len ,
248
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Sss |b" , & algo , & data , & data_len ,
249
249
& key , & key_len , & raw_output ) == FAILURE ) {
250
250
RETURN_THROWS ();
251
251
}
252
252
253
- ops = php_hash_fetch_ops (algo , algo_len );
253
+ ops = php_hash_fetch_ops (algo );
254
254
if (!ops ) {
255
- zend_throw_error (NULL , "Unknown hashing algorithm: %s" , algo );
255
+ zend_throw_error (NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
256
256
RETURN_THROWS ();
257
257
}
258
258
else if (!ops -> is_crypto ) {
259
- zend_throw_error (NULL , "Non-cryptographic hashing algorithm: %s" , algo );
259
+ zend_throw_error (NULL , "Non-cryptographic hashing algorithm: %s" , ZSTR_VAL ( algo ) );
260
260
RETURN_THROWS ();
261
261
}
262
262
@@ -356,7 +356,7 @@ PHP_FUNCTION(hash_init)
356
356
RETURN_THROWS ();
357
357
}
358
358
359
- ops = php_hash_fetch_ops (ZSTR_VAL ( algo ), ZSTR_LEN ( algo ) );
359
+ ops = php_hash_fetch_ops (algo );
360
360
if (!ops ) {
361
361
zend_throw_error (NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL (algo ));
362
362
RETURN_THROWS ();
@@ -645,7 +645,7 @@ PHP_FUNCTION(hash_hkdf)
645
645
RETURN_THROWS ();
646
646
}
647
647
648
- ops = php_hash_fetch_ops (ZSTR_VAL ( algo ), ZSTR_LEN ( algo ) );
648
+ ops = php_hash_fetch_ops (algo );
649
649
if (!ops ) {
650
650
zend_throw_error (NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL (algo ));
651
651
RETURN_THROWS ();
@@ -732,26 +732,26 @@ Generate a PBKDF2 hash of the given password and salt
732
732
Returns lowercase hexits by default */
733
733
PHP_FUNCTION (hash_pbkdf2 )
734
734
{
735
- zend_string * returnval ;
736
- char * algo , * salt , * pass = NULL ;
735
+ zend_string * returnval , * algo ;
736
+ char * salt , * pass = NULL ;
737
737
unsigned char * computed_salt , * digest , * temp , * result , * K1 , * K2 = NULL ;
738
738
zend_long loops , i , j , iterations , digest_length = 0 , length = 0 ;
739
- size_t algo_len , pass_len , salt_len = 0 ;
739
+ size_t pass_len , salt_len = 0 ;
740
740
zend_bool raw_output = 0 ;
741
741
const php_hash_ops * ops ;
742
742
void * context ;
743
743
744
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sssl |lb" , & algo , & algo_len , & pass , & pass_len , & salt , & salt_len , & iterations , & length , & raw_output ) == FAILURE ) {
744
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Sssl |lb" , & algo , & pass , & pass_len , & salt , & salt_len , & iterations , & length , & raw_output ) == FAILURE ) {
745
745
RETURN_THROWS ();
746
746
}
747
747
748
- ops = php_hash_fetch_ops (algo , algo_len );
748
+ ops = php_hash_fetch_ops (algo );
749
749
if (!ops ) {
750
- zend_throw_error (NULL , "Unknown hashing algorithm: %s" , algo );
750
+ zend_throw_error (NULL , "Unknown hashing algorithm: %s" , ZSTR_VAL ( algo ) );
751
751
RETURN_THROWS ();
752
752
}
753
753
else if (!ops -> is_crypto ) {
754
- zend_throw_error (NULL , "Non-cryptographic hashing algorithm: %s" , algo );
754
+ zend_throw_error (NULL , "Non-cryptographic hashing algorithm: %s" , ZSTR_VAL ( algo ) );
755
755
RETURN_THROWS ();
756
756
}
757
757
@@ -1035,7 +1035,7 @@ PHP_FUNCTION(mhash_get_block_size)
1035
1035
if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS ) {
1036
1036
struct mhash_bc_entry algorithm_lookup = mhash_to_hash [algorithm ];
1037
1037
if (algorithm_lookup .mhash_name ) {
1038
- const php_hash_ops * ops = php_hash_fetch_ops ( algorithm_lookup .hash_name , strlen (algorithm_lookup .hash_name ));
1038
+ const php_hash_ops * ops = zend_hash_str_find_ptr ( & php_hash_hashtable , algorithm_lookup .hash_name , strlen (algorithm_lookup .hash_name ));
1039
1039
if (ops ) {
1040
1040
RETVAL_LONG (ops -> digest_size );
1041
1041
}
@@ -1078,7 +1078,7 @@ PHP_FUNCTION(mhash_keygen_s2k)
1078
1078
if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS ) {
1079
1079
struct mhash_bc_entry algorithm_lookup = mhash_to_hash [algorithm ];
1080
1080
if (algorithm_lookup .mhash_name ) {
1081
- const php_hash_ops * ops = php_hash_fetch_ops ( algorithm_lookup .hash_name , strlen (algorithm_lookup .hash_name ));
1081
+ const php_hash_ops * ops = zend_hash_str_find_ptr ( & php_hash_hashtable , algorithm_lookup .hash_name , strlen (algorithm_lookup .hash_name ));
1082
1082
if (ops ) {
1083
1083
unsigned char null = '\0' ;
1084
1084
void * context ;
0 commit comments