@@ -711,9 +711,18 @@ static psa_status_t setup_psa_key_derivation( psa_key_derivation_operation_t* de
711711 if ( status != PSA_SUCCESS )
712712 return ( status );
713713
714- status = psa_key_derivation_input_key ( derivation ,
715- PSA_KEY_DERIVATION_INPUT_SECRET ,
716- slot );
714+ if ( slot == 0 )
715+ {
716+ status = psa_key_derivation_input_bytes (
717+ derivation , PSA_KEY_DERIVATION_INPUT_SECRET ,
718+ NULL , 0 );
719+ }
720+ else
721+ {
722+ status = psa_key_derivation_input_key (
723+ derivation , PSA_KEY_DERIVATION_INPUT_SECRET ,
724+ slot );
725+ }
717726 if ( status != PSA_SUCCESS )
718727 return ( status );
719728
@@ -743,8 +752,7 @@ static int tls_prf_generic( mbedtls_md_type_t md_type,
743752{
744753 psa_status_t status ;
745754 psa_algorithm_t alg ;
746- psa_key_attributes_t key_attributes ;
747- psa_key_handle_t master_slot ;
755+ psa_key_handle_t master_slot = 0 ;
748756 psa_key_derivation_operation_t derivation =
749757 PSA_KEY_DERIVATION_OPERATION_INIT ;
750758
@@ -753,14 +761,24 @@ static int tls_prf_generic( mbedtls_md_type_t md_type,
753761 else
754762 alg = PSA_ALG_TLS12_PRF (PSA_ALG_SHA_256 );
755763
756- key_attributes = psa_key_attributes_init ();
757- psa_set_key_usage_flags ( & key_attributes , PSA_KEY_USAGE_DERIVE );
758- psa_set_key_algorithm ( & key_attributes , alg );
759- psa_set_key_type ( & key_attributes , PSA_KEY_TYPE_DERIVE );
760-
761- status = psa_import_key ( & key_attributes , secret , slen , & master_slot );
762- if ( status != PSA_SUCCESS )
763- return ( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
764+ /* Normally a "secret" should be long enough to be impossible to
765+ * find by brute force, and in particular should not be empty. But
766+ * this PRF is also used to derive an IV, in particular in EAP-TLS,
767+ * and for this use case it makes sense to have a 0-length "secret".
768+ * Since the key API doesn't allow importing a key of length 0,
769+ * keep master_slot=0, which setup_psa_key_derivation() understands
770+ * to mean a 0-length "secret" input. */
771+ if ( slen != 0 )
772+ {
773+ psa_key_attributes_t key_attributes = psa_key_attributes_init ();
774+ psa_set_key_usage_flags ( & key_attributes , PSA_KEY_USAGE_DERIVE );
775+ psa_set_key_algorithm ( & key_attributes , alg );
776+ psa_set_key_type ( & key_attributes , PSA_KEY_TYPE_DERIVE );
777+
778+ status = psa_import_key ( & key_attributes , secret , slen , & master_slot );
779+ if ( status != PSA_SUCCESS )
780+ return ( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
781+ }
764782
765783 status = setup_psa_key_derivation ( & derivation ,
766784 master_slot , alg ,
@@ -790,7 +808,8 @@ static int tls_prf_generic( mbedtls_md_type_t md_type,
790808 return ( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
791809 }
792810
793- status = psa_destroy_key ( master_slot );
811+ if ( master_slot != 0 )
812+ status = psa_destroy_key ( master_slot );
794813 if ( status != PSA_SUCCESS )
795814 return ( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
796815
0 commit comments