@@ -2902,8 +2902,8 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
29022902 psa_algorithm_t alg ,
29032903 mbedtls_operation_t cipher_operation )
29042904{
2905- int ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ;
2906- psa_status_t status ;
2905+ int ret = 0 ;
2906+ psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
29072907 psa_key_slot_t * slot ;
29082908 size_t key_bits ;
29092909 const mbedtls_cipher_info_t * cipher_info = NULL ;
@@ -2923,19 +2923,19 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
29232923
29242924 status = psa_get_key_from_slot ( handle , & slot , usage , alg );
29252925 if ( status != PSA_SUCCESS )
2926- return ( status ) ;
2926+ goto exit ;
29272927 key_bits = psa_get_key_bits ( slot );
29282928
29292929 cipher_info = mbedtls_cipher_info_from_psa ( alg , slot -> type , key_bits , NULL );
29302930 if ( cipher_info == NULL )
2931- return ( PSA_ERROR_NOT_SUPPORTED );
2931+ {
2932+ status = PSA_ERROR_NOT_SUPPORTED ;
2933+ goto exit ;
2934+ }
29322935
29332936 ret = mbedtls_cipher_setup ( & operation -> ctx .cipher , cipher_info );
29342937 if ( ret != 0 )
2935- {
2936- psa_cipher_abort ( operation );
2937- return ( mbedtls_to_psa_error ( ret ) );
2938- }
2938+ goto exit ;
29392939
29402940#if defined(MBEDTLS_DES_C )
29412941 if ( slot -> type == PSA_KEY_TYPE_DES && key_bits == 128 )
@@ -2956,10 +2956,7 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
29562956 (int ) key_bits , cipher_operation );
29572957 }
29582958 if ( ret != 0 )
2959- {
2960- psa_cipher_abort ( operation );
2961- return ( mbedtls_to_psa_error ( ret ) );
2962- }
2959+ goto exit ;
29632960
29642961#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING )
29652962 switch ( alg )
@@ -2978,10 +2975,7 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
29782975 break ;
29792976 }
29802977 if ( ret != 0 )
2981- {
2982- psa_cipher_abort ( operation );
2983- return ( mbedtls_to_psa_error ( ret ) );
2984- }
2978+ goto exit ;
29852979#endif //MBEDTLS_CIPHER_MODE_WITH_PADDING
29862980
29872981 operation -> key_set = 1 ;
@@ -2992,7 +2986,12 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
29922986 operation -> iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE ( slot -> type );
29932987 }
29942988
2995- return ( PSA_SUCCESS );
2989+ exit :
2990+ if ( status == 0 )
2991+ status = mbedtls_to_psa_error ( ret );
2992+ if ( status != 0 )
2993+ psa_cipher_abort ( operation );
2994+ return ( status );
29962995}
29972996
29982997psa_status_t psa_cipher_encrypt_setup ( psa_cipher_operation_t * operation ,
0 commit comments