@@ -610,7 +610,7 @@ PHP_FUNCTION(hash_algos)
610
610
RFC5869 HMAC-based key derivation function */
611
611
PHP_FUNCTION (hash_hkdf )
612
612
{
613
- zend_string * returnval , * ikm , * algo , * info = NULL , * salt ;
613
+ zend_string * returnval , * ikm , * algo , * info = NULL , * salt = NULL ;
614
614
zend_long length = 0 ;
615
615
char * prk , * computed_salt ;
616
616
unsigned char * digest , * K ;
@@ -645,25 +645,24 @@ PHP_FUNCTION(hash_hkdf)
645
645
RETURN_FALSE ;
646
646
}
647
647
648
- if (salt -> len == 0 )
649
- {
648
+ if (salt != NULL && salt -> len > 0 ) {
649
+ computed_salt = safe_emalloc (salt -> len , salt -> len , 0 );
650
+ memcpy (computed_salt , salt -> val , salt -> len );
651
+ }
652
+ else {
650
653
computed_salt = safe_emalloc (ops -> digest_size , ops -> digest_size , 0 );
651
654
for (i = 0 ; i < ops -> digest_size ; i ++ )
652
655
{
653
656
computed_salt [i ] = 0x00 ;
654
657
}
655
658
}
656
- else {
657
- computed_salt = safe_emalloc (salt -> len , salt -> len , 0 );
658
- memcpy (computed_salt , salt -> val , salt -> len );
659
- }
660
659
661
660
context = emalloc (ops -> context_size );
662
661
663
662
// Extract
664
663
ops -> hash_init (context );
665
664
K = emalloc (ops -> block_size );
666
- php_hash_hmac_prep_key (K , ops , context , computed_salt , salt -> len ? salt -> len : ops -> digest_size );
665
+ php_hash_hmac_prep_key (K , ops , context , computed_salt , ( salt != NULL && salt -> len ? salt -> len : ops -> digest_size ) );
667
666
prk = safe_emalloc (ops -> digest_size , ops -> digest_size , 0 );
668
667
php_hash_hmac_round (prk , ops , context , K , ikm -> val , ikm -> len );
669
668
php_hash_string_xor_char (K , K , 0x6A , ops -> block_size );
0 commit comments