@@ -349,7 +349,7 @@ PHP_HASH_API int php_hash_unserialize(php_hashcontext_object *hash, zend_long ma
349
349
/* Userspace */
350
350
351
351
static void php_hash_do_hash (
352
- zval * return_value , zend_string * algo , char * data , size_t data_len , zend_bool raw_output , bool isfilename
352
+ zval * return_value , zend_string * algo , char * data , size_t data_len , zend_bool raw_output , bool isfilename , HashTable * args
353
353
) /* {{{ */ {
354
354
zend_string * digest ;
355
355
const php_hash_ops * ops ;
@@ -374,7 +374,7 @@ static void php_hash_do_hash(
374
374
}
375
375
376
376
context = php_hash_alloc_context (ops );
377
- ops -> hash_init (context );
377
+ ops -> hash_init (context , args );
378
378
379
379
if (isfilename ) {
380
380
char buf [1024 ];
@@ -418,15 +418,17 @@ PHP_FUNCTION(hash)
418
418
char * data ;
419
419
size_t data_len ;
420
420
zend_bool raw_output = 0 ;
421
+ HashTable * args = NULL ;
421
422
422
- ZEND_PARSE_PARAMETERS_START (2 , 3 )
423
+ ZEND_PARSE_PARAMETERS_START (2 , 4 )
423
424
Z_PARAM_STR (algo )
424
425
Z_PARAM_STRING (data , data_len )
425
426
Z_PARAM_OPTIONAL
426
427
Z_PARAM_BOOL (raw_output )
428
+ Z_PARAM_ARRAY_HT (args )
427
429
ZEND_PARSE_PARAMETERS_END ();
428
430
429
- php_hash_do_hash (return_value , algo , data , data_len , raw_output , 0 );
431
+ php_hash_do_hash (return_value , algo , data , data_len , raw_output , 0 , args );
430
432
}
431
433
/* }}} */
432
434
@@ -438,15 +440,17 @@ PHP_FUNCTION(hash_file)
438
440
char * data ;
439
441
size_t data_len ;
440
442
zend_bool raw_output = 0 ;
443
+ HashTable * args = NULL ;
441
444
442
445
ZEND_PARSE_PARAMETERS_START (2 , 3 )
443
446
Z_PARAM_STR (algo )
444
447
Z_PARAM_STRING (data , data_len )
445
448
Z_PARAM_OPTIONAL
446
449
Z_PARAM_BOOL (raw_output )
450
+ Z_PARAM_ARRAY_HT (args )
447
451
ZEND_PARSE_PARAMETERS_END ();
448
452
449
- php_hash_do_hash (return_value , algo , data , data_len , raw_output , 1 );
453
+ php_hash_do_hash (return_value , algo , data , data_len , raw_output , 1 , args );
450
454
}
451
455
/* }}} */
452
456
@@ -468,7 +472,7 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *
468
472
memset (K , 0 , ops -> block_size );
469
473
if (key_len > ops -> block_size ) {
470
474
/* Reduce the key first */
471
- ops -> hash_init (context );
475
+ ops -> hash_init (context , NULL );
472
476
ops -> hash_update (context , key , key_len );
473
477
ops -> hash_final (K , context );
474
478
} else {
@@ -479,7 +483,7 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *
479
483
}
480
484
481
485
static inline void php_hash_hmac_round (unsigned char * final , const php_hash_ops * ops , void * context , const unsigned char * key , const unsigned char * data , const zend_long data_size ) {
482
- ops -> hash_init (context );
486
+ ops -> hash_init (context , NULL );
483
487
ops -> hash_update (context , key , ops -> block_size );
484
488
ops -> hash_update (context , data , data_size );
485
489
ops -> hash_final (final , context );
@@ -522,7 +526,7 @@ static void php_hash_do_hash_hmac(
522
526
if (isfilename ) {
523
527
char buf [1024 ];
524
528
ssize_t n ;
525
- ops -> hash_init (context );
529
+ ops -> hash_init (context , NULL );
526
530
ops -> hash_update (context , K , ops -> block_size );
527
531
while ((n = php_stream_read (stream , buf , sizeof (buf ))) > 0 ) {
528
532
ops -> hash_update (context , (unsigned char * ) buf , n );
@@ -605,8 +609,9 @@ PHP_FUNCTION(hash_init)
605
609
void * context ;
606
610
const php_hash_ops * ops ;
607
611
php_hashcontext_object * hash ;
612
+ HashTable * args = NULL ;
608
613
609
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "S|lS " , & algo , & options , & key ) == FAILURE ) {
614
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "S|lSh " , & algo , & options , & key , & args ) == FAILURE ) {
610
615
RETURN_THROWS ();
611
616
}
612
617
@@ -632,7 +637,7 @@ PHP_FUNCTION(hash_init)
632
637
hash = php_hashcontext_from_object (Z_OBJ_P (return_value ));
633
638
634
639
context = php_hash_alloc_context (ops );
635
- ops -> hash_init (context );
640
+ ops -> hash_init (context , args );
636
641
637
642
hash -> ops = ops ;
638
643
hash -> context = context ;
@@ -650,7 +655,7 @@ PHP_FUNCTION(hash_init)
650
655
ops -> hash_update (context , (unsigned char * ) ZSTR_VAL (key ), ZSTR_LEN (key ));
651
656
ops -> hash_final ((unsigned char * ) K , context );
652
657
/* Make the context ready to start over */
653
- ops -> hash_init (context );
658
+ ops -> hash_init (context , args );
654
659
} else {
655
660
memcpy (K , ZSTR_VAL (key ), ZSTR_LEN (key ));
656
661
}
@@ -792,7 +797,7 @@ PHP_FUNCTION(hash_final)
792
797
}
793
798
794
799
/* Feed this result into the outer hash */
795
- hash -> ops -> hash_init (hash -> context );
800
+ hash -> ops -> hash_init (hash -> context , NULL );
796
801
hash -> ops -> hash_update (hash -> context , hash -> key , hash -> ops -> block_size );
797
802
hash -> ops -> hash_update (hash -> context , (unsigned char * ) ZSTR_VAL (digest ), hash -> ops -> digest_size );
798
803
hash -> ops -> hash_final ((unsigned char * ) ZSTR_VAL (digest ), hash -> context );
@@ -915,7 +920,7 @@ PHP_FUNCTION(hash_hkdf)
915
920
context = php_hash_alloc_context (ops );
916
921
917
922
// Extract
918
- ops -> hash_init (context );
923
+ ops -> hash_init (context , NULL );
919
924
K = emalloc (ops -> block_size );
920
925
php_hash_hmac_prep_key (K , ops , context ,
921
926
(unsigned char * ) (salt ? ZSTR_VAL (salt ) : "" ), salt ? ZSTR_LEN (salt ) : 0 );
@@ -935,7 +940,7 @@ PHP_FUNCTION(hash_hkdf)
935
940
c [0 ] = (i & 0xFF );
936
941
937
942
php_hash_hmac_prep_key (K , ops , context , prk , ops -> digest_size );
938
- ops -> hash_init (context );
943
+ ops -> hash_init (context , NULL );
939
944
ops -> hash_update (context , K , ops -> block_size );
940
945
941
946
if (i > 1 ) {
@@ -980,8 +985,9 @@ PHP_FUNCTION(hash_pbkdf2)
980
985
zend_bool raw_output = 0 ;
981
986
const php_hash_ops * ops ;
982
987
void * context ;
988
+ HashTable * args ;
983
989
984
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Sssl|lb " , & algo , & pass , & pass_len , & salt , & salt_len , & iterations , & length , & raw_output ) == FAILURE ) {
990
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Sssl|lbh " , & algo , & pass , & pass_len , & salt , & salt_len , & iterations , & length , & raw_output , & args ) == FAILURE ) {
985
991
RETURN_THROWS ();
986
992
}
987
993
@@ -1007,7 +1013,7 @@ PHP_FUNCTION(hash_pbkdf2)
1007
1013
}
1008
1014
1009
1015
context = php_hash_alloc_context (ops );
1010
- ops -> hash_init (context );
1016
+ ops -> hash_init (context , args );
1011
1017
1012
1018
K1 = emalloc (ops -> block_size );
1013
1019
K2 = emalloc (ops -> block_size );
@@ -1212,7 +1218,7 @@ PHP_FUNCTION(mhash)
1212
1218
if (key ) {
1213
1219
php_hash_do_hash_hmac (return_value , algo , data , data_len , key , key_len , 1 , 0 );
1214
1220
} else {
1215
- php_hash_do_hash (return_value , algo , data , data_len , 1 , 0 );
1221
+ php_hash_do_hash (return_value , algo , data , data_len , 1 , 0 , NULL );
1216
1222
}
1217
1223
1218
1224
if (algo ) {
@@ -1319,13 +1325,13 @@ PHP_FUNCTION(mhash_keygen_s2k)
1319
1325
}
1320
1326
1321
1327
context = php_hash_alloc_context (ops );
1322
- ops -> hash_init (context );
1328
+ ops -> hash_init (context , NULL );
1323
1329
1324
1330
key = ecalloc (1 , times * block_size );
1325
1331
digest = emalloc (ops -> digest_size + 1 );
1326
1332
1327
1333
for (i = 0 ; i < times ; i ++ ) {
1328
- ops -> hash_init (context );
1334
+ ops -> hash_init (context , NULL );
1329
1335
1330
1336
for (j = 0 ;j < i ;j ++ ) {
1331
1337
ops -> hash_update (context , & null , 1 );
@@ -1392,7 +1398,7 @@ static zend_object *php_hashcontext_clone(zend_object *zobj) {
1392
1398
newobj -> ops = oldobj -> ops ;
1393
1399
newobj -> options = oldobj -> options ;
1394
1400
newobj -> context = php_hash_alloc_context (newobj -> ops );
1395
- newobj -> ops -> hash_init (newobj -> context );
1401
+ newobj -> ops -> hash_init (newobj -> context , NULL );
1396
1402
1397
1403
if (SUCCESS != newobj -> ops -> hash_copy (newobj -> ops , oldobj -> context , newobj -> context )) {
1398
1404
efree (newobj -> context );
@@ -1529,8 +1535,8 @@ PHP_METHOD(HashContext, __unserialize)
1529
1535
1530
1536
hash -> ops = ops ;
1531
1537
hash -> context = php_hash_alloc_context (ops );
1532
- ops -> hash_init (hash -> context );
1533
1538
hash -> options = options ;
1539
+ ops -> hash_init (hash -> context , NULL );
1534
1540
1535
1541
unserialize_result = ops -> hash_unserialize (hash , magic , hash_zv );
1536
1542
if (unserialize_result != SUCCESS ) {
0 commit comments