@@ -2902,8 +2902,8 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
2902
2902
psa_algorithm_t alg ,
2903
2903
mbedtls_operation_t cipher_operation )
2904
2904
{
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 ;
2907
2907
psa_key_slot_t * slot ;
2908
2908
size_t key_bits ;
2909
2909
const mbedtls_cipher_info_t * cipher_info = NULL ;
@@ -2923,19 +2923,19 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
2923
2923
2924
2924
status = psa_get_key_from_slot ( handle , & slot , usage , alg );
2925
2925
if ( status != PSA_SUCCESS )
2926
- return ( status ) ;
2926
+ goto exit ;
2927
2927
key_bits = psa_get_key_bits ( slot );
2928
2928
2929
2929
cipher_info = mbedtls_cipher_info_from_psa ( alg , slot -> type , key_bits , NULL );
2930
2930
if ( cipher_info == NULL )
2931
- return ( PSA_ERROR_NOT_SUPPORTED );
2931
+ {
2932
+ status = PSA_ERROR_NOT_SUPPORTED ;
2933
+ goto exit ;
2934
+ }
2932
2935
2933
2936
ret = mbedtls_cipher_setup ( & operation -> ctx .cipher , cipher_info );
2934
2937
if ( ret != 0 )
2935
- {
2936
- psa_cipher_abort ( operation );
2937
- return ( mbedtls_to_psa_error ( ret ) );
2938
- }
2938
+ goto exit ;
2939
2939
2940
2940
#if defined(MBEDTLS_DES_C )
2941
2941
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,
2956
2956
(int ) key_bits , cipher_operation );
2957
2957
}
2958
2958
if ( ret != 0 )
2959
- {
2960
- psa_cipher_abort ( operation );
2961
- return ( mbedtls_to_psa_error ( ret ) );
2962
- }
2959
+ goto exit ;
2963
2960
2964
2961
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING )
2965
2962
switch ( alg )
@@ -2978,10 +2975,7 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
2978
2975
break ;
2979
2976
}
2980
2977
if ( ret != 0 )
2981
- {
2982
- psa_cipher_abort ( operation );
2983
- return ( mbedtls_to_psa_error ( ret ) );
2984
- }
2978
+ goto exit ;
2985
2979
#endif //MBEDTLS_CIPHER_MODE_WITH_PADDING
2986
2980
2987
2981
operation -> key_set = 1 ;
@@ -2992,7 +2986,12 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
2992
2986
operation -> iv_size = PSA_BLOCK_CIPHER_BLOCK_SIZE ( slot -> type );
2993
2987
}
2994
2988
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 );
2996
2995
}
2997
2996
2998
2997
psa_status_t psa_cipher_encrypt_setup ( psa_cipher_operation_t * operation ,
0 commit comments