@@ -556,6 +556,7 @@ static int derive_retained_key(const EVP_MD *md, const char *hostnqn,
556556 size_t key_len )
557557{
558558 EVP_PKEY_CTX * ctx ;
559+ uint16_t length = key_len & 0xFFFF ;
559560 int ret ;
560561
561562 ctx = EVP_PKEY_CTX_new_id (EVP_PKEY_HKDF , NULL );
@@ -573,6 +574,9 @@ static int derive_retained_key(const EVP_MD *md, const char *hostnqn,
573574 goto out_free_ctx ;
574575 if (EVP_PKEY_CTX_set1_hkdf_key (ctx , generated , key_len ) <= 0 )
575576 goto out_free_ctx ;
577+ if (EVP_PKEY_CTX_add1_hkdf_info (ctx ,
578+ (const unsigned char * )& length , 2 ) <= 0 )
579+ goto out_free_ctx ;
576580 if (EVP_PKEY_CTX_add1_hkdf_info (ctx ,
577581 (const unsigned char * )"tls13 " , 6 ) <= 0 )
578582 goto out_free_ctx ;
@@ -600,6 +604,7 @@ static int derive_tls_key(const EVP_MD *md, const char *identity,
600604 unsigned char * psk , size_t key_len )
601605{
602606 EVP_PKEY_CTX * ctx ;
607+ uint16_t length = key_len & 0xFFFF ;
603608 int ret ;
604609
605610 ctx = EVP_PKEY_CTX_new_id (EVP_PKEY_HKDF , NULL );
@@ -617,6 +622,9 @@ static int derive_tls_key(const EVP_MD *md, const char *identity,
617622 goto out_free_ctx ;
618623 if (EVP_PKEY_CTX_set1_hkdf_key (ctx , retained , key_len ) <= 0 )
619624 goto out_free_ctx ;
625+ if (EVP_PKEY_CTX_add1_hkdf_info (ctx ,
626+ (const unsigned char * )& length , 2 ) <= 0 )
627+ goto out_free_ctx ;
620628 if (EVP_PKEY_CTX_add1_hkdf_info (ctx ,
621629 (const unsigned char * )"tls13 " , 6 ) <= 0 )
622630 goto out_free_ctx ;
0 commit comments